From 95d52d6c221703c2797513afb71283bec47e0c83 Mon Sep 17 00:00:00 2001 From: "minho.sun" Date: Thu, 26 Jul 2018 17:18:18 +0900 Subject: [PATCH] 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: I898fd967eb571437789dc5c84444f8091dc88ee6 Signed-off-by: minho.sun --- dali/devel-api/text-abstraction/font-client.cpp | 4 ++-- dali/devel-api/text-abstraction/font-client.h | 14 ++++++++------ dali/devel-api/text-abstraction/glyph-info.cpp | 8 ++++++-- dali/devel-api/text-abstraction/glyph-info.h | 18 ++++++++++-------- .../text/text-abstraction/font-client-impl.cpp | 4 ++-- dali/internal/text/text-abstraction/font-client-impl.h | 4 ++-- .../text/text-abstraction/font-client-plugin-impl.cpp | 18 ++++++++++++++++-- .../text/text-abstraction/font-client-plugin-impl.h | 5 +++-- 8 files changed, 49 insertions(+), 26 deletions(-) diff --git a/dali/devel-api/text-abstraction/font-client.cpp b/dali/devel-api/text-abstraction/font-client.cpp index e49410a..2dcb128 100644 --- a/dali/devel-api/text-abstraction/font-client.cpp +++ b/dali/devel-api/text-abstraction/font-client.cpp @@ -182,9 +182,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/dali/devel-api/text-abstraction/font-client.h b/dali/devel-api/text-abstraction/font-client.h index 6411b16..167607d 100755 --- a/dali/devel-api/text-abstraction/font-client.h +++ b/dali/devel-api/text-abstraction/font-client.h @@ -351,12 +351,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/dali/devel-api/text-abstraction/glyph-info.cpp b/dali/devel-api/text-abstraction/glyph-info.cpp index 2d7c811..898a2d5 100644 --- a/dali/devel-api/text-abstraction/glyph-info.cpp +++ b/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/dali/devel-api/text-abstraction/glyph-info.h b/dali/devel-api/text-abstraction/glyph-info.h index 79e1996..6bf9208 100644 --- a/dali/devel-api/text-abstraction/glyph-info.h +++ b/dali/devel-api/text-abstraction/glyph-info.h @@ -44,14 +44,16 @@ struct DALI_ADAPTOR_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/dali/internal/text/text-abstraction/font-client-impl.cpp b/dali/internal/text/text-abstraction/font-client-impl.cpp index 6e081af..4d3126b 100644 --- a/dali/internal/text/text-abstraction/font-client-impl.cpp +++ b/dali/internal/text/text-abstraction/font-client-impl.cpp @@ -246,11 +246,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/dali/internal/text/text-abstraction/font-client-impl.h b/dali/internal/text/text-abstraction/font-client-impl.h index cfa3a20..0bbba30 100644 --- a/dali/internal/text/text-abstraction/font-client-impl.h +++ b/dali/internal/text/text-abstraction/font-client-impl.h @@ -169,9 +169,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/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp b/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp index fc85a4b..ba65f4d 100644 --- a/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp +++ b/dali/internal/text/text-abstraction/font-client-plugin-impl.cpp @@ -43,6 +43,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" ); @@ -1071,7 +1072,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() ) ) @@ -1094,6 +1095,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 @@ -1159,7 +1173,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/dali/internal/text/text-abstraction/font-client-plugin-impl.h b/dali/internal/text/text-abstraction/font-client-plugin-impl.h index 4de27b7..7971aa5 100644 --- a/dali/internal/text/text-abstraction/font-client-plugin-impl.h +++ b/dali/internal/text/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; @@ -299,9 +300,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