This repository has been archived by the owner on May 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.php
98 lines (98 loc) · 3.47 KB
/
render.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/*
render.php is part of the PHP teletext viewer project, codenamed 'Non Editing Teletext Viewer' or NETV (NET-v)
Display Functions
Nathan Dane, 2018
*/
function lineRender($line,$control,$mpp)
{
$lastesc=strpos($line,"\e"); // Find the first control code
$lastesc++;
$i=0;
$dh=""; // Reset the double height flag
$end=""; // Nothing to close yet
$out=""; // Prepare the output buffer
$everycode=""; // Once a background is declared, it should be on every code until it changes or is removed
foreach ($control as $key => $code)
{
if (is_array($code[0]))
{
$count=0;
$pre="f";
$codesgroup=array();
foreach($code as $process)
{
$last=($count-1);
if ($process[0] == "]")
{
$codesgroup[$last][1]='b';
$everycode=$codesgroup[$last][1].$codesgroup[$last][0];
}
else
{
$control=codeControl($process[0]); // This'll give us the html version of the code we need.
array_push($codesgroup,array($control[0],'f'));
$count++;
}
}
$html=str_repeat(' ',$count).'<span class="';
foreach($codesgroup as $process)
{
$html.="$process[1]$process[0] ";
}
$lastesc+=$count;
$html.="$pre$control[0] ";
$out.=$html;
$out.="$everycode".'"> ';
$thisesc=strpos($line,"\e",($lastesc)); // Add 'count': how many control codes there were in this group
if ($thisesc === false) $thisesc=40; // no more control codes, go to the end of the line
$wait=substr($line,($lastesc),($thisesc-$lastesc));
if ($control[1] === true) // Is this a graphics code?
$out.=contiguousGraphics($wait,0); // Convert the text to graphics
else
$out.=$wait;
$lastesc=$thisesc;
$lastesc++; // Add one so that it doesn't include the esc
$i++;
}
else
{
$control=codeControl($code[0]); // This'll give us the html version of the code we need.
if (is_array($control))
{
if ($i > 0) $end="</span>"; // If we've already done something, make sure to close it
$thisesc=strpos($line,"\e",$lastesc);
if ($thisesc === false) $thisesc=40; // no more control codes, go to the end of the line
$out.="$end".'<span class="f'."$control[0]$dh $everycode".'"> '; // Add the control code
$wait=substr($line,$lastesc,($thisesc-$lastesc)); // and text to the output 'buffer'. NO, WAIT!!!
if ($control[1] === true) // Is this a graphics code?
$out.=contiguousGraphics($wait,0); // Convert the text to graphics
// Need to add option for seperated graphics here @todo
// Also if this isn't graphics, nothing will get output.
// Not sure if this is a problem yet
else
$out.=$wait;
$lastesc=$thisesc;
$lastesc++; // Add one so that it doesn't include the esc
$i++;
//$out.= "got called";
}
else
{
if ($i > 0) $end="</span>"; // If we've already done something, make sure to close it
$thisesc=strpos($line,"\e",$lastesc);
if ($thisesc === false) $thisesc=40; // no more control codes, go to the end of the line
if ($control!="dh") $start="f";
$out.="$end".'<span class="'."$start$control$dh $everycode".'"> '; // Add the control code
$out.=substr($line,$lastesc,($thisesc-$lastesc)); // and text to the output 'buffer'.
$lastesc=$thisesc;
$lastesc++; // Add one so that it doesn't include the esc
$i++;
//$out.= "got called";
}
if ($control=="dh") $dh=" dh";
}
}
$out=str_replace("`",'—',$out); // Make dashes look right
return $out;
}