- const LineRun& line = *it;
-
- // 1) Get the paragrap's direction.
- bool paragraphDirection = false;
-
- // Check if there is any right to left line.
- if( ( NULL != layoutParameters.lineBidirectionalInfoRunsBuffer ) &&
- ( bidiLineIndex < layoutParameters.numberOfBidirectionalInfoRuns ) )
- {
- const BidirectionalLineInfoRun* bidiLine = layoutParameters.lineBidirectionalInfoRunsBuffer + bidiLineIndex;
-
- // Get the right to left line that match with current line.
- while( ( line.characterRun.characterIndex > bidiLine->characterRun.characterIndex ) &&
- ( bidiLineIndex < layoutParameters.numberOfBidirectionalInfoRuns ) )
- {
- ++bidiLineIndex;
- bidiLine = layoutParameters.lineBidirectionalInfoRunsBuffer + bidiLineIndex;
- }
-
- if( line.characterRun.characterIndex == bidiLine->characterRun.characterIndex )
- {
- paragraphDirection = bidiLine->direction;
- }
- }
-
- // 2) Calculate the alignment offset accordingly with the align option,
- // the box width, line length, and the paragraphs direction.
- float alignOffset = CalculateHorizontalAlignment( layoutSize.width,
- line.width,
- line.extraLength,
- paragraphDirection );
-
- // 3) Traverse all glyphs and update the 'x' position.
- for( GlyphIndex index = line.glyphIndex,
- endIndex = line.glyphIndex + line.numberOfGlyphs;
- index < endIndex;
- ++index )
- {
- Vector2& position = *( glyphPositionsBuffer + index );
-
- position.x += alignOffset;
- }
- }
- }
-
- 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;