Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / inc / swfont.hxx
blob86f44fb3eb641484eee895ff0fa0c7c919ef4b96
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 .
19 #ifndef INCLUDED_SW_SOURCE_CORE_INC_SWFONT_HXX
20 #define INCLUDED_SW_SOURCE_CORE_INC_SWFONT_HXX
22 #include <memory>
23 #include <i18nlangtag/lang.h>
24 #include <tools/color.hxx>
25 #include <tools/gen.hxx>
26 #include <svl/poolitem.hxx>
27 #include <editeng/svxfont.hxx>
28 #include <swtypes.hxx>
29 #include "drawfont.hxx"
30 #include <editeng/borderline.hxx>
31 #include <optional>
32 #include <o3tl/enumarray.hxx>
34 class SfxItemSet;
35 class SwAttrSet;
36 class SwDoCapitals; // DoCapitals
37 class SwScriptInfo; // GetTextSize_
38 class SwViewShell;
39 class IDocumentSettingAccess;
40 enum class SvxShadowItemSide;
42 const sal_Unicode CH_BLANK = ' '; // ' ' blank spaces
43 const sal_Unicode CH_BREAK = 0x0A;
44 const sal_Unicode CH_TAB = '\t'; // \t
45 constexpr OUStringChar CH_PAR = u'\u00B6'; // paragraph
46 const sal_Unicode CH_BULLET = 0xB7; // centered dot
47 const sal_Unicode CH_FULL_BLANK = 0x3000;
48 const sal_Unicode CH_NB_SPACE = 0xA0;
49 const sal_Unicode CH_SIX_PER_EM = 0x2006; // six-per-em space
51 Degree10 UnMapDirection( Degree10 nDir, const bool bVertFormat, const bool bVertFormatLRBT );
53 class SwSubFont final : public SvxFont
55 friend class SwFont;
56 const void* m_nFontCacheId; // "MagicNumber" within the font cache
57 Size m_aSize; // foreigners only see this size
58 sal_uInt16 m_nFontIndex; // index in the font cache
59 sal_uInt16 m_nOrgHeight; // height including escapement/proportion
60 sal_uInt16 m_nOrgAscent; // ascent including escapement/proportion
61 sal_uInt16 m_nProportionalWidth; // proportional width
62 bool m_bSmallCapsPercentage66;
64 sal_uInt16 CalcEscAscent( const sal_uInt16 nOldAscent ) const;
65 sal_uInt16 CalcEscHeight( const sal_uInt16 nOldHeight,
66 const sal_uInt16 nOldAscent ) const;
67 void CalcEsc( SwDrawTextInfo const & rInf, Point& rPos );
69 short CheckKerning_( );
71 bool ChgFnt( SwViewShell const *pSh, OutputDevice& rOut );
72 bool IsSymbol( SwViewShell const *pSh );
73 sal_uInt16 GetAscent( SwViewShell const *pSh, const OutputDevice& rOut );
74 sal_uInt16 GetHeight( SwViewShell const *pSh, const OutputDevice& rOut );
75 sal_uInt16 GetHangingBaseline( SwViewShell const *pSh, const OutputDevice& rOut );
76 Size GetTextSize_( SwDrawTextInfo& rInf );
77 Size GetCapitalSize( SwDrawTextInfo& rInf );
78 void DrawText_( SwDrawTextInfo &rInf, const bool bGrey );
79 void DrawCapital( SwDrawTextInfo &rInf );
80 void DrawStretchCapital( SwDrawTextInfo &rInf );
81 void DoOnCapitals( SwDoCapitals &rDo );
82 void DrawStretchText_( SwDrawTextInfo &rInf );
83 TextFrameIndex GetModelPositionForViewPoint_( SwDrawTextInfo& rInf );
84 TextFrameIndex GetCapitalCursorOfst( SwDrawTextInfo& rInf );
86 inline void SetColor( const Color& rColor );
87 inline void SetFillColor( const Color& rColor );
88 inline void SetCharSet( const rtl_TextEncoding eCharSet );
89 inline void SetPitch( const FontPitch ePitch );
90 inline void SetAlign( const TextAlign eAlign );
91 inline void SetUnderline( const FontLineStyle eUnderline );
92 inline void SetOverline( const FontLineStyle eOverline );
93 inline void SetStrikeout( const FontStrikeout eStrikeout );
94 inline void SetItalic( const FontItalic eItalic );
95 inline void SetOutline( const bool bOutline );
96 inline void SetVertical( const Degree10 nDir, const bool bVertFormat );
97 inline void SetShadow( const bool bShadow );
98 inline void SetAutoKern( FontKerning nAutoKern );
99 inline void SetWordLineMode( const bool bWordLineMode );
100 inline void SetEmphasisMark( const FontEmphasisMark eValue );
101 inline void SetRelief( const FontRelief eNew );
103 // methods for sub-/superscript
104 inline void SetEscapement( const short nNewEsc );
105 inline void SetProportion( const sal_uInt8 nNewPropr );
107 inline void SetFamily( const FontFamily eFamily );
108 inline void SetName( const OUString& rName );
109 inline void SetStyleName( const OUString& rStyleName );
110 inline void SetSize( const Size& rSize );
111 inline void SetWeight( const FontWeight eWeight );
112 inline void SetLanguage( LanguageType eNewLang );
113 short CheckKerning()
114 { return GetFixKerning() >= 0 ? GetFixKerning() : CheckKerning_( ); }
115 void SetPropWidth( const sal_uInt16 nNew )
116 { m_nFontCacheId = nullptr; m_nProportionalWidth = nNew; }
117 public:
118 SwSubFont() : m_aSize(0,0)
119 { m_nFontCacheId = nullptr; m_nFontIndex = m_nOrgHeight = m_nOrgAscent = 0; m_nProportionalWidth =100; m_bSmallCapsPercentage66 = false; }
120 sal_uInt16 GetPropWidth() const { return m_nProportionalWidth; }
123 enum class SwFontScript
125 Latin, CJK, CTL, LAST = CTL
128 // mostly used as a "unknown script" marker
129 #define SW_SCRIPTS (SwFontScript(int(SwFontScript::LAST)+1))
131 /// To take Asian or other languages into consideration, an SwFont object consists of 3 SwSubFonts
132 /// (Latin, CJK, and CTL). The m_nActual member indicates the current script, i.e. the currently
133 /// active subfont.
134 class SwFont
136 // CJK == Chinese, Japanese, Korean
137 // CTL == Complex text layout ( Hebrew, Arabic )
138 o3tl::enumarray<SwFontScript, SwSubFont> m_aSub; // Latin-, CJK- and CTL-font
140 std::optional<Color>
141 mxBackColor; // background color (i.e. at character styles)
142 Color m_aHighlightColor; // highlight color
143 Color m_aUnderColor; // color of the underlining
144 Color m_aOverColor; // color of the overlining
146 // character borders
147 std::optional<editeng::SvxBorderLine> m_aTopBorder;
148 std::optional<editeng::SvxBorderLine> m_aBottomBorder;
149 std::optional<editeng::SvxBorderLine> m_aRightBorder;
150 std::optional<editeng::SvxBorderLine> m_aLeftBorder;
152 // border distance
153 sal_uInt16 m_nTopBorderDist;
154 sal_uInt16 m_nBottomBorderDist;
155 sal_uInt16 m_nRightBorderDist;
156 sal_uInt16 m_nLeftBorderDist;
158 Color m_aShadowColor;
159 sal_uInt16 m_nShadowWidth;
160 SvxShadowLocation m_aShadowLocation;
162 sal_uInt8 m_nToxCount; // counts the nesting depth of the Tox
163 sal_uInt8 m_nRefCount; // counts the nesting depth of the Refs
164 sal_uInt8 m_nMetaCount; // count META/METAFIELD
165 sal_uInt8 m_nContentControlCount; // count CONTENTCONTROL
166 sal_uInt8 m_nInputFieldCount; // count INPUTFIELD
168 SwFontScript m_nActual; // actual font (Latin, CJK or CTL)
170 // switch for the font-extensions
171 bool m_bPaintBlank :1; // blanks not with DrawRect
172 bool m_bFontChg :1;
173 bool m_bOrgChg :1; // nOrgHeight/Ascent are invalid
174 bool m_bGreyWave :1; // for the extended TextInput: gray waveline
176 public:
177 SwFont( const SwAttrSet* pSet, const IDocumentSettingAccess* pIDocumentSettingAccess );
178 SwFont( const SwFont& rFont );
180 void ChgFnt( SwViewShell const *pSh, OutputDevice& rOut )
181 { m_bPaintBlank = m_aSub[m_nActual].ChgFnt( pSh, rOut ); }
183 ~SwFont();
185 SwFont& operator=( const SwFont &rFont );
187 SwFontScript GetActual() const { return m_nActual; }
188 inline void SetActual( SwFontScript nNew );
189 const SvxFont& GetActualFont() const { return m_aSub[m_nActual]; }
191 // gets a font cache id via SwFntAccess
192 void AllocFontCacheId( SwViewShell const *pSh, SwFontScript nWhich );
193 // set background color
194 void SetBackColor( std::optional<Color> xNewColor );
195 const std::optional<Color>& GetBackColor() const{ return mxBackColor; }
196 void SetHighlightColor( const Color& aNewColor );
197 const Color& GetHighlightColor() const { return m_aHighlightColor; }
199 void CheckFontCacheId( SwViewShell const *pSh, SwFontScript nWhich )
200 { if( !m_aSub[ nWhich ].m_nFontCacheId ) AllocFontCacheId( pSh, nWhich ); }
201 void GetFontCacheId( const void* &rnFontCacheId, sal_uInt16 &rIdx, SwFontScript nWhich )
202 { rnFontCacheId = m_aSub[nWhich].m_nFontCacheId; rIdx = m_aSub[nWhich].m_nFontIndex; }
203 void SetFontCacheId( const void* nNewFontCacheId, const sal_uInt16 nIdx, SwFontScript nWhich )
204 { m_aSub[nWhich].m_nFontCacheId = nNewFontCacheId; m_aSub[nWhich].m_nFontIndex = nIdx; }
205 bool DifferentFontCacheId( const SwFont* pFnt, SwFontScript nWhich )
206 { return m_aSub[nWhich].m_nFontCacheId != pFnt->m_aSub[nWhich].m_nFontCacheId ||
207 !m_aSub[nWhich].m_nFontCacheId || !pFnt->m_aSub[nWhich].m_nFontCacheId; }
209 const Size &GetSize( SwFontScript nWhich ) const
210 { return m_aSub[nWhich].m_aSize; }
211 bool IsFntChg() const { return m_bFontChg; }
212 void SetFntChg( const bool bNew ) { m_bFontChg = bNew; }
214 // the encapsulated SV-Font-methods (set bFntChg to true)
215 inline void SetColor( const Color& rColor );
216 inline void SetFillColor( const Color& rColor );
217 inline void SetAlign( const TextAlign eAlign );
218 inline void SetUnderline( const FontLineStyle eUnderline );
219 void SetUnderColor( const Color &rColor ) { m_aUnderColor = rColor; }
220 inline void SetOverline( const FontLineStyle eOverline );
221 void SetOverColor( const Color &rColor ) { m_aOverColor = rColor; }
222 inline void SetStrikeout( const FontStrikeout eStrikeout );
223 inline void SetOutline( const bool bOutline );
224 void SetVertical(Degree10 nDir, const bool bVertLayout = false,
225 const bool bVertLayoutLRBT = false);
226 inline void SetShadow( const bool bShadow );
227 inline void SetAutoKern( FontKerning nAutoKern );
228 inline void SetTransparent( const bool bTrans );
229 inline void SetWordLineMode( const bool bWordLineMode );
230 inline void SetFixKerning( const short nNewKern );
231 inline void SetCaseMap( const SvxCaseMap eNew );
232 inline void SetEmphasisMark( const FontEmphasisMark eValue );
234 // methods for sub-/superscript
235 inline void SetEscapement( const short nNewEsc );
236 inline void SetProportion( const sal_uInt8 nNewPropr );
238 inline void SetPropWidth( const sal_uInt16 nNew );
240 inline void SetFamily( const FontFamily eFamily, const SwFontScript nWhich );
241 inline void SetName( const OUString& rName, const SwFontScript nWhich );
242 inline void SetStyleName( const OUString& rStyleName, const SwFontScript nWhich );
243 inline void SetSize( const Size& rSize, const SwFontScript nWhich );
244 inline void SetWeight( const FontWeight eWeight, const SwFontScript nWhich );
245 inline void SetItalic( const FontItalic eItalic, const SwFontScript nWhich );
246 inline void SetLanguage( LanguageType eNewLang, const SwFontScript nWhich );
247 inline void SetCharSet( const rtl_TextEncoding eCharSet, const SwFontScript nWhich );
248 inline void SetPitch( const FontPitch ePitch, const SwFontScript nWhich );
249 inline void SetRelief( const FontRelief eNew );
251 // Get/Set-methods for the current setting
252 sal_uInt8 &GetTox() { return m_nToxCount; }
253 bool IsTox() const { return ( 0 != m_nToxCount ); }
254 sal_uInt8 &GetRef() { return m_nRefCount; }
255 bool IsRef() const { return ( 0 != m_nRefCount ); }
256 sal_uInt8 &GetMeta() { return m_nMetaCount; }
257 bool IsMeta() const { return (0 != m_nMetaCount); }
258 sal_uInt8& GetContentControl() { return m_nContentControlCount; }
259 bool IsContentControl() const { return m_nContentControlCount != 0; }
260 sal_uInt8 &GetInputField() { return m_nInputFieldCount; }
261 bool IsInputField() const { return (0 != m_nInputFieldCount); }
262 inline void SetGreyWave( const bool bNew );
263 bool IsGreyWave() const { return m_bGreyWave; }
264 bool IsPaintBlank() const { return m_bPaintBlank; }
266 // setting of the base class font for SwTextCharFormat
267 void SetDiffFnt( const SfxItemSet* pSet,
268 const IDocumentSettingAccess* pIDocumentSettingAccess );
270 const SvxFont &GetFnt( const SwFontScript nWhich ) const
271 { return m_aSub[nWhich]; };
273 bool IsSymbol( SwViewShell const *pSh )
274 { return m_aSub[m_nActual].IsSymbol( pSh ); }
275 FontLineStyle GetUnderline() const { return m_aSub[m_nActual].GetUnderline(); }
276 const Color& GetUnderColor() const { return m_aUnderColor; }
277 FontLineStyle GetOverline() const { return m_aSub[m_nActual].GetOverline(); }
278 const Color& GetOverColor() const { return m_aOverColor; }
279 FontStrikeout GetStrikeout() const { return m_aSub[m_nActual].GetStrikeout(); }
280 const Color& GetColor() const { return m_aSub[m_nActual].GetColor(); }
281 bool IsWordLineMode() const { return m_aSub[m_nActual].IsWordLineMode(); }
282 short GetEscapement() const { return m_aSub[m_nActual].GetEscapement(); }
283 SvxCaseMap GetCaseMap() const { return m_aSub[m_nActual].GetCaseMap(); }
284 sal_uInt8 GetPropr() const { return m_aSub[m_nActual].GetPropr(); }
285 FontItalic GetItalic() const { return m_aSub[m_nActual].GetItalic(); }
286 LanguageType GetLanguage() const { return m_aSub[m_nActual].GetLanguage(); }
287 tools::Long GetHeight() const { return m_aSub[m_nActual].GetFontSize().Height(); }
288 FontWeight GetWeight() const { return m_aSub[m_nActual].GetWeight(); }
289 FontEmphasisMark GetEmphasisMark() const
290 { return m_aSub[m_nActual].GetEmphasisMark(); }
291 Degree10 GetOrientation(const bool bVertLayout = false,
292 const bool bVertFormatLRBT = false) const;
294 const OUString& GetName( const SwFontScript nWhich ) const
295 { return m_aSub[nWhich].GetFamilyName(); }
296 LanguageType GetLanguage( const SwFontScript nWhich ) const
297 { return m_aSub[nWhich].GetLanguage(); }
298 rtl_TextEncoding GetCharSet( const SwFontScript nWhich ) const
299 { return m_aSub[nWhich].GetCharSet(); }
300 tools::Long GetHeight( const SwFontScript nWhich ) const
301 { return m_aSub[nWhich].GetFontSize().Height(); }
303 // makes the logical font be effective in the OutputDevice
304 void ChgPhysFnt( SwViewShell const *pSh, OutputDevice& rOut );
306 TextFrameIndex GetCapitalBreak( SwViewShell const* pSh, const OutputDevice* pOut,
307 const SwScriptInfo* pScript, const OUString& rText,
308 tools::Long nTextWidth, TextFrameIndex nIdx, TextFrameIndex nLen);
310 void DoOnCapitals( SwDoCapitals &rDo )
311 { m_aSub[m_nActual].DoOnCapitals( rDo ); }
313 Size GetTextSize_( SwDrawTextInfo& rInf )
314 { rInf.SetFont( this ); return m_aSub[m_nActual].GetTextSize_( rInf ); }
316 TextFrameIndex GetTextBreak( SwDrawTextInfo const & rInf, tools::Long nTextWidth );
318 TextFrameIndex GetModelPositionForViewPoint_( SwDrawTextInfo& rInf )
319 { return m_aSub[m_nActual].GetModelPositionForViewPoint_( rInf ); }
321 void DrawText_( SwDrawTextInfo &rInf )
322 { m_aSub[m_nActual].DrawText_( rInf, IsGreyWave() ); }
324 void DrawStretchText_( SwDrawTextInfo &rInf )
325 { m_aSub[m_nActual].DrawStretchText_( rInf ); }
327 short CheckKerning()
328 { return m_aSub[m_nActual].CheckKerning(); }
330 sal_uInt16 GetAscent( SwViewShell const *pSh, const OutputDevice& rOut )
331 { return m_aSub[m_nActual].GetAscent( pSh, rOut ); }
332 sal_uInt16 GetHeight( SwViewShell const *pSh, const OutputDevice& rOut )
333 { return m_aSub[m_nActual].GetHeight( pSh, rOut ); }
335 sal_uInt16 GetHangingBaseline( SwViewShell const *pSh, const OutputDevice& rOut )
336 { return m_nActual == SwFontScript::CTL ? m_aSub[m_nActual].GetHangingBaseline( pSh, rOut ) : 0; }
338 void Invalidate()
339 { m_bFontChg = m_bOrgChg = true; }
341 void SetTopBorder( const editeng::SvxBorderLine* pTopBorder );
342 void SetBottomBorder( const editeng::SvxBorderLine* pBottomBorder );
343 void SetRightBorder( const editeng::SvxBorderLine* pRightBorder );
344 void SetLeftBorder( const editeng::SvxBorderLine* pLeftBorder );
346 const std::optional<editeng::SvxBorderLine>& GetTopBorder() const { return m_aTopBorder; }
347 const std::optional<editeng::SvxBorderLine>& GetBottomBorder() const { return m_aBottomBorder; }
348 const std::optional<editeng::SvxBorderLine>& GetRightBorder() const { return m_aRightBorder; }
349 const std::optional<editeng::SvxBorderLine>& GetLeftBorder() const { return m_aLeftBorder; }
351 // Get absolute border correspond to the layout verticality and orientation.
352 const std::optional<editeng::SvxBorderLine>&
353 GetAbsTopBorder(const bool bVertLayout, const bool bVertLayoutLRBT) const;
354 const std::optional<editeng::SvxBorderLine>&
355 GetAbsBottomBorder(const bool bVertLayout, const bool bVertLayoutLRBT) const;
356 const std::optional<editeng::SvxBorderLine>&
357 GetAbsRightBorder(const bool bVertLayout, const bool bVertLayoutLRBT) const;
358 const std::optional<editeng::SvxBorderLine>&
359 GetAbsLeftBorder(const bool bVertLayout, const bool bVertLayoutLRBT) const;
361 void SetTopBorderDist( const sal_uInt16 nTopDist );
362 void SetBottomBorderDist( const sal_uInt16 nBottomDist );
363 void SetRightBorderDist( const sal_uInt16 nRightDist );
364 void SetLeftBorderDist( const sal_uInt16 nLeftDist );
366 sal_uInt16 GetTopBorderDist() const { return m_nTopBorderDist; }
367 sal_uInt16 GetBottomBorderDist() const { return m_nBottomBorderDist; }
368 sal_uInt16 GetRightBorderDist() const { return m_nRightBorderDist; }
369 sal_uInt16 GetLeftBorderDist() const { return m_nLeftBorderDist; }
371 // Return with the whole space which border holed (border width, spacing and shadow width)
372 sal_uInt16 GetTopBorderSpace() const;
373 sal_uInt16 GetBottomBorderSpace() const;
374 sal_uInt16 GetRightBorderSpace() const;
375 sal_uInt16 GetLeftBorderSpace() const;
377 /// Check whether font has any border on any side
378 bool HasBorder() const;
380 void SetShadowColor( const Color& rColor );
381 void SetShadowWidth( const sal_uInt16 nWidth );
382 void SetShadowLocation( const SvxShadowLocation aLocation );
384 const Color& GetShadowColor() const { return m_aShadowColor; }
385 sal_uInt16 GetShadowWidth() const { return m_nShadowWidth; }
386 SvxShadowLocation GetShadowLocation() const { return m_aShadowLocation; }
389 * Get the absolute shadow location dependent from orientation.
391 * @param[in] bVertLayout true, if the container layout is vertical
392 * false, otherwise
393 * @param[in] bVertLayoutLRBT true if the container layout is vertical
394 * (bottom to top, left to right), false otherwise
395 * @return absolute location
397 SvxShadowLocation GetAbsShadowLocation(const bool bVertLayout,
398 const bool bVertLayoutLRBT) const;
401 * Calculate the shadow space on the specified side dependent from
402 * the orientation and connection with neighbours.
403 * @see shaditem.hxx for integer constants of sides
405 * @param[in] nShadow specify the side
406 * @param[in] bVertLayout true, if the container layout is vertical
407 * false, otherwise
408 * @param[in] bVertLayoutLRBT true if the container layout is vertical
409 * (bottom to top, left to right), false otherwise
410 * @param[in] bSkipLeft relative left shadow space is skipped
411 * @param[in] bSkipRight relative right shadow space is skipped
412 * @return the shadow space
414 sal_uInt16 CalcShadowSpace(
415 const SvxShadowItemSide nShadow, const bool bVertLayout, const bool bVertLayoutLRBT,
416 const bool bSkipLeft, const bool bSkipRight ) const;
418 void dumpAsXml( xmlTextWriterPtr writer ) const;
421 inline void SwFont::SetColor( const Color& rColor )
423 m_bFontChg = true;
424 m_aSub[SwFontScript::Latin].SetColor( rColor );
425 m_aSub[SwFontScript::CJK].SetColor( rColor );
426 m_aSub[SwFontScript::CTL].SetColor( rColor );
429 // encapsulated SV-Font-method
430 inline void SwSubFont::SetColor( const Color& rColor )
432 m_nFontCacheId = nullptr;
433 Font::SetColor( rColor );
436 // encapsulated SV-Font-method
437 inline void SwSubFont::SetFillColor( const Color& rColor )
439 m_nFontCacheId = nullptr;
440 Font::SetFillColor( rColor );
443 inline void SwFont::SetFillColor( const Color& rColor )
445 m_bFontChg = true;
446 m_aSub[SwFontScript::Latin].SetFillColor( rColor );
447 m_aSub[SwFontScript::CJK].SetFillColor( rColor );
448 m_aSub[SwFontScript::CTL].SetFillColor( rColor );
451 // encapsulated SV-Font-method
452 inline void SwSubFont::SetFamily( const FontFamily eFamily )
454 m_nFontCacheId = nullptr;
455 Font::SetFamily( eFamily );
458 inline void SwFont::SetFamily( const FontFamily eFamily, const SwFontScript nWhich )
460 m_bFontChg = true;
461 m_aSub[nWhich].SetFamily( eFamily );
464 // encapsulated SV-Font-method
465 inline void SwSubFont::SetName( const OUString& rName )
467 m_nFontCacheId = nullptr;
468 Font::SetFamilyName( rName );
471 inline void SwFont::SetName( const OUString& rName, const SwFontScript nWhich )
473 m_bFontChg = true;
474 m_aSub[nWhich].SetName( rName );
477 // encapsulated SV-Font-method
478 inline void SwSubFont::SetStyleName( const OUString& rStyleName )
480 m_nFontCacheId = nullptr;
481 Font::SetStyleName( rStyleName );
484 inline void SwFont::SetStyleName( const OUString& rStyle, const SwFontScript nWhich )
486 m_bFontChg = true;
487 m_aSub[nWhich].SetStyleName( rStyle );
490 // encapsulated SV-Font-method
491 inline void SwSubFont::SetCharSet( const rtl_TextEncoding eCharSet )
493 m_nFontCacheId = nullptr;
494 Font::SetCharSet( eCharSet );
497 inline void SwFont::SetCharSet( const rtl_TextEncoding eCharSet, const SwFontScript nWhich )
499 m_bFontChg = true;
500 m_aSub[nWhich].SetCharSet( eCharSet );
503 // encapsulated SV-Font-method
504 inline void SwSubFont::SetPitch( const FontPitch ePitch )
506 m_nFontCacheId = nullptr;
507 Font::SetPitch( ePitch );
510 // encapsulated SV-Font-method
511 inline void SwFont::SetPitch( const FontPitch ePitch, const SwFontScript nWhich )
513 m_bFontChg = true;
514 m_aSub[nWhich].SetPitch( ePitch );
517 // encapsulated SV-Font-method
518 inline void SwSubFont::SetAlign( const TextAlign eAlign )
520 m_nFontCacheId = nullptr;
521 Font::SetAlignment( eAlign );
524 inline void SwFont::SetAlign( const TextAlign eAlign )
526 m_bFontChg = true;
527 m_aSub[SwFontScript::Latin].SetAlign( eAlign );
528 m_aSub[SwFontScript::CJK].SetAlign( eAlign );
529 m_aSub[SwFontScript::CTL].SetAlign( eAlign );
532 // encapsulated SV-Font-method
533 inline void SwSubFont::SetWeight( const FontWeight eWeight )
535 m_nFontCacheId = nullptr;
536 Font::SetWeight( eWeight );
539 inline void SwFont::SetWeight( const FontWeight eWeight, const SwFontScript nWhich )
541 m_bFontChg = true;
542 m_aSub[nWhich].SetWeight( eWeight );
545 // encapsulated SV-Font-method
546 inline void SwSubFont::SetUnderline( const FontLineStyle eUnderline )
548 m_nFontCacheId = nullptr;
549 Font::SetUnderline( eUnderline );
552 inline void SwFont::SetUnderline( const FontLineStyle eUnderline )
554 m_bFontChg = true;
555 m_aSub[SwFontScript::Latin].SetUnderline( eUnderline );
556 m_aSub[SwFontScript::CJK].SetUnderline( eUnderline );
557 m_aSub[SwFontScript::CTL].SetUnderline( eUnderline );
560 // encapsulated SV-Font-method
561 inline void SwSubFont::SetOverline( const FontLineStyle eOverline )
563 m_nFontCacheId = nullptr;
564 Font::SetOverline( eOverline );
567 inline void SwFont::SetOverline( const FontLineStyle eOverline )
569 m_bFontChg = true;
570 m_aSub[SwFontScript::Latin].SetOverline( eOverline );
571 m_aSub[SwFontScript::CJK].SetOverline( eOverline );
572 m_aSub[SwFontScript::CTL].SetOverline( eOverline );
575 // encapsulated SV-Font-method
576 inline void SwSubFont::SetStrikeout( const FontStrikeout eStrikeout )
578 m_nFontCacheId = nullptr;
579 Font::SetStrikeout( eStrikeout );
582 inline void SwFont::SetStrikeout( const FontStrikeout eStrikeout )
584 m_bFontChg = true;
585 m_aSub[SwFontScript::Latin].SetStrikeout( eStrikeout );
586 m_aSub[SwFontScript::CJK].SetStrikeout( eStrikeout );
587 m_aSub[SwFontScript::CTL].SetStrikeout( eStrikeout );
590 // encapsulated SV-Font-method
591 inline void SwSubFont::SetItalic( const FontItalic eItalic )
593 m_nFontCacheId = nullptr;
594 Font::SetItalic( eItalic );
597 inline void SwFont::SetItalic( const FontItalic eItalic, const SwFontScript nWhich )
599 m_bFontChg = true;
600 m_aSub[nWhich].SetItalic( eItalic );
603 // encapsulated SV-Font-method
604 inline void SwSubFont::SetOutline( const bool bOutline )
606 m_nFontCacheId = nullptr;
607 Font::SetOutline( bOutline );
610 inline void SwFont::SetOutline( const bool bOutline )
612 m_bFontChg = true;
613 m_aSub[SwFontScript::Latin].SetOutline( bOutline );
614 m_aSub[SwFontScript::CJK].SetOutline( bOutline );
615 m_aSub[SwFontScript::CTL].SetOutline( bOutline );
618 // encapsulated SV-Font-method
619 inline void SwSubFont::SetShadow( const bool bShadow )
621 m_nFontCacheId = nullptr;
622 Font::SetShadow( bShadow );
625 inline void SwFont::SetShadow( const bool bShadow )
627 m_bFontChg = true;
628 m_aSub[SwFontScript::Latin].SetShadow( bShadow );
629 m_aSub[SwFontScript::CJK].SetShadow( bShadow );
630 m_aSub[SwFontScript::CTL].SetShadow( bShadow );
633 // encapsulated SV-Font-method
634 inline void SwSubFont::SetAutoKern( FontKerning nAutoKern )
636 m_nFontCacheId = nullptr;
637 Font::SetKerning( nAutoKern );
640 inline void SwFont::SetAutoKern( FontKerning nAutoKern )
642 m_bFontChg = true;
643 m_aSub[SwFontScript::CJK].SetAutoKern( nAutoKern );
644 if( nAutoKern != FontKerning::NONE )
645 nAutoKern = FontKerning::FontSpecific;
646 m_aSub[SwFontScript::Latin].SetAutoKern( nAutoKern );
647 m_aSub[SwFontScript::CTL].SetAutoKern( nAutoKern );
650 inline void SwFont::SetTransparent( const bool bTrans )
652 m_aSub[SwFontScript::Latin].SetTransparent( bTrans );
653 m_aSub[SwFontScript::CJK].SetTransparent( bTrans );
654 m_aSub[SwFontScript::CTL].SetTransparent( bTrans );
657 inline void SwFont::SetFixKerning( const short nNewKern )
659 m_aSub[SwFontScript::Latin].SetFixKerning( nNewKern );
660 m_aSub[SwFontScript::CJK].SetFixKerning( nNewKern );
661 m_aSub[SwFontScript::CTL].SetFixKerning( nNewKern );
664 inline void SwFont::SetCaseMap( const SvxCaseMap eNew )
666 m_aSub[SwFontScript::Latin].SetCaseMap( eNew );
667 m_aSub[SwFontScript::CJK].SetCaseMap( eNew );
668 m_aSub[SwFontScript::CTL].SetCaseMap( eNew );
671 // encapsulated SV-Font-method
672 inline void SwSubFont::SetWordLineMode( const bool bWordLineMode )
674 m_nFontCacheId = nullptr;
675 Font::SetWordLineMode( bWordLineMode );
678 inline void SwFont::SetWordLineMode( const bool bWordLineMode )
680 m_bFontChg = true;
681 m_aSub[SwFontScript::Latin].SetWordLineMode( bWordLineMode );
682 m_aSub[SwFontScript::CJK].SetWordLineMode( bWordLineMode );
683 m_aSub[SwFontScript::CTL].SetWordLineMode( bWordLineMode );
685 // encapsulated SV-Font-method
686 inline void SwSubFont::SetEmphasisMark( const FontEmphasisMark eValue )
688 m_nFontCacheId = nullptr;
689 Font::SetEmphasisMark( eValue );
692 inline void SwFont::SetEmphasisMark( const FontEmphasisMark eValue )
694 m_bFontChg = true;
695 m_aSub[SwFontScript::Latin].SetEmphasisMark( eValue );
696 m_aSub[SwFontScript::CJK].SetEmphasisMark( eValue );
697 m_aSub[SwFontScript::CTL].SetEmphasisMark( eValue );
700 inline void SwFont::SetPropWidth( const sal_uInt16 nNew )
702 if( nNew != m_aSub[SwFontScript::Latin].GetPropWidth() )
704 m_bFontChg = true;
705 m_aSub[SwFontScript::Latin].SetPropWidth( nNew );
706 m_aSub[SwFontScript::CJK].SetPropWidth( nNew );
707 m_aSub[SwFontScript::CTL].SetPropWidth( nNew );
711 // encapsulated SV-Font-method
712 inline void SwSubFont::SetRelief( const FontRelief eNew )
714 m_nFontCacheId = nullptr;
715 Font::SetRelief( eNew );
718 inline void SwFont::SetRelief( const FontRelief eNew )
720 if( eNew != m_aSub[SwFontScript::Latin].GetRelief() )
722 m_bFontChg = true;
723 m_aSub[SwFontScript::Latin].SetRelief( eNew );
724 m_aSub[SwFontScript::CJK].SetRelief( eNew );
725 m_aSub[SwFontScript::CTL].SetRelief( eNew );
729 // overloaded font-method
730 inline void SwSubFont::SetSize( const Size& rSize )
732 m_aSize = rSize;
733 if ( GetPropr() == 100 )
734 Font::SetFontSize( m_aSize );
735 else
737 Font::SetFontSize( Size(
738 m_aSize.Width() * GetPropr() / 100,
739 m_aSize.Height() * GetPropr() / 100 ) );
741 m_nFontCacheId = nullptr;
744 inline void SwFont::SetSize( const Size& rSize, const SwFontScript nWhich )
746 if( m_aSub[nWhich].m_aSize != rSize )
748 m_aSub[nWhich].SetSize( rSize );
749 m_bFontChg = true;
750 m_bOrgChg = true;
754 inline void SwFont::SetActual( SwFontScript nNew )
756 if ( m_nActual != nNew )
758 m_bFontChg = true;
759 m_bOrgChg = true;
760 m_nActual = nNew;
764 inline void SwSubFont::SetProportion( const sal_uInt8 nNewPropr )
766 m_nFontCacheId = nullptr;
767 Font::SetFontSize( Size( m_aSize.Width() * nNewPropr / 100,
768 m_aSize.Height() * nNewPropr / 100 ) );
769 SvxFont::SetPropr( nNewPropr );
772 inline void SwFont::SetProportion( const sal_uInt8 nNewPropr )
774 if( nNewPropr != m_aSub[SwFontScript::Latin].GetPropr() )
776 m_bFontChg = true;
777 m_bOrgChg = true;
779 m_aSub[SwFontScript::Latin].SetProportion( nNewPropr );
780 m_aSub[SwFontScript::CJK].SetProportion( nNewPropr );
781 m_aSub[SwFontScript::CTL].SetProportion( nNewPropr );
785 inline void SwSubFont::SetEscapement( const short nNewEsc )
787 m_nFontCacheId = nullptr;
788 SvxFont::SetEscapement( nNewEsc );
791 inline void SwFont::SetEscapement( const short nNewEsc )
793 if( nNewEsc != m_aSub[SwFontScript::Latin].GetEscapement() )
795 // these have to be set, otherwise nOrgHeight and nOrgAscent will not
796 // be calculated
797 m_bFontChg = true;
798 m_bOrgChg = true;
800 m_aSub[SwFontScript::Latin].SetEscapement( nNewEsc );
801 m_aSub[SwFontScript::CJK].SetEscapement( nNewEsc );
802 m_aSub[SwFontScript::CTL].SetEscapement( nNewEsc );
806 inline void SwSubFont::SetLanguage( LanguageType eNewLang )
808 m_nFontCacheId = nullptr;
809 if( eNewLang == LANGUAGE_SYSTEM )
810 eNewLang = GetAppLanguage();
811 SvxFont::SetLanguage( eNewLang );
814 inline void SwFont::SetLanguage( const LanguageType eNewLang, const SwFontScript nWhich )
816 m_aSub[nWhich].SetLanguage( eNewLang );
817 if( SwFontScript::CJK == nWhich )
819 m_aSub[SwFontScript::Latin].SetCJKContextLanguage( eNewLang );
820 m_aSub[SwFontScript::CJK].SetCJKContextLanguage( eNewLang );
821 m_aSub[SwFontScript::CTL].SetCJKContextLanguage( eNewLang );
825 inline void SwFont::SetGreyWave( const bool bNew )
827 m_bGreyWave = bNew;
830 inline void SwSubFont::SetVertical( const Degree10 nDir, const bool bVertFormat )
832 m_nFontCacheId = nullptr;
833 Font::SetVertical( bVertFormat );
834 Font::SetOrientation( nDir );
837 inline void SwFont::SetTopBorderDist( const sal_uInt16 nTopDist )
839 m_nTopBorderDist = nTopDist;
840 m_bFontChg = true;
841 m_aSub[SwFontScript::Latin].m_nFontCacheId = m_aSub[SwFontScript::CJK].m_nFontCacheId = m_aSub[SwFontScript::CTL].m_nFontCacheId = nullptr;
844 inline void SwFont::SetBottomBorderDist( const sal_uInt16 nBottomDist )
846 m_nBottomBorderDist = nBottomDist;
847 m_bFontChg = true;
848 m_aSub[SwFontScript::Latin].m_nFontCacheId = m_aSub[SwFontScript::CJK].m_nFontCacheId = m_aSub[SwFontScript::CTL].m_nFontCacheId = nullptr;
851 inline void SwFont::SetRightBorderDist( const sal_uInt16 nRightDist )
853 m_nRightBorderDist = nRightDist;
854 m_bFontChg = true;
855 m_aSub[SwFontScript::Latin].m_nFontCacheId = m_aSub[SwFontScript::CJK].m_nFontCacheId = m_aSub[SwFontScript::CTL].m_nFontCacheId = nullptr;
858 inline void SwFont::SetLeftBorderDist( const sal_uInt16 nLeftDist )
860 m_nLeftBorderDist = nLeftDist;
861 m_bFontChg = true;
862 m_aSub[SwFontScript::Latin].m_nFontCacheId = m_aSub[SwFontScript::CJK].m_nFontCacheId = m_aSub[SwFontScript::CTL].m_nFontCacheId = nullptr;
865 inline sal_uInt16 SwFont::GetTopBorderSpace() const
867 sal_uInt16 nRet = 0;
868 if( m_aTopBorder )
870 nRet += m_aTopBorder->GetScaledWidth() + m_nTopBorderDist;
872 if( m_aShadowLocation == SvxShadowLocation::TopLeft ||
873 m_aShadowLocation == SvxShadowLocation::TopRight )
875 nRet += m_nShadowWidth;
877 return nRet;
880 inline sal_uInt16 SwFont::GetBottomBorderSpace() const
882 sal_uInt16 nRet = 0;
883 if( m_aBottomBorder )
885 nRet += m_aBottomBorder->GetScaledWidth() + m_nBottomBorderDist;
887 if( m_aShadowLocation == SvxShadowLocation::BottomLeft ||
888 m_aShadowLocation == SvxShadowLocation::BottomRight )
890 nRet += m_nShadowWidth;
892 return nRet;
895 inline sal_uInt16 SwFont::GetRightBorderSpace() const
897 sal_uInt16 nRet = 0;
898 if( m_aRightBorder )
900 nRet += m_aRightBorder->GetScaledWidth() + m_nRightBorderDist;
902 if( m_aShadowLocation == SvxShadowLocation::TopRight ||
903 m_aShadowLocation == SvxShadowLocation::BottomRight )
905 nRet += m_nShadowWidth;
907 return nRet;
910 inline sal_uInt16 SwFont::GetLeftBorderSpace() const
912 sal_uInt16 nRet = 0;
913 if( m_aLeftBorder )
915 nRet += m_aLeftBorder->GetScaledWidth() + m_nLeftBorderDist;
917 if( m_aShadowLocation == SvxShadowLocation::TopLeft ||
918 m_aShadowLocation == SvxShadowLocation::BottomLeft )
920 nRet += m_nShadowWidth;
922 return nRet;
925 inline bool SwFont::HasBorder() const
927 return m_aTopBorder || m_aBottomBorder || m_aLeftBorder || m_aRightBorder;
930 inline void SwFont::SetShadowColor( const Color& rColor )
932 m_aShadowColor = rColor;
933 m_bFontChg = true;
934 m_aSub[SwFontScript::Latin].m_nFontCacheId = m_aSub[SwFontScript::CJK].m_nFontCacheId = m_aSub[SwFontScript::CTL].m_nFontCacheId = nullptr;
937 inline void SwFont::SetShadowWidth( const sal_uInt16 nWidth )
939 m_nShadowWidth = nWidth;
940 m_bFontChg = true;
941 m_aSub[SwFontScript::Latin].m_nFontCacheId = m_aSub[SwFontScript::CJK].m_nFontCacheId = m_aSub[SwFontScript::CTL].m_nFontCacheId = nullptr;
944 inline void SwFont::SetShadowLocation( const SvxShadowLocation aLocation )
946 m_aShadowLocation = aLocation;
947 m_bFontChg = true;
948 m_aSub[SwFontScript::Latin].m_nFontCacheId = m_aSub[SwFontScript::CJK].m_nFontCacheId = m_aSub[SwFontScript::CTL].m_nFontCacheId = nullptr;
951 inline void SwFont::SetHighlightColor( const Color& aNewColor )
953 m_aHighlightColor = aNewColor;
954 m_bFontChg = true;
955 m_aSub[SwFontScript::Latin].m_nFontCacheId = m_aSub[SwFontScript::CJK].m_nFontCacheId = m_aSub[SwFontScript::CTL].m_nFontCacheId = nullptr;
958 // Used for the "continuous underline" feature.
959 class SwUnderlineFont
961 Point m_aPos;
962 TextFrameIndex m_nEnd;
963 std::unique_ptr<SwFont> m_pFont;
965 public:
966 // sets the font which should paint the common baseline,
967 // index where continuous underline ends,
968 // and the starting point of the common baseline
969 SwUnderlineFont(SwFont& rFnt, TextFrameIndex nEnd, const Point& rPoint);
970 ~SwUnderlineFont();
972 SwFont& GetFont()
974 OSL_ENSURE( m_pFont, "No underline font" );
975 return *m_pFont;
977 const Point& GetPos() const { return m_aPos; }
978 TextFrameIndex GetEnd() const { return m_nEnd; }
979 // the x coordinate of the starting point has to be set for each portion
980 void SetPos( const Point& rPoint ) { m_aPos = rPoint; }
983 #ifdef DBG_UTIL
985 class SvStatistics
987 public:
988 sal_uInt16 nGetTextSize;
989 sal_uInt16 nDrawText;
990 sal_uInt16 nGetStretchTextSize;
991 sal_uInt16 nDrawStretchText;
992 sal_uInt16 nChangeFont;
994 SvStatistics()
995 { nGetTextSize = nDrawText = nGetStretchTextSize = nDrawStretchText = nChangeFont = 0; }
998 // global variable, implemented in swfont.cxx
999 extern SvStatistics g_SvStat;
1001 #define SV_STAT(nWhich) ++(g_SvStat.nWhich);
1004 #else
1005 #define SV_STAT(nWhich)
1006 #endif /* DBG_UTIL */
1008 #endif
1010 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */