X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Flayouts%2Flayout-engine.cpp;h=fa1e91969f56747fbec8c3f48157edd365e491d7;hp=ebbf65bf447cdc3825a14a4b611f7e61f87521d2;hb=a117d2b75fc50a0e12ce7c5ffc1f6ad88c9fbc35;hpb=40a47ee7e802afa836ba45f481b87d0bd28e34fa diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index ebbf65b..fa1e919 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -55,7 +55,8 @@ struct LayoutEngine::Impl { Impl() : mLayout( LayoutEngine::SINGLE_LINE_BOX ), - mAlignment( LayoutEngine::ALIGN_BEGIN ) + mHorizontalAlignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN ), + mVerticalAlignment( LayoutEngine::VERTICAL_ALIGN_TOP ) { mFontClient = TextAbstraction::FontClient::Get(); } @@ -355,14 +356,16 @@ struct LayoutEngine::Impl void ReLayoutRightToLeftLines( const LayoutParameters& layoutParameters, Vector& glyphPositions ) { + // Traverses the paragraphs with right to left characters. for( LineIndex lineIndex = 0u; lineIndex < layoutParameters.numberOfBidirectionalInfoRuns; ++lineIndex ) { - const BidirectionalLineInfoRun& bidiLine = *( layoutParameters.lineBidirectionalInfoRunsBuffer +lineIndex ); + const BidirectionalLineInfoRun& bidiLine = *( layoutParameters.lineBidirectionalInfoRunsBuffer + lineIndex ); float penX = 0.f; Vector2* glyphPositionsBuffer = glyphPositions.Begin(); + // Traverses the characters of the right to left paragraph. for( CharacterIndex characterLogicalIndex = 0u; characterLogicalIndex < bidiLine.characterRun.numberOfCharacters; ++characterLogicalIndex ) @@ -376,7 +379,9 @@ struct LayoutEngine::Impl for( GlyphIndex index = 0u; index < numberOfGlyphs; ++index ) { // Convert the character in the visual order into the glyph in the visual order. - GlyphIndex glyphIndex = 1u + *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex + index ) - numberOfGlyphs; + const GlyphIndex glyphIndex = *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) + index; + + DALI_ASSERT_DEBUG( 0u <= glyphIndex && glyphIndex < layoutParameters.totalNumberOfGlyphs ); const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + glyphIndex ); Vector2& position = *( glyphPositionsBuffer + glyphIndex ); @@ -431,10 +436,10 @@ struct LayoutEngine::Impl // 2) Calculate the alignment offset accordingly with the align option, // the box width, line length, and the paragraphs direction. - float alignOffset = CalculateAlignment( layoutSize.width, - line.lineSize.width, - line.extraLength, - paragraphDirection ); + float alignOffset = CalculateHorizontalAlignment( layoutSize.width, + line.lineSize.width, + line.extraLength, + paragraphDirection ); // 3) Traverse all glyphs and update the 'x' position. for( GlyphIndex index = line.glyphIndex, @@ -564,42 +569,42 @@ struct LayoutEngine::Impl return true; } - float CalculateAlignment( float boxWidth, - float lineLength, - float extraLength, - bool paragraphDirection ) + float CalculateHorizontalAlignment( float boxWidth, + float lineLength, + float extraLength, + bool paragraphDirection ) { float offset = 0.f; - Alignment alignment = mAlignment; + HorizontalAlignment alignment = mHorizontalAlignment; if( paragraphDirection && - ( ALIGN_CENTER != alignment ) ) + ( HORIZONTAL_ALIGN_CENTER != alignment ) ) { - if( ALIGN_BEGIN == alignment ) + if( HORIZONTAL_ALIGN_BEGIN == alignment ) { - alignment = ALIGN_END; + alignment = HORIZONTAL_ALIGN_END; } else { - alignment = ALIGN_BEGIN; + alignment = HORIZONTAL_ALIGN_BEGIN; } } switch( alignment ) { - case ALIGN_BEGIN: + case HORIZONTAL_ALIGN_BEGIN: { offset = 0.f; break; } - case ALIGN_CENTER: + case HORIZONTAL_ALIGN_CENTER: { offset = 0.5f * ( boxWidth - lineLength ); const int intOffset = static_cast( offset ); // try to avoid pixel alignment. offset = static_cast( intOffset ); break; } - case ALIGN_END: + case HORIZONTAL_ALIGN_END: { offset = boxWidth - lineLength; break; @@ -615,7 +620,8 @@ struct LayoutEngine::Impl } LayoutEngine::Layout mLayout; - LayoutEngine::Alignment mAlignment; + LayoutEngine::HorizontalAlignment mHorizontalAlignment; + LayoutEngine::VerticalAlignment mVerticalAlignment; TextAbstraction::FontClient mFontClient; }; @@ -641,14 +647,24 @@ unsigned int LayoutEngine::GetLayout() const return mImpl->mLayout; } -void LayoutEngine::SetAlignment( Alignment alignment ) +void LayoutEngine::SetHorizontalAlignment( HorizontalAlignment alignment ) +{ + mImpl->mHorizontalAlignment = alignment; +} + +LayoutEngine::HorizontalAlignment LayoutEngine::GetHorizontalAlignment() const +{ + return mImpl->mHorizontalAlignment; +} + +void LayoutEngine::SetVerticalAlignment( VerticalAlignment alignment ) { - mImpl->mAlignment = alignment; + mImpl->mVerticalAlignment = alignment; } -LayoutEngine::Alignment LayoutEngine::GetAlignment() const +LayoutEngine::VerticalAlignment LayoutEngine::GetVerticalAlignment() const { - return mImpl->mAlignment; + return mImpl->mVerticalAlignment; } bool LayoutEngine::LayoutText( const LayoutParameters& layoutParameters,