File: pdfvrsintatico.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (628 lines) | stat: -rw-r--r-- 18,045 bytes parent folder | download | duplicates (12)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
unit pdfvrsintatico;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, pdfvrlexico;

type
  AnSintaticoPage = class
  public
    Estado: Int64;
    obj1,obj2 : String;
    pageFound: Boolean;
    constructor Create;
    procedure automata(t: Token);
  end;

  AnSintaticoPageContents = class
  public
    Estado: Int64;
    obj1,obj2 : String;
    len_obj1,len_obj2: String;
    contentsFound: Boolean;
    h: PageHeader;
    constructor Create;
    procedure automata(t: Token; Input: TStream);
  end;

  AnSintaticoCommand = class
  public
    Estado: Int64;
    Codigo: Boolean;
    c: Command;
    constructor Create;
    function automata(t: Token):Command;
  end;

  AnSintaticoLength = class
  public
    Estado: Int64;
    len_obj1,len_obj2: String;
    page_length : Int64;
    lenghtFound: Boolean;
    constructor Create;
    procedure automata(t: Token);
  end;

implementation

procedure AnSintaticoPage.automata(t: Token);
begin
  case Estado of
  1:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPage.automata Estado 1');
    {$endif}
             if(t.token_string = 'Type') then
                   begin
                       Estado := 2;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  2:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPage.automata Estado 2');
    {$endif}
             if(t.token_string = 'Page') then
                   begin
                        Estado := 3;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  3:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPage.automata Estado 3');
    {$endif}
             if(t.token_string = 'Contents') then
                   begin
                        Estado := 4;
                   end
             else
                   begin
                        Estado := 3;
                   end;
  end;
  4:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPage.automata Estado 4');
    {$endif}
             if(t.tipo = 1) then // numbers 1
                   begin
                        obj1:=t.token_string;
                        Estado := 5;
                   end
             else
                   begin
                        raise Exception.Create('ERROR: Arquivo corrompido.');
                        Halt(1);
                   end;
  end;
  5:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPage.automata Estado 5');
    {$endif}
             if(t.tipo = 1) then // numbers 2
                   begin
                        obj2:=t.token_string;
                        Estado := 6; // symbolic state
                        pageFound := true;
                   end
             else
                   begin
                        raise Exception.Create('ERROR: Arquivo corrompido.');
                        Halt(1);
                   end;
  end;
  else
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPage.automata Estado ELSE');
    {$endif}
    Estado := 1;
  end;
end;

procedure AnSintaticoPageContents.automata(t: Token; Input: TStream);
var
  myAnLexicoLength: AnLexico;
  myAnSintaticoLength: AnSintaticoLength;
  mytokenLength: Token;
