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 "TextFrameIndex.hxx"
32 namespace sw
{ class WrongListIterator
; }
36 class TextLayoutCache
;
37 typedef OutputDevice RenderContext
;
39 class SwUnderlineFont
;
41 // encapsulates information for drawing text
42 class SW_DLLPUBLIC SwDrawTextInfo
44 const SwTextFrame
* m_pFrame
;
45 VclPtr
<OutputDevice
> m_pOut
;
46 SwViewShell
const * m_pSh
;
47 const SwScriptInfo
* m_pScriptInfo
;
49 vcl::TextLayoutCache
const* m_pCachedVclData
;
51 sw::WrongListIterator
* m_pWrong
;
52 sw::WrongListIterator
* m_pGrammarCheck
;
53 sw::WrongListIterator
* m_pSmartTags
;
56 SwUnderlineFont
* m_pUnderFnt
;
57 TextFrameIndex
* m_pHyphPos
;
58 tools::Long m_nKanaDiff
;
59 TextFrameIndex m_nIdx
;
60 TextFrameIndex m_nLen
;
61 /// this is not a string index
65 sal_uInt16 m_nCompress
;
66 tools::Long m_nSperren
;
69 TextFrameIndex m_nNumberOfBlanks
;
70 sal_uInt8 m_nCursorBidiLevel
;
72 bool m_bUpper
: 1; // for small caps: upper case flag
73 bool m_bDrawSpace
: 1; // for small caps: underline/ line through
74 bool m_bGreyWave
: 1; // grey wave line for extended text input
75 // For underlining we need to know, if a section is right in front of a
76 // whole block or a fix margin section.
77 bool m_bSpaceStop
: 1;
78 bool m_bSnapToGrid
: 1; // Does paragraph snap to grid?
79 // Paint text as if text has LTR direction, used for line numbering
80 bool m_bIgnoreFrameRTL
: 1;
81 // GetModelPositionForViewPoint should not return the next position if screen position is
82 // inside second half of bound rect, used for Accessibility
83 bool m_bPosMatchesBounds
:1;
88 // These flags should control that the appropriate Set-function has been
89 // called before calling the Get-function of a member
92 bool m_bGrammarCheck
: 1;
101 bool m_bNumberOfBlanks
: 1;
106 /// constructor for simple strings
107 SwDrawTextInfo( SwViewShell
const *pSh
, OutputDevice
&rOut
,
108 const OUString
&rText
, sal_Int32
const nIdx
, sal_Int32
const nLen
,
109 sal_uInt16 nWidth
= 0, bool bBullet
= false)
110 : SwDrawTextInfo(pSh
, rOut
, nullptr, rText
, TextFrameIndex(nIdx
), TextFrameIndex(nLen
), nWidth
, bBullet
)
112 /// constructor for text frame contents
113 SwDrawTextInfo( SwViewShell
const *pSh
, OutputDevice
&rOut
, const SwScriptInfo
* pSI
,
114 const OUString
&rText
, TextFrameIndex
const nIdx
, TextFrameIndex
const nLen
,
115 sal_uInt16 nWidth
= 0, bool bBullet
= false,
116 vcl::TextLayoutCache
const*const pCachedVclData
= nullptr)
117 : m_pCachedVclData(pCachedVclData
)
129 m_nNumberOfBlanks
= TextFrameIndex(0);
130 m_nCursorBidiLevel
= 0;
132 m_pUnderFnt
= nullptr;
134 m_bSpaceStop
= false;
135 m_bSnapToGrid
= false;
136 m_bIgnoreFrameRTL
= false;
137 m_bPosMatchesBounds
= false;
139 // These values are initialized but have to be set explicitly via their
140 // Set-function before they may be accessed by their Get-function:
142 m_pGrammarCheck
= nullptr;
143 m_pSmartTags
= nullptr;
145 m_pHyphPos
= nullptr;
152 m_bDrawSpace
= false;
155 // these flags control whether the matching member variables have been
156 // set by using the Set-function before they may be accessed by their
158 m_bPos
= m_bWrong
= m_bGrammarCheck
= m_bSize
= m_bFnt
= m_bAscent
=
159 m_bSpace
= m_bNumberOfBlanks
= m_bUppr
=
160 m_bDrawSp
= m_bKana
= m_bOfst
= m_bHyph
=
165 const SwTextFrame
* GetFrame() const
170 void SetFrame( const SwTextFrame
* pNewFrame
)
172 m_pFrame
= pNewFrame
;
175 SwViewShell
const *GetShell() const
180 vcl::RenderContext
& GetOut() const
185 vcl::RenderContext
*GetpOut() const
190 const SwScriptInfo
* GetScriptInfo() const
192 return m_pScriptInfo
;
195 const Point
&GetPos() const
198 OSL_ENSURE( m_bPos
, "DrawTextInfo: Undefined Position" );
203 TextFrameIndex
*GetHyphPos() const
206 OSL_ENSURE( m_bHyph
, "DrawTextInfo: Undefined Hyph Position" );
211 vcl::TextLayoutCache
const* GetVclCache() const
213 return m_pCachedVclData
;
216 const OUString
&GetText() const
221 sw::WrongListIterator
* GetWrong() const
224 OSL_ENSURE( m_bWrong
, "DrawTextInfo: Undefined WrongList" );
229 sw::WrongListIterator
* GetGrammarCheck() const
232 OSL_ENSURE( m_bGrammarCheck
, "DrawTextInfo: Undefined GrammarCheck List" );
234 return m_pGrammarCheck
;
237 sw::WrongListIterator
* GetSmartTags() const
242 const Size
&GetSize() const
245 OSL_ENSURE( m_bSize
, "DrawTextInfo: Undefined Size" );
250 SwFont
* GetFont() const
253 OSL_ENSURE( m_bFnt
, "DrawTextInfo: Undefined Font" );
258 SwUnderlineFont
* GetUnderFnt() const
263 TextFrameIndex
GetIdx() const
268 TextFrameIndex
GetLen() const
273 sal_Int32
GetOffset() const
276 OSL_ENSURE( m_bOfst
, "DrawTextInfo: Undefined Offset" );
281 TextFrameIndex
GetEnd() const
283 return m_nIdx
+ m_nLen
;
286 tools::Long
GetKanaDiff() const
289 OSL_ENSURE( m_bKana
, "DrawTextInfo: Undefined kana difference" );
294 sal_uInt16
GetWidth() const
299 sal_uInt16
GetAscent() const
302 OSL_ENSURE( m_bAscent
, "DrawTextInfo: Undefined Ascent" );
307 sal_uInt16
GetKanaComp() const
312 tools::Long
GetSperren() const
315 OSL_ENSURE( m_bSperr
, "DrawTextInfo: Undefined >Sperren<" );
320 tools::Long
GetKern() const
325 tools::Long
GetSpace() const
328 OSL_ENSURE( m_bSpace
, "DrawTextInfo: Undefined Spacing" );
333 TextFrameIndex
GetNumberOfBlanks() const
336 OSL_ENSURE( m_bNumberOfBlanks
, "DrawTextInfo::Undefined NumberOfBlanks" );
338 return m_nNumberOfBlanks
;
341 sal_uInt8
GetCursorBidiLevel() const
343 return m_nCursorBidiLevel
;
346 bool GetBullet() const
351 bool GetUpper() const
354 OSL_ENSURE( m_bUppr
, "DrawTextInfo: Undefined Upperflag" );
359 bool GetDrawSpace() const
362 OSL_ENSURE( m_bDrawSp
, "DrawTextInfo: Undefined DrawSpaceflag" );
367 bool GetGreyWave() const
372 bool IsSpaceStop() const
377 bool SnapToGrid() const
379 return m_bSnapToGrid
;
382 bool IsIgnoreFrameRTL() const
384 return m_bIgnoreFrameRTL
;
387 bool IsPosMatchesBounds() const
389 return m_bPosMatchesBounds
;
392 void SetOut( OutputDevice
&rNew
)
397 void SetPos( const Point
&rNew
)
405 void SetHyphPos(TextFrameIndex
*const pNew
)
413 void SetText( const OUString
&rNew
)
416 m_pCachedVclData
= nullptr; // would any case benefit from save/restore?
419 void SetWrong(sw::WrongListIterator
*const pNew
)
427 void SetGrammarCheck(sw::WrongListIterator
*const pNew
)
429 m_pGrammarCheck
= pNew
;
431 m_bGrammarCheck
= true;
435 void SetSmartTags(sw::WrongListIterator
*const pNew
)
440 void SetSize( const Size
&rNew
)
448 void SetFont( SwFont
* pNew
)
456 void SetIdx(TextFrameIndex
const nNew
)
461 void SetLen(TextFrameIndex
const nNew
)
466 void SetOffset( sal_Int32 nNew
)
474 void SetKanaDiff( tools::Long nNew
)
482 void SetWidth( sal_uInt16 nNew
)
487 void SetAscent( sal_uInt16 nNew
)
495 void SetKern( tools::Long nNew
)
500 void SetSpace( tools::Long nNew
)
518 void SetNumberOfBlanks( TextFrameIndex
const nNew
)
521 m_bNumberOfBlanks
= true;
523 m_nNumberOfBlanks
= nNew
;
526 void SetCursorBidiLevel( sal_uInt8 nNew
)
528 m_nCursorBidiLevel
= nNew
;
531 void SetKanaComp( short nNew
)
536 void SetBullet( bool bNew
)
541 void SetUnderFnt( SwUnderlineFont
* pULFnt
)
543 m_pUnderFnt
= pULFnt
;
546 void SetUpper( bool bNew
)
554 void SetDrawSpace( bool bNew
)
562 void SetGreyWave( bool bNew
)
567 void SetSpaceStop( bool bNew
)
572 void SetSnapToGrid( bool bNew
)
574 m_bSnapToGrid
= bNew
;
577 void SetIgnoreFrameRTL( bool bNew
)
579 m_bIgnoreFrameRTL
= bNew
;
582 void SetPosMatchesBounds( bool bNew
)
584 m_bPosMatchesBounds
= bNew
;
587 void Shift( Degree10 nDir
);
589 // sets a new color at the output device if necessary if a font is passed
590 // as argument, the change if made to the font otherwise the font at the
591 // output device is changed returns if the font has been changed
592 bool ApplyAutoColor( vcl::Font
* pFnt
= nullptr );
597 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */