X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fpublic-api%2Ftext%2Fshaper.cpp;h=376a1b7a00bc2e5f6fe724bb96f20838f47983ab;hp=54444ace5a6000c98666243cdd66facc7e6a669a;hb=09e2475439f1d40c576df0fdc0bc9e26a9661758;hpb=bee80770f7faa39a9d71c21e4d9ccf34a47fcc2e diff --git a/dali-toolkit/public-api/text/shaper.cpp b/dali-toolkit/public-api/text/shaper.cpp index 54444ac..376a1b7 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 @@ -56,14 +59,15 @@ void ShapeText( const Vector& text, return; } +#ifdef DEBUG_ENABLED const Length numberOfFontRuns = fonts.Count(); + const Length numberOfScriptRuns = scripts.Count(); +#endif DALI_ASSERT_DEBUG( ( 0u != numberOfFontRuns ) && ( numberOfCharacters == fonts[numberOfFontRuns - 1u].characterRun.characterIndex + fonts[numberOfFontRuns - 1u].characterRun.numberOfCharacters ) && "Toolkit::Text::ShapeText. All characters must have a font set." ); - const Length numberOfScriptRuns = scripts.Count(); - DALI_ASSERT_DEBUG( ( 0u != numberOfScriptRuns ) && ( numberOfCharacters == scripts[numberOfScriptRuns - 1u].characterRun.characterIndex + scripts[numberOfScriptRuns - 1u].characterRun.numberOfCharacters ) && "Toolkit::Text::ShapeText. All characters must have a script set." ); @@ -78,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; @@ -99,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; ) { @@ -114,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 ); @@ -138,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 ) @@ -154,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 ); @@ -163,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 ); } @@ -173,6 +193,14 @@ void ShapeText( const Vector& text, charactersPerGlyph.Resize( totalNumberOfGlyphs ); } +void ShapeText( const LogicalModel& logicalModel, + VisualModel& visualModel, + CharacterIndex characterIndex, + Length numberOfCharactersToRemove, + Length numberOfCharactersToInsert ) +{ +} + } // namespace Text } // namespace Toolkit