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/gfx/2D.h"
10 #include "mozilla/UniquePtr.h"
13 #include "nsTHashtable.h"
27 class FontPaletteValueSet
{
29 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FontPaletteValueSet
)
31 struct OverrideColor
{
36 struct PaletteValues
{
37 enum { kLight
= -1, kDark
= -2 };
38 int32_t mBasePalette
= 0; // 0-based index, or kLight/kDark constants
39 nsTArray
<OverrideColor
> mOverrides
;
42 const PaletteValues
* Lookup(nsAtom
* aName
, const nsACString
& aFamily
) const;
44 PaletteValues
* Insert(nsAtom
* aName
, const nsACString
& aFamily
);
47 ~FontPaletteValueSet() = default;
49 struct PaletteHashKey
{
53 PaletteHashKey() = delete;
54 PaletteHashKey(nsAtom
* aName
, const nsACString
& aFamily
)
55 : mName(aName
), mFamily(aFamily
) {}
56 PaletteHashKey(const PaletteHashKey
& aKey
) = default;
59 class HashEntry
: public PLDHashEntryHdr
{
61 using KeyType
= const PaletteHashKey
&;
62 using KeyTypePointer
= const PaletteHashKey
*;
65 explicit HashEntry(KeyTypePointer aKey
) : mKey(*aKey
) {}
66 HashEntry(HashEntry
&& other
) noexcept
67 : PLDHashEntryHdr(std::move(other
)),
69 mValue(std::move(other
.mValue
)) {
70 NS_ERROR("Should not be called");
72 ~HashEntry() = default;
74 bool KeyEquals(const KeyTypePointer aKey
) const {
75 return mKey
.mName
== aKey
->mName
&& mKey
.mFamily
.Equals(aKey
->mFamily
);
77 static KeyTypePointer
KeyToPointer(KeyType aKey
) { return &aKey
; }
78 static PLDHashNumber
HashKey(const KeyTypePointer aKey
) {
79 return aKey
->mName
->hash() +
80 HashString(aKey
->mFamily
.get(), aKey
->mFamily
.Length());
82 enum { ALLOW_MEMMOVE
= true };
88 nsTHashtable
<HashEntry
> mValues
;
93 static bool ValidateColorGlyphs(hb_blob_t
* aCOLR
, hb_blob_t
* aCPAL
);
95 // COLRv0: color glyph is represented as a simple list of colored layers.
96 // (This is used only as an opaque pointer; the internal type is private.)
99 static const GlyphLayers
* GetGlyphLayers(hb_blob_t
* aCOLR
, uint32_t aGlyphId
);
101 static bool PaintGlyphLayers(
102 hb_blob_t
* aCOLR
, hb_face_t
* aFace
, const GlyphLayers
* aLayers
,
103 DrawTarget
* aDrawTarget
, layout::TextDrawTarget
* aTextDrawer
,
104 ScaledFont
* aScaledFont
, DrawOptions aDrawOptions
, const Point
& aPoint
,
105 const sRGBColor
& aCurrentColor
, const nsTArray
<sRGBColor
>* aColors
);
107 // COLRv1 support: color glyph is represented by a directed acyclic graph of
109 // (This is used only as an opaque pointer; the internal type is private.)
110 struct GlyphPaintGraph
;
112 static const GlyphPaintGraph
* GetGlyphPaintGraph(hb_blob_t
* aCOLR
,
115 static bool PaintGlyphGraph(
116 hb_blob_t
* aCOLR
, hb_font_t
* aFont
, const GlyphPaintGraph
* aPaintGraph
,
117 DrawTarget
* aDrawTarget
, layout::TextDrawTarget
* aTextDrawer
,
118 ScaledFont
* aScaledFont
, DrawOptions aDrawOptions
, const Point
& aPoint
,
119 const sRGBColor
& aCurrentColor
, const nsTArray
<sRGBColor
>* aColors
,
120 uint32_t aGlyphId
, float aFontUnitsToPixels
);
122 static Rect
GetColorGlyphBounds(hb_blob_t
* aCOLR
, hb_font_t
* aFont
,
123 uint32_t aGlyphId
, DrawTarget
* aDrawTarget
,
124 ScaledFont
* aScaledFont
,
125 float aFontUnitsToPixels
);
127 static uint16_t GetColrTableVersion(hb_blob_t
* aCOLR
);
129 static UniquePtr
<nsTArray
<sRGBColor
>> SetupColorPalette(
130 hb_face_t
* aFace
, const FontPaletteValueSet
* aPaletteValueSet
,
131 nsAtom
* aFontPalette
, const nsACString
& aFamilyName
);
136 } // namespace mozilla
138 #endif // COLR_FONTS_H