From 01a4891a7625e7bccef3e40fa5d7fe4115bfb73f Mon Sep 17 00:00:00 2001 From: "minho.sun" Date: Thu, 26 Jul 2018 17:18:18 +0900 Subject: [PATCH] [4.0] Support software styling 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 --- text/dali/devel-api/text-abstraction/font-client.cpp | 4 ++-- text/dali/devel-api/text-abstraction/font-client.h | 14 ++++++++------ text/dali/devel-api/text-abstraction/glyph-info.cpp | 8 ++++++-- text/dali/devel-api/text-abstraction/glyph-info.h | 18 ++++++++++-------- .../internal/text-abstraction/font-client-impl.cpp | 4 ++-- text/dali/internal/text-abstraction/font-client-impl.h | 4 ++-- .../text-abstraction/font-client-plugin-impl.cpp | 18 ++++++++++++++++-- .../text-abstraction/font-client-plugin-impl.h | 5 +++-- 8 files changed, 49 insertions(+), 26 deletions(-) diff --git a/text/dali/devel-api/text-abstraction/font-client.cpp b/text/dali/devel-api/text-abstraction/font-client.cpp index c823b1b..15c1b87 100644 --- a/text/dali/devel-api/text-abstraction/font-client.cpp +++ b/text/dali/devel-api/text-abstraction/font-client.cpp @@ -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 ) diff --git a/text/dali/devel-api/text-abstraction/font-client.h b/text/dali/devel-api/text-abstraction/font-client.h index 0a9e417..c3a30fa 100644 --- a/text/dali/devel-api/text-abstraction/font-client.h +++ b/text/dali/devel-api/text-abstraction/font-client.h @@ -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. diff --git a/text/dali/devel-api/text-abstraction/glyph-info.cpp b/text/dali/devel-api/text-abstraction/glyph-info.cpp index 2d7c811..898a2d5 100644 --- a/text/dali/devel-api/text-abstraction/glyph-info.cpp +++ b/text/dali/devel-api/text-abstraction/glyph-info.cpp @@ -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) { } diff --git a/text/dali/devel-api/text-abstraction/glyph-info.h b/text/dali/devel-api/text-abstraction/glyph-info.h index 952a302..ad06940 100644 --- a/text/dali/devel-api/text-abstraction/glyph-info.h +++ b/text/dali/devel-api/text-abstraction/glyph-info.h @@ -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 diff --git a/text/dali/internal/text-abstraction/font-client-impl.cpp b/text/dali/internal/text-abstraction/font-client-impl.cpp index ee026cf..b932859 100644 --- a/text/dali/internal/text-abstraction/font-client-impl.cpp +++ b/text/dali/internal/text-abstraction/font-client-impl.cpp @@ -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 ) diff --git a/text/dali/internal/text-abstraction/font-client-impl.h b/text/dali/internal/text-abstraction/font-client-impl.h index 725f0e0..e59b2e1 100644 --- a/text/dali/internal/text-abstraction/font-client-impl.h +++ b/text/dali/internal/text-abstraction/font-client-impl.h @@ -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 ) diff --git a/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp b/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp index 5f5a304..b11fd72 100644 --- a/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp +++ b/text/dali/internal/text-abstraction/font-client-plugin-impl.cpp @@ -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 ), diff --git a/text/dali/internal/text-abstraction/font-client-plugin-impl.h b/text/dali/internal/text-abstraction/font-client-plugin-impl.h index 2e6e35a..f97168b 100644 --- a/text/dali/internal/text-abstraction/font-client-plugin-impl.h +++ b/text/dali/internal/text-abstraction/font-client-plugin-impl.h @@ -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 ) -- 2.7.4