return new GlyphSet::Character(bitmapData, glyphMetrics);
}
+Integration::BitmapPtr GetGlyphBitmap( FT_Face face, FT_ULong charCode )
+{
+ Integration::BitmapPtr image;
+
+ FT_Glyph ftGlyph = GetGlyph( face, charCode, FT_LOAD_RENDER );
+ if( NULL != ftGlyph )
+ {
+ FT_Error ftError = FT_Err_Ok;
+
+ // convert glyph to bitmap
+ if( ftGlyph->format != FT_GLYPH_FORMAT_BITMAP )
+ {
+ ftError = FT_Glyph_To_Bitmap( &ftGlyph, FT_RENDER_MODE_NORMAL, 0, 1 );
+
+ if( ftError != FT_Err_Ok)
+ {
+ DALI_LOG_WARNING( "FT_Glyph_To_Bitmap failed %d\n", ftError );
+ FT_Done_Glyph( ftGlyph );
+ return image;
+ }
+ }
+
+ // cast the FT_Glyph to a FT_BitmapGlyph
+ FT_BitmapGlyph ftBitmapGlyph = (FT_BitmapGlyph)ftGlyph;
+
+ // access the underlying bitmap data
+ FT_Bitmap ftBitmap = ftBitmapGlyph->bitmap;
+
+ const std::size_t size = ftBitmap.width * ftBitmap.rows;
+ if( 0 < size )
+ {
+ image = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, true );
+ image->GetPackedPixelsProfile()->ReserveBuffer( Pixel::A8, ftBitmap.width, ftBitmap.rows );
+
+ memcpy( static_cast<unsigned char*>( image->GetBuffer() ), ftBitmap.buffer, size );
+ }
+
+ // finished with glyph, so, release it
+ FT_Done_Glyph( ftGlyph );
+ }
+
+ return image;
+}
+
} // namespace SlpPlatform
} // namespace Dali
const Vector2& maxGlyphCell,
const bool renderBitmap, const bool highQuality );
+/**
+ * Retrieves a glyph's image from the given Freetype face object.
+ *
+ * @param[in] face Freetype face object.
+ * @param[in] charCode UCS4 character code (UTF32).
+ *
+ * @return The glyph's image for the given character.
+ */
+Integration::BitmapPtr GetGlyphBitmap( FT_Face face, FT_ULong charCode );
+
} // namespace SlpPlatform
} // namespace Dali
return result;
}
+Integration::BitmapPtr ResourceLoader::GetGlyphImage( FT_Library freeType, const std::string& fontFamily, const std::string& fontStyle, const float fontSize, const uint32_t character )
+{
+ Integration::BitmapPtr image;
+
+ const std::string fontFileName = GetFontPath( fontFamily, fontStyle );
+ SlpFace* slpFace = LoadFontFace( fontFileName, PixelSize( Font::PointsToPixels( fontSize ) ), freeType );
+
+ if( NULL != slpFace )
+ {
+ image = GetGlyphBitmap( slpFace->face, character );
+ }
+
+ return image;
+}
+
void ResourceLoader::SetDefaultFontFamily( const std::string& fontFamily, const std::string& fontStyle )
{
mImpl->mFontController->SetDefaultFontFamily( Platform::FontController::StyledFontFamily( fontFamily, fontStyle ) );
*/
void SetDefaultFontFamily( const std::string& fontFamily, const std::string& fontStyle );
+ /**
+ * Retrieves the glyp's image representing the given character.
+ *
+ * @param[in] freeType Handle to the FreeType library.
+ * @param[in] fontFamily The font's family name.
+ * @param[in] fontStyle The font's style.
+ * @param[in] fontSize The font's size.
+ * @param[in] character The given character.
+ *
+ * @return The bitmap image.
+ */
+ Integration::BitmapPtr GetGlyphImage( FT_Library freeType, const std::string& fontFamily, const std::string& fontStyle, const float fontSize, const uint32_t character );
+
private:
/**
#include "slp-platform-abstraction.h"
#include <vconf.h>
+#include <dirent.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/bitmap.h>
return mDefaultFontSize;
}
-const PixelSize SlpPlatformAbstraction::GetFontLineHeightFromCapsHeight(const std::string fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight) const
+const PixelSize SlpPlatformAbstraction::GetFontLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight) const
{
PixelSize result(0);
MetricsCache::Write( fontFamily, fontStyle, glyphSet );
}
+void SlpPlatformAbstraction::GetFileNamesFromDirectory( const std::string& directoryName,
+ std::vector<std::string>& fileNames )
+{
+ dirent* de = NULL;
+ DIR* dp;
+ dp = opendir( directoryName.c_str() );
+ if( dp )
+ {
+ const std::string dot( "." );
+ const std::string dotDot( ".." );
+ while( true )
+ {
+ de = readdir( dp );
+ if( de == NULL )
+ {
+ break;
+ }
+ const std::string fileName( de->d_name );
+ if( ( fileName != dot ) &&
+ ( fileName != dotDot ) )
+ {
+ fileNames.push_back( fileName );
+ }
+ }
+ closedir( dp );
+ }
+}
+
+Integration::BitmapPtr SlpPlatformAbstraction::GetGlyphImage( const std::string& fontFamily, const std::string& fontStyle, const float fontSize, const uint32_t character ) const
+{
+ Integration::BitmapPtr glyphImage;
+
+ if( mResourceLoader )
+ {
+ glyphImage = mResourceLoader->GetGlyphImage( mFreeTypeHandle, fontFamily, fontStyle, fontSize, character );
+ }
+
+ return glyphImage;
+}
+
} // namespace SlpPlatform
} // namespace Dali
/**
*@copydoc PlatformAbstraction::GetFontLineHeightFromCapsHeight()
*/
- virtual const PixelSize GetFontLineHeightFromCapsHeight(const std::string fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight) const;
+ virtual const PixelSize GetFontLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight) const;
/**
* @copydoc PlatformAbstraction::GetGlyphData()
const std::string& fontStyle,
const Integration::GlyphSet& glyphSet );
+ /**
+ * @copydoc PlatformAbstraction::GetFileNamesFromDirectory()
+ */
+ virtual void GetFileNamesFromDirectory( const std::string& directoryName,
+ std::vector<std::string>& fileNames );
+
+ /**
+ * @copydoc PlatformAbstraction::GetGlyphImage()
+ */
+ virtual Integration::BitmapPtr GetGlyphImage( const std::string& fontFamily, const std::string& fontStyle, float fontSize, uint32_t character ) const;
+
private:
ResourceLoader* mResourceLoader;
FT_Library mFreeTypeHandle; ///< Freetype library