begin
  case Estado of
  1:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPageContents.automata Estado 1');
    {$endif}
             if(t.token_string = obj1) then
                   begin
                        Estado := 2;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  2:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPageContents.automata Estado 2');
    {$endif}
             if(t.token_string = obj2) then
                   begin
                        Estado := 3;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  3:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPageContents.automata Estado 3');
    {$endif}
             if(t.token_string = 'obj') then
                   begin
                        Estado := 4;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  4:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPageContents.automata Estado 4');
    {$endif}
             if(t.token_string = 'Length') then
                   begin
                        Estado := 5;
                   end
             else if (t.token_string = 'Filter') then
                  begin
                       Estado := 7;
                  end
             else
                   begin
                        Estado := 4;
                   end;
  end;
  5:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPageContents.automata Estado 5');
    {$endif}
             if(t.tipo = 1) then
                   begin
                        h.page_length := StrToInt(t.token_string);
                        len_obj1:=t.token_string;
                        Estado := 6;
                   end
             else
                   begin
                        raise Exception.Create('ERROR: Arquivo corrompido.');
                        Halt(1);
                   end;
  end;
  6:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPageContents.automata Estado 6');
    {$endif}
             if(t.token_string = 'Filter') then
                   begin
                        Estado := 7;
                   end
             else if (t.token_string = 'stream') then
                  begin
                       contentsFound := true;
                       Estado := 9; // symbolic state
                  end
             else if (t.tipo = 1) then
                  begin
                      len_obj2:=t.token_string;
                      myAnLexicoLength := AnLexico.Create;
                      myAnLexicoLength.Doc := Input;
                      myAnLexicoLength.bytesRemaining:= myAnLexicoLength.Doc.Size;
                      myAnSintaticoLength := AnSintaticoLength.Create;

                      myAnSintaticoLength.len_obj1:=len_obj1;
                      myAnSintaticoLength.len_obj2:=len_obj2;

                      while ((myAnSintaticoLength.lenghtFound <> true) and
                            (myAnLexicoLength.bytesRemaining > 0)) do
                      begin
                           mytokenLength := myAnLexicoLength.getToken();
                           myAnSintaticoLength.automata(mytokenLength);
                      end;

                      if (myAnSintaticoLength.lenghtFound = false) then
                      begin
                           raise Exception.Create('ERROR: Arquivo corrompido.');
                           Halt(1);
                      end;

                      h.page_length:=myAnSintaticoLength.page_length;
                      myAnLexicoLength.Doc.Destroy;
                      Estado := 6;
                  end
             else
                   begin
                        Estado := 6;
                   end;
  end;
  7:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPageContents.automata Estado 7');
    {$endif}
             if(t.token_string = 'FlateDecode') then
                   begin
                        h.flate_decode := true;
                        Estado := 8;
                   end
             else
                   begin
                        raise Exception.Create('ERROR: Encodificacao nao suportada.');
                        Halt(1);
                   end;
  end;
  8:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPageContents.automata Estado 8');
    {$endif}
             if(t.token_string = 'stream') then
                   begin
                        contentsFound := true;
                        Estado := 9; // symbolic state
                   end
             else if (t.token_string = 'Length') then
                  begin
                       Estado := 5;
                  end
             else
                   begin
                        Estado := 8;
                   end;
  end;
  else
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoPageContents.automata Estado ELSE');
    {$endif}
    Estado := 1;
  end;
end;

procedure AnSintaticoLength.automata(t: Token);
begin
  case Estado of
  1:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoLength.automata Estado 1');
    {$endif}
             if(t.token_string = len_obj1) then
                   begin
                        Estado := 2;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  2:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoLength.automata Estado 2');
    {$endif}
             if(t.token_string = len_obj2) then
                   begin
                        Estado := 3;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  3:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoLength.automata Estado 3');
    {$endif}
             if(t.token_string = 'obj') then
                   begin
                        Estado := 4;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  4:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoLength.automata Estado 4 Length: ', StrToInt(t.token_string));
    {$endif}
             if(t.tipo = 1) then
                   begin
                        page_length:=StrToInt(t.token_string);
                        lenghtFound:=true;
                        Estado := 5; // symbolic state
                   end
             else
                   begin
                        raise Exception.Create('ERROR: Arquivo corrompido.');
                        Halt(1);
                   end;
  end;
  else
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoLength.automata Estado ELSE');
    {$endif}
    Estado := 1;
  end;
end;

