1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_FNTCACHE_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_FNTCACHE_HXX
23 #include <sal/config.h>
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"
42 class SwFntCache
: public SwCache
45 SwFntCache() : SwCache(50
47 , OString(RTL_CONSTASCII_STRINGPARAM("Global Font-Cache pFntCache"))
51 inline SwFntObj
*First( );
52 static inline SwFntObj
*Next( SwFntObj
*pFntObj
);
56 /// Clears the pre-calculated text glyphs in all SwFntObj instances.
57 void SwClearFntCacheTextGlyphs();
59 // Font cache, global variable, created/destroyed in txtinit.cxx
60 extern SwFntCache
*pFntCache
;
61 extern SwFntObj
*pLastFont
;
64 * Defines a substring on a given output device, to be used as an std::map<>
67 struct SwTextGlyphsKey
69 VclPtr
<OutputDevice
> m_pOutputDevice
;
75 bool operator<(const SwTextGlyphsKey
& l
, const SwTextGlyphsKey
& r
);
77 class SwFntObj
: public SwCacheObj
79 friend class SwFntAccess
;
80 friend void InitCore();
81 friend void FinitCore();
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 m_nPropWidth
;
96 bool m_bPaintBlank
: 1;
98 /// Cache of already calculated layout glyphs.
99 std::map
<SwTextGlyphsKey
, SalLayoutGlyphs
> m_aTextGlyphs
;
101 static tools::Long nPixWidth
;
102 static MapMode
*pPixMap
;
105 SwFntObj( const SwSubFont
&rFont
, std::uintptr_t nFontCacheId
,
106 SwViewShell
const *pSh
);
108 virtual ~SwFntObj() override
;
110 vcl::Font
*GetScrFont() { return m_pScrFont
; }
111 vcl::Font
& GetFont() { return m_aFont
; }
112 const vcl::Font
& GetFont() const { return m_aFont
; }
114 sal_uInt16
GetGuessedLeading() const { return m_nGuessedLeading
; }
115 sal_uInt16
GetExternalLeading() const { return m_nExtLeading
; }
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
);
121 void GuessLeading( const SwViewShell
& rSh
, const FontMetric
& rMet
);
123 void SetDevFont( const SwViewShell
*pSh
, OutputDevice
& rOut
);
124 OutputDevice
* GetPrt() const { return m_pPrinter
; }
125 sal_uInt16
GetZoom() const { return m_nZoom
; }
126 sal_uInt16
GetPropWidth() const { return m_nPropWidth
; }
127 bool IsSymbol() const { return m_bSymbol
; }
128 std::map
<SwTextGlyphsKey
, SalLayoutGlyphs
>& GetTextGlyphs() { return m_aTextGlyphs
; }
130 void DrawText( SwDrawTextInfo
&rInf
);
131 /// determine the TextSize (of the printer)
132 Size
GetTextSize( SwDrawTextInfo
&rInf
);
133 TextFrameIndex
GetModelPositionForViewPoint(SwDrawTextInfo
&rInf
);
135 void CreateScrFont( const SwViewShell
& rSh
, const OutputDevice
& rOut
);
136 void CreatePrtFont( const OutputDevice
& rOut
);
139 SwFntObj
*SwFntCache::First( )
141 return static_cast<SwFntObj
*>(SwCache::First());
144 SwFntObj
*SwFntCache::Next( SwFntObj
*pFntObj
)
146 return static_cast<SwFntObj
*>(SwCache::Next( pFntObj
));
149 class SwFntAccess
: public SwCacheAccess
151 SwViewShell
const *m_pShell
;
153 virtual SwCacheObj
*NewObj( ) override
;
156 SwFntAccess( const void*& rnFontCacheId
, sal_uInt16
&rIndex
, const void *pOwner
,
157 SwViewShell
const *pShell
,
158 bool bCheck
= false );
159 SwFntObj
* Get() { return static_cast<SwFntObj
*>( SwCacheAccess::Get() ); }
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */