From 8d92a2cdf4665c1831b524af0a316208947e27c1 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Thu, 14 Jul 2016 09:29:28 +0100 Subject: [PATCH] Fix for the cursor position with the arabic script. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * This is a workaround to fix an issue with complex characters in the arabic script like i.e. رّ or الأَبْجَدِيَّة العَرَبِيَّة. A proper fix needs to be done in order to be able to place the cursor correctly in all characters. Change-Id: I22ba797b6487c3ca11bdb15fdd0168d16810ba15 Signed-off-by: Victor Cebollada --- .../internal/text/cursor-helper-functions.cpp | 45 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/dali-toolkit/internal/text/cursor-helper-functions.cpp b/dali-toolkit/internal/text/cursor-helper-functions.cpp index 2b5e328..b3b7250 100644 --- a/dali-toolkit/internal/text/cursor-helper-functions.cpp +++ b/dali-toolkit/internal/text/cursor-helper-functions.cpp @@ -107,10 +107,10 @@ CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel, CharacterIndex logicalIndex = 0u; - const Length numberOfGlyphs = visualModel->mGlyphs.Count(); - const Length numberOfLines = visualModel->mLines.Count(); - if( ( 0 == numberOfGlyphs ) || - ( 0 == numberOfLines ) ) + const Length totalNumberOfGlyphs = visualModel->mGlyphs.Count(); + const Length totalNumberOfLines = visualModel->mLines.Count(); + if( ( 0 == totalNumberOfGlyphs ) || + ( 0 == totalNumberOfLines ) ) { return logicalIndex; } @@ -184,14 +184,43 @@ CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel, // Get the position of the first glyph. const Vector2& position = *( positionsBuffer + firstLogicalGlyphIndex ); - // Whether the glyph can be split, like Latin ligatures fi, ff or Arabic ﻻ. - const Length numberOfCharacters = *( charactersPerGlyphBuffer + firstLogicalGlyphIndex ); + // Whether the glyph can be split, like Latin ligatures fi, ff or Arabic (ل + ا). + Length numberOfCharacters = *( charactersPerGlyphBuffer + firstLogicalGlyphIndex ); if( direction != LTR ) { // As characters are being traversed in visual order, // for right to left ligatures, the character which contains the // number of glyphs in the table is found first. // Jump the number of characters to the next glyph is needed. + + if( 0u == numberOfCharacters ) + { + // TODO: This is a workaround to fix an issue with complex characters in the arabic + // script like i.e. رّ or الأَبْجَدِيَّة العَرَبِيَّة + // There are characters that are not shaped in one glyph but in combination with + // the next one generates two of them. + // The visual to logical conversion table have characters in different order than + // expected even if all of them are arabic. + + // The workaround doesn't fix the issue completely but it prevents the application + // to hang in an infinite loop. + + // Find the number of characters. + for( GlyphIndex index = firstLogicalGlyphIndex + 1u; + ( 0u == numberOfCharacters ) && ( index < totalNumberOfGlyphs ) ; + ++index ) + { + numberOfCharacters = *( charactersPerGlyphBuffer + index ); + } + + if( 2u > numberOfCharacters ) + { + continue; + } + + --numberOfCharacters; + } + visualIndex += numberOfCharacters - 1u; } @@ -264,7 +293,7 @@ CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel, { // The paragraph direction is right to left. - if( ( lineIndex != numberOfLines - 1u ) && // is not the last line. + if( ( lineIndex != totalNumberOfLines - 1u ) && // is not the last line. ( visualIndex == startCharacter ) ) { // It places the cursor just after the first character in visual order. @@ -285,7 +314,7 @@ CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel, // This branch checks if the closest line is the one with the last '\n'. If it is, it decrements the visual index to place // the cursor just before the last '\n'. - if( ( lineIndex != numberOfLines - 1u ) && + if( ( lineIndex != totalNumberOfLines - 1u ) && TextAbstraction::IsNewParagraph( *( logicalModel->mText.Begin() + visualIndex - 1u ) ) ) { --visualIndex; -- 2.7.4