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:
SwFntCache()45 SwFntCache() : SwCache(50
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
56 /// Clears the pre-calculated text glyphs in all SwFntObj instances.
57 void SwClearFntCacheTextGlyphs();
58
59 // Font cache, global variable, created/destroyed in txtinit.cxx
60 extern SwFntCache *pFntCache;
61 extern SwFntObj *pLastFont;
62
63 /**
64 * Defines a substring on a given output device, to be used as an std::map<>
65 * key.
66 */
67 struct SwTextGlyphsKey
68 {
69 VclPtr<OutputDevice> m_pOutputDevice;
70 OUString m_aText;
71 sal_Int32 m_nIndex;
72 sal_Int32 m_nLength;
73
74 };
75 bool operator<(const SwTextGlyphsKey& l, const SwTextGlyphsKey& r);
76
77 class SwFntObj : public SwCacheObj
78 {
79 friend class SwFntAccess;
80 friend void InitCore();
81 friend void FinitCore();
82
83 vcl::Font m_aFont;
84 vcl::Font *m_pScrFont;
85 vcl::Font *m_pPrtFont;
86 VclPtr<OutputDevice> m_pPrinter;
87 sal_uInt16 m_nGuessedLeading;
88 sal_uInt16 m_nExtLeading;
89 sal_uInt16 m_nScrAscent;
90 sal_uInt16 m_nPrtAscent;
91 sal_uInt16 m_nScrHeight;
92 sal_uInt16 m_nPrtHeight;
93 sal_uInt16 const m_nPropWidth;
94 sal_uInt16 m_nZoom;
95 bool m_bSymbol : 1;
96 bool m_bPaintBlank : 1;
97
98 /// Cache of already calculated layout glyphs.
99 std::map<SwTextGlyphsKey, SalLayoutGlyphs> m_aTextGlyphs;
100
101 static long nPixWidth;
102 static MapMode *pPixMap;
103
104 public:
105 SwFntObj( const SwSubFont &rFont, std::uintptr_t nFontCacheId,
106 SwViewShell const *pSh );
107
108 virtual ~SwFntObj() override;
109
GetScrFont()110 vcl::Font *GetScrFont() { return m_pScrFont; }
GetFont()111 vcl::Font& GetFont() { return m_aFont; }
GetFont() const112 const vcl::Font& GetFont() const { return m_aFont; }
113
GetGuessedLeading() const114 sal_uInt16 GetGuessedLeading() const { return m_nGuessedLeading; }
GetExternalLeading() const115 sal_uInt16 GetExternalLeading() const { return m_nExtLeading; }
116
117 sal_uInt16 GetFontAscent( const SwViewShell *pSh, const OutputDevice& rOut );
118 sal_uInt16 GetFontHeight( const SwViewShell *pSh, const OutputDevice& rOut );
119 sal_uInt16 GetFontLeading( const SwViewShell *pSh, const OutputDevice& rOut );
120
121 void GuessLeading( const SwViewShell& rSh, const FontMetric& rMet );
122
123 void SetDevFont( const SwViewShell *pSh, OutputDevice& rOut );
GetPrt() const124 OutputDevice* GetPrt() const { return m_pPrinter; }
GetZoom() const125 sal_uInt16 GetZoom() const { return m_nZoom; }
GetPropWidth() const126 sal_uInt16 GetPropWidth() const { return m_nPropWidth; }
IsSymbol() const127 bool IsSymbol() const { return m_bSymbol; }
GetTextGlyphs()128 std::map<SwTextGlyphsKey, SalLayoutGlyphs>& GetTextGlyphs() { return m_aTextGlyphs; }
129
130 void DrawText( SwDrawTextInfo &rInf );
131 /// determine the TextSize (of the printer)
132 Size GetTextSize( SwDrawTextInfo &rInf );
133 TextFrameIndex GetCursorOfst(SwDrawTextInfo &rInf);
134
135 void CreateScrFont( const SwViewShell& rSh, const OutputDevice& rOut );
136 void CreatePrtFont( const OutputDevice& rOut );
137 };
138
First()139 SwFntObj *SwFntCache::First( )
140 {
141 return static_cast<SwFntObj *>(SwCache::First());
142 }
143
Next(SwFntObj * pFntObj)144 SwFntObj *SwFntCache::Next( SwFntObj *pFntObj)
145 {
146 return static_cast<SwFntObj *>(SwCache::Next( pFntObj ));
147 }
148
149 class SwFntAccess : public SwCacheAccess
150 {
151 SwViewShell const *m_pShell;
152 protected:
153 virtual SwCacheObj *NewObj( ) override;
154
155 public:
156 SwFntAccess( const void*& rnFontCacheId, sal_uInt16 &rIndex, const void *pOwner,
157 SwViewShell const *pShell,
158 bool bCheck = false );
Get()159 SwFntObj* Get() { return static_cast<SwFntObj*>( SwCacheAccess::Get() ); }
160 };
161
162 #endif
163
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
165