// INTERNAL INCLUDES
#include <dali-toolkit/internal/text/bidirectional-line-info-run.h>
+#include <dali-toolkit/internal/text/cursor-helper-functions.h>
#include <dali-toolkit/internal/text/glyph-metrics-helper.h>
#include <dali-toolkit/internal/text/layouts/layout-parameters.h>
const float MAX_FLOAT = std::numeric_limits<float>::max();
const bool RTL = true;
const float CURSOR_WIDTH = 1.f;
-
-Length CountParagraphs( const LayoutParameters& layoutParameters )
-{
- Length numberOfParagraphs = 0u;
-
- const CharacterIndex startCharacterIndex = *( layoutParameters.glyphsToCharactersBuffer + layoutParameters.startGlyphIndex );
-
- const GlyphIndex lastGlyphIndex = layoutParameters.startGlyphIndex + layoutParameters.numberOfGlyphs - 1u;
- const CharacterIndex lastCharacterIndexPlusOne = *( layoutParameters.glyphsToCharactersBuffer + lastGlyphIndex ) + *( layoutParameters.charactersPerGlyphBuffer + lastGlyphIndex );
-
- for( CharacterIndex index = startCharacterIndex; index < lastCharacterIndexPlusOne; ++index )
- {
- if( TextAbstraction::LINE_MUST_BREAK == *( layoutParameters.lineBreakInfoBuffer + index ) )
- {
- ++numberOfParagraphs;
- }
- }
-
- return numberOfParagraphs;
-}
+const float LINE_SPACING= 0.f;
} //namespace
mHorizontalAlignment( LayoutEngine::HORIZONTAL_ALIGN_BEGIN ),
mVerticalAlignment( LayoutEngine::VERTICAL_ALIGN_TOP ),
mCursorWidth( CURSOR_WIDTH ),
+ mDefaultLineSpacing( LINE_SPACING ),
mEllipsisEnabled( false )
{
}
DALI_LOG_INFO( gLogFilter, Debug::Verbose, "<--GetLineLayoutForBox\n" );
}
- /**
- * @brief Calculates the vertical offset to add to the new laid-out glyphs.
- *
- * @pre @p lineIndex must be between 0 and the number of lines (both inclusive).
- *
- * @param[in] lines The previously laid-out lines.
- * @param[in] lineIndex Index to the line where the new laid-out lines are inserted.
- *
- * @return The vertical offset of the lines starting from the beginning to the line @p lineIndex.
- */
- float SetParagraphOffset( const Vector<LineRun>& lines,
- LineIndex lineIndex )
- {
- float offset = 0.f;
-
- for( Vector<LineRun>::ConstIterator it = lines.Begin(),
- endIt = lines.Begin() + lineIndex;
- it != endIt;
- ++it )
- {
- const LineRun& line = *it;
-
- offset += line.ascender + -line.descender;
- }
-
- return offset;
- }
-
void SetGlyphPositions( const GlyphInfo* const glyphsBuffer,
Length numberOfGlyphs,
- float penY,
Vector2* glyphPositionsBuffer )
{
// Traverse the glyphs and set the positions.
Vector2& position = *( glyphPositionsBuffer + i );
position.x = penX + glyph.xBearing;
- position.y = penY - glyph.yBearing;
+ position.y = -glyph.yBearing;
penX += glyph.advance;
}
SetGlyphPositions( layoutParameters.glyphsBuffer + lineRun->glyphRun.glyphIndex,
ellipsisLayout.numberOfGlyphs,
- penY,
glyphPositionsBuffer + lineRun->glyphRun.glyphIndex - layoutParameters.startGlyphIndex );
}
* @brief Updates the text layout with the last laid-out line.
*
* @param[in] layoutParameters The parameters needed to layout the text.
- * @param[in] layout The line layout.
+ * @param[in] characterIndex The character index of the line.
+ * @param[in] glyphIndex The glyph index of the line.
* @param[in,out] layoutSize The text's layout size.
* @param[in,out] linesBuffer Pointer to the line's buffer.
- * @param[in] index Index to the vector of glyphs.
* @param[in,out] numberOfLines The number of laid-out lines.
*/
void UpdateTextLayout( const LayoutParameters& layoutParameters,
- const LineLayout& layout,
+ CharacterIndex characterIndex,
+ GlyphIndex glyphIndex,
Size& layoutSize,
LineRun* linesBuffer,
- GlyphIndex index,
Length& numberOfLines )
{
// Need to add a new line with no characters but with height to increase the layoutSize.height
LineRun& lineRun = *( linesBuffer + numberOfLines );
++numberOfLines;
- lineRun.glyphRun.glyphIndex = index + layout.numberOfGlyphs;
+ lineRun.glyphRun.glyphIndex = glyphIndex;
lineRun.glyphRun.numberOfGlyphs = 0u;
- lineRun.characterRun.characterIndex = layout.characterIndex + layout.numberOfCharacters;
+ lineRun.characterRun.characterIndex = characterIndex;
lineRun.characterRun.numberOfCharacters = 0u;
lineRun.width = 0.f;
lineRun.ascender = fontMetrics.ascender;
if( 0u == layoutParameters.numberOfGlyphs )
{
- // Nothing to do if there are no glyphs to layout.
+ // Add an extra line if the last character is a new paragraph character and the last line doesn't have zero characters.
+ if( layoutParameters.isLastNewParagraph )
+ {
+ Length numberOfLines = lines.Count();
+ if( 0u != numberOfLines )
+ {
+ const LineRun& lastLine = *( lines.End() - 1u );
+
+ if( 0u != lastLine.characterRun.numberOfCharacters )
+ {
+ // Need to add a new line with no characters but with height to increase the layoutSize.height
+ LineRun newLine;
+ Initialize( newLine );
+ lines.PushBack( newLine );
+
+ UpdateTextLayout( layoutParameters,
+ lastLine.characterRun.characterIndex + lastLine.characterRun.numberOfCharacters,
+ lastLine.glyphRun.glyphIndex + lastLine.glyphRun.numberOfGlyphs,
+ layoutSize,
+ lines.Begin(),
+ numberOfLines );
+ }
+ }
+ }
+
+ // Nothing else do if there are no glyphs to layout.
return false;
}
+ const GlyphIndex lastGlyphPlusOne = layoutParameters.startGlyphIndex + layoutParameters.numberOfGlyphs;
+
+ // In a previous layout, an extra line with no characters may have been added if the text ended with a new paragraph character.
+ // This extra line needs to be removed.
+ if( 0u != lines.Count() )
+ {
+ Vector<LineRun>::Iterator lastLine = lines.End() - 1u;
+
+ if( ( 0u == lastLine->characterRun.numberOfCharacters ) &&
+ ( lastGlyphPlusOne == layoutParameters.totalNumberOfGlyphs ) )
+ {
+ lines.Remove( lastLine );
+ }
+ }
+
// Set the first paragraph's direction.
CharacterDirection paragraphDirection = ( NULL != layoutParameters.characterDirectionBuffer ) ? *layoutParameters.characterDirectionBuffer : !RTL;
Vector<LineRun> newLines;
// Estimate the number of lines.
- // TODO: In a next patch the paragraphs are properly managed and this can be removed.
- Length linesCapacity = CountParagraphs( layoutParameters );
+ Length linesCapacity = std::max( 1u, layoutParameters.estimatedNumberOfLines );
Length numberOfLines = 0u;
if( updateCurrentBuffer )
linesBuffer = lines.Begin();
}
- float penY = SetParagraphOffset( lines,
- layoutParameters.startLineIndex );
+ float penY = CalculateLineOffset( lines,
+ layoutParameters.startLineIndex );
- const GlyphIndex lastGlyphPlusOne = layoutParameters.startGlyphIndex + layoutParameters.numberOfGlyphs;
for( GlyphIndex index = layoutParameters.startGlyphIndex; index < lastGlyphPlusOne; )
{
CharacterDirection currentParagraphDirection = paragraphDirection;
numberOfLines,
isLastLine );
- if( isLastLine &&
+ const GlyphIndex nextIndex = index + layout.numberOfGlyphs;
+
+ if( ( nextIndex == layoutParameters.totalNumberOfGlyphs ) &&
layoutParameters.isLastNewParagraph &&
( mLayout == MULTI_LINE_BOX ) )
{
}
UpdateTextLayout( layoutParameters,
- layout,
+ layout.characterIndex + layout.numberOfCharacters,
+ index + layout.numberOfGlyphs,
layoutSize,
linesBuffer,
- index,
numberOfLines );
} // whether to add a last line.
// Sets the positions of the glyphs.
SetGlyphPositions( layoutParameters.glyphsBuffer + index,
layout.numberOfGlyphs,
- penY,
glyphPositionsBuffer + index - layoutParameters.startGlyphIndex );
// Updates the vertical pen's position.
penY += -layout.descender;
// Increase the glyph index.
- index += layout.numberOfGlyphs;
-
+ index = nextIndex;
} // no ellipsis
} // end for() traversing glyphs.
glyphPositions.Insert( glyphPositions.Begin() + layoutParameters.startGlyphIndex,
newGlyphPositions.Begin(),
newGlyphPositions.End() );
+ glyphPositions.Resize( layoutParameters.totalNumberOfGlyphs );
newLines.Resize( numberOfLines );
}
}
+ void Initialize( LineRun& line )
+ {
+ line.glyphRun.glyphIndex = 0u;
+ line.glyphRun.numberOfGlyphs = 0u;
+ line.characterRun.characterIndex = 0u;
+ line.characterRun.numberOfCharacters = 0u;
+ line.width = 0.f;
+ line.ascender = 0.f;
+ line.descender = 0.f;
+ line.extraLength = 0.f;
+ line.alignmentOffset = 0.f;
+ line.direction = !RTL;
+ line.ellipsis = false;
+ }
+
LayoutEngine::Layout mLayout;
LayoutEngine::HorizontalAlignment mHorizontalAlignment;
LayoutEngine::VerticalAlignment mVerticalAlignment;
float mCursorWidth;
+ float mDefaultLineSpacing;
IntrusivePtr<Metrics> mMetrics;
LayoutEngine::Layout LayoutEngine::GetLayout() const
{
+ DALI_LOG_INFO( gLogFilter, Debug::Verbose, "GetLayout[%d]\n", mImpl->mLayout);
return mImpl->mLayout;
}
void LayoutEngine::SetTextEllipsisEnabled( bool enabled )
{
+ DALI_LOG_INFO( gLogFilter, Debug::General, "-->LayoutEngine::SetTextEllipsisEnabled[%s]\n", (enabled)?"true":"false" );
mImpl->mEllipsisEnabled = enabled;
}
lines );
}
+void LayoutEngine::SetDefaultLineSpacing( float lineSpacing )
+{
+ mImpl->mDefaultLineSpacing = lineSpacing;
+}
+
+float LayoutEngine::GetDefaultLineSpacing() const
+{
+ return mImpl->mDefaultLineSpacing;
+}
+
} // namespace Text
} // namespace Toolkit