Support software styling 41/185141/5
authorminho.sun <minho.sun@samsung.com>
Thu, 26 Jul 2018 08:18:18 +0000 (17:18 +0900)
committerMinho Sun <minho.sun@samsung.com>
Fri, 3 Aug 2018 02:06:42 +0000 (02:06 +0000)
When DALi fails to find font which support correct style,
apply software styling to glyph.

DALi will support bold / italic by software.

Change-Id: I898fd967eb571437789dc5c84444f8091dc88ee6
Signed-off-by: minho.sun <minho.sun@samsung.com>
dali/devel-api/text-abstraction/font-client.cpp
dali/devel-api/text-abstraction/font-client.h
dali/devel-api/text-abstraction/glyph-info.cpp
dali/devel-api/text-abstraction/glyph-info.h
dali/internal/text/text-abstraction/font-client-impl.cpp
dali/internal/text/text-abstraction/font-client-impl.h
dali/internal/text/text-abstraction/font-client-plugin-impl.cpp
dali/internal/text/text-abstraction/font-client-plugin-impl.h

index e49410a..2dcb128 100644 (file)
@@ -182,9 +182,9 @@ bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType typ
   return GetImplementation(*this).GetGlyphMetrics( array, size, type, horizontal );
 }
 
-void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, GlyphBufferData& data, int outlineWidth )
+void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, GlyphBufferData& data, int outlineWidth )
 {
-  GetImplementation(*this).CreateBitmap( fontId, glyphIndex, data, outlineWidth );
+  GetImplementation(*this).CreateBitmap( fontId, glyphIndex, softwareItalic, softwareBold, data, outlineWidth );
 }
 
 PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
index 6411b16..167607d 100755 (executable)
@@ -351,12 +351,14 @@ public:
    *
    * @note The caller is responsible for deallocating the bitmap data @p data.buffer using delete[].
    *
-   * @param[in] fontId The identifier of the font.
-   * @param[in] glyphIndex The index of a glyph within the specified font.
-   * @param[out] data The bitmap data.
-   * @param[in] outlineWidth The width of the glyph outline in pixels.
-   */
-  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, GlyphBufferData& data, int outlineWidth );
+   * @param[in]  fontId          The identifier of the font.
+   * @param[in]  glyphIndex      The index of a glyph within the specified font.
+   * @param[in]  softwareItalic  Whether glyph needs software support to draw italic style.
+   * @param[in]  softwareBold    Whether glyph needs software support to draw bold style.
+   * @param[out] data            The bitmap data.
+   * @param[in]  outlineWidth    The width of the glyph outline in pixels.
+   */
+  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, GlyphBufferData& data, int outlineWidth );
 
   /**
    * @brief Create a bitmap representation of a glyph.
index 2d7c811..898a2d5 100644 (file)
@@ -32,7 +32,9 @@ GlyphInfo::GlyphInfo()
   xBearing( 0 ),
   yBearing( 0 ),
   advance( 0 ),
-  scaleFactor( 0 )
+  scaleFactor( 0 ),
+  softwareItalic(false),
+  softwareBold(false)
 {
 }
 
@@ -44,7 +46,9 @@ GlyphInfo::GlyphInfo( FontId font, GlyphIndex i )
   xBearing( 0 ),
   yBearing( 0 ),
   advance( 0 ),
-  scaleFactor( 0 )
+  scaleFactor( 0 ),
+  softwareItalic(false),
+  softwareBold(false)
 {
 }
 
index 79e1996..6bf9208 100644 (file)
@@ -44,14 +44,16 @@ struct DALI_ADAPTOR_API GlyphInfo
    */
   GlyphInfo( FontId font, GlyphIndex i );
 
-  FontId fontId;     ///< Identifies the font containing the glyph
-  GlyphIndex index;  ///< Uniquely identifies a glyph for a given FontId
-  float width;       ///< The width of the glyph
-  float height;      ///< The height of the glyph
-  float xBearing;    ///< The distance from the cursor position to the leftmost border of the glyph
-  float yBearing;    ///< The distance from the baseline to the topmost border of the glyph
-  float advance;     ///< The distance to move the cursor for this glyph
-  float scaleFactor; ///< The scaling applied (fixed-size fonts only)
+  FontId fontId;       ///< Identifies the font containing the glyph
+  GlyphIndex index;    ///< Uniquely identifies a glyph for a given FontId
+  float width;         ///< The width of the glyph
+  float height;        ///< The height of the glyph
+  float xBearing;      ///< The distance from the cursor position to the leftmost border of the glyph
+  float yBearing;      ///< The distance from the baseline to the topmost border of the glyph
+  float advance;       ///< The distance to move the cursor for this glyph
+  float scaleFactor;   ///< The scaling applied (fixed-size fonts only)
+  bool softwareItalic; ///< Whether glyph needs software support to draw italic style
+  bool softwareBold;   ///< Whether glyph needs software support to draw bold style
 };
 
 } // Dali
index 6e081af..4d3126b 100644 (file)
@@ -246,11 +246,11 @@ bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType typ
   return mPlugin->GetGlyphMetrics( array, size, type, horizontal );
 }
 
-void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
+void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
 {
   CreatePlugin();
 
-  mPlugin->CreateBitmap( fontId, glyphIndex, data, outlineWidth );
+  mPlugin->CreateBitmap( fontId, glyphIndex, softwareItalic, softwareBold, data, outlineWidth );
 }
 
 PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
index cfa3a20..0bbba30 100644 (file)
@@ -169,9 +169,9 @@ public:
   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal );
 
   /**
-   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
+   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
    */
-  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
+  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
index fc85a4b..ba65f4d 100644 (file)
@@ -43,6 +43,7 @@ Dali::Integration::Log::Filter* gLogFilter = Dali::Integration::Log::Filter::New
  */
 const float FROM_266 = 1.0f / 64.0f;
 const float POINTS_PER_INCH = 72.f;
+const FT_Fixed FONT_SLANT_TANGENT = 0.221694663 * 0x10000; // For support software italic
 
 const std::string FONT_FORMAT( "TrueType" );
 const std::string DEFAULT_FONT_FAMILY_NAME( "Tizen" );
@@ -1071,7 +1072,7 @@ bool FontClient::Plugin::GetVectorMetrics( GlyphInfo* array,
 #endif
 }
 
-void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
+void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
 {
   if( ( fontId > 0 ) &&
       ( fontId - 1u < mFontFaceCache.size() ) )
@@ -1094,6 +1095,19 @@ void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dal
     if( FT_Err_Ok == error )
     {
       FT_Glyph glyph;
+
+      if( softwareBold )
+      {
+        FT_GlyphSlot_Embolden(ftFace->glyph);
+      }
+
+      if( softwareItalic )
+      {
+        // FT Matrix uses 16.16 fixed-point format
+        FT_Matrix transform = {0x10000, FONT_SLANT_TANGENT, 0x00000, 0x10000};
+        FT_Outline_Transform(&ftFace->glyph->outline, &transform);
+      }
+
       error = FT_Get_Glyph( ftFace->glyph, &glyph );
 
       // Convert to bitmap if necessary
@@ -1159,7 +1173,7 @@ PixelData FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex
 {
   TextAbstraction::FontClient::GlyphBufferData data;
 
-  CreateBitmap( fontId, glyphIndex, data, outlineWidth );
+  CreateBitmap( fontId, glyphIndex, false, false, data, outlineWidth );
 
   return PixelData::New( data.buffer,
                          data.width * data.height * Pixel::GetBytesPerPixel( data.format ),
index 4de27b7..7971aa5 100644 (file)
@@ -35,6 +35,7 @@ class VectorFontCache;
 #include FT_GLYPH_H
 #include FT_OUTLINE_H
 #include FT_STROKER_H
+#include FT_SYNTHESIS_H
 
 // forward declarations of font config types.
 struct _FcCharSet;
@@ -299,9 +300,9 @@ struct FontClient::Plugin
   bool GetVectorMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
 
   /**
-   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
+   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
    */
-  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
+  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, bool softwareItalic, bool softwareBold, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )