GetLineOfGlyph() and GetLineOfCharacter() methods added to the visual model.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / visual-model-impl.cpp
index 0c056ad..c070179 100644 (file)
@@ -343,6 +343,46 @@ void VisualModel::GetLinesOfGlyphRange( LineRun* lines,
   memcpy( lines, mLines.Begin() + firstLine, numberOfLines * sizeof( LineRun ) );
 }
 
+LineIndex VisualModel::GetLineOfGlyph( GlyphIndex glyphIndex )
+{
+  const CharacterIndex characterIndex = *( mGlyphsToCharacters.Begin() + glyphIndex );
+
+  return GetLineOfCharacter( characterIndex );
+}
+
+LineIndex VisualModel::GetLineOfCharacter( CharacterIndex characterIndex )
+{
+  // 1) Check first in the cached line.
+
+  const LineRun& lineRun = *( mLines.Begin() + mCachedLineIndex );
+
+  if( ( lineRun.characterRun.characterIndex <= characterIndex ) &&
+      ( characterIndex < lineRun.characterRun.characterIndex + lineRun.characterRun.numberOfCharacters ) )
+  {
+    return mCachedLineIndex;
+  }
+
+  // 2) Is not in the cached line. Check in the other lines.
+
+  LineIndex index = characterIndex < lineRun.characterRun.characterIndex ? 0u : mCachedLineIndex + 1u;
+
+  for( Vector<LineRun>::ConstIterator it = mLines.Begin() + index,
+         endIt = mLines.End();
+       it != endIt;
+       ++it, ++index )
+  {
+    const LineRun& lineRun = *it;
+
+    if( characterIndex < lineRun.characterRun.characterIndex + lineRun.characterRun.numberOfCharacters )
+    {
+      mCachedLineIndex = index;
+      break;
+    }
+  }
+
+  return index;
+}
+
 void VisualModel::ReplaceLines( GlyphIndex glyphIndex,
                                 Length numberOfGlyphsToRemove,
                                 const LineRun* const lines,
@@ -370,6 +410,16 @@ const Vector2& VisualModel::GetActualSize() const
   return mActualSize;
 }
 
+void VisualModel::SetTextColor( const Vector4& textColor )
+{
+  mTextColor = textColor;
+
+  if ( !mUnderlineColorSet )
+  {
+    mUnderlineColor = textColor;
+  }
+}
+
 void VisualModel::SetShadowOffset( const Vector2& shadowOffset )
 {
   mShadowOffset = shadowOffset;
@@ -380,6 +430,22 @@ void VisualModel::SetShadowColor( const Vector4& shadowColor )
   mShadowColor = shadowColor;
 }
 
+void VisualModel::SetUnderlineColor( const Vector4& color )
+{
+  mUnderlineColor = color;
+  mUnderlineColorSet = true;
+}
+
+void VisualModel::SetUnderlineEnabled( bool enabled )
+{
+  mUnderlineEnabled = enabled;
+}
+
+const Vector4& VisualModel::GetTextColor() const
+{
+  return mTextColor;
+}
+
 const Vector2& VisualModel::GetShadowOffset() const
 {
   return mShadowOffset;
@@ -390,12 +456,42 @@ const Vector4& VisualModel::GetShadowColor() const
   return mShadowColor;
 }
 
+const Vector4& VisualModel::GetUnderlineColor() const
+{
+  return mUnderlineColor;
+}
+
+bool VisualModel::IsUnderlineEnabled() const
+{
+  return mUnderlineEnabled;
+}
+
+void VisualModel::ClearCaches()
+{
+  mCachedLineIndex = 0u;
+}
 
 VisualModel::~VisualModel()
 {
 }
 
 VisualModel::VisualModel()
+: mGlyphs(),
+  mGlyphsToCharacters(),
+  mCharactersToGlyph(),
+  mCharactersPerGlyph(),
+  mGlyphsPerCharacter(),
+  mGlyphPositions(),
+  mLines(),
+  mTextColor(),
+  mShadowColor(),
+  mUnderlineColor(),
+  mShadowOffset(),
+  mNaturalSize(),
+  mActualSize(),
+  mCachedLineIndex( 0u ),
+  mUnderlineEnabled( false ),
+  mUnderlineColorSet( false )
 {
 }