2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/devel-api/text-abstraction/font-client.h>
25 #include <dali/integration-api/debug.h>
28 #include <dali-toolkit/internal/text/layouts/layout-parameters.h>
29 #include <dali-toolkit/internal/text/bidirectional-line-info-run.h>
43 #if defined(DEBUG_ENABLED)
44 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_LAYOUT");
47 const float MAX_FLOAT = std::numeric_limits<float>::max();
48 const bool RTL = true;
53 * @brief Stores temporary layout info of the line.
61 numberOfCharacters( 0u ),
65 wsLengthEndOfLine( 0.f ),
67 descender( MAX_FLOAT )
78 numberOfCharacters = 0u;
82 wsLengthEndOfLine = 0.f;
84 descender = MAX_FLOAT;
87 GlyphIndex glyphIndex; ///< Index of the first glyph to be laid-out.
88 CharacterIndex characterIndex; ///< Index of the first character to be laid-out.
89 Length numberOfGlyphs; ///< The number of glyph which fit in one line.
90 Length numberOfCharacters; ///< The number of characters which fit in one line.
91 float length; ///< The addition of the advance metric of all the glyphs which fit in one line.
92 float extraBearing; ///< The extra width to be added to the line's length when the bearing of the first glyph is negative.
93 float extraWidth; ///< The extra width to be added to the line's length when the bearing + width of the last glyph is greater than the advance.
94 float wsLengthEndOfLine; ///< The length of the white spaces at the end of the line.
95 float ascender; ///< The maximum ascender of all fonts in the line.
96 float descender; ///< The minimum descender of all fonts in the line.
99 struct LayoutEngine::Impl
102 : mLayout( LayoutEngine::SINGLE_LINE_BOX ),
103 mHorizontalAlignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN ),
104 mVerticalAlignment( LayoutEngine::VERTICAL_ALIGN_TOP ),
105 mEllipsisEnabled( false )
107 mFontClient = TextAbstraction::FontClient::Get();
111 * @brief Updates the line ascender and descender with the metrics of a new font.
113 * @param[in] fontId The id of the new font.
114 * @param[in,out] lineLayout The line layout.
116 void UpdateLineHeight( FontId fontId, LineLayout& lineLayout )
118 Text::FontMetrics fontMetrics;
119 mFontClient.GetFontMetrics( fontId, fontMetrics );
121 // Sets the maximum ascender.
122 if( fontMetrics.ascender > lineLayout.ascender )
124 lineLayout.ascender = fontMetrics.ascender;
127 // Sets the minimum descender.
128 if( fontMetrics.descender < lineLayout.descender )
130 lineLayout.descender = fontMetrics.descender;
135 * @brief Merges a temporary line layout into the line layout.
137 * @param[in,out] lineLayout The line layout.
138 * @param[in] tmpLineLayout A temporary line layout.
140 void MergeLineLayout( LineLayout& lineLayout,
141 const LineLayout& tmpLineLayout )
143 lineLayout.numberOfCharacters += tmpLineLayout.numberOfCharacters;
144 lineLayout.numberOfGlyphs += tmpLineLayout.numberOfGlyphs;
145 lineLayout.length += tmpLineLayout.length;
147 if( 0.f < tmpLineLayout.length )
149 lineLayout.length += lineLayout.wsLengthEndOfLine;
151 lineLayout.wsLengthEndOfLine = tmpLineLayout.wsLengthEndOfLine;
155 lineLayout.wsLengthEndOfLine += tmpLineLayout.wsLengthEndOfLine;
158 if( tmpLineLayout.ascender > lineLayout.ascender )
160 lineLayout.ascender = tmpLineLayout.ascender;
163 if( tmpLineLayout.descender < lineLayout.descender )
165 lineLayout.descender = tmpLineLayout.descender;
170 * Retrieves the line layout for a given box width.
172 * @note This method lais out text as it were left to right. At this point is not possible to reorder the line
173 * because the number of characters of the line is not known (one of the responsabilities of this method
174 * is calculate that). Due to glyph's 'x' bearing, width and advance, when right to left or mixed right to left
175 * and left to right text is laid out, it can be small differences in the line length. One solution is to
176 * reorder and re-lay out the text after this method and add or remove one extra glyph if needed. However,
177 * this method calculates which are the first and last glyphs of the line (the ones that causes the
178 * differences). This is a good point to check if there is problems with the text exceeding the boundaries
179 * of the control when there is right to left text.
181 * @param[in] parameters The layout parameters.
182 * @param[out] lineLayout The line layout.
183 * @param[in,out] paragraphDirection in: the current paragraph's direction, out: the next paragraph's direction. Is set after a must break.
184 * @param[in] completelyFill Whether to completely fill the line ( even if the last word exceeds the boundaries ).
186 void GetLineLayoutForBox( const LayoutParameters& parameters,
187 LineLayout& lineLayout,
188 CharacterDirection& paragraphDirection,
189 bool completelyFill )
191 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->GetLineLayoutForBox\n" );
192 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " initial glyph index : %d\n", lineLayout.glyphIndex );
193 // Stores temporary line layout which has not been added to the final line layout.
194 LineLayout tmpLineLayout;
196 const bool isMultiline = mLayout == MULTI_LINE_BOX;
197 const GlyphIndex lastGlyphIndex = parameters.totalNumberOfGlyphs - 1u;
199 // If the first glyph has a negative bearing its absolute value needs to be added to the line length.
200 // In the case the line starts with a right to left character, if the width is longer than the advance,
201 // the difference needs to be added to the line length.
202 const GlyphInfo& glyphInfo = *( parameters.glyphsBuffer + lineLayout.glyphIndex );
204 // Set the direction of the first character of the line.
205 lineLayout.characterIndex = *( parameters.glyphsToCharactersBuffer + lineLayout.glyphIndex );
206 const CharacterDirection firstCharacterDirection = ( NULL == parameters.characterDirectionBuffer ) ? false : *( parameters.characterDirectionBuffer + lineLayout.characterIndex );
207 CharacterDirection previousCharacterDirection = firstCharacterDirection;
209 const float extraWidth = glyphInfo.xBearing + glyphInfo.width - glyphInfo.advance;
210 float tmpExtraWidth = ( 0.f < extraWidth ) ? extraWidth : 0.f;
212 float tmpExtraBearing = ( 0.f > glyphInfo.xBearing ) ? -glyphInfo.xBearing : 0.f;
214 tmpLineLayout.length += 1.f; // Added one unit to give some space to the cursor.
216 // Calculate the line height if there is no characters.
217 FontId lastFontId = glyphInfo.fontId;
218 UpdateLineHeight( lastFontId, tmpLineLayout );
220 bool oneWordLaidOut = false;
222 for( GlyphIndex glyphIndex = lineLayout.glyphIndex;
223 glyphIndex < parameters.totalNumberOfGlyphs;
226 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " glyph index : %d\n", glyphIndex );
227 const bool isLastGlyph = glyphIndex == lastGlyphIndex;
229 // Get the glyph info.
230 const GlyphInfo& glyphInfo = *( parameters.glyphsBuffer + glyphIndex );
232 // Get the character indices for the current glyph. The last character index is needed
233 // because there are glyphs formed by more than one character but their break info is
234 // given only for the last character.
235 const Length charactersPerGlyph = *( parameters.charactersPerGlyphBuffer + glyphIndex );
236 const CharacterIndex characterFirstIndex = *( parameters.glyphsToCharactersBuffer + glyphIndex );
237 const CharacterIndex characterLastIndex = characterFirstIndex + ( ( 1u > charactersPerGlyph ) ? 0u : charactersPerGlyph - 1u );
239 // Get the line break info for the current character.
240 const LineBreakInfo lineBreakInfo = *( parameters.lineBreakInfoBuffer + characterLastIndex );
242 // Get the word break info for the current character.
243 const WordBreakInfo wordBreakInfo = *( parameters.wordBreakInfoBuffer + characterLastIndex );
245 // Increase the number of characters.
246 tmpLineLayout.numberOfCharacters += charactersPerGlyph;
248 // Increase the number of glyphs.
249 tmpLineLayout.numberOfGlyphs++;
251 // Check whether is a white space.
252 const Character character = *( parameters.textBuffer + characterFirstIndex );
253 const bool isWhiteSpace = TextAbstraction::IsWhiteSpace( character );
255 // Used to restore the temporal line layout when a single word does not fit in the control's width and is split by character.
256 const float previousTmpLineLength = tmpLineLayout.length;
257 const float previousTmpExtraBearing = tmpExtraBearing;
258 const float previousTmpExtraWidth = tmpExtraWidth;
260 // Get the character's direction.
261 const CharacterDirection characterDirection = ( NULL == parameters.characterDirectionBuffer ) ? false : *( parameters.characterDirectionBuffer + characterFirstIndex );
263 // Increase the accumulated length.
266 // Add the length to the length of white spaces at the end of the line.
267 tmpLineLayout.wsLengthEndOfLine += glyphInfo.advance; // The advance is used as the width is always zero for the white spaces.
271 // Add as well any previous white space length.
272 tmpLineLayout.length += tmpLineLayout.wsLengthEndOfLine + glyphInfo.advance;
274 // An extra space may be added to the line for the first and last glyph of the line.
275 // If the bearing of the first glyph is negative, its positive value needs to be added.
276 // If the bearing plus the width of the last glyph is greater than the advance, the difference
277 // needs to be added.
279 if( characterDirection == paragraphDirection )
281 if( RTL == characterDirection )
292 tmpExtraBearing = ( 0.f > glyphInfo.xBearing ) ? -glyphInfo.xBearing : 0.f;
305 const float extraWidth = glyphInfo.xBearing + glyphInfo.width - glyphInfo.advance;
306 tmpExtraWidth = ( 0.f < extraWidth ) ? extraWidth : 0.f;
311 if( characterDirection != previousCharacterDirection )
313 if( RTL == characterDirection )
318 const float extraWidth = glyphInfo.xBearing + glyphInfo.width - glyphInfo.advance;
319 tmpExtraWidth = ( 0.f < extraWidth ) ? extraWidth : 0.f;
326 tmpExtraBearing = ( 0.f > glyphInfo.xBearing ) ? -glyphInfo.xBearing : 0.f;
329 else if( characterDirection == firstCharacterDirection )
331 if( RTL == characterDirection )
337 tmpExtraBearing = ( 0.f > glyphInfo.xBearing ) ? -glyphInfo.xBearing : 0.f;
345 const float extraWidth = glyphInfo.xBearing + glyphInfo.width - glyphInfo.advance;
346 tmpExtraWidth = ( 0.f < extraWidth ) ? extraWidth : 0.f;
351 // Clear the white space length at the end of the line.
352 tmpLineLayout.wsLengthEndOfLine = 0.f;
355 // Check if the accumulated length fits in the width of the box.
356 if( ( completelyFill || isMultiline ) && !isWhiteSpace &&
357 ( tmpExtraBearing + lineLayout.length + lineLayout.wsLengthEndOfLine + tmpLineLayout.length + tmpExtraWidth > parameters.boundingBox.width ) )
359 // Current word does not fit in the box's width.
360 if( !oneWordLaidOut || completelyFill )
362 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " Break the word by character\n" );
364 // The word's with doesn't fit in the control's with. It needs to be split by character.
365 if( tmpLineLayout.numberOfGlyphs > 0u )
367 tmpLineLayout.numberOfCharacters -= charactersPerGlyph;
368 --tmpLineLayout.numberOfGlyphs;
369 tmpLineLayout.length = previousTmpLineLength;
370 tmpExtraBearing = previousTmpExtraBearing;
371 tmpExtraWidth = previousTmpExtraWidth;
374 // Add part of the word to the line layout.
375 MergeLineLayout( lineLayout, tmpLineLayout );
379 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " Current word does not fit.\n" );
382 lineLayout.extraBearing = tmpExtraBearing;
383 lineLayout.extraWidth = tmpExtraWidth;
385 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--GetLineLayoutForBox.\n" );
390 if( ( isMultiline || isLastGlyph ) &&
391 ( TextAbstraction::LINE_MUST_BREAK == lineBreakInfo ) )
393 // Must break the line. Update the line layout and return.
394 MergeLineLayout( lineLayout, tmpLineLayout );
396 // Set the next paragraph's direction.
398 ( NULL != parameters.characterDirectionBuffer ) )
400 paragraphDirection = *( parameters.characterDirectionBuffer + 1u + characterLastIndex );
403 lineLayout.extraBearing = tmpExtraBearing;
404 lineLayout.extraWidth = tmpExtraWidth;
406 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " Must break\n" );
407 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--GetLineLayoutForBox\n" );
412 ( TextAbstraction::WORD_BREAK == wordBreakInfo ) )
414 oneWordLaidOut = true;
415 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " One word laid out\n" );
417 // Current glyph is the last one of the current word.
418 // Add the temporal layout to the current one.
419 MergeLineLayout( lineLayout, tmpLineLayout );
421 tmpLineLayout.Clear();
424 // Check if the font of the current glyph is the same of the previous one.
425 // If it's different the ascender and descender need to be updated.
426 if( lastFontId != glyphInfo.fontId )
428 UpdateLineHeight( glyphInfo.fontId, tmpLineLayout );
429 lastFontId = glyphInfo.fontId;
432 previousCharacterDirection = characterDirection;
435 lineLayout.extraBearing = tmpExtraBearing;
436 lineLayout.extraWidth = tmpExtraWidth;
438 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--GetLineLayoutForBox\n" );
441 void SetGlyphPositions( const GlyphInfo* const glyphsBuffer,
442 Length numberOfGlyphs,
444 Vector2* glyphPositionsBuffer )
446 // Traverse the glyphs and set the positions.
448 // Check if the x bearing of the first character is negative.
449 // If it has a negative x bearing, it will exceed the boundaries of the actor,
450 // so the penX position needs to be moved to the right.
452 const GlyphInfo& glyph = *glyphsBuffer;
453 float penX = ( 0.f > glyph.xBearing ) ? -glyph.xBearing : 0.f;
454 penX += 1.f; // Added one unit to give some space to the cursor.
456 for( GlyphIndex i = 0u; i < numberOfGlyphs; ++i )
458 const GlyphInfo& glyph = *( glyphsBuffer + i );
459 Vector2& position = *( glyphPositionsBuffer + i );
461 position.x = penX + glyph.xBearing;
462 position.y = penY - glyph.yBearing;
464 penX += glyph.advance;
468 bool LayoutText( const LayoutParameters& layoutParameters,
469 Vector<Vector2>& glyphPositions,
470 Vector<LineRun>& lines,
473 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->LayoutText\n" );
474 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " box size %f, %f\n", layoutParameters.boundingBox.width, layoutParameters.boundingBox.height );
476 // Set the first paragraph's direction.
477 CharacterDirection paragraphDirection = ( NULL != layoutParameters.characterDirectionBuffer ) ? *layoutParameters.characterDirectionBuffer : !RTL;
480 for( GlyphIndex index = 0u; index < layoutParameters.totalNumberOfGlyphs; )
482 CharacterDirection currentParagraphDirection = paragraphDirection;
484 // Get the layout for the line.
486 layout.glyphIndex = index;
487 GetLineLayoutForBox( layoutParameters,
492 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " glyph index %d\n", layout.glyphIndex );
493 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " character index %d\n", layout.characterIndex );
494 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of glyphs %d\n", layout.numberOfGlyphs );
495 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " number of characters %d\n", layout.numberOfCharacters );
496 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " length %f\n", layout.length );
498 if( 0u == layout.numberOfGlyphs )
500 // The width is too small and no characters are laid-out.
501 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--LayoutText width too small!\n\n" );
505 // Set the line position. Discard if ellipsis is enabled and the position exceeds the boundaries
507 penY += layout.ascender;
509 DALI_LOG_INFO( gLogFilter, Debug::Verbose, " pen y %f\n", penY );
510 if( mEllipsisEnabled &&
511 ( ( penY - layout.descender > layoutParameters.boundingBox.height ) ||
512 ( ( mLayout == SINGLE_LINE_BOX ) &&
513 ( layout.extraBearing + layout.length + layout.extraWidth > layoutParameters.boundingBox.width ) ) ) )
515 // Do not layout more lines if ellipsis is enabled.
517 // The last line needs to be completely filled with characters.
518 // Part of a word may be used.
520 const Length numberOfLines = lines.Count();
523 LineLayout ellipsisLayout;
524 if( 0u != numberOfLines )
526 // Get the last line and layout it again with the 'completelyFill' flag to true.
527 lineRun = *( lines.Begin() + ( numberOfLines - 1u ) );
529 penY -= layout.ascender - lineRun.descender;
531 ellipsisLayout.glyphIndex = lineRun.glyphIndex;
535 lineRun.glyphIndex = 0u;
536 ellipsisLayout.glyphIndex = 0u;
539 GetLineLayoutForBox( layoutParameters,
541 currentParagraphDirection,
544 lineRun.numberOfGlyphs = ellipsisLayout.numberOfGlyphs;
545 lineRun.characterRun.characterIndex = ellipsisLayout.characterIndex;
546 lineRun.characterRun.numberOfCharacters = ellipsisLayout.numberOfCharacters;
547 lineRun.width = ellipsisLayout.length;
548 lineRun.extraLength = ( ellipsisLayout.wsLengthEndOfLine > 0.f ) ? ellipsisLayout.wsLengthEndOfLine - ellipsisLayout.extraWidth : 0.f;
549 lineRun.ascender = ellipsisLayout.ascender;
550 lineRun.descender = ellipsisLayout.descender;
551 lineRun.ellipsis = true;
553 actualSize.width = layoutParameters.boundingBox.width;
554 actualSize.height += ( lineRun.ascender + -lineRun.descender );
556 SetGlyphPositions( layoutParameters.glyphsBuffer + lineRun.glyphIndex,
557 ellipsisLayout.numberOfGlyphs,
559 glyphPositions.Begin() + lineRun.glyphIndex );
561 if( 0u != numberOfLines )
563 // Set the last line with the ellipsis layout.
564 *( lines.Begin() + ( numberOfLines - 1u ) ) = lineRun;
569 lines.PushBack( lineRun );
576 const bool isLastLine = index + layout.numberOfGlyphs == layoutParameters.totalNumberOfGlyphs;
579 lineRun.glyphIndex = index;
580 lineRun.numberOfGlyphs = layout.numberOfGlyphs;
581 lineRun.characterRun.characterIndex = layout.characterIndex;
582 lineRun.characterRun.numberOfCharacters = layout.numberOfCharacters;
585 const float width = layout.extraBearing + layout.length + layout.extraWidth + layout.wsLengthEndOfLine;
586 if( MULTI_LINE_BOX == mLayout )
588 lineRun.width = ( width > layoutParameters.boundingBox.width ) ? layoutParameters.boundingBox.width : width;
592 lineRun.width = width;
595 lineRun.extraLength = 0.f;
599 lineRun.width = layout.extraBearing + layout.length + layout.extraWidth;
600 lineRun.extraLength = ( layout.wsLengthEndOfLine > 0.f ) ? layout.wsLengthEndOfLine - layout.extraWidth : 0.f;
602 lineRun.ascender = layout.ascender;
603 lineRun.descender = layout.descender;
604 lineRun.direction = false;
605 lineRun.ellipsis = false;
607 lines.PushBack( lineRun );
609 // Update the actual size.
610 if( lineRun.width > actualSize.width )
612 actualSize.width = lineRun.width;
615 actualSize.height += ( lineRun.ascender + -lineRun.descender );
617 SetGlyphPositions( layoutParameters.glyphsBuffer + index,
618 layout.numberOfGlyphs,
620 glyphPositions.Begin() + index );
622 penY += -layout.descender;
624 // Increase the glyph index.
625 index += layout.numberOfGlyphs;
629 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--LayoutText\n\n" );
634 void ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
635 Vector<Vector2>& glyphPositions )
637 // Traverses the paragraphs with right to left characters.
638 for( LineIndex lineIndex = 0u; lineIndex < layoutParameters.numberOfBidirectionalInfoRuns; ++lineIndex )
640 const BidirectionalLineInfoRun& bidiLine = *( layoutParameters.lineBidirectionalInfoRunsBuffer + lineIndex );
642 const CharacterIndex characterVisualIndex = bidiLine.characterRun.characterIndex + *bidiLine.visualToLogicalMap;
643 const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) );
645 float penX = ( 0.f > glyph.xBearing ) ? -glyph.xBearing : 0.f;
646 penX += 1.f; // Added one unit to give some space to the cursor.
648 Vector2* glyphPositionsBuffer = glyphPositions.Begin();
650 // Traverses the characters of the right to left paragraph.
651 for( CharacterIndex characterLogicalIndex = 0u;
652 characterLogicalIndex < bidiLine.characterRun.numberOfCharacters;
653 ++characterLogicalIndex )
655 // Convert the character in the logical order into the character in the visual order.
656 const CharacterIndex characterVisualIndex = bidiLine.characterRun.characterIndex + *( bidiLine.visualToLogicalMap + characterLogicalIndex );
658 // Get the number of glyphs of the character.
659 const Length numberOfGlyphs = *( layoutParameters.glyphsPerCharacterBuffer + characterVisualIndex );
661 for( GlyphIndex index = 0u; index < numberOfGlyphs; ++index )
663 // Convert the character in the visual order into the glyph in the visual order.
664 const GlyphIndex glyphIndex = *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) + index;
666 DALI_ASSERT_DEBUG( 0u <= glyphIndex && glyphIndex < layoutParameters.totalNumberOfGlyphs );
668 const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + glyphIndex );
669 Vector2& position = *( glyphPositionsBuffer + glyphIndex );
671 position.x = penX + glyph.xBearing;
672 penX += glyph.advance;
678 void Align( const Size& layoutSize,
679 Vector<LineRun>& lines )
681 // Traverse all lines and align the glyphs.
683 for( Vector<LineRun>::Iterator it = lines.Begin(), endIt = lines.End();
688 const bool isLastLine = lines.End() == it + 1u;
690 // Calculate the alignment offset accordingly with the align option,
691 // the box width, line length, and the paragraphs direction.
692 CalculateHorizontalAlignment( layoutSize.width,
698 void CalculateHorizontalAlignment( float boxWidth,
702 line.alignmentOffset = 0.f;
703 const bool isRTL = RTL == line.direction;
704 float lineLength = line.width;
706 HorizontalAlignment alignment = mHorizontalAlignment;
708 ( HORIZONTAL_ALIGN_CENTER != alignment ) )
710 if( HORIZONTAL_ALIGN_BEGIN == alignment )
712 alignment = HORIZONTAL_ALIGN_END;
716 alignment = HORIZONTAL_ALIGN_BEGIN;
722 case HORIZONTAL_ALIGN_BEGIN:
724 line.alignmentOffset = 0.f;
728 // 'Remove' the white spaces at the end of the line (which are at the beginning in visual order)
729 line.alignmentOffset -= line.extraLength;
733 line.alignmentOffset += std::min( line.extraLength, boxWidth - lineLength );
738 case HORIZONTAL_ALIGN_CENTER:
740 if( isLastLine && !isRTL )
742 lineLength += line.extraLength;
743 if( lineLength > boxWidth )
745 lineLength = boxWidth;
746 line.alignmentOffset = 0.f;
751 line.alignmentOffset = 0.5f * ( boxWidth - lineLength );
755 line.alignmentOffset -= line.extraLength;
759 line.alignmentOffset += 0.5f * std::min( line.extraLength, boxWidth - lineLength );
763 line.alignmentOffset = floorf( line.alignmentOffset ); // try to avoid pixel alignment.
766 case HORIZONTAL_ALIGN_END:
768 if( isLastLine && !isRTL )
770 lineLength += line.extraLength;
771 if( lineLength > boxWidth )
773 line.alignmentOffset = 0.f;
780 lineLength += line.extraLength;
783 line.alignmentOffset = boxWidth - lineLength;
789 LayoutEngine::Layout mLayout;
790 LayoutEngine::HorizontalAlignment mHorizontalAlignment;
791 LayoutEngine::VerticalAlignment mVerticalAlignment;
793 TextAbstraction::FontClient mFontClient;
795 bool mEllipsisEnabled:1;
798 LayoutEngine::LayoutEngine()
801 mImpl = new LayoutEngine::Impl();
804 LayoutEngine::~LayoutEngine()
809 void LayoutEngine::SetLayout( Layout layout )
811 mImpl->mLayout = layout;
814 unsigned int LayoutEngine::GetLayout() const
816 return mImpl->mLayout;
819 void LayoutEngine::SetTextEllipsisEnabled( bool enabled )
821 mImpl->mEllipsisEnabled = enabled;
824 bool LayoutEngine::GetTextEllipsisEnabled() const
826 return mImpl->mEllipsisEnabled;
829 void LayoutEngine::SetHorizontalAlignment( HorizontalAlignment alignment )
831 mImpl->mHorizontalAlignment = alignment;
834 LayoutEngine::HorizontalAlignment LayoutEngine::GetHorizontalAlignment() const
836 return mImpl->mHorizontalAlignment;
839 void LayoutEngine::SetVerticalAlignment( VerticalAlignment alignment )
841 mImpl->mVerticalAlignment = alignment;
844 LayoutEngine::VerticalAlignment LayoutEngine::GetVerticalAlignment() const
846 return mImpl->mVerticalAlignment;
849 bool LayoutEngine::LayoutText( const LayoutParameters& layoutParameters,
850 Vector<Vector2>& glyphPositions,
851 Vector<LineRun>& lines,
854 return mImpl->LayoutText( layoutParameters,
860 void LayoutEngine::ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters,
861 Vector<Vector2>& glyphPositions )
863 mImpl->ReLayoutRightToLeftLines( layoutParameters,
867 void LayoutEngine::Align( const Size& layoutSize,
868 Vector<LineRun>& lines )
870 mImpl->Align( layoutSize,
876 } // namespace Toolkit