Emoticons - Read file names from directory. Retrieves bitmaps from the font face. 54/19454/1
authorVictor Cebollada <v.cebollada@samsung.com>
Tue, 1 Apr 2014 08:38:16 +0000 (09:38 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Fri, 11 Apr 2014 14:44:19 +0000 (15:44 +0100)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] N/A

Change-Id: If4c2b99b3132c6c85087cf161dfa3cba5236bc0a
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
platform-abstractions/slp/resource-loader/loader-font.cpp
platform-abstractions/slp/resource-loader/loader-font.h
platform-abstractions/slp/resource-loader/resource-loader.cpp
platform-abstractions/slp/resource-loader/resource-loader.h
platform-abstractions/slp/slp-platform-abstraction.cpp
platform-abstractions/slp/slp-platform-abstraction.h

index be50a674f1eebb36fa734d487fa276931d2e61f2..a9b796d99108c3e3b0c566a60e618ad0eabe966c 100644 (file)
@@ -313,6 +313,50 @@ GlyphSet::Character* GetCharacter(FT_Face face, FT_ULong charcode,
   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
index 4475683e8349a08e100c6a43f4801323fa597816..89838a48c1891c2fa9655f8fb4bf970611a74dd6 100644 (file)
@@ -109,6 +109,16 @@ Integration::GlyphSet::Character* GetCharacter(FT_Face face, const FT_ULong char
                                                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
index 0abdded4aff1fa42759df1d41c175ccf163f9c56..947348f845759228d100997d7fa60b3dcc404d11 100755 (executable)
@@ -892,6 +892,21 @@ bool ResourceLoader::SaveFile(const std::string& filename, std::vector< unsigned
   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 ) );
index d4b1f56604505ff247675aa13cdd1231266f112a..0fedd91296d21e745e9fc85d1a9227d3ab2a10b1 100644 (file)
@@ -364,6 +364,19 @@ public:
    */
   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:
 
   /**
index 6b393651644e96750d7769fed1d2a7659edb2dad..1033877fb8782be5f13b25177b667e624c99bdff 100644 (file)
@@ -17,6 +17,7 @@
 #include "slp-platform-abstraction.h"
 
 #include <vconf.h>
+#include <dirent.h>
 
 #include <dali/integration-api/debug.h>
 #include <dali/integration-api/bitmap.h>
@@ -118,7 +119,7 @@ const float SlpPlatformAbstraction::GetDefaultFontSize() const
   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);
 
@@ -392,6 +393,46 @@ void SlpPlatformAbstraction::WriteMetricsToCache( const std::string& fontFamily,
   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
index a445ecbc50e47fd2321796b272f2a7016106652b..c948ba5b241cb14d30bb3cb5b5b9621766517c0d 100644 (file)
@@ -136,7 +136,7 @@ public: // PlatformAbstraction overrides
   /**
    *@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()
@@ -236,6 +236,17 @@ public: // PlatformAbstraction overrides
                                     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