(ItemFactory) Add GetExtension
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / visual-model-impl.h
index 415b4a0..fb9f7bc 100644 (file)
@@ -21,6 +21,7 @@
 // EXTERNAL INCLUDES
 #include <dali/public-api/common/dali-vector.h>
 #include <dali/public-api/common/intrusive-ptr.h>
+#include <dali/public-api/math/vector4.h>
 #include <dali/public-api/object/ref-object.h>
 
 // INTERNAL INCLUDES
@@ -80,6 +81,8 @@ public:
   /**
    * @brief Creates the character to glyph conversion table.
    *
+   * @pre The glyphs per character table needs to be created first.
+   *
    * @param[in] numberOfCharacters The number of characters.
    */
   void CreateCharacterToGlyphTable( Length numberOfCharacters = 0u );
@@ -92,7 +95,7 @@ public:
   void CreateGlyphsPerCharacterTable( Length numberOfCharacters = 0u );
 
   /**
-   * Retrieves the number of glyphs.
+   * @brief Retrieves the number of glyphs.
    *
    * @return The number of glyphs.
    */
@@ -111,7 +114,7 @@ public:
                   Length numberOfGlyphs ) const;
 
   /**
-   * Retrieves a glyph.
+   * @brief Retrieves a glyph.
    *
    * @param[in] glyphIndex Index to a glyph.
    *
@@ -120,7 +123,7 @@ public:
   const GlyphInfo& GetGlyphInfo( GlyphIndex glyphIndex ) const;
 
   /**
-   * Replaces glyphs.
+   * @brief Replaces glyphs.
    *
    * If the @p numberOfGlyphsToRemove is zero, this operation is like an insert.
    * If the @p numberOfGlyphsToInsert is zero, this operation is like a remove.
@@ -158,7 +161,7 @@ public:
   Length GetCharactersPerGlyph( GlyphIndex glyphIndex ) const;
 
   /**
-   * Retrieves the first glyph in the visual model which represents a given character.
+   * @brief Retrieves the first glyph in the visual model which represents a given character.
    *
    * @note After shaping several characters may be represented by the same glyph.
    * Alternatively several glyphs may be required to display a character.
@@ -168,7 +171,7 @@ public:
   GlyphIndex GetGlyphIndex( CharacterIndex characterIndex ) const;
 
   /**
-   * Retrieves the whole or part of the character to glyph conversion map.
+   * @brief Retrieves the whole or part of the character to glyph conversion map.
    *
    * The size of the buffer needs to be big enough to copy the @p numberOfCharacters.
    *
@@ -181,7 +184,7 @@ public:
                                Length numberOfCharacters ) const;
 
   /**
-   * Retrieves the whole or part of the glyph to character conversion map.
+   * @brief Retrieves the whole or part of the glyph to character conversion map.
    *
    * The size of the buffer needs to be big enough to copy the @p numberOfGlyphs.
    *
@@ -194,7 +197,7 @@ public:
                                Length numberOfGlyphs ) const;
 
   /**
-   * Retrieves for each glyph the number of characters the glyph represents.
+   * @brief Retrieves for each glyph the number of characters the glyph represents.
    *
    * @param[out] charactersPerGlyph Pointer to a buffer where the number of characters for each glyph are copied.
    * @param[in] glyphIndex Index to the first glyph.
@@ -205,7 +208,7 @@ public:
                                  Length numberOfGlyphs ) const;
 
   /**
-   * Retrieves for each character the number of glyphs the character is shaped.
+   * @brief Retrieves for each character the number of glyphs the character is shaped.
    *
    * @param[out] glyphsPerCharacter Pointer to a buffer where the number of glyphs for each character are copied.
    * @param[in] characterIndex Index to the first character.
@@ -229,7 +232,7 @@ public:
                           Length numberOfGlyphs );
 
   /**
-   * Retrieves the number of glyph positions set.
+   * @brief Retrieves the number of glyph positions set.
    *
    * @note This may be less than the number of glyphs in the model.
    * @return The number of glyphs.
@@ -249,7 +252,7 @@ public:
                           Length numberOfGlyphs ) const;
 
   /**
-   * Retrieve the glyph's position of the given glyph.
+   * @brief Retrieve the glyph's position of the given glyph.
    *
    * @param[in] glyphIndex Index to the glyph.
    *
@@ -258,7 +261,7 @@ public:
   const Vector2& GetGlyphPosition( GlyphIndex glyphIndex ) const;
 
   /**
-   * Replaces glyph's positions.
+   * @brief Replaces glyph's positions.
    *
    * If the @p numberOfGlyphsToRemove is zero, this operation is like an insert.
    * If the @p numberOfGlyphsToInsert is zero, this operation is like a remove.
@@ -276,7 +279,7 @@ public:
   // Line interface.
 
   /**
-   * Sets the lines.
+   * @brief Sets the lines.
    *
    * Replaces any lines previously set.
    *
@@ -291,14 +294,14 @@ public:
                  Length numberOfLines );
 
   /**
-   * Retrieves the number of lines of the whole text.
+   * @brief Retrieves the number of lines of the whole text.
    *
    * @return The number of lines.
    */
   Length GetNumberOfLines() const;
 
   /**
-   * Retrieves lines.
+   * @brief Retrieves lines.
    *
    * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
    *
@@ -311,7 +314,7 @@ public:
                  Length numberOfLines ) const;
 
   /**
-   * Retrieves the number of lines and the index to the first line where the given range of glyphs is laid out.
+   * @brief Retrieves the number of lines and the index to the first line where the given range of glyphs is laid out.
    *
    * @param[in] glyphIndex Index to the first glyph.
    * @param[in] numberOfGlyphs The number of glyph.
@@ -323,7 +326,7 @@ public:
                          LineIndex& firstLine,
                          Length& numberOfLines ) const;
   /**
-   * Retrieves the lines where the given range of glyphs is laid out.
+   * @brief Retrieves the lines where the given range of glyphs is laid out.
    *
    * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines.
    *
@@ -336,7 +339,25 @@ public:
                              Length numberOfGlyphs ) const;
 
   /**
-   * Replaces lines for the given range of glyphs.
+   * @brief Retrieves the line index where the glyph is laid-out.
+   *
+   * @param[in] glyphIndex The glyph's index.
+   *
+   * @return The line index.
+   */
+  LineIndex GetLineOfGlyph( GlyphIndex glyphIndex );
+
+  /**
+   * @brief Retrieves the line index where the character is laid-out.
+   *
+   * @param[in] characterIndex The character's index.
+   *
+   * @return The line index.
+   */
+  LineIndex GetLineOfCharacter( CharacterIndex characterIndex );
+
+  /**
+   * @brief Replaces lines for the given range of glyphs.
    *
    * If the @p numberOfGlyphsToRemove is zero, this operation is like an insert.
    * If the @p numberOfGlyphsToInsert is zero, this operation is like a remove.
@@ -354,33 +375,122 @@ public:
   // Size interface
 
   /**
-   * Sets the natural size.
+   * @brief Sets the natural size.
    *
    * @param[in] size The text's natural size.
    */
   void SetNaturalSize( const Vector2& size  );
 
   /**
-   * Retrieves the natural size.
+   * @brief Retrieves the natural size.
    *
    * @return The text's natural size.
    */
   const Vector2& GetNaturalSize() const;
 
   /**
-   * Sets the text's actual size after it has been laid out.
+   * @brief Sets the text's actual size after it has been laid out.
    *
    * @param[in] size The text's size.
    */
   void SetActualSize( const Vector2& size );
 
   /**
-   * Retrieves the text's actual size after it has been laid out.
+   * @brief Retrieves the text's actual size after it has been laid out.
    *
    * @return The text's size.
    */
   const Vector2& GetActualSize() const;
 
