Performance enhancements for stroke font initialisation.

This commit is contained in:
Jeff Young 2020-03-07 18:51:42 +00:00
parent 1e4ae5d526
commit fb00ca12d6
2 changed files with 13 additions and 13 deletions

View File

@ -69,7 +69,7 @@ bool STROKE_FONT::LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNe
for( int j = 0; j < aNewStrokeFontSize; j++ ) for( int j = 0; j < aNewStrokeFontSize; j++ )
{ {
GLYPH glyph; GLYPH* glyph = new GLYPH;
double glyphStartX = 0.0; double glyphStartX = 0.0;
double glyphEndX = 0.0; double glyphEndX = 0.0;
double glyphWidth = 0.0; double glyphWidth = 0.0;
@ -88,7 +88,7 @@ bool STROKE_FONT::LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNe
i += 2; i += 2;
} }
glyph.reserve( strokes + 1 ); glyph->reserve( strokes + 1 );
i = 0; i = 0;
@ -134,8 +134,8 @@ bool STROKE_FONT::LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNe
if( !pointList ) if( !pointList )
{ {
glyph.emplace_back(); pointList = new std::vector<VECTOR2D>;
pointList = &glyph.back(); glyph->push_back( pointList );
} }
pointList->push_back( point ); pointList->push_back( point );
@ -167,14 +167,14 @@ double STROKE_FONT::GetInterline( double aGlyphHeight )
} }
BOX2D STROKE_FONT::computeBoundingBox( const GLYPH& aGLYPH, double aGlyphWidth ) const BOX2D STROKE_FONT::computeBoundingBox( const GLYPH* aGLYPH, double aGlyphWidth ) const
{ {
VECTOR2D min( 0, 0 ); VECTOR2D min( 0, 0 );
VECTOR2D max( aGlyphWidth, 0 ); VECTOR2D max( aGlyphWidth, 0 );
for( const std::vector<VECTOR2D>& pointList : aGLYPH ) for( const std::vector<VECTOR2D>* pointList : *aGLYPH )
{ {
for( const VECTOR2D& point : pointList ) for( const VECTOR2D& point : *pointList )
{ {
min.y = std::min( min.y, point.y ); min.y = std::min( min.y, point.y );
max.y = std::max( max.y, point.y ); max.y = std::max( max.y, point.y );
@ -427,7 +427,7 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags )
dd = substitute - ' '; dd = substitute - ' ';
} }
const GLYPH& glyph = m_glyphs->at( dd ); const GLYPH* glyph = m_glyphs->at( dd );
const BOX2D& bbox = m_glyphBoundingBoxes->at( dd ); const BOX2D& bbox = m_glyphBoundingBoxes->at( dd );
if( in_overbar ) if( in_overbar )
@ -455,11 +455,11 @@ void STROKE_FONT::drawSingleLineText( const UTF8& aText, int markupFlags )
last_had_overbar = false; last_had_overbar = false;
} }
for( const std::vector<VECTOR2D>& ptList : glyph ) for( const std::vector<VECTOR2D>* ptList : *glyph )
{ {
std::deque<VECTOR2D> ptListScaled; std::deque<VECTOR2D> ptListScaled;
for( const VECTOR2D& pt : ptList ) for( const VECTOR2D& pt : *ptList )
{ {
VECTOR2D scaledPt( pt.x * glyphSize.x + xOffset, pt.y * glyphSize.y + yOffset ); VECTOR2D scaledPt( pt.x * glyphSize.x + xOffset, pt.y * glyphSize.y + yOffset );

View File

@ -42,8 +42,8 @@ namespace KIGFX
{ {
class GAL; class GAL;
typedef std::vector<std::vector<VECTOR2D>> GLYPH; typedef std::vector<std::vector<VECTOR2D>*> GLYPH;
typedef std::vector<GLYPH> GLYPH_LIST; typedef std::vector<GLYPH*> GLYPH_LIST;
/** /**
* @brief Class STROKE_FONT implements stroke font drawing. * @brief Class STROKE_FONT implements stroke font drawing.
@ -148,7 +148,7 @@ private:
* @param aGlyphWidth is the x-component of the bounding box size. * @param aGlyphWidth is the x-component of the bounding box size.
* @return is the complete bounding box size. * @return is the complete bounding box size.
*/ */
BOX2D computeBoundingBox( const GLYPH& aGlyph, double aGlyphWidth ) const; BOX2D computeBoundingBox( const GLYPH* aGlyph, double aGlyphWidth ) const;
/** /**
* @brief Draws a single line of text. Multiline texts should be split before using the * @brief Draws a single line of text. Multiline texts should be split before using the