Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;workarea:    <- RTF_work
2
;  listptr dd savelist    0
3
;  szKeyword rb 31        4
4
;  szParameter rb 21      35
5
 
6
include 'rtftype.inc'
7
include 'rtfactn.inc'
8
 
9
read_next_block:
10
  inc  [cur_block]
11
read_block:
12
  mov  esi,I_END
13
  pusha
14
  mov  ecx,[cur_block]
15
  mov  ebx,fileinfo
16
  mov  eax,ecx
17
  shl  eax,7
18
  mov  [ebx+4],eax
19
;  mov  [ebx+12],esi
20
  mcall 58
21
if DEBUG_BLOCK eq 1
22
;  dps  'B='
23
;  dpd  ecx
24
;  dps  <13,10>
25
end if
26
  cmp  ecx,[max_block]
27
  je   .last
28
  mov  ebx,I_END+RTFSIZE
29
  jmp  .add
30
.last:
31
  mov  ebx,[tail]
32
;  dpd  ebx
33
.add:
34
;  dpd  ebx
35
  mov  [block_end],ebx
36
  popa
37
;  dpd  esi
38
;  dps  <13,10>
39
  ret
40
;
41
; %%Function: ecRtfParse
42
;
43
; Step 1:
44
; Isolate RTF keywords and send them to ecParseRtfKeyword;
45
; Push and pop state at the start and end of RTF groups;
46
; Send text to ecParseChar for further processing.
47
;
48
macro CopySave _src,_dest
49
{
50
    pusha
51
    mov  ecx,SIZE_save
52
    mov  esi,_src
53
    mov  edi,_dest
54
    rep  movsb
55
    popa
56
}
57
 
58
RtfParse:
59
 
60
 if BENCH eq 1
61
    mcall 26,9
62
    mov  [bench],eax
63
 end if
64
    mov  [RetroPtr],esi
65
    CopySave Chp,RetroSave
66
    push dword[Free+4]
67
    pop  dword[RetroXY]
68
    xor  eax,eax
69
    mov  [cur_block],eax
70
    mov  [RetroBlock],eax
71
    push [cGroup]
72
    pop  [RetroGroup]
73
    and  [mode],not RTF_BLIND
74
    mov  [listptr],save_stack
75
    mov  [fileinfo.size],128
76
;    test ebp,RTF_HELP
77
    test [mode],RTF_HELP
78
    jne  .noread
79
    call read_block
80
  .noread:
81
    mov  [RetroPtr],esi
82
  .nib2:
83
    mov  [nibble],2
84
    and  [b],al
85
  .getc:
86
    xor  eax,eax
87
    lods_block
88
    cmp  [cGroup],0
89
    jge  .ok1
90
    Return ecStackUnderflow
91
  .ok1:
92
    cmp  [ris],risBin
93
    jne  .nobin
94
    RetError ecParseChar
95
  .nobin:
96
    cmp  al,'{'
97
    jne  .nobr1
98
    RetError ecPushRtfState
99
  .nobr1:
100
    cmp  al,'}'
101
    jne  .nobr2
102
    RetError ecPopRtfState
103
  .nobr2:
104
    cmp  al,'\'
105
    jne  .noslash
106
    RetError ecParseRtfKeyword
107
  .noslash:
108
    cmp  al,0xd
109
    je   .getc
110
    cmp  al,0xa
111
    je   .getc
112
  .nouc:
113
    cmp  [ris],risNorm
114
    jne  .nonorm
115
    call ecParseChar
116
    cmp  eax,ecOutOfWindow
117
    je   .__ex
118
    test eax,eax
119
    je   .getc
120
    jmp  .__ex
121
  .nonorm:
122
    cmp  [ris],risHex
123
    je   .noassert
124
    Return ecAssertion
125
  .noassert:
126
    shl  [b],4
127
    isdigit al, .nodig
128
    sub  al,'0'
129
    add  [b],al
130
    jmp  .nibble
131
  .nodig:
132
    islower al, .nolow
133
    cmp  al,'a'
134
    jb   .inval
135
    cmp  al,'f'
136
    ja   .inval
137
    sub  al,'a'-10
138
    jmp  .nib0
139
  .inval:
140
  if INVALHEX eq 0
141
    jmp  .getc
142
  else
143
;    sub  esi,I_END+1
144
;    dpd  esi
145
;    movzx eax,al
146
;    dpd  eax
147
;    movzx eax,[b]
148
;    dpd  eax
149
    Return ecInvalidHex
150
  end if
151
  .nolow:
152
    cmp  al,'A'
153
    jb   .inval
154
    cmp  al,'F'
155
    ja   .inval
156
    sub  al,'A'-10
157
  .nib0:
158
    add  [b],al
159
  .nibble:
160
    dec  [nibble]
161
    cmp  [nibble],0
162
    jnz  .getc
163
    movzx eax,[b]
164
    mov  [ris],risNorm
165
    call ecParseChar
166
    test eax,eax
167
    jnz  .__ex
168
;    mov  [ris],risNorm
169
    jmp  .nib2
170
  .eof:
171
    xor  eax,eax
172
    cmp  eax,[cGroup]
173
    je   .__ex
174
    jg   .unbr
175
    Return ecStackUnderflow
176
  .unbr:
177
    mov  eax,ecUnmatchedBrace
178
  .__ex:
179
    ret
180
nibble db 2
181
b      db 0
182
RTF_maxlist dd ?
183
;
184
; %%Function: ecParseRtfKeyword
185
;
186
; Step 2:
187
; get a control word (and its associated value) and
188
; call ecTranslateKeyword to dispatch the control.
189
;
190
 
191
ecParseRtfKeyword:
192
; ch-al,bl-fParam, bh-fNeg
193
    mov  [ris],risNorm
194
    xor  eax,eax
195
    xor  ebx,ebx
196
    push edx
197
    mov  [szKeyword],al
198
    mov  [szParameter],al
199
    lods_block
200
    isalpha al,.ctrl
201
    jmp  .alph
202
  .ctrl:
203
    push esi
204
    mov  esi,szKeyword
205
    inc  byte[esi]
206
    mov  [esi+1],al
207
    mov  eax,ebx
208
    xor  ebx,ebx
209
    call ecTranslateKeyword
210
    pop  esi
211
    jmp  .__ex
212
  .alph:
213
    push edi
214
    mov  edi,szKeyword+1
215
  .loop1:
216
    stosb
217
    inc  [szKeyword]
218
    lods_block
219
    isalpha al,.outloop1
220
    jmp  .loop1
221
  .outloop1:
222
    pop  edi
223
    cmp  al,'-'
224
    jne  .noneg
225
    not  bh
226
    lods_block
227
  .noneg:
228
    isdigit al,.nodig
229
    not  bl
230
    push edi
231
    mov  edi,szParameter+1
232
  .loop2:
233
    stosb
234
    inc  [szParameter]
235
    lods_block
236
    isdigit al,.outloop2
237
    jmp  .loop2
238
  .outloop2:
239
    pop  edi
240
    push eax esi
241
    mov  esi,szParameter
242
    atoi
243
    pop  esi
244
    mov  edx,eax
245
    pop  eax
246
    mov  [lParam],edx
247
    test bh,bh
248
    jz   .nodig
249
    neg  edx
250
  .nodig:
251
    cmp  al,' '
252
    je   .space
253
    cmp  esi,I_END
254
    jne  .ok_block
255
    dec  [cur_block]
256
    call read_block
257
    mov  esi,[block_end]
258
  .ok_block:
259
    dec  esi
260
  .space:
261
    mov eax,ebx
262
    mov ebx,edx
263
    push esi
264
    mov  esi,szKeyword
265
    call ecTranslateKeyword
266
    pop  esi
267
  .__ex:
268
    pop  edx
269
    ret
270
 
271
;
272
; %%Function: ecParseChar
273
;
274
; Route the character to the appropriate destination stream.
275
;
276
 
277
ecParseChar:
278
;in: ch-al, esi->rtf
279
   cmp  [ris],risBin
280
   jne  .nobin
281
   dec  [cbBin]
282
   cmp  [cbBin],0
283
   jg   .nobin
284
   mov  [ris],risNorm
285
 .nobin:
286
   cmp  [rds],rdsColor
287
   jne  .nodelim
288
   cmp  al,';'
289
   jne  .non
290
   mov  eax,[colorptr]
291
   cmp  eax,ct_end-4
292
   jae  .non
293
   add  [colorptr],4
294
   jmp  .non
295
 .nodelim:
296
   cmp  [rds],rdsSkip
297
   je  .non
298
   cmp  [rds],rdsNorm
299
   je   ecPrintChar
300
;   ret
301
 .non:
302
   mov  eax,ecOK
303
   ret
304
 
305
macro PrintTrap _char
306
{
307
local .notrap
308
    cmp  byte[esi],_char
309
    jne  .notrap
310
    sub  esi,I_END
311
    dps  'Trapped at '
312
    dpd  esi
313
    dps  <13,10>
314
    ud2
315
  .notrap:
316
}
317
;
318
; %%Function: ecPrintChar
319
;
320
; Send a character to the output file.
321
;
322
 
323
ecPrintChar:
324
; in:ch-al, esi - rtf pointer
325
;    stosb
326
;    jmp  .nowrap
327
    mov  ebp,[mode]
328
    cmp  al,0xa
329
    jne   .nopar
330
;    and  ebp,not RTF_NO1STLINE
331
    and  [mode],not RTF_NO1STLINE
332
    jmp  .par
333
  .nopar:
334
    cmp  al,0x9
335
    jne  .notab
336
    add  word[Free+6],CHARW*3
337
    jmp  .chkwrap
338
  .notab:
339
    xor  ebx,ebx
340
  if ~ RENDER eq FREE
341
    cmp  word[Free+4],TOP
342
    jl   .nodraw
343
  end if
344
    ansi2oem
345
    mov  [char],al
346
;    PrintTrap '/'
347
    pusha
348
    xor   eax,eax
349
;    test  [mode],RTF_BLIND
350
    test  ebp,RTF_BLIND
351
    je   .rend
352
;    test  [mode],RTF_COLORLESS
353
    test  ebp,RTF_COLORLESS
354
    jz    .setcolor
355
    mov   ecx,DEFCOLOR
356
    jmp   .rend
357
  .setcolor:
358
    movzx ecx,byte[Chp+3]
359
    mov   ecx,[colortbl+ecx*4]
360
  .rend:
361
  if RENDER eq FREE
362
    mov   ebx,Free
363
    mov   dword[ebx+32],eax
364
    mov   [ebx+28],ecx
365
;    test  [mode], RTF_BOTTOM
366
    test  ebp, RTF_BOTTOM
367
    jne   .nodraw2
368
    cmp  word[Free+4],TOP
369
    jl   .nodraw2
370
    cmp   byte[Chp],fTrue
371
    jne   .nobold
372
    or    dword[ebx+32],BGI_BOLD
373
  .nobold:
374
;    test  [mode], RTF_BLIND
375
    test  ebp, RTF_BLIND
376
    jne   .freet
377
  .nodraw2:
378
    or    dword[ebx+32],BGI_NODRAW
379
  .freet:
380
    BGIfont_Freetext
381
 
382
    mov  [Free+4],eax
383
    test [mode],RTF_BLIND
384
;    jmp  .nohei
385
    jne  .nohei
386
    fild word[BGIheight]
387
    fmul dword[Free+12]
388
;    fistp word[curheight]
389
    fistp word[maxheight]
390
;    movzx eax,[curheight]
391
;    dpd  eax
392
;    cmp  ax,[maxheight]
393
;    jae  .nohei
394
;    mov  [maxheight],ax
395
;    dps 'M'
396
;    dpd  eax
397
 
398
;    dps <13,10>
399
  .nohei:
400
  else
401
    and   ecx,0xffffff
402
    mov   ebx,[Free+4]
403
    mov   edx,char
404
    mov   esi,1
405
  end if
406
 
407
  if RENDER eq BGI
408
    add   ecx,0x44000000
409
    cmp   byte[Chp],fTrue
410
    jne   .nobold
411
    or    esi,BGI_BOLD
412
  .nobold:
413
    test  ebp,RTF_BLIND
414
;    test  [mode],RTF_BLIND
415
    jne    .freet
416
    or    esi,BGI_NODRAW
417
  .freet:
418
    BGIfont_Outtext
419
    mov   [Free+4],eax
420
  end if
421
 
422
  if RENDER eq PIX
423
;    test  [mode],RTF_TOEOF
424
;    jne   .blind
425
;    test  [mode],RTF_BOTTOM
426
    test  ebp,RTF_BOTTOM
427
    jne   .nobold
428
  .blind:
429
;    test  [mode],RTF_BLIND
430
    test  ebp,RTF_BLIND
431
    je    .nobold
432
    mcall 4
433
    cmp   byte[Chp],fTrue
434
    jne   .nobold
435
    add   ebx,1 shl 16
436
    mcall
437
  .nobold:
438
  end if
439
    popa
440
  .nodraw:
441
  if  RENDER eq PIX
442
    add  word[Free+6],CHARW
443
  end if
444
    movsx eax,[pitch]
445
    add  word[Free+6],ax
446
  .chkwrap:
447
    mov  eax,dword[prcinfo+42]
448
    cmp  ax,word[Free+6]
449
    ja   .nowrap
450
;    or   ebp,RTF_NO1STLINE
451
    or   [mode],RTF_NO1STLINE
452
  .par:
453
    xor  [mode],RTF_BLIND
454
;    not  [blind]
455
    test [mode] ,RTF_BLIND
456
    je   .makewrap
457
    ; [blind]=false
458
    movzx eax,word[Free+6]
459
    sub  ax,word[RetroXY+2]
460
    push dword[RetroXY]
461
    pop  dword[Free+4]
462
    mov  [mark],0xff0000
463
    test [mode],RTF_ALIGNLESS
464
    jnz  .letsdraw
465
    cmp  byte[Pap+12],justR
466
    jb   .letsdraw
467
    mov  [mark],0xff
468
    mov  ebx,dword[prcinfo+42] ; wnd width
469
    sub  ebx,eax
470
    cmp  byte[Pap+12],justC
471
    jne  .nocenter
472
    shr  ebx,1
473
    mov  [mark],0x00ff00
474
  .nocenter:
475
    mov  word[Free+6],bx
476
  .letsdraw:
477
;    test [mode],RTF_NO1STLINE
478
;    jnz  .no1st
479
;    add  word[Free+6],60
480
  .no1st:
481
  if STEPBYSTEP eq 1
482
;    movzx eax,[mode]
483
;    dph  eax
484
;    test [mode],RTF_NO1STLINE
485
;    jnz  .no1st
486
;    mcall 4,[RetroXY],[mark],sym,1
487
;    dps  '1st '
488
;  .no1st:
489
    dps  <'false ',13,10>
490
;    dpd  eax
491
;    dpd  ebx
492
  end if
493
  if SHOWALIGN eq 1
494
    mcall 4,[RetroXY],[mark],sym,1
495
  end if
496
  if STEPBYSTEP eq 1
497
    mcall 10
498
    mcall 2
499
  end if
500
    mov  eax,[RetroBlock]
501
    cmp  eax,[cur_block]
502
    je   .norblock
503
    mov  [cur_block],eax
504
    call read_block
505
  .norblock:
506
    mov  esi,[RetroPtr]
507
    push [RetroGroup]
508
    pop  [cGroup]
509
    CopySave RetroSave,Chp
510
    jmp  .nowrap
511
  .makewrap:       ; second pass preparing
512
    ; [blind]=true
513
  if STEPBYSTEP eq 1
514
    dps  'true '
515
    mcall 10
516
    mcall 2
517
  end if
518
    mov  word[Free+6],LMARGIN
519
  if RENDER eq FREE
520
    fld [line_space]
521
    fimul [maxheight]
522
    fistp [maxheight]
523
    movzx eax,[maxheight]
524
    add  word[Free+4],ax
525
;    and  [maxheight],0
526
;    add  word[Free+4],CHARH
527
  else
528
    mov  eax,CHARH
529
    add  word[Free+4],ax
530
  end if
531
    test [mode],RTF_TOEOF
532
    je   .nohdoc
533
    add  [HDoc],eax
534
    inc  [line_count]
535
  .nohdoc:
536
    test [mode],RTF_BOTTOM
537
    jne  .text
538
;    dps  '1'
539
    mov  ebx,dword[prcinfo+46]
540
    cmp  bx,word[Free+4]
541
    jge   .text
542
    or   [mode],RTF_BOTTOM
543
    dps  <'btm',13,10>
544
    test [mode],RTF_TOEOF
545
    jne  .text
546
    mov  eax,ecOutOfWindow
547
    ret
548
;  end if
549
  .text:
550
    push dword[Free+4]
551
    pop  dword[RetroXY]
552
    mov  word[RetroXY+2],LMARGIN
553
    mov  [RetroPtr],esi
554
    push [cur_block]
555
    pop  [RetroBlock]
556
    CopySave Chp,RetroSave
557
    push [cGroup]
558
    pop  [RetroGroup]
559
;  if STEPBYSTEP eq 1
560
;    mcall 10
561
;    mcall 2
562
;  end if
563
  .nowrap:
564
    mov  eax,ecOK
565
    ret
566
mark dd ?
567
sym db 0x10
568
line_space dd 1.6
569
;
570
; %%Function: ecPushRtfState
571
;
572
; Save relevant info on a linked list of SAVE structures.
573
;
574
 
575
ecPushRtfState:
576
    pusha
577
    mov  edi,[listptr]
578
    mov  eax,edi
579
    mov  ecx,SIZE_save
580
    add  eax,ecx
581
    cmp  eax,save_limit
582
    jb   .malloc
583
    Return ecStackOverflow
584
  .malloc:
585
    mov  esi,Chp
586
    rep  movsb
587
    mov  [listptr],edi
588
    mov  [ris],risNorm
589
    inc  [cGroup]
590
    xor  eax,eax
591
    Epilog
592
 
593
; %%Function: ecPopRtfState
594
;
595
; If we're ending a destination (that is, the destination is changing),
596
; call ecEndGroupAction.
597
; Always restore relevant info from the top of the SAVE list.
598
 
599
ecPopRtfState:
600
    pusha
601
    mov  esi,[listptr]
602
    cmp  esi,save_stack
603
    ja  .okpop
604
    Return ecStackUnderflow
605
  .okpop:
606
    movzx eax,[rds]
607
    cmp  al,[esi-2]
608
    je   .noega
609
    RetError ecEndGroupAction, .noega
610
  .noega:
611
    mov  ecx,SIZE_save
612
    sub  esi,ecx
613
    mov  [listptr],esi
614
    mov  edi,Chp
615
    rep  movsb
616
    dec  [cGroup]
617
    xor  eax,eax
618
    Epilog
619
 
620
ansitbl:
621
    db 0xaa,0xba,0xbf,0xaf
622
    db 0xa7,0xa8,0xa1,0xab,0xb0,0xb2,0xb3,0xb6,0xb7,0xb8,0xb9
623
    db 0xa2,0xbb,0x93,0x94,0x85
624
oematbl:
625
 if RENDER eq PIX
626
    db 0xf2,0xf3,0xf5,0xf4
627
 else
628
    db 0x85,0xa5,0x69,0x49
629
 end if
630
    db 0x15,0xf0,0xf6,0x22,0x1d,0x49,0x69,0x14,0x1c,0xf1,0x23
631
    db 0xf7,0x22,0x22,0x22,0x16
632
uctbl:
633
    dw 0x451
634
oemutbl:
635
    db 0xb8