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=f97a8ea96e2dac3a2ae81454637eeee4a2058f9c;hp=4ace75b8d90b25afe728548ab59983d96853d6a7;hb=fe706c2b9e0a2ce31c91317dd6749faecef6d92e;hpb=b11fd29e45c9c10a5e7086d75c37aa1a0d923d27 diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp old mode 100644 new mode 100755 index 4ace75b..f97a8ea --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -394,11 +394,19 @@ struct Engine::Impl tmpLineLayout.wsLengthEndOfLine = 0.f; } + // If calculation is end but wsLengthEndOfLine is exist, it means end of text is space. + // Merge remained length. + if ( !parameters.ignoreSpaceAfterText && glyphIndex == lastGlyphOfParagraphPlusOne-1 && tmpLineLayout.wsLengthEndOfLine > 0 ) + { + tmpLineLayout.length += tmpLineLayout.wsLengthEndOfLine; + tmpLineLayout.wsLengthEndOfLine = 0u; + } + // Save the current extra width to compare with the next one mPreviousCharacterExtraWidth = tmpExtraWidth; // Check if the accumulated length fits in the width of the box. - if( ( completelyFill || isMultiline ) && !isWhiteSpace && + if( ( completelyFill || isMultiline ) && !(parameters.ignoreSpaceAfterText && isWhiteSpace) && ( tmpExtraBearing + lineLayout.length + lineLayout.wsLengthEndOfLine + tmpLineLayout.length + tmpExtraWidth > parameters.boundingBox.width ) ) { // Current word does not fit in the box's width. @@ -547,6 +555,7 @@ struct Engine::Impl * @param[in,out] numberOfLines The number of laid-out lines. * @param[in] penY The vertical layout position. * @param[in] currentParagraphDirection The current paragraph's direction. + * @param[in,out] isAutoScrollEnabled If the isAutoScrollEnabled is true and the height of the text exceeds the boundaries of the control the text is elided and the isAutoScrollEnabled is set to false to disable the autoscroll * * return Whether the line is ellipsized. */ @@ -557,14 +566,17 @@ struct Engine::Impl Vector2* glyphPositionsBuffer, Length& numberOfLines, float penY, - CharacterDirection currentParagraphDirection ) + CharacterDirection currentParagraphDirection, + bool& isAutoScrollEnabled ) { - const bool ellipsis = ( ( penY - layout.descender > layoutParameters.boundingBox.height ) || - ( ( mLayout == SINGLE_LINE_BOX ) && - ( layout.extraBearing + layout.length + layout.extraWidth > layoutParameters.boundingBox.width ) ) ); + const bool ellipsis = isAutoScrollEnabled ? ( penY - layout.descender > layoutParameters.boundingBox.height ) : + ( ( penY - layout.descender > layoutParameters.boundingBox.height ) || + ( ( mLayout == SINGLE_LINE_BOX ) && + ( layout.extraBearing + layout.length + layout.extraWidth > layoutParameters.boundingBox.width ) ) ); if( ellipsis ) { + isAutoScrollEnabled = false; // Do not layout more lines if ellipsis is enabled. // The last line needs to be completely filled with characters. @@ -783,7 +795,8 @@ struct Engine::Impl Vector& glyphPositions, Vector& lines, Size& layoutSize, - bool elideTextEnabled ) + bool elideTextEnabled, + bool& isAutoScrollEnabled ) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->LayoutText\n" ); DALI_LOG_INFO( gLogFilter, Debug::Verbose, " box size %f, %f\n", layoutParameters.boundingBox.width, layoutParameters.boundingBox.height ); @@ -917,7 +930,8 @@ struct Engine::Impl glyphPositionsBuffer, numberOfLines, penY, - currentParagraphDirection ); + currentParagraphDirection, + isAutoScrollEnabled ); } if( ellipsis ) @@ -1096,7 +1110,9 @@ struct Engine::Impl Length numberOfCharacters, Text::HorizontalAlignment::Type horizontalAlignment, Vector& lines, - float& alignmentOffset ) + float& alignmentOffset, + Dali::LayoutDirection::Type layoutDirection, + bool matchSystemLanguageDirection ) { const CharacterIndex lastCharacterPlusOne = startIndex + numberOfCharacters; @@ -1124,7 +1140,9 @@ struct Engine::Impl // the box width, line length, and the paragraph's direction. CalculateHorizontalAlignment( size.width, horizontalAlignment, - line ); + line, + layoutDirection, + matchSystemLanguageDirection ); // Updates the alignment offset. alignmentOffset = std::min( alignmentOffset, line.alignmentOffset ); @@ -1133,47 +1151,46 @@ struct Engine::Impl void CalculateHorizontalAlignment( float boxWidth, HorizontalAlignment::Type horizontalAlignment, - LineRun& line ) + LineRun& line, + Dali::LayoutDirection::Type layoutDirection, + bool matchSystemLanguageDirection ) { line.alignmentOffset = 0.f; - const bool isRTL = RTL == line.direction; + const bool isLineRTL = RTL == line.direction; + // Whether to swap the alignment. + // Swap if the line is RTL and is not required to match the direction of the system's language or if it's required to match the direction of the system's language and it's RTL. + bool isLayoutRTL = isLineRTL; float lineLength = line.width; - HorizontalAlignment::Type alignment = horizontalAlignment; - if( isRTL ) + // match align for system language direction + if( matchSystemLanguageDirection ) { // Swap the alignment type if the line is right to left. - switch( alignment ) - { - case HorizontalAlignment::BEGIN: - { - alignment = HorizontalAlignment::END; - break; - } - case HorizontalAlignment::CENTER: - { - // Nothing to do. - break; - } - case HorizontalAlignment::END: - { - alignment = HorizontalAlignment::BEGIN; - break; - } - } + isLayoutRTL = layoutDirection == LayoutDirection::RIGHT_TO_LEFT; } - // Calculate the horizontal line offset. - switch( alignment ) + switch( horizontalAlignment ) { case HorizontalAlignment::BEGIN: { - line.alignmentOffset = 0.f; + if( isLayoutRTL ) + { + if( isLineRTL ) + { + lineLength += line.extraLength; + } - if( isRTL ) + line.alignmentOffset = boxWidth - lineLength; + } + else { - // 'Remove' the white spaces at the end of the line (which are at the beginning in visual order) - line.alignmentOffset -= line.extraLength; + line.alignmentOffset = 0.f; + + if( isLineRTL ) + { + // 'Remove' the white spaces at the end of the line (which are at the beginning in visual order) + line.alignmentOffset -= line.extraLength; + } } break; } @@ -1181,7 +1198,7 @@ struct Engine::Impl { line.alignmentOffset = 0.5f * ( boxWidth - lineLength ); - if( isRTL ) + if( isLineRTL ) { line.alignmentOffset -= line.extraLength; } @@ -1191,12 +1208,25 @@ struct Engine::Impl } case HorizontalAlignment::END: { - if( isRTL ) + if( isLayoutRTL ) { - lineLength += line.extraLength; + line.alignmentOffset = 0.f; + + if( isLineRTL ) + { + // 'Remove' the white spaces at the end of the line (which are at the beginning in visual order) + line.alignmentOffset -= line.extraLength; + } } + else + { + if( isLineRTL ) + { + lineLength += line.extraLength; + } - line.alignmentOffset = boxWidth - lineLength; + line.alignmentOffset = boxWidth - lineLength; + } break; } } @@ -1267,13 +1297,15 @@ bool Engine::LayoutText( const Parameters& layoutParameters, Vector& glyphPositions, Vector& lines, Size& layoutSize, - bool elideTextEnabled ) + bool elideTextEnabled, + bool& isAutoScrollEnabled ) { return mImpl->LayoutText( layoutParameters, glyphPositions, lines, layoutSize, - elideTextEnabled ); + elideTextEnabled, + isAutoScrollEnabled ); } void Engine::ReLayoutRightToLeftLines( const Parameters& layoutParameters, @@ -1292,14 +1324,18 @@ void Engine::Align( const Size& size, Length numberOfCharacters, Text::HorizontalAlignment::Type horizontalAlignment, Vector& lines, - float& alignmentOffset ) + float& alignmentOffset, + Dali::LayoutDirection::Type layoutDirection, + bool matchSystemLanguageDirection ) { mImpl->Align( size, startIndex, numberOfCharacters, horizontalAlignment, lines, - alignmentOffset ); + alignmentOffset, + layoutDirection, + matchSystemLanguageDirection ); } void Engine::SetDefaultLineSpacing( float lineSpacing )