/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #ifndef INCLUDED_VCL_GLYPHITEMCACHE_HXX #define INCLUDED_VCL_GLYPHITEMCACHE_HXX #include #include #include #include #include #include #include #include /** A cache for SalLayoutGlyphs objects. Allows caching for OutputDevice::DrawText() and similar calls. Pass the text and the output device for the call to OutputDevice::ImplLayout(). Items are cached per output device and its font. If something more changes, call clear(). */ class VCL_DLLPUBLIC SalLayoutGlyphsCache final { public: SalLayoutGlyphsCache(int size = 1000) : mCachedGlyphs(size) { } const SalLayoutGlyphs* GetLayoutGlyphs(VclPtr outputDevice, const OUString& text) const { return GetLayoutGlyphs(outputDevice, text, 0, text.getLength()); } const SalLayoutGlyphs* GetLayoutGlyphs(VclPtr outputDevice, const OUString& text, sal_Int32 nIndex, sal_Int32 nLen, const Point& rLogicPos = Point(0, 0), tools::Long nLogicWidth = 0) const; void clear() { mCachedGlyphs.clear(); } private: struct CachedGlyphsKey { VclPtr outputDevice; OUString text; sal_Int32 index; sal_Int32 len; Point logicPos; tools::Long logicWidth; size_t hashValue; CachedGlyphsKey(const VclPtr& dev, const OUString& t, sal_Int32 i, sal_Int32 l, const Point& p, tools::Long w); bool operator==(const CachedGlyphsKey& other) const; }; struct CachedGlyphsHash { size_t operator()(const CachedGlyphsKey& key) const { return key.hashValue; } }; mutable o3tl::lru_map mCachedGlyphs; SalLayoutGlyphsCache(const SalLayoutGlyphsCache&) = delete; SalLayoutGlyphsCache& operator=(const SalLayoutGlyphsCache&) = delete; }; #endif // INCLUDED_VCL_GLYPHITEMCACHE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */