X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fcursor-helper-functions.cpp;h=c70d530c3577705f43dc6f7f67737db33213b349;hp=c2d35d9be5e1731d64384d027632ec637c2a4fba;hb=2512aa2794f3c5ea5841542b9ed9c8c32973540b;hpb=17655f69059d8b9f766f350501b3f1ba5efb7231 diff --git a/dali-toolkit/internal/text/cursor-helper-functions.cpp b/dali-toolkit/internal/text/cursor-helper-functions.cpp index c2d35d9..c70d530 100644 --- a/dali-toolkit/internal/text/cursor-helper-functions.cpp +++ b/dali-toolkit/internal/text/cursor-helper-functions.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. @@ -212,6 +212,7 @@ CharacterIndex GetClosestCursorIndex(VisualModelPtr visualModel, { return logicalIndex; } + const float characterSpacing = visualModel->GetCharacterSpacing(); // Whether there is a hit on a line. bool matchedLine = false; @@ -262,8 +263,11 @@ CharacterIndex GetClosestCursorIndex(VisualModelPtr visualModel, bool isBeforeFirstGlyph = false; // Traverses glyphs in visual order. To do that use the visual to logical conversion table. - CharacterIndex visualIndex = startCharacter; - Length numberOfVisualCharacters = 0; + CharacterIndex visualIndex = startCharacter; + Length numberOfVisualCharacters = 0; + float calculatedAdvance = 0.f; + Vector& glyphToCharacterMap = visualModel->mGlyphsToCharacters; + const CharacterIndex* glyphToCharacterMapBuffer = glyphToCharacterMap.Begin(); for(; visualIndex < endCharacter; ++visualIndex) { // The character in logical order. @@ -283,11 +287,13 @@ CharacterIndex GetClosestCursorIndex(VisualModelPtr visualModel, // Get the metrics for the group of glyphs. GlyphMetrics glyphMetrics; + calculatedAdvance = GetCalculatedAdvance(*(logicalModel->mText.Begin() + (*(glyphToCharacterMapBuffer + firstLogicalGlyphIndex))), characterSpacing, (*(visualModel->mGlyphs.Begin() + firstLogicalGlyphIndex)).advance); GetGlyphsMetrics(firstLogicalGlyphIndex, numberOfGlyphs, glyphMetrics, glyphInfoBuffer, - metrics); + metrics, + calculatedAdvance); // Get the position of the first glyph. const Vector2& position = *(positionsBuffer + firstLogicalGlyphIndex); @@ -458,6 +464,7 @@ CharacterIndex GetClosestCursorIndex(VisualModelPtr visualModel, } void GetCursorPosition(GetCursorPositionParameters& parameters, + float defaultFontLineHeight, CursorInfo& cursorInfo) { const LineRun* const modelLines = parameters.visualModel->mLines.Begin(); @@ -479,6 +486,12 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, const LineIndex lineIndex = parameters.visualModel->GetLineOfCharacter(characterOfLine); const LineRun& line = *(modelLines + lineIndex); + CharacterIndex index; + GlyphMetrics glyphMetrics; + MetricsPtr& metrics = parameters.metrics; + GlyphIndex glyphIndex = 0u; + Length numberOfGlyphs = 0u; + if(isLastNewParagraph) { // The cursor is in a new line with no characters. Place the cursor in that line. @@ -493,8 +506,18 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, cursorInfo.lineHeight = GetLineHeight(newLine); + index = 0u; + const Length totalNumberOfCharacters = parameters.logicalModel->mText.Count(); + if(totalNumberOfCharacters > 0u) + { + index = totalNumberOfCharacters - 1u; + } + + GetGlyphMetricsFromCharacterIndex(index, parameters.visualModel, parameters.logicalModel, metrics, glyphMetrics, glyphIndex, numberOfGlyphs); + // Set the primary cursor's height. - cursorInfo.primaryCursorHeight = cursorInfo.lineHeight; + // The primary cursor height will take the font height of the last character and if there are no characters, it'll take the default font line height. + cursorInfo.primaryCursorHeight = (totalNumberOfCharacters > 0) ? (cursorInfo.isSecondaryCursor ? 0.5f * glyphMetrics.fontHeight : glyphMetrics.fontHeight) : defaultFontLineHeight; // Set the primary cursor's position. cursorInfo.primaryPosition.x = (LTR == line.direction) ? newLine.alignmentOffset : parameters.visualModel->mControlSize.width - newLine.alignmentOffset; @@ -541,7 +564,7 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, // Calculate the primary cursor. - CharacterIndex index = characterIndex; + index = characterIndex; if(cursorInfo.isSecondaryCursor) { // If there is a secondary position, the primary cursor may be in a different place than the logical index. @@ -574,26 +597,18 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, } } - const GlyphIndex* const charactersToGlyphBuffer = parameters.visualModel->mCharactersToGlyph.Begin(); - const Length* const glyphsPerCharacterBuffer = parameters.visualModel->mGlyphsPerCharacter.Begin(); const Length* const charactersPerGlyphBuffer = parameters.visualModel->mCharactersPerGlyph.Begin(); const CharacterIndex* const glyphsToCharactersBuffer = parameters.visualModel->mGlyphsToCharacters.Begin(); const Vector2* const glyphPositionsBuffer = parameters.visualModel->mGlyphPositions.Begin(); - const GlyphInfo* const glyphInfoBuffer = parameters.visualModel->mGlyphs.Begin(); + const float characterSpacing = parameters.visualModel->GetCharacterSpacing(); + + // Get the metrics for the group of glyphs. + GetGlyphMetricsFromCharacterIndex(index, parameters.visualModel, parameters.logicalModel, metrics, glyphMetrics, glyphIndex, numberOfGlyphs); // Convert the cursor position into the glyph position. - const GlyphIndex primaryGlyphIndex = *(charactersToGlyphBuffer + index); - const Length primaryNumberOfGlyphs = *(glyphsPerCharacterBuffer + index); + const GlyphIndex primaryGlyphIndex = glyphIndex; const Length primaryNumberOfCharacters = *(charactersPerGlyphBuffer + primaryGlyphIndex); - // Get the metrics for the group of glyphs. - GlyphMetrics glyphMetrics; - GetGlyphsMetrics(primaryGlyphIndex, - primaryNumberOfGlyphs, - glyphMetrics, - glyphInfoBuffer, - parameters.metrics); - // Whether to add the glyph's advance to the cursor position. // i.e if the paragraph is left to right and the logical cursor is zero, the position is the position of the first glyph and the advance is not added, // if the logical cursor is one, the position is the position of the first glyph and the advance is added. @@ -628,7 +643,7 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, (isFirstPositionOfLine && isRightToLeftParagraph) || (!isFirstPositionOfLine && !isLastPosition && !isCurrentRightToLeft)); - float glyphAdvance = addGlyphAdvance ? glyphMetrics.advance : 0.f; + float glyphAdvance = addGlyphAdvance ? (glyphMetrics.advance) : 0.f; if(!isLastPositionOfLine && (primaryNumberOfCharacters > 1u)) @@ -647,7 +662,7 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, numberOfGlyphAdvance = primaryNumberOfCharacters - numberOfGlyphAdvance; } - glyphAdvance = static_cast(numberOfGlyphAdvance) * glyphMetrics.advance / static_cast(primaryNumberOfCharacters); + glyphAdvance = static_cast(numberOfGlyphAdvance) * (glyphMetrics.advance) / static_cast(primaryNumberOfCharacters); } // Get the glyph position and x bearing (in the line's coords). @@ -676,16 +691,10 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, index = (isRightToLeftParagraph == isCurrentRightToLeft) ? nextCharacterIndex : characterIndex; } - const GlyphIndex secondaryGlyphIndex = *(charactersToGlyphBuffer + index); - const Length secondaryNumberOfGlyphs = *(glyphsPerCharacterBuffer + index); + GetGlyphMetricsFromCharacterIndex(index, parameters.visualModel, parameters.logicalModel, metrics, glyphMetrics, glyphIndex, numberOfGlyphs); - const Vector2& secondaryPosition = *(glyphPositionsBuffer + secondaryGlyphIndex); - - GetGlyphsMetrics(secondaryGlyphIndex, - secondaryNumberOfGlyphs, - glyphMetrics, - glyphInfoBuffer, - parameters.metrics); + const GlyphIndex secondaryGlyphIndex = glyphIndex; + const Vector2& secondaryPosition = *(glyphPositionsBuffer + secondaryGlyphIndex); // Set the secondary cursor's position. @@ -708,7 +717,7 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, const bool addGlyphAdvance = ((!isFirstPositionOfLine && !isCurrentRightToLeft) || (isFirstPositionOfLine && !isRightToLeftParagraph)); - cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + (addGlyphAdvance ? glyphMetrics.advance : 0.f); + cursorInfo.secondaryPosition.x = -glyphMetrics.xBearing + secondaryPosition.x + (addGlyphAdvance ? (glyphMetrics.advance + characterSpacing) : 0.f); cursorInfo.secondaryPosition.y = cursorInfo.lineOffset + cursorInfo.lineHeight - cursorInfo.secondaryCursorHeight; // Transform the cursor info from line's coords to text's coords.