[4.0] Support software styling 83/186083/1
authorminho.sun <minho.sun@samsung.com>
Thu, 26 Jul 2018 08:18:18 +0000 (17:18 +0900)
committerminho.sun <minho.sun@samsung.com>
Tue, 7 Aug 2018 06:37:52 +0000 (15:37 +0900)
When DALi fails to find font which support correct style,
apply software styling to glyph.

DALi will support bold / italic by software.

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

index c823b1b..15c1b87 100644 (file)
@@ -187,9 +187,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 0a9e417..c3a30fa 100644 (file)
@@ -356,12 +356,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 952a302..ad06940 100644 (file)
@@ -46,14 +46,16 @@ struct DALI_IMPORT_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 ee026cf..b932859 100644 (file)
@@ -255,11 +255,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 725f0e0..e59b2e1 100644 (file)
@@ -174,9 +174,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 5f5a304..b11fd72 100644 (file)
@@ -44,6 +44,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" );
@@ -1097,7 +1098,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() ) )
@@ -1120,6 +1121,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
@@ -1185,7 +1199,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 2e6e35a..f97168b 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;
@@ -304,9 +305,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 )