LibreOffice Module vcl (master) 1
glyphitemcache.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_VCL_GLYPHITEMCACHE_HXX
21#define INCLUDED_VCL_GLYPHITEMCACHE_HXX
22
23#include <sal/types.h>
24#include <vcl/dllapi.h>
25
26#include <o3tl/lru_map.hxx>
27#include <o3tl/hash_combine.hxx>
28#include <vcl/glyphitem.hxx>
29#include <vcl/metric.hxx>
30#include <vcl/outdev.hxx>
31#include <vcl/vclptr.hxx>
32#include <tools/gen.hxx>
33
34#include <optional>
35
44{
45public:
46 // NOTE: The lifetime of the returned value is guaranteed only until the next call
47 // to any function in this class.
49 const OUString& text,
50 const vcl::text::TextLayoutCache* layoutCache = nullptr)
51 {
52 return GetLayoutGlyphs(outputDevice, text, 0, text.getLength(), 0, layoutCache);
53 }
54 const SalLayoutGlyphs* GetLayoutGlyphs(VclPtr<const OutputDevice> outputDevice,
55 const OUString& text, sal_Int32 nIndex, sal_Int32 nLen,
56 tools::Long nLogicWidth = 0,
57 const vcl::text::TextLayoutCache* layoutCache = nullptr);
58 void clear();
59
60 static SalLayoutGlyphsCache* self();
61 SalLayoutGlyphsCache(int size) // needs to be public for vcl::DeleteOnDeinit
62 : mCachedGlyphs(size)
63 {
64 }
65
66private:
68 {
69 OUString text;
70 sal_Int32 index;
71 sal_Int32 len;
74 double fontScaleX;
75 double fontScaleY;
77 bool rtl;
80 size_t hashValue;
81 CachedGlyphsKey(const VclPtr<const OutputDevice>& dev, const OUString& t, sal_Int32 i,
82 sal_Int32 l, tools::Long w);
83 bool operator==(const CachedGlyphsKey& other) const;
84 };
86 {
87 size_t operator()(const CachedGlyphsKey& key) const { return key.hashValue; }
88 };
90 {
91 size_t operator()(const SalLayoutGlyphs&) const;
92 };
94 std::equal_to<CachedGlyphsKey>, GlyphsCost>
97 // Last temporary glyphs returned (pointer is returned, so the object needs to be kept somewhere).
98 std::optional<CachedGlyphsKey> mLastTemporaryKey;
100 // If set, info about the last call which wanted a substring of the full text.
101 std::optional<CachedGlyphsKey> mLastSubstringKey;
102
105};
106
107#endif // INCLUDED_VCL_GLYPHITEMCACHE_HXX
108
109/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A cache for SalLayoutGlyphs objects.
std::optional< CachedGlyphsKey > mLastTemporaryKey
SalLayoutGlyphs mLastTemporaryGlyphs
o3tl::lru_map< CachedGlyphsKey, SalLayoutGlyphs, CachedGlyphsHash, std::equal_to< CachedGlyphsKey >, GlyphsCost > GlyphsCache
std::optional< CachedGlyphsKey > mLastSubstringKey
SalLayoutGlyphsCache & operator=(const SalLayoutGlyphsCache &)=delete
SalLayoutGlyphsCache(const SalLayoutGlyphsCache &)=delete
const SalLayoutGlyphs * GetLayoutGlyphs(VclPtr< const OutputDevice > outputDevice, const OUString &text, const vcl::text::TextLayoutCache *layoutCache=nullptr)
SalLayoutGlyphsCache(int size)
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
def text(shape, orig_st)
size
long Long
ComplexTextLayoutFlags
Definition: State.hxx:76
size_t operator()(const CachedGlyphsKey &key) const
vcl::text::ComplexTextLayoutFlags layoutMode
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:182