X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit-internal%2Fdali-toolkit-test-utils%2Ftoolkit-text-utils.cpp;h=701977d80d9473f07dd19e4cf68192a9bf198385;hp=e3ccad8b616026b1a332cd6d89fe22a8e95846b9;hb=fbd8d4da2506b57b46a71c5d113f4cb86f23c731;hpb=6e1032b5996011523338aa4bc5cdbeffcfc71ad5 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..701977d 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -32,6 +32,7 @@ #include #include #include +#include namespace Dali { @@ -79,7 +80,6 @@ void ClearModelData( CharacterIndex characterIndex, logicalModel->mScriptRuns.Clear(); logicalModel->mFontRuns.Clear(); - logicalModel->mWordBreakInfo.Clear(); logicalModel->mBidirectionalParagraphInfo.Clear(); logicalModel->mCharacterDirections.Clear(); logicalModel->mBidirectionalLineInfo.Clear(); @@ -99,17 +99,23 @@ void CreateTextModel( const std::string& text, const Vector& fontDescriptions, const LayoutOptions& options, Size& layoutSize, - LogicalModelPtr& logicalModel, - VisualModelPtr& visualModel, + ModelPtr& textModel, MetricsPtr& metrics, - bool markupProcessorEnabled ) + bool markupProcessorEnabled, + LineWrap::Mode wrapMode, + bool ellipsisEnabled, + DevelText::EllipsisPosition::Type ellipsisPosition) { - 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, - logicalModel->mEmbeddedItems ); + logicalModel->mEmbeddedItems, + logicalModel->mAnchors, + logicalModel->mUnderlinedCharacterRuns, + logicalModel->mBackgroundColorRuns); Length textSize = 0u; const uint8_t* utf8 = NULL; @@ -129,6 +135,12 @@ void CreateTextModel( const std::string& text, utf8 = reinterpret_cast( text.c_str() ); } + //Ellipsis + textModel-> mElideEnabled = ellipsisEnabled; + textModel-> mVisualModel->SetTextElideEnabled(ellipsisEnabled); + textModel-> mEllipsisPosition = ellipsisPosition; + textModel-> mVisualModel->SetEllipsisPosition(ellipsisPosition); + // 1) Convert to utf32 Vector& utf32Characters = logicalModel->mText; utf32Characters.Resize( textSize ); @@ -153,14 +165,40 @@ 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 ); + textModel->mLineWrapMode = wrapMode; - SetWordBreakInfo( utf32Characters, - 0u, - characterCount, - wordBreakInfo ); + if(textModel->mLineWrapMode == ((Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION) || + textModel->mLineWrapMode == ((Text::LineWrap::Mode)DevelText::LineWrap::MIXED)) + { + CharacterIndex end = characterCount; + LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin(); + + for(CharacterIndex index = 0; index < end; index++) + { + CharacterIndex wordEnd = index; + while((*(lineBreakInfoBuffer + wordEnd) != TextAbstraction::LINE_ALLOW_BREAK) && (*(lineBreakInfoBuffer + wordEnd) != TextAbstraction::LINE_MUST_BREAK)) + { + wordEnd++; + } + + if((wordEnd + 1) == end) // add last char + { + wordEnd++; + } + + Vector hyphens = GetWordHyphens(utf32Characters.Begin() + index, wordEnd - index, nullptr); + + for(CharacterIndex i = 0; i < (wordEnd - index); i++) + { + if(hyphens[i]) + { + *(lineBreakInfoBuffer + index + i) = TextAbstraction::LINE_HYPHENATION_BREAK; + } + } + + index = wordEnd; + } + } // 3) Set the script info. MultilanguageSupport multilanguageSupport = MultilanguageSupport::Get(); @@ -291,25 +329,10 @@ 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->mIgnoreSpacesAfterText = true; 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; @@ -326,41 +349,10 @@ void CreateTextModel( const std::string& text, bool isAutoScroll = false; layoutEngine.LayoutText( layoutParameters, - glyphPositions, - lines, layoutSize, false, - isAutoScroll ); - - // 10) Reorder the lines - if( 0u != bidirectionalInfo.Count() ) - { - Vector& bidirectionalLineInfo = logicalModel->mBidirectionalLineInfo; - - // Get the lines - const Length numberOfLines = lines.Count(); - - // Reorder the lines. - bidirectionalLineInfo.Reserve( numberOfLines ); // Reserve because is not known yet how many lines have right to left characters. - ReorderLines( bidirectionalInfo, - 0u, - characterCount, - lines, - bidirectionalLineInfo ); - - // Set the bidirectional info per line into the layout parameters. - layoutParameters.lineBidirectionalInfoRunsBuffer = bidirectionalLineInfo.Begin(); - layoutParameters.numberOfBidirectionalInfoRuns = bidirectionalLineInfo.Count(); - - if( options.reorder ) - { - // Re-layout the text. Reorder those lines with right to left characters. - layoutEngine.ReLayoutRightToLeftLines( layoutParameters, - 0u, - characterCount, - glyphPositions ); - } - } + isAutoScroll, + ellipsisPosition); if( options.align ) { @@ -399,6 +391,9 @@ void ConfigureTextLabel( ControllerPtr controller ) // Enable the text elide. controller->SetTextElideEnabled( true ); + + // Disable match system language direction + controller->SetMatchLayoutDirection(DevelText::MatchLayoutDirection::CONTENTS); } void ConfigureTextField( ControllerPtr controller ) @@ -428,6 +423,9 @@ void ConfigureTextField( ControllerPtr controller ) // Disable the text elide. controller->SetTextElideEnabled( false ); + + // Disable match system language direction + controller->SetMatchLayoutDirection(DevelText::MatchLayoutDirection::CONTENTS); } void ConfigureTextEditor( ControllerPtr controller ) @@ -457,6 +455,50 @@ void ConfigureTextEditor( ControllerPtr controller ) // Disable the text elide. controller->SetTextElideEnabled( false ); + + // Disable match system language direction + controller->SetMatchLayoutDirection(DevelText::MatchLayoutDirection::CONTENTS); +} + + +Vector CreateSingleFontDescription( + const CharacterRun& characterRun, + const std::string fontFamilyName, + const FontWeight weight, + const FontWidth width, + const FontSlant slant, + const PointSize26Dot6 size, + const bool familyDefined, + const bool weightDefined, + const bool widthDefined, + const bool slantDefined, + const bool sizeDefined) +{ + + FontDescriptionRun fontDescriptionRun = + { + characterRun, + nullptr, + 0u, + weight, + width, + slant, + size, + familyDefined, + weightDefined, + widthDefined, + slantDefined, + sizeDefined + }; + + fontDescriptionRun.familyLength = fontFamilyName.size(); + fontDescriptionRun.familyName = new char[fontDescriptionRun.familyLength]; + memcpy( fontDescriptionRun.familyName, fontFamilyName.c_str(), fontDescriptionRun.familyLength ); + + Vector fontDescriptionRuns; + fontDescriptionRuns.PushBack(fontDescriptionRun); + + return fontDescriptionRuns; } } // namespace Text