1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
33 namespace sw
{ class WrongListIterator
; }
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
;
52 vcl::text::TextLayoutCache
const* m_pCachedVclData
;
54 sw::WrongListIterator
* m_pWrong
;
55 sw::WrongListIterator
* m_pGrammarCheck
;
56 sw::WrongListIterator
* m_pSmartTags
;
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
69 sal_uInt16 m_nCompress
;
70 tools::Long m_nCharacterSpacing
;
73 TextFrameIndex m_nNumberOfBlanks
;
74 sal_uInt8 m_nCursorBidiLevel
;
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;
92 // These flags should control that the appropriate Set-function has been
93 // called before calling the Get-function of a member
96 bool m_bGrammarCheck
: 1;
103 bool m_bCharacterSpacing
: 1;
105 bool m_bNumberOfBlanks
: 1;
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() );
131 m_nMeasureLen
= TextFrameIndex(COMPLETE_STRING
);
135 m_nNumberOfBlanks
= TextFrameIndex(0);
136 m_nCursorBidiLevel
= 0;
138 m_pUnderFnt
= nullptr;
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:
148 m_pGrammarCheck
= nullptr;
149 m_pSmartTags
= nullptr;
151 m_pHyphPos
= nullptr;
155 m_nCharacterSpacing
= 0;
158 m_bDrawSpace
= false;
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
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;
171 const SwTextFrame
* GetFrame() const
176 void SetFrame( const SwTextFrame
* pNewFrame
)
178 m_pFrame
= pNewFrame
;
181 SwViewShell
const *GetShell() const
186 vcl::RenderContext
& GetOut() const
191 vcl::RenderContext
*GetpOut() const
196 const SwScriptInfo
* GetScriptInfo() const
198 return m_pScriptInfo
;
201 const Point
&GetPos() const
204 OSL_ENSURE( m_bPos
, "DrawTextInfo: Undefined Position" );
209 TextFrameIndex
*GetHyphPos() const
212 OSL_ENSURE( m_bHyph
, "DrawTextInfo: Undefined Hyph Position" );
217 vcl::text::TextLayoutCache
const* GetVclCache() const
219 return m_pCachedVclData
;
222 const OUString
&GetText() const
227 sw::WrongListIterator
* GetWrong() const
230 OSL_ENSURE( m_bWrong
, "DrawTextInfo: Undefined WrongList" );
235 sw::WrongListIterator
* GetGrammarCheck() const
238 OSL_ENSURE( m_bGrammarCheck
, "DrawTextInfo: Undefined GrammarCheck List" );
240 return m_pGrammarCheck
;
243 sw::WrongListIterator
* GetSmartTags() const
248 const Size
&GetSize() const
251 OSL_ENSURE( m_bSize
, "DrawTextInfo: Undefined Size" );
256 SwFont
* GetFont() const
259 OSL_ENSURE( m_bFnt
, "DrawTextInfo: Undefined Font" );
264 SwUnderlineFont
* GetUnderFnt() const
269 TextFrameIndex
GetIdx() const
274 TextFrameIndex
GetLen() const
279 TextFrameIndex
GetMeasureLen() const
281 return m_nMeasureLen
;
284 sal_Int32
GetOffset() const
287 OSL_ENSURE( m_bOfst
, "DrawTextInfo: Undefined Offset" );
292 TextFrameIndex
GetEnd() const
294 return m_nIdx
+ m_nLen
;
297 tools::Long
GetKanaDiff() const
300 OSL_ENSURE( m_bKana
, "DrawTextInfo: Undefined kana difference" );
305 sal_uInt16
GetWidth() const
310 sal_uInt16
GetAscent() const
313 OSL_ENSURE( m_bAscent
, "DrawTextInfo: Undefined Ascent" );
318 sal_uInt16
GetKanaComp() const
323 tools::Long
GetCharacterSpacing() const
326 OSL_ENSURE( m_bCharacterSpacing
, "DrawTextInfo: Undefined CharacterSpacing" );
328 return m_nCharacterSpacing
;
331 tools::Long
GetKern() const
336 tools::Long
GetSpace() const
339 OSL_ENSURE( m_bSpace
, "DrawTextInfo: Undefined Spacing" );
344 TextFrameIndex
GetNumberOfBlanks() const
347 OSL_ENSURE( m_bNumberOfBlanks
, "DrawTextInfo::Undefined NumberOfBlanks" );
349 return m_nNumberOfBlanks
;
352 sal_uInt8
GetCursorBidiLevel() const
354 return m_nCursorBidiLevel
;
357 bool GetBullet() const
362 bool GetUpper() const
365 OSL_ENSURE( m_bUppr
, "DrawTextInfo: Undefined Upperflag" );
370 bool GetDrawSpace() const
373 OSL_ENSURE( m_bDrawSp
, "DrawTextInfo: Undefined DrawSpaceflag" );
378 bool GetGreyWave() const
383 bool IsSpaceStop() const
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
)
408 void SetPos( const Point
&rNew
)
416 void SetHyphPos(TextFrameIndex
*const pNew
)
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() );
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() );
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() );
449 void SetWrong(sw::WrongListIterator
*const pNew
)
457 void SetGrammarCheck(sw::WrongListIterator
*const pNew
)
459 m_pGrammarCheck
= pNew
;
461 m_bGrammarCheck
= true;
465 void SetSmartTags(sw::WrongListIterator
*const pNew
)
470 void SetSize( const Size
&rNew
)
478 void SetFont( SwFont
* pNew
)
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() );
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() );
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
)
512 void SetKanaDiff( tools::Long nNew
)
520 void SetWidth( sal_uInt16 nNew
)
525 void SetAscent( sal_uInt16 nNew
)
533 void SetKern( tools::Long nNew
)
538 void SetSpace( tools::Long nNew
)
542 m_nCharacterSpacing
= -nNew
;
548 m_nCharacterSpacing
= 0;
552 m_bCharacterSpacing
= true;
556 void SetNumberOfBlanks( TextFrameIndex
const nNew
)
559 m_bNumberOfBlanks
= true;
561 m_nNumberOfBlanks
= nNew
;
564 void SetCursorBidiLevel( sal_uInt8 nNew
)
566 m_nCursorBidiLevel
= nNew
;
569 void SetKanaComp( short nNew
)
574 void SetBullet( bool bNew
)
579 void SetUnderFnt( SwUnderlineFont
* pULFnt
)
581 m_pUnderFnt
= pULFnt
;
584 void SetUpper( bool bNew
)
592 void SetDrawSpace( bool bNew
)
600 void SetGreyWave( bool bNew
)
605 void SetSpaceStop( bool 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 );
635 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */