Backed out changeset 5c7de47bcacb (bug 1927094) for causing Bug 1928689. a=backout
[gecko.git] / gfx / thebes / gfxFT2Fonts.h
blob3b164c711ef54b18d4b92b2a1643f387df697e51
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_FT2FONTS_H
7 #define GFX_FT2FONTS_H
9 #include "mozilla/MemoryReporting.h"
10 #include "gfxTypes.h"
11 #include "gfxFont.h"
12 #include "gfxFT2FontBase.h"
13 #include "gfxContext.h"
14 #include "gfxFontUtils.h"
15 #include "gfxUserFontSet.h"
17 class FT2FontEntry;
19 class gfxFT2Font final : public gfxFT2FontBase {
20 public: // new functions
21 gfxFT2Font(const RefPtr<mozilla::gfx::UnscaledFontFreeType>& aUnscaledFont,
22 RefPtr<mozilla::gfx::SharedFTFace>&& aFTFace,
23 FT2FontEntry* aFontEntry, const gfxFontStyle* aFontStyle,
24 int aLoadFlags);
26 FT2FontEntry* GetFontEntry();
28 already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
29 const TextRunDrawParams& aRunParams) override;
31 bool ShouldHintMetrics() const override;
33 void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
34 FontCacheSizes* aSizes) const override;
35 void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
36 FontCacheSizes* aSizes) const override;
38 protected:
39 ~gfxFT2Font() override;
41 struct CachedGlyphData {
42 CachedGlyphData() : glyphIndex(0xffffffffU) {}
44 explicit CachedGlyphData(uint32_t gid) : glyphIndex(gid) {}
46 uint32_t glyphIndex;
47 int32_t lsbDelta;
48 int32_t rsbDelta;
49 int32_t xAdvance;
52 const CachedGlyphData* GetGlyphDataForChar(FT_Face aFace, uint32_t ch) {
53 CharGlyphMapEntryType* entry = mCharGlyphCache.PutEntry(ch);
55 if (!entry) return nullptr;
57 if (entry->GetData().glyphIndex == 0xffffffffU) {
58 // this is a new entry, fill it
59 FillGlyphDataForChar(aFace, ch, entry->GetModifiableData());
62 return &entry->GetData();
65 bool ShapeText(DrawTarget* aDrawTarget, const char16_t* aText,
66 uint32_t aOffset, uint32_t aLength, Script aScript,
67 nsAtom* aLanguage, bool aVertical, RoundingFlags aRounding,
68 gfxShapedText* aShapedText) override;
70 void FillGlyphDataForChar(FT_Face face, uint32_t ch, CachedGlyphData* gd);
72 void AddRange(const char16_t* aText, uint32_t aOffset, uint32_t aLength,
73 gfxShapedText* aShapedText);
75 typedef nsBaseHashtableET<nsUint32HashKey, CachedGlyphData>
76 CharGlyphMapEntryType;
77 typedef nsTHashtable<CharGlyphMapEntryType> CharGlyphMap;
78 CharGlyphMap mCharGlyphCache;
81 #endif /* GFX_FT2FONTS_H */