Krita Source Code Documentation
Loading...
Searching...
No Matches
ColorLayersLoader Class Reference

Helper class to load CPAL/COLR v0 color layers, functionally based off the sample code in the freetype docs. More...

Public Member Functions

 ColorLayersLoader (FT_Face face, FT_UInt baseGlyph)
 Construct a ColorLayersLoader object. The first color layer is selected if there are any.
 
std::tuple< QPainterPath, QBrush, bool > layer (const CharacterResult &charResult, const FT_Int32 faceLoadFlags, int *x_advance, int *y_advance)
 Load the current glyph layer.
 
bool moveNext ()
 Move to the next glyph layer.
 
 operator bool () const
 Check whether there are color layers to be loaded.
 

Private Attributes

FT_UInt m_baseGlyph
 
FT_Face m_face
 
bool m_haveLayers
 
FT_LayerIterator m_iterator {}
 
FT_UInt m_layerColorIndex {}
 
FT_UInt m_layerGlyphIndex {}
 
FT_Color * m_palette {}
 

Detailed Description

Helper class to load CPAL/COLR v0 color layers, functionally based off the sample code in the freetype docs.

Definition at line 179 of file KoSvgTextShape_p_glyphs.cpp.

Constructor & Destructor Documentation

◆ ColorLayersLoader()

ColorLayersLoader::ColorLayersLoader ( FT_Face face,
FT_UInt baseGlyph )
inline

Construct a ColorLayersLoader object. The first color layer is selected if there are any.

Parameters
face
baseGlyph

Definition at line 189 of file KoSvgTextShape_p_glyphs.cpp.

190 : m_face(face)
191 , m_baseGlyph(baseGlyph)
192 {
193 const unsigned short paletteIndex = 0;
194 if (FT_Palette_Select(m_face, paletteIndex, &m_palette) != 0) {
195 m_palette = nullptr;
196 }
198 }
bool moveNext()
Move to the next glyph layer.

References m_face, m_haveLayers, m_palette, and moveNext().

Member Function Documentation

◆ layer()

std::tuple< QPainterPath, QBrush, bool > ColorLayersLoader::layer ( const CharacterResult & charResult,
const FT_Int32 faceLoadFlags,
int * x_advance,
int * y_advance )
inline

Load the current glyph layer.

Parameters
charResult
faceLoadFlags
x_advancePointer to the X advance to be adjusted if needed.
y_advancePointer to the Y advance to be adjusted if needed.
Returns
std::tuple<QPainterPath, QBrush, bool> {glyphOutline, layerColor, isForeGroundColor}

Definition at line 218 of file KoSvgTextShape_p_glyphs.cpp.

219 {
220 QBrush layerColor;
221 bool isForeGroundColor = false;
222
223 if (m_layerColorIndex == 0xFFFF) {
224 layerColor = Qt::black;
225 isForeGroundColor = true;
226 } else {
227 const FT_Color color = m_palette[m_layerColorIndex];
228 layerColor = QColor(color.red, color.green, color.blue, color.alpha);
229 }
230 if (const FT_Error err = FT_Load_Glyph(m_face, m_layerGlyphIndex, faceLoadFlags)) {
231 warnFlake << "Failed to load glyph, freetype error" << err;
232 return {};
233 }
234 if (m_face->glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
235 // Check whether we need to synthesize bold by emboldening the glyph:
236 emboldenGlyphIfNeeded(m_face, charResult, x_advance, y_advance);
237
238 const QPainterPath p = convertFromFreeTypeOutline(m_face->glyph);
239 return {p, layerColor, isForeGroundColor};
240 } else {
241 warnFlake << "Unsupported glyph format" << glyphFormatToStr(m_face->glyph->format) << "in glyph layers";
242 return {};
243 }
244 }
#define warnFlake
Definition FlakeDebug.h:16
const Params2D p
static QPainterPath convertFromFreeTypeOutline(FT_GlyphSlotRec *glyphSlot)
static void emboldenGlyphIfNeeded(const FT_Face ftface, const CharacterResult &charResult, int *x_advance, int *y_advance)
Embolden a glyph (synthesize bold) if the font does not have native bold.
static QString glyphFormatToStr(const FT_Glyph_Format _v)

References convertFromFreeTypeOutline(), emboldenGlyphIfNeeded(), glyphFormatToStr(), m_face, m_layerColorIndex, m_layerGlyphIndex, m_palette, p, and warnFlake.

◆ moveNext()

bool ColorLayersLoader::moveNext ( )
inline

Move to the next glyph layer.

Returns
true if there are more layers.
false if there are no more layers.

Definition at line 252 of file KoSvgTextShape_p_glyphs.cpp.

253 {
255 FT_Get_Color_Glyph_Layer(m_face, m_baseGlyph, &m_layerGlyphIndex, &m_layerColorIndex, &m_iterator);
256 return m_haveLayers;
257 }

References m_baseGlyph, m_face, m_haveLayers, m_iterator, m_layerColorIndex, and m_layerGlyphIndex.

◆ operator bool()

ColorLayersLoader::operator bool ( ) const
inline

Check whether there are color layers to be loaded.

Definition at line 203 of file KoSvgTextShape_p_glyphs.cpp.

204 {
205 return m_haveLayers && m_palette;
206 }

References m_haveLayers, and m_palette.

Member Data Documentation

◆ m_baseGlyph

FT_UInt ColorLayersLoader::m_baseGlyph
private

Definition at line 265 of file KoSvgTextShape_p_glyphs.cpp.

◆ m_face

FT_Face ColorLayersLoader::m_face
private

Definition at line 264 of file KoSvgTextShape_p_glyphs.cpp.

◆ m_haveLayers

bool ColorLayersLoader::m_haveLayers
private

Definition at line 266 of file KoSvgTextShape_p_glyphs.cpp.

◆ m_iterator

FT_LayerIterator ColorLayersLoader::m_iterator {}
private

Definition at line 262 of file KoSvgTextShape_p_glyphs.cpp.

262{};

◆ m_layerColorIndex

FT_UInt ColorLayersLoader::m_layerColorIndex {}
private

Definition at line 261 of file KoSvgTextShape_p_glyphs.cpp.

261{};

◆ m_layerGlyphIndex

FT_UInt ColorLayersLoader::m_layerGlyphIndex {}
private

Definition at line 260 of file KoSvgTextShape_p_glyphs.cpp.

260{};

◆ m_palette

FT_Color* ColorLayersLoader::m_palette {}
private

Definition at line 263 of file KoSvgTextShape_p_glyphs.cpp.

263{};

The documentation for this class was generated from the following file: