From: Victor Cebollada Date: Tue, 24 Feb 2015 15:05:22 +0000 (+0000) Subject: Fixes for Shaping. Do not shape \n characters. X-Git-Tag: new_text_0.1~35 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=1575a786324e7350600cbcd51e22b9db9be76f36 Fixes for Shaping. Do not shape \n characters. Change-Id: Id1525613266d1c0aa2dde1eb6d0323c828f3a0e3 Signed-off-by: Victor Cebollada --- diff --git a/dali-toolkit/public-api/text/shaper.cpp b/dali-toolkit/public-api/text/shaper.cpp index 7ef076f..6a68310 100644 --- a/dali-toolkit/public-api/text/shaper.cpp +++ b/dali-toolkit/public-api/text/shaper.cpp @@ -18,10 +18,13 @@ // CLASS HEADER #include -// INTERNAL INCLUDES +// EXTERNAL INCLUDES #include + +// INTERNAL INCLUDES #include #include +#include #include #include @@ -79,9 +82,6 @@ void ShapeText( const Vector& text, Vector::ConstIterator fontRunIt = fonts.Begin(); Vector::ConstIterator scriptRunIt = scripts.Begin(); - // The line must break token converted to LineBreakInfo to be compared and avoid a compile error. - const LineBreakInfo MUST_BREAK = static_cast( TextAbstraction::LINE_MUST_BREAK ); - // Index to the the next one to be shaped. Is pointing the character after the last one it was shaped. CharacterIndex previousIndex = 0u; @@ -100,6 +100,11 @@ void ShapeText( const Vector& text, // The actual number of glyphs. Length totalNumberOfGlyphs = 0u; + const Character* textBuffer = text.Begin(); + const LineBreakInfo* lineBreakInfoBuffer = lineBreakInfo.Begin(); + GlyphInfo* glyphsBuffer = glyphs.Begin(); + Length* charactersPerGlyphBuffer = charactersPerGlyph.Begin(); + // Traverse the characters and shape the text. for( previousIndex = 0; previousIndex < numberOfCharacters; ) { @@ -115,18 +120,28 @@ void ShapeText( const Vector& text, scriptRun.characterRun.characterIndex + scriptRun.characterRun.numberOfCharacters ); // Check if there is a line must break. + bool mustBreak = false; for( CharacterIndex index = previousIndex; index < currentIndex; ++index ) { - if( MUST_BREAK == lineBreakInfo.Begin() + index ) + mustBreak = TextAbstraction::LINE_MUST_BREAK == *( lineBreakInfoBuffer + index ); + if( mustBreak ) { currentIndex = index; break; } } + // Check if the current index is a white space. Do not want to shape a \n. + // The last character is always a must-break even if it's not a \n. + Length numberOfCharactersToShape = currentIndex - previousIndex; + if( mustBreak && !IsWhiteSpace( *( textBuffer + currentIndex ) ) ) + { + ++numberOfCharactersToShape; + } + // Shape the text for the current chunk. - const Length numberOfGlyphs = shaping.Shape( text.Begin() + previousIndex, - currentIndex - previousIndex, + const Length numberOfGlyphs = shaping.Shape( textBuffer + previousIndex, + numberOfCharactersToShape, currentFontId, currentScript ); @@ -139,11 +154,15 @@ void ShapeText( const Vector& text, numberOfGlyphsReserved = static_cast( totalNumberOfGlyphs * 1.3f ); glyphs.Resize( numberOfGlyphsReserved ); charactersPerGlyph.Resize( numberOfGlyphsReserved ); + + // Iterators are not valid anymore, set them again. + glyphsBuffer = glyphs.Begin(); + charactersPerGlyphBuffer = charactersPerGlyph.Begin(); } // Retrieve the glyphs and the glyph to character conversion map. - shaping.GetGlyphs( glyphs.Begin() + glyphIndex, - charactersPerGlyph.Begin() + glyphIndex ); + shaping.GetGlyphs( glyphsBuffer + glyphIndex, + charactersPerGlyphBuffer + glyphIndex ); // Update the iterators to get the next font or script run. if( currentIndex == fontRun.characterRun.characterIndex + fontRun.characterRun.numberOfCharacters ) @@ -155,8 +174,8 @@ void ShapeText( const Vector& text, ++scriptRunIt; } - // Update the previous index. - previousIndex = currentIndex; + // Update the previous index. Jumps the \n if needed. + previousIndex = mustBreak ? currentIndex + 1u : currentIndex; } characterIndices.Reserve( totalNumberOfGlyphs ); @@ -164,7 +183,7 @@ void ShapeText( const Vector& text, characterIndices.PushBack( characterIndex ); for( Length index = 0u, length = totalNumberOfGlyphs - 1u; index < length; ++index ) { - characterIndex += *( charactersPerGlyph.Begin() + index ); + characterIndex += *( charactersPerGlyphBuffer + index ); characterIndices.PushBack( characterIndex ); }