Merge "[4.0] Support software styling" into tizen_4.0
authorminho.sun <minho.sun@samsung.com>
Fri, 10 Aug 2018 02:19:37 +0000 (02:19 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Fri, 10 Aug 2018 02:19:37 +0000 (02:19 +0000)
1  2 
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

@@@ -255,11 -255,11 +255,11 @@@ bool FontClient::GetGlyphMetrics( Glyph
    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 )
@@@ -297,13 -297,6 +297,13 @@@ bool FontClient::AddCustomFontDirectory
    return mPlugin->AddCustomFontDirectory( path );
  }
  
 +FT_FaceRec_* FontClient::GetFreetypeFace( FontId fontId )
 +{
 +  CreatePlugin();
 +
 +  return mPlugin->GetFreetypeFace( fontId );
 +}
 +
  void FontClient::CreatePlugin()
  {
    if( !mPlugin )
@@@ -24,9 -24,6 +24,9 @@@
  // INTERNAL INCLUDES
  #include <dali/devel-api/text-abstraction/font-client.h>
  
 +
 +struct FT_FaceRec_;
 +
  namespace Dali
  {
  
@@@ -177,9 -174,9 +177,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 )
     */
    bool AddCustomFontDirectory( const FontPath& path );
  
 +  /**
 +   * @brief Retrieves the pointer to the FreeType Font Face for the given @p fontId.
 +   *
 +   * @param[in] fontId The font id.
 +   *
 +   * @return The pointer to the FreeType Font Face.
 +   */
 +  FT_FaceRec_* GetFreetypeFace( FontId fontId );
 +
  private:
  
    /**
@@@ -44,6 -44,7 +44,7 @@@ Dali::Integration::Log::Filter* gLogFil
   */
  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 +1098,7 @@@ bool FontClient::Plugin::GetVectorMetri
  #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() ) )
      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 +1199,7 @@@ PixelData FontClient::Plugin::CreateBit
  {
    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 ),
@@@ -1288,19 -1302,6 +1302,19 @@@ bool FontClient::Plugin::AddCustomFontD
    return FcConfigAppFontAddDir( nullptr, reinterpret_cast<const FcChar8 *>( path.c_str() ) );
  }
  
 +FT_FaceRec_* FontClient::Plugin::GetFreetypeFace( FontId fontId )
 +{
 +  FT_Face fontFace = nullptr;
 +
 +  if( ( fontId > 0u ) &&
 +      ( fontId - 1u < mFontFaceCache.size() ) )
 +  {
 +    fontFace = mFontFaceCache[fontId - 1u].mFreeTypeFace;
 +  }
 +
 +  return fontFace;
 +}
 +
  void FontClient::Plugin::InitSystemFonts()
  {
    DALI_LOG_INFO( gLogFilter, Debug::General, "-->FontClient::Plugin::InitSystemFonts\n" );
@@@ -35,6 -35,7 +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 +305,9 @@@ struct FontClient::Plugi
    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 )
     */
    bool AddCustomFontDirectory( const FontPath& path );
  
 +  /**
 +   * @copydoc Dali::TextAbstraction::Internal::FontClient::GetFreetypeFace()
 +   */
 +  FT_FaceRec_* GetFreetypeFace( FontId fontId );
 +
  private:
  
    /**