File: pdfvrlexico.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 (113 lines) | stat: -rw-r--r-- 2,867 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
unit pdfvrlexico;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;

type
  Token = record
    tipo: Int64;
    token_string: String;
  end;

    TPDFCommandCode = (cc_NONE, cc_m_START_PATH, cc_l_ADD_LINE_TO_PATH,
     cc_H_CLOSE_PATH, cc_S_END_PATH, cc_hS_CLOSE_AND_END_PATH,
     cc_c_BEZIER_TO_X_Y_USING_X2_Y2_AND_X3_Y3,
     cc_v_BEZIER_TO_X_Y_USING_CURRENT_POS_AND_X2_Y2,
     cc_y_BEZIER_TO_X_Y_USING_X_Y_AND_X2_Y2,
     cc_CONCATENATE_MATRIX,cc_RESTORE_MATRIX);

    Command = record
            cord_x3: String;
            cord_y3: String;
            cord_x2: String;
            cord_y2: String;
            cord_x: String;
            cord_y: String;
            my_operator: String;
            code: TPDFCommandCode;
    end;

    PageHeader = record
            page_length: Int64;
            flate_decode: Boolean;
    end;

  AnLexico = class
  public
    Doc: TStream;
    bytesRemaining: Int64;
    constructor Create();
    function getToken(): Token;
    function getPageToken(): Token;
  end;

implementation

function AnLexico.getToken(): Token;
var
  t: Byte;
  mytoken: Token;
begin
    mytoken.tipo := 0;
    while( bytesRemaining > 0 ) do
    begin
         t := Doc.ReadByte();
         bytesRemaining := bytesRemaining - 1;
         // numbers or points or minus
         if((((t >= 48) and (t <= 57)) or (t = 46 ) or (t = 45)) and
           ((mytoken.tipo = 1) or (mytoken.tipo = 0))) then
             begin
                  mytoken.token_string := mytoken.token_string + char(t);
                  mytoken.tipo:=1;
             end
         else if(((t >= 65) and (t <= 90)) or ((t >= 97) and (t <= 122)) // letters
                   or (t = 42) // *
                   and ((mytoken.tipo = 2) or (mytoken.tipo = 0))) then
              begin
                   mytoken.token_string := mytoken.token_string + char(t);
                   mytoken.tipo:=2;
              end
         else // everything else
              begin
                   if (mytoken.tipo <> 0) then
                   begin
                        // solve CorelDraw problem after "stream"
                        if ((t=13) and (bytesRemaining>0)) then
                        begin
                             t := Doc.ReadByte();
                             bytesRemaining:=bytesRemaining-1;
                        end;
                        Result := mytoken;
                        Exit;
                   end;
              end;
  end;
  Result := mytoken;
end;

function AnLexico.getPageToken(): Token;
var
  t: Byte;
  mytoken: Token;
begin
     mytoken.tipo := 0;
     if (bytesRemaining > 0) then
     begin
         t := Doc.ReadByte;
         mytoken.token_string:=char(t);
         bytesRemaining := bytesRemaining - 1;
     end;
     Result := mytoken;
end;

constructor AnLexico.Create();
begin
  inherited Create;
end;

end.