xref: /aoo41x/main/sw/source/core/inc/drawfont.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef	_DRAWFONT_HXX
24 #define	_DRAWFONT_HXX
25 
26 #include <tools/solar.h>
27 #include <tools/string.hxx>
28 #include <errhdl.hxx>
29 
30 class SwTxtFrm;
31 class OutputDevice;
32 class ViewShell;
33 class SwScriptInfo;
34 class Point;
35 class SwWrongList;
36 class Size;
37 class SwFont;
38 class Font;
39 class SwUnderlineFont;
40 
41 /*************************************************************************
42  *                      class SwDrawTextInfo
43  *
44  * encapsulates information for drawing text
45  *************************************************************************/
46 
47 class SwDrawTextInfo
48 {
49     const SwTxtFrm* pFrm;
50 	OutputDevice* pOut;
51 	ViewShell* pSh;
52     const SwScriptInfo* pScriptInfo;
53 	const Point* pPos;
54 	const XubString* pText;
55 	const SwWrongList* pWrong;
56     const SwWrongList* pGrammarCheck;
57     const SwWrongList* pSmartTags; // SMARTTAGS
58     const Size* pSize;
59 	SwFont *pFnt;
60     SwUnderlineFont* pUnderFnt;
61 	xub_StrLen* pHyphPos;
62     long nLeft;
63 	long nRight;
64 	long nKanaDiff;
65 	xub_StrLen nIdx;
66 	xub_StrLen nLen;
67     xub_StrLen nOfst;
68 	sal_uInt16 nWidth;
69 	sal_uInt16 nAscent;
70     sal_uInt16 nCompress;
71     long nSperren;
72     long nSpace;
73     long nKern;
74     xub_StrLen nNumberOfBlanks;
75     sal_uInt8 nCursorBidiLevel;
76 	sal_Bool bBullet : 1;
77 	sal_Bool bUpper : 1;		// Fuer Kapitaelchen: Grossbuchstaben-Flag
78 	sal_Bool bDrawSpace : 1;	// Fuer Kapitaelchen: Unter/Durchstreichung
79 	sal_Bool bGreyWave	: 1;	// Graue Wellenlinie beim extended TextInput
80     sal_Bool bSpaceStop : 1;    // For underlining we need to know, if a portion
81                             // is right in front of a hole portion or a
82                             // fix margin portion.
83     sal_Bool bSnapToGrid : 1;   // Does paragraph snap to grid?
84     sal_Bool bIgnoreFrmRTL : 1; // Paint text as if text has LTR direction, used for
85                             // line numbering
86     sal_Bool bPosMatchesBounds :1;  // GetCrsrOfst should not return the next
87                                 // position if screen position is inside second
88                                 // half of bound rect, used for Accessibility
89 
90     SwDrawTextInfo();       // nicht zulaessig
91 public:
92 
93 #ifdef DBG_UTIL
94     sal_Bool bPos   : 1;            // These flags should control, that the appropriate
95     sal_Bool bWrong : 1;            // Set-function has been called before calling
96     sal_Bool bGrammarCheck : 1;     //  the Get-function of a member
97     sal_Bool bSize  : 1;
98     sal_Bool bFnt   : 1;
99     sal_Bool bHyph  : 1;
100     sal_Bool bLeft  : 1;
101     sal_Bool bRight : 1;
102     sal_Bool bKana  : 1;
103     sal_Bool bOfst  : 1;
104     sal_Bool bAscent: 1;
105 	sal_Bool bSperr : 1;
106     sal_Bool bSpace : 1;
107     sal_Bool bNumberOfBlanks : 1;
108     sal_Bool bUppr  : 1;
109 	sal_Bool bDrawSp: 1;
110 #endif
111 
SwDrawTextInfo(ViewShell * pS,OutputDevice & rO,const SwScriptInfo * pSI,const XubString & rSt,xub_StrLen nI,xub_StrLen nL,sal_uInt16 nW=0,sal_Bool bB=sal_False)112     SwDrawTextInfo( ViewShell *pS, OutputDevice &rO, const SwScriptInfo* pSI,
113 					const XubString &rSt, xub_StrLen nI, xub_StrLen nL,
114                     sal_uInt16 nW = 0, sal_Bool bB = sal_False )
115     {
116         pFrm = NULL;
117         pSh = pS;
118         pOut = &rO;
119         pScriptInfo = pSI;
120         pText = &rSt;
121         nIdx = nI;
122         nLen = nL;
123         nKern = 0;
124         nCompress = 0;
125         nWidth = nW;
126         nNumberOfBlanks = 0;
127         nCursorBidiLevel = 0;
128         bBullet = bB;
129         pUnderFnt = 0;
130         bGreyWave = sal_False;
131         bSpaceStop = sal_False;
132         bSnapToGrid = sal_False;
133         bIgnoreFrmRTL = sal_False;
134         bPosMatchesBounds = sal_False;
135 
136         // These values are initialized but, they have to be
137         // set explicitly via their Set-function before they may
138         // be accessed by their Get-function:
139         pPos = 0;
140         pWrong = 0;
141         pGrammarCheck = 0;
142         pSmartTags = 0;
143         pSize = 0;
144         pFnt = 0;
145         pHyphPos = 0;
146         nLeft = 0;
147         nRight = 0;
148         nKanaDiff = 0;
149         nOfst = 0;
150         nAscent = 0;
151         nSperren = 0;
152         nSpace = 0;
153         bUpper = sal_False;
154         bDrawSpace = sal_False;
155 
156 #ifdef DBG_UTIL
157         // these flags control, whether the matching member variables have
158         // been set by using the Set-function before they may be accessed
159         // by their Get-function:
160         bPos = bWrong = bGrammarCheck = bSize = bFnt = bAscent = bSpace = bNumberOfBlanks = bUppr =
161         bDrawSp = bLeft = bRight = bKana = bOfst = bHyph = bSperr = sal_False;
162 #endif
163 	}
164 
GetFrm() const165     const SwTxtFrm* GetFrm() const
166     {
167         return pFrm;
168     }
169 
SetFrm(const SwTxtFrm * pNewFrm)170     void SetFrm( const SwTxtFrm* pNewFrm )
171     {
172         pFrm = pNewFrm;
173     }
174 
GetShell() const175     ViewShell *GetShell() const
176     {
177         return pSh;
178     }
179 
GetOut() const180     OutputDevice& GetOut() const
181     {
182         return *pOut;
183 	}
184 
GetpOut() const185     OutputDevice *GetpOut() const
186     {
187         return pOut;
188 	}
189 
GetScriptInfo() const190     const SwScriptInfo* GetScriptInfo() const
191     {
192         return pScriptInfo;
193     }
194 
GetPos() const195     const Point &GetPos() const
196     {
197 		ASSERT( bPos, "DrawTextInfo: Undefined Position" );
198 		return *pPos;
199 	}
200 
GetHyphPos() const201     xub_StrLen *GetHyphPos() const
202     {
203 		ASSERT( bHyph, "DrawTextInfo: Undefined Hyph Position" );
204 		return pHyphPos;
205 	}
206 
GetText() const207     const XubString &GetText() const
208     {
209         return *pText;
210 	}
211 
GetWrong() const212     const SwWrongList* GetWrong() const
213     {
214 		ASSERT( bWrong, "DrawTextInfo: Undefined WrongList" );
215 		return pWrong;
216 	}
217 
GetGrammarCheck() const218     const SwWrongList* GetGrammarCheck() const
219     {
220         ASSERT( bGrammarCheck, "DrawTextInfo: Undefined GrammarCheck List" );
221         return pGrammarCheck;
222     }
223 
GetSmartTags() const224     const SwWrongList* GetSmartTags() const
225     {
226         return pSmartTags;
227     }
228 
GetSize() const229     const Size &GetSize() const
230     {
231 		ASSERT( bSize, "DrawTextInfo: Undefined Size" );
232 		return *pSize;
233 	}
234 
GetFont() const235     SwFont* GetFont() const
236     {
237 		ASSERT( bFnt, "DrawTextInfo: Undefined Font" );
238 		return pFnt;
239 	}
240 
GetUnderFnt() const241     SwUnderlineFont* GetUnderFnt() const
242     {
243         return pUnderFnt;
244 	}
245 
GetIdx() const246     xub_StrLen GetIdx() const
247     {
248         return nIdx;
249 	}
250 
GetLen() const251     xub_StrLen GetLen() const
252     {
253         return nLen;
254 	}
255 
GetOfst() const256     xub_StrLen GetOfst() const
257     {
258         ASSERT( bOfst, "DrawTextInfo: Undefined Offset" );
259 		return nOfst;
260 	}
261 
GetEnd() const262     xub_StrLen GetEnd() const
263     {
264         return nIdx + nLen;
265 	}
266 
GetLeft() const267     long GetLeft() const
268     {
269 		ASSERT( bLeft, "DrawTextInfo: Undefined left range" );
270 		return nLeft;
271 	}
272 
GetRight() const273     long GetRight() const
274     {
275 		ASSERT( bRight, "DrawTextInfo: Undefined right range" );
276 		return nRight;
277 	}
278 
GetKanaDiff() const279     long GetKanaDiff() const
280     {
281 		ASSERT( bKana, "DrawTextInfo: Undefined kana difference" );
282 		return nKanaDiff;
283 	}
284 
GetWidth() const285     sal_uInt16 GetWidth() const
286     {
287         return nWidth;
288 	}
289 
GetAscent() const290     sal_uInt16 GetAscent() const
291     {
292 		ASSERT( bAscent, "DrawTextInfo: Undefined Ascent" );
293 		return nAscent;
294 	}
295 
GetKanaComp() const296     sal_uInt16 GetKanaComp() const
297     {
298         return nCompress;
299 	}
300 
GetSperren() const301     long GetSperren() const
302     {
303 		ASSERT( bSperr, "DrawTextInfo: Undefined >Sperren<" );
304 		return nSperren;
305 	}
306 
GetKern() const307     long GetKern() const
308     {
309         return nKern;
310 	}
311 
GetSpace() const312     long GetSpace() const
313     {
314 		ASSERT( bSpace, "DrawTextInfo: Undefined Spacing" );
315         return nSpace;
316 	}
317 
GetNumberOfBlanks() const318     xub_StrLen GetNumberOfBlanks() const
319     {
320         ASSERT( bNumberOfBlanks, "DrawTextInfo::Undefined NumberOfBlanks" );
321         return nNumberOfBlanks;
322     }
323 
GetCursorBidiLevel() const324     sal_uInt8 GetCursorBidiLevel() const
325     {
326         return nCursorBidiLevel;
327     }
328 
GetBullet() const329     sal_Bool GetBullet() const
330     {
331         return bBullet;
332 	}
333 
GetUpper() const334     sal_Bool GetUpper() const
335     {
336 		ASSERT( bUppr, "DrawTextInfo: Undefined Upperflag" );
337 		return bUpper;
338 	}
339 
GetDrawSpace() const340     sal_Bool GetDrawSpace() const
341     {
342 		ASSERT( bDrawSp, "DrawTextInfo: Undefined DrawSpaceflag" );
343 		return bDrawSpace;
344 	}
345 
GetGreyWave() const346     sal_Bool GetGreyWave() const
347     {
348         return bGreyWave;
349 	}
350 
IsSpaceStop() const351     sal_Bool IsSpaceStop() const
352     {
353         return bSpaceStop;
354 	}
355 
SnapToGrid() const356     sal_Bool SnapToGrid() const
357     {
358         return bSnapToGrid;
359     }
360 
IsIgnoreFrmRTL() const361     sal_Bool IsIgnoreFrmRTL() const
362     {
363         return bIgnoreFrmRTL;
364     }
365 
IsPosMatchesBounds() const366     sal_Bool IsPosMatchesBounds() const
367     {
368         return bPosMatchesBounds;
369     }
370 
SetOut(OutputDevice & rNew)371     void SetOut( OutputDevice &rNew )
372     {
373         pOut = &rNew;
374     }
375 
SetPos(const Point & rNew)376     void SetPos( const Point &rNew )
377     {
378         pPos = &rNew;
379 #ifdef DBG_UTIL
380 		bPos = sal_True;
381 #endif
382 	}
383 
SetHyphPos(xub_StrLen * pNew)384     void SetHyphPos( xub_StrLen *pNew )
385     {
386         pHyphPos = pNew;
387 #ifdef DBG_UTIL
388 		bHyph = sal_True;
389 #endif
390 	}
391 
SetText(const XubString & rNew)392     void SetText( const XubString &rNew )
393     {
394         pText = &rNew;
395     }
396 
SetWrong(const SwWrongList * pNew)397     void SetWrong( const SwWrongList* pNew )
398     {
399         pWrong = pNew;
400 #ifdef DBG_UTIL
401 		bWrong = sal_True;
402 #endif
403 	}
404 
SetGrammarCheck(const SwWrongList * pNew)405     void SetGrammarCheck( const SwWrongList* pNew )
406     {
407         pGrammarCheck = pNew;
408 #ifdef DBG_UTIL
409         bGrammarCheck = sal_True;
410 #endif
411     }
412 
SetSmartTags(const SwWrongList * pNew)413     void SetSmartTags( const SwWrongList* pNew )
414     {
415         pSmartTags = pNew;
416     }
417 
SetSize(const Size & rNew)418     void SetSize( const Size &rNew )
419     {
420         pSize = &rNew;
421 #ifdef DBG_UTIL
422 		bSize = sal_True;
423 #endif
424 	}
425 
SetFont(SwFont * pNew)426     void SetFont( SwFont* pNew )
427     {
428         pFnt = pNew;
429 #ifdef DBG_UTIL
430 		bFnt = sal_True;
431 #endif
432 	}
433 
SetIdx(xub_StrLen nNew)434     void SetIdx( xub_StrLen nNew )
435     {
436         nIdx = nNew;
437     }
438 
SetLen(xub_StrLen nNew)439     void SetLen( xub_StrLen nNew )
440     {
441         nLen = nNew;
442     }
443 
SetOfst(xub_StrLen nNew)444     void SetOfst( xub_StrLen nNew )
445     {
446         nOfst = nNew;
447 #ifdef DBG_UTIL
448 		bOfst = sal_True;
449 #endif
450 	}
451 
SetLeft(long nNew)452     void SetLeft( long nNew )
453     {
454         nLeft = nNew;
455 #ifdef DBG_UTIL
456 		bLeft = sal_True;
457 #endif
458 	}
459 
SetRight(long nNew)460     void SetRight( long nNew )
461     {
462         nRight = nNew;
463 #ifdef DBG_UTIL
464 		bRight = sal_True;
465 #endif
466 	}
467 
SetKanaDiff(long nNew)468     void SetKanaDiff( long nNew )
469     {
470         nKanaDiff = nNew;
471 #ifdef DBG_UTIL
472 		bKana = sal_True;
473 #endif
474 	}
475 
SetWidth(sal_uInt16 nNew)476     void SetWidth( sal_uInt16 nNew )
477     {
478         nWidth = nNew;
479     }
480 
SetAscent(sal_uInt16 nNew)481     void SetAscent( sal_uInt16 nNew )
482     {
483         nAscent = nNew;
484 #ifdef DBG_UTIL
485 		bAscent = sal_True;
486 #endif
487 	}
488 
SetKern(long nNew)489     void SetKern( long nNew )
490     {
491         nKern = nNew;
492     }
493 
SetSpace(long nNew)494     void SetSpace( long nNew )
495     {
496 		if( nNew < 0 )
497 		{
498             nSperren = -nNew;
499             nSpace = 0;
500 		}
501 		else
502 		{
503 			nSpace = nNew;
504             nSperren = 0;
505 		}
506 #ifdef DBG_UTIL
507 		bSpace = sal_True;
508         bSperr = sal_True;
509 #endif
510 	}
511 
SetNumberOfBlanks(xub_StrLen nNew)512     void SetNumberOfBlanks( xub_StrLen nNew )
513     {
514 #ifdef DBG_UTIL
515         bNumberOfBlanks = sal_True;
516 #endif
517         nNumberOfBlanks = nNew;
518     }
519 
SetCursorBidiLevel(sal_uInt8 nNew)520     void SetCursorBidiLevel( sal_uInt8 nNew )
521     {
522         nCursorBidiLevel = nNew;
523     }
524 
SetKanaComp(short nNew)525     void SetKanaComp( short nNew )
526     {
527 		nCompress = nNew;
528 	}
529 
SetBullet(sal_Bool bNew)530     void SetBullet( sal_Bool bNew )
531     {
532         bBullet = bNew;
533     }
534 
SetUnderFnt(SwUnderlineFont * pULFnt)535     void SetUnderFnt( SwUnderlineFont* pULFnt )
536     {
537         pUnderFnt = pULFnt;
538     }
539 
SetUpper(sal_Bool bNew)540     void SetUpper( sal_Bool bNew )
541     {
542         bUpper = bNew;
543 #ifdef DBG_UTIL
544 		bUppr = sal_True;
545 #endif
546 	}
547 
SetDrawSpace(sal_Bool bNew)548     void SetDrawSpace( sal_Bool bNew )
549     {
550         bDrawSpace = bNew;
551 #ifdef DBG_UTIL
552 		bDrawSp = sal_True;
553 #endif
554 	}
555 
SetGreyWave(sal_Bool bNew)556     void SetGreyWave( sal_Bool bNew )
557     {
558         bGreyWave = bNew;
559     }
560 
SetSpaceStop(sal_Bool bNew)561     void SetSpaceStop( sal_Bool bNew )
562     {
563         bSpaceStop = bNew;
564     }
565 
SetSnapToGrid(sal_Bool bNew)566     void SetSnapToGrid( sal_Bool bNew )
567     {
568         bSnapToGrid = bNew;
569     }
570 
SetIgnoreFrmRTL(sal_Bool bNew)571     void SetIgnoreFrmRTL( sal_Bool bNew )
572     {
573         bIgnoreFrmRTL = bNew;
574     }
575 
SetPosMatchesBounds(sal_Bool bNew)576     void SetPosMatchesBounds( sal_Bool bNew )
577     {
578         bPosMatchesBounds = bNew;
579     }
580 
581     void Shift( sal_uInt16 nDir );
582 
583     // sets a new color at the output device if necessary
584     // if a font is passed as argument, the change if made to the font
585     // otherwise the font at the output device is changed
586     // returns if the font has been changed
587     sal_Bool ApplyAutoColor( Font* pFnt = 0 );
588 };
589 
590 #endif
591