LibreOffice Module sw (master)  1
fntcache.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_FNTCACHE_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_FNTCACHE_HXX
22 
23 #include <sal/config.h>
24 
25 #include <cstdint>
26 #include <unordered_map>
27 
28 #include <vcl/font.hxx>
29 #include <vcl/vclptr.hxx>
30 #include <vcl/vcllayout.hxx>
31 #include <vcl/outdev.hxx>
32 #include "swcache.hxx"
33 #include "TextFrameIndex.hxx"
34 
35 class FontMetric;
36 class SwFntObj;
37 class SwDrawTextInfo;
38 class SwViewShell;
39 class SwSubFont;
40 class MapMode;
41 
42 class SwFntCache : public SwCache
43 {
44 public:
46 #ifdef DBG_UTIL
47  , OString(RTL_CONSTASCII_STRINGPARAM("Global Font-Cache pFntCache"))
48 #endif
49  ) {}
50 
51  inline SwFntObj *First( );
52  static inline SwFntObj *Next( SwFntObj *pFntObj);
53  void Flush();
54 };
55 
58 
59 // Font cache, global variable, created/destroyed in txtinit.cxx
60 extern SwFntCache *pFntCache;
61 extern SwFntObj *pLastFont;
62 
68 {
70  OUString m_aText;
71  sal_Int32 m_nIndex;
72  sal_Int32 m_nLength;
73  size_t mnHashCode;
74 
75  SwTextGlyphsKey(VclPtr<OutputDevice> const& pOutputDevice, const OUString & sText, sal_Int32 nIndex, sal_Int32 nLength);
76  bool operator==(SwTextGlyphsKey const & rhs) const;
77 };
79 {
80  size_t operator()(SwTextGlyphsKey const & rKey) const { return rKey.mnHashCode; }
81 };
86 {
88  tools::Long m_nTextWidth = -1; // -1 = not computed yet
89 };
90 typedef std::unordered_map<SwTextGlyphsKey, SwTextGlyphsData, SwTextGlyphsKeyHash> SwTextGlyphsMap;
91 
92 class SwFntObj final : public SwCacheObj
93 {
94  friend class SwFntAccess;
95  friend void InitCore();
96  friend void FinitCore();
97 
102  sal_uInt16 m_nGuessedLeading;
103  sal_uInt16 m_nExtLeading;
104  sal_uInt16 m_nScrAscent;
105  sal_uInt16 m_nPrtAscent;
106  sal_uInt16 m_nScrHeight;
107  sal_uInt16 m_nPrtHeight;
108  sal_uInt16 m_nPropWidth;
109  sal_uInt16 m_nZoom;
110  bool m_bSymbol : 1;
111  bool m_bPaintBlank : 1;
112 
115 
118 
119 public:
120  SwFntObj( const SwSubFont &rFont, std::uintptr_t nFontCacheId,
121  SwViewShell const *pSh );
122 
123  virtual ~SwFntObj() override;
124 
126  vcl::Font& GetFont() { return m_aFont; }
127  const vcl::Font& GetFont() const { return m_aFont; }
128 
129  sal_uInt16 GetGuessedLeading() const { return m_nGuessedLeading; }
130  sal_uInt16 GetExternalLeading() const { return m_nExtLeading; }
131 
132  sal_uInt16 GetFontAscent( const SwViewShell *pSh, const OutputDevice& rOut );
133  sal_uInt16 GetFontHeight( const SwViewShell *pSh, const OutputDevice& rOut );
134  sal_uInt16 GetFontLeading( const SwViewShell *pSh, const OutputDevice& rOut );
135 
136  void GuessLeading( const SwViewShell& rSh, const FontMetric& rMet );
137 
138  void SetDevFont( const SwViewShell *pSh, OutputDevice& rOut );
139  OutputDevice* GetPrt() const { return m_pPrinter; }
140  sal_uInt16 GetZoom() const { return m_nZoom; }
141  sal_uInt16 GetPropWidth() const { return m_nPropWidth; }
142  bool IsSymbol() const { return m_bSymbol; }
143 
146  void ClearCachedTextGlyphs();
147 
148  void DrawText( SwDrawTextInfo &rInf );
152 
153  void CreateScrFont( const SwViewShell& rSh, const OutputDevice& rOut );
154  void CreatePrtFont( const OutputDevice& rOut );
155 };
156 
158 {
159  return static_cast<SwFntObj *>(SwCache::First());
160 }
161 
163 {
164  return static_cast<SwFntObj *>(SwCache::Next( pFntObj ));
165 }
166 
167 class SwFntAccess final : public SwCacheAccess
168 {
170 
171  virtual SwCacheObj *NewObj( ) override;
172 
173 public:
174  SwFntAccess( const void*& rnFontCacheId, sal_uInt16 &rIndex, const void *pOwner,
175  SwViewShell const *pShell,
176  bool bCheck = false );
177  SwFntObj* Get() { return static_cast<SwFntObj*>( SwCacheAccess::Get() ); }
178 };
179 
180 #endif
181 
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OutputDevice * GetPrt() const
Definition: fntcache.hxx:139
SwFntObj * pLastFont
Definition: fntcache.cxx:68
sal_uInt16 m_nExtLeading
Definition: fntcache.hxx:103
void SwClearFntCacheTextGlyphs()
Clears the pre-calculated text glyphs in all SwFntObj instances.
Definition: fntcache.cxx:2722
void CreateScrFont(const SwViewShell &rSh, const OutputDevice &rOut)
Definition: fntcache.cxx:505
size_t operator()(SwTextGlyphsKey const &rKey) const
Definition: fntcache.hxx:80
virtual SwCacheObj * NewObj() override
Can be use in NewObj.
Definition: fntcache.cxx:2384
SwFntAccess(const void *&rnFontCacheId, sal_uInt16 &rIndex, const void *pOwner, SwViewShell const *pShell, bool bCheck=false)
Definition: fntcache.cxx:2280
bool m_bPaintBlank
Definition: fntcache.hxx:111
sal_uInt16 m_nPropWidth
Definition: fntcache.hxx:108
SwCacheObj * First()
Definition: swcache.hxx:115
sal_uInt16 GetFontHeight(const SwViewShell *pSh, const OutputDevice &rOut)
Definition: fntcache.cxx:414
bool m_bSymbol
Definition: fntcache.hxx:110
static SwCacheObj * Next(SwCacheObj *pCacheObj)
Definition: swcache.hxx:222
long Long
TextFrameIndex GetModelPositionForViewPoint(SwDrawTextInfo &rInf)
Definition: fntcache.cxx:2094
sal_uInt16 GetFontAscent(const SwViewShell *pSh, const OutputDevice &rOut)
Definition: fntcache.cxx:377
sal_uInt16 m_nScrHeight
Definition: fntcache.hxx:106
void ClearCachedTextGlyphs()
Definition: fntcache.cxx:256
sal_uInt16 GetGuessedLeading() const
Definition: fntcache.hxx:129
VclPtr< OutputDevice > m_pOutputDevice
Definition: fntcache.hxx:69
SalLayoutGlyphs m_aTextGlyphs
Definition: fntcache.hxx:87
sal_uInt16 GetZoom() const
Definition: fntcache.hxx:140
VclPtr< OutputDevice > m_pPrinter
Definition: fntcache.hxx:101
SalLayoutGlyphs * GetCachedSalLayoutGlyphs(const SwTextGlyphsKey &key)
Definition: fntcache.cxx:224
SwCacheObj * Get(bool isDuplicateOwnerAllowed)
Definition: swcache.hxx:257
vcl::Font & GetFont()
Definition: fntcache.hxx:126
static SwFntObj * Next(SwFntObj *pFntObj)
Definition: fntcache.hxx:162
sal_uInt16 GetFontLeading(const SwViewShell *pSh, const OutputDevice &rOut)
Definition: fntcache.cxx:453
void Flush()
Definition: fntcache.cxx:127
bool IsSymbol() const
Definition: fntcache.hxx:142
tools::Long GetCachedTextWidth(const SwTextGlyphsKey &key, const vcl::text::TextLayoutCache *vclCache)
Definition: fntcache.cxx:240
bool operator==(SwTextGlyphsKey const &rhs) const
Definition: fntcache.cxx:90
Defines a substring on a given output device, to be used as an std::unordered_map<> key...
Definition: fntcache.hxx:67
OUString m_aText
Definition: fntcache.hxx:70
vcl::Font * m_pScrFont
Definition: fntcache.hxx:99
void CreatePrtFont(const OutputDevice &rOut)
Definition: fntcache.cxx:168
vcl::Font * m_pPrtFont
Definition: fntcache.hxx:100
void GuessLeading(const SwViewShell &rSh, const FontMetric &rMet)
Definition: fntcache.cxx:579
size_t mnHashCode
Definition: fntcache.hxx:73
SwViewShell const * m_pShell
Definition: fntcache.hxx:169
static MapMode * s_pPixMap
Definition: fntcache.hxx:117
sal_uInt16 m_nZoom
Definition: fntcache.hxx:109
sal_uInt16 GetPropWidth() const
Definition: fntcache.hxx:141
tools::Long m_nTextWidth
Definition: fntcache.hxx:88
Glyphs and text width for the given SwTextGlyphsKey.
Definition: fntcache.hxx:85
SwTextGlyphsKey(VclPtr< OutputDevice > const &pOutputDevice, const OUString &sText, sal_Int32 nIndex, sal_Int32 nLength)
Defines a substring on a given output device, to be used as an std::unordered_map<> key...
Definition: fntcache.cxx:80
SwFntCache * pFntCache
Definition: fntcache.cxx:66
friend void FinitCore()
Definition: init.cxx:666
sal_Int32 m_nIndex
Definition: fntcache.hxx:71
vcl::Font * GetScrFont()
Definition: fntcache.hxx:125
void SetDevFont(const SwViewShell *pSh, OutputDevice &rOut)
Definition: fntcache.cxx:659
SwFntObj * Get()
Definition: fntcache.hxx:177
sal_Int32 m_nLength
Definition: fntcache.hxx:72
virtual ~SwFntObj() override
Definition: fntcache.cxx:160
The Cache object base class Users of the Cache must derive a class from the SwCacheObj and store thei...
Definition: swcache.hxx:134
sal_uInt16 m_nPrtAscent
Definition: fntcache.hxx:105
SwFntObj * First()
Definition: fntcache.hxx:157
std::unordered_map< SwTextGlyphsKey, SwTextGlyphsData, SwTextGlyphsKeyHash > SwTextGlyphsMap
Definition: fntcache.hxx:90
SwFntObj(const SwSubFont &rFont, std::uintptr_t nFontCacheId, SwViewShell const *pSh)
Definition: fntcache.cxx:137
friend void InitCore()
Definition: init.cxx:447
void DrawText(SwDrawTextInfo &rInf)
Definition: fntcache.cxx:855
Access class for the Cache.
Definition: swcache.hxx:195
sal_uInt16 m_nGuessedLeading
Definition: fntcache.hxx:102
static tools::Long s_nPixWidth
Definition: fntcache.hxx:116
vcl::Font m_aFont
Definition: fntcache.hxx:98
sal_uInt16 GetExternalLeading() const
Definition: fntcache.hxx:130
SwTextGlyphsMap m_aTextGlyphs
Cache of already calculated layout glyphs and text widths.
Definition: fntcache.hxx:114
const vcl::Font & GetFont() const
Definition: fntcache.hxx:127
sal_uInt16 m_nScrAscent
Definition: fntcache.hxx:104
Size GetTextSize(SwDrawTextInfo &rInf)
determine the TextSize (of the printer)
Definition: fntcache.cxx:1897
sal_uInt16 m_nPrtHeight
Definition: fntcache.hxx:107