-
Notifications
You must be signed in to change notification settings - Fork 7
/
RTFImporting.pck.st
2559 lines (1981 loc) · 81 KB
/
RTFImporting.pck.st
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
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'From Cuis 6.0 [latest update: #6025] on 12 September 2023 at 5:08:08 pm'!
'Description Please enter a description for this package.'!
!provides: 'RTFImporting' 1 7!
!requires: 'ExtendedClipboard' 1 nil nil!
!requires: 'Graphics-Files-Additional' 1 nil nil!
SystemOrganization addCategory: #RTFimporting!
!classDefinition: #RTFException category: #RTFimporting!
Error subclass: #RTFException
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFException class' category: #RTFimporting!
RTFException class
instanceVariableNames: ''!
!classDefinition: #RTFChunkScanner category: #RTFimporting!
Object subclass: #RTFChunkScanner
instanceVariableNames: 'destX lastIndex xTable rightEdge stopConditions prevIndex bufferStream buffer chunk'
classVariableNames: 'BufferStream ScannerTable XTable'
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFChunkScanner class' category: #RTFimporting!
RTFChunkScanner class
instanceVariableNames: ''!
!classDefinition: #RTFColorDef category: #RTFimporting!
Object subclass: #RTFColorDef
instanceVariableNames: 'red green blue'
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFColorDef class' category: #RTFimporting!
RTFColorDef class
instanceVariableNames: ''!
!classDefinition: #RTFFontInfo category: #RTFimporting!
Object subclass: #RTFFontInfo
instanceVariableNames: 'name num family charset cpg'
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFFontInfo class' category: #RTFimporting!
RTFFontInfo class
instanceVariableNames: ''!
!classDefinition: #RTFParser category: #RTFimporting!
Object subclass: #RTFParser
instanceVariableNames: 'tokenizer state builder'
classVariableNames: 'HandleMessages'
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFParser class' category: #RTFimporting!
RTFParser class
instanceVariableNames: ''!
!classDefinition: #RTFParserDestination category: #RTFimporting!
Object subclass: #RTFParserDestination
instanceVariableNames: 'block type'
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFParserDestination class' category: #RTFimporting!
RTFParserDestination class
instanceVariableNames: ''!
!classDefinition: #RTFParserState category: #RTFimporting!
Object subclass: #RTFParserState
instanceVariableNames: 'stack destination context'
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFParserState class' category: #RTFimporting!
RTFParserState class
instanceVariableNames: ''!
!classDefinition: #RTFStylesheet category: #RTFimporting!
Object subclass: #RTFStylesheet
instanceVariableNames: 'additive name type num style basedon'
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFStylesheet class' category: #RTFimporting!
RTFStylesheet class
instanceVariableNames: ''!
!classDefinition: #RTFSophieStylesheet category: #RTFimporting!
RTFStylesheet subclass: #RTFSophieStylesheet
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFSophieStylesheet class' category: #RTFimporting!
RTFSophieStylesheet class
instanceVariableNames: ''!
!classDefinition: #RTFTextBuilder category: #RTFimporting!
Object subclass: #RTFTextBuilder
instanceVariableNames: 'textConverter colorTable fontTable styleTable skipNextCharacters defaultSkipNextCharacters textStream currentFgColor fontFamilyName fontPointSize bold italic underline align stateStack firstIndent leftIndent rightIndent spaceBefore spaceAfter'
classVariableNames: 'CodePageConverterTable'
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFTextBuilder class' category: #RTFimporting!
RTFTextBuilder class
instanceVariableNames: ''!
!classDefinition: #RTFTextConverter category: #RTFimporting!
Object subclass: #RTFTextConverter
instanceVariableNames: 'acceptingEncodings'
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFTextConverter class' category: #RTFimporting!
RTFTextConverter class
instanceVariableNames: ''!
!classDefinition: #RTFLatin1TextConverter category: #RTFimporting!
RTFTextConverter subclass: #RTFLatin1TextConverter
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFLatin1TextConverter class' category: #RTFimporting!
RTFLatin1TextConverter class
instanceVariableNames: ''!
!classDefinition: #RTFMappingUnicodeTextConverter category: #RTFimporting!
RTFTextConverter subclass: #RTFMappingUnicodeTextConverter
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFMappingUnicodeTextConverter class' category: #RTFimporting!
RTFMappingUnicodeTextConverter class
instanceVariableNames: ''!
!classDefinition: #RTFCP1250UnicodeTextConverter category: #RTFimporting!
RTFMappingUnicodeTextConverter subclass: #RTFCP1250UnicodeTextConverter
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFCP1250UnicodeTextConverter class' category: #RTFimporting!
RTFCP1250UnicodeTextConverter class
instanceVariableNames: ''!
!classDefinition: #RTFCP1251UnicodeTextConverter category: #RTFimporting!
RTFMappingUnicodeTextConverter subclass: #RTFCP1251UnicodeTextConverter
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFCP1251UnicodeTextConverter class' category: #RTFimporting!
RTFCP1251UnicodeTextConverter class
instanceVariableNames: ''!
!classDefinition: #RTFCP1252UnicodeTextConverter category: #RTFimporting!
RTFMappingUnicodeTextConverter subclass: #RTFCP1252UnicodeTextConverter
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFCP1252UnicodeTextConverter class' category: #RTFimporting!
RTFCP1252UnicodeTextConverter class
instanceVariableNames: ''!
!classDefinition: #RTFMacRomanUnicodeTextConverter category: #RTFimporting!
RTFMappingUnicodeTextConverter subclass: #RTFMacRomanUnicodeTextConverter
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFMacRomanUnicodeTextConverter class' category: #RTFimporting!
RTFMacRomanUnicodeTextConverter class
instanceVariableNames: ''!
!classDefinition: #RTFToken category: #RTFimporting!
Object subclass: #RTFToken
instanceVariableNames: 'type content arg'
classVariableNames: 'DefaultArgs'
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFToken class' category: #RTFimporting!
RTFToken class
instanceVariableNames: ''!
!classDefinition: #RTFTokenizer category: #RTFimporting!
Object subclass: #RTFTokenizer
instanceVariableNames: 'stream buffer chunkBuffer last next afterNext afterAfter'
classVariableNames: 'ControlSymbolSet EndOfKeywordSet'
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFTokenizer class' category: #RTFimporting!
RTFTokenizer class
instanceVariableNames: ''!
!classDefinition: #RTFUnicode category: #RTFimporting!
Object subclass: #RTFUnicode
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'RTFimporting'!
!classDefinition: 'RTFUnicode class' category: #RTFimporting!
RTFUnicode class
instanceVariableNames: ''!
!RTFColorDef commentStamp: '<historical>' prior: 0!
Carries color information for the color table!
!RTFFontInfo commentStamp: '<historical>' prior: 0!
Carries RTF font information to be passed to a builder!
!RTFParser commentStamp: '<historical>' prior: 0!
An RTF parser!
!RTFParserState commentStamp: '<historical>' prior: 0!
A state of the RTF parser contains:
- a destination block (to send plain text to)
- a context (a currently built object for the builder, e.g. RTFFontInfo)
The state has abilities for saving and restoring states on a stack!
!RTFStylesheet commentStamp: '<historical>' prior: 0!
Carries information about RTF styles!
!RTFSophieStylesheet commentStamp: '<historical>' prior: 0!
Adds style applying functionality to stylesheets!
!RTFTextBuilder commentStamp: '<historical>' prior: 0!
To do:
- Ensure consistency between rtf export and import
- write tests for that consistency
- integrate with StyledTextBuilder (el parser der rtf seria un transcodificador???)!!
(el builder es solo para StyledText... Yo quisiera que esto sea mas general!!)!
!RTFTextConverter commentStamp: '<historical>' prior: 0!
The abstract class for all different type of text converters. nextFromStream: and nextPut:toStream: are the public accessible methods. If you are going to make a subclass for a stateful text conversion, you should override restoreStateOf:with: and saveStateOf: along the line of CompoundTextConverter.
!
!RTFLatin1TextConverter commentStamp: '<historical>' prior: 0!
Text converter for ISO 8859-1. An international encoding used in Western Europe.!
!RTFMappingUnicodeTextConverter commentStamp: '<historical>' prior: 0!
Base class for Unicode converters based on mappings as defined in
http://www.unicode.org/Public/MAPPINGS/!
!RTFCP1250UnicodeTextConverter commentStamp: '<historical>' prior: 0!
CP1250 to Unicode converter based on
http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT!
!RTFCP1251UnicodeTextConverter commentStamp: '<historical>' prior: 0!
CP1251 to Unicode converter based on
http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT!
!RTFCP1252UnicodeTextConverter commentStamp: '<historical>' prior: 0!
CP1251 to Unicode converter based on
http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT!
!RTFMacRomanUnicodeTextConverter commentStamp: '<historical>' prior: 0!
True MacRoman to Unicode converter based on
http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/ROMAN.TXT!
!RTFToken commentStamp: '<historical>' prior: 0!
token types:
#blockOpen - '{'
#blockClose - '}'
#keyword - e.g. '\alabala'
#string - e.g. 'alabala'
content stores keyword or string
arg stores keyword argument
if any field unapplicable for type, it returns nil
DafaultArgs: All keywords have argument value. Default keyowrd parameters is defined in DefaultArgs. If no default argument is fount, the default is assumed 0. !
!RTFTokenizer commentStamp: '<historical>' prior: 0!
Because of getAfterNext, don't expect the stream of this token to behave as expected. Two tokens ahead are actually read from the stream
At initialization last is nil. Must getToken to get first
newline is a Mac-hack. No newlines are expected in a RTF, but Mac makes escaped newlines!
!RTFUnicode commentStamp: '<historical>' prior: 0!
Not a real Unicode implementation. Just compatibility for Sophie-RTF. Answers instances of Character (i.e. ISO-8859-15).
Based on http://www.unicode.org/Public/MAPPINGS/ISO8859/8859-15.TXT!
!RTFChunkScanner methodsFor: 'private' stamp: 'mir 8/14/2006 16:25'!
addScannedString
| scannedString |
scannedString := ''.
prevIndex < lastIndex
ifTrue: [scannedString := chunk copyFrom: prevIndex to: lastIndex-1].
self bufferStream isEmpty
ifFalse: [
self bufferStream nextPutAll: scannedString.
scannedString := self bufferStream contents.
self bufferStream reset].
scannedString isEmpty
ifFalse: [buffer add: (RTFToken newString: scannedString)]
! !
!RTFChunkScanner methodsFor: 'private' stamp: 'mir 8/12/2006 15:51'!
addScannedStringToBuffer
prevIndex < lastIndex
ifFalse: [^self].
self bufferStream nextPutAll: (chunk copyFrom: prevIndex to: lastIndex-1)! !
!RTFChunkScanner methodsFor: 'private' stamp: 'mir 8/12/2006 14:59'!
bufferStream
^BufferStream! !
!RTFChunkScanner methodsFor: 'private' stamp: 'jmv 9/5/2016 20:31:48'!
scanCharactersFrom: startIndex to: stopIndex in: sourceString rightX: rightX stopConditions: stops kern: kernDelta
"Primitive. This is the inner loop of text display--but see
scanCharactersFrom: to:rightX: which would get the string,
stopConditions and displaying from the instance. March through source
String from startIndex to stopIndex. If any character is flagged with a
non-nil entry in stops, then return the corresponding value. Determine
width of each character from xTable, indexed by map.
If dextX would exceed rightX, then return stops at: 258.
Advance destX by the width of the character. If stopIndex has been
reached, then return stops at: 257. Optional.
See Object documentation whatIsAPrimitive."
| ascii char |
<primitive: 103>
lastIndex _ startIndex.
[lastIndex <= stopIndex]
whileTrue:
[char _ (sourceString at: lastIndex).
ascii _ char numericValue + 1.
(stops at: ascii) == nil ifFalse: [^stops at: ascii].
lastIndex _ lastIndex + 1].
lastIndex _ stopIndex.
^stops at: CharacterScanner endOfRunCode! !
!RTFChunkScanner methodsFor: 'private' stamp: 'mir 8/12/2006 15:16'!
scanFrom: startIndex to: stopIndex
| stopCondition |
stopCondition := self scanCharactersFrom: startIndex to: stopIndex in: chunk rightX: SmallInteger maxVal stopConditions: stopConditions kern: 0.
stopCondition
ifNil: [^nil]
ifNotNil: [stopCondition == #scanFinished
ifTrue: [^nil]
ifFalse: [self perform: stopCondition with: lastIndex]]! !
!RTFChunkScanner methodsFor: 'private' stamp: 'mir 8/14/2006 16:32'!
scanStartingAt: index
| chunkSize |
self bufferStream reset.
stopConditions := ScannerTable.
xTable := XTable.
destX := 0.
lastIndex := index.
prevIndex := index.
rightEdge := SmallInteger maxVal.
chunkSize := chunk size.
[(self scanFrom: lastIndex to: chunkSize) isNil]
whileFalse.
prevIndex <= lastIndex
ifTrue: [lastIndex := lastIndex + 1].
self addScannedString! !
!RTFChunkScanner methodsFor: 'stop conditions' stamp: 'mir 8/12/2006 15:44'!
blockCloseAt: index
self addScannedString.
buffer add: (RTFToken newBlockClose).
lastIndex := lastIndex + 1.
prevIndex := lastIndex! !
!RTFChunkScanner methodsFor: 'stop conditions' stamp: 'mir 8/12/2006 15:44'!
blockOpenAt: index
self addScannedString.
buffer add: (RTFToken newBlockOpen).
lastIndex := lastIndex + 1.
prevIndex := lastIndex! !
!RTFChunkScanner methodsFor: 'stop conditions' stamp: 'mir 8/12/2006 15:46'!
crAt: index
self addScannedStringToBuffer.
lastIndex := lastIndex + 1.
prevIndex := lastIndex! !
!RTFChunkScanner methodsFor: 'stop conditions' stamp: 'mir 8/12/2006 15:50'!
lfAt: index
self addScannedStringToBuffer.
lastIndex := lastIndex + 1.
prevIndex := lastIndex! !
!RTFChunkScanner methodsFor: 'initialization' stamp: 'mir 8/12/2006 16:05'!
scan: chunkString into: aBuffer startingAt: index
chunk := chunkString.
buffer := aBuffer.
self scanStartingAt: index! !
!RTFChunkScanner class methodsFor: 'class initialization' stamp: 'jmv 9/5/2016 20:31:57'!
initialize
"RTFChunkScanner initialize"
BufferStream := (String new: 4096) writeStream.
XTable := Array new: 258 withAll: 0.
ScannerTable := Array new: 258.
ScannerTable atAllPut: nil.
ScannerTable at: CharacterScanner endOfRunCode put: #scanFinished.
ScannerTable at: CharacterScanner crossedXCode put: #scanFinished.
ScannerTable at: ${ numericValue + 1 put: #blockOpenAt:.
ScannerTable at: $} numericValue + 1 put: #blockCloseAt:.
ScannerTable at: Character lfCharacter numericValue + 1 put: #lfAt:.
ScannerTable at: Character crCharacter numericValue + 1 put: #crAt:.
! !
!RTFChunkScanner class methodsFor: 'instance creation' stamp: 'mir 8/12/2006 16:04'!
scan: chunk into: buffer startingAt: index
^self new scan: chunk into: buffer startingAt: index! !
!RTFColorDef methodsFor: 'accessing' stamp: 'tat 5/5/2006 13:49'!
blue
^blue! !
!RTFColorDef methodsFor: 'accessing' stamp: 'tat 5/5/2006 13:49'!
blue: b
blue := b! !
!RTFColorDef methodsFor: 'accessing' stamp: 'tat 5/5/2006 13:48'!
green
^green! !
!RTFColorDef methodsFor: 'accessing' stamp: 'tat 5/5/2006 13:48'!
green: g
green := g! !
!RTFColorDef methodsFor: 'accessing' stamp: 'tat 5/5/2006 13:48'!
red
^red! !
!RTFColorDef methodsFor: 'accessing' stamp: 'tat 5/5/2006 13:48'!
red: r
red := r! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/5/2006 01:40'!
charset
^charset! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/5/2006 01:40'!
charset: c
charset := c! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/5/2006 01:44'!
cpg
^cpg! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/5/2006 01:44'!
cpg: n
cpg := n! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/5/2006 01:31'!
family
^family! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/5/2006 01:31'!
family: f
family := f! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/3/2006 02:21'!
name
^name! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/3/2006 02:21'!
name: fn
name := fn! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/3/2006 02:22'!
num
^num! !
!RTFFontInfo methodsFor: 'accessing' stamp: 'tat 5/3/2006 02:22'!
num: n
num := n! !
!RTFParser methodsFor: 'handlers' stamp: 'tat 11/1/2006 15:00'!
addContents
"assuming that the next RTF token is a string - add the string to the content tree
using current style settings"
|token|
"self break."
token := tokenizer getToken.
state destination value: (token string)
! !
!RTFParser methodsFor: 'handlers' stamp: 'tat 11/1/2006 15:09'!
handledatafield: token
state destination block: [:string|] type: #ignore.
self parseUntilBlockClose.! !
!RTFParser methodsFor: 'handlers' stamp: 'tat 11/1/2006 15:09'!
handlefield: token
|linkUri linkAlt|
linkUri := nil.
linkAlt := ''.
state destination block:
[:string | linkUri isNil ifTrue:
[(string findString: 'HYPERLINK') > 0 ifTrue:
[linkUri := self getAddress: string]]
ifFalse:
[linkAlt := linkAlt , string]
] type: #field.
self parseUntilBlockClose.
linkAlt isNil not ifTrue: [builder buildAddURI: linkUri alternate: linkAlt].
! !
!RTFParser methodsFor: 'handlers' stamp: 'kalin 6/24/2006 17:17'!
handlefldinst: token
! !
!RTFParser methodsFor: 'handlers' stamp: 'tat 5/5/2006 00:30'!
handleinfo: token
self handlerSupressText! !
!RTFParser methodsFor: 'handlers' stamp: 'tat 5/2/2006 02:04'!
handlepntxtb: token
self handlepntxta: token! !
!RTFParser methodsFor: 'handlers' stamp: 'kalin 5/3/2006 11:16'!
handlesectd: token
builder buildResetSectionSettings! !
!RTFParser methodsFor: 'utilities' stamp: 'mir 8/12/2006 16:56'!
createHandleMessage: token
"builds a handle message from a keyword token"
^HandleMessages at: token word ifAbsent: [('handle' , token word , ':') asSymbol]! !
!RTFParser methodsFor: 'utilities' stamp: 'jmv 9/5/2016 20:32:13'!
digitValue: char
| value |
value _ char numericValue.
value <= $9 numericValue
ifTrue: [^value - $0 numericValue].
value >= $a numericValue
ifTrue: [value <= $z numericValue ifTrue: [^value - $a numericValue + 10]].
value >= $A numericValue
ifTrue: [value <= $Z numericValue ifTrue: [^value - $A numericValue + 10]].
! !
!RTFParser methodsFor: 'utilities' stamp: 'tat 5/3/2006 02:18'!
emptyToken
^tokenizer tokenClass emptyToken
! !
!RTFParser methodsFor: 'utilities' stamp: 'jmv 4/4/2011 16:26'!
getAddress: string
"expects a string of the type
HYPERLINK<whitespaces>('|dblquot)<some link text>('|dblquot)
and answers the link text"
|count countEnd first last |
"self break."
"skip the HYPERLINK part"
count := 10.
[(((string at: count) = $') or: [(string at: count) = $"]) or: [count >= (string size)]] whileFalse:
[count := count +1].
"skip potential whitechars after the address"
countEnd := string size.
[(((string at: countEnd) = $') or: [(string at: countEnd) = $"] or: [countEnd <= (count+1)])] whileFalse:
[countEnd := countEnd - 1].
first _ count + 1 max: 1.
last _ countEnd-1 min: string size.
(first > string size or: [first > last ]) ifTrue: [ ^''].
^string copyFrom: first to: last! !
!RTFParser methodsFor: 'utilities' stamp: 'tat 8/13/2007 10:41'!
parseBlock
| token |
"parses a complete {..} block"
"is there a block to parse?"
token := (tokenizer lookAhead: 1).
((token isNil not) and: [token type == #blockOpen]) ifFalse: [^self].
"skip the { character"
tokenizer getToken.
"save the state"
self saveState.
"parse all words until the end of the block is reached"
self parseUntilBlockClose.
"skip the } character"
tokenizer getToken.
"restore the state"
self restoreState! !
!RTFParser methodsFor: 'utilities' stamp: 'kalin 5/1/2006 14:08'!
parseCommand
"parse a command, string or a block of commands
disregarding their inner sctructure"
|peeked|
peeked := (tokenizer lookAhead: 1) type.
(peeked == #blockOpen)
ifTrue: [self parseBlock].
(peeked == #string)
ifTrue: [self addContents].
(peeked == #keyword)
ifTrue: [self parseKeyWord].
! !
!RTFParser methodsFor: 'utilities' stamp: 'kalin 5/16/2006 12:04'!
parseKeyWord
"assuming that the next RTF token is a keyword,
find appropriate keyword handler and execute it"
| token message |
token := tokenizer getToken.
"build the message name for the RTF keyword"
message := self createHandleMessage: token.
(self respondsTo: message) ifTrue: [
"Transcript show: 'Handling keyword: '; show: (token word); cr."
self perform: message with: token
] ifFalse: [
"run a general handler"
self handleAll: token
]
! !
!RTFParser methodsFor: 'utilities' stamp: 'tat 5/4/2006 23:09'!
parseUntilBlockClose
"reads until a not parsed #blockClose token"
[(tokenizer lookAhead: 1) type = #blockClose] whileFalse:
[self parseCommand]
! !
!RTFParser methodsFor: 'utilities' stamp: 'tat 5/4/2006 23:59'!
restoreState
"restores the state of the parser on exiting a block"
state restoreState.
builder restoreState! !
!RTFParser methodsFor: 'utilities' stamp: 'tat 5/4/2006 23:59'!
saveState
"saves the state of the parser on entering a block"
state saveState.
builder saveState! !
!RTFParser methodsFor: 'utilities' stamp: 'tat 5/4/2006 23:11'!
skipBlock
"skips a complete {..} block"
"is there a block to skip?"
((tokenizer lookAhead: 1) type = #blockOpen) ifFalse: [^self].
"skip the { character"
tokenizer getToken.
"skip until }"
self skipUntilBlockClose.
"skip the } character"
tokenizer getToken! !
!RTFParser methodsFor: 'utilities' stamp: 'kalin 4/30/2006 23:12'!
skipCommand
"skips a command. skips the whole block if the next token
is a #blockOpen"
((tokenizer lookAhead: 1) type == #blockOpen)
ifTrue: [self skipBlock]
ifFalse: [tokenizer getToken]
! !
!RTFParser methodsFor: 'utilities' stamp: 'tat 5/4/2006 23:13'!
skipUntilBlockClose
"skips until a not parsed #blockClose token"
[(tokenizer lookAhead: 1) type = #blockClose] whileFalse:
[self skipCommand]
! !
!RTFParser methodsFor: 'handlers-general' stamp: 'tat 5/5/2006 13:53'!
handleAll: token! !
!RTFParser methodsFor: 'handlers-general' stamp: 'tat 5/5/2006 14:36'!
handleStar: token
"check if the parser can respond to the command following the *"
(self respondsTo: (self createHandleMessage: (tokenizer lookAhead: 1))) ifFalse: [
"if not, suppress plain text within this block"
self handlerSupressText
]! !
!RTFParser methodsFor: 'handlers-general' stamp: 'tat 7/11/2006 22:26'!
handleansi: token
builder buildAnsiCharacterSet! !
!RTFParser methodsFor: 'handlers-general' stamp: 'tat 7/27/2006 11:38'!
handleansicpg: token
builder buildCodePage: (token arg)! !
!RTFParser methodsFor: 'handlers-general' stamp: 'tat 6/24/2006 00:37'!
handlebin: token
"ignore binary data in RTF"
self skipUntilBlockClose! !
!RTFParser methodsFor: 'handlers-general' stamp: 'tat 11/1/2006 17:24'!
handlefootnote: token
self skipUntilBlockClose! !
!RTFParser methodsFor: 'handlers-general' stamp: 'tat 7/11/2006 22:26'!
handlemac: token
builder buildMacCharacterSet! !
!RTFParser methodsFor: 'handlers-general' stamp: 'tat 11/1/2006 15:11'!
handlerSupressText
"suppress plain text output"
state destination block: [:string | ] type: #ignore.
self parseUntilBlockClose.! !
!RTFParser methodsFor: 'handlers-general' stamp: 'jmv 9/5/2016 20:30:28'!
handleu: token
| string char |
char _ token arg < 0
ifTrue: [ RTFUnicode codePoint: (65536 + token arg) or: nil ]
ifFalse: [ RTFUnicode codePoint: token arg or: nil ].
"Do not output Unicode characters to a different destination, just suppress output"
state destination type = #default ifFalse: [^self].
"If we can represent char (i.e. it belongs in ISO 8859-15), add it, and skip next char
(as it should be included only if the unicode char point is not recognized)"
char ifNotNil: [
string _ char asString.
builder buildAddUnicodeContents: string.
builder skipNextCharacters: 1 ]! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 4/11/2007 15:07'!
handleLeftCurlyBracket: token
builder addUnicodeContents: '{'! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 4/11/2007 14:30'!
handleRightCurlyBracket: token
builder addUnicodeContents: '}'! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'jmv 9/5/2016 21:03:40'!
handleSomeCodePageHexValue: token
"send text to destination if not nil"
state destination value: (String with: (Character codePoint: token arg))
! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:54'!
handlebullet: token
builder buildAddBullet! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:53'!
handleemdash: token
builder buildAddEmDash! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:53'!
handleemspace: token
builder buildAddEmSpace! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:53'!
handleendash: token
builder buildAddEnDash! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:53'!
handleenspace: token
builder buildAddEnSpace! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:42'!
handleldblquote: token
builder buildAddDoubleLeftQuote! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'MR 7/10/2007 08:31'!
handleline: token
builder buildStartParagraph! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:54'!
handlelquote: token
builder buildAddLeftQuote! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:55'!
handlenbhyph: token
builder buildAddNonBreakingHyphen! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:55'!
handlenbsp: token
builder buildAddNonBreakingSpace! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:55'!
handleopthyph: token
builder buildAddOptionalHyphen! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 5/2/2006 01:46'!
handlepntxta: token
"only skips the text that follows"
((tokenizer lookAhead: 1) type = #string)
ifTrue: [tokenizer getToken].
! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:53'!
handleqmspace: token
builder buildAddQmSpace! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:42'!
handlerdblquote: token
builder buildAddDoubleRightQuote! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/22/2006 22:54'!
handlerquote: token
builder buildAddRightQuote! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'kalin 5/3/2006 12:34'!
handletab: token
builder buildAddTab! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 1/16/2007 12:03'!
handleuc: token
"this command states how many characters to skip after reading an unicode character"
builder defaultSkipNextCharacters: token arg! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/21/2006 23:51'!
handleud: token
"Do nothing. This handler exists only to state that the upcoming block of unicode text should not be ignored"! !
!RTFParser methodsFor: 'handlers-characters' stamp: 'tat 6/21/2006 23:51'!
handleupr: token
"{\upr{keyword ansi_text}{\*\ud{keyword Unicode_text}}}"
"skip the first block of ansi text"
self skipBlock
"the Unicode block will be parsed by the \ud keyword"! !
!RTFParser methodsFor: 'handlers-stylesheet' stamp: 'tat 5/5/2006 14:45'!
handleadditive: token
state context additive! !
!RTFParser methodsFor: 'handlers-stylesheet' stamp: 'tat 5/6/2006 17:08'!
handlecs: token
self handles: token.
state context isNil ifFalse: [state context type: #character]! !
!RTFParser methodsFor: 'handlers-stylesheet' stamp: 'tat 5/6/2006 16:57'!
handleds: token
self handles: token.
state context isNil ifFalse: [state context type: #paragraph]! !
!RTFParser methodsFor: 'handlers-stylesheet' stamp: 'tat 11/1/2006 15:13'!
handles: token
state destination type = #stylesheet
ifFalse: [ builder buildApplyStylesheet: (token arg)]
ifTrue: [
state context: (builder buildStartStylesheet).
state context num: (token arg).
state context type: #paragraph
]! !
!RTFParser methodsFor: 'handlers-stylesheet' stamp: 'tat 5/6/2006 16:53'!
handlesbasedon: token
state context basedon: (token arg)! !
!RTFParser methodsFor: 'handlers-stylesheet' stamp: 'tat 11/1/2006 15:11'!
handlestylesheet: token
state destination block: [:string | (string endsWith: ';')
ifTrue: [builder buildAddStylesheet: state context]
ifFalse: [state context name: string]
] type: #stylesheet.
state context: (builder buildStartStylesheet)
! !
!RTFParser methodsFor: 'handlers-skipping' stamp: 'kalin 7/9/2006 16:58'!
handleaftnsep: token
self skipUntilBlockClose.! !
!RTFParser methodsFor: 'handlers-skipping' stamp: 'kalin 7/9/2006 16:57'!
handlechftnsep: token
self skipUntilBlockClose.! !
!RTFParser methodsFor: 'handlers-skipping' stamp: 'tat 6/18/2007 00:47'!
handlefooter: token
self skipUntilBlockClose.! !
!RTFParser methodsFor: 'handlers-skipping' stamp: 'kalin 7/9/2006 16:58'!
handleftnsepc: token
self skipUntilBlockClose.! !
!RTFParser methodsFor: 'handlers-skipping' stamp: 'kalin 7/9/2006 16:55'!
handleheader: token
self skipUntilBlockClose.! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'tat 7/10/2006 23:31'!
handleb: token
builder buildSetBold: (token arg = 1)! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'kalin 5/3/2006 12:00'!
handlecaps: token
builder buildSetCaps! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'kalin 5/3/2006 12:03'!
handlecb: token
builder buildSetBkColor: (token arg)! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'tat 3/12/2007 19:22'!
handlecbpat: token
"treat this as changing the background color"
self handlecb: token! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'kalin 5/3/2006 12:03'!
handlecf: token
builder buildSetFgColor: (token arg)! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'tat 3/1/2007 15:37'!
handlechcbpat: token
"treat this as changing the background color"
self handlecb: token! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'MR 6/7/2006 18:09'!
handledn: token
builder buildSetBaselineOffset: (token arg negated)! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'kalin 5/3/2006 12:12'!
handlefs: token
builder buildSetFontSize: (token arg)! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'tat 6/13/2007 23:50'!
handlehighlight: token
"treat highlighting as changing the background color"
self handlecb: token! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'tat 7/11/2006 00:38'!
handlei: token
builder buildSetItalic: (token arg = 1)! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'MR 6/7/2006 17:59'!
handlekerning: token
builder buildSetKerning: (token arg)! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'kalin 5/3/2006 11:58'!
handleplain: token
builder buildResetCharFormat! !
!RTFParser methodsFor: 'handlers-charformat' stamp: 'kalinm 5/4/2006 19:51'!
handleul: token
builder buildSetUnderline: true! !