From 2c41553e8144b52da80b174939367a34ac2a871d Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Fri, 1 Nov 2019 10:42:26 +0000 Subject: [PATCH] Text cleaning. * Refactor the Layout::Parameters struct * Remove unnecesary code. Change-Id: I1ebd7a01b3d7fe33917d51c481b536118c5c9bae Signed-off-by: Victor Cebollada --- .../dali-toolkit-test-utils/toolkit-text-utils.cpp | 41 ++------ .../dali-toolkit-test-utils/toolkit-text-utils.h | 9 +- .../utc-Dali-BidirectionalSupport.cpp | 36 ++++--- .../utc-Dali-LogicalModel.cpp | 45 ++++---- .../dali-toolkit-internal/utc-Dali-Text-Cursor.cpp | 36 ++++--- .../dali-toolkit-internal/utc-Dali-Text-Layout.cpp | 71 +++++-------- .../utc-Dali-Text-Shaping.cpp | 9 +- .../dali-toolkit-internal/utc-Dali-VisualModel.cpp | 18 ++-- dali-toolkit/devel-api/text/text-utils-devel.cpp | 103 ++++++++---------- .../internal/text/layouts/layout-engine.cpp | 116 +++++++++++++-------- .../internal/text/layouts/layout-parameters.h | 83 +++------------ dali-toolkit/internal/text/logical-model-impl.h | 1 - .../internal/text/text-controller-impl.cpp | 27 ----- dali-toolkit/internal/text/text-controller.cpp | 27 +---- dali-toolkit/internal/text/text-controller.h | 19 ++-- 15 files changed, 262 insertions(+), 379 deletions(-) diff --git a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp index e3ccad8..16666e9 100755 --- a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp +++ b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.cpp @@ -79,7 +79,6 @@ void ClearModelData( CharacterIndex characterIndex, logicalModel->mScriptRuns.Clear(); logicalModel->mFontRuns.Clear(); - logicalModel->mWordBreakInfo.Clear(); logicalModel->mBidirectionalParagraphInfo.Clear(); logicalModel->mCharacterDirections.Clear(); logicalModel->mBidirectionalLineInfo.Clear(); @@ -99,13 +98,13 @@ void CreateTextModel( const std::string& text, const Vector& fontDescriptions, const LayoutOptions& options, Size& layoutSize, - LogicalModelPtr& logicalModel, - VisualModelPtr& visualModel, + ModelPtr& textModel, MetricsPtr& metrics, bool markupProcessorEnabled ) { - logicalModel = LogicalModel::New(); - visualModel = VisualModel::New(); + textModel = Model::New(); ///< Pointer to the text's model. + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; MarkupProcessData markupProcessData( logicalModel->mColorRuns, logicalModel->mFontDescriptionRuns, @@ -153,15 +152,6 @@ void CreateTextModel( const std::string& text, return; } - // Retrieves the word break info. The word break info is used to layout the text (where to wrap the text in lines). - Vector& wordBreakInfo = logicalModel->mWordBreakInfo; - wordBreakInfo.Resize( characterCount ); - - SetWordBreakInfo( utf32Characters, - 0u, - characterCount, - wordBreakInfo ); - // 3) Set the script info. MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get(); @@ -291,25 +281,12 @@ void CreateTextModel( const std::string& text, layoutEngine.SetLayout( Layout::Engine::MULTI_LINE_BOX ); // Set the layout parameters. - const Vector& charactersToGlyph = visualModel->mCharactersToGlyph; - const Vector& glyphsPerCharacter = visualModel->mGlyphsPerCharacter; - float outlineWidth = visualModel->GetOutlineWidth(); + textModel->mHorizontalAlignment = Text::HorizontalAlignment::BEGIN; + textModel->mLineWrapMode = LineWrap::WORD; + textModel->mIgnoreSpacesAfterText = true; + textModel->mMatchSystemLanguageDirection = false; Layout::Parameters layoutParameters( textArea, - utf32Characters.Begin(), - lineBreakInfo.Begin(), - wordBreakInfo.Begin(), - ( 0u != characterDirections.Count() ) ? characterDirections.Begin() : NULL, - glyphs.Begin(), - glyphsToCharactersMap.Begin(), - charactersPerGlyph.Begin(), - charactersToGlyph.Begin(), - glyphsPerCharacter.Begin(), - numberOfGlyphs, - Text::HorizontalAlignment::BEGIN, - Text::LineWrap::WORD, - outlineWidth, - true, - false ); + textModel ); Vector& lines = visualModel->mLines; diff --git a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.h b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.h index 1e6d750..e4b7ddd 100644 --- a/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.h +++ b/automated-tests/src/dali-toolkit-internal/dali-toolkit-test-utils/toolkit-text-utils.h @@ -19,10 +19,9 @@ */ // INTERNAL INCLUDES -#include #include -#include #include +#include namespace Dali { @@ -56,8 +55,7 @@ struct LayoutOptions * @param[in] fontDescriptions The fonts to be used. * @param[in] options Layout options. * @param[out] layoutSize The laid-out size. - * @param[out] logicalModel Pointer to a logical text model instance. - * @param[out] visualModel Pointer to a visual text model instance. + * @param[out] textModel Pointer to a text model instance. * @param[out] metrics Pointer to a wrapper around FontClient used to get metrics. * @param[in] markupProcessorEnabled Enable markup processor to use markup text. */ @@ -66,8 +64,7 @@ void CreateTextModel( const std::string& text, const Vector& fontDescriptions, const LayoutOptions& options, Size& layoutSize, - LogicalModelPtr& logicalModel, - VisualModelPtr& visualModel, + ModelPtr& textModel, MetricsPtr& metrics, bool markupProcessorEnabled ); diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-BidirectionalSupport.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-BidirectionalSupport.cpp index 191ead1..cc6e070 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-BidirectionalSupport.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-BidirectionalSupport.cpp @@ -112,8 +112,7 @@ struct GetCharactersDirectionData bool SetBidirectionalInfoTest( const SetBidirectionalInfoData& data ) { // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(100.f, 60.f); Size layoutSize; @@ -126,11 +125,13 @@ bool SetBidirectionalInfoTest( const SetBidirectionalInfoData& data ) fontDescriptions, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + // 2) Clear the bidirectional paragraph info data. Vector& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo; if( 0u != data.numberOfCharacters ) @@ -219,8 +220,7 @@ void FreeBidirectionalLineInfoResources( Vector bidire bool ReorderLinesTest( const ReorderLinesData& data ) { // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(100.f, 300.f); Size layoutSize; @@ -233,11 +233,13 @@ bool ReorderLinesTest( const ReorderLinesData& data ) fontDescriptions, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + // 2) Clear the bidirectional line info data. uint32_t startRemoveIndex = logicalModel->mBidirectionalLineInfo.Count(); uint32_t endRemoveIndex = startRemoveIndex; @@ -345,8 +347,7 @@ bool ReorderLinesTest( const ReorderLinesData& data ) bool GetMirroredTextTest( const GetMirroredTextData& data ) { // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(100.f, 60.f); Size layoutSize; @@ -359,11 +360,13 @@ bool GetMirroredTextTest( const GetMirroredTextData& data ) fontDescriptions, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + // 2) Call the GetMirroredText() function for the whole text Vector mirroredText; bool mirrored = false; @@ -420,8 +423,7 @@ bool GetMirroredTextTest( const GetMirroredTextData& data ) bool GetCharactersDirectionTest( const GetCharactersDirectionData& data ) { // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(100.f, 60.f); Size layoutSize; @@ -434,11 +436,13 @@ bool GetCharactersDirectionTest( const GetCharactersDirectionData& data ) fontDescriptions, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, data.markupProcessorEnabled ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + Vector& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo; // 2) Clear the direction info data. diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-LogicalModel.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-LogicalModel.cpp index 67c7e24..7cbbe90 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-LogicalModel.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-LogicalModel.cpp @@ -104,8 +104,7 @@ struct GetLogicalCursorIndexData bool CreateParagraphTest( const CreateParagraphData& data ) { // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(100.f, 60.f); Size layoutSize; @@ -117,11 +116,13 @@ bool CreateParagraphTest( const CreateParagraphData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + // 2) Clear the paragraphs. Vector& paragraphs = logicalModel->mParagraphInfo; ClearCharacterRuns( data.index, @@ -165,8 +166,7 @@ bool CreateParagraphTest( const CreateParagraphData& data ) bool FindParagraphTest( const FindParagraphData& data ) { // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(100.f, 60.f); Size layoutSize; @@ -178,11 +178,13 @@ bool FindParagraphTest( const FindParagraphData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + // 2) Find the paragraphs. Vector paragraphs; logicalModel->FindParagraphs( data.index, data.numberOfCharacters, paragraphs ); @@ -214,8 +216,7 @@ bool FetchBidirectionalLineInfoTest( const FetchBidirectionalLineInfoData& data { std::cout << " testing : " << data.description << std::endl; // Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea( 100.f, 300.f ); Size layoutSize; @@ -228,11 +229,13 @@ bool FetchBidirectionalLineInfoTest( const FetchBidirectionalLineInfoData& data fontDescriptions, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + for( unsigned int index = 0; index < data.numberOfTests; ++index ) { const bool fetched = logicalModel->FetchBidirectionalLineInfo( data.characterIndex[index] ); @@ -260,8 +263,7 @@ bool GetLogicalCharacterIndexTest( const GetLogicalCharacterIndexData& data ) { std::cout << " testing : " << data.description << std::endl; // Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size layoutSize; @@ -273,11 +275,13 @@ bool GetLogicalCharacterIndexTest( const GetLogicalCharacterIndexData& data ) fontDescriptions, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + for( unsigned int index = 0u; index < data.numberOfIndices; ++index ) { // Check the current cached bidi line index. (Check it before call the GetLogicalCharacterIndex() method ) @@ -315,8 +319,7 @@ bool GetLogicalCursorIndexTest( const GetLogicalCursorIndexData& data ) fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf" ); // Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size layoutSize; @@ -335,11 +338,13 @@ bool GetLogicalCursorIndexTest( const GetLogicalCursorIndexData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + for( unsigned int index = 0u; index < data.numberOfIndices; ++index ) { const bool fetched = logicalModel->FetchBidirectionalLineInfo( data.characterIndex[index] ); diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Cursor.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Cursor.cpp index 74d3358..3af2020 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Cursor.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Cursor.cpp @@ -97,8 +97,7 @@ bool GetClosestLineTest( const GetClosestLineData& data ) std::cout << " testing : " << data.description << std::endl; // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(400.f, 600.f); Size layoutSize; @@ -110,11 +109,13 @@ bool GetClosestLineTest( const GetClosestLineData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + for( unsigned int index = 0; index < data.numberOfTests; ++index ) { bool isLineHit = false; @@ -142,8 +143,7 @@ bool GetClosestCursorIndexTest( const GetClosestCursorIndexData& data ) std::cout << " testing : " << data.description << std::endl; // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(400.f, 600.f); Size layoutSize; @@ -155,11 +155,13 @@ bool GetClosestCursorIndexTest( const GetClosestCursorIndexData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + for( unsigned int index = 0; index < data.numberOfTests; ++index ) { bool isCharacterHit = false; @@ -191,8 +193,7 @@ bool GetCursorPositionTest( const GetCursorPositionData& data ) std::cout << " testing : " << data.description << std::endl; // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(400.f, 600.f); Size layoutSize; @@ -204,11 +205,13 @@ bool GetCursorPositionTest( const GetCursorPositionData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + GetCursorPositionParameters parameters; parameters.visualModel = visualModel; parameters.logicalModel = logicalModel; @@ -243,8 +246,7 @@ bool FindSelectionIndicesTest( const FindSelectionIndicesData& data ) std::cout << " testing : " << data.description << std::endl; // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(400.f, 600.f); Size layoutSize; @@ -256,11 +258,13 @@ bool FindSelectionIndicesTest( const FindSelectionIndicesData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + for( unsigned int index = 0; index < data.numberOfTests; ++index ) { CharacterIndex startIndex = 0; diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp index f27f4d7..3e4eb33 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Layout.cpp @@ -87,8 +87,7 @@ bool LayoutTextTest( const LayoutTextData& data ) fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHindiRegular.ttf" ); // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size layoutSize; @@ -108,11 +107,13 @@ bool LayoutTextTest( const LayoutTextData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + // 2) Clear the layout. Vector& lines = visualModel->mLines; @@ -158,25 +159,12 @@ bool LayoutTextTest( const LayoutTextData& data ) engine.SetMetrics( metrics ); engine.SetLayout( data.layout ); - const Length totalNumberOfGlyphs = visualModel->mGlyphs.Count(); - float outlineWidth = visualModel->GetOutlineWidth(); - + textModel->mHorizontalAlignment = Text::HorizontalAlignment::BEGIN; + textModel->mLineWrapMode = LineWrap::WORD; + textModel->mIgnoreSpacesAfterText = true; + textModel->mMatchSystemLanguageDirection = false; Layout::Parameters layoutParameters( data.textArea, - logicalModel->mText.Begin(), - logicalModel->mLineBreakInfo.Begin(), - logicalModel->mWordBreakInfo.Begin(), - ( 0u != logicalModel->mCharacterDirections.Count() ) ? logicalModel->mCharacterDirections.Begin() : NULL, - visualModel->mGlyphs.Begin(), - visualModel->mGlyphsToCharacters.Begin(), - visualModel->mCharactersPerGlyph.Begin(), - visualModel->mCharactersToGlyph.Begin(), - visualModel->mGlyphsPerCharacter.Begin(), - totalNumberOfGlyphs, - Text::HorizontalAlignment::BEGIN, - Text::LineWrap::WORD, - outlineWidth, - true, - false ); + textModel ); layoutParameters.isLastNewParagraph = isLastNewParagraph; @@ -353,8 +341,7 @@ bool ReLayoutRightToLeftLinesTest( const ReLayoutRightToLeftLinesData& data ) fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" ); // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size layoutSize; @@ -374,32 +361,23 @@ bool ReLayoutRightToLeftLinesTest( const ReLayoutRightToLeftLinesData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + // 2) Call the ReLayoutRightToLeftLines() method. Layout::Engine engine; engine.SetMetrics( metrics ); - float outlineWidth = visualModel->GetOutlineWidth(); + textModel->mHorizontalAlignment = Text::HorizontalAlignment::BEGIN; + textModel->mLineWrapMode = LineWrap::WORD; + textModel->mIgnoreSpacesAfterText = true; + textModel->mMatchSystemLanguageDirection = false; Layout::Parameters layoutParameters( data.textArea, - logicalModel->mText.Begin(), - logicalModel->mLineBreakInfo.Begin(), - logicalModel->mWordBreakInfo.Begin(), - ( 0u != logicalModel->mCharacterDirections.Count() ) ? logicalModel->mCharacterDirections.Begin() : NULL, - visualModel->mGlyphs.Begin(), - visualModel->mGlyphsToCharacters.Begin(), - visualModel->mCharactersPerGlyph.Begin(), - visualModel->mCharactersToGlyph.Begin(), - visualModel->mGlyphsPerCharacter.Begin(), - visualModel->mGlyphs.Count(), - Text::HorizontalAlignment::BEGIN, - Text::LineWrap::WORD, - outlineWidth, - true, - false ); + textModel ); layoutParameters.numberOfBidirectionalInfoRuns = logicalModel->mBidirectionalLineInfo.Count(); layoutParameters.lineBidirectionalInfoRunsBuffer = logicalModel->mBidirectionalLineInfo.Begin(); @@ -471,8 +449,7 @@ bool AlignTest( const AlignData& data ) fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansArabicRegular.ttf" ); // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size layoutSize; @@ -491,11 +468,13 @@ bool AlignTest( const AlignData& data ) fontDescriptionRuns, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + // Call the Align method. Layout::Engine engine; engine.SetMetrics( metrics ); diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Shaping.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Shaping.cpp index 025dd54..2bdd217 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Shaping.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Shaping.cpp @@ -123,8 +123,7 @@ struct ShapeInfoData bool ShapeInfoTest( const ShapeInfoData& data ) { // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(100.f, 60.f); Size layoutSize; @@ -136,11 +135,13 @@ bool ShapeInfoTest( const ShapeInfoData& data ) data.fontDescriptions, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + // 2) Clear the model. Vector& glyphs = visualModel->mGlyphs; diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualModel.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualModel.cpp index c36fed6..df247e0 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualModel.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-VisualModel.cpp @@ -65,8 +65,7 @@ struct SetCharacterToGlyphData bool SetGlyphsPerCharacterTest( const SetGlyphsPerCharacterData& data ) { // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(100.f, 60.f); Size layoutSize; @@ -78,11 +77,13 @@ bool SetGlyphsPerCharacterTest( const SetGlyphsPerCharacterData& data ) fontDescriptions, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + Vector& charactersToGlyph = visualModel->mCharactersToGlyph; Vector& glyphsPerCharacter = visualModel->mGlyphsPerCharacter; @@ -148,8 +149,7 @@ bool SetGlyphsPerCharacterTest( const SetGlyphsPerCharacterData& data ) bool SetCharacterToGlyphTest( const SetCharacterToGlyphData& data ) { // 1) Create the model. - LogicalModelPtr logicalModel; - VisualModelPtr visualModel; + ModelPtr textModel; MetricsPtr metrics; Size textArea(100.f, 60.f); Size layoutSize; @@ -161,11 +161,13 @@ bool SetCharacterToGlyphTest( const SetCharacterToGlyphData& data ) fontDescriptions, options, layoutSize, - logicalModel, - visualModel, + textModel, metrics, false ); + LogicalModelPtr logicalModel = textModel->mLogicalModel; + VisualModelPtr visualModel = textModel->mVisualModel; + Vector& charactersToGlyph = visualModel->mCharactersToGlyph; Vector& glyphsPerCharacter = visualModel->mGlyphsPerCharacter; diff --git a/dali-toolkit/devel-api/text/text-utils-devel.cpp b/dali-toolkit/devel-api/text/text-utils-devel.cpp index eaab0e5..37b5847 100755 --- a/dali-toolkit/devel-api/text/text-utils-devel.cpp +++ b/dali-toolkit/devel-api/text/text-utils-devel.cpp @@ -32,14 +32,13 @@ #include #include #include -#include #include #include #include #include #include #include -#include +#include namespace Dali { @@ -133,20 +132,19 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, Vector blendingMode; ///< How embedded items and bitmap font glyphs are blended with color text. - Vector isEmoji; ///< Whether the glyph is an emoji. + Text::Layout::Engine layoutEngine; ///< The layout engine. + Text::ModelPtr textModel = Text::Model::New(); ///< Pointer to the text's model. + Vector blendingMode; ///< How embedded items and bitmap font glyphs are blended with color text. + Vector isEmoji; ///< Whether the glyph is an emoji. // Use this to access FontClient i.e. to get down-scaled Emoji metrics. metrics = Metrics::New( fontClient ); layoutEngine.SetMetrics( metrics ); - TextAbstraction::TextRenderer::Parameters rendererParameters( visualModel->mGlyphs, - visualModel->mGlyphPositions, - visualModel->mColors, - visualModel->mColorIndices, + TextAbstraction::TextRenderer::Parameters rendererParameters( textModel->mVisualModel->mGlyphs, + textModel->mVisualModel->mGlyphPositions, + textModel->mVisualModel->mColors, + textModel->mVisualModel->mColorIndices, blendingMode, isEmoji ); @@ -154,22 +152,22 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, Vector& utf32Characters = logicalModel->mText; // Characters encoded in utf32. - Vector mirroredUtf32Characters; // The utf32Characters Characters but mirrored if there are RTL text. - Vector& lineBreakInfo = logicalModel->mLineBreakInfo; // The line break info. - Vector& scripts = logicalModel->mScriptRuns; // Charactes's script. - Vector& fontDescriptionRuns = logicalModel->mFontDescriptionRuns; // Desired font descriptions. - Vector& validFonts = logicalModel->mFontRuns; // Validated fonts. - Vector& bidirectionalInfo = logicalModel->mBidirectionalParagraphInfo; // The bidirectional info per paragraph. - Vector& bidirectionalLineInfo = logicalModel->mBidirectionalLineInfo; // The bidirectional info per line. - Vector& directions = logicalModel->mCharacterDirections; // Character's directions. - Vector& colorRuns = logicalModel->mColorRuns; // colors of the text. - - Vector& glyphsToCharacters = visualModel->mGlyphsToCharacters; // Glyphs to character map. - Vector& charactersToGlyph = visualModel->mCharactersToGlyph; // Characters to glyphs map. - Vector& charactersPerGlyph = visualModel->mCharactersPerGlyph; // Number of characters per glyph. - Vector& glyphsPerCharacter = visualModel->mGlyphsPerCharacter; // The number of glyphs that are shaped. - Vector& lines = visualModel->mLines; // The laid out lines. + Vector& utf32Characters = textModel->mLogicalModel->mText; // Characters encoded in utf32. + Vector mirroredUtf32Characters; // The utf32Characters Characters but mirrored if there are RTL text. + Vector& lineBreakInfo = textModel->mLogicalModel->mLineBreakInfo; // The line break info. + Vector& scripts = textModel->mLogicalModel->mScriptRuns; // Charactes's script. + Vector& fontDescriptionRuns = textModel->mLogicalModel->mFontDescriptionRuns; // Desired font descriptions. + Vector& validFonts = textModel->mLogicalModel->mFontRuns; // Validated fonts. + Vector& bidirectionalInfo = textModel->mLogicalModel->mBidirectionalParagraphInfo; // The bidirectional info per paragraph. + //Vector& bidirectionalLineInfo = textModel->mLogicalModel->mBidirectionalLineInfo; // The bidirectional info per line. + Vector& directions = textModel->mLogicalModel->mCharacterDirections; // Character's directions. + Vector& colorRuns = textModel->mLogicalModel->mColorRuns; // colors of the text. + + Vector& glyphsToCharacters = textModel->mVisualModel->mGlyphsToCharacters; // Glyphs to character map. + Vector& charactersToGlyph = textModel->mVisualModel->mCharactersToGlyph; // Characters to glyphs map. + Vector& charactersPerGlyph = textModel->mVisualModel->mCharactersPerGlyph; // Number of characters per glyph. + Vector& glyphsPerCharacter = textModel->mVisualModel->mGlyphsPerCharacter; // The number of glyphs that are shaped. + Vector& lines = textModel->mVisualModel->mLines; // The laid out lines. Vector newParagraphGlyphs; // Glyphs for the new paragraph characters. @@ -189,7 +187,7 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, VectormEmbeddedItems ); + textModel->mLogicalModel->mEmbeddedItems ); if (textParameters.markupEnabled) { @@ -362,19 +360,19 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, VectorCreateGlyphsPerCharacterTable( 0u, 0u, numberOfCharacters ); - visualModel->CreateCharacterToGlyphTable( 0u, 0u, numberOfCharacters ); + textModel->mVisualModel->CreateGlyphsPerCharacterTable( 0u, 0u, numberOfCharacters ); + textModel->mVisualModel->CreateCharacterToGlyphTable( 0u, 0u, numberOfCharacters ); const Length numberOfGlyphs = rendererParameters.glyphs.Count(); // Once the text has been shaped and the glyphs created it's possible to replace the font id of those glyphs // that represent an image or an item and create the embedded item layout info. // Note: the position of the embedded item can't be set until the text is laid-out. - embeddedItemLayout.Reserve( logicalModel->mEmbeddedItems.Count() ); - for( const auto& item : logicalModel->mEmbeddedItems ) + embeddedItemLayout.Reserve( textModel->mLogicalModel->mEmbeddedItems.Count() ); + for( const auto& item : textModel->mLogicalModel->mEmbeddedItems ) { // Get the glyph that matches with the character index. - const GlyphIndex glyphIndex = visualModel->mCharactersToGlyph[item.characterIndex]; + const GlyphIndex glyphIndex = textModel->mVisualModel->mCharactersToGlyph[item.characterIndex]; GlyphInfo& glyph = rendererParameters.glyphs[glyphIndex]; glyph.fontId = 0u; @@ -421,11 +419,11 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, VectormColors, - visualModel->mColorIndices ); + textModel->mVisualModel->mColors, + textModel->mVisualModel->mColorIndices ); // Insert the default color at the beginning of the vector. - visualModel->mColors.Insert( visualModel->mColors.Begin(),textParameters.textColor ); + textModel->mVisualModel->mColors.Insert( textModel->mVisualModel->mColors.Begin(),textParameters.textColor ); // Set how the embedded items are blended with text color. blendingMode.Resize( numberOfGlyphs, textParameters.isTextColorSet ? ColorBlendingMode::MULTIPLY : ColorBlendingMode::NONE ); @@ -435,9 +433,9 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, VectormCharactersToGlyph[run.characterRun.characterIndex]; + const GlyphIndex firstGlyph = textModel->mVisualModel->mCharactersToGlyph[run.characterRun.characterIndex]; const CharacterIndex lastCharacter = run.characterRun.characterIndex + run.characterRun.numberOfCharacters - 1u; - const GlyphIndex lastGlyphPlusOne = visualModel->mCharactersToGlyph[lastCharacter] + visualModel->mGlyphsPerCharacter[lastCharacter]; + const GlyphIndex lastGlyphPlusOne = textModel->mVisualModel->mCharactersToGlyph[lastCharacter] + textModel->mVisualModel->mGlyphsPerCharacter[lastCharacter]; for( GlyphIndex index = firstGlyph; index < lastGlyphPlusOne; ++index ) { @@ -447,9 +445,9 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, VectormEmbeddedItems ) + for( const auto& item : textModel->mLogicalModel->mEmbeddedItems ) { - const GlyphIndex glyphIndex = visualModel->mCharactersToGlyph[item.characterIndex]; + const GlyphIndex glyphIndex = textModel->mVisualModel->mCharactersToGlyph[item.characterIndex]; blendingMode[glyphIndex] = item.colorBlendingMode; } @@ -463,9 +461,9 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, VectormCharactersToGlyph[run.characterRun.characterIndex]; + const GlyphIndex firstGlyph = textModel->mVisualModel->mCharactersToGlyph[run.characterRun.characterIndex]; const CharacterIndex lastCharacter = run.characterRun.characterIndex + run.characterRun.numberOfCharacters - 1u; - const GlyphIndex lastGlyphPlusOne = visualModel->mCharactersToGlyph[lastCharacter] + visualModel->mGlyphsPerCharacter[lastCharacter]; + const GlyphIndex lastGlyphPlusOne = textModel->mVisualModel->mCharactersToGlyph[lastCharacter] + textModel->mVisualModel->mGlyphsPerCharacter[lastCharacter]; for( GlyphIndex index = firstGlyph; index < lastGlyphPlusOne; ++index ) { @@ -560,22 +558,12 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, Vector( rendererParameters.radius ) ); } + textModel->mHorizontalAlignment = isCircularTextLayout ? horizontalCircularAlignment : horizontalAlignment; + textModel->mLineWrapMode = LineWrap::WORD; + textModel->mIgnoreSpacesAfterText = false; + textModel->mMatchSystemLanguageDirection = false; Text::Layout::Parameters layoutParameters( textLayoutArea, - textToShape.Begin(), - lineBreakInfo.Begin(), - nullptr, - ( 0u != directions.Count() ) ? directions.Begin() : nullptr, - rendererParameters.glyphs.Begin(), - glyphsToCharacters.Begin(), - charactersPerGlyph.Begin(), - charactersToGlyph.Begin(), - glyphsPerCharacter.Begin(), - numberOfGlyphs, - isCircularTextLayout ? horizontalCircularAlignment : horizontalAlignment, - LineWrap::WORD, - 0.f, - false, - false ); // Outline's width + textModel ); // Resize the vector of positions to have the same size than the vector of glyphs. rendererParameters.positions.Resize( numberOfGlyphs ); @@ -606,6 +594,7 @@ Devel::PixelBuffer Render( const RendererParameters& textParameters, Vector& bidirectionalLineInfo = textModel->mLogicalModel->mBidirectionalLineInfo; // Reorder the line. bidirectionalLineInfo.Reserve( 1u ); diff --git a/dali-toolkit/internal/text/layouts/layout-engine.cpp b/dali-toolkit/internal/text/layouts/layout-engine.cpp index 6e8be71..f4e11bf 100755 --- a/dali-toolkit/internal/text/layouts/layout-engine.cpp +++ b/dali-toolkit/internal/text/layouts/layout-engine.cpp @@ -50,7 +50,8 @@ namespace #endif const float MAX_FLOAT = std::numeric_limits::max(); -const bool RTL = true; +const CharacterDirection LTR = false; +const CharacterDirection RTL = !LTR; const float LINE_SPACING= 0.f; inline bool isEmptyLineAtLast( const Vector& lines, const Vector::Iterator& line ) @@ -196,8 +197,20 @@ struct Engine::Impl DALI_LOG_INFO( gLogFilter, Debug::Verbose, "-->GetLineLayoutForBox\n" ); DALI_LOG_INFO( gLogFilter, Debug::Verbose, " initial glyph index : %d\n", lineLayout.glyphIndex ); + const Character* const textBuffer = parameters.textModel->mLogicalModel->mText.Begin(); + const Length* const charactersPerGlyphBuffer = parameters.textModel->mVisualModel->mCharactersPerGlyph.Begin(); + const GlyphInfo* const glyphsBuffer = parameters.textModel->mVisualModel->mGlyphs.Begin(); + const CharacterIndex* const glyphsToCharactersBuffer = parameters.textModel->mVisualModel->mGlyphsToCharacters.Begin(); + const LineBreakInfo* const lineBreakInfoBuffer = parameters.textModel->mLogicalModel->mLineBreakInfo.Begin(); + + const bool hasBidiParagraphs = !parameters.textModel->mLogicalModel->mBidirectionalParagraphInfo.Empty(); + const CharacterDirection* const characterDirectionBuffer = hasBidiParagraphs ? parameters.textModel->mLogicalModel->mCharacterDirections.Begin() : nullptr; + + const float outlineWidth = static_cast( parameters.textModel->GetOutlineWidth() ); + const Length totalNumberOfGlyphs = parameters.textModel->mVisualModel->mGlyphs.Count(); + const bool isMultiline = mLayout == MULTI_LINE_BOX; - const bool isWordLaidOut = parameters.lineWrapMode == Text::LineWrap::WORD; + const bool isWordLaidOut = parameters.textModel->mLineWrapMode == Text::LineWrap::WORD; // The last glyph to be laid-out. const GlyphIndex lastGlyphOfParagraphPlusOne = parameters.startGlyphIndex + parameters.numberOfGlyphs; @@ -209,17 +222,17 @@ struct Engine::Impl // Check whether the first glyph comes from a character that is shaped in multiple glyphs. const Length numberOfGLyphsInGroup = GetNumberOfGlyphsOfGroup( lineLayout.glyphIndex, lastGlyphOfParagraphPlusOne, - parameters.charactersPerGlyphBuffer ); + charactersPerGlyphBuffer ); GlyphMetrics glyphMetrics; GetGlyphsMetrics( lineLayout.glyphIndex, numberOfGLyphsInGroup, glyphMetrics, - parameters.glyphsBuffer, + glyphsBuffer, mMetrics ); // Set the direction of the first character of the line. - lineLayout.characterIndex = *( parameters.glyphsToCharactersBuffer + lineLayout.glyphIndex ); + lineLayout.characterIndex = *( glyphsToCharactersBuffer + lineLayout.glyphIndex ); // Stores temporary line layout which has not been added to the final line layout. LineLayout tmpLineLayout; @@ -229,7 +242,7 @@ struct Engine::Impl // The initial start point is zero. However it needs a correction according the 'x' bearing of the first glyph. // i.e. if the bearing of the first glyph is negative it may exceed the boundaries of the text area. // It needs to add as well space for the cursor if the text is in edit mode and extra space in case the text is outlined. - tmpLineLayout.penX = -glyphMetrics.xBearing + mCursorWidth + parameters.outlineWidth; + tmpLineLayout.penX = -glyphMetrics.xBearing + mCursorWidth + outlineWidth; // Initialize the advance of the previous glyph. tmpLineLayout.previousAdvance = 0.f; @@ -248,16 +261,16 @@ struct Engine::Impl // Check whether this glyph comes from a character that is shaped in multiple glyphs. const Length numberOfGLyphsInGroup = GetNumberOfGlyphsOfGroup( glyphIndex, lastGlyphOfParagraphPlusOne, - parameters.charactersPerGlyphBuffer ); + charactersPerGlyphBuffer ); GlyphMetrics glyphMetrics; GetGlyphsMetrics( glyphIndex, numberOfGLyphsInGroup, glyphMetrics, - parameters.glyphsBuffer, + glyphsBuffer, mMetrics ); - const bool isLastGlyph = glyphIndex + numberOfGLyphsInGroup == parameters.totalNumberOfGlyphs; + const bool isLastGlyph = glyphIndex + numberOfGLyphsInGroup == totalNumberOfGlyphs; // Check if the font of the current glyph is the same of the previous one. // If it's different the ascender and descender need to be updated. @@ -270,13 +283,13 @@ struct Engine::Impl // Get the character indices for the current glyph. The last character index is needed // because there are glyphs formed by more than one character but their break info is // given only for the last character. - const Length charactersPerGlyph = *( parameters.charactersPerGlyphBuffer + glyphIndex + numberOfGLyphsInGroup - 1u ); + const Length charactersPerGlyph = *( charactersPerGlyphBuffer + glyphIndex + numberOfGLyphsInGroup - 1u ); const bool hasCharacters = charactersPerGlyph > 0u; - const CharacterIndex characterFirstIndex = *( parameters.glyphsToCharactersBuffer + glyphIndex ); + const CharacterIndex characterFirstIndex = *( glyphsToCharactersBuffer + glyphIndex ); const CharacterIndex characterLastIndex = characterFirstIndex + ( hasCharacters ? charactersPerGlyph - 1u : 0u ); // Get the line break info for the current character. - const LineBreakInfo lineBreakInfo = hasCharacters ? *( parameters.lineBreakInfoBuffer + characterLastIndex ) : TextAbstraction::LINE_NO_BREAK; + const LineBreakInfo lineBreakInfo = hasCharacters ? *( lineBreakInfoBuffer + characterLastIndex ) : TextAbstraction::LINE_NO_BREAK; // Increase the number of characters. tmpLineLayout.numberOfCharacters += charactersPerGlyph; @@ -285,7 +298,7 @@ struct Engine::Impl tmpLineLayout.numberOfGlyphs += numberOfGLyphsInGroup; // Check whether is a white space. - const Character character = *( parameters.textBuffer + characterFirstIndex ); + const Character character = *( textBuffer + characterFirstIndex ); const bool isWhiteSpace = TextAbstraction::IsWhiteSpace( character ); // Calculate the length of the line. @@ -353,9 +366,9 @@ struct Engine::Impl // Set the next paragraph's direction. if( !isLastGlyph && - ( NULL != parameters.characterDirectionBuffer ) ) + ( nullptr != characterDirectionBuffer ) ) { - paragraphDirection = *( parameters.characterDirectionBuffer + 1u + characterLastIndex ); + paragraphDirection = *( characterDirectionBuffer + 1u + characterLastIndex ); } DALI_LOG_INFO( gLogFilter, Debug::Verbose, " Must break\n" ); @@ -425,7 +438,7 @@ struct Engine::Impl Length& linesCapacity, bool updateCurrentBuffer ) { - LineRun* linesBuffer = NULL; + LineRun* linesBuffer = nullptr; // Reserve more space for the next lines. linesCapacity *= 2u; if( updateCurrentBuffer ) @@ -480,7 +493,7 @@ struct Engine::Impl // The last line needs to be completely filled with characters. // Part of a word may be used. - LineRun* lineRun = NULL; + LineRun* lineRun = nullptr; LineLayout ellipsisLayout; if( 0u != numberOfLines ) { @@ -514,7 +527,7 @@ struct Engine::Impl lineRun->extraLength = std::ceil( ellipsisLayout.wsLengthEndOfLine ); lineRun->ascender = ellipsisLayout.ascender; lineRun->descender = ellipsisLayout.descender; - lineRun->direction = !RTL; + lineRun->direction = LTR; lineRun->ellipsis = true; layoutSize.width = layoutParameters.boundingBox.width; @@ -523,9 +536,12 @@ struct Engine::Impl layoutSize.height += ( lineRun->ascender + -lineRun->descender ) + lineRun->lineSpacing; } - SetGlyphPositions( layoutParameters.glyphsBuffer + lineRun->glyphRun.glyphIndex, + const GlyphInfo* const glyphsBuffer = layoutParameters.textModel->mVisualModel->mGlyphs.Begin(); + const float outlineWidth = static_cast( layoutParameters.textModel->GetOutlineWidth() ); + + SetGlyphPositions( glyphsBuffer + lineRun->glyphRun.glyphIndex, ellipsisLayout.numberOfGlyphs, - layoutParameters.outlineWidth, + outlineWidth, layoutParameters.interGlyphExtraAdvance, glyphPositionsBuffer + lineRun->glyphRun.glyphIndex - layoutParameters.startGlyphIndex ); } @@ -586,7 +602,7 @@ struct Engine::Impl lineRun.ascender = layout.ascender; lineRun.descender = layout.descender; - lineRun.direction = !RTL; + lineRun.direction = LTR; lineRun.ellipsis = false; // Update the actual size. @@ -615,8 +631,10 @@ struct Engine::Impl LineRun* linesBuffer, Length& numberOfLines ) { + const Vector& glyphs = layoutParameters.textModel->mVisualModel->mGlyphs; + // Need to add a new line with no characters but with height to increase the layoutSize.height - const GlyphInfo& glyphInfo = *( layoutParameters.glyphsBuffer + layoutParameters.totalNumberOfGlyphs - 1u ); + const GlyphInfo& glyphInfo = glyphs[glyphs.Count() - 1u]; Text::FontMetrics fontMetrics; if( 0u != glyphInfo.fontId ) @@ -636,7 +654,7 @@ struct Engine::Impl lineRun.descender = fontMetrics.descender; lineRun.extraLength = 0.f; lineRun.alignmentOffset = 0.f; - lineRun.direction = !RTL; + lineRun.direction = LTR; lineRun.ellipsis = false; lineRun.lineSpacing = mDefaultLineSpacing; @@ -746,6 +764,7 @@ struct Engine::Impl } const GlyphIndex lastGlyphPlusOne = layoutParameters.startGlyphIndex + layoutParameters.numberOfGlyphs; + const Length totalNumberOfGlyphs = layoutParameters.textModel->mVisualModel->mGlyphs.Count(); // In a previous layout, an extra line with no characters may have been added if the text ended with a new paragraph character. // This extra line needs to be removed. @@ -754,22 +773,27 @@ struct Engine::Impl Vector::Iterator lastLine = lines.End() - 1u; if( ( 0u == lastLine->characterRun.numberOfCharacters ) && - ( lastGlyphPlusOne == layoutParameters.totalNumberOfGlyphs ) ) + ( lastGlyphPlusOne == totalNumberOfGlyphs ) ) { lines.Remove( lastLine ); } } + // Retrieve BiDi info. + const bool hasBidiParagraphs = !layoutParameters.textModel->mLogicalModel->mBidirectionalParagraphInfo.Empty(); + + const CharacterDirection* const characterDirectionBuffer = hasBidiParagraphs ? layoutParameters.textModel->mLogicalModel->mCharacterDirections.Begin() : nullptr; + // Set the first paragraph's direction. - CharacterDirection paragraphDirection = ( NULL != layoutParameters.characterDirectionBuffer ) ? *layoutParameters.characterDirectionBuffer : !RTL; + CharacterDirection paragraphDirection = ( nullptr != characterDirectionBuffer ) ? *characterDirectionBuffer : LTR; // Whether the layout is being updated or set from scratch. - const bool updateCurrentBuffer = layoutParameters.numberOfGlyphs < layoutParameters.totalNumberOfGlyphs; + const bool updateCurrentBuffer = layoutParameters.numberOfGlyphs < totalNumberOfGlyphs; - Vector2* glyphPositionsBuffer = NULL; + Vector2* glyphPositionsBuffer = nullptr; Vector newGlyphPositions; - LineRun* linesBuffer = NULL; + LineRun* linesBuffer = nullptr; Vector newLines; // Estimate the number of lines. @@ -792,9 +816,14 @@ struct Engine::Impl linesBuffer = lines.Begin(); } + + const GlyphInfo* const glyphsBuffer = layoutParameters.textModel->mVisualModel->mGlyphs.Begin(); + const float outlineWidth = static_cast( layoutParameters.textModel->GetOutlineWidth() ); + float penY = CalculateLineOffset( lines, layoutParameters.startLineIndex ); + for( GlyphIndex index = layoutParameters.startGlyphIndex; index < lastGlyphPlusOne; ) { CharacterDirection currentParagraphDirection = paragraphDirection; @@ -855,7 +884,7 @@ struct Engine::Impl else { // Whether the last line has been laid-out. - const bool isLastLine = index + layout.numberOfGlyphs == layoutParameters.totalNumberOfGlyphs; + const bool isLastLine = index + layout.numberOfGlyphs == totalNumberOfGlyphs; if( numberOfLines == linesCapacity ) { @@ -877,7 +906,7 @@ struct Engine::Impl const GlyphIndex nextIndex = index + layout.numberOfGlyphs; - if( ( nextIndex == layoutParameters.totalNumberOfGlyphs ) && + if( ( nextIndex == totalNumberOfGlyphs ) && layoutParameters.isLastNewParagraph && ( mLayout == MULTI_LINE_BOX ) ) { @@ -903,9 +932,9 @@ struct Engine::Impl } // whether to add a last line. // Sets the positions of the glyphs. - SetGlyphPositions( layoutParameters.glyphsBuffer + index, + SetGlyphPositions( glyphsBuffer + index, layout.numberOfGlyphs, - layoutParameters.outlineWidth, + outlineWidth, layoutParameters.interGlyphExtraAdvance, glyphPositionsBuffer + index - layoutParameters.startGlyphIndex ); @@ -922,7 +951,7 @@ struct Engine::Impl glyphPositions.Insert( glyphPositions.Begin() + layoutParameters.startGlyphIndex, newGlyphPositions.Begin(), newGlyphPositions.End() ); - glyphPositions.Resize( layoutParameters.totalNumberOfGlyphs ); + glyphPositions.Resize( totalNumberOfGlyphs ); newLines.Resize( numberOfLines ); @@ -968,6 +997,11 @@ struct Engine::Impl Length numberOfCharacters, Vector& glyphPositions ) { + const GlyphInfo* const glyphsBuffer = layoutParameters.textModel->mVisualModel->mGlyphs.Begin(); + const GlyphIndex* const charactersToGlyphsBuffer = layoutParameters.textModel->mVisualModel->mCharactersToGlyph.Begin(); + const Length* const glyphsPerCharacterBuffer = layoutParameters.textModel->mVisualModel->mGlyphsPerCharacter.Begin(); + const float outlineWidth = static_cast( layoutParameters.textModel->GetOutlineWidth() ); + const CharacterIndex lastCharacterIndex = startIndex + numberOfCharacters; // Traverses the paragraphs with right to left characters. @@ -988,9 +1022,9 @@ struct Engine::Impl } const CharacterIndex characterVisualIndex = bidiLine.characterRun.characterIndex + *bidiLine.visualToLogicalMap; - const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) ); + const GlyphInfo& glyph = *( glyphsBuffer + *( charactersToGlyphsBuffer + characterVisualIndex ) ); - float penX = -glyph.xBearing + layoutParameters.outlineWidth + mCursorWidth; + float penX = -glyph.xBearing + outlineWidth + mCursorWidth; Vector2* glyphPositionsBuffer = glyphPositions.Begin(); @@ -1003,16 +1037,16 @@ struct Engine::Impl const CharacterIndex characterVisualIndex = bidiLine.characterRun.characterIndex + *( bidiLine.visualToLogicalMap + characterLogicalIndex ); // Get the number of glyphs of the character. - const Length numberOfGlyphs = *( layoutParameters.glyphsPerCharacterBuffer + characterVisualIndex ); + const Length numberOfGlyphs = *( glyphsPerCharacterBuffer + characterVisualIndex ); for( GlyphIndex index = 0u; index < numberOfGlyphs; ++index ) { // Convert the character in the visual order into the glyph in the visual order. - const GlyphIndex glyphIndex = *( layoutParameters.charactersToGlyphsBuffer + characterVisualIndex ) + index; + const GlyphIndex glyphIndex = *( charactersToGlyphsBuffer + characterVisualIndex ) + index; - DALI_ASSERT_DEBUG( 0u <= glyphIndex && glyphIndex < layoutParameters.totalNumberOfGlyphs ); + DALI_ASSERT_DEBUG( 0u <= glyphIndex && glyphIndex < layoutParameters.textModel->mVisualModel->mGlyphs.Count() ); - const GlyphInfo& glyph = *( layoutParameters.glyphsBuffer + glyphIndex ); + const GlyphInfo& glyph = *( glyphsBuffer + glyphIndex ); Vector2& position = *( glyphPositionsBuffer + glyphIndex ); position.x = std::round( penX + glyph.xBearing ); @@ -1166,7 +1200,7 @@ struct Engine::Impl line.descender = 0.f; line.extraLength = 0.f; line.alignmentOffset = 0.f; - line.direction = !RTL; + line.direction = LTR; line.ellipsis = false; line.lineSpacing = mDefaultLineSpacing; } @@ -1179,7 +1213,7 @@ struct Engine::Impl }; Engine::Engine() -: mImpl( NULL ) +: mImpl( nullptr ) { mImpl = new Engine::Impl(); } diff --git a/dali-toolkit/internal/text/layouts/layout-parameters.h b/dali-toolkit/internal/text/layouts/layout-parameters.h index e877e64..b3aeaad 100755 --- a/dali-toolkit/internal/text/layouts/layout-parameters.h +++ b/dali-toolkit/internal/text/layouts/layout-parameters.h @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include #include +#include namespace Dali { @@ -48,86 +49,30 @@ struct Parameters * Constructor with the needed parameters to layout the text. * * @param[in] boundingBox The size of the box containing the text. - * @param[in] textBuffer The text buffer. - * @param[in] lineBreakInfoBuffer The line break info. - * @param[in] wordBreakInfoBuffer The word break info. - * @param[in] characterDirectionBuffer Vector with the direction of each character. - * @param[in] glyphsBuffer Vector with glyphs. - * @param[in] glyphsToCharactersBuffer Vector with indices pointing the first character of each glyph. - * @param[in] charactersPerGlyphBuffer Vector with the number of characters that forms each glyph. - * @param[in] charactersToGlyphsBuffer Vector with indices pointing the first glyph of each character. - * @param[in] glyphsPerCharacterBuffer Vector with the number of glyphs shaped from the character. - * @param[in] totalNumberOfGlyphs The number of glyphs. - * @param[in] horizontalAlignment The horizontal alignment. - * @param[in] lineWrapMode The text wrap mode. - * @param[in] outlineWidth The outline width. - * @param[in] ignoreSpaceAfterText Whether ignoring spaces after text or not. - * @param[in] matchSystemLanguageDirection Whether match align for system language direction or not.. + * @param[in,out] textModel The text's model. */ Parameters( const Vector2& boundingBox, - const Character* const textBuffer, - const LineBreakInfo* const lineBreakInfoBuffer, - const WordBreakInfo* const wordBreakInfoBuffer, - const CharacterDirection* const characterDirectionBuffer, - const GlyphInfo* const glyphsBuffer, - const CharacterIndex* const glyphsToCharactersBuffer, - const Length* const charactersPerGlyphBuffer, - const GlyphIndex* const charactersToGlyphsBuffer, - const Length* const glyphsPerCharacterBuffer, - Length totalNumberOfGlyphs, - Text::HorizontalAlignment::Type horizontalAlignment, - Text::LineWrap::Mode lineWrapMode, - float outlineWidth, - bool ignoreSpaceAfterText, - bool matchSystemLanguageDirection ) - : boundingBox( boundingBox ), - textBuffer( textBuffer ), - lineBreakInfoBuffer( lineBreakInfoBuffer ), - wordBreakInfoBuffer( wordBreakInfoBuffer ), - characterDirectionBuffer( characterDirectionBuffer ), - glyphsBuffer( glyphsBuffer ), - glyphsToCharactersBuffer( glyphsToCharactersBuffer ), - charactersPerGlyphBuffer( charactersPerGlyphBuffer ), - charactersToGlyphsBuffer( charactersToGlyphsBuffer ), - glyphsPerCharacterBuffer( glyphsPerCharacterBuffer ), - lineBidirectionalInfoRunsBuffer( NULL ), - numberOfBidirectionalInfoRuns( 0u ), - startGlyphIndex( 0u ), - numberOfGlyphs( 0u ), - totalNumberOfGlyphs( totalNumberOfGlyphs ), - horizontalAlignment( horizontalAlignment ), - startLineIndex( 0u ), - estimatedNumberOfLines( 0u ), - lineWrapMode( lineWrapMode ), - outlineWidth( outlineWidth ), - ignoreSpaceAfterText( ignoreSpaceAfterText ), - matchSystemLanguageDirection ( matchSystemLanguageDirection ), - interGlyphExtraAdvance( 0.f ), - isLastNewParagraph( false ) + ModelPtr textModel ) + : boundingBox{ boundingBox }, + textModel{ textModel }, + lineBidirectionalInfoRunsBuffer{ nullptr }, + numberOfBidirectionalInfoRuns{ 0u }, + startGlyphIndex{ 0u }, + numberOfGlyphs{ 0u }, + startLineIndex{ 0u }, + estimatedNumberOfLines{ 0u }, + interGlyphExtraAdvance{ 0.f }, + isLastNewParagraph{ false } {} Vector2 boundingBox; ///< The size of the box containing the text. - const Character* const textBuffer; ///< The text buffer. - const LineBreakInfo* const lineBreakInfoBuffer; ///< The line break info. - const WordBreakInfo* const wordBreakInfoBuffer; ///< The word break info. - const CharacterDirection* const characterDirectionBuffer; ///< Vector with the direction of each character. - const GlyphInfo* const glyphsBuffer; ///< Vector with glyphs. - const CharacterIndex* const glyphsToCharactersBuffer; ///< Vector with indices pointing the first character of each glyph. - const Length* const charactersPerGlyphBuffer; ///< Vector with the number of characters that forms each glyph. - const GlyphIndex* const charactersToGlyphsBuffer; ///< Vector with indices pointing the first glyph of each character. - const Length* const glyphsPerCharacterBuffer; ///< Vector with the number of glyphs shaped from the character. + ModelPtr textModel; BidirectionalLineInfoRun* lineBidirectionalInfoRunsBuffer; ///< Bidirectional conversion tables per line. Length numberOfBidirectionalInfoRuns; ///< The number of lines with bidirectional info. GlyphIndex startGlyphIndex; ///< Index to the first glyph to layout. Length numberOfGlyphs; ///< The number of glyphs to layout. - Length totalNumberOfGlyphs; ///< The number of glyphs. - HorizontalAlignment::Type horizontalAlignment; ///< The horizontal alignment. LineIndex startLineIndex; ///< The line index where to insert the new lines. Length estimatedNumberOfLines; ///< The estimated number of lines. - Text::LineWrap::Mode lineWrapMode; ///< The line wrap mode for moving to next line. - float outlineWidth; ///< The outline width. - bool ignoreSpaceAfterText:1; ///< Whether ignoring spaces after text or not. Default is true. - bool matchSystemLanguageDirection:1; ///< Whether match align for system language direction or not. Default is false. float interGlyphExtraAdvance; ///< Extra advance added to each glyph. bool isLastNewParagraph:1; ///< Whether the last character is a new paragraph character. }; diff --git a/dali-toolkit/internal/text/logical-model-impl.h b/dali-toolkit/internal/text/logical-model-impl.h index b2fc5a1..040444f 100755 --- a/dali-toolkit/internal/text/logical-model-impl.h +++ b/dali-toolkit/internal/text/logical-model-impl.h @@ -213,7 +213,6 @@ public: Vector mColorRuns; Vector mFontDescriptionRuns; Vector mLineBreakInfo; - Vector mWordBreakInfo; Vector mParagraphInfo; Vector mBidirectionalParagraphInfo; Vector mCharacterDirections; ///< For each character, whether is right to left. ( @e flase is left to right, @e true right to left ). diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index 2c9a78d..6908f04 100755 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -505,11 +505,6 @@ void Controller::Impl::ClearFullModelData( OperationsMask operations ) mModel->mLogicalModel->mParagraphInfo.Clear(); } - if( NO_OPERATION != ( GET_WORD_BREAKS & operations ) ) - { - mModel->mLogicalModel->mLineBreakInfo.Clear(); - } - if( NO_OPERATION != ( GET_SCRIPTS & operations ) ) { mModel->mLogicalModel->mScriptRuns.Clear(); @@ -584,15 +579,6 @@ void Controller::Impl::ClearCharacterModelData( CharacterIndex startIndex, Chara mModel->mLogicalModel->mParagraphInfo ); } - if( NO_OPERATION != ( GET_WORD_BREAKS & operations ) ) - { - // Clear the word break info. - WordBreakInfo* wordBreakInfoBuffer = mModel->mLogicalModel->mWordBreakInfo.Begin(); - - mModel->mLogicalModel->mWordBreakInfo.Erase( wordBreakInfoBuffer + startIndex, - wordBreakInfoBuffer + endIndexPlusOne ); - } - if( NO_OPERATION != ( GET_SCRIPTS & operations ) ) { // Clear the scripts. @@ -877,19 +863,6 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired ) updated = true; } - Vector& wordBreakInfo = mModel->mLogicalModel->mWordBreakInfo; - if( NO_OPERATION != ( GET_WORD_BREAKS & operations ) ) - { - // Retrieves the word break info. The word break info is used to layout the text (where to wrap the text in lines). - wordBreakInfo.Resize( numberOfCharacters, TextAbstraction::WORD_NO_BREAK ); - - SetWordBreakInfo( utf32Characters, - startIndex, - requestedNumberOfCharacters, - wordBreakInfo ); - updated = true; - } - const bool getScripts = NO_OPERATION != ( GET_SCRIPTS & operations ); const bool validateFonts = NO_OPERATION != ( VALIDATE_FONTS & operations ); diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 9f524dc..e660591 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -2045,7 +2045,6 @@ Vector3 Controller::GetNaturalSize() GET_SCRIPTS | VALIDATE_FONTS | GET_LINE_BREAKS | - GET_WORD_BREAKS | BIDI_INFO | SHAPE_TEXT | GET_GLYPH_METRICS ); @@ -2117,7 +2116,6 @@ bool Controller::CheckForTextFit( float pointSize, Size& layoutSize ) GET_SCRIPTS | VALIDATE_FONTS | GET_LINE_BREAKS | - GET_WORD_BREAKS | BIDI_INFO | SHAPE_TEXT| GET_GLYPH_METRICS ); @@ -2213,7 +2211,6 @@ float Controller::GetHeightForWidth( float width ) GET_SCRIPTS | VALIDATE_FONTS | GET_LINE_BREAKS | - GET_WORD_BREAKS | BIDI_INFO | SHAPE_TEXT | GET_GLYPH_METRICS ); @@ -2435,7 +2432,6 @@ Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection() GET_SCRIPTS | VALIDATE_FONTS | GET_LINE_BREAKS | - GET_WORD_BREAKS | BIDI_INFO | SHAPE_TEXT | GET_GLYPH_METRICS ); @@ -3829,32 +3825,11 @@ bool Controller::DoRelayout( const Size& size, return true; } - const Vector& lineBreakInfo = mImpl->mModel->mLogicalModel->mLineBreakInfo; - const Vector& wordBreakInfo = mImpl->mModel->mLogicalModel->mWordBreakInfo; - const Vector& characterDirection = mImpl->mModel->mLogicalModel->mCharacterDirections; - const Vector& glyphs = mImpl->mModel->mVisualModel->mGlyphs; - const Vector& glyphsToCharactersMap = mImpl->mModel->mVisualModel->mGlyphsToCharacters; - const Vector& charactersPerGlyph = mImpl->mModel->mVisualModel->mCharactersPerGlyph; const Character* const textBuffer = mImpl->mModel->mLogicalModel->mText.Begin(); - const float outlineWidth = static_cast( mImpl->mModel->GetOutlineWidth() ); // Set the layout parameters. Layout::Parameters layoutParameters( size, - textBuffer, - lineBreakInfo.Begin(), - wordBreakInfo.Begin(), - ( 0u != characterDirection.Count() ) ? characterDirection.Begin() : NULL, - glyphs.Begin(), - glyphsToCharactersMap.Begin(), - charactersPerGlyph.Begin(), - charactersToGlyphBuffer, - glyphsPerCharacterBuffer, - totalNumberOfGlyphs, - mImpl->mModel->mHorizontalAlignment, - mImpl->mModel->mLineWrapMode, - outlineWidth, - mImpl->mModel->mIgnoreSpacesAfterText, - mImpl->mModel->mMatchSystemLanguageDirection ); + mImpl->mModel ); // Resize the vector of positions to have the same size than the vector of glyphs. Vector& glyphPositions = mImpl->mModel->mVisualModel->mGlyphPositions; diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 18ff68e..3e2a50d 100755 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -74,16 +74,15 @@ public: // Enumerated types. GET_SCRIPTS = 0x0002, VALIDATE_FONTS = 0x0004, GET_LINE_BREAKS = 0x0008, - GET_WORD_BREAKS = 0x0010, - BIDI_INFO = 0x0020, - SHAPE_TEXT = 0x0040, - GET_GLYPH_METRICS = 0x0080, - LAYOUT = 0x0100, - UPDATE_LAYOUT_SIZE = 0x0200, - REORDER = 0x0400, - ALIGN = 0x0800, - COLOR = 0x1000, - UPDATE_DIRECTION = 0x2000, + BIDI_INFO = 0x0010, + SHAPE_TEXT = 0x0020, + GET_GLYPH_METRICS = 0x0040, + LAYOUT = 0x0080, + UPDATE_LAYOUT_SIZE = 0x0100, + REORDER = 0x0200, + ALIGN = 0x0400, + COLOR = 0x0800, + UPDATE_DIRECTION = 0x1000, ALL_OPERATIONS = 0xFFFF }; -- 2.7.4