Retrieve outline glyph from freetype 16/147716/3
authorRichard Huang <r.huang@samsung.com>
Tue, 5 Sep 2017 09:47:51 +0000 (10:47 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Mon, 18 Sep 2017 10:41:53 +0000 (11:41 +0100)
Change-Id: I352d6b4ab2d976e1ad7276cba9d96f7b9c6a3a01

text/dali/devel-api/text-abstraction/font-client.cpp
text/dali/devel-api/text-abstraction/font-client.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 9c56a45..90470d2 100644 (file)
@@ -182,14 +182,14 @@ bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType typ
   return GetImplementation(*this).GetGlyphMetrics( array, size, type, horizontal );
 }
 
   return GetImplementation(*this).GetGlyphMetrics( array, size, type, horizontal );
 }
 
-void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, GlyphBufferData& data )
+void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, GlyphBufferData& data, int outlineWidth )
 {
 {
-  GetImplementation(*this).CreateBitmap( fontId, glyphIndex, data );
+  GetImplementation(*this).CreateBitmap( fontId, glyphIndex, data, outlineWidth );
 }
 
 }
 
-PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
+PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
 {
 {
-  return GetImplementation(*this).CreateBitmap( fontId, glyphIndex );
+  return GetImplementation(*this).CreateBitmap( fontId, glyphIndex, outlineWidth );
 }
 
 void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
 }
 
 void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
index 0a8474d..8c8cfca 100644 (file)
@@ -353,18 +353,20 @@ public:
    * @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] 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 );
+  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, GlyphBufferData& data, int outlineWidth );
 
   /**
    * @brief Create a bitmap representation of a glyph.
    *
    * @param[in] fontId The identifier of the font.
    * @param[in] glyphIndex The index of a glyph within the specified font.
 
   /**
    * @brief Create a bitmap representation of a glyph.
    *
    * @param[in] fontId The identifier of the font.
    * @param[in] glyphIndex The index of a glyph within the specified font.
+   * @param[in] outlineWidth The width of the glyph outline in pixels.
    *
    * @return A valid BufferImage, or an empty handle if the glyph could not be rendered.
    */
    *
    * @return A valid BufferImage, or an empty handle if the glyph could not be rendered.
    */
-  PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
+  PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth );
 
   /**
    * @brief Create a vector representation of a glyph.
 
   /**
    * @brief Create a vector representation of a glyph.
index 2c9948b..4ab90bf 100644 (file)
@@ -246,18 +246,18 @@ bool FontClient::GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType typ
   return mPlugin->GetGlyphMetrics( array, size, type, horizontal );
 }
 
   return mPlugin->GetGlyphMetrics( array, size, type, horizontal );
 }
 
-void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data )
+void FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
 {
   CreatePlugin();
 
 {
   CreatePlugin();
 
-  mPlugin->CreateBitmap( fontId, glyphIndex, data );
+  mPlugin->CreateBitmap( fontId, glyphIndex, data, outlineWidth );
 }
 
 }
 
-PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
+PixelData FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
 {
   CreatePlugin();
 
 {
   CreatePlugin();
 
-  return mPlugin->CreateBitmap( fontId, glyphIndex );
+  return mPlugin->CreateBitmap( fontId, glyphIndex, outlineWidth );
 }
 
 void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
 }
 
 void FontClient::CreateVectorBlob( FontId fontId, GlyphIndex glyphIndex, VectorBlob*& blob, unsigned int& blobLength, unsigned int& nominalWidth, unsigned int& nominalHeight )
index a13715c..cfa3a20 100644 (file)
@@ -169,14 +169,14 @@ public:
   bool GetGlyphMetrics( GlyphInfo* array, uint32_t size, GlyphType type, bool horizontal );
 
   /**
   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 )
+   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
    */
    */
-  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data );
+  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
 
   /**
 
   /**
-   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
+   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
    */
    */
-  PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
+  PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth );
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
index 6e7d294..a1e4cc6 100644 (file)
@@ -1084,7 +1084,7 @@ bool FontClient::Plugin::GetVectorMetrics( GlyphInfo* array,
 #endif
 }
 
 #endif
 }
 
-void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data )
+void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
 {
   if( ( fontId > 0 ) &&
       ( fontId - 1u < mFontCache.size() ) )
 {
   if( ( fontId > 0 ) &&
       ( fontId - 1u < mFontCache.size() ) )
@@ -1114,6 +1114,33 @@ void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dal
       {
         if( glyph->format != FT_GLYPH_FORMAT_BITMAP )
         {
       {
         if( glyph->format != FT_GLYPH_FORMAT_BITMAP )
         {
+          // Check whether we should create a bitmap for the outline
+          if( glyph->format == FT_GLYPH_FORMAT_OUTLINE && outlineWidth > 0 )
+          {
+            // Set up a stroker
+            FT_Stroker stroker;
+            error = FT_Stroker_New(mFreeTypeLibrary, &stroker );
+
+            if ( FT_Err_Ok == error )
+            {
+              FT_Stroker_Set( stroker, outlineWidth * 64, FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0 );
+              error = FT_Glyph_StrokeBorder( &glyph, stroker, 0, 1 );
+
+              if ( FT_Err_Ok == error )
+              {
+                FT_Stroker_Done( stroker );
+              }
+              else
+              {
+                DALI_LOG_ERROR( "FT_Glyph_StrokeBorder Failed with error: %d\n", error );
+              }
+            }
+            else
+            {
+              DALI_LOG_ERROR( "FT_Stroker_New Failed with error: %d\n", error );
+            }
+          }
+
           error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, 0, 1 );
           if ( FT_Err_Ok == error )
           {
           error = FT_Glyph_To_Bitmap( &glyph, FT_RENDER_MODE_NORMAL, 0, 1 );
           if ( FT_Err_Ok == error )
           {
@@ -1141,12 +1168,11 @@ void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dal
   }
 }
 
   }
 }
 
-PixelData FontClient::Plugin::CreateBitmap( FontId fontId,
-                                            GlyphIndex glyphIndex )
+PixelData FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
 {
   TextAbstraction::FontClient::GlyphBufferData data;
 
 {
   TextAbstraction::FontClient::GlyphBufferData data;
 
-  CreateBitmap( fontId, glyphIndex, data );
+  CreateBitmap( fontId, glyphIndex, data, outlineWidth );
 
   return PixelData::New( data.buffer,
                          data.width * data.height * Pixel::GetBytesPerPixel( data.format ),
 
   return PixelData::New( data.buffer,
                          data.width * data.height * Pixel::GetBytesPerPixel( data.format ),
index d0601e7..c1e158f 100644 (file)
@@ -33,6 +33,8 @@ class VectorFontCache;
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include FT_GLYPH_H
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include FT_GLYPH_H
+#include FT_OUTLINE_H
+#include FT_STROKER_H
 
 // forward declarations of font config types.
 struct _FcCharSet;
 
 // forward declarations of font config types.
 struct _FcCharSet;
@@ -295,14 +297,14 @@ struct FontClient::Plugin
   bool GetVectorMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
 
   /**
   bool GetVectorMetrics( GlyphInfo* array, uint32_t size, bool horizontal );
 
   /**
-   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data )
+   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth )
    */
    */
-  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data );
+  void CreateBitmap( FontId fontId, GlyphIndex glyphIndex, Dali::TextAbstraction::FontClient::GlyphBufferData& data, int outlineWidth );
 
   /**
 
   /**
-   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex )
+   * @copydoc Dali::TextAbstraction::FontClient::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth )
    */
    */
-  PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex );
+  PixelData CreateBitmap( FontId fontId, GlyphIndex glyphIndex, int outlineWidth );
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()
 
   /**
    * @copydoc Dali::TextAbstraction::FontClient::CreateVectorBlob()