function AnSintaticoCommand.automata(t: Token):Command;
begin
  c.cord_x3 := c.cord_y3;
  c.cord_y3 := c.cord_x2;
  c.cord_x2 := c.cord_y2;
  c.cord_y2 := c.cord_x;
  c.cord_x := c.cord_y;
  c.cord_y := c.my_operator;
  c.my_operator := t.token_string;
  c.code := cc_NONE;

  Codigo := false;

  case Estado of
  1:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoCommand.automata Estado 1');
    {$endif}
             if(t.tipo = 1) then // numbers 1
                   begin
                       Estado := 2;
                   end
             else if( t.token_string = 'h' ) then  // command h
                  begin
                        Estado := 9; // symbolic state
                        Estado := 1;
                        Codigo := true;
                        c.code:=cc_H_CLOSE_PATH;
                        Result:=c;
                  end
             else if( t.token_string = 's' ) then // command s
                  begin
                        Estado := 10; // symbolic state
                        Estado := 1;
                        Codigo := true;
                        c.code:=cc_hS_CLOSE_AND_END_PATH;
                        Result:=c;
                  end
             else if( t.token_string = 'S' ) then // command S
                  begin
                        Estado := 11; // symbolic state
                        Estado := 1;
                        Codigo := true;
                        c.code:=cc_S_END_PATH;
                        Result:=c;
                  end
             else if( t.token_string = 'Q' ) then // command Q
                  begin
                       Estado := 21; // symbolic state
                       Estado := 1;
                       Codigo := true;
                       c.code:=cc_RESTORE_MATRIX;
                       Result:=c;
                  end
             else if ((t.token_string = 'f') or (t.token_string = 'F')
                  or (t.token_string = 'f*') or (t.token_string = 'B')
                  or (t.token_string = 'B*') or (t.token_string = 'b')
                  or (t.token_string = 'b*') or (t.token_string = 'n')) then
                  begin
                      Estado := 12; // symbolic state
                      Estado := 1;
                      Codigo := true;
                      c.code:=cc_hS_CLOSE_AND_END_PATH; // ignore painting..
                      Result:=c;
                      //raise Exception.Create('ERROR: Prenchimento nao eh suportado.');
                      //Halt(1);
                  end
             else if ((t.token_string = 'W') or (t.token_string = 'W*')) then
                  begin
                      Estado := 13; // symbolic state
                      raise Exception.Create('ERROR: Clipping nao eh suportado.');
                      Halt(1);
                  end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  2:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoCommand.automata Estado 2');
    {$endif}
             if(t.tipo = 1) then // numbers 2
                   begin
                        Estado := 3;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  3:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoCommand.automata Estado 3');
    {$endif}
             if(t.tipo = 1) then // numbers 3
                  begin
                       Estado := 5;
                  end
             else if(t.token_string = 'l') then // command l
                  begin
                       Estado := 14; // symbolic state
                       Estado := 1;
                       c.code:=cc_l_ADD_LINE_TO_PATH;
                       Codigo := true;
                       Result:=c;
                  end
             else if(t.token_string = 'm') then  // command m
                  begin
                       Estado := 15; // symbolic state
                       Estado := 1;
                       c.code:=cc_m_START_PATH;
                       Codigo := true;
                       Result:=c;
                  end
             else
                  begin
                       Estado := 1;
                  end;
  end;
  5:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoCommand.automata Estado 5');
    {$endif}
             if(t.tipo = 1) then // numbers 4
                   begin
                       Estado := 6;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  6:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoCommand.automata Estado 6');
    {$endif}
             if(t.tipo = 1) then // numbers 5
                   begin
                       Estado := 7;
                   end
             else if( t.token_string = 'v' ) then // command v
                  begin
                       Estado := 16; // symbolic state
                       raise Exception.Create('ERROR: Curva de bezier nao eh suportada.');
                       Halt(1);
                  end
             else if( t.token_string = 'y' ) then // command y
                  begin
                       Estado := 17; // symbolic state
                       raise Exception.Create('ERROR: Curva de bezier nao eh suportada.');
                       Halt(1);
                  end
             else if( t.token_string = 're' ) then // command re
                  begin
                       Estado := 18; // symbolic state
                       raise Exception.Create('ERROR: Comando nao suportado.');
                       Halt(1);
                  end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  7:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoCommand.automata Estado 7');
    {$endif}
             if(t.tipo = 1) then // numbers 6
                   begin
                       Estado := 8;
                   end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  8:
  begin
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoCommand.automata Estado 8');
    {$endif}
             if(t.token_string = 'c') then // commmand c
                   begin
                       Estado := 19; // symbolic state
                       Estado := 1;
                       c.code:=cc_c_BEZIER_TO_X_Y_USING_X2_Y2_AND_X3_Y3;
                       Codigo := true;
                       Result:=c;
                   end
             else if( t.token_string = 'cm' ) then // command cm
                  begin
                       Estado := 20; // symbolic state
                       Estado := 1;
                       c.code:=cc_CONCATENATE_MATRIX;
                       Codigo := true;
                       Result:=c;
                  end
             else
                   begin
                        Estado := 1;
                   end;
  end;
  else
    {$ifdef FPVECTORIALDEBUG}
    WriteLn(':> AnSintaticoCommand.automata Estado ELSE');
    {$endif}
    Estado := 1;
  end;
end;

constructor AnSintaticoCommand.Create;
begin
  inherited Create;
  Estado := 1;
end;

constructor AnSintaticoPage.Create;
begin
  inherited Create;
  Estado := 1;
  pageFound := false;
end;

constructor AnSintaticoPageContents.Create;
begin
  inherited Create;
  Estado := 1;
  contentsFound := false;
  h.flate_decode := false;
end;

constructor AnSintaticoLength.Create;
begin
  inherited Create;
  Estado := 1;
  lenghtFound := false;
end;

end.