From b7a6bc2dcbd598916a74186ba69bd9e522c23d09 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Fri, 6 Mar 2015 07:49:03 +0000 Subject: [PATCH] Fix for Shaping. - In a text with different scripts, the text is shaped in runs of characters with the same script. Adpator return the character index of each glyph starting always by 0. Toolkit was not updating the indices given by the adaptor for the runs after the first one. - characterIndices renamed to glyphsToCharactersMap. - Adaptor retrieves the glyphsToCharactersMap. Toolkit was setting the glyphsToCharactersMap to the charactersPerGlyph vector. Change-Id: I9c74741fadb6d68bca29629ff79ed7bc48dd2840 Signed-off-by: Victor Cebollada --- dali-toolkit/internal/text/shaper.cpp | 42 +++++++++++++++++--------- dali-toolkit/internal/text/shaper.h | 4 +-- dali-toolkit/internal/text/text-controller.cpp | 10 +++--- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/dali-toolkit/internal/text/shaper.cpp b/dali-toolkit/internal/text/shaper.cpp index e70750c..eaaedeb 100644 --- a/dali-toolkit/internal/text/shaper.cpp +++ b/dali-toolkit/internal/text/shaper.cpp @@ -48,7 +48,7 @@ void ShapeText( const Vector& text, const Vector& scripts, const Vector& fonts, Vector& glyphs, - Vector& characterIndices, + Vector& glyphToCharacterMap, Vector& charactersPerGlyph ) { const Length numberOfCharacters = text.Count(); @@ -95,7 +95,7 @@ void ShapeText( const Vector& text, Length numberOfGlyphsReserved = static_cast( numberOfCharacters * 1.3f ); glyphs.Resize( numberOfGlyphsReserved ); - charactersPerGlyph.Resize( numberOfGlyphsReserved ); + glyphToCharacterMap.Resize( numberOfGlyphsReserved ); // The actual number of glyphs. Length totalNumberOfGlyphs = 0u; @@ -103,7 +103,7 @@ void ShapeText( const Vector& text, const Character* textBuffer = text.Begin(); const LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin(); GlyphInfo* glyphsBuffer = glyphs.Begin(); - Length* charactersPerGlyphBuffer = charactersPerGlyph.Begin(); + CharacterIndex* glyphToCharacterMapBuffer = glyphToCharacterMap.Begin(); // Traverse the characters and shape the text. for( previousIndex = 0; previousIndex < numberOfCharacters; ) @@ -153,16 +153,26 @@ void ShapeText( const Vector& text, // Resize the vectors to get enough space. numberOfGlyphsReserved = static_cast( totalNumberOfGlyphs * 1.3f ); glyphs.Resize( numberOfGlyphsReserved ); - charactersPerGlyph.Resize( numberOfGlyphsReserved ); + glyphToCharacterMap.Resize( numberOfGlyphsReserved ); // Iterators are not valid anymore, set them again. glyphsBuffer = glyphs.Begin(); - charactersPerGlyphBuffer = charactersPerGlyph.Begin(); + glyphToCharacterMapBuffer = glyphToCharacterMap.Begin(); } // Retrieve the glyphs and the glyph to character conversion map. shaping.GetGlyphs( glyphsBuffer + glyphIndex, - charactersPerGlyphBuffer + glyphIndex ); + glyphToCharacterMapBuffer + glyphIndex ); + + // Update indices. + if( 0u != glyphIndex ) + { + for( Length index = glyphIndex; index < glyphIndex + numberOfGlyphs; ++index ) + { + CharacterIndex& characterIndex = *( glyphToCharacterMapBuffer + index ); + characterIndex += previousIndex; + } + } // Update the iterators to get the next font or script run. if( currentIndex == fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters ) @@ -178,19 +188,23 @@ void ShapeText( const Vector& text, previousIndex = mustBreak ? currentIndex + 1u : currentIndex; } - characterIndices.Reserve( totalNumberOfGlyphs ); - CharacterIndex characterIndex = 0u; - characterIndices.PushBack( characterIndex ); - for( Length index = 0u, length = totalNumberOfGlyphs - 1u; index < length; ++index ) + // Add the number of characters per glyph. + charactersPerGlyph.Reserve( totalNumberOfGlyphs ); + previousIndex = 0u; + for( Length index = 1u; index < totalNumberOfGlyphs; ++index ) { - characterIndex += *( charactersPerGlyphBuffer + index ); - characterIndices.PushBack( characterIndex ); + const CharacterIndex characterIndex = *( glyphToCharacterMapBuffer + index ); + + charactersPerGlyph.PushBack( characterIndex - previousIndex ); + + previousIndex = characterIndex; } + charactersPerGlyph.PushBack( numberOfCharacters - previousIndex ); + // Resize the vectors to set the right number of items. glyphs.Resize( totalNumberOfGlyphs ); - // characterIndices.Resize( totalNumberOfGlyphs ); - charactersPerGlyph.Resize( totalNumberOfGlyphs ); + glyphToCharacterMap.Resize( totalNumberOfGlyphs ); } void ShapeText( const LogicalModel& logicalModel, diff --git a/dali-toolkit/internal/text/shaper.h b/dali-toolkit/internal/text/shaper.h index 441465c..c1ccfb5 100644 --- a/dali-toolkit/internal/text/shaper.h +++ b/dali-toolkit/internal/text/shaper.h @@ -43,7 +43,7 @@ class VisualModel; * @param[in] scripts Vector containing the script runs for the whole text. * @param[in] fonts Vector with validated fonts. * @param[out] glyphs Vector of glyphs in the visual order. - * @param[out] characterIndices Vector containing the first character in the logical model that each glyph relates to. + * @param[out] glyphToCharacterMap Vector containing the first character in the logical model that each glyph relates to. * @param[out] charactersPerGlyph Vector containing the number of characters per glyph. */ void ShapeText( const Vector& text, @@ -51,7 +51,7 @@ void ShapeText( const Vector& text, const Vector& scripts, const Vector& fonts, Vector& glyphs, - Vector& characterIndices, + Vector& glyphToCharacterMap, Vector& charactersPerGlyph ); /** diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index f12ba5b..67f91c4 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -435,7 +435,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations ) } Vector glyphs; - Vector characterIndices; + Vector glyphsToCharactersMap; Vector charactersPerGlyph; if( SHAPE_TEXT & operations ) { @@ -445,7 +445,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations ) scripts, fonts, glyphs, - characterIndices, + glyphsToCharactersMap, charactersPerGlyph ); } @@ -461,14 +461,14 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations ) const Length numberOfGlyphs = mImpl->mVisualModel->GetNumberOfGlyphs(); glyphs.Resize( numberOfGlyphs ); - characterIndices.Resize( numberOfGlyphs ); + glyphsToCharactersMap.Resize( numberOfGlyphs ); charactersPerGlyph.Resize( numberOfGlyphs ); mImpl->mVisualModel->GetGlyphs( glyphs.Begin(), 0u, numberOfGlyphs ); - mImpl->mVisualModel->GetGlyphToCharacterMap( characterIndices.Begin(), + mImpl->mVisualModel->GetGlyphToCharacterMap( glyphsToCharactersMap.Begin(), 0u, numberOfGlyphs ); @@ -480,7 +480,7 @@ bool Controller::DoRelayout( const Vector2& size, OperationsMask operations ) // Update the visual model mImpl->mLayoutEngine.UpdateVisualModel( size, glyphs, - characterIndices, + glyphsToCharactersMap, charactersPerGlyph, *mImpl->mVisualModel ); -- 2.7.4