+  /**
+   * @brief Set the text's color
+   *
+   * @param[in] textColor The text's color
+   */
+  void SetTextColor( const Vector4& textColor );
+
+  /**
+   * @brief Retrieve the text's color
+   *
+   * @return The text's color
+   */
+  const Vector4& GetTextColor() const;
+
+  /**
+   * @brief Sets the text's shadow offset.
+   *
+   * @param[in] shadowOffset The shadow offset, 0,0 indicates no shadow.
+   */
+  void SetShadowOffset( const Vector2& shadowOffset );
+
+  /**
+   * @brief Retrieves the text's shadow offset.
+   *
+   * @return The text's shadow offset, 0,0 indicates no shadow.
+   */
+  const Vector2& GetShadowOffset() const;
+
+  /**
+   * @brief Sets the text's shadow color.
+   *
+   * @param[in] shadowColor The shadow color.
+   */
+  void SetShadowColor( const Vector4& shadowColor );
+
+  /**
+   * @brief Retrieves the text's shadow color.
+   *
+   * @return The text's shadow color.
+   */
+  const Vector4& GetShadowColor() const;
+
+  /**
+   * @brief Sets the text's underline color.
+   *
+   * @param[in] color The text's underline color.
+   */
+  void SetUnderlineColor( const Vector4& color );
+
+  /**
+   * @brief Retrieves the text's underline color.
+   *
+   * @return The text's underline color.
+   */
+  const Vector4& GetUnderlineColor() const;
+
+  /**
+   * @brief Sets the text underline flag.
+   *
+   * @param[in] enabled true if underlined.
+   */
+  void SetUnderlineEnabled( bool enabled );
+
+  /**
+   * @brief Returns whether the text is underlined or not.
+   *
+   * @return underline state.
+   */
+  bool IsUnderlineEnabled() const;
+
+  /**
+   * @brief Clear the caches.
+   */
+  void ClearCaches();
+
+  /**
+   * @brief Set the override used for underline height, 0 indicates height will be come from font metrics
+   *
+   * @param[in] height The height in pixels of the underline
+   */
+  void SetUnderlineHeight( float height );
+
+  /**
+   * @brief Retrieves the underline height override
+   *
+   * @return Returns the override height for an underline, 0 indicates that font metrics will determine the height
+   */
+  float GetUnderlineHeight() const;
+
 protected:
 
   /**
@@ -403,18 +513,35 @@ private:
 
 public:
 
-  Vector<GlyphInfo>      mGlyphs;             ///< For each glyph, the font's id, glyph's index within the font and glyph's metrics.
-  Vector<CharacterIndex> mGlyphsToCharacters; ///< For each glyph, the index of the first character.
-  Vector<GlyphIndex>     mCharactersToGlyph;  ///< For each character, the index of the first glyph.
-  Vector<Length>         mCharactersPerGlyph; ///< For each glyph, the number of characters that form the glyph.
-  Vector<Length>         mGlyphsPerCharacter; ///< For each character, the number of glyphs that are shaped.
-  Vector<Vector2>        mGlyphPositions;     ///< For each glyph, the position.
-  Vector<LineRun>        mLines;              ///< The laid out lines.
+  Vector<GlyphInfo>      mGlyphs;               ///< For each glyph, the font's id, glyph's index within the font and glyph's metrics.
+  Vector<CharacterIndex> mGlyphsToCharacters;   ///< For each glyph, the index of the first character.
+  Vector<GlyphIndex>     mCharactersToGlyph;    ///< For each character, the index of the first glyph.
+  Vector<Length>         mCharactersPerGlyph;   ///< For each glyph, the number of characters that form the glyph.
+  Vector<Length>         mGlyphsPerCharacter;   ///< For each character, the number of glyphs that are shaped.
+  Vector<Vector2>        mGlyphPositions;       ///< For each glyph, the position.
+  Vector<LineRun>        mLines;                ///< The laid out lines.
+
+  Vector4                mTextColor;            ///< The text color
+  Vector4                mShadowColor;          ///< Color of drop shadow
+  Vector4                mUnderlineColor;       ///< Color of underline
+  Vector2                mShadowOffset;         ///< Offset for drop shadow, 0 indicates no shadow
+  float                  mUnderlineHeight;      ///< Fixed height for underline to override font metrics.
+
+
 
 private:
 
   Size                   mNaturalSize;        ///< Size of the text with no line wrapping.
   Size                   mActualSize;         ///< Size of the laid-out text considering the layout properties set.
+
+  // Caches to increase performance in some consecutive operations.
+  LineIndex mCachedLineIndex; ///< Used to increase performance in consecutive calls to GetLineOfGlyph() or GetLineOfCharacter() with consecutive glyphs or characters.
+
+public:
+
+  bool                   mUnderlineEnabled:1;   ///< Underline enabled flag
+  bool                   mUnderlineColorSet:1;  ///< Has the underline color been explicitly set?
+
 };
 
 } // namespace Text