Fix the incorrect offset of text outline 55/216055/3
authorRichard Huang <r.huang@samsung.com>
Fri, 18 Oct 2019 13:41:51 +0000 (14:41 +0100)
committerRichard Huang <r.huang@samsung.com>
Thu, 24 Oct 2019 14:35:45 +0000 (15:35 +0100)
Change-Id: I9fb55dabf3ff8e5519ba05d4c8e0206015b326fd

dali/devel-api/text-abstraction/font-client.cpp
dali/devel-api/text-abstraction/font-client.h
dali/internal/text/text-abstraction/font-client-plugin-impl.cpp

index 4f9172a..8484200 100755 (executable)
@@ -34,6 +34,8 @@ FontClient::GlyphBufferData::GlyphBufferData()
 : buffer{ nullptr },
   width{ 0u },
   height{ 0u },
+  outlineOffsetX{ 0 },
+  outlineOffsetY{ 0 },
   format{ Pixel::A8 },
   isColorEmoji{ false },
   isColorBitmap{ false }
index 2c95f9c..b0219c0 100755 (executable)
@@ -87,6 +87,8 @@ public:
     unsigned char* buffer;          ///< The glyph's bitmap buffer data.
     unsigned int   width;           ///< The width of the bitmap.
     unsigned int   height;          ///< The height of the bitmap.
+    int            outlineOffsetX;  ///< The additional horizontal offset to be added for the glyph's position for outline.
+    int            outlineOffsetY;  ///< The additional vertical offset to be added for the glyph's position for outline.
     Pixel::Format  format;          ///< The pixel's format of the bitmap.
     bool           isColorEmoji:1;  ///< Whether the glyph is an emoji.
     bool           isColorBitmap:1; ///< Whether the glyph is a color bitmap.
index 43bf941..8bae462 100755 (executable)
@@ -1463,9 +1463,34 @@ void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, boo
           {
             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 )
+              int offsetX, offsetY;
+              bool isOutlineGlyph = ( glyph->format == FT_GLYPH_FORMAT_OUTLINE && outlineWidth > 0 );
+
+              // Create a bitmap for the outline
+              if( isOutlineGlyph )
               {
+                // Retrieve the horizontal and vertical distance from the current pen position to the
+                // left and top border of the glyph bitmap for a normal glyph before applying the outline.
+                if( FT_Err_Ok == error )
+                {
+                  FT_Glyph normalGlyph;
+                  error = FT_Get_Glyph( ftFace->glyph, &normalGlyph );
+
+                  error = FT_Glyph_To_Bitmap( &normalGlyph, FT_RENDER_MODE_NORMAL, 0, 1 );
+                  if( FT_Err_Ok == error )
+                  {
+                    FT_BitmapGlyph bitmapGlyph = reinterpret_cast< FT_BitmapGlyph >( normalGlyph );
+
+                    offsetX = bitmapGlyph->left;
+                    offsetY = bitmapGlyph->top;
+                  }
+
+                  // Created FT_Glyph object must be released with FT_Done_Glyph
+                  FT_Done_Glyph( normalGlyph );
+                }
+
+                // Now apply the outline
+
                 // Set up a stroker
                 FT_Stroker stroker;
                 error = FT_Stroker_New( mFreeTypeLibrary, &stroker );
@@ -1494,6 +1519,14 @@ void FontClient::Plugin::CreateBitmap( FontId fontId, GlyphIndex glyphIndex, boo
               if( FT_Err_Ok == error )
               {
                 FT_BitmapGlyph bitmapGlyph = reinterpret_cast< FT_BitmapGlyph >( glyph );
+
+                if( isOutlineGlyph )
+                {
+                  // Calculate the additional horizontal and vertical offsets needed for the position of the outline glyph
+                  data.outlineOffsetX = offsetX - bitmapGlyph->left - outlineWidth;
+                  data.outlineOffsetY = bitmapGlyph->top - offsetY - outlineWidth;
+                }
+
                 ConvertBitmap( data, bitmapGlyph->bitmap, isShearRequired );
               }
               else