- bool SingleLineLayout( const LayoutParameters& layoutParameters,
- Vector<Vector2>& glyphPositions,
- Vector<LineRun>& lines,
- Size& actualSize )
- {
- LineLayout layout;
- layout.glyphIndex = 0u;
- GetLineLayoutForBox( layoutParameters,
- layout );
-
- // Create a line run and add it to the lines.
- const GlyphIndex lastGlyphIndex = layoutParameters.totalNumberOfGlyphs - 1u;
-
- LineRun lineRun;
- lineRun.glyphIndex = 0u;
- lineRun.numberOfGlyphs = layoutParameters.totalNumberOfGlyphs;
- lineRun.characterRun.characterIndex = 0u;
- lineRun.characterRun.numberOfCharacters = *( layoutParameters.glyphsToCharactersBuffer + lastGlyphIndex ) + *( layoutParameters.charactersPerGlyphBuffer + lastGlyphIndex );
- lineRun.width = layout.length;
- lineRun.ascender = layout.ascender;
- lineRun.descender = layout.descender;
- lineRun.extraLength = layout.wsLengthEndOfLine;
- lineRun.direction = false;
-
- lines.PushBack( lineRun );
-
- // Update the actual size.
- actualSize.width = layout.length;
- actualSize.height = lineRun.ascender + -lineRun.descender;
-
- float penX = 0.f;
- float penY = layout.ascender;
-
- Vector2* glyphPositionsBuffer = glyphPositions.Begin();
- for( GlyphIndex glyphIndex = 0u; glyphIndex < layout.numberOfGlyphs; ++glyphIndex )
- {
- const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + glyphIndex );
- Vector2& position = *( glyphPositionsBuffer + glyphIndex );
-
- position.x = penX + glyph.xBearing;
- position.y = penY - glyph.yBearing;
-
- penX += glyph.advance;
- }
-
- return true;
- }
-
- bool MultiLineLayout( const LayoutParameters& layoutParameters,
- Vector<Vector2>& glyphPositions,
- Vector<LineRun>& lines,
- Size& actualSize )
- {
- float penY = 0.f;
- for( GlyphIndex index = 0u; index < layoutParameters.totalNumberOfGlyphs; )
- {
- float penX = 0.f;
-
- // Get the layout for the line.
- LineLayout layout;
- layout.glyphIndex = index;
- GetMultiLineLayoutForBox( layoutParameters,
- layout );
-
- if( 0u == layout.numberOfGlyphs )
- {
- // The width is too small and no characters are laid-out.
- return false;
- }
-
- // Create a line run and add it to the lines.
- const GlyphIndex lastGlyphIndex = index + layout.numberOfGlyphs - 1u;
-
- LineRun lineRun;
- lineRun.glyphIndex = index;
- lineRun.numberOfGlyphs = layout.numberOfGlyphs;
- lineRun.characterRun.characterIndex = *( layoutParameters.glyphsToCharactersBuffer + index );
- lineRun.characterRun.numberOfCharacters = ( *( layoutParameters.glyphsToCharactersBuffer + lastGlyphIndex ) + *( layoutParameters.charactersPerGlyphBuffer + lastGlyphIndex ) ) - lineRun.characterRun.characterIndex;
- lineRun.width = layout.length + ( ( layout.widthAdvanceDiff > 0.f ) ? layout.widthAdvanceDiff : 0.f );
- lineRun.ascender = layout.ascender;
- lineRun.descender = layout.descender;
- lineRun.extraLength = layout.wsLengthEndOfLine;
- lineRun.direction = false;
-
- lines.PushBack( lineRun );
-
- // Update the actual size.
- if( layout.length + layout.widthAdvanceDiff > actualSize.width )
- {
- actualSize.width = layout.length;
- }
-
- actualSize.height += ( lineRun.ascender + -lineRun.descender );
-
- // Traverse the glyphs and set the positions.
-
- penY += layout.ascender;
-
- Vector2* glyphPositionsBuffer = glyphPositions.Begin();
- for( GlyphIndex i = index; i < index + layout.numberOfGlyphs; ++i )
- {
- const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + i );
- Vector2& position = *( glyphPositionsBuffer + i );
-
- position.x = penX + glyph.xBearing;
- position.y = penY - glyph.yBearing;
-
- penX += glyph.advance;
- }
-
- penY += -layout.descender;
-
- // Increase the glyph index.
- index += layout.numberOfGlyphs;
- }
-
- return true;
- }
-