1 # include "appUtilConfig.h"
2
3 # include "utilDocumentGeometry.h"
4 # include "utilPropMask.h"
5
6 # include <appDebugon.h>
7
8 /************************************************************************/
9 /* */
10 /* Set default document geometry. */
11 /* */
12 /************************************************************************/
13
utilInitDocumentGeometry(DocumentGeometry * dg)14 void utilInitDocumentGeometry( DocumentGeometry * dg )
15 {
16 dg->dgPageWideTwips= 12240;
17 dg->dgPageHighTwips= 15840;
18
19 dg->dgLeftMarginTwips= 1800;
20 dg->dgTopMarginTwips= 1440;
21 dg->dgRightMarginTwips= 1800;
22 dg->dgBottomMarginTwips= 1440;
23
24 dg->dgHeaderPositionTwips= 720;
25 dg->dgFooterPositionTwips= 720;
26
27 dg->dgGutterTwips= 0;
28 dg->dgMirrorMargins= 0;
29 }
30
31 /************************************************************************/
32 /* */
33 /* Copy a document Geometry. */
34 /* */
35 /************************************************************************/
36
utilUpdDocumentGeometry(PropertyMask * dpDoneMask,DocumentGeometry * dgTo,const PropertyMask * dgSetMask,const DocumentGeometry * dgSet)37 void utilUpdDocumentGeometry( PropertyMask * dpDoneMask,
38 DocumentGeometry * dgTo,
39 const PropertyMask * dgSetMask,
40 const DocumentGeometry * dgSet )
41 {
42 PropertyMask doneMask;
43
44 utilPropMaskClear( &doneMask );
45
46 if ( PROPmaskISSET( dgSetMask, DGpropPAGE_WIDTH ) )
47 {
48 if ( dgTo->dgPageWideTwips != dgSet->dgPageWideTwips )
49 {
50 dgTo->dgPageWideTwips= dgSet->dgPageWideTwips;
51 PROPmaskADD( &doneMask, DGpropPAGE_WIDTH );
52 }
53 }
54
55 if ( PROPmaskISSET( dgSetMask, DGpropPAGE_HEIGHT ) )
56 {
57 if ( dgTo->dgPageHighTwips != dgSet->dgPageHighTwips )
58 {
59 dgTo->dgPageHighTwips= dgSet->dgPageHighTwips;
60 PROPmaskADD( &doneMask, DGpropPAGE_HEIGHT );
61 }
62 }
63
64 if ( PROPmaskISSET( dgSetMask, DGpropLEFT_MARGIN ) )
65 {
66 if ( dgTo->dgLeftMarginTwips != dgSet->dgLeftMarginTwips )
67 {
68 dgTo->dgLeftMarginTwips= dgSet->dgLeftMarginTwips;
69 PROPmaskADD( &doneMask, DGpropLEFT_MARGIN );
70 }
71 }
72
73 if ( PROPmaskISSET( dgSetMask, DGpropRIGHT_MARGIN ) )
74 {
75 if ( dgTo->dgRightMarginTwips != dgSet->dgRightMarginTwips )
76 {
77 dgTo->dgRightMarginTwips= dgSet->dgRightMarginTwips;
78 PROPmaskADD( &doneMask, DGpropRIGHT_MARGIN );
79 }
80 }
81
82 if ( PROPmaskISSET( dgSetMask, DGpropTOP_MARGIN ) )
83 {
84 if ( dgTo->dgTopMarginTwips != dgSet->dgTopMarginTwips )
85 {
86 dgTo->dgTopMarginTwips= dgSet->dgTopMarginTwips;
87 PROPmaskADD( &doneMask, DGpropTOP_MARGIN );
88 }
89 }
90
91 if ( PROPmaskISSET( dgSetMask, DGpropBOTTOM_MARGIN ) )
92 {
93 if ( dgTo->dgBottomMarginTwips != dgSet->dgBottomMarginTwips )
94 {
95 dgTo->dgBottomMarginTwips= dgSet->dgBottomMarginTwips;
96 PROPmaskADD( &doneMask, DGpropBOTTOM_MARGIN );
97 }
98 }
99
100 if ( PROPmaskISSET( dgSetMask, DGpropHEADER_POSITION ) )
101 {
102 if ( dgTo->dgHeaderPositionTwips != dgSet->dgHeaderPositionTwips )
103 {
104 dgTo->dgHeaderPositionTwips= dgSet->dgHeaderPositionTwips;
105 PROPmaskADD( &doneMask, DGpropHEADER_POSITION );
106 }
107 }
108
109 if ( PROPmaskISSET( dgSetMask, DGpropFOOTER_POSITION ) )
110 {
111 if ( dgTo->dgFooterPositionTwips != dgSet->dgFooterPositionTwips )
112 {
113 dgTo->dgFooterPositionTwips= dgSet->dgFooterPositionTwips;
114 PROPmaskADD( &doneMask, DGpropFOOTER_POSITION );
115 }
116 }
117
118 if ( PROPmaskISSET( dgSetMask, DGpropGUTTER ) )
119 {
120 if ( dgTo->dgGutterTwips != dgSet->dgGutterTwips )
121 {
122 dgTo->dgGutterTwips= dgSet->dgGutterTwips;
123 PROPmaskADD( &doneMask, DGpropGUTTER );
124 }
125 }
126
127 if ( PROPmaskISSET( dgSetMask, DGpropMARGMIR ) )
128 {
129 if ( dgTo->dgMirrorMargins != dgSet->dgMirrorMargins )
130 {
131 dgTo->dgMirrorMargins= dgSet->dgMirrorMargins;
132 PROPmaskADD( &doneMask, DGpropMARGMIR );
133 }
134 }
135
136 if ( dpDoneMask )
137 { utilPropMaskOr( dpDoneMask, dpDoneMask, &doneMask ); }
138
139 return;
140 }
141
utilDocumentGeometryGetBodyRect(DocumentRectangle * dr,const DocumentGeometry * dg)142 void utilDocumentGeometryGetBodyRect(
143 DocumentRectangle * dr,
144 const DocumentGeometry * dg )
145 {
146 dr->drX0= dg->dgLeftMarginTwips;
147 dr->drX1= dg->dgPageWideTwips- dg->dgRightMarginTwips;
148 dr->drY0= dg->dgTopMarginTwips;
149 dr->drY1= dg->dgPageHighTwips- dg->dgBottomMarginTwips;
150 }
151
utilDocumentGeometryGetHeaderRect(DocumentRectangle * dr,const DocumentGeometry * dg)152 void utilDocumentGeometryGetHeaderRect(
153 DocumentRectangle * dr,
154 const DocumentGeometry * dg )
155 {
156 dr->drX0= dg->dgLeftMarginTwips;
157 dr->drX1= dg->dgPageWideTwips- dg->dgRightMarginTwips;
158 dr->drY0= dg->dgHeaderPositionTwips;
159 dr->drY1= dg->dgTopMarginTwips;
160 }
161
utilDocumentGeometryGetFooterRect(DocumentRectangle * dr,const DocumentGeometry * dg)162 void utilDocumentGeometryGetFooterRect(
163 DocumentRectangle * dr,
164 const DocumentGeometry * dg )
165 {
166 dr->drX0= dg->dgLeftMarginTwips;
167 dr->drX1= dg->dgPageWideTwips- dg->dgRightMarginTwips;
168 dr->drY0= dg->dgPageHighTwips- dg->dgBottomMarginTwips;
169 dr->drY1= dg->dgPageHighTwips- dg->dgFooterPositionTwips;
170 }
171
utilDocumentGeometryGetPageBoundingBox(DocumentRectangle * dr,const DocumentGeometry * dg,int hasHeader,int hasFooter)172 void utilDocumentGeometryGetPageBoundingBox(
173 DocumentRectangle * dr,
174 const DocumentGeometry * dg,
175 int hasHeader,
176 int hasFooter )
177 {
178 utilDocumentGeometryGetBodyRect( dr, dg );
179
180 if ( hasHeader )
181 {
182 DocumentRectangle drHead;
183
184 utilDocumentGeometryGetHeaderRect( &drHead, dg );
185 geoUnionRectangle( dr, dr, &drHead );
186 }
187
188 if ( hasFooter )
189 {
190 DocumentRectangle drFoot;
191
192 utilDocumentGeometryGetFooterRect( &drFoot, dg );
193 geoUnionRectangle( dr, dr, &drFoot );
194 }
195 }
196
utilOverridePaperSize(DocumentGeometry * dgTo,const DocumentGeometry * dgFrom)197 void utilOverridePaperSize( DocumentGeometry * dgTo,
198 const DocumentGeometry * dgFrom )
199 {
200 if ( dgTo->dgPageWideTwips > dgTo->dgPageHighTwips &&
201 dgFrom->dgPageHighTwips > dgFrom->dgPageWideTwips )
202 {
203 dgTo->dgPageWideTwips= dgFrom->dgPageHighTwips;
204 dgTo->dgPageHighTwips= dgFrom->dgPageWideTwips;
205 }
206 else{
207 dgTo->dgPageWideTwips= dgFrom->dgPageWideTwips;
208 dgTo->dgPageHighTwips= dgFrom->dgPageHighTwips;
209 }
210 }
211
212