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=5e5cce7024e1ad612be3258d8fb17ef16a4a7349;hp=d73ee6aa48ed7cb40ce71099f9a1a5cd3a25a674;hb=bb9b5c8a2b3f0ce6bcf368e3bdea380d65353b1f;hpb=271110063e8b896a45d7c9116cf4ad53585933bd diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index d73ee6a..5e5cce7 100755 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,7 +52,8 @@ namespace const float MAX_FLOAT = std::numeric_limits::max(); const CharacterDirection LTR = false; const CharacterDirection RTL = !LTR; -const float LINE_SPACING= 0.f; +const float LINE_SPACING = 0.f; +const float MIN_LINE_SIZE = 0.f; inline bool isEmptyLineAtLast( const Vector& lines, const Vector::Iterator& line ) { @@ -130,7 +131,8 @@ struct Engine::Impl Impl() : mLayout{ Layout::Engine::SINGLE_LINE_BOX }, mCursorWidth{ 0.f }, - mDefaultLineSpacing{ LINE_SPACING } + mDefaultLineSpacing{ LINE_SPACING }, + mDefaultLineSize{ MIN_LINE_SIZE } { } @@ -162,8 +164,12 @@ struct Engine::Impl // Sets the minimum descender. lineLayout.descender = std::min( lineLayout.descender, fontMetrics.descender ); - // set the line spacing - lineLayout.lineSpacing = mDefaultLineSpacing; + // Sets the line size + lineLayout.lineSpacing = mDefaultLineSize - ( lineLayout.ascender + -lineLayout.descender ); + lineLayout.lineSpacing = lineLayout.lineSpacing < 0.f ? 0.f : lineLayout.lineSpacing; + + // Add the line spacing + lineLayout.lineSpacing += mDefaultLineSpacing; } /** @@ -376,7 +382,7 @@ struct Engine::Impl } else { - lineLayout.length = length; + lineLayout.length = std::max( length, lineLayout.length ); } } } @@ -551,7 +557,7 @@ struct Engine::Impl tmpLineLayout.penX += tmpLineLayout.previousAdvance + tmpLineLayout.whiteSpaceLengthEndOfLine; tmpLineLayout.previousAdvance = ( glyphMetrics.advance + parameters.interGlyphExtraAdvance ); - tmpLineLayout.length = tmpLineLayout.penX + glyphMetrics.xBearing + glyphMetrics.width; + tmpLineLayout.length = std::max( tmpLineLayout.length, tmpLineLayout.penX + glyphMetrics.xBearing + glyphMetrics.width ); // Clear the white space length at the end of the line. tmpLineLayout.whiteSpaceLengthEndOfLine = 0.f; @@ -664,7 +670,7 @@ struct Engine::Impl const GlyphInfo& glyph = *( glyphsBuffer + i ); Vector2& position = *( glyphPositionsBuffer + i ); - position.x = std::roundf( penX + glyph.xBearing ); + position.x = penX + glyph.xBearing; position.y = -glyph.yBearing; penX += ( glyph.advance + interGlyphExtraAdvance ); @@ -721,12 +727,12 @@ struct Engine::Impl // Convert the character in the visual order into the glyph in the visual order. const GlyphIndex glyphIndex = *( charactersToGlyphsBuffer + characterVisualIndex ) + index; - DALI_ASSERT_DEBUG( 0u <= glyphIndex && glyphIndex < layoutParameters.textModel->mVisualModel->mGlyphs.Count() ); + DALI_ASSERT_DEBUG( glyphIndex < layoutParameters.textModel->mVisualModel->mGlyphs.Count() ); const GlyphInfo& glyph = *( glyphsBuffer + glyphIndex ); Vector2& position = *( glyphPositionsBuffer + glyphIndex - layoutParameters.startGlyphIndex ); - position.x = std::round( penX + glyph.xBearing ); + position.x = penX + glyph.xBearing; position.y = -glyph.yBearing; penX += ( glyph.advance + layoutParameters.interGlyphExtraAdvance ); @@ -921,26 +927,9 @@ struct Engine::Impl lineRun.glyphRun.numberOfGlyphs = layout.numberOfGlyphs; lineRun.characterRun.characterIndex = layout.characterIndex; lineRun.characterRun.numberOfCharacters = layout.numberOfCharacters; - lineRun.lineSpacing = mDefaultLineSpacing; + lineRun.width = layout.length; + lineRun.extraLength = std::ceil( layout.whiteSpaceLengthEndOfLine ); - if( isLastLine && !layoutParameters.isLastNewParagraph ) - { - lineRun.width = layout.length; - if( LTR == layout.direction ) - { - lineRun.width += layout.whiteSpaceLengthEndOfLine; - lineRun.extraLength = 0.f; - } - else - { - lineRun.extraLength = layout.whiteSpaceLengthEndOfLine; - } - } - else - { - lineRun.width = layout.length; - lineRun.extraLength = std::ceil( layout.whiteSpaceLengthEndOfLine ); - } // Rounds upward to avoid a non integer size. lineRun.width = std::ceil( lineRun.width ); @@ -950,6 +939,12 @@ struct Engine::Impl lineRun.direction = layout.direction; lineRun.ellipsis = false; + lineRun.lineSpacing = mDefaultLineSize - ( lineRun.ascender + -lineRun.descender ); + lineRun.lineSpacing = lineRun.lineSpacing < 0.f ? 0.f : lineRun.lineSpacing; + + lineRun.lineSpacing += mDefaultLineSpacing; + + // Update the actual size. if( lineRun.width > layoutSize.width ) { @@ -1001,7 +996,11 @@ struct Engine::Impl lineRun.alignmentOffset = 0.f; lineRun.direction = LTR; lineRun.ellipsis = false; - lineRun.lineSpacing = mDefaultLineSpacing; + + lineRun.lineSpacing = mDefaultLineSize - ( lineRun.ascender + -lineRun.descender ); + lineRun.lineSpacing = lineRun.lineSpacing < 0.f ? 0.f : lineRun.lineSpacing; + + lineRun.lineSpacing += mDefaultLineSpacing; layoutSize.height += ( lineRun.ascender + -lineRun.descender ) + lineRun.lineSpacing; } @@ -1361,6 +1360,13 @@ struct Engine::Impl // Updates the vertical pen's position. penY += -layout.descender + layout.lineSpacing + mDefaultLineSpacing; + // If there is a defaultLineSize, updates the pen's position. + if( mDefaultLineSize > 0.f ) + { + float lineSpacing = mDefaultLineSize - ( layout.ascender + -layout.descender ); + lineSpacing = lineSpacing < 0.f ? 0.f : lineSpacing; + penY += lineSpacing; + } // Increase the glyph index. index = nextIndex; @@ -1566,6 +1572,7 @@ struct Engine::Impl Type mLayout; float mCursorWidth; float mDefaultLineSpacing; + float mDefaultLineSize; IntrusivePtr mMetrics; }; @@ -1647,6 +1654,16 @@ float Engine::GetDefaultLineSpacing() const return mImpl->mDefaultLineSpacing; } +void Engine::SetDefaultLineSize( float lineSize ) +{ + mImpl->mDefaultLineSize = lineSize; +} + +float Engine::GetDefaultLineSize() const +{ + return mImpl->mDefaultLineSize; +} + } // namespace Layout } // namespace Text