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_IMPFONTCACHE_HXX
21 #define INCLUDED_VCL_INC_IMPFONTCACHE_HXX
24 #include <rtl/ref.hxx>
25 #include <o3tl/lru_map.hxx>
26 #include <o3tl/hash_combine.hxx>
27 #include <tools/gen.hxx>
28 #include <vcl/glyphitem.hxx>
30 #include "fontselect.hxx"
33 namespace vcl
{ class Font
; }
34 class PhysicalFontCollection
;
36 // TODO: closely couple with PhysicalFontCollection
38 struct GlyphBoundRectCacheKey
40 const LogicalFontInstance
* m_pFont
;
41 const sal_GlyphId m_nId
;
43 GlyphBoundRectCacheKey(const LogicalFontInstance
* pFont
, sal_GlyphId nID
)
44 : m_pFont(pFont
), m_nId(nID
)
47 bool operator==(GlyphBoundRectCacheKey
const& aOther
) const
48 { return m_pFont
== aOther
.m_pFont
&& m_nId
== aOther
.m_nId
; }
51 struct GlyphBoundRectCacheHash
53 std::size_t operator()(GlyphBoundRectCacheKey
const& aCache
) const
56 o3tl::hash_combine(seed
, aCache
.m_pFont
);
57 o3tl::hash_combine(seed
, aCache
.m_nId
);
62 typedef o3tl::lru_map
<GlyphBoundRectCacheKey
, tools::Rectangle
,
63 GlyphBoundRectCacheHash
> GlyphBoundRectCache
;
68 // cache of recently used font instances
69 struct IFSD_Equal
{ bool operator()( const FontSelectPattern
&, const FontSelectPattern
& ) const; };
70 struct IFSD_Hash
{ size_t operator()( const FontSelectPattern
& ) const; };
71 typedef o3tl::lru_map
<FontSelectPattern
, rtl::Reference
<LogicalFontInstance
>, IFSD_Hash
, IFSD_Equal
> FontInstanceList
;
73 LogicalFontInstance
* mpLastHitCacheEntry
; ///< keeps the last hit cache entry
74 FontInstanceList maFontInstanceList
;
75 GlyphBoundRectCache m_aBoundRectCache
;
77 rtl::Reference
<LogicalFontInstance
> GetFontInstance(PhysicalFontCollection
const*, FontSelectPattern
&);
83 rtl::Reference
<LogicalFontInstance
> GetFontInstance(PhysicalFontCollection
const *,
84 const vcl::Font
&, const Size
& rPixelSize
, float fExactHeight
, bool bNonAntialias
= false);
85 rtl::Reference
<LogicalFontInstance
> GetGlyphFallbackFont( PhysicalFontCollection
const *, FontSelectPattern
&,
86 LogicalFontInstance
* pLogicalFont
,
87 int nFallbackLevel
, OUString
& rMissingCodes
);
89 bool GetCachedGlyphBoundRect(const LogicalFontInstance
*, sal_GlyphId
, tools::Rectangle
&);
90 void CacheGlyphBoundRect(const LogicalFontInstance
*, sal_GlyphId
, tools::Rectangle
&);
95 #endif // INCLUDED_VCL_INC_IMPFONTCACHE_HXX
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */