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=9062b07c1d3d0d337365a0c1f1bdbee554e61bb3;hp=442b631fcfffc2e54ab112a54c05e2baf22e9dcf;hb=9fd0114ee708e9c197cc539b09acc6b8eaaf1c61;hpb=85b83b75993f7e01302d67c19aa53c3e1fc63586 diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index 442b631..9062b07 100644 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -20,9 +20,8 @@ // EXTERNAL INCLUDES #include -#include -#include #include +#include // INTERNAL INCLUDES #include @@ -46,6 +45,7 @@ namespace const float MAX_FLOAT = std::numeric_limits::max(); const bool RTL = true; +const float CURSOR_WIDTH = 1.f; } //namespace @@ -102,9 +102,9 @@ struct LayoutEngine::Impl : mLayout( LayoutEngine::SINGLE_LINE_BOX ), mHorizontalAlignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN ), mVerticalAlignment( LayoutEngine::VERTICAL_ALIGN_TOP ), + mCursorWidth( CURSOR_WIDTH ), mEllipsisEnabled( false ) { - mFontClient = TextAbstraction::FontClient::Get(); } /** @@ -116,7 +116,7 @@ struct LayoutEngine::Impl void UpdateLineHeight( FontId fontId, LineLayout& lineLayout ) { Text::FontMetrics fontMetrics; - mFontClient.GetFontMetrics( fontId, fontMetrics ); + mMetrics->GetFontMetrics( fontId, fontMetrics ); // Sets the maximum ascender. if( fontMetrics.ascender > lineLayout.ascender ) @@ -211,7 +211,7 @@ struct LayoutEngine::Impl float tmpExtraBearing = ( 0.f > glyphInfo.xBearing ) ? -glyphInfo.xBearing : 0.f; - tmpLineLayout.length += 1.f; // Added one unit to give some space to the cursor. + tmpLineLayout.length += mCursorWidth; // Added to give some space to the cursor. // Calculate the line height if there is no characters. FontId lastFontId = glyphInfo.fontId; @@ -451,7 +451,7 @@ struct LayoutEngine::Impl const GlyphInfo& glyph = *glyphsBuffer; float penX = ( 0.f > glyph.xBearing ) ? -glyph.xBearing : 0.f; - penX += 1.f; // Added one unit to give some space to the cursor. + penX += mCursorWidth; // Added to give some space to the cursor. for( GlyphIndex i = 0u; i < numberOfGlyphs; ++i ) { @@ -528,11 +528,11 @@ struct LayoutEngine::Impl penY -= layout.ascender - lineRun.descender; - ellipsisLayout.glyphIndex = lineRun.glyphIndex; + ellipsisLayout.glyphIndex = lineRun.glyphRun.glyphIndex; } else { - lineRun.glyphIndex = 0u; + lineRun.glyphRun.glyphIndex = 0u; ellipsisLayout.glyphIndex = 0u; } @@ -541,22 +541,23 @@ struct LayoutEngine::Impl currentParagraphDirection, true ); - lineRun.numberOfGlyphs = ellipsisLayout.numberOfGlyphs; + lineRun.glyphRun.numberOfGlyphs = ellipsisLayout.numberOfGlyphs; lineRun.characterRun.characterIndex = ellipsisLayout.characterIndex; lineRun.characterRun.numberOfCharacters = ellipsisLayout.numberOfCharacters; lineRun.width = ellipsisLayout.length; lineRun.extraLength = ( ellipsisLayout.wsLengthEndOfLine > 0.f ) ? ellipsisLayout.wsLengthEndOfLine - ellipsisLayout.extraWidth : 0.f; lineRun.ascender = ellipsisLayout.ascender; lineRun.descender = ellipsisLayout.descender; + lineRun.direction = !RTL; lineRun.ellipsis = true; actualSize.width = layoutParameters.boundingBox.width; actualSize.height += ( lineRun.ascender + -lineRun.descender ); - SetGlyphPositions( layoutParameters.glyphsBuffer + lineRun.glyphIndex, + SetGlyphPositions( layoutParameters.glyphsBuffer + lineRun.glyphRun.glyphIndex, ellipsisLayout.numberOfGlyphs, penY, - glyphPositions.Begin() + lineRun.glyphIndex ); + glyphPositions.Begin() + lineRun.glyphRun.glyphIndex ); if( 0u != numberOfLines ) { @@ -576,8 +577,8 @@ struct LayoutEngine::Impl const bool isLastLine = index + layout.numberOfGlyphs == layoutParameters.totalNumberOfGlyphs; LineRun lineRun; - lineRun.glyphIndex = index; - lineRun.numberOfGlyphs = layout.numberOfGlyphs; + lineRun.glyphRun.glyphIndex = index; + lineRun.glyphRun.numberOfGlyphs = layout.numberOfGlyphs; lineRun.characterRun.characterIndex = layout.characterIndex; lineRun.characterRun.numberOfCharacters = layout.numberOfCharacters; if( isLastLine && !layoutParameters.isLastNewParagraph ) @@ -601,7 +602,7 @@ struct LayoutEngine::Impl } lineRun.ascender = layout.ascender; lineRun.descender = layout.descender; - lineRun.direction = false; + lineRun.direction = !RTL; lineRun.ellipsis = false; lines.PushBack( lineRun ); @@ -632,11 +633,11 @@ struct LayoutEngine::Impl const GlyphInfo& glyphInfo = *( layoutParameters.glyphsBuffer + layoutParameters.totalNumberOfGlyphs - 1u ); Text::FontMetrics fontMetrics; - mFontClient.GetFontMetrics( glyphInfo.fontId, fontMetrics ); + mMetrics->GetFontMetrics( glyphInfo.fontId, fontMetrics ); LineRun lineRun; - lineRun.glyphIndex = 0u; - lineRun.numberOfGlyphs = 0u; + lineRun.glyphRun.glyphIndex = 0u; + lineRun.glyphRun.numberOfGlyphs = 0u; lineRun.characterRun.characterIndex = 0u; lineRun.characterRun.numberOfCharacters = 0u; lineRun.width = 0.f; @@ -671,7 +672,7 @@ struct LayoutEngine::Impl const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) ); float penX = ( 0.f > glyph.xBearing ) ? -glyph.xBearing : 0.f; - penX += 1.f; // Added one unit to give some space to the cursor. + penX += mCursorWidth; // Added to give some space to the cursor. Vector2* glyphPositionsBuffer = glyphPositions.Begin(); @@ -817,8 +818,9 @@ struct LayoutEngine::Impl LayoutEngine::Layout mLayout; LayoutEngine::HorizontalAlignment mHorizontalAlignment; LayoutEngine::VerticalAlignment mVerticalAlignment; + float mCursorWidth; - TextAbstraction::FontClient mFontClient; + IntrusivePtr mMetrics; bool mEllipsisEnabled:1; }; @@ -834,6 +836,11 @@ LayoutEngine::~LayoutEngine() delete mImpl; } +void LayoutEngine::SetMetrics( MetricsPtr& metrics ) +{ + mImpl->mMetrics = metrics; +} + void LayoutEngine::SetLayout( Layout layout ) { mImpl->mLayout = layout; @@ -874,6 +881,16 @@ LayoutEngine::VerticalAlignment LayoutEngine::GetVerticalAlignment() const return mImpl->mVerticalAlignment; } +void LayoutEngine::SetCursorWidth( int width ) +{ + mImpl->mCursorWidth = static_cast( width ); +} + +int LayoutEngine::GetCursorWidth() const +{ + return static_cast( mImpl->mCursorWidth ); +} + bool LayoutEngine::LayoutText( const LayoutParameters& layoutParameters, Vector& glyphPositions, Vector& lines,