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_VCL_INC_GENERIC_GLYPHCACHE_HXX
21 #define INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
25 #include FT_FREETYPE_H
28 #include <com/sun/star/i18n/XBreakIterator.hpp>
29 #include <tools/gen.hxx>
30 #include <vcl/dllapi.h>
31 #include <vcl/metric.hxx>
33 #include <sallayout.hxx>
34 #include <fontattributes.hxx>
35 #include <fontselect.hxx>
36 #include <impfontmetricdata.hxx>
39 #include <unordered_map>
41 class FreetypeManager
;
42 class FreetypeFontInfo
;
44 class FontConfigFontOptions
;
45 class PhysicalFontCollection
;
49 namespace basegfx
{ class B2DPolyPolygon
; }
50 namespace vcl
{ struct FontCapabilities
; }
52 class VCL_DLLPUBLIC GlyphCache
55 explicit GlyphCache();
56 virtual ~GlyphCache();
58 static GlyphCache
& GetInstance();
61 const OString
& rNormalizedName
,
62 int nFaceNum
, sal_IntPtr nFontId
,
63 const FontAttributes
&);
65 void AnnounceFonts( PhysicalFontCollection
* ) const;
67 FreetypeFont
* CacheFont( const FontSelectPattern
& );
68 void UncacheFont( FreetypeFont
& );
69 void ClearFontCache();
70 void InvalidateAllGlyphs();
71 void ClearFontOptions();
74 friend class FreetypeFont
;
75 // used by FreetypeFont class only
76 void AddedGlyph( GlyphData
& );
78 void UsingGlyph( GlyphData
const & );
81 void GarbageCollect();
83 // the GlyphCache's FontList matches a font request to a serverfont instance
84 // the FontList key's mpFontData member is reinterpreted as integer font id
85 struct IFSD_Equal
{ bool operator()( const FontSelectPattern
&, const FontSelectPattern
& ) const; };
86 struct IFSD_Hash
{ size_t operator()( const FontSelectPattern
& ) const; };
87 typedef std::unordered_map
<FontSelectPattern
,FreetypeFont
*,IFSD_Hash
,IFSD_Equal
> FontList
;
90 sal_uLong mnMaxSize
; // max overall cache size in bytes
91 mutable sal_uLong mnBytesUsed
;
92 mutable long mnLruIndex
;
93 mutable int mnGlyphCount
;
94 FreetypeFont
* mpCurrentGCFont
;
96 std::unique_ptr
<FreetypeManager
> mpFtManager
;
102 GlyphData() : mnLruValue(0) {}
104 const tools::Rectangle
& GetBoundRect() const { return maBoundRect
; }
105 void SetBoundRect(tools::Rectangle r
) { maBoundRect
= r
; }
107 void SetLruValue( int n
) const { mnLruValue
= n
; }
108 long GetLruValue() const { return mnLruValue
;}
111 tools::Rectangle maBoundRect
;
113 // used by GlyphCache for cache LRU algorithm
114 mutable long mnLruValue
;
117 class VCL_DLLPUBLIC FreetypeFont final
120 FreetypeFont( const FontSelectPattern
&, FreetypeFontInfo
* );
123 const OString
& GetFontFileName() const;
124 int GetFontFaceIndex() const;
125 bool TestFont() const { return mbFaceOk
;}
126 FT_Face
GetFtFace() const;
127 int GetLoadFlags() const { return (mnLoadFlags
& ~FT_LOAD_IGNORE_TRANSFORM
); }
128 const FontConfigFontOptions
* GetFontOptions() const;
129 void ClearFontOptions();
130 bool NeedsArtificialBold() const { return mbArtBold
; }
131 bool NeedsArtificialItalic() const { return mbArtItalic
; }
133 void GetFontMetric(ImplFontMetricDataRef
const &) const;
134 const unsigned char* GetTable( const char* pName
, sal_uLong
* pLength
) const;
135 const FontCharMapRef
GetFontCharMap() const;
136 bool GetFontCapabilities(vcl::FontCapabilities
&) const;
138 const tools::Rectangle
& GetGlyphBoundRect(const GlyphItem
& rGlyph
);
139 bool GetGlyphOutline(const GlyphItem
& rGlyph
, basegfx::B2DPolyPolygon
&) const;
140 bool GetAntialiasAdvice() const;
142 LogicalFontInstance
* GetFontInstance() const { return mpFontInstance
; }
145 friend class GlyphCache
;
146 friend class FreetypeFontInstance
;
147 friend class X11SalGraphics
;
148 friend class CairoTextRender
;
150 void AddRef() const { ++mnRefCount
; }
151 long GetRefCount() const { return mnRefCount
; }
152 long Release() const;
153 sal_uLong
GetByteCount() const { return mnBytesUsed
; }
155 void InitGlyphData(const GlyphItem
&, GlyphData
&) const;
156 void GarbageCollect( long );
157 void ReleaseFromGarbageCollect();
159 void ApplyGlyphTransform(bool bVertical
, FT_Glyph
) const;
161 typedef std::unordered_map
<int,GlyphData
> GlyphList
;
162 mutable GlyphList maGlyphList
;
164 LogicalFontInstance
* const mpFontInstance
;
166 // used by GlyphCache for cache LRU algorithm
167 mutable long mnRefCount
;
168 mutable sal_uLong mnBytesUsed
;
170 FreetypeFont
* mpPrevGCFont
;
171 FreetypeFont
* mpNextGCFont
;
173 // 16.16 fixed point values used for a rotated font
179 FreetypeFontInfo
* mpFontInfo
;
182 FT_FaceRec_
* maFaceFT
;
183 FT_SizeRec_
* maSizeFT
;
185 mutable std::unique_ptr
<FontConfigFontOptions
> mxFontOptions
;
192 #endif // INCLUDED_VCL_INC_GENERIC_GLYPHCACHE_HXX
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */