Generate tofu if we fail to decompose outline font glyph.

This commit is contained in:
Jeff Young 2024-02-05 15:33:03 +00:00
parent a28f092b67
commit de634c6f3e
3 changed files with 35 additions and 6 deletions

View File

@ -122,7 +122,7 @@ int OUTLINE_DECOMPOSER::cubicTo( const FT_Vector* aFirstControlPoint,
} }
void OUTLINE_DECOMPOSER::OutlineToSegments( std::vector<CONTOUR>* aContours ) bool OUTLINE_DECOMPOSER::OutlineToSegments( std::vector<CONTOUR>* aContours )
{ {
m_contours = aContours; m_contours = aContours;
@ -138,12 +138,12 @@ void OUTLINE_DECOMPOSER::OutlineToSegments( std::vector<CONTOUR>* aContours )
FT_Error e = FT_Outline_Decompose( &m_outline, &callbacks, this ); FT_Error e = FT_Outline_Decompose( &m_outline, &callbacks, this );
if( e ) if( e )
{ return false;
// TODO: handle error != 0
}
for( CONTOUR& c : *m_contours ) for( CONTOUR& c : *m_contours )
c.m_Winding = winding( c.m_Points ); c.m_Winding = winding( c.m_Points );
return true;
} }

View File

@ -328,7 +328,36 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphsUnlocked( BOX2I* aBBox,
std::vector<CONTOUR> contours; std::vector<CONTOUR> contours;
OUTLINE_DECOMPOSER decomposer( face->glyph->outline ); OUTLINE_DECOMPOSER decomposer( face->glyph->outline );
decomposer.OutlineToSegments( &contours );
if( !decomposer.OutlineToSegments( &contours ) )
{
double hb_advance = glyphPos[i].x_advance * GLYPH_SIZE_SCALER;
BOX2D tofuBox( { scaler * 0.03, 0.0 },
{ hb_advance - scaler * 0.02, scaler * 0.72 } );
contours.clear();
CONTOUR outline;
outline.m_Winding = 1;
outline.m_Orientation = FT_ORIENTATION_TRUETYPE;
outline.m_Points.push_back( tofuBox.GetPosition() );
outline.m_Points.push_back( { tofuBox.GetSize().x, tofuBox.GetPosition().y } );
outline.m_Points.push_back( tofuBox.GetSize() );
outline.m_Points.push_back( { tofuBox.GetPosition().x, tofuBox.GetSize().y } );
contours.push_back( outline );
CONTOUR hole;
tofuBox.Move( { scaler * 0.06, scaler * 0.06 } );
tofuBox.SetSize( { tofuBox.GetWidth() - scaler * 0.06,
tofuBox.GetHeight() - scaler * 0.06 } );
hole.m_Winding = 1;
hole.m_Orientation = FT_ORIENTATION_NONE;
hole.m_Points.push_back( tofuBox.GetPosition() );
hole.m_Points.push_back( { tofuBox.GetSize().x, tofuBox.GetPosition().y } );
hole.m_Points.push_back( tofuBox.GetSize() );
hole.m_Points.push_back( { tofuBox.GetPosition().x, tofuBox.GetSize().y } );
contours.push_back( hole );
}
std::unique_ptr<OUTLINE_GLYPH> glyph = std::make_unique<OUTLINE_GLYPH>(); std::unique_ptr<OUTLINE_GLYPH> glyph = std::make_unique<OUTLINE_GLYPH>();
std::vector<SHAPE_LINE_CHAIN> holes; std::vector<SHAPE_LINE_CHAIN> holes;

View File

@ -54,7 +54,7 @@ class OUTLINE_DECOMPOSER
public: public:
OUTLINE_DECOMPOSER( FT_Outline& aOutline ); OUTLINE_DECOMPOSER( FT_Outline& aOutline );
void OutlineToSegments( std::vector<CONTOUR>* aContours ); bool OutlineToSegments( std::vector<CONTOUR>* aContours );
private: private:
void newContour(); void newContour();