Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / inc / drawfont.hxx
blob9a02e881e10e9d0f35311fafc753057884b9ea59
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_DRAWFONT_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_DRAWFONT_HXX
23 #include <osl/diagnose.h>
24 #include <vcl/vclptr.hxx>
25 #include <vcl/outdev.hxx>
26 #include <swtypes.hxx>
27 #include "TextFrameIndex.hxx"
28 #include <swdllapi.h>
30 class SwTextFrame;
31 class SwViewShell;
32 class SwScriptInfo;
33 namespace sw { class WrongListIterator; }
34 class SwFont;
35 namespace vcl {
36 class Font;
37 namespace text {
38 class TextLayoutCache;
40 typedef OutputDevice RenderContext;
42 class SwUnderlineFont;
44 // encapsulates information for drawing text
45 class SW_DLLPUBLIC SwDrawTextInfo
47 const SwTextFrame* m_pFrame;
48 VclPtr<OutputDevice> m_pOut;
49 SwViewShell const * m_pSh;
50 const SwScriptInfo* m_pScriptInfo;
51 Point m_aPos;
52 vcl::text::TextLayoutCache const* m_pCachedVclData;
53 OUString m_aText;
54 sw::WrongListIterator* m_pWrong;
55 sw::WrongListIterator* m_pGrammarCheck;
56 sw::WrongListIterator* m_pSmartTags;
57 Size m_aSize;
58 SwFont *m_pFnt;
59 SwUnderlineFont* m_pUnderFnt;
60 TextFrameIndex* m_pHyphPos;
61 tools::Long m_nKanaDiff;
62 TextFrameIndex m_nIdx;
63 TextFrameIndex m_nLen;
64 TextFrameIndex m_nMeasureLen;
65 /// this is not a string index
66 sal_Int32 m_nOfst;
67 sal_uInt16 m_nWidth;
68 sal_uInt16 m_nAscent;
69 sal_uInt16 m_nCompress;
70 tools::Long m_nCharacterSpacing;
71 tools::Long m_nSpace;
72 tools::Long m_nKern;
73 TextFrameIndex m_nNumberOfBlanks;
74 sal_uInt8 m_nCursorBidiLevel;
75 bool m_bBullet : 1;
76 bool m_bUpper : 1; // for small caps: upper case flag
77 bool m_bDrawSpace : 1; // for small caps: underline/ line through
78 bool m_bGreyWave : 1; // grey wave line for extended text input
79 // For underlining we need to know, if a section is right in front of a
80 // whole block or a fix margin section.
81 bool m_bSpaceStop : 1;
82 bool m_bSnapToGrid : 1; // Does paragraph snap to grid?
83 // Paint text as if text has LTR direction, used for line numbering
84 bool m_bIgnoreFrameRTL : 1;
85 // GetModelPositionForViewPoint should not return the next position if screen position is
86 // inside second half of bound rect, used for Accessibility
87 bool m_bPosMatchesBounds :1;
89 public:
91 #ifdef DBG_UTIL
92 // These flags should control that the appropriate Set-function has been
93 // called before calling the Get-function of a member
94 bool m_bPos : 1;
95 bool m_bWrong : 1;
96 bool m_bGrammarCheck : 1;
97 bool m_bSize : 1;
98 bool m_bFnt : 1;
99 bool m_bHyph : 1;
100 bool m_bKana : 1;
101 bool m_bOfst : 1;
102 bool m_bAscent: 1;
103 bool m_bCharacterSpacing : 1;
104 bool m_bSpace : 1;
105 bool m_bNumberOfBlanks : 1;
106 bool m_bUppr : 1;
107 bool m_bDrawSp: 1;
108 #endif
110 /// constructor for simple strings
111 SwDrawTextInfo( SwViewShell const *pSh, OutputDevice &rOut,
112 const OUString &rText, sal_Int32 const nIdx, sal_Int32 const nLen,
113 sal_uInt16 nWidth = 0, bool bBullet = false)
114 : SwDrawTextInfo(pSh, rOut, nullptr, rText, TextFrameIndex(nIdx), TextFrameIndex(nLen), nWidth, bBullet)
116 /// constructor for text frame contents
117 SwDrawTextInfo( SwViewShell const *pSh, OutputDevice &rOut, const SwScriptInfo* pSI,
118 const OUString &rText, TextFrameIndex const nIdx, TextFrameIndex const nLen,
119 sal_uInt16 nWidth = 0, bool bBullet = false,
120 vcl::text::TextLayoutCache const*const pCachedVclData = nullptr)
121 : m_pCachedVclData(pCachedVclData)
123 assert( (nLen == TextFrameIndex(COMPLETE_STRING)) ? (nIdx.get() < rText.getLength()) : (nIdx + nLen).get() <= rText.getLength() );
124 m_pFrame = nullptr;
125 m_pSh = pSh;
126 m_pOut = &rOut;
127 m_pScriptInfo = pSI;
128 m_aText = rText;
129 m_nIdx = nIdx;
130 m_nLen = nLen;
131 m_nMeasureLen = TextFrameIndex(COMPLETE_STRING);
132 m_nKern = 0;
133 m_nCompress = 0;
134 m_nWidth = nWidth;
135 m_nNumberOfBlanks = TextFrameIndex(0);
136 m_nCursorBidiLevel = 0;
137 m_bBullet = bBullet;
138 m_pUnderFnt = nullptr;
139 m_bGreyWave = false;
140 m_bSpaceStop = false;
141 m_bSnapToGrid = false;
142 m_bIgnoreFrameRTL = false;
143 m_bPosMatchesBounds = false;
145 // These values are initialized but have to be set explicitly via their
146 // Set-function before they may be accessed by their Get-function:
147 m_pWrong = nullptr;
148 m_pGrammarCheck = nullptr;
149 m_pSmartTags = nullptr;
150 m_pFnt = nullptr;
151 m_pHyphPos = nullptr;
152 m_nKanaDiff = 0;
153 m_nOfst = 0;
154 m_nAscent = 0;
155 m_nCharacterSpacing = 0;
156 m_nSpace = 0;
157 m_bUpper = false;
158 m_bDrawSpace = false;
160 #ifdef DBG_UTIL
161 // these flags control whether the matching member variables have been
162 // set by using the Set-function before they may be accessed by their
163 // Get-function:
164 m_bPos = m_bWrong = m_bGrammarCheck = m_bSize = m_bFnt = m_bAscent =
165 m_bSpace = m_bNumberOfBlanks = m_bUppr =
166 m_bDrawSp = m_bKana = m_bOfst = m_bHyph =
167 m_bCharacterSpacing = false;
168 #endif
171 const SwTextFrame* GetFrame() const
173 return m_pFrame;
176 void SetFrame( const SwTextFrame* pNewFrame )
178 m_pFrame = pNewFrame;
181 SwViewShell const *GetShell() const
183 return m_pSh;
186 vcl::RenderContext& GetOut() const
188 return *m_pOut;
191 vcl::RenderContext *GetpOut() const
193 return m_pOut;
196 const SwScriptInfo* GetScriptInfo() const
198 return m_pScriptInfo;
201 const Point &GetPos() const
203 #ifdef DBG_UTIL
204 OSL_ENSURE( m_bPos, "DrawTextInfo: Undefined Position" );
205 #endif
206 return m_aPos;
209 TextFrameIndex *GetHyphPos() const
211 #ifdef DBG_UTIL
212 OSL_ENSURE( m_bHyph, "DrawTextInfo: Undefined Hyph Position" );
213 #endif
214 return m_pHyphPos;
217 vcl::text::TextLayoutCache const* GetVclCache() const
219 return m_pCachedVclData;
222 const OUString &GetText() const
224 return m_aText;
227 sw::WrongListIterator* GetWrong() const
229 #ifdef DBG_UTIL
230 OSL_ENSURE( m_bWrong, "DrawTextInfo: Undefined WrongList" );
231 #endif
232 return m_pWrong;
235 sw::WrongListIterator* GetGrammarCheck() const
237 #ifdef DBG_UTIL
238 OSL_ENSURE( m_bGrammarCheck, "DrawTextInfo: Undefined GrammarCheck List" );
239 #endif
240 return m_pGrammarCheck;
243 sw::WrongListIterator* GetSmartTags() const
245 return m_pSmartTags;
248 const Size &GetSize() const
250 #ifdef DBG_UTIL
251 OSL_ENSURE( m_bSize, "DrawTextInfo: Undefined Size" );
252 #endif
253 return m_aSize;
256 SwFont* GetFont() const
258 #ifdef DBG_UTIL
259 OSL_ENSURE( m_bFnt, "DrawTextInfo: Undefined Font" );
260 #endif
261 return m_pFnt;
264 SwUnderlineFont* GetUnderFnt() const
266 return m_pUnderFnt;
269 TextFrameIndex GetIdx() const
271 return m_nIdx;
274 TextFrameIndex GetLen() const
276 return m_nLen;
279 TextFrameIndex GetMeasureLen() const
281 return m_nMeasureLen;
284 sal_Int32 GetOffset() const
286 #ifdef DBG_UTIL
287 OSL_ENSURE( m_bOfst, "DrawTextInfo: Undefined Offset" );
288 #endif
289 return m_nOfst;
292 TextFrameIndex GetEnd() const
294 return m_nIdx + m_nLen;
297 tools::Long GetKanaDiff() const
299 #ifdef DBG_UTIL
300 OSL_ENSURE( m_bKana, "DrawTextInfo: Undefined kana difference" );
301 #endif
302 return m_nKanaDiff;
305 sal_uInt16 GetWidth() const
307 return m_nWidth;
310 sal_uInt16 GetAscent() const
312 #ifdef DBG_UTIL
313 OSL_ENSURE( m_bAscent, "DrawTextInfo: Undefined Ascent" );
314 #endif
315 return m_nAscent;
318 sal_uInt16 GetKanaComp() const
320 return m_nCompress;
323 tools::Long GetCharacterSpacing() const
325 #ifdef DBG_UTIL
326 OSL_ENSURE( m_bCharacterSpacing, "DrawTextInfo: Undefined CharacterSpacing" );
327 #endif
328 return m_nCharacterSpacing;
331 tools::Long GetKern() const
333 return m_nKern;
336 tools::Long GetSpace() const
338 #ifdef DBG_UTIL
339 OSL_ENSURE( m_bSpace, "DrawTextInfo: Undefined Spacing" );
340 #endif
341 return m_nSpace;
344 TextFrameIndex GetNumberOfBlanks() const
346 #ifdef DBG_UTIL
347 OSL_ENSURE( m_bNumberOfBlanks, "DrawTextInfo::Undefined NumberOfBlanks" );
348 #endif
349 return m_nNumberOfBlanks;
352 sal_uInt8 GetCursorBidiLevel() const
354 return m_nCursorBidiLevel;
357 bool GetBullet() const
359 return m_bBullet;
362 bool GetUpper() const
364 #ifdef DBG_UTIL
365 OSL_ENSURE( m_bUppr, "DrawTextInfo: Undefined Upperflag" );
366 #endif
367 return m_bUpper;
370 bool GetDrawSpace() const
372 #ifdef DBG_UTIL
373 OSL_ENSURE( m_bDrawSp, "DrawTextInfo: Undefined DrawSpaceflag" );
374 #endif
375 return m_bDrawSpace;
378 bool GetGreyWave() const
380 return m_bGreyWave;
383 bool IsSpaceStop() const
385 return m_bSpaceStop;
388 bool SnapToGrid() const
390 return m_bSnapToGrid;
393 bool IsIgnoreFrameRTL() const
395 return m_bIgnoreFrameRTL;
398 bool IsPosMatchesBounds() const
400 return m_bPosMatchesBounds;
403 void SetOut( OutputDevice &rNew )
405 m_pOut = &rNew;
408 void SetPos( const Point &rNew )
410 m_aPos = rNew;
411 #ifdef DBG_UTIL
412 m_bPos = true;
413 #endif
416 void SetHyphPos(TextFrameIndex *const pNew)
418 m_pHyphPos = pNew;
419 #ifdef DBG_UTIL
420 m_bHyph = true;
421 #endif
424 void SetText( const OUString &rNew )
426 assert( (m_nLen == TextFrameIndex(COMPLETE_STRING)) ? (m_nIdx.get() < rNew.getLength()) : (m_nIdx + m_nLen).get() <= rNew.getLength() );
427 m_aText = rNew;
428 m_pCachedVclData = nullptr; // would any case benefit from save/restore?
431 // These methods are here so we can set all the related fields together to preserve the invariants that we assert
432 void SetTextIdxLen( const OUString &rNewStr, TextFrameIndex const nNewIdx, TextFrameIndex const nNewLen )
434 assert( (nNewLen == TextFrameIndex(COMPLETE_STRING)) ? (nNewIdx.get() < rNewStr.getLength()) : (nNewIdx + nNewLen).get() <= rNewStr.getLength() );
435 m_aText = rNewStr;
436 m_nIdx = nNewIdx;
437 m_nLen = nNewLen;
438 m_pCachedVclData = nullptr; // would any case benefit from save/restore?
441 // These methods are here so we can set all the related fields together to preserve the invariants that we assert
442 void SetIdxLen( TextFrameIndex const nNewIdx, TextFrameIndex const nNewLen )
444 assert( (nNewLen == TextFrameIndex(COMPLETE_STRING)) ? (nNewIdx.get() < m_aText.getLength()) : (nNewIdx + nNewLen).get() <= m_aText.getLength() );
445 m_nIdx = nNewIdx;
446 m_nLen = nNewLen;
449 void SetWrong(sw::WrongListIterator *const pNew)
451 m_pWrong = pNew;
452 #ifdef DBG_UTIL
453 m_bWrong = true;
454 #endif
457 void SetGrammarCheck(sw::WrongListIterator *const pNew)
459 m_pGrammarCheck = pNew;
460 #ifdef DBG_UTIL
461 m_bGrammarCheck = true;
462 #endif
465 void SetSmartTags(sw::WrongListIterator *const pNew)
467 m_pSmartTags = pNew;
470 void SetSize( const Size &rNew )
472 m_aSize = rNew;
473 #ifdef DBG_UTIL
474 m_bSize = true;
475 #endif
478 void SetFont( SwFont* pNew )
480 m_pFnt = pNew;
481 #ifdef DBG_UTIL
482 m_bFnt = true;
483 #endif
486 void SetIdx(TextFrameIndex const nNew)
488 assert( (m_nLen == TextFrameIndex(COMPLETE_STRING)) ? (nNew.get() < m_aText.getLength()) : (nNew + m_nLen).get() <= m_aText.getLength() );
489 m_nIdx = nNew;
492 void SetLen(TextFrameIndex const nNew)
494 assert( (nNew == TextFrameIndex(COMPLETE_STRING)) ? (m_nIdx.get() < m_aText.getLength()) : (m_nIdx + nNew).get() <= m_aText.getLength() );
495 m_nLen = nNew;
498 void SetMeasureLen(TextFrameIndex const nNew)
500 assert( nNew == TextFrameIndex(COMPLETE_STRING) || nNew <= m_nLen );
501 m_nMeasureLen = nNew;
504 void SetOffset( sal_Int32 nNew )
506 m_nOfst = nNew;
507 #ifdef DBG_UTIL
508 m_bOfst = true;
509 #endif
512 void SetKanaDiff( tools::Long nNew )
514 m_nKanaDiff = nNew;
515 #ifdef DBG_UTIL
516 m_bKana = true;
517 #endif
520 void SetWidth( sal_uInt16 nNew )
522 m_nWidth = nNew;
525 void SetAscent( sal_uInt16 nNew )
527 m_nAscent = nNew;
528 #ifdef DBG_UTIL
529 m_bAscent = true;
530 #endif
533 void SetKern( tools::Long nNew )
535 m_nKern = nNew;
538 void SetSpace( tools::Long nNew )
540 if( nNew < 0 )
542 m_nCharacterSpacing = -nNew;
543 m_nSpace = 0;
545 else
547 m_nSpace = nNew;
548 m_nCharacterSpacing = 0;
550 #ifdef DBG_UTIL
551 m_bSpace = true;
552 m_bCharacterSpacing = true;
553 #endif
556 void SetNumberOfBlanks( TextFrameIndex const nNew )
558 #ifdef DBG_UTIL
559 m_bNumberOfBlanks = true;
560 #endif
561 m_nNumberOfBlanks = nNew;
564 void SetCursorBidiLevel( sal_uInt8 nNew )
566 m_nCursorBidiLevel = nNew;
569 void SetKanaComp( short nNew )
571 m_nCompress = nNew;
574 void SetBullet( bool bNew )
576 m_bBullet = bNew;
579 void SetUnderFnt( SwUnderlineFont* pULFnt )
581 m_pUnderFnt = pULFnt;
584 void SetUpper( bool bNew )
586 m_bUpper = bNew;
587 #ifdef DBG_UTIL
588 m_bUppr = true;
589 #endif
592 void SetDrawSpace( bool bNew )
594 m_bDrawSpace = bNew;
595 #ifdef DBG_UTIL
596 m_bDrawSp = true;
597 #endif
600 void SetGreyWave( bool bNew )
602 m_bGreyWave = bNew;
605 void SetSpaceStop( bool bNew )
607 m_bSpaceStop = bNew;
610 void SetSnapToGrid( bool bNew )
612 m_bSnapToGrid = bNew;
615 void SetIgnoreFrameRTL( bool bNew )
617 m_bIgnoreFrameRTL = bNew;
620 void SetPosMatchesBounds( bool bNew )
622 m_bPosMatchesBounds = bNew;
625 void Shift( Degree10 nDir );
627 // sets a new color at the output device if necessary if a font is passed
628 // as argument, the change if made to the font otherwise the font at the
629 // output device is changed returns if the font has been changed
630 bool ApplyAutoColor( vcl::Font* pFnt = nullptr );
633 #endif
635 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */