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 <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 
63 struct SwTextGlyphsKey;
64 bool operator<(const SwTextGlyphsKey& l, const SwTextGlyphsKey& r);
65 struct SwTextGlyphsData;
66 
67 class SwFntObj final : public SwCacheObj
68 {
69  friend class SwFntAccess;
70  friend void InitCore();
71  friend void FinitCore();
72 
77  sal_uInt16 m_nGuessedLeading;
78  sal_uInt16 m_nExtLeading;
79  sal_uInt16 m_nScrAscent;
80  sal_uInt16 m_nPrtAscent;
81  sal_uInt16 m_nScrHeight;
82  sal_uInt16 m_nPrtHeight;
83  sal_uInt16 m_nPropWidth;
84  sal_uInt16 m_nZoom;
85  bool m_bSymbol : 1;
86  bool m_bPaintBlank : 1;
87 
89  std::map<SwTextGlyphsKey, SwTextGlyphsData> m_aTextGlyphs;
90 
92  static MapMode *s_pPixMap;
93 
94 public:
95  SwFntObj( const SwSubFont &rFont, std::uintptr_t nFontCacheId,
96  SwViewShell const *pSh );
97 
98  virtual ~SwFntObj() override;
99 
101  vcl::Font& GetFont() { return m_aFont; }
102  const vcl::Font& GetFont() const { return m_aFont; }
103 
104  sal_uInt16 GetGuessedLeading() const { return m_nGuessedLeading; }
105  sal_uInt16 GetExternalLeading() const { return m_nExtLeading; }
106 
107  sal_uInt16 GetFontAscent( const SwViewShell *pSh, const OutputDevice& rOut );
108  sal_uInt16 GetFontHeight( const SwViewShell *pSh, const OutputDevice& rOut );
109  sal_uInt16 GetFontLeading( const SwViewShell *pSh, const OutputDevice& rOut );
110 
111  void GuessLeading( const SwViewShell& rSh, const FontMetric& rMet );
112 
113  void SetDevFont( const SwViewShell *pSh, OutputDevice& rOut );
114  OutputDevice* GetPrt() const { return m_pPrinter; }
115  sal_uInt16 GetZoom() const { return m_nZoom; }
116  sal_uInt16 GetPropWidth() const { return m_nPropWidth; }
117  bool IsSymbol() const { return m_bSymbol; }
118 
121  void ClearCachedTextGlyphs();
122 
123  void DrawText( SwDrawTextInfo &rInf );
127 
128  void CreateScrFont( const SwViewShell& rSh, const OutputDevice& rOut );
129  void CreatePrtFont( const OutputDevice& rOut );
130 };
131 
133 {
134  return static_cast<SwFntObj *>(SwCache::First());
135 }
136 
138 {
139  return static_cast<SwFntObj *>(SwCache::Next( pFntObj ));
140 }
141 
142 class SwFntAccess final : public SwCacheAccess
143 {
145 
146  virtual SwCacheObj *NewObj( ) override;
147 
148 public:
149  SwFntAccess( const void*& rnFontCacheId, sal_uInt16 &rIndex, const void *pOwner,
150  SwViewShell const *pShell,
151  bool bCheck = false );
152  SwFntObj* Get() { return static_cast<SwFntObj*>( SwCacheAccess::Get() ); }
153 };
154 
155 #endif
156 
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OutputDevice * GetPrt() const
Definition: fntcache.hxx:114
SwFntObj * pLastFont
Definition: fntcache.cxx:67
sal_uInt16 m_nExtLeading
Definition: fntcache.hxx:78
void SwClearFntCacheTextGlyphs()
Clears the pre-calculated text glyphs in all SwFntObj instances.
Definition: fntcache.cxx:2746
bool operator<(const SwTextGlyphsKey &l, const SwTextGlyphsKey &r)
Definition: fntcache.cxx:121
void CreateScrFont(const SwViewShell &rSh, const OutputDevice &rOut)
Definition: fntcache.cxx:525
virtual SwCacheObj * NewObj() override
Can be use in NewObj.
Definition: fntcache.cxx:2408
SwFntAccess(const void *&rnFontCacheId, sal_uInt16 &rIndex, const void *pOwner, SwViewShell const *pShell, bool bCheck=false)
Definition: fntcache.cxx:2304
bool m_bPaintBlank
Definition: fntcache.hxx:86
sal_uInt16 m_nPropWidth
Definition: fntcache.hxx:83
SwCacheObj * First()
Definition: swcache.hxx:115
sal_uInt16 GetFontHeight(const SwViewShell *pSh, const OutputDevice &rOut)
Definition: fntcache.cxx:434
bool m_bSymbol
Definition: fntcache.hxx:85
static SwCacheObj * Next(SwCacheObj *pCacheObj)
Definition: swcache.hxx:222
long Long
TextFrameIndex GetModelPositionForViewPoint(SwDrawTextInfo &rInf)
Definition: fntcache.cxx:2118
sal_uInt16 GetFontAscent(const SwViewShell *pSh, const OutputDevice &rOut)
Definition: fntcache.cxx:397
sal_uInt16 m_nScrHeight
Definition: fntcache.hxx:81
void ClearCachedTextGlyphs()
Definition: fntcache.cxx:276
sal_uInt16 GetGuessedLeading() const
Definition: fntcache.hxx:104
sal_uInt16 GetZoom() const
Definition: fntcache.hxx:115
VclPtr< OutputDevice > m_pPrinter
Definition: fntcache.hxx:76
SalLayoutGlyphs * GetCachedSalLayoutGlyphs(const SwTextGlyphsKey &key)
Definition: fntcache.cxx:244
SwCacheObj * Get(bool isDuplicateOwnerAllowed)
Definition: swcache.hxx:257
vcl::Font & GetFont()
Definition: fntcache.hxx:101
static SwFntObj * Next(SwFntObj *pFntObj)
Definition: fntcache.hxx:137
sal_uInt16 GetFontLeading(const SwViewShell *pSh, const OutputDevice &rOut)
Definition: fntcache.cxx:473
void Flush()
Definition: fntcache.cxx:154
bool IsSymbol() const
Definition: fntcache.hxx:117
Defines a substring on a given output device, to be used as an std::map<> key.
Definition: fntcache.cxx:79
vcl::Font * m_pScrFont
Definition: fntcache.hxx:74
void CreatePrtFont(const OutputDevice &rOut)
Definition: fntcache.cxx:195
vcl::Font * m_pPrtFont
Definition: fntcache.hxx:75
void GuessLeading(const SwViewShell &rSh, const FontMetric &rMet)
Definition: fntcache.cxx:599
SwViewShell const * m_pShell
Definition: fntcache.hxx:144
static MapMode * s_pPixMap
Definition: fntcache.hxx:92
sal_uInt16 m_nZoom
Definition: fntcache.hxx:84
sal_uInt16 GetPropWidth() const
Definition: fntcache.hxx:116
std::map< SwTextGlyphsKey, SwTextGlyphsData > m_aTextGlyphs
Cache of already calculated layout glyphs and text widths.
Definition: fntcache.hxx:89
Glyphs and text width for the given SwTextGlyphsKey.
Definition: fntcache.cxx:91
SwFntCache * pFntCache
Definition: fntcache.cxx:65
friend void FinitCore()
Definition: init.cxx:665
vcl::Font * GetScrFont()
Definition: fntcache.hxx:100
void SetDevFont(const SwViewShell *pSh, OutputDevice &rOut)
Definition: fntcache.cxx:679
SwFntObj * Get()
Definition: fntcache.hxx:152
virtual ~SwFntObj() override
Definition: fntcache.cxx:187
The Cache object base class Users of the Cache must derive a class from the SwCacheObj and store thei...
Definition: swcache.hxx:134
tools::Long GetCachedTextWidth(const SwTextGlyphsKey &key, const vcl::TextLayoutCache *vclCache)
Definition: fntcache.cxx:260
sal_uInt16 m_nPrtAscent
Definition: fntcache.hxx:80
SwFntObj * First()
Definition: fntcache.hxx:132
SwFntObj(const SwSubFont &rFont, std::uintptr_t nFontCacheId, SwViewShell const *pSh)
Definition: fntcache.cxx:164
friend void InitCore()
Definition: init.cxx:446
void DrawText(SwDrawTextInfo &rInf)
Definition: fntcache.cxx:875
Access class for the Cache.
Definition: swcache.hxx:195
sal_uInt16 m_nGuessedLeading
Definition: fntcache.hxx:77
static tools::Long s_nPixWidth
Definition: fntcache.hxx:91
vcl::Font m_aFont
Definition: fntcache.hxx:73
sal_uInt16 GetExternalLeading() const
Definition: fntcache.hxx:105
const vcl::Font & GetFont() const
Definition: fntcache.hxx:102
sal_uInt16 m_nScrAscent
Definition: fntcache.hxx:79
Size GetTextSize(SwDrawTextInfo &rInf)
determine the TextSize (of the printer)
Definition: fntcache.cxx:1919
sal_uInt16 m_nPrtHeight
Definition: fntcache.hxx:82