File: docBuf.h

package info (click to toggle)
ted 2.6-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,928 kB
  • ctags: 8,734
  • sloc: ansic: 71,878; makefile: 2,363; sh: 159
file content (1210 lines) | stat: -rw-r--r-- 33,959 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
/************************************************************************/
/*									*/
/*  Text Editor Buffer structure.					*/
/*									*/
/************************************************************************/

#   ifndef	DOC_BUF_H
#   define	DOC_BUF_H

#   include	<bitmap.h>
#   include	<docFont.h>
#   include	"docShape.h"
#   include	<appGeo.h>
#   include	<sioGeneral.h>

/************************************************************************/
/*									*/
/*  An homogenous piece of text. Without hyphenation, it will not be	*/
/*  divided over lines.							*/
/*  It consists of some characters and then some spaces.		*/
/*									*/
/************************************************************************/
#   define	DOCkindUNKNOWN		0
#   define	DOCkindTEXT		1
#   define	DOCkindTAB		2
#   define	DOCkindOBJECT		3
#   define	DOCkindFIELDSTART	4
#   define	DOCkindFIELDEND		5
#   define	DOCkindBKMKSTART	6
#   define	DOCkindBKMKEND		7
#   define	DOCkindBKMKEND		7
#   define	DOCkindTC		8
#   define	DOCkindXE		9

typedef struct TextParticule
    {
    unsigned int	tpStroff;
    unsigned short int	tpStrlen;
    unsigned short int	tpX0;
    unsigned short int	tpPixelsWide;
    short int		tpPhysicalFont;
    short int		tpKind;
    TextAttribute	tpTextAttribute;
    short int		tpObjectNumber;
    } TextParticule;

/************************************************************************/
/*									*/
/*  Used to layout lines of text.					*/
/*									*/
/************************************************************************/
typedef struct FormattingFrame
    {
    int		ffX0Geometry;
    int		ffX0TextLines;
    int		ffX0FirstLine;
    int		ffX1Geometry;
    int		ffX1TextLines;
    int		ffY1;
    } FormattingFrame;

/************************************************************************/
/*									*/
/*  Describes tabs.							*/
/*									*/
/*  !)	RS6000/AIX compler only supports unsigned bitfields.		*/
/*									*/
/************************************************************************/

typedef enum TabKind
    {
    DOCtkLEFT= 0,

    DOCtkRIGHT,
    DOCtkCENTRE,
    DOCtkDECIMAL
    } TabKind;

typedef enum TabLeader
    {
    DOCtlNONE= 0,

    DOCtlDOTS,
    DOCtlHYPH,
    DOCtlUNDERLINE,
    DOCtlTHICK,
    DOCtlEQUAL
    } TabLeader;

typedef struct TabStop
    {
    int			tsTwips;
    int			tsPixels;
    unsigned int	tsKind:2;	/*  (enum)	*/
    unsigned int	tsLeader:3;	/*  (enum)	*/
    } TabStop;

/************************************************************************/
/*									*/
/*  Used to lay out the text on the page.				*/
/*  A text line consists of a series of particules.			*/
/*									*/
/************************************************************************/
typedef struct TextLine
    {
    int			tlStroff;
    int			tlStrlen;
				/****************************************/
				/*  What piece of text.			*/
				/****************************************/
    int			tlFirstParticule;
    int			tlParticuleCount;
				/****************************************/
				/*  What particules in the paragraph.	*/
				/****************************************/
    int			tlY;
    int			tlY0;
    int			tlY1;
				/****************************************/
				/*  Base line.				*/
				/*  Ascender top.			*/
				/*  Descender bottom+ line dist.	*/
				/****************************************/
    } TextLine;

/************************************************************************/
/*									*/
/*  A paragraph in a document.						*/
/*									*/
/*  !)	RS6000/AIX compler only supports unsigned bitfields.		*/
/*									*/
/************************************************************************/

typedef enum BorderStyle
    {
    DOCbsSHADOWED= 0,
    DOCbsDOUBLE,
    DOCbsDOT,
    DOCbsDASH,
    DOCbsHAIR,
    DOCbsDASHSM,
    DOCbsDASHD,
    DOCbsDASHDD,
    DOCbsTRIPLE,
    DOCbsTNTHSG,
    DOCbsTHTNSG,
    DOCbsTNTHTNSG,
    DOCbsTNTHMG,
    DOCbsTHTNMG,
    DOCbsTNTHTNMG,
    DOCbsTNTHLG,
    DOCbsTHTNLG,
    DOCbsTNTHTNLG,
    DOCbsWAVY,
    DOCbsWAVYDB,
    DOCbsDASHDOTSTR,
    DOCbsEMBOSS,
    DOCbsENGRAVE
    } BorderStyle;

typedef struct BorderProperties
    {
    unsigned int	bpColor:8;
    unsigned int	bpSpacingTwips:16;
    unsigned int	bpWidthTwips:8;
    unsigned int	bpStyle:5;		/*  (enum)	*/
    unsigned int	bpThickness:2;		/*  0, 1 or 2	*/
    unsigned int	bpIsSet:1;
    } BorderProperties;

#   define	docCopyBorderProperties( bp1, bp2 ) *(bp1)= *(bp2)

typedef enum ItemAlignment
    {
    DOCiaLEFT= 0,
    DOCiaRIGHT,
    DOCiaCENTERED,
    DOCiaJUSTIFIED
    } ItemAlignment;

typedef enum ObjectKind
    {
    DOCokUNKNOWN= 0,
    DOCokPICTWMETAFILE,
    DOCokPICTPNGBLIP,
    DOCokPICTJPEGBLIP,
    DOCokOLEOBJECT
    } ObjectKind;

typedef enum VerticalTextAlignment
    {
    DOCvtaTOP= 0,
    DOCvtaCENTERED,
    DOCvtaBOTTOM,
    DOCvtaVERT_LEFT,
    DOCvtaVERT_RIGHT
    } VerticalTextAlignment;

typedef enum ShadingPattern
    {
    DOCspSOLID= 0,

    DOCspHORIZONTAL,
    DOCspVERTICAL,
    DOCspDIAGONAL_DOWN,
    DOCspDIAGONAL_UP,
    DOCspCROSSED,
    DOCspDIAGONALCROSSED,
    DOCspDK_HORIZONTAL,
    DOCspDK_VERTICAL,
    DOCspDK_DIAGONAL_DOWN,
    DOCspDK_DIAGONAL_UP,
    DOCspDK_CROSSED,
    DOCspDK_DIAGONALCROSSED
    } ShadingPattern;

typedef struct CellProperties
    {
    int			cpRightBoundaryTwips;
    int			cpRightBoundaryPixels;

    int			cpForegroundColor;
    int			cpBackgroundColor;

    BorderProperties	cpTopBorder;
    BorderProperties	cpBottomBorder;
    BorderProperties	cpLeftBorder;
    BorderProperties	cpRightBorder;

    unsigned int	cpShadingLevel:10;
    unsigned int	cpShadingPattern:4;		/*  (enum)	*/

    unsigned int	cpFirstInMergedRange:1;
    unsigned int	cpMergedWithPrevious:1;

    unsigned int	cpVerticalTextAlignment:3;	/*  (enum)	*/
    } CellProperties;

#   define	docCopyCellProperties( cp1, cp2 ) \
					    ( ( *(cp1)= *(cp2) ), 0 )

#   define	docCleanCellProperties( cp ) /* nothing */

typedef struct RowProperties
    {
    int			rpCellCount;
    CellProperties *	rpCells;

    int			rpHalfGapWidthTwips;
    int			rpHalfGapWidthPixels;

    int			rpHeightTwips;
    int			rpHeightPixels;

    int			rpLeftIndentTwips;
    int			rpLeftIndentPixels;

			/************************************************/
			/*  Row borders are not stored in the word	*/
			/*  binary format, and seem to be irrelevant:	*/
			/************************************************/
    BorderProperties	rpTopBorder;
    BorderProperties	rpBottomBorder;
    BorderProperties	rpLeftBorder;
    BorderProperties	rpRightBorder;
    BorderProperties	rpHorizontalBorder;
    BorderProperties	rpVerticalBorder;

    ItemAlignment	rpAlignment:3;
    unsigned int	rpHasTableParagraphs:1;

    unsigned int	rpHasHorizontalBorders:1;
    unsigned int	rpHasVerticalBorders:1;

    unsigned int	rpIsTableHeader:1;
    unsigned int	rpKeepOnPage:1;
    } RowProperties;

typedef struct SectionProperties
    {
    int			spColumnCount;

    unsigned int	spHasFacingPages:1;
    unsigned int	spHasTitlePage:1;

    struct BufferItem *	spHeader;
    struct BufferItem *	spFirstPageHeader;
    struct BufferItem *	spLeftPageHeader;
    struct BufferItem *	spRightPageHeader;

    struct BufferItem *	spFooter;
    struct BufferItem *	spFirstPageFooter;
    struct BufferItem *	spLeftPageFooter;
    struct BufferItem *	spRightPageFooter;

    } SectionProperties;

typedef struct DocumentProperties
    {
    int			dpContainsTables;
    int			dpTabIntervalTwips;
    int			dpDefaultColor;
    int			dpAnsiCodePage;
    } DocumentProperties;

typedef struct ParagraphProperties
    {
    short int		ppTabCount;
    TabStop *		ppTabStops;

    short int		ppFirstIndentTwips;
    short int		ppFirstIndentPixels;

    short int		ppLeftIndentTwips;
    short int		ppLeftIndentPixels;

    short int		ppRightIndentTwips;
    short int		ppRightIndentPixels;

    short int		ppSpaceBeforeTwips;
    short int		ppSpaceBeforePixels;

    short int		ppSpaceAfterTwips;
    short int		ppSpaceAfterPixels;

    short int		ppLineSpacingTwips;
    short int		ppLineSpacingPixels;

    short int		ppStyle;

    BorderProperties	ppTopBorder;
    BorderProperties	ppBottomBorder;
    BorderProperties	ppLeftBorder;
    BorderProperties	ppRightBorder;
    BorderProperties	ppBetweenBorder;
    BorderProperties	ppBoxBorder;
    BorderProperties	ppBar;

    unsigned int	ppOutlineLevel:4;

    unsigned int	ppShadingLevel:10;
    unsigned int	ppShadingPattern:4;		/*  (enum)	*/

    unsigned int	ppAlignment:3;			/*  (enum)	*/

    unsigned int	ppStartsOnNewPage:1;
    unsigned int	ppInTable:1;
    unsigned int	ppLineSpacingIsMultiple:1;

    unsigned int	ppKeepOnPage:1;
    unsigned int	ppKeepWithNext:1;
    } ParagraphProperties;

/************************************************************************/
/*									*/
/*  Masks for updating paragraph properies.				*/
/*									*/
/************************************************************************/

#   define	PPupdNONE		0x0000

#   define	PPupdLEFT_INDENT	0x0001
#   define	PPupdFIRST_INDENT	0x0002
#   define	PPupdRIGHT_INDENT	0x0004
#   define	PPupdTAB_STOPS		0x0008

#   define	PPupdNEWPAGE		0x0010
#   define	PPupdSPACE_BEFORE	0x0020
#   define	PPupdSPACE_AFTER	0x0040
#   define	PPupdTOP_BORDER		0x0080
#   define	PPupdBOTTOM_BORDER	0x0100
#   define	PPupdALIGNMENT		0x0200
#   define	PPupdLINE_SPACING	0x0400

#   define	PPupdALL		0x7fff

#   define	PPupdCOLUMNS		0x8000		/*  not real	*/

typedef enum ShapeHorizontalAttachment
    {
    SHPshaPAGE= 0,
    SHPshaMARGIN,
    SHPshaCOLUMN
    } ShapeHorizontalAttachment;

typedef enum ShapeVerticalAttachment
    {
    SHPsvaPAGE= 0,
    SHPsvaMARGIN,
    SHPsvaPARAGRAPH
    } ShapeVerticalAttachment;

typedef enum ShapeWrapStyle
    {
    SHPswsTOPBOTTOM= 1,
    SHPswsAROUND,
    SHPswsNONE,
    SHPswsTIGHTLY,
    SHPswsTHROUGH
    } ShapeWrapStyle;

typedef enum ShapeWrapSide
    {
    SHPswsBOTH= 0,
    SHPswsLEFT,
    SHPswsRIGHT,
    SHPswsLARGEST
    } ShapeWrapSide;

typedef struct ShapeProperties
    {
    int			spTwipsLeftOfAnchor;
    int			spTwipsAboveAnchor;
    int			spTwipsBelowAnchor;
    int			spTwipsRightOfAnchor;

    unsigned int	spHorizontalAttachment:2;	/*  (enum)	*/
    unsigned int	spVerticalAttachment:2;		/*  (enum)	*/
    unsigned int	spWrapStyle:3;			/*  (enum)	*/
    unsigned int	spWrapSide:2;			/*  (enum)	*/
    unsigned int	spLockAnchor:1;
    } ShapeProperties;

typedef struct ObjectData
    {
    unsigned char *	odBytes;
    int			odSize;
    } ObjectData;

typedef struct InsertedObject
    {
    int			ioKind;		/*  Kind of object.		*/
    int			ioResultKind;	/*  Kind of object.		*/
    int			ioTwipsWide;	/*  Width of object.		*/
    int			ioTwipsHigh;	/*  Height of object.		*/
    int			ioScaleX;	/*  In %.			*/
    int			ioScaleY;	/*  In %.			*/
    int			ioPixelsWide;	/*  Width of object on screen	*/
    int			ioPixelsHigh;	/*  Height of object on screen	*/
    int			ioXExtent;	/*  Of metafile picture.	*/
    int			ioYExtent;	/*  Of metafile picture.	*/
    int			ioUnitsPerInch;	/*  Only use if > 0		*/

    int			ioDragWide;	/*  PixelsWide during resize.	*/
    int			ioDragHigh;	/*  PixelsHigh during resize.	*/

    ObjectData		ioObjectData;
    ObjectData		ioResultData;

    unsigned char *	ioObjectName;
    unsigned char *	ioObjectClass;
    int			ioBliptag;

    unsigned long	ioPixmap;
    void *		ioPrivate;
    } InsertedObject;

typedef enum FieldKind
    {
    DOCfkFREE= 0,
    DOCfkUNKNOWN,
    DOCfkHYPERLINK,
    DOCfkINDEX_ENTRY,
    DOCfkCONTENTS_ENTRY,
    DOCfkBKMKSTART,
    DOCfkBKMKEND,
    DOCfkPAGEFIELD
    } FieldKind;

typedef struct DocumentField
    {
    FieldKind		dfKind;
    ObjectData		dfData;
    ObjectData		dfInstructions;
    int			dfNumberInDocument;
    } DocumentField;

typedef struct DocumentFieldList
    {
    DocumentField *	dflFields;
    int			dflFieldCount;
    } DocumentFieldList;

typedef struct BufferPara
    {
    unsigned char *	btString;
    unsigned int	btStrlen;

    int			btParticuleCount;
    TextParticule *	btParticules;

    int			btObjectCount;
    InsertedObject *	btObjects;

    int			btLineCount;
    TextLine *		btLines;

    DocumentFieldList	btFieldList;

    int			btShapeCount;
    DrawingShape *	btShapes;

    ParagraphProperties	btProperties;
    } BufferPara;

typedef struct BufferGroup
    {
    struct BufferItem **	bgChildren;
    int				bgChildCount;

    union	BGU
	{
	DocumentProperties	bguDocumentProperties;
	SectionProperties	bguSectionProperties;
	RowProperties		bguRowProperties;
	CellProperties		bguCellProperties;
	} BGU;

    } BufferGroup;

/************************************************************************/
/*  Levels of nesting.							*/
/************************************************************************/
typedef enum ItemLevel
    {
    DOClevANY,
    DOClevOUT,
			/****************************************/
			/*  Ignore, Garbage values.		*/
			/****************************************/
    DOClevDOC,
#	define	biDocumentProperties	BIU.biuGroup.BGU.bguDocumentProperties
#	define	biDocContainsTables	biDocumentProperties.dpContainsTables
#	define	biDocTabIntervalTwips	biDocumentProperties.dpTabIntervalTwips
#	define	biDocDefaultColor	biDocumentProperties.dpDefaultColor
#	define	biDocAnsiCodePage	biDocumentProperties.dpAnsiCodePage
			/****************************************/
			/*					*/
			/*  Document.				*/
			/*					*/
			/*  * biGroupChildren			*/
			/*  * biGroupChildCount			*/
			/****************************************/
    DOClevSECT,
			/****************************************/
			/*					*/
			/*  Section.				*/
			/*					*/
			/*  * biGroupChildren			*/
			/*  * biGroupChildCount			*/
			/*					*/
			/****************************************/
#	define	biSectProperties	BIU.biuGroup.BGU.bguSectionProperties
#	define	biSectHeader		biSectProperties.spHeader
#	define	biSectFirstPageHeader	biSectProperties.spFirstPageHeader
#	define	biSectLeftPageHeader	biSectProperties.spLeftPageHeader
#	define	biSectRightPageHeader	biSectProperties.spRightPageHeader

#	define	biSectFooter		biSectProperties.spFooter
#	define	biSectFirstPageFooter	biSectProperties.spFirstPageFooter
#	define	biSectLeftPageFooter	biSectProperties.spLeftPageFooter
#	define	biSectRightPageFooter	biSectProperties.spRightPageFooter

			/****************************************/

    DOClevROW,
			/****************************************/
			/*  Row.				*/
			/*  * biGroupChildren			*/
			/*  * biGroupChildCount			*/
			/****************************************/
#	define	biRowProperties		BIU.biuGroup.BGU.bguRowProperties
#	define	biRowHasTableParagraphs	biRowProperties.rpHasTableParagraphs
#	define	biRowHalfGapWidthTwips	biRowProperties.rpHalfGapWidthTwips
#	define	biRowHalfGapWidthPixels \
					biRowProperties.rpHalfGapWidthPixels
#	define	biRowLeftIndentTwips	biRowProperties.rpLeftIndentTwips
#	define	biRowLeftIndentPixels	biRowProperties.rpLeftIndentPixels
#	define	biRowHeightTwips	biRowProperties.rpHeightTwips
#	define	biRowHeightPixels	biRowProperties.rpHeightPixels
#	define	biRowIsTableHeader	biRowProperties.rpIsTableHeader
#	define	biRowKeepOnPage		biRowProperties.rpKeepOnPage
#	define	biRowHasHorizontalBorders \
					biRowProperties.rpHasHorizontalBorders
#	define	biRowHasVerticalBorders \
					biRowProperties.rpHasVerticalBorders
#	define	biRowCells		biRowProperties.rpCells
#	define	biRowCellCount		biRowProperties.rpCellCount
#	define	biRowAlignment		biRowProperties.rpAlignment

#	define	biRowTopBorder		biRowProperties.rpTopBorder
#	define	biRowBottomBorder	biRowProperties.rpBottomBorder
#	define	biRowLeftBorder		biRowProperties.rpLeftBorder
#	define	biRowRightBorder	biRowProperties.rpRightBorder
#	define	biRowVerticalBorder	biRowProperties.rpVerticalBorder
#	define	biRowHorizontalBorder	biRowProperties.rpHorizontalBorder

    DOClevCELL,
			/****************************************/
			/*  Cell.				*/
			/*  * biGroupChildren			*/
			/*  * biGroupChildCount			*/
			/****************************************/
#	define	biCellProperties	BIU.biuGroup.BGU.bguCellProperties
#	define	biCellRightBoundaryPixels \
					biCellProperties.cpRightBoundaryPixels
#	define	biCellRightBoundaryTwips \
					biCellProperties.cpRightBoundaryTwips
#	define	biCellTopBorder		biCellProperties.cpTopBorder
#	define	biCellBottomBorder	biCellProperties.cpBottomBorder
#	define	biCellLeftBorder	biCellProperties.cpLeftBorder
#	define	biCellRightBorder	biCellProperties.cpRightBorder

    DOClevPARA,
			/********************************/
			/*  Paragraph.			*/
			/********************************/
#	define	biParaString		BIU.biuPara.btString
#	define	biParaStrlen		BIU.biuPara.btStrlen
#	define	biParaParticuleCount	BIU.biuPara.btParticuleCount
#	define	biParaParticules	BIU.biuPara.btParticules
#	define	biParaObjectCount	BIU.biuPara.btObjectCount
#	define	biParaObjects		BIU.biuPara.btObjects
#	define	biParaLineCount		BIU.biuPara.btLineCount
#	define	biParaLines		BIU.biuPara.btLines
#	define	biParaFieldList		BIU.biuPara.btFieldList
#	define	biParaShapeCount	BIU.biuPara.btShapeCount
#	define	biParaShapes		BIU.biuPara.btShapes
#	define	biParaProperties	BIU.biuPara.btProperties
#	define	biParaInTable		biParaProperties.ppInTable
#	define	biParaLineSpacingIsMultiple \
					biParaProperties.ppLineSpacingIsMultiple
#	define	biParaStartsOnNewPage	biParaProperties.ppStartsOnNewPage
#	define	biParaFirstIndentTwips	biParaProperties.ppFirstIndentTwips
#	define	biParaLeftIndentTwips	biParaProperties.ppLeftIndentTwips
#	define	biParaRightIndentTwips	biParaProperties.ppRightIndentTwips
#	define	biParaSpaceBeforeTwips	biParaProperties.ppSpaceBeforeTwips
#	define	biParaSpaceAfterTwips	biParaProperties.ppSpaceAfterTwips
#	define	biParaLineSpacingTwips	biParaProperties.ppLineSpacingTwips
#	define	biParaAlignment		biParaProperties.ppAlignment
#	define	biParaTabStops		biParaProperties.ppTabStops
#	define	biParaTabCount		biParaProperties.ppTabCount
#	define	biParaFirstIndentPixels \
					biParaProperties.ppFirstIndentPixels
#	define	biParaLeftIndentPixels \
					biParaProperties.ppLeftIndentPixels
#	define	biParaRightIndentPixels \
					biParaProperties.ppRightIndentPixels
#	define	biParaSpaceBeforePixels \
					biParaProperties.ppSpaceBeforePixels
#	define	biParaLineSpacingPixels \
					biParaProperties.ppLineSpacingPixels
#	define	biParaSpaceAfterPixels	biParaProperties.ppSpaceAfterPixels
#	define	biParaKeepOnPage	biParaProperties.ppKeepOnPage
#	define	biParaKeepWithNext	biParaProperties.ppKeepWithNext
#	define	biParaShadingLevel	biParaProperties.ppShadingLevel
#	define	biParaShadingPattern	biParaProperties.ppShadingPattern
#	define	biParaOutlineLevel	biParaProperties.ppOutlineLevel
#	define	biParaTopBorder		biParaProperties.ppTopBorder
#	define	biParaBottomBorder	biParaProperties.ppBottomBorder
#	define	biParaLeftBorder	biParaProperties.ppLeftBorder
#	define	biParaRightBorder	biParaProperties.ppRightBorder
#	define	biParaBoxBorder		biParaProperties.ppBoxBorder
#	define	biParaBetweenBorder	biParaProperties.ppBetweenBorder
#	define	biParaBar		biParaProperties.ppBar
#	define	biParaStyle		biParaProperties.ppStyle

    DOClevTEXT
			/********************************/
			/*  Handeled inside TEXT.	*/
			/********************************/
    } ItemLevel;

#   define	biGroupChildren		BIU.biuGroup.bgChildren
#   define	biGroupChildCount	BIU.biuGroup.bgChildCount

typedef struct BufferItem
    {
    ItemLevel		biLevel;
    struct BufferItem *	biParent;
    int			biNumberInParent;

    int			biY0;
    int			biY1;

    union	BIU
	{
	BufferGroup	biuGroup;
	BufferPara	biuPara;
	} BIU;

    } BufferItem;

/************************************************************************/
/*									*/
/*  A position in a document.						*/
/*									*/
/*  1)  Geometry is derived from the position, NOT the other way round.	*/
/*									*/
/************************************************************************/
typedef struct BufferPosition
    {
    BufferItem *	bpBi;
    int			bpLine;
    int			bpParticule;
    int			bpStroff;

    /*  1  */
    int			bpX;
    int			bpY0;
    int			bpY1;
    } BufferPosition;

typedef struct BufferSelection
    {
    BufferPosition	bsBegin;
    BufferPosition	bsEnd;
    BufferPosition	bsAnchor;
    int			bsCol0;
    int			bsCol1;
    int			bsDirection;
    } BufferSelection;

#   define	docPositionsInsideCell(b,e) \
		((b)->bpBi->biParent == (e)->bpBi->biParent)
#   define	docPositionsInsideRow(b,e) \
		((b)->bpBi->biParent->biParent == (e)->bpBi->biParent->biParent)

#   define	docSelectionInsideCell(bs) \
		docPositionsInsideCell(&(bs)->bsBegin,&(bs)->bsEnd)
#   define	docSelectionInsideRow(bs) \
		docPositionsInsideRow(&(bs)->bsBegin,&(bs)->bsEnd)

/************************************************************************/
/*									*/
/*  Styles in a document.						*/
/*									*/
/*  dsBusy is used to prevent recursion when styles are expanded.	*/
/*									*/
/************************************************************************/

typedef struct DocumentStyle
    {
    int			dsStyleNumber;
    int			dsBasedOn;
    int			dsIsCharacterStyle;
    int			dsBusy;
    ParagraphProperties	dsParagraphProperties;
    TextAttribute	dsTextAttribute;
    char *		dsName;
    } DocumentStyle;

/************************************************************************/
/*									*/
/*  The document as a whole.						*/
/*									*/
/************************************************************************/

typedef struct BufferDocument
    {
    BufferItem		bdItem;
    DocumentGeometry	bdGeometry;
    DocumentProperties	bdProperties;
    DocumentFontList	bdFontList;

    RGB8Color *		bdColors;
    int			bdColorCount;

    DocumentStyle *	bdStyles;
    int			bdStyleCount;

    DocumentFieldList	bdBookmarks;

    unsigned char *	bdTitle;
    unsigned char *	bdSubject;
    unsigned char *	bdKeywords;
    unsigned char *	bdComment;
    unsigned char *	bdAuthor;
    } BufferDocument;

#   define	docHasDocumentInfo( bd )	\
		( (bd)->bdTitle		||	\
		  (bd)->bdSubject	||	\
		  (bd)->bdKeywords	||	\
		  (bd)->bdComment	||	\
		  (bd)->bdAuthor	)

typedef void (*DOC_CLOSE_OBJECT)(	BufferDocument *	bd,
					BufferItem *		bi,
					TextParticule *		tp,
					void *			voiddis );

/************************************************************************/
/*									*/
/*  Routine declarations.						*/
/*									*/
/************************************************************************/

extern BufferDocument *	docPlainReadFile(	SimpleInputStream *	sis );

extern BufferDocument *	docRtfReadFile(		SimpleInputStream *	sis );
extern BufferDocument *	docLeafReadFile(	SimpleInputStream *	sis );
extern BufferDocument *	docWordReadFile(	SimpleInputStream *	sis );

extern BufferDocument * docNewFile(	const char *	fontName,
					int		fontSize	);

extern int docRtfSaveDocument(		SimpleOutputStream *	sos,
					const BufferDocument *	bd,
					const BufferSelection *	bs,
					int			saveBookmarks );

extern int docRtfSaveSelectionAsLink(	SimpleOutputStream *	sos,
					const BufferDocument *	bd,
					const BufferSelection *	bs,
					const char *		fileName,
					int			fileSize,
					const char *		markName,
					int			markSize );

extern int docHtmlSaveDocument(		SimpleOutputStream *	sos,
					const BufferDocument *	bd,
					const char *		filename );

extern int docPlainSaveDocument(	SimpleOutputStream *	sos,
					const BufferDocument *	bd,
					const BufferSelection *	bs,
					int			fold,
					int			closed );

extern int docRtfSaveRuler(	SimpleOutputStream *		sos,
				const ParagraphProperties *	pp );

extern int docRtfReadRuler(	SimpleInputStream *	sis,
				ParagraphProperties *	pp );

extern int docInflateTextString(	BufferItem *    bi,
					int		by	);

extern TextLine * docInsertTextLine(	BufferItem *	bi,
					int		line,
					int		stroff,
					int		part );

extern void docCleanItem(	BufferDocument *	bd,
				BufferItem *		bi );

extern void docFreeItem(	BufferDocument *	bd,
				BufferItem *		bi );

extern void docFreeDocument( BufferDocument *	bd );

extern void docInitDocument(	BufferDocument *	bd	);

extern void docInitParagraphProperties(	ParagraphProperties *	pp );
extern void docInitDocumentProperties(	DocumentProperties *	dp );
extern void docInitSectionProperties(	SectionProperties *	sp );

extern void docInitTabStop(	TabStop *	ts );

extern void docCleanParagraphProperties(	ParagraphProperties *	pp );
extern void docCleanSectionProperties(		SectionProperties *	sp );

extern int docCopyParagraphProperties(	ParagraphProperties *		to,
					const ParagraphProperties *	from );
extern int docCopySectProperties(	SectionProperties *		to,
					const SectionProperties *	from );
extern int docCopyRowProperties(	RowProperties *			to,
					const RowProperties *		from );

extern int docCopyParagraphRuler(	ParagraphProperties *		to,
					const ParagraphProperties *	from );

extern BufferItem * docInsertItem(	BufferItem *	parent,
					int		n,
					ItemLevel	level	);

extern BufferItem * docCopyParaItem(	BufferDocument *	bdTo,
					BufferItem *		biCellTo,
					int			n,
					BufferItem *		biParaFrom,
					const char *		filename );

extern BufferItem * docCopyRowItem(	BufferDocument *	bdTo,
					BufferItem *		biSectTo,
					int			n,
					BufferItem *		biRowFrom,
					const char *		filename );

extern void docDeleteItems(	BufferDocument *	bd,
				BufferItem *		bi,
				int			first,
				int			count	);

extern TextParticule *	docInsertTextParticule(	BufferItem *	bi,
						int		n,
						int		off,
						int		len,
						int		kind,
						TextAttribute	ta	);

extern TextParticule * docCopyParticule(	BufferItem *		bi,
						int			n,
						int			off,
						int			len,
						int			kind,
						const TextParticule *	from );

void docDeleteParticules	(	BufferItem *	bi,
					int		first,
					int		count	);

extern void docDeleteLines	(	BufferItem *	bi,
					int		first,
					int		count	);

extern int docParaAddTab(	ParagraphProperties *	pp,
				const TabStop *		ts	);

extern void docInitPosition(	BufferPosition *	bp	);
extern void docInitSelection(	BufferSelection *	bs	);

extern int docParaReplaceText(	BufferDocument *	bd,
				BufferItem *		bi,
				int			part,
				unsigned int		stroffBegin,
				int *			pPartShift,
				int *			pStroffShift,
				unsigned int		stroffEnd,
				const unsigned char *	addedText,
				unsigned int		addedLength,
				TextAttribute		addedAttribute,
				void *			voiddisplay,
				DOC_CLOSE_OBJECT	closeObject );

extern int docSplitParaItem(	BufferDocument *	bd,
				BufferItem **		pNewBi,
				BufferItem *		oldBi,
				int			stroff );

extern int docSplitGroupItem(	BufferItem **		pNewBi,
				BufferItem *		oldBi,
				int			n );

extern BufferItem * docNextParagraph(	BufferItem *	bi	);
extern BufferItem * docPrevParagraph(	BufferItem *	bi	);

extern int docNextPosition(	BufferPosition *	bp	);

extern int docPrevPosition(	BufferPosition *	bp,
				int			lastOne );

extern int docNextLine(		TextParticule **	pTp,
				TextLine **		pTl,
				BufferPosition *	bp	);

extern int docPrevLine(		TextParticule **	pTp,
				TextLine **		pTl,
				BufferPosition *	bp	);

extern int docFirstPosition(	BufferItem *		bi,
				BufferPosition *	bp	);

extern int docLastPosition(	BufferItem *		bi,
				BufferPosition *	bp	);

extern void docSetSelection(	BufferSelection *	bs,
				BufferItem *		bi,
				int			direction,
				int			start,
				int			length	);

extern int docComparePositions(	const BufferPosition *	bp1,
				const BufferPosition *	bp2,
				int			mindLine );

extern int docCompareItemPositions(	const BufferItem *	bi1,
					const BufferItem *	bi2 );

extern TextParticule * docParaSpecialParticule(	BufferItem *	bi,
					int			kind,
					int			part,
					int			stroff,
					int *			pPartShift,
					int *			pStroffShift );

extern int docFindLineAndParticule(	BufferItem *		bi,
					int			stroff,
					BufferPosition *	bp ,
					int			lastOne );

extern int docFindParticule(		BufferItem *		bi,
					int			stroff,
					int *			pPart,
					int			lastOne );

extern void docDeleteItem(	BufferDocument *	bd,
				BufferItem *		bi );

extern void docListItem(	int			indent,
				const BufferItem *	bi );

extern void docListParticule(	int			indent,
				const char *		label,
				int			n,
				const BufferItem *	bi,
				const TextParticule *	tp );

extern int docReplaceSelection(	BufferDocument *	bd,
				const BufferSelection *	bs,
				int *			pPartShift,
				int *			pStroffShift,
				const unsigned char *	addedText,
				int			addedLength,
				TextAttribute		addedAttribute,
				void *			voiddisplay,
				DOC_CLOSE_OBJECT	closeObject );

extern void docInitItem(	BufferItem *	bi,
				BufferItem *	parent,
				int		numberInParent,
				int		level	);

extern char *	docKindStr(		int			kind );
extern char *	docLevelStr(		int			level );
extern char *	docAttributeStr(	TextAttribute		ta );

extern TextParticule *	docInsertObject(	BufferItem *		bi,
						InsertedObject **	pIo,
						int			n,
						int			off,
						TextAttribute		ta );

extern int docSetObjectData(	InsertedObject *	io,
				const unsigned char *	bytes,
				int			size );

extern int docCopyObjectData(	ObjectData *		odTo,
				const ObjectData *	odFrom );

extern int docSetResultData(	InsertedObject *	io,
				const unsigned char *	bytes,
				int			size );

extern int docSaveObjectTag(	InsertedObject *	io,
				const char *		tag,
				int			arg );

extern int docSaveResultTag(	InsertedObject *	io,
				const char *		tag,
				int			arg );

extern void docCloseItemObjects(	BufferDocument *	bd,
					BufferItem *		bi,
					void *			voiddisplay,
					DOC_CLOSE_OBJECT	closeObject );

extern void docCleanParticuleObject(	BufferItem *	bi,
					TextParticule *	tp );

extern InsertedObject *	docClaimObject(	int *			pNr,
					BufferItem *		bi );

extern InsertedObject * docClaimObjectCopy( BufferItem *	bi,
					int *			pNr,
					const InsertedObject *	ioFrom );

extern int docSetObjectName(	InsertedObject *	io,
				const unsigned char *	name,
				int			len );

extern int docSetObjectClass(	InsertedObject *	io,
				const unsigned char *	name,
				int			len );

extern DocumentField * docClaimField(	int *			pNr,
					DocumentFieldList *	dfl );

extern int docSetFieldInst(	DocumentField *		df,
				const unsigned char *	bytes,
				int			size );

extern void docInitRowProperties(	RowProperties *	rp );
extern void docCleanRowProperties(	RowProperties *	rp );
extern void docCleanInitRowProperties(	RowProperties *	rp );

extern void docInitCellProperties(	CellProperties *	cp );

extern int docInsertRowColumn(	RowProperties *			rp,
				int				n,
				const CellProperties *	cp );

extern void docInitBorderProperties(	BorderProperties *	bp );

extern int docAlignedColumns(	const RowProperties *	rp1,
				const RowProperties *	rp2 );

extern int docEqualRows(	const RowProperties *	rp1,
				const RowProperties *	rp2 );

extern int docDelimitTable(	BufferItem *		paraBi,
				BufferItem **		pSectBi,
				int *			pCol,
				int *			pRow0,
				int *			pRow,
				int *			pRow1 );

extern void docParagraphFrame(		FormattingFrame *		ff,
					const DocumentGeometry *	dg,
					int				bottom,
					const BufferItem *		bi );

extern void docInitShapeProperties(	ShapeProperties *		sp );


extern int docGetBookmarkForPosition(	const BufferPosition *	bp,
					int *			pPart,
					int *			pEndPart,
					const char **		pMarkName,
					int *			pMarkSize );

extern DocumentField *	docFindBookmarkField( const DocumentFieldList * dfl,
					const unsigned char *	mark,
					int			markSize );

extern int docGetHyperlink(		DocumentField *		df,
					const char **		pFileName,
					int *			pFileSize,
					const char **		pMarkName,
					int *			pMarkSize );

extern int docGetPagefield(		DocumentField *		df );

extern int docGetHyperlinkForPosition(	const BufferPosition *	bp,
					int *			pStartPart,
					int *			pEndPart,
					const char **		pFileName,
					int *			pFileSize,
					const char **		pMarkName,
					int *			pMarkSize );

extern int docSetHyperlinkDestination(	DocumentField *		df,
					const char *		file,
					const char *		mark );

extern void docInitField(	DocumentField *	df );
extern void docCleanField(	DocumentField *	df );

extern void docCleanFieldList(	DocumentFieldList *	dfl );
extern void docInitFieldList(	DocumentFieldList *	dfl );

DocumentField *	docClaimFieldCopy(	BufferItem *		bi,
					int *			pNr,
					const DocumentField *	dfFrom );

extern int docCopyParticuleData(	BufferItem *		biTo,
					const BufferItem *	biFrom,
					TextParticule *		tpTo,
					const TextParticule *	tpFrom );

extern int docCopyParticules(	BufferItem *		biTo,
				const BufferItem *	biFrom,
				int			partTo,
				int			partFrom,
				int			countFrom,
				int *			pParticulesInserted,
				int *			pCharactersCopied,
				const char *		refFileName );

extern int docEqualBorder(	const BorderProperties *	bp1,
				const BorderProperties *	bp2 );

extern void docInitShape(	DrawingShape *	ds );
extern void docCleanShape(	DrawingShape *	ds );

extern DrawingShape * docClaimShape(	int *			pNr,
					BufferItem *		bi );

extern void docInitStyle(	DocumentStyle *	ds );
extern void docCleanStyle(	DocumentStyle *	ds );

extern DocumentStyle * docInsertStyle(	BufferDocument *	bd,
					int			n,
					const char *		name );

extern int docParticuleInField(		BufferItem *	bi,
					int		part );
extern int docParticuleInBookmark(	BufferItem *	bi,
					int		part );

extern int docSaveParticules(	BufferItem *		bi,
				TextAttribute		ta,
				const unsigned char	inputMapping[256],
				const unsigned char *	text,
				int			len );

extern int docSaveTab(		BufferItem *		bi,
				TextAttribute		ta );

extern unsigned int docParaPropertyDifference(
				const ParagraphProperties *	pp1,
				const ParagraphProperties *	pp2,
				unsigned int			updMask );

extern void docLogRectangle(	const char *			label,
				const DocumentRectangle *	dr );

extern int docSubstitutePageNumber(	BufferItem *		bi,
					int			pageNumber );
#   endif