1 /************************************************************************/
2 /* */
3 /* Drawing functionality: Utility functions. */
4 /* */
5 /************************************************************************/
6
7 # include "docLayoutConfig.h"
8
9 # include "docDraw.h"
10
11 # include <docTextLine.h>
12 # include <appDebugon.h>
13
14 /************************************************************************/
15 /* */
16 /* Initialise a DrawingContext */
17 /* */
18 /************************************************************************/
19
docInitDrawingContext(DrawingContext * dc)20 void docInitDrawingContext( DrawingContext * dc )
21 {
22 dc->dcCurrentTextAttributeSet= 0;
23 utilInitTextAttribute( &(dc->dcCurrentTextAttribute) );
24
25 dc->dcCurrentColorSet= 0;
26 utilInitRGB8Color( &(dc->dcCurrentColor) );
27
28 layoutInitContext( &(dc->dcLayoutContext) );
29
30 dc->dcClipRect= (DocumentRectangle *)0;
31 dc->dcSelection= (DocumentSelection *)0;
32 dc->dcSelectionGeometry= (SelectionGeometry *)0;
33 dc->dcFirstPage= -1;
34 dc->dcLastPage= -1;
35 dc->dcDrawExternalItems= 0;
36 dc->dcPostponeHeadersFooters= 0;
37 dc->dcDocHasPageHeaders= 0;
38 dc->dcDocHasPageFooters= 0;
39
40 dc->dcDrawTableGrid= 0;
41
42 dc->dcSetColorRgb= (SET_COLOR_RGB)0;
43 dc->dcSetFont= (SET_FONT)0;
44 dc->dcDrawShape= (DRAW_SHAPE)0;
45 dc->dcDrawObject= (DRAW_OBJECT)0;
46 dc->dcStartField= (START_FIELD)0;
47 dc->dcFinishField= (FINISH_FIELD)0;
48 dc->dcDrawTab= (DRAW_TAB)0;
49 dc->dcDrawFtnsep= (DRAW_FTNSEP)0;
50 dc->dcDrawUnderline= (DRAW_UNDERLINE)0;
51 dc->dcDrawStrikethrough= (DRAW_STRIKETHROUGH)0;
52 dc->dcDrawSpan= (DRAW_SPAN)0;
53
54 dc->dcDrawTextLine= (DRAW_TEXT_LINE)0;
55 dc->dcDrawOrnaments= (DRAW_ORNAMENTS)0;
56
57 dc->dcFinishPage= (FINISH_PAGE)0;
58 dc->dcStartPage= (START_PAGE)0;
59 dc->dcInitLayoutExternal= (INIT_LAYOUT_EXTERNAL)0;
60
61 return;
62 }
63
64 /************************************************************************/
65
docInitDrawTextLine(DrawTextLine * dtl)66 void docInitDrawTextLine( DrawTextLine * dtl )
67 {
68 dtl->dtlThrough= (void *)0;
69 dtl->dtlDrawingContext= (DrawingContext *)0;
70
71 docInitLayoutPosition( &(dtl->dtlShiftedTop) );
72 geoInitRectangle( &(dtl->dtlLineRectangle) );
73 docInitLayoutPosition( &(dtl->dtlBaselinePosition) );
74 docInitLayoutPosition( &(dtl->dtlShiftedBaselinePosition) );
75 dtl->dtlXShift= 0;
76 dtl->dtlYShift= 0;
77 dtl->dtlPartUpto= 0;
78 dtl->dtlParticuleData= (const ParticuleData *)0;
79 dtl->dtlTextLine= (const struct TextLine *)0;
80 dtl->dtlParaNode= (struct BufferItem *)0;
81 dtl->dtlParagraphFrame= (ParagraphFrame *)0;
82 dtl->dtlDrawParticulesSeparately= 0;
83 }
84
docSetDrawTextLine(DrawTextLine * dtl,void * through,DrawingContext * dc,const TextLine * tl,const struct BufferItem * paraBi,const BlockOrigin * bo,const ParagraphFrame * pf,const DocumentRectangle * drLine)85 void docSetDrawTextLine( DrawTextLine * dtl,
86 void * through,
87 DrawingContext * dc,
88 const TextLine * tl,
89 const struct BufferItem * paraBi,
90 const BlockOrigin * bo,
91 const ParagraphFrame * pf,
92 const DocumentRectangle * drLine )
93 {
94 dtl->dtlThrough= through;
95 dtl->dtlDrawingContext= dc;
96
97 dtl->dtlTextLine= tl;
98 dtl->dtlPartUpto= tl->tlFirstParticule+ tl->tlParticuleCount;
99 dtl->dtlBaselinePosition= tl->tlTopPosition;
100 dtl->dtlBaselinePosition.lpPageYTwips += TL_BASELINE( tl );
101 dtl->dtlParaNode= paraBi;
102 dtl->dtlXShift= bo->boXShift;
103 dtl->dtlYShift= bo->boYShift;
104 docShiftPosition( &(dtl->dtlShiftedTop), bo, &(tl->tlTopPosition) );
105 dtl->dtlParagraphFrame= pf;
106 dtl->dtlLineRectangle= *drLine;
107 dtl->dtlShiftedBaselinePosition= dtl->dtlShiftedTop;
108 dtl->dtlShiftedBaselinePosition.lpPageYTwips += TL_BASELINE( tl );
109
110 return;
111 }
112
113 /************************************************************************/
114 /* */
115 /* Cause subsequent drawing to be done in a certain color. */
116 /* */
117 /* NOTE that background drawing with color= 0 is against the RTF idea */
118 /* of the default background color: transparent. */
119 /* */
120 /************************************************************************/
121
docDrawSetColorRgb(DrawingContext * dc,void * through,const RGB8Color * rgb8)122 void docDrawSetColorRgb( DrawingContext * dc,
123 void * through,
124 const RGB8Color * rgb8 )
125 {
126 if ( ! dc->dcCurrentColorSet ||
127 dc->dcCurrentColor.rgb8Red != rgb8->rgb8Red ||
128 dc->dcCurrentColor.rgb8Green != rgb8->rgb8Green ||
129 dc->dcCurrentColor.rgb8Blue != rgb8->rgb8Blue )
130 {
131 if ( ! dc->dcSetColorRgb ||
132 (*dc->dcSetColorRgb)( dc, through, rgb8 ) )
133 { LDEB(1); return; }
134
135 dc->dcCurrentColor= *rgb8;
136 dc->dcCurrentColorSet= 1;
137 }
138
139 return;
140 }
141
docDrawSetColorNumber(DrawingContext * dc,void * through,int colorNumber)142 void docDrawSetColorNumber( DrawingContext * dc,
143 void * through,
144 int colorNumber )
145 {
146 const LayoutContext * lc= &(dc->dcLayoutContext);
147 RGB8Color rgb8;
148
149 docGetColorByNumber( &rgb8, lc->lcDocument, colorNumber );
150 docDrawSetColorRgb( dc, through, &rgb8 );
151
152 return;
153 }
154
docDrawSetFont(DrawingContext * dc,void * through,int textAttr,const TextAttribute * newTa)155 void docDrawSetFont( DrawingContext * dc,
156 void * through,
157 int textAttr,
158 const TextAttribute * newTa )
159 {
160 TextAttribute * curTa= &(dc->dcCurrentTextAttribute);
161
162 if ( ! dc->dcCurrentTextAttributeSet ||
163 curTa->taFontNumber != newTa->taFontNumber ||
164 curTa->taFontSizeHalfPoints != newTa->taFontSizeHalfPoints ||
165 curTa->taFontIsBold != newTa->taFontIsBold ||
166 curTa->taFontIsSlanted != newTa->taFontIsSlanted ||
167 curTa->taSmallCaps != newTa->taSmallCaps ||
168 curTa->taSuperSub != newTa->taSuperSub )
169 {
170 if ( ! dc->dcSetFont ||
171 (*dc->dcSetFont)( dc, through, textAttr, newTa ) )
172 { LDEB(1); return; }
173
174 dc->dcCurrentTextAttributeSet= 1;
175 *curTa= *newTa;
176 }
177
178 return;
179 }
180
181