X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fcursor-helper-functions.cpp;h=2379bcc3b93aed421ad02708d16fbb472a136ac8;hb=6c542cda6eb2ae887cb7a8a6c5d77e2f9659cbf7;hp=1df142c7c3ebe01873a6b8ac5e240a931f47ccef;hpb=2ca1c3856ce848a94f54444f1014a820e91ee207;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/cursor-helper-functions.cpp b/dali-toolkit/internal/text/cursor-helper-functions.cpp index 1df142c..2379bcc 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. @@ -155,9 +155,7 @@ LineIndex GetClosestLine(VisualModelPtr visualModel, { const LineRun& lineRun = *it; - // The line height is the addition of the line ascender and the line descender. - // However, the line descender has a negative value, hence the subtraction. - totalHeight += lineRun.ascender - lineRun.descender; + totalHeight += GetLineHeight(lineRun); if(visualY < totalHeight) { @@ -186,9 +184,7 @@ float CalculateLineOffset(const Vector& lines, { const LineRun& lineRun = *it; - // The line height is the addition of the line ascender and the line descender. - // However, the line descender has a negative value, hence the subtraction. - offset += lineRun.ascender - lineRun.descender; + offset += GetLineHeight(lineRun); } return offset; @@ -462,6 +458,7 @@ CharacterIndex GetClosestCursorIndex(VisualModelPtr visualModel, } void GetCursorPosition(GetCursorPositionParameters& parameters, + float defaultFontLineHeight, CursorInfo& cursorInfo) { const LineRun* const modelLines = parameters.visualModel->mLines.Begin(); @@ -483,6 +480,15 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, const LineIndex lineIndex = parameters.visualModel->GetLineOfCharacter(characterOfLine); const LineRun& line = *(modelLines + lineIndex); + const GlyphIndex* const charactersToGlyphBuffer = parameters.visualModel->mCharactersToGlyph.Begin(); + const Length* const glyphsPerCharacterBuffer = parameters.visualModel->mGlyphsPerCharacter.Begin(); + const GlyphInfo* const glyphInfoBuffer = parameters.visualModel->mGlyphs.Begin(); + 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. @@ -495,12 +501,20 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, cursorInfo.lineOffset = CalculateLineOffset(parameters.visualModel->mLines, newLineIndex); - // The line height is the addition of the line ascender and the line descender. - // However, the line descender has a negative value, hence the subtraction. - cursorInfo.lineHeight = newLine.ascender - newLine.descender; + cursorInfo.lineHeight = GetLineHeight(newLine); + + index = 0u; + const Length totalNumberOfCharacters = parameters.logicalModel->mText.Count(); + if(totalNumberOfCharacters > 0u) + { + index = totalNumberOfCharacters - 1u; + } + + GetGlyphMetricsFromCharacterIndex(index, glyphInfoBuffer, charactersToGlyphBuffer, glyphsPerCharacterBuffer, 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; @@ -543,13 +557,11 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, cursorInfo.lineOffset = CalculateLineOffset(parameters.visualModel->mLines, lineIndex); - // The line height is the addition of the line ascender and the line descender. - // However, the line descender has a negative value, hence the subtraction. - cursorInfo.lineHeight = line.ascender - line.descender; + cursorInfo.lineHeight = GetLineHeight(line); // 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. @@ -582,26 +594,14 @@ 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(); - // Convert the cursor position into the glyph position. - const GlyphIndex primaryGlyphIndex = *(charactersToGlyphBuffer + index); - const Length primaryNumberOfGlyphs = *(glyphsPerCharacterBuffer + index); + GetGlyphMetricsFromCharacterIndex(index, glyphInfoBuffer, charactersToGlyphBuffer, glyphsPerCharacterBuffer, metrics, glyphMetrics, glyphIndex, numberOfGlyphs); + 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. @@ -684,16 +684,9 @@ void GetCursorPosition(GetCursorPositionParameters& parameters, index = (isRightToLeftParagraph == isCurrentRightToLeft) ? nextCharacterIndex : characterIndex; } - const GlyphIndex secondaryGlyphIndex = *(charactersToGlyphBuffer + index); - const Length secondaryNumberOfGlyphs = *(glyphsPerCharacterBuffer + index); - - const Vector2& secondaryPosition = *(glyphPositionsBuffer + secondaryGlyphIndex); - - GetGlyphsMetrics(secondaryGlyphIndex, - secondaryNumberOfGlyphs, - glyphMetrics, - glyphInfoBuffer, - parameters.metrics); + GetGlyphMetricsFromCharacterIndex(index, glyphInfoBuffer, charactersToGlyphBuffer, glyphsPerCharacterBuffer, metrics, glyphMetrics, glyphIndex, numberOfGlyphs); + const GlyphIndex secondaryGlyphIndex = glyphIndex; + const Vector2& secondaryPosition = *(glyphPositionsBuffer + secondaryGlyphIndex); // Set the secondary cursor's position.