瀏覽代碼

Working events

Patryk Konopka 10 年之前
父節點
當前提交
dc37832b9c

+ 9 - 10
Source/Core/BitmapFont/FontFaceHandle.cpp

@@ -67,8 +67,9 @@ bool FontFaceHandle::Initialise(BitmapFontDefinitions *bm_face, const String& _c
 {
     this->bm_face = bm_face;
     size = _size;
-    TextureWidth = bm_face->CommonCharactersInfo.ScaleWidth;
-    TextureHeight = bm_face->CommonCharactersInfo.ScaleHeight;
+    line_height = _size;
+    texture_width = bm_face->CommonCharactersInfo.ScaleWidth;
+    texture_height = bm_face->CommonCharactersInfo.ScaleHeight;
     raw_charset = _charset;
 
     // Construct proper path to texture
@@ -76,15 +77,15 @@ bool FontFaceHandle::Initialise(BitmapFontDefinitions *bm_face, const String& _c
     URL bitmap_source = bm_face->Face.BitmapSource;
     if(bitmap_source.GetPath().Empty())
     {
-        TextureSource = fnt_source.GetPath() + bitmap_source.GetFileName();
+        texture_source = fnt_source.GetPath() + bitmap_source.GetFileName();
         if(!bitmap_source.GetExtension().Empty())
         {
-            TextureSource += "." + bitmap_source.GetExtension();
+            texture_source += "." + bitmap_source.GetExtension();
         }
     }
     else
     {
-        TextureSource = bitmap_source.GetPathedFileName();
+        texture_source = bitmap_source.GetPathedFileName();
     }
 
     if (!UnicodeRange::BuildList(charset, raw_charset))
@@ -305,12 +306,10 @@ void FontFaceHandle::GenerateMetrics(BitmapFontDefinitions *bm_face)
     line_height = bm_face->CommonCharactersInfo.LineHeight;
     baseline = bm_face->CommonCharactersInfo.BaseLine;
 
-    underline_position = (float)line_height - bm_face->CommonCharactersInfo.BaseLine;//FT_MulFix(ft_face->underline_position, ft_face->size->metrics.y_scale) / float(1 << 6);
-    /*underline_thickness = FT_MulFix(ft_face->underline_thickness, ft_face->size->metrics.y_scale) / float(1 << 6);
-    underline_thickness = Math::Max(underline_thickness, 1.0f);
-*/
-    baseline += int( underline_position / 1.5f );
+    underline_position = (float)line_height - bm_face->CommonCharactersInfo.BaseLine;
+    baseline += int( underline_position / 1.6f );
     underline_thickness = 1.0f;
+
     average_advance = 0;
     for (FontGlyphList::iterator i = glyphs.begin(); i != glyphs.end(); ++i)
         average_advance += i->advance;

+ 7 - 7
Source/Core/BitmapFont/FontFaceHandle.h

@@ -95,17 +95,17 @@ public:
 
     const String & GetTextureSource() const
     {
-        return TextureSource;
+        return texture_source;
     }
 
     unsigned int GetTextureWidth() const
     {
-        return TextureWidth;
+        return texture_width;
     }
 
     unsigned int GetTextureHeight() const
     {
-        return TextureHeight;
+        return texture_height;
     }
 
 protected:
@@ -123,10 +123,10 @@ private:
     virtual FontFaceLayer* GenerateLayer(FontEffect* font_effect);
 
     BitmapFontDefinitions * bm_face;
-    String TextureSource;
-    String TextureDirectory;
-    unsigned int TextureWidth;
-    unsigned int TextureHeight;
+    String texture_source;
+    String texture_directory;
+    unsigned int texture_width;
+    unsigned int texture_height;
 };
 
 }

+ 3 - 10
Source/Core/BitmapFont/FontFaceLayer.cpp

@@ -41,27 +41,20 @@ FontFaceLayer::FontFaceLayer() : Rocket::Core::FontFaceLayer()
 
 FontFaceLayer::~FontFaceLayer()
 {
-    //if (effect != NULL)
-    //    effect->RemoveReference();
 }
 
 // Generates the character and texture data for the layer.
 bool FontFaceLayer::Initialise(const Rocket::Core::FontFaceHandle* _handle, FontEffect* _effect, const Rocket::Core::FontFaceLayer* clone, bool deep_clone)
 {
+    (void)(_effect);
+
     Rocket::Core::BitmapFont::FontFaceHandle
         * bm_font_face_handle;
 
     handle = _handle;
-    //effect = _effect;
 
     bm_font_face_handle = ( Rocket::Core::BitmapFont::FontFaceHandle * ) handle;
 
-    if (effect != NULL)
-    {
-        //effect->AddReference();
-        //Log::Message( Log::LT_WARNING, "Effects are not supported" );
-    }
-
     const FontGlyphList& glyphs = handle->GetGlyphs();
 
     // Clone the geometry and textures from the clone layer.
@@ -96,7 +89,7 @@ bool FontFaceLayer::Initialise(const Rocket::Core::FontFaceHandle* _handle, Font
             Vector2i glyph_dimensions = glyph.dimensions; // size of char
 
             Character character;
-            character.origin = Vector2f((float) (glyph.bearing.x), (float) (glyph.bearing.y));
+            character.origin = Vector2f((float) (glyph.bearing.x), (float) (glyph.bearing.y) - handle->GetBaseline()*3 );
             character.dimensions = Vector2f((float) glyph.dimensions.x, (float) glyph.dimensions.y);
 
             // Set the character's texture index.

+ 27 - 27
Source/Core/BitmapFont/FontParser.cpp

@@ -35,7 +35,7 @@ namespace BitmapFont {
 FontParser::FontParser( BitmapFontDefinitions *face )
     : BaseXMLParser()
 {
-    BM_face = face;
+    bm_face = face;
     char_id = 0;
     kern_id = 0;
 }
@@ -49,49 +49,49 @@ void FontParser::HandleElementStart(const String& name, const XMLAttributes& att
 {
     if ( name == "info" )
     {
-        BM_face->Face.FamilyName = attributes.Get( "face" )->Get< String >();
-        BM_face->Face.Size = attributes.Get( "size" )->Get< int >();
-        BM_face->Face.Weight = attributes.Get( "bold" )->Get< bool >() ? Font::WEIGHT_BOLD : Font::WEIGHT_NORMAL;
-        BM_face->Face.Style = attributes.Get( "italic" )->Get< bool >() ? Font::STYLE_ITALIC : Font::STYLE_NORMAL;
-        BM_face->Face.BitmapSource = attributes.Get( "src" )->Get< String >();
+        bm_face->Face.FamilyName = attributes.Get( "face" )->Get< String >();
+        bm_face->Face.Size = attributes.Get( "size" )->Get< int >();
+        bm_face->Face.Weight = attributes.Get( "bold" )->Get< bool >() ? Font::WEIGHT_BOLD : Font::WEIGHT_NORMAL;
+        bm_face->Face.Style = attributes.Get( "italic" )->Get< bool >() ? Font::STYLE_ITALIC : Font::STYLE_NORMAL;
+        bm_face->Face.BitmapSource = attributes.Get( "src" )->Get< String >();
     }
     else if ( name == "common" )
     {
-        BM_face->CommonCharactersInfo.LineHeight = attributes.Get( "lineHeight" )->Get< int >();
-        BM_face->CommonCharactersInfo.BaseLine = attributes.Get( "base" )->Get< int >();
-        BM_face->CommonCharactersInfo.ScaleWidth = attributes.Get( "scaleW" )->Get< int >();
-        BM_face->CommonCharactersInfo.ScaleHeight = attributes.Get( "scaleH" )->Get< int >();
-        BM_face->CommonCharactersInfo.CharacterCount = 0;
-        BM_face->CommonCharactersInfo.KerningCount = 0;
+        bm_face->CommonCharactersInfo.LineHeight = attributes.Get( "lineHeight" )->Get< int >();
+        bm_face->CommonCharactersInfo.BaseLine = attributes.Get( "base" )->Get< int >() * -1;
+        bm_face->CommonCharactersInfo.ScaleWidth = attributes.Get( "scaleW" )->Get< int >();
+        bm_face->CommonCharactersInfo.ScaleHeight = attributes.Get( "scaleH" )->Get< int >();
+        bm_face->CommonCharactersInfo.CharacterCount = 0;
+        bm_face->CommonCharactersInfo.KerningCount = 0;
     }
     else if ( name == "chars" )
     {
-        BM_face->CommonCharactersInfo.CharacterCount = attributes.Get( "count" )->Get< int >();
-        BM_face->CharactersInfo = new CharacterInfo[ attributes.Get( "count" )->Get< int >() ];
+        bm_face->CommonCharactersInfo.CharacterCount = attributes.Get( "count" )->Get< int >();
+        bm_face->CharactersInfo = new CharacterInfo[ attributes.Get( "count" )->Get< int >() ];
     }
     else if ( name == "char" )
     {
-        BM_face->CharactersInfo[ char_id ].Id = attributes.Get( "id" )->Get< int >();
-        BM_face->CharactersInfo[ char_id ].X = attributes.Get( "x" )->Get< int >(); //The left position of the character image in the texture.
-        BM_face->CharactersInfo[ char_id ].Y = attributes.Get( "y" )->Get< int >(); //The top position of the character image in the texture.
-        BM_face->CharactersInfo[ char_id ].Width = attributes.Get( "width" )->Get< int >(); //The width of the character image in the texture.
-        BM_face->CharactersInfo[ char_id ].Height = attributes.Get( "height" )->Get< int >(); //The height of the character image in the texture.
-        BM_face->CharactersInfo[ char_id ].XOffset = attributes.Get( "xoffset" )->Get< int >();
-        BM_face->CharactersInfo[ char_id ].YOffset = attributes.Get( "yoffset" )->Get< int >();
-        BM_face->CharactersInfo[ char_id ].Advance = attributes.Get( "xadvance" )->Get< int >();
+        bm_face->CharactersInfo[ char_id ].Id = attributes.Get( "id" )->Get< int >();
+        bm_face->CharactersInfo[ char_id ].X = attributes.Get( "x" )->Get< int >(); //The left position of the character image in the texture.
+        bm_face->CharactersInfo[ char_id ].Y = attributes.Get( "y" )->Get< int >(); //The top position of the character image in the texture.
+        bm_face->CharactersInfo[ char_id ].Width = attributes.Get( "width" )->Get< int >(); //The width of the character image in the texture.
+        bm_face->CharactersInfo[ char_id ].Height = attributes.Get( "height" )->Get< int >(); //The height of the character image in the texture.
+        bm_face->CharactersInfo[ char_id ].XOffset = attributes.Get( "xoffset" )->Get< int >();
+        bm_face->CharactersInfo[ char_id ].YOffset = attributes.Get( "yoffset" )->Get< int >();
+        bm_face->CharactersInfo[ char_id ].Advance = attributes.Get( "xadvance" )->Get< int >();
 
         char_id++;
     }
     else if ( name == "kernings" )
     {
-        BM_face->CommonCharactersInfo.KerningCount = attributes.Get( "count" )->Get< int >();
-        BM_face->KerningsInfo = new KerningInfo[ attributes.Get( "count" )->Get< int >() ];
+        bm_face->CommonCharactersInfo.KerningCount = attributes.Get( "count" )->Get< int >();
+        bm_face->KerningsInfo = new KerningInfo[ attributes.Get( "count" )->Get< int >() ];
     }
     else if ( name == "kerning" )
     {
-        BM_face->KerningsInfo[ kern_id ].FirstCharacterId = attributes.Get( "first" )->Get< int >();
-        BM_face->KerningsInfo[ kern_id ].SecondCharacterId = attributes.Get( "second" )->Get< int >();
-        BM_face->KerningsInfo[ kern_id ].KerningAmount = attributes.Get( "amount" )->Get< int >();
+        bm_face->KerningsInfo[ kern_id ].FirstCharacterId = attributes.Get( "first" )->Get< int >();
+        bm_face->KerningsInfo[ kern_id ].SecondCharacterId = attributes.Get( "second" )->Get< int >();
+        bm_face->KerningsInfo[ kern_id ].KerningAmount = attributes.Get( "amount" )->Get< int >();
 
         kern_id++;
     }

+ 1 - 1
Source/Core/BitmapFont/FontParser.h

@@ -57,7 +57,7 @@ class FontParser : public BaseXMLParser
 
     private:
         FontParser();
-        BitmapFontDefinitions *BM_face;
+        BitmapFontDefinitions *bm_face;
         int char_id;
         int kern_id;
 };

+ 3 - 34
Source/Core/BitmapFont/FontProvider.cpp

@@ -130,46 +130,15 @@ bool FontProvider::LoadFontFace(const String& file_name, const String& family, F
 
 bool FontProvider::LoadFontFace(const byte* data, int data_length)
 {
-    //    BM_Font *bm_font = (BM_Font*) instance->LoadFace(data, data_length, family, false);
-    //    if (bm_font == NULL)
-    //    {
-    //        Log::Message(Log::LT_ERROR, "Failed to load font face from byte stream.");
-    //        return false;
-    //    }
-
-    //    if (instance->AddFace(bm_font, bm_font->Face.FamilyName, style, weight, false))
-    //    {
-    //        Log::Message(Log::LT_INFO, "Loaded font face %s (from byte stream).", bm_font->Face.FamilyName.CString());
-    //        return true;
-    //    }
-    //    else
-    //    {
-    //        Log::Message(Log::LT_ERROR, "Failed to load font face %s (from byte stream).", bm_font->Face.FamilyName.CString());
-    //        return false;
-    //    }
+    // TODO: Loading from memory
     return false;
 }
 
 // Adds a new font face to the database, loading from memory.
 bool FontProvider::LoadFontFace(const byte* data, int data_length, const String& family, Font::Style style, Font::Weight weight)
 {
-//    BM_Font *bm_font = (BM_Font*) instance->LoadFace(data, data_length, family, false);
-//    if (bm_font == NULL)
-//    {
-//        Log::Message(Log::LT_ERROR, "Failed to load font face from byte stream.");
-//        return false;
-//    }
-
-//    if (instance->AddFace(bm_font, family, style, weight, false))
-//    {
-//        Log::Message(Log::LT_INFO, "Loaded font face %s (from byte stream).", bm_font->Face.FamilyName.CString());
-//        return true;
-//    }
-//    else
-//    {
-//        Log::Message(Log::LT_ERROR, "Failed to load font face %s (from byte stream).", bm_font->Face.FamilyName.CString());
-//        return false;
-//    }
+    // TODO Loading from memory
+    return false;
 }
 
 // Adds a loaded face to the appropriate font family.