Sry etwas später geworden.
Code: Alles auswählen
<?php
define('TextBox', 0); // Standard TextBox, nach Schriftgröße
define('RealBox', 1); // Echte TextBox, genau nach größe
define('RotateBox', 2); // Zeichen wird um 180° gedreht
define('SpaceElement', 4); // Das Element bekommt links und rechts ein Freiraum
define('BigElement', 8); // Das Element ist besonders größ und bekommt detailänderungen
// Fügt Farben und Transparentwerte hinzu
//===============================================
function imagehexcolorallocate($Image, $Color)
{
$Int = hexdec($Color);
return imagecolorallocate($Image, 255&($Int>>16),255&($Int>>8),255&$Int);
}
function AddImageColor($Image, $FrontColor)
{
$Color = array
(0,
imagehexcolorallocate($Image, $FrontColor), // Schriftfarbe
imagehexcolorallocate($Image, 'D00000'), // Debug
imagehexcolorallocate($Image, '50F050'), // Elementrahmen
imagehexcolorallocate($Image, 'A0A0A0')); // Wasserzeichen
return $Color;
}
//===============================================
// Berechnet die Ausdrehung eines Textes
//===============================================
function TextBox($Size, $Angle, $Face, $Text, $Type=TextBox, $Flag=false)
{
$Box = imagettfbbox($Size, $Angle, $Face, $Text);
$minX = min($Box[0],$Box[6]);
$maxX = max($Box[2],$Box[4]);
$minY = min($Box[5],$Box[7]);
$maxY = max($Box[1],$Box[3]);
if ($Type&RealBox)
{
// Echte TextBox, genau nach größe
$BoxSize = array
('Left' => $minX,
'Top' => $minY,
'Width' => $maxX-$minX,
'Height' => $maxY-$minY,
'Base' => 0,
'Angle' => 0);
}
else
{
// Standard TextBox, nach Schriftgröße
$BoxSize = array
('Left' => $minX,
'Top' => -$Size,
'Width' => $maxX-$minX,
'Height' => $Size*4/3,
'Base' => 0,
'Angle' => 0,
'SpaceHeight' => $minY+$Size,
'SpaceDepth' => ($Size*4/3)-($maxY-$minY)-($minY+$Size));
}
if (!($Type&RealBox))
{
if (substr($Text,strlen($Text)-1)=='f') // Verbreiterung beim "f"
{ $BoxSize['Width'] += $Size*0.3; }
if (substr($Text,0,1)==chr(176)) // Verschiebung beim "°"
{ $BoxSize['Top'] -= $Size*1/3; }
if (substr($Text,0,1)==chr(214)) // verschiebung bei Wurzel
{ $BoxSize['Top'] -= $Size*1/4; }
if (substr($Text,0,1)==chr(242)) // Verschiebung bei Integral
{ $BoxSize['Width'] += $Size*1/8; $BoxSize['Top'] -= $Size*1/6; }
if (substr($Text,0,1)=='*') // verschiebung bei *
{ $BoxSize['Top'] -= $Size*1/8; }
if ($Flag=='+-') // Verdrehung von "+-" zu "-+"
{ $BoxSize['Left'] -= $Size*0.7; $BoxSize['Top'] += $Size*0.6; $BoxSize['Angle']=180; }
if ($Flag=='h-') // Verdrehung von "+-" zu "-+"
{ $BoxSize['Left'] += $Size*0.5+3; $BoxSize['Top'] += $Size*0.4; $BoxSize['Width']=0; }
}
else
{
if (substr($Text,0,1)==chr(183)) // verschiebung bei *
{ $BoxSize['Left'] -= $Size*1/10; }
}
return $BoxSize;
}
//===============================================
// Erstellt ein neue Element der Formel
//===============================================
function CreateElement($ID, $Text, $Size, $Face, $Type=TextBox)
{
global $Element, $Space, $Font;
if ($Text==chr(178))
{ $Text = chr(177); $BoxSize = TextBox($Size, 0, $Face, $Text, $Type, '+-'); }
elseif ($Text==chr(96))
{ $Text = '-'; $Face = $Font['Variable']; $BoxSize = TextBox($Size, 0, $Face, $Text, $Type, 'h-'); }
else
{ $BoxSize = TextBox($Size, 0, $Face, $Text, $Type); }
if ($Type&SpaceElement)
{
$BoxSize['Width'] += $Size*$Space['Right']*2;
$BoxSize['Left'] -= $Size*$Space['Right'];
}
if ($Type&BigElement)
{
if ( ($Text=='S') or ($Text=='P') ) // Summe
$BoxSize['Base'] += $Size*1/8;
if ($Text==chr(242)) // Integral
{ $BoxSize['Base'] += $Size*2/5; }
}
$Element[$ID] = array
(
'Text'=>$Text, 'Size'=>$Size, 'Face'=>$Face,
'Width'=>$BoxSize['Width'], 'Height'=>$BoxSize['Height'],
'Left'=>$BoxSize['Left'], 'Top'=>$BoxSize['Top'],
'Base'=>$BoxSize['Base'], 'Angle'=>$BoxSize['Angle'],
'SpaceHeight'=>$BoxSize['SpaceHeight'], 'SpaceDepth'=>$BoxSize['SpaceDepth']
);
}
//===============================================
// verbindet zwei Elemente zu einem neuen
//===============================================
function ConnectElement($ID, $ElementID1, $ElementID2, $Type, $Size=0, $FakeSize=0, $Shift=0)
{ // ^^ Verschiebung eines Pow-Elements JA/NEIN
// ^^ Wahre Größe der Umgebung
// oder Verschiebungswert
// ^^ Größe der Verbindung
global $Element, $Space, $Font, $LastIndexWidth;
if ($Type=='Index')
{
$Element[$ElementID2]['Base'] -= $Element[$ElementID1]['Size']*$Space['Index'];
$LastIndexWidth = $Element[$ElementID2]['Width'];
if ($Element[$ElementID1]['Text']=='S')
$Element[$ElementID2]['Base'] += $Element[$ElementID1]['Size']*$Space['Border'];
if ($Element[$ElementID1]['Text']==chr(242))
$Element[$ElementID2]['Base'] += $Element[$ElementID1]['Size']*$Space['Line'];
}
if ($Type=='Pow')
{
$Element[$ElementID2]['Base'] += $Element[$ElementID1]['Size']*$Space['Pow'];
}
if ( ($Type=='Right') or ($Type=='Index') or ($Type=='Pow') )
{
$Base = max($Element[$ElementID1]['Base'],$Element[$ElementID2]['Base']);
$DeltaBase = $Element[$ElementID1]['Base']-$Element[$ElementID2]['Base'];
$Height = max($Element[$ElementID1]['Height']-($DeltaBase<=0?$DeltaBase:0),$Element[$ElementID2]['Height']+($DeltaBase>0?$DeltaBase:0));
$Width = $Element[$ElementID1]['Width']+$Element[$ElementID2]['Width']+($Shift?$FakeSize:0);
if ( ($Shift) and ($Type=='Pow') )
$Width = $Element[$ElementID1]['Width']-$LastIndexWidth+max($Element[$ElementID2]['Width']+$FakeSize,$LastIndexWidth);
$Element[$ID] = array
('ElementID1'=>$ElementID1,'ElementID2'=>$ElementID2,
'Text'=>$Element[$ElementID1]['Text'].$Element[$ElementID2]['Text'],
'Width'=>$Width,'Height'=>$Height,
'Size'=>max($Element[$ElementID1]['Size'],$Element[$ElementID2]['Size']),
'Base'=>$Base);
$Element[$ElementID1]['x'] = 0;
$Element[$ElementID1]['y'] = $Base-$Element[$ElementID1]['Base'];
$Element[$ElementID2]['x'] = $Element[$ElementID1]['Width']+($Shift?$FakeSize:0);
if ( ($Shift) and ($Type=='Pow') )
$Element[$ElementID2]['x'] += -$LastIndexWidth;
$Element[$ElementID2]['y'] = $Base-$Element[$ElementID2]['Base'];
}
elseif ($Type=='Column')
{
$DeltaHeight = $Element[$ElementID2]['Height']+$Size*$Space['Break'];
$Height = $Element[$ElementID1]['Height']+$DeltaHeight;
$Width = max($Element[$ElementID1]['Width'],$Element[$ElementID2]['Width']);
$Element[$ID] = array
('ElementID1'=>$ElementID1,'ElementID2'=>$ElementID2,
'Text'=>$Element[$ElementID1]['Text'].$Element[$ElementID2]['Text'],
'Width'=>$Width,'Height'=>$Height,
'Size'=>$Size,
'Base'=>$Element[$ElementID1]['Base']+$DeltaHeight/2);
$Element[$ElementID1]['x'] = ($Width-$Element[$ElementID1]['Width'])/2;
$Element[$ElementID1]['y'] = 0;
$Element[$ElementID2]['x'] = ($Width-$Element[$ElementID2]['Width'])/2;
$Element[$ElementID2]['y'] = $Element[$ElementID1]['Height'] + $Size*$Space['Break'];
}
elseif ($Type=='Down')
{
if ($Element[$ElementID1]['SpaceDepth']>$Element[$ElementID2]['Height']+$Size*$Space['Down'])
$DeltaHeight = 0;
else
$DeltaHeight = $Element[$ElementID2]['Height']+$Size*$Space['Down']-$Element[$ElementID1]['SpaceDepth'];
$Height = $Element[$ElementID1]['Height']+$DeltaHeight;
$Width = max($Element[$ElementID1]['Width'],$Element[$ElementID2]['Width']);
$Element[$ID] = array
('ElementID1'=>$ElementID1,'ElementID2'=>$ElementID2,
'Text'=>$Element[$ElementID1]['Text'],
'Width'=>$Width,'Height'=>$Height,
'Size'=>$Element[$ElementID1]['Size'],
'SpaceHeight'=>$Element[$ElementID1]['SpaceHeight'],
'Base'=>$Element[$ElementID1]['Base']);
$Element[$ElementID1]['x'] = ($Width-$Element[$ElementID1]['Width'])/2;
$Element[$ElementID1]['y'] = 0;
$Element[$ElementID2]['x'] = ($Width-$Element[$ElementID2]['Width'])/2;
$Element[$ElementID2]['y'] = $Element[$ElementID1]['Height'] + $Size*$Space['Down'] - $Element[$ElementID1]['SpaceDepth'];
}
elseif ($Type=='Up')
{
$Real = $Element[$ElementID2]['Height'] + $Size*$Space['Up'];
if ($FakeSize)
{
$Real -= min($Element[$ElementID1]['SpaceHeight'], $Element[$ElementID2]['Height'] + $Size*$Space['Up']);
if (!$Real)
$Delta = $Element[$ElementID1]['SpaceHeight']-($Element[$ElementID2]['Height'] + $Size*$Space['Up']);
}
$Height = $Element[$ElementID1]['Height']+$Real;
$Width = max($Element[$ElementID1]['Width'],$Element[$ElementID2]['Width']);
$Element[$ID] = array
('ElementID1'=>$ElementID1,'ElementID2'=>$ElementID2,
'Text'=>$Element[$ElementID1]['Text'],
'Size'=>$Element[$ElementID1]['Size'],
'Width'=>$Width,'Height'=>$Height,
'SpaceDepth'=>$Element[$ElementID1]['SpaceDepth'],
'Base'=>$Element[$ElementID1]['Base']+$Real);
$Element[$ElementID1]['x'] = ($Width-$Element[$ElementID1]['Width'])/2;
$Element[$ElementID1]['y'] = $Real;
$Element[$ElementID2]['x'] = ($Width-$Element[$ElementID2]['Width'])/2;
$Element[$ElementID2]['y'] = $Delta;
if (substr($Element[$ElementID1]['Text'],0,1)==chr(242))
$Element[$ElementID2]['x'] += $Element[$ElementID1]['Size']*$Space['Border'];
}
elseif ($Type=='Break')
{
$Height = $Element[$ElementID1]['Height']+$Element[$ElementID2]['Height'] + $Size*$Space['Break'];
$Width = max($Element[$ElementID1]['Width'],$Element[$ElementID2]['Width']) + $Size*$Space['Border']*2;
$Element[$ID] = array
('ElementID1'=>$ElementID1,'ElementID2'=>$ElementID2,
'Size'=>$Size,
'Width'=>$Width,'Height'=>$Height,
'Base'=>$Element[$ElementID1]['Height'] - $FakeSize/2,
'Type'=>'Break');
$Element[$ElementID1]['x'] = ($Width-$Element[$ElementID1]['Width'])/2;
$Element[$ElementID1]['y'] = 0;
$Element[$ElementID2]['x'] = ($Width-$Element[$ElementID2]['Width'])/2;
$Element[$ElementID2]['y'] = $Element[$ElementID1]['Height'] + $Size*$Space['Break'];
}
elseif ($Type=='Sqr')
{
$DeltaHeight = $Size*($Space['Border']+$Space['Line']);
$Height = $Element[$ElementID2]['Height'] + $DeltaHeight;
$Width = $Element[$ElementID1]['Width'] + $Size*($Space['Break']+$Space['Border']*2) + $Element[$ElementID2]['Width'];
$Element[$ID] = array
('ElementID1'=>$ElementID1,'ElementID2'=>$ElementID2,
'Size'=>$Size,
'Width'=>$Width,'Height'=>$Height,
'Base'=>$DeltaHeight+$Element[$ElementID2]['Base'],
'Type'=>'Sqr');
if ($Element[$ElementID1]['Text']=='2')
{$Element[$ElementID1]['Text']=' ';}
$Element[$ElementID1]['x'] = 0;
$Element[$ElementID1]['y'] = $Height/2-$Element[$ElementID1]['Height'];
$Element[$ElementID2]['x'] = $Element[$ElementID1]['Width'] + $Size*($Space['Break']+$Space['Border']);
$Element[$ElementID2]['y'] = $DeltaHeight;
}
}
//===============================================
// Zeigt ein Element (mit Unterelementen) an
//===============================================
function DisplayKlammer($Image, $ID, $x, $y, $Klammer, $Ascii, $Flag=0)
{
global $Element, $Font, $Space;
$Size = $Element[$ID]['Size'];
$Height = $Element[$ID]['Height'];
$Width = $Element[$ID]['Width'];
if ($Element[$ID]['Size']*2<$Element[$ID]['Height'])
{
$TextBoxU = TextBox($Size, 0, $Font['Symbol'], chr($Ascii), RealBox);
imagettftext($Image, $Size, 0, $x+$Flag*($Width-$TextBoxU['Width'])-$TextBoxU['Left'], $y-$TextBoxU['Top'], $Font['Color'][1], $Font['Symbol'], chr($Ascii));
$TextBoxD = TextBox($Size, 0, $Font['Symbol'], chr($Ascii+2), RealBox);
imagettftext($Image, $Size, 0, $x+$Flag*($Width-$TextBoxD['Width'])-$TextBoxD['Left'], $y+$Height-$TextBoxD['Height']-$TextBoxD['Top'], $Font['Color'][1], $Font['Symbol'], chr($Ascii+2));
$TextBoxC = TextBox($Size, 0, $Font['Symbol'], chr($Ascii+1), RealBox);
$Count = ($Height-$TextBoxD['Height']-$TextBoxU['Height']) / $TextBoxC['Height'];
if ($Count>0)
{
$RealCount = floor($Count*2);
$DeltaCount = $RealCount*$TextBoxC['Height']/4;
for ($n=0;$n<=$RealCount;$n++)
imagettftext($Image, $Size, 0, $x+$Flag*($Width-$TextBoxC['Width'])-$TextBoxC['Left'], $y+$Height/2-$DeltaCount+($n-1)*$TextBoxC['Height']/2-$TextBoxC['Top'], $Font['Color'][1], $Font['Symbol'], chr($Ascii+1));
}
}
else
{
$TextBox = TextBox($Height*0.75, 0, $Font['Symbol'], $Klammer, RealBox);
imagettftext($Image, $Height*0.75, 0, $x-$TextBox['Left'], $y-$TextBox['Top'], $Font['Color'][1], $Element[$ID]['Face'], $Klammer);
}
}
function DisplayElement($Image, $ID, $x, $y)
{
global $Element, $Font, $Space;
if ($_GET['debug']==2)
imagerectangle($Image,$x,$y,$x+$Element[$ID]['Width']-1,$y+$Element[$ID]['Height']-1, $Font['Color'][3]);
if ($Element[$ID]['ElementID1'])
{
DisplayElement($Image, $Element[$ID]['ElementID1'], $x+$Element[$Element[$ID]['ElementID1']]['x'], $y+$Element[$Element[$ID]['ElementID1']]['y']);
if ($Element[$ID]['ElementID2'])
DisplayElement($Image, $Element[$ID]['ElementID2'], $x+$Element[$Element[$ID]['ElementID2']]['x'], $y+$Element[$Element[$ID]['ElementID2']]['y']);
if ($Element[$ID]['Type']=='Break')
{
$Height = $Element[$ID]['Size']*$Space['Border'];
$DeltaHeight = floor($Element[$ID]['Size']*$Space['Line']);
if ($DeltaHeight >= 1)
$DeltaHeight--;
imagefilledrectangle($Image,$x,$y+$Element[$Element[$ID]['ElementID1']]['Height']+$Height,$x+$Element[$ID]['Width']-1,$y+$Element[$Element[$ID]['ElementID1']]['Height']+$Height+$DeltaHeight, $Font['Color'][1]);
}
if ($Element[$ID]['Type']=='Sqr')
{
$DeltaHeight = round($Element[$ID]['Size']*$Space['Line']);
$DeltaWidth = $Element[$Element[$ID]['ElementID1']]['Width']+$Element[$ID]['Size']*$Space['Break'];
if ($DeltaHeight >= 1)
$DeltaHeight--;
imagefilledrectangle($Image,$x+$DeltaWidth,$y,$x+$Element[$ID]['Width']-1,$y+$DeltaHeight, $Font['Color'][1]);
$Polygon = array
($x+$DeltaWidth-$DeltaHeight,$y,
$x+$DeltaWidth,$y,
$x+$DeltaWidth-$Element[$ID]['Size']*$Space['Break'],$y+$Element[$ID]['Height']-1,
$x+$DeltaWidth-$Element[$ID]['Size']*$Space['Break']-$DeltaHeight,$y+$Element[$ID]['Height']-1);
imagefilledpolygon($Image,$Polygon,4, $Font['Color'][1]);
$Polygon = array
($x+$DeltaWidth-$Element[$ID]['Size']*$Space['Index']-$DeltaHeight*2,$y+$Element[$ID]['Height']/2,
$x+$DeltaWidth-$Element[$ID]['Size']*$Space['Index'],$y+$Element[$ID]['Height']/2,
$x+$DeltaWidth-$Element[$ID]['Size']*$Space['Break'],$y+$Element[$ID]['Height']-1,
$x+$DeltaWidth-$Element[$ID]['Size']*$Space['Break']-$DeltaHeight*2,$y+$Element[$ID]['Height']-1);
imagefilledpolygon($Image,$Polygon,4, $Font['Color'][1]);
imagefilledrectangle($Image,$x,$y+$Element[$ID]['Height']/2,$x+$DeltaWidth-$Element[$ID]['Size']*$Space['Index'],$y+$Element[$ID]['Height']/2+$DeltaHeight, $Font['Color'][1]);
}
}
elseif ($Element[$ID]['Text']=='(')
DisplayKlammer($Image, $ID, $x, $y, '(', 230, 0);
elseif ($Element[$ID]['Text']==')')
DisplayKlammer($Image, $ID, $x, $y, ')', 246, 1);
elseif ($Element[$ID]['Text']=='[')
DisplayKlammer($Image, $ID, $x, $y, '[', 233, 0);
elseif ($Element[$ID]['Text']==']')
DisplayKlammer($Image, $ID, $x, $y, ']', 249, 1);
// elseif ($Element[$ID]['Text']=='{')
// DisplayKlammer($Image, $ID, $x, $y, '{', 236, 0);
// elseif ($Element[$ID]['Text']=='}')
// DisplayKlammer($Image, $ID, $x, $y, '}', 252, 1);
else
{
imagettftext($Image, $Element[$ID]['Size'], $Element[$ID]['Angle'], $x-$Element[$ID]['Left'], $y-$Element[$ID]['Top'], $Font['Color'][1], $Element[$ID]['Face'], $Element[$ID]['Text']);
}
}
//===============================================
/* $Bild = imagecreatetruecolor($Point, 18);
*/
// Erstellt das Bild zun zeichnet die Elemente
//===============================================
function imagecreatetruecolortransparent($x, $y)
{
$im = imagecreatetruecolor($x, $y);
imagealphablending($im, false);
imagesavealpha($im, true);
imagefill($im, 0, 0, imagecolorallocatealpha($im, 255, 255, 255, 127));
imagealphablending($im, true);
return $im;
}
function CreateElementImage($ID, $FrontColor, $Debug)
{
global $Element, $Font;
if ($Debug)
$Image = imagecreatetruecolortransparent($Element[$ID]['Width'], $Element[$ID]['Height']+10);
else
$Image = imagecreatetruecolortransparent($Element[$ID]['Width'], $Element[$ID]['Height']);
if (!$FrontColor) $FrontColor='000000';
$Font['Color'] = AddImageColor($Image, $FrontColor);
DisplayElement($Image, $ID, 0, 0);
if ($Debug)
{
imageline($Image,0,$Element[$ID]['Height'],$Element[$ID]['Width'],$Element[$ID]['Height'], $Font['Color'][2]);
imagettftext($Image, 8, 0, 0, $Element[$ID]['Height']+10, $Font['Color'][2], $Font['Text'], $Debug);
}
return $Image;
}
//===============================================
// Gibt den Bereich ün zwei zeichen wieder
//===============================================
function GetArea($Text, $Open, $Close)
{
if (substr($Text, 0, 1)==$Open)
{
$u=1;
$j=strpos($Text,$Close,1)+1;
while ((strpos($Text,$Open,$u)!==false) and (strpos($Text,$Open,$u)<$j-1))
{
$u = strpos($Text,$Open,$u)+1;
$j = strpos($Text,$Close,$j)+1;
}
return array(1,$j-2);
}
else
{
return array(0,1);
}
}
//===============================================
// Entschlüsselt die URL und bildet Elemente
//===============================================
function SelectFormula($ID, $Text, $Size, $Operation=1)
{
global $Font, $Space, $Element;
// Zahl
if ($Len = strspn($Text,'0123456789,.'))
{
CreateElement($ID, substr($Text, 0, $Len), $Size, $Font['Text']);
}
// Variable
elseif ($Len = strspn($Text,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'))
{
if ( ($Len>=6) and (strstr(' arcsin arccos arctan arccot ', ' '.strtolower(substr($Text,0,6)).' ')) )
{ CreateElement($ID, substr($Text, 0, 6), $Size, $Font['Text']); $Len = 6; }
elseif ( ($Len>=3) and (strstr(' sin cos tan cot log exp det lim ', ' '.strtolower(substr($Text,0,3)).' ')) )
{ CreateElement($ID, substr($Text, 0, 3), $Size, $Font['Text']); $Len = 3; }
elseif ( ($Len>=2) and (strstr(' ln im re ', ' '.strtolower(substr($Text,0,2)).' ')) )
{ CreateElement($ID, substr($Text, 0, 2), $Size, $Font['Text']); $Len = 2; }
else
{ CreateElement($ID, substr($Text, 0, $Len), $Size, $Font['Variable']); }
}
// Grichischer Buchstabe
elseif ($Len = strspn($Text,'$'))
{
if (substr($Text, 1, 1)=='|')
{ CreateElement($ID, substr($Text, 2, 1), $Size, $Font['Menge']); $Len=3; }
elseif (substr($Text, 1, 1)=='~')
{ CreateElement($ID, substr($Text, 2, 1), $Size, $Font['Script']); $Len=3; }
elseif (substr($Text, 1, 1)==chr(215))
{ CreateElement($ID, substr($Text, 2, 1), $Size, $Font['Vektor']); $Len=3; }
else
{ CreateElement($ID, substr($Text, 1, 1), $Size, $Font['Symbol']); $Len=2; }
}
// Verknüpfungszeichen
elseif ($Len = strspn($Text,'*~+-×/:=<>'.chr(185).chr(186).chr(179).chr(163).chr(177).chr(178).chr(187).chr(181).chr(176).chr(180).chr(172).chr(174).chr(171).chr(220).chr(222).chr(219).chr(217).chr(218)))
{
if (substr($Text, 0, 2)==':=')
{
CreateElement($ID, substr($Text, 0, 2), $Size, $Font['Symbol'], SpaceElement*$Operation);
$Len=2;
}
else
{
CreateElement($ID, substr($Text, 0, 1), $Size, $Font['Symbol'], SpaceElement*$Operation);
$Len=1;
}
}
elseif ($Len = strspn($Text,chr(162)))
{
CreateElement($ID, substr($Text, 0, 1), $Size, $Font['Symbol']);
$Len=1;
}
elseif ( (substr($Text, 0, 1)!='@') and (substr($Text, 0, 1)!='(') and (substr($Text, 0, 1)!='[') ) // and (substr($Text, 0, 1)!='{') )
{
CreateElement($ID, substr($Text, 0, 1), $Size, $Font['Symbol']);
$Len=1;
}
$Text = substr($Text, $Len);
if ( (substr($Text,0,1)=='(') or (substr($Text,0,1)=='[') )// or (substr($Text,0,1)=='{') )
{
if (substr($Text,0,1)=='(') $Klammer=array('(',')');
if (substr($Text,0,1)=='[') $Klammer=array('[',']');
// if (substr($Text,0,1)=='{') $Klammer=array('{','}');
$Area = GetArea($Text, $Klammer[0], $Klammer[1]);
If (!$Len) {$TempID=$ID;} else {$TempID=$ID+1;}
$ElementInner = SelectFormula($TempID, substr($Text, $Area[0], $Area[1]), $Size, $Operation);
CreateElement($ElementInner+1, $Klammer[0], $Size, $Font['Symbol']);
if ($Element[$ElementInner]['Height']>$Size*2)
$Element[$ElementInner+1]['Width'] += $Size*0.2+2;
else
$Element[$ElementInner+1]['Width'] += ($Element[$ElementInner]['Height']*0.75-$Size)*0.2+2;
$Element[$ElementInner+1]['Height'] = $Element[$ElementInner]['Height'];
$Element[$ElementInner+1]['Base'] = $Element[$ElementInner]['Base'];
CreateElement($ElementInner+2, $Klammer[1], $Size, $Font['Symbol']);
if ($Element[$ElementInner]['Height']>$Size*2)
{ $Element[$ElementInner+2]['Width'] += $Size*0.2;
$Element[$ElementInner+2]['Left'] += $Size*0.2; }
else
{ $Element[$ElementInner+2]['Width'] += ($Element[$ElementInner]['Height']*0.75-$Size)*0.2;
$Element[$ElementInner+2]['Left'] += ($Element[$ElementInner]['Height']*0.75-$Size)*0.2; }
$Element[$ElementInner+2]['Height'] = $Element[$ElementInner]['Height'];
$Element[$ElementInner+2]['Base'] = $Element[$ElementInner]['Base'];
ConnectElement($ElementInner+3, $ElementInner+1, $ElementInner, 'Right');
ConnectElement($ElementInner+4, $ElementInner+3, $ElementInner+2, 'Right');
$Element[$ElementInner+4]['Size'] = $Element[$ElementInner]['Height']*0.8;
If (!$Len)
{$ID = $ElementInner+4;}
else
{ConnectElement($ElementInner+5, $ID, $ElementInner+4, 'Right');
$ID = $ElementInner+5;}
$Text = substr($Text, $Area[1]+2);
}
// Besondere Bauelemente
elseif (substr($Text, 0, 1)=='@')
{
// Bruch
if ((substr($Text,1,2)=='fr') or (substr($Text,1,2)=='Fr'))
{
if (substr($Text,1,2)=='Fr')
{ $TempPos1 = 1+2; $TempSize = $Size; }
if (substr($Text,1,2)=='fr')
{ $TempPos1 = 1+2; $TempSize = $Size*$Font['Zoom']; }
$Area1 = GetArea(substr($Text, $TempPos1), '{', '}');
$TempPos2 = $Area1[0]*2+$Area1[1] + $TempPos1;
$Area2 = GetArea(substr($Text, $TempPos2), '{', '}');
If (!$Len) {$TempID=$ID;} else {$TempID=$ID+1;}
$Element1 = SelectFormula($TempID, substr($Text, $Area1[0]+$TempPos1, $Area1[1]), $TempSize, $Operation);
$Element2 = SelectFormula($Element1+1, substr($Text, $Area2[0]+$TempPos2, $Area2[1]), $TempSize, $Operation);
ConnectElement($Element2+1, $Element1, $Element2, 'Break', $TempSize, $Size);
If (!$Len)
{$ID = $Element2+1;}
else
{ConnectElement($Element2+2, $ID, $Element2+1, 'Right');
$ID = $Element2+2;}
$Text = substr($Text, $TempPos2 + $Area2[0]*2+$Area2[1]);
}
// Vektor
elseif ((substr($Text,1,3)=='col') or (substr($Text,1,3)=='Col'))
{
$TempPos = array();
$TempPos[0] = 1+3;
$Area = array();
$Area[0] = GetArea(substr($Text, $TempPos[0]), '{', '}');
$Count = substr($Text, $Area[0][0]+$TempPos[0], $Area[0][1]);
for ($n=1;$n<=$Count;$n++)
{
$TempPos[$n] = $Area[$n-1][0]*2+$Area[$n-1][1] + $TempPos[$n-1];
$Area[$n] = GetArea(substr($Text, $TempPos[$n]), '{', '}');
}
If (!$Len) {$TempID=$ID;} else {$TempID=$ID+1;}
$ElementV = SelectFormula($TempID, substr($Text, $Area[1][0]+$TempPos[1], $Area[1][1]), $Size, $Operation);
for ($n=2;$n<=$Count;$n++)
{
$ElementN = SelectFormula($ElementV+1, substr($Text, $Area[$n][0]+$TempPos[$n], $Area[$n][1]), $Size, $Operation);
ConnectElement($ElementN+1, $ElementV, $ElementN, 'Column', $Size, $Size);
$ElementV = $ElementN+1;
}
If (!$Len)
{$ID = $ElementV;}
else
{ConnectElement($ElementV+1, $ID, $ElementV, 'Right');
$ID = $ElementV+1;}
$Text = substr($Text, $TempPos[$Count] + $Area[$Count][0]*2+$Area[$Count][1]);
}
// Drüber & Drunter
elseif ((substr($Text,1,2)=='up') or (substr($Text,1,2)=='dn'))
{
$TempPos1 = 1+2;
$Area1 = GetArea(substr($Text, $TempPos1), '{', '}');
$TempPos2 = $Area1[0]*2+$Area1[1] + $TempPos1;
$Area2 = GetArea(substr($Text, $TempPos2), '{', '}');
If (!$Len) {$TempID=$ID;} else {$TempID=$ID+1;}
$Element1 = SelectFormula($TempID, substr($Text, $Area1[0]+$TempPos1, $Area1[1]), $Size, $Operation);
$Element2 = SelectFormula($Element1+1, substr($Text, $Area2[0]+$TempPos2, $Area2[1]), $Size*$Font['Zoom'], 0);
if (substr($Text,1,2)=='up')
ConnectElement($Element2+1, $Element1, $Element2, 'Up', $Size, $Size);
else
ConnectElement($Element2+1, $Element1, $Element2, 'Down', $Size, $Size);
If (!$Len)
{$ID = $Element2+1;}
else
{ConnectElement($Element2+2, $ID, $Element2+1, 'Right');
$ID = $Element2+2;}
$Text = substr($Text, $TempPos2 + $Area2[0]*2+$Area2[1]);
}
// Wurzel
elseif ((substr($Text,1,2)=='ro') or (substr($Text,1,2)=='Ro'))
{
$TempPos1 = 1+2;
$Area1 = GetArea(substr($Text, $TempPos1), '{', '}');
$TempPos2 = $Area1[0]*2+$Area1[1] + $TempPos1;
$Area2 = GetArea(substr($Text, $TempPos2), '{', '}');
If (!$Len) {$TempID=$ID;} else {$TempID=$ID+1;}
$Element1 = SelectFormula($TempID, substr($Text, $Area1[0]+$TempPos1, $Area1[1]), $Size*$Font['Zoom'], 0);
$Element2 = SelectFormula($Element1+1, substr($Text, $Area2[0]+$TempPos2, $Area2[1]), $Size, $Operation);
ConnectElement($Element2+1, $Element1, $Element2, 'Sqr', $Size);
If (!$Len)
{$ID = $Element2+1;}
else
{ConnectElement($Element2+2, $ID, $Element2+1, 'Right');
$ID = $Element2+2;}
$Text = substr($Text, $TempPos2 + $Area2[0]*2+$Area2[1]);
}
// Summe
elseif ((substr($Text,1,3)=='sum') or (substr($Text,1,3)=='Sum') or (substr($Text,1,3)=='pro') or (substr($Text,1,3)=='Pro') or (substr($Text,1,3)=='int') or (substr($Text,1,3)=='Int') or (substr($Text,1,3)=='lim') or (substr($Text,1,3)=='Lim'))
{
if ( (substr($Text,1,3)=='sum') or (substr($Text,1,3)=='pro') or (substr($Text,1,3)=='int') or (substr($Text,1,3)=='lim') )
{ $Up = 'Pow'; $Down = 'Index'; }
else
{ $Up = 'Up'; $Down = 'Down'; }
$TempPos1 = 1+3;
$TempPos2 = 1+3;
$TempPos3 = 1+3;
if (substr($Text,$TempPos1,1)=='_')
{
$Area1 = GetArea(substr($Text, $TempPos1+1), '{', '}');
$TempPos2 = $Area1[0]*2+$Area1[1] + $TempPos1 + 1;
$TempPos3 = $TempPos2;
}
if (substr($Text,$TempPos2,1)=='^')
{
$Area2 = GetArea(substr($Text, $TempPos2+1), '{', '}');
$TempPos3 = $Area2[0]*2+$Area2[1] + $TempPos2 + 1;
}
$Area3 = GetArea(substr($Text, $TempPos3), '{', '}');
$Shift = 0;
If (!$Len) {$TempID=$ID;} else {$TempID=$ID+1;}
if ( (substr($Text,1,3)=='sum') or (substr($Text,1,3)=='Sum') )
{ CreateElement($TempID, 'S', $Size*1.8, $Font['Symbol'], RealBox|BigElement); $Delta=0; }
elseif ( (substr($Text,1,3)=='pro') or (substr($Text,1,3)=='Pro') )
{ CreateElement($TempID, 'P', $Size*1.8, $Font['Symbol'], RealBox|BigElement); $Delta=0; }
elseif ( (substr($Text,1,3)=='int') or (substr($Text,1,3)=='Int') )
{ CreateElement($TempID, chr(242), $Size*1.8, $Font['Symbol'], RealBox|BigElement);$Delta=0.3;
$Shift = $Size*$Space['Right']; }
else
{ CreateElement($TempID, 'lim', $Size, $Font['Text'], RealBox);$Delta=0.0; }
if ($Area1[1])
{
$Element01 = SelectFormula($TempID+1, substr($Text, $Area1[0]+$TempPos1+1, $Area1[1]), $Size*$Font['Zoom'], 0);
ConnectElement($Element01+1, $TempID, $Element01, $Down, $Size);
$TempID = $Element01+1;
}
if ($Area2[1])
{
$Element02 = SelectFormula($TempID+1, substr($Text, $Area2[0]+$TempPos2+1, $Area2[1]), $Size*$Font['Zoom'], 0);
ConnectElement($Element02+1, $TempID, $Element02, $Up, $Size, $Shift, true);
$TempID = $Element02+1;
}
$Element1 = SelectFormula($TempID+1, substr($Text, $Area3[0]+$TempPos3, $Area3[1]), $Size, $Operation);
ConnectElement($Element1+1, $TempID, $Element1, 'Right', 0, $Size*$Space['Right'], true);
If (!$Len)
{$ID = $Element1+1;}
else
{ConnectElement($Element1+2, $ID, $Element1+1, 'Right');
$ID = $Element1+2;}
$Text = substr($Text, $TempPos3 + $Area3[0]*2+$Area3[1]);
}
else
{
If (!$Len)
{
CreateElement($ID, substr($Text, 0, 1), $Size, $Font['Text']);
}
else
{
CreateElement($ID+1, substr($Text, 0, 1), $Size, $Font['Text']);
ConnectElement($ID+2, $ID, $ID+1, 'Right');
$ID = $ID+2;
}
$Len=1;
$Text = substr($Text, $Len);
}
}
$OrnamentTEMP=1;
while ($OrnamentTEMP)
{
$OrnamentTEMP=0;
// Indize
if (substr($Text, 0, 1)=='_')
{
$Ornament=0;
// Falls Ornamente :
if ((substr($Text,1,1)=='_') or (substr($Text,1,1)=='='))
{ CreateElement($ID+1, substr($Text,1,1), $Size, $Font['Text'], RealBox); $Ornament=1; }
if ($Ornament)
{
$OrnamentTEMP = $Ornament;
ConnectElement($ID+2, $ID, $ID+1, 'Down', $Size, true);
$ID = $ID+2;
$Text = substr($Text, 2);
}
else
{
$Area = GetArea(substr($Text, 1), '{', '}');
$Element0 = SelectFormula($ID+1, substr($Text, $Area[0]+1, $Area[1]), $Size*$Font['Zoom'], 0);
ConnectElement($Element0+1, $ID, $Element0, 'Index');
$Text = substr($Text, $Area[0]*2+$Area[1]+1);
$ID = $Element0+1;
$Sub = 1;
}
}
else
$Sub = 0;
// Exponent
if (substr($Text, 0, 1)=='^')
{
$Ornament=0;
// Falls Ornamente :
if (substr($Text,1,1)=='.')
{ CreateElement($ID+1, chr(183), $Size, $Font['Text'], RealBox); $Ornament=1; }
elseif (substr($Text,1,1)==':')
{ CreateElement($ID+1, chr(183).chr(183), $Size, $Font['Text'], RealBox); $Ornament=1; }
elseif ((substr($Text,1,1)=='~') or (substr($Text,1,1)=='^') or (substr($Text,1,1)=='_'))
{ CreateElement($ID+1, substr($Text,1,1), $Size, $Font['Text'], RealBox); $Ornament=1; }
elseif (substr($Text,1,1)=='-')
{ CreateElement($ID+1, chr(174), $Size*$Font['Zoom'], $Font['Symbol'], RealBox); $Ornament=1; }
if ($Ornament)
{
$OrnamentTEMP = $Ornament;
ConnectElement($ID+2, $ID, $ID+1, 'Up', 0, true);
$ID = $ID+2;
$Text = substr($Text, 2);
}
else
{
$Area = GetArea(substr($Text, 1), '{', '}');
$Element0 = SelectFormula($ID+1, substr($Text, $Area[0]+1, $Area[1]), $Size*$Font['Zoom'], 0);
ConnectElement($Element0+1, $ID, $Element0, 'Pow', 0, $Size*$Font['Line'], $Sub);
$Text = substr($Text, $Area[0]*2+$Area[1]+1);
$ID = $Element0+1;
}
}
}
if (strlen($Text))
{
$Element0 = SelectFormula($ID+1, $Text, $Size, $Operation);
ConnectElement($Element0+1, $ID, $Element0, 'Right');
$ID = $Element0+1;
}
return $ID;
}
//===============================================
// Einlade und Konfigurieren
//=============================
putenv('GDFONTPATH='.realpath('Font'));
$Element = array();
if ($_GET['get'])
{
$Output = explode('@@', $_GET['get']);
if (strlen($Output[1])==6)
{
$OutputTemp = $Output[1];
$Output[1] = $Output[2];
$Output[2] = $OutputTemp;
}
$Text = stripslashes(strtr($Output[0],' *'."'",'+×'.chr(162)));
// Andere Symbole
$Text = str_replace('.inf.',chr(165),$Text);
$Text = str_replace('.del.',chr(182),$Text);
$Text = str_replace('.pro.',chr(181),$Text);
$Text = str_replace('.nab.',chr(209),$Text);
$Text = str_replace('.root.',chr(214),$Text);
$Text = str_replace('.int.',chr(242),$Text);
$Text = str_replace('.h.','h'.chr(96),$Text);
$Text = str_replace('.rec.',chr(133),$Text);
$Text = str_replace('.tab.',' ',$Text);
$Text = str_replace('.sp.',' ',$Text);
// Relationszeichen
$Text = str_replace('.id.',chr(186),$Text);
$Text = str_replace('.isnot.',chr(185),$Text);
$Text = str_replace('.rou.',chr(187),$Text);
$Text = str_replace('.isle.',chr(163),$Text);
$Text = str_replace('.isgr.',chr(179),$Text);
$Text = str_replace('.is.','=',$Text);
$Text = str_replace('.le.','<',$Text);
$Text = str_replace('.gr.','>',$Text);
// Operationszeichen
$Text = str_replace('+-',chr(177),$Text);
$Text = str_replace('-+',chr(178),$Text); $Text = str_replace('^'.chr(178),'^-+',$Text);
$Text = str_replace('.com.',chr(176),$Text);
$Text = str_replace('.x.',chr(180),$Text);
$Text = str_replace('.×.','*',$Text);
// Aussagenlogik
$Text = str_replace('.and.',chr(217),$Text);
$Text = str_replace('.or.',chr(218),$Text);
$Text = str_replace('.not.',chr(216),$Text);
$Text = str_replace('.all.','"',$Text);
$Text = str_replace('.ex.','$$',$Text);
// Pfeile
$Text = str_replace('.larr.',chr(172),$Text);
$Text = str_replace('.rarr.',chr(174),$Text);
$Text = str_replace('.harr.',chr(171),$Text);
$Text = str_replace('.lArr.',chr(220),$Text);
$Text = str_replace('.rArr.',chr(222),$Text);
$Text = str_replace('.hArr.',chr(219),$Text);
// Mengenlehre
$Text = str_replace('.uni.',chr(200),$Text);
$Text = str_replace('.cut.',chr(199),$Text);
$Text = str_replace('.lpart.',chr(204),$Text);
$Text = str_replace('.lPart.',chr(205),$Text);
$Text = str_replace('.rpart.',chr(201),$Text);
$Text = str_replace('.rPart.',chr(202),$Text);
$Text = str_replace('.el.',chr(206),$Text);
$Text = str_replace('.elnot.',chr(207),$Text);
$Text = str_replace('@all','"',$Text);
$Text = str_replace('@ex','$$',$Text);
$Text = str_replace('@inf',chr(165),$Text);
$Text = str_replace('@elnot',chr(207),$Text);
$Text = str_replace('@el',chr(206),$Text);
$Text = str_replace('@del',chr(182),$Text);
$Text = str_replace('@nab',chr(209),$Text);
$Text = str_replace('@larr',chr(172),$Text);
$Text = str_replace('@rarr',chr(174),$Text);
$Text = str_replace('@harr',chr(171),$Text);
$Text = str_replace('@lArr',chr(220),$Text);
$Text = str_replace('@rArr',chr(222),$Text);
$Text = str_replace('@hArr',chr(219),$Text);
$Text = str_replace('@and',chr(217),$Text);
$Text = str_replace('@or',chr(218),$Text);
$Text = str_replace('@not',chr(216),$Text);
$Text = str_replace('@uni',chr(200),$Text);
$Text = str_replace('@cut',chr(199),$Text);
$Text = str_replace('@lpart',chr(204),$Text);
$Text = str_replace('@lPart',chr(205),$Text);
$Text = str_replace('@rpart',chr(201),$Text);
$Text = str_replace('@rPart',chr(202),$Text);
$Text = str_replace('@isnot',chr(185),$Text);
$Text = str_replace('@rou',chr(187),$Text);
$Text = str_replace('@isle',chr(163),$Text);
$Text = str_replace('@isgr',chr(179),$Text);
$Text = str_replace('@is','=',$Text);
$Text = str_replace('@le','<',$Text);
$Text = str_replace('@gr','>',$Text);
$Font = array();
if ($Output[1])
$Font['Size'] = $Output[1];
else
$Font['Size'] = 13;
$Font['Text'] = 'text.ttf';
$Font['Variable'] = 'variable.ttf';
$Font['Symbol'] = 'symbol.ttf';
$Font['Menge'] = 'menge.ttf';
$Font['Script'] = 'script.ttf';
$Font['Vektor'] = 'vektor.ttf';
$Space = array();
$Space['Font'] = 1.0;
$Space['Right'] = 0.2;
$Space['Index'] = 2/3;
$Space['Pow'] = 1/3;
$Space['Up'] = 1/8;
$Space['Down'] = 1/6;
$Space['Break'] = 0.4;
$Space['Border'] = 0.15;
$Space['Line'] = 0.08;
$Font['Zoom'] = 0.7;
$MainElement = SelectFormula(1, $Text, $Font['Size']);
$Image = CreateElementImage($MainElement, $Output[2], $Debug);
header("Content-Type: image/png");
header("Expires: Sat, 4 Jul 2020 05:00:00 GMT");
header('Content-disposition: inline; filename="image.png"');
imagepng($Image);
}
?>