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 be50a67..a9b796d 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 4475683..89838a4 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 0abdded..947348f 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 d4b1f56..0fedd91 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 6b39365..1033877 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 a445ecb..c948ba5 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