| 1 |
unit plottext; |
| 2 |
{$IFDEF FPC} |
| 3 |
{$MODE DELPHI}{$H+} |
| 4 |
{$ENDIF} |
| 5 |
(***************************************) |
| 6 |
(* Copyright (C) 2009, SHIRAISHI Kazuo *) |
| 7 |
(***************************************) |
| 8 |
|
| 9 |
|
| 10 |
interface |
| 11 |
var |
| 12 |
TextPhysicalCoordinate:boolean = false; |
| 13 |
|
| 14 |
|
| 15 |
implementation |
| 16 |
uses SysUtils,Classes, |
| 17 |
listcoll,base,base0,texthand,variabl,struct,express, print,format, |
| 18 |
affine,draw,graphic,helpctex{,using},graphsys,graphlib; |
| 19 |
|
| 20 |
type |
| 21 |
TSetTextJustify=class(TStatement) |
| 22 |
exp1:TPrincipal; |
| 23 |
exp2:TPrincipal; |
| 24 |
constructor create(prev,eld:TStatement); |
| 25 |
destructor destroy;override; |
| 26 |
//procedure exec;override; |
| 27 |
function code:ansistring;override; |
| 28 |
end; |
| 29 |
|
| 30 |
constructor TSetTextJustify.create(prev,eld:TStatement); |
| 31 |
begin |
| 32 |
inherited create(prev,eld); |
| 33 |
exp1:=SExpression; |
| 34 |
check(',',IDH_SET_TEXT_JUSTIFY); |
| 35 |
exp2:=SExpression; |
| 36 |
end; |
| 37 |
|
| 38 |
destructor TSetTextJustify.destroy; |
| 39 |
begin |
| 40 |
exp1.free; |
| 41 |
exp2.free; |
| 42 |
inherited destroy |
| 43 |
end; |
| 44 |
|
| 45 |
(* |
| 46 |
procedure TSetTextJustify.exec; |
| 47 |
var |
| 48 |
s1,s2:ansistring; |
| 49 |
begin |
| 50 |
s1:=exp1.evalS; |
| 51 |
s2:=exp2.evalS; |
| 52 |
|
| 53 |
s1:=ansiUpperCase(s1); |
| 54 |
s2:=ansiUpperCase(s2); |
| 55 |
|
| 56 |
SetTextJustify(s1,s2, insideOfWhen); |
| 57 |
|
| 58 |
end; |
| 59 |
*) |
| 60 |
function SetTextJustifyst(prev,eld:TStatement):TStatement;far; |
| 61 |
begin |
| 62 |
SetTextJustifyst:=TSetTextJustify.create(prev,eld) |
| 63 |
end; |
| 64 |
|
| 65 |
|
| 66 |
type |
| 67 |
TPlotText=class(TStatement) |
| 68 |
exp1,exp2,exp3:TPrincipal; |
| 69 |
image:TPrincipal; |
| 70 |
items:TListCollection; |
| 71 |
GraphStm:boolean; |
| 72 |
LabelStm:boolean; |
| 73 |
LettersStm:boolean; |
| 74 |
|
| 75 |
constructor create(prev,eld:TStatement); |
| 76 |
destructor destroy;override; |
| 77 |
//procedure exec;override; |
| 78 |
function Code:ansistring;override; |
| 79 |
private |
| 80 |
//function formatted:ansistring; |
| 81 |
end; |
| 82 |
|
| 83 |
|
| 84 |
function PlotTextst(prev,eld:TStatement):TStatement;far; |
| 85 |
begin |
| 86 |
PlotTextst:=TPlotText.create(prev,eld); |
| 87 |
end; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
constructor TPLotText.create(prev,eld:TStatement); //2011.3.5 |
| 92 |
begin |
| 93 |
inherited create(prev,eld); |
| 94 |
GraphStm:=(prevToken='GRAPH'); |
| 95 |
LabelStm:=(Token='LABEL'); |
| 96 |
LettersStm:=(Token='LETTERS') or TextPhysicalCoordinate and not LabelStm; |
| 97 |
gettoken; |
| 98 |
check(',',IDH_TEXT); |
| 99 |
check('AT',IDH_TEXT); |
| 100 |
exp1:=NEXpression; |
| 101 |
if (programunit.Arithmetic=PrecisionComplex) |
| 102 |
and ((token=':') or (token=',') and (nexttoken='USING') |
| 103 |
and not((nextnexttoken=',') or (nextnexttoken=':'))) then |
| 104 |
// ������������ |
| 105 |
else |
| 106 |
begin |
| 107 |
check(',',IDH_TEXT); |
| 108 |
exp2:=NExpression; |
| 109 |
end; |
| 110 |
if test(',') then |
| 111 |
begin |
| 112 |
CheckToken('USING',IDH_TEXT); |
| 113 |
image:=ImageRef; |
| 114 |
checkToken(':',IDH_PRINT_USING); |
| 115 |
items:=TListCollection.create; |
| 116 |
repeat |
| 117 |
items.insert(NSExpression); |
| 118 |
until test(',')=false; |
| 119 |
end |
| 120 |
else |
| 121 |
begin |
| 122 |
check(':',IDH_TEXT); |
| 123 |
exp3:=SExpression; |
| 124 |
end; |
| 125 |
end; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
destructor TPLotText.destroy; |
| 130 |
begin |
| 131 |
exp1.free; |
| 132 |
exp2.free; |
| 133 |
exp3.free; |
| 134 |
items.free; |
| 135 |
image.free; |
| 136 |
inherited destroy |
| 137 |
end; |
| 138 |
|
| 139 |
|
| 140 |
(* |
| 141 |
procedure TPlotText.exec; |
| 142 |
var |
| 143 |
n,m:extended; |
| 144 |
s:ansistring; |
| 145 |
begin |
| 146 |
with MyGraphSys do |
| 147 |
if BeamMode=bmRigorous then beam:=false; |
| 148 |
n:=exp1.evalX; |
| 149 |
m:=exp2.evalX; |
| 150 |
if exp3<>nil then |
| 151 |
s:=exp3.evalS |
| 152 |
else |
| 153 |
s:=Formatted; |
| 154 |
if GraphStm then |
| 155 |
MyGraphSys.puttext(n,m,s) |
| 156 |
else if currentTransform.transform(n,m) then |
| 157 |
if LabelStm then |
| 158 |
MyGraphSys.puttext(n,m,s) |
| 159 |
else |
| 160 |
MyGraphSys.Plottext(n,m,s) |
| 161 |
end; |
| 162 |
*) |
| 163 |
|
| 164 |
(* |
| 165 |
function TPlotText.formatted:ansistring; |
| 166 |
var |
| 167 |
form:ansistring; |
| 168 |
c,i,code:integer; |
| 169 |
begin |
| 170 |
result:=''; |
| 171 |
if image<>nil then |
| 172 |
form:=image.evalS; |
| 173 |
i:=1; |
| 174 |
result:=literals(form,i); |
| 175 |
c:=0; |
| 176 |
while (c<items.count) do |
| 177 |
begin |
| 178 |
result:=result + TPrincipal(items.items[c]).format(form,i,code); |
| 179 |
inc(c); |
| 180 |
result:=result +literals(form,i) |
| 181 |
end; |
| 182 |
end; |
| 183 |
*) |
| 184 |
|
| 185 |
function TPlotText.Code:ansistring; |
| 186 |
var |
| 187 |
c:integer; |
| 188 |
s:ansistring; |
| 189 |
begin |
| 190 |
if exp2<>nil then |
| 191 |
if exp3<>nil then |
| 192 |
begin |
| 193 |
if GraphStm then |
| 194 |
if LabelStm then |
| 195 |
result:='GraphLabel('+exp1.code+','+exp2.code+','+exp3.code+');' |
| 196 |
else |
| 197 |
result:='GraphText('+exp1.code+','+exp2.code+','+exp3.code+');' |
| 198 |
else |
| 199 |
if LabelStm then |
| 200 |
result:='PlotLabel('+exp1.code+','+exp2.code+','+exp3.code+');' |
| 201 |
else if LettersStm then |
| 202 |
result:='PlotLetters('+exp1.code+','+exp2.code+','+exp3.code+');' |
| 203 |
else |
| 204 |
result:='PlotText('+exp1.code+','+exp2.code+','+exp3.code+');' |
| 205 |
end |
| 206 |
else |
| 207 |
begin |
| 208 |
if GraphStm then |
| 209 |
if LabelStm then |
| 210 |
result:='GraphLabelUsing('+exp1.code+','+exp2.code+','+image.code +',[' |
| 211 |
else |
| 212 |
result:='GraphTextUsing('+exp1.code+','+exp2.code+','+image.code +',[' |
| 213 |
else |
| 214 |
if LabelStm then |
| 215 |
result:='PlotLabelUsing('+exp1.code+','+exp2.code+','+image.code +',[' |
| 216 |
else if LettersStm then |
| 217 |
result:='PlotLettersUsing('+exp1.code+','+exp2.code+','+image.code +',[' |
| 218 |
else |
| 219 |
result:='PlotTextUsing('+exp1.code+','+exp2.code+','+image.code +',['; |
| 220 |
|
| 221 |
for c:=0 to items.count-1 do |
| 222 |
begin |
| 223 |
if c>0 then result:=result+','; |
| 224 |
s:=TPrincipal(items.items[c]).code; |
| 225 |
if (TPrincipal(items.items[c]).kind='n') and (PUnit.Arithmetic=precisionComplex) then |
| 226 |
s:='testreal('+s+')'; |
| 227 |
result:=result+s; |
| 228 |
end; |
| 229 |
result:=result+']);' |
| 230 |
end |
| 231 |
else |
| 232 |
if exp3<>nil then |
| 233 |
begin |
| 234 |
if GraphStm then |
| 235 |
if LabelStm then |
| 236 |
result:='GraphLabelComplex('+exp1.code+','+exp3.code+');' |
| 237 |
else |
| 238 |
result:='GraphTextComplex('+exp1.code+','+exp3.code+');' |
| 239 |
else |
| 240 |
if LabelStm then |
| 241 |
result:='PlotLabelComplex('+exp1.code+','+exp3.code+');' |
| 242 |
else if LettersStm then |
| 243 |
result:='PlotLettersComplex('+exp1.code+','+exp3.code+');' |
| 244 |
else |
| 245 |
result:='PlotTextComplex('+exp1.code+','+exp3.code+');' |
| 246 |
end |
| 247 |
else |
| 248 |
begin |
| 249 |
if GraphStm then |
| 250 |
if LabelStm then |
| 251 |
result:='GraphLabelUsingComplex('+exp1.code+','+image.code +',[' |
| 252 |
else |
| 253 |
result:='GraphTextUsingComplex('+exp1.code+','+image.code +',[' |
| 254 |
else |
| 255 |
if LabelStm then |
| 256 |
result:='PlotLabelUsingComplex('+exp1.code+','+image.code +',[' |
| 257 |
else if LettersStm then |
| 258 |
result:='PlotLettersUsingComplex('+exp1.code+','+image.code +',[' |
| 259 |
else |
| 260 |
result:='PlotTextUsingComplex('+exp1.code+','+image.code +',['; |
| 261 |
|
| 262 |
for c:=0 to items.count-1 do |
| 263 |
begin |
| 264 |
if c>0 then result:=result+','; |
| 265 |
s:=TPrincipal(items.items[c]).code; |
| 266 |
if (TPrincipal(items.items[c]).kind='n') and (PUnit.Arithmetic=precisionComplex) then |
| 267 |
s:='testreal('+s+')'; |
| 268 |
result:=result+s; |
| 269 |
end; |
| 270 |
result:=result+']);' |
| 271 |
end |
| 272 |
end; |
| 273 |
|
| 274 |
|
| 275 |
function TSetTextJustify.code:ansistring; |
| 276 |
begin |
| 277 |
result:='SetTextJustify('+exp1.code+','+exp2.code+','+TruthLiteral(insideofwhen)+');' |
| 278 |
end; |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
begin |
| 283 |
graphic.settextjustifyst:=settextjustifyst; |
| 284 |
graphic.plottextst:=plottextst; |
| 285 |
end. |