X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller-impl.cpp;h=47877c487090e25e61bd10a3b0e29bcc35f56d85;hp=f287daf84cc80827c1434efa9d84f9b3d670631c;hb=750fadba87bb959c9af32e89e3f1bc7af6cb6dd2;hpb=478e477e07fde916953748d2cd4befc0326bfc34 diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index f287daf..47877c4 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -22,11 +22,13 @@ #include #include #include +#include #include // INTERNAL INCLUDES #include #include +#include #include #include #include @@ -37,6 +39,7 @@ #include #include #include +#include using namespace Dali; @@ -359,6 +362,27 @@ void ChangeTextControllerState(Controller::Impl& impl, EventData::State newState } } +void UpdateCursorPositionForAlignment(Controller::Impl& impl, bool needFullAlignment) +{ + EventData* eventData = impl.mEventData; + + // Set the flag to redo the alignment operation + impl.mOperationsPending = static_cast(impl.mOperationsPending | Controller::OperationsMask::ALIGN); + + if(eventData) + { + // Note: mUpdateAlignment is currently only needed for horizontal alignment + eventData->mUpdateAlignment = needFullAlignment; + + // Update the cursor if it's in editing mode + if(EventData::IsEditingState(eventData->mState)) + { + impl.ChangeState(EventData::EDITING); + eventData->mUpdateCursorPosition = true; + } + } +} + } // unnamed Namespace EventData::EventData(DecoratorPtr decorator, InputMethodContext& inputMethodContext) @@ -516,7 +540,8 @@ Dali::LayoutDirection::Type Controller::Impl::GetLayoutDirection(Dali::Actor& ac if(mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::LOCALE || (mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::INHERIT && !mIsLayoutDirectionChanged)) { - return static_cast(DevelWindow::Get(actor).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get()); + Window window = DevelWindow::Get(actor); + return static_cast(window ? window.GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get() : LayoutDirection::LEFT_TO_RIGHT); } else { @@ -672,11 +697,11 @@ float Controller::Impl::GetDefaultFontLineHeight() if(nullptr == mFontDefaults) { TextAbstraction::FontDescription fontDescription; - defaultFontId = mFontClient.GetFontId(fontDescription, TextAbstraction::FontClient::DEFAULT_POINT_SIZE * mFontSizeScale); + defaultFontId = mFontClient.GetFontId(fontDescription, TextAbstraction::FontClient::DEFAULT_POINT_SIZE * GetFontSizeScale()); } else { - defaultFontId = mFontDefaults->GetFontId(mFontClient, mFontDefaults->mDefaultPointSize * mFontSizeScale); + defaultFontId = mFontDefaults->GetFontId(mFontClient, mFontDefaults->mDefaultPointSize * GetFontSizeScale()); } Text::FontMetrics fontMetrics; @@ -691,7 +716,7 @@ bool Controller::Impl::SetDefaultLineSpacing(float lineSpacing) { mLayoutEngine.SetDefaultLineSpacing(lineSpacing); - RelayoutForNewLineSize(); + RelayoutAllCharacters(); return true; } return false; @@ -703,12 +728,29 @@ bool Controller::Impl::SetDefaultLineSize(float lineSize) { mLayoutEngine.SetDefaultLineSize(lineSize); - RelayoutForNewLineSize(); + RelayoutAllCharacters(); + return true; + } + return false; +} + +bool Controller::Impl::SetRelativeLineSize(float relativeLineSize) +{ + if(std::fabs(relativeLineSize - GetRelativeLineSize()) > Math::MACHINE_EPSILON_1000) + { + mLayoutEngine.SetRelativeLineSize(relativeLineSize); + + RelayoutAllCharacters(); return true; } return false; } +float Controller::Impl::GetRelativeLineSize() +{ + return mLayoutEngine.GetRelativeLineSize(); +} + string Controller::Impl::GetSelectedText() { string text; @@ -889,7 +931,8 @@ void Controller::Impl::SetEditable(bool editable) if(mEventData->mDecorator) { - mEventData->mDecorator->SetEditable(editable); + bool decoratorEditable = editable && mIsUserInteractionEnabled; + mEventData->mDecorator->SetEditable(decoratorEditable); } } } @@ -1195,7 +1238,10 @@ void Controller::Impl::GetCursorPosition(CharacterIndex logical, parameters.logical = logical; parameters.isMultiline = isMultiLine; + float defaultFontLineHeight = GetDefaultFontLineHeight(); + Text::GetCursorPosition(parameters, + defaultFontLineHeight, cursorInfo); // Adds Outline offset. @@ -1416,6 +1462,10 @@ void Controller::Impl::ScrollToMakePositionVisible(const Vector2& position, floa { mModel->mScrollPosition.y = mModel->mVisualModel->mControlSize.height - positionEndY; } + else if(mModel->mLogicalModel->mText.Count() == 0u) + { + Relayouter::CalculateVerticalOffset(*this, mModel->mVisualModel->mControlSize); + } } } @@ -1458,7 +1508,7 @@ void Controller::Impl::RequestRelayout() } } -void Controller::Impl::RelayoutForNewLineSize() +void Controller::Impl::RelayoutAllCharacters() { // relayout all characters mTextUpdateInfo.mCharacterIndex = 0; @@ -1613,13 +1663,92 @@ void Controller::Impl::CopyUnderlinedFromLogicalToVisualModels(bool shouldClearP { CharacterIndex characterIndex = it->characterRun.characterIndex; Length numberOfCharacters = it->characterRun.numberOfCharacters; - for(Length index = 0u; index < numberOfCharacters; index++) + + if(numberOfCharacters == 0) + { + continue; + } + + // Create one run for all glyphs of all run's characters that has same properties + // This enhance performance and reduce the needed memory to store glyphs-runs + UnderlinedGlyphRun underlineGlyphRun; + underlineGlyphRun.glyphRun.glyphIndex = charactersToGlyph[characterIndex]; + underlineGlyphRun.glyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex]; + //Copy properties (attributes) + underlineGlyphRun.properties = it->properties; + + for(Length index = 1u; index < numberOfCharacters; index++) { - GlyphRun underlineGlyphRun; - underlineGlyphRun.glyphIndex = charactersToGlyph[characterIndex + index]; - underlineGlyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex + index]; - mModel->mVisualModel->mUnderlineRuns.PushBack(underlineGlyphRun); + underlineGlyphRun.glyphRun.numberOfGlyphs += glyphsPerCharacter[characterIndex + index]; } + + mModel->mVisualModel->mUnderlineRuns.PushBack(underlineGlyphRun); + } +} + +void Controller::Impl::CopyStrikethroughFromLogicalToVisualModels() +{ + //Strikethrough character runs from markup-processor + const Vector& strikethroughCharacterRuns = mModel->mLogicalModel->mStrikethroughCharacterRuns; + const Vector& charactersToGlyph = mModel->mVisualModel->mCharactersToGlyph; + const Vector& glyphsPerCharacter = mModel->mVisualModel->mGlyphsPerCharacter; + + mModel->mVisualModel->mStrikethroughRuns.Clear(); + + for(Vector::ConstIterator it = strikethroughCharacterRuns.Begin(), endIt = strikethroughCharacterRuns.End(); it != endIt; ++it) + { + CharacterIndex characterIndex = it->characterRun.characterIndex; + Length numberOfCharacters = it->characterRun.numberOfCharacters; + + if(numberOfCharacters == 0) + { + continue; + } + + StrikethroughGlyphRun strikethroughGlyphRun; + strikethroughGlyphRun.properties = it->properties; + strikethroughGlyphRun.glyphRun.glyphIndex = charactersToGlyph[characterIndex]; + strikethroughGlyphRun.glyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex]; + + for(Length index = 1u; index < numberOfCharacters; index++) + { + strikethroughGlyphRun.glyphRun.numberOfGlyphs += glyphsPerCharacter[characterIndex + index]; + } + + mModel->mVisualModel->mStrikethroughRuns.PushBack(strikethroughGlyphRun); + } +} + +void Controller::Impl::CopyCharacterSpacingFromLogicalToVisualModels() +{ + //CharacterSpacing character runs from markup-processor + const Vector& characterSpacingCharacterRuns = mModel->mLogicalModel->mCharacterSpacingCharacterRuns; + const Vector& charactersToGlyph = mModel->mVisualModel->mCharactersToGlyph; + const Vector& glyphsPerCharacter = mModel->mVisualModel->mGlyphsPerCharacter; + + mModel->mVisualModel->mCharacterSpacingRuns.Clear(); + + for(Vector::ConstIterator it = characterSpacingCharacterRuns.Begin(), endIt = characterSpacingCharacterRuns.End(); it != endIt; ++it) + { + const CharacterIndex& characterIndex = it->characterRun.characterIndex; + const Length& numberOfCharacters = it->characterRun.numberOfCharacters; + + if(numberOfCharacters == 0) + { + continue; + } + + CharacterSpacingGlyphRun characterSpacingGlyphRun; + characterSpacingGlyphRun.value = it->value; + characterSpacingGlyphRun.glyphRun.glyphIndex = charactersToGlyph[characterIndex]; + characterSpacingGlyphRun.glyphRun.numberOfGlyphs = glyphsPerCharacter[characterIndex]; + + for(Length index = 1u; index < numberOfCharacters; index++) + { + characterSpacingGlyphRun.glyphRun.numberOfGlyphs += glyphsPerCharacter[characterIndex + index]; + } + + mModel->mVisualModel->mCharacterSpacingRuns.PushBack(characterSpacingGlyphRun); } } @@ -1699,22 +1828,7 @@ void Controller::Impl::SetHorizontalAlignment(Text::HorizontalAlignment::Type al { // Set the alignment. mModel->mHorizontalAlignment = alignment; - - // Set the flag to redo the alignment operation. - mOperationsPending = static_cast(mOperationsPending | ALIGN); - - if(mEventData) - { - mEventData->mUpdateAlignment = true; - - // Update the cursor if it's in editing mode - if(EventData::IsEditingState(mEventData->mState)) - { - ChangeState(EventData::EDITING); - mEventData->mUpdateCursorPosition = true; - } - } - + UpdateCursorPositionForAlignment(*this, true); RequestRelayout(); } } @@ -1725,7 +1839,7 @@ void Controller::Impl::SetVerticalAlignment(VerticalAlignment::Type alignment) { // Set the alignment. mModel->mVerticalAlignment = alignment; - mOperationsPending = static_cast(mOperationsPending | ALIGN); + UpdateCursorPositionForAlignment(*this, false); RequestRelayout(); } } @@ -1772,6 +1886,17 @@ void Controller::Impl::SetDefaultColor(const Vector4& color) } } +void Controller::Impl::SetUserInteractionEnabled(bool enabled) +{ + mIsUserInteractionEnabled = enabled; + + if(mEventData && mEventData->mDecorator) + { + bool editable = mEventData->mEditingEnabled && enabled; + mEventData->mDecorator->SetEditable(editable); + } +} + void Controller::Impl::ClearFontData() { if(mFontDefaults) @@ -1803,6 +1928,7 @@ void Controller::Impl::ClearStyleData() { mModel->mLogicalModel->mColorRuns.Clear(); mModel->mLogicalModel->ClearFontDescriptionRuns(); + mModel->mLogicalModel->ClearStrikethroughRuns(); } void Controller::Impl::ResetScrollPosition()