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/. */
9 #include "mozilla/MemoryReporting.h"
12 #include "gfxFT2FontBase.h"
13 #include "gfxContext.h"
14 #include "gfxFontUtils.h"
15 #include "gfxUserFontSet.h"
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
,
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
;
39 ~gfxFT2Font() override
;
41 struct CachedGlyphData
{
42 CachedGlyphData() : glyphIndex(0xffffffffU
) {}
44 explicit CachedGlyphData(uint32_t gid
) : glyphIndex(gid
) {}
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 */