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 <map>
24 
25 #include <vcl/font.hxx>
26 #include <vcl/vclptr.hxx>
27 #include <vcl/vcllayout.hxx>
28 #include <vcl/outdev.hxx>
29 #include "swcache.hxx"
30 #include "TextFrameIndex.hxx"
31 
32 class FontMetric;
33 class SwFntObj;
34 class SwDrawTextInfo;
35 class SwViewShell;
36 class SwSubFont;
37 class MapMode;
38 
39 class SwFntCache : public SwCache
40 {
41 public:
43 #ifdef DBG_UTIL
44  , OString(RTL_CONSTASCII_STRINGPARAM("Global Font-Cache pFntCache"))
45 #endif
46  ) {}
47 
48  inline SwFntObj *First( );
49  static inline SwFntObj *Next( SwFntObj *pFntObj);
50  void Flush();
51 };
52 
55 
56 // Font cache, global variable, created/destroyed in txtinit.cxx
57 extern SwFntCache *pFntCache;
58 extern SwFntObj *pLastFont;
60 
66 {
68  OUString m_aText;
69  sal_Int32 m_nIndex;
70  sal_Int32 m_nLength;
71 
72 };
73 bool operator<(const SwTextGlyphsKey& l, const SwTextGlyphsKey& r);
74 
75 class SwFntObj : public SwCacheObj
76 {
77  friend class SwFntAccess;
78  friend void InitCore();
79  friend void FinitCore();
80 
85  sal_uInt16 m_nGuessedLeading;
86  sal_uInt16 m_nExtLeading;
87  sal_uInt16 m_nScrAscent;
88  sal_uInt16 m_nPrtAscent;
89  sal_uInt16 m_nScrHeight;
90  sal_uInt16 m_nPrtHeight;
91  sal_uInt16 const m_nPropWidth;
92  sal_uInt16 m_nZoom;
93  bool m_bSymbol : 1;
94  bool m_bPaintBlank : 1;
95 
97  std::map<SwTextGlyphsKey, SalLayoutGlyphs> m_aTextGlyphs;
98 
99  static long nPixWidth;
100  static MapMode *pPixMap;
101 
102 public:
103  SwFntObj( const SwSubFont &rFont, const void* nFontCacheId,
104  SwViewShell const *pSh );
105 
106  virtual ~SwFntObj() override;
107 
109  vcl::Font& GetFont() { return m_aFont; }
110  const vcl::Font& GetFont() const { return m_aFont; }
111 
112  sal_uInt16 GetGuessedLeading() const { return m_nGuessedLeading; }
113  sal_uInt16 GetExternalLeading() const { return m_nExtLeading; }
114 
115  sal_uInt16 GetFontAscent( const SwViewShell *pSh, const OutputDevice& rOut );
116  sal_uInt16 GetFontHeight( const SwViewShell *pSh, const OutputDevice& rOut );
117  sal_uInt16 GetFontLeading( const SwViewShell *pSh, const OutputDevice& rOut );
118 
119  void GuessLeading( const SwViewShell& rSh, const FontMetric& rMet );
120 
121  void SetDevFont( const SwViewShell *pSh, OutputDevice& rOut );
122  OutputDevice* GetPrt() const { return m_pPrinter; }
123  sal_uInt16 GetZoom() const { return m_nZoom; }
124  sal_uInt16 GetPropWidth() const { return m_nPropWidth; }
125  bool IsSymbol() const { return m_bSymbol; }
126  std::map<SwTextGlyphsKey, SalLayoutGlyphs>& GetTextGlyphs() { return m_aTextGlyphs; }
127 
128  void DrawText( SwDrawTextInfo &rInf );
132 
133  void CreateScrFont( const SwViewShell& rSh, const OutputDevice& rOut );
134  void CreatePrtFont( const OutputDevice& rOut );
135 };
136 
138 {
139  return static_cast<SwFntObj *>(SwCache::First());
140 }
141 
143 {
144  return static_cast<SwFntObj *>(SwCache::Next( pFntObj ));
145 }
146 
148 {
150 protected:
151  virtual SwCacheObj *NewObj( ) override;
152 
153 public:
154  SwFntAccess( const void*& rnFontCacheId, sal_uInt16 &rIndex, const void *pOwner,
155  SwViewShell const *pShell,
156  bool bCheck = false );
157  SwFntObj* Get() { return static_cast<SwFntObj*>( SwCacheAccess::Get() ); }
158 };
159 
160 #endif
161 
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OutputDevice * GetPrt() const
Definition: fntcache.hxx:122
SwFntObj * pLastFont
Definition: fntcache.cxx:69
sal_uInt16 m_nExtLeading
Definition: fntcache.hxx:86
void SwClearFntCacheTextGlyphs()
Clears the pre-calculated text glyphs in all SwFntObj instances.
Definition: fntcache.cxx:2713
SwFntObj(const SwSubFont &rFont, const void *nFontCacheId, SwViewShell const *pSh)
Definition: fntcache.cxx:176
bool operator<(const SwTextGlyphsKey &l, const SwTextGlyphsKey &r)
Definition: fntcache.cxx:133
void CreateScrFont(const SwViewShell &rSh, const OutputDevice &rOut)
Definition: fntcache.cxx:471
virtual SwCacheObj * NewObj() override
Can be use in NewObj.
Definition: fntcache.cxx:2383
SwFntAccess(const void *&rnFontCacheId, sal_uInt16 &rIndex, const void *pOwner, SwViewShell const *pShell, bool bCheck=false)
Definition: fntcache.cxx:2279
bool m_bPaintBlank
Definition: fntcache.hxx:94
std::map< SwTextGlyphsKey, SalLayoutGlyphs > m_aTextGlyphs
Cache of already calculated layout glyphs.
Definition: fntcache.hxx:97
SwCacheObj * First()
Definition: swcache.hxx:114
sal_uInt8 * mnFontCacheIdCounter
Definition: fntcache.cxx:71
sal_uInt16 GetFontHeight(const SwViewShell *pSh, const OutputDevice &rOut)
Definition: fntcache.cxx:380
bool m_bSymbol
Definition: fntcache.hxx:93
static SwCacheObj * Next(SwCacheObj *pCacheObj)
Definition: swcache.hxx:225
sal_uInt16 GetFontAscent(const SwViewShell *pSh, const OutputDevice &rOut)
Definition: fntcache.cxx:343
sal_uInt16 m_nScrHeight
Definition: fntcache.hxx:89
sal_uInt16 GetGuessedLeading() const
Definition: fntcache.hxx:112
std::map< SwTextGlyphsKey, SalLayoutGlyphs > & GetTextGlyphs()
Definition: fntcache.hxx:126
VclPtr< OutputDevice > m_pOutputDevice
Definition: fntcache.hxx:67
sal_uInt16 GetZoom() const
Definition: fntcache.hxx:123
VclPtr< OutputDevice > m_pPrinter
Definition: fntcache.hxx:84
SwCacheObj * Get(bool isDuplicateOwnerAllowed)
Definition: swcache.hxx:252
vcl::Font & GetFont()
Definition: fntcache.hxx:109
static SwFntObj * Next(SwFntObj *pFntObj)
Definition: fntcache.hxx:142
sal_uInt16 GetFontLeading(const SwViewShell *pSh, const OutputDevice &rOut)
Definition: fntcache.cxx:419
TextFrameIndex GetCursorOfst(SwDrawTextInfo &rInf)
Definition: fntcache.cxx:2093
void Flush()
Definition: fntcache.cxx:166
bool IsSymbol() const
Definition: fntcache.hxx:125
Defines a substring on a given output device, to be used as an std::map<> key.
Definition: fntcache.hxx:65
OUString m_aText
Definition: fntcache.hxx:68
vcl::Font * m_pScrFont
Definition: fntcache.hxx:82
void CreatePrtFont(const OutputDevice &rOut)
Definition: fntcache.cxx:207
vcl::Font * m_pPrtFont
Definition: fntcache.hxx:83
void GuessLeading(const SwViewShell &rSh, const FontMetric &rMet)
Definition: fntcache.cxx:563
SwViewShell const * m_pShell
Definition: fntcache.hxx:149
sal_uInt16 m_nZoom
Definition: fntcache.hxx:92
sal_uInt16 GetPropWidth() const
Definition: fntcache.hxx:124
sal_uInt16 const m_nPropWidth
Definition: fntcache.hxx:91
SwFntCache * pFntCache
Definition: fntcache.cxx:67
friend void FinitCore()
Definition: init.cxx:670
sal_Int32 m_nIndex
Definition: fntcache.hxx:69
vcl::Font * GetScrFont()
Definition: fntcache.hxx:108
void SetDevFont(const SwViewShell *pSh, OutputDevice &rOut)
Definition: fntcache.cxx:643
static long nPixWidth
Definition: fntcache.hxx:99
SwFntObj * Get()
Definition: fntcache.hxx:157
sal_Int32 m_nLength
Definition: fntcache.hxx:70
virtual ~SwFntObj() override
Definition: fntcache.cxx:199
unsigned char sal_uInt8
The Cache object base class Users of the Cache must derive a class from the SwCacheObj and store thei...
Definition: swcache.hxx:133
static MapMode * pPixMap
Definition: fntcache.hxx:100
sal_uInt16 m_nPrtAscent
Definition: fntcache.hxx:88
SwFntObj * First()
Definition: fntcache.hxx:137
friend void InitCore()
Definition: init.cxx:454
void DrawText(SwDrawTextInfo &rInf)
Definition: fntcache.cxx:839
Access class for the Cache.
Definition: swcache.hxx:194
sal_uInt16 m_nGuessedLeading
Definition: fntcache.hxx:85
vcl::Font m_aFont
Definition: fntcache.hxx:81
sal_uInt16 GetExternalLeading() const
Definition: fntcache.hxx:113
const vcl::Font & GetFont() const
Definition: fntcache.hxx:110
sal_uInt16 m_nScrAscent
Definition: fntcache.hxx:87
Size GetTextSize(SwDrawTextInfo &rInf)
determine the TextSize (of the printer)
Definition: fntcache.cxx:1891
sal_uInt16 m_nPrtHeight
Definition: fntcache.hxx:90