Browse Source

Finally works

Patryk Konopka 10 years ago
parent
commit
b6a71b5ec5

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

@@ -77,20 +77,16 @@ bool FontFaceLayer::Initialise(const Rocket::Core::FontFaceHandle* _handle, Font
     else
     {
         // Initialise the texture layout for the glyphs.
-        unsigned int size = glyphs.size();
-        if(size == 0)
-        {
-            return false;
-        }
-
-        characters.resize(glyphs[size - 1].character);
-
+        characters.resize(glyphs.size(), Character());
         for (FontGlyphList::const_iterator i = glyphs.begin(); i != glyphs.end(); ++i)
-        {
+        {            
             const FontGlyph& glyph = *i;
 
+            if(glyph.dimensions.x <= 0 || glyph.dimensions.y <= 0)
+                continue;
+
             Vector2i glyph_origin( glyph.bitmap_dimensions.x, glyph.bitmap_dimensions.y ); // position in texture
-            Vector2i glyph_dimension = glyph.dimensions; // size of char
+            Vector2i glyph_dimensions = glyph.dimensions; // size of char
 
             Character character;
             character.origin = Vector2f((float) (glyph.bearing.x), (float) (glyph.bearing.y));
@@ -107,8 +103,16 @@ bool FontFaceLayer::Initialise(const Rocket::Core::FontFaceHandle* _handle, Font
 
             characters[glyph.character] = character;
 
+            // Add the character's dimensions into the texture layout engine.
+            texture_layout.AddRectangle(glyph.character, glyph_dimensions);
+
         }
 
+        // Generate the texture layout; this will position the glyph rectangles efficiently and
+        // allocate the texture data ready for writing.
+        if (!texture_layout.GenerateLayout(512))
+            return false;
+
         Texture texture;
         if (!texture.Load( bm_font_face_handle->GetTextureBaseName() + "_0.tga", bm_font_face_handle->GetTextureDirectory() ) )
             return false;

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

@@ -49,11 +49,11 @@ void FontParser::HandleElementStart(const String& name, const XMLAttributes& att
 {
     if ( name == "info" )
     {
-        BM_face->Face.FamilyName = "Arial";//attributes.Get( "face" )->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.CharsetName = "";//attributes.Get( "charset" )->Get< String >();
+        BM_face->Face.CharsetName = attributes.Get( "charset" )->Get< String >();
         BM_face->Face.IsUnicode = attributes.Get( "unicode" )->Get< bool >();
         BM_face->Face.StretchHeight = attributes.Get( "stretchH" )->Get< int >();
         BM_face->Face.IsSmoothed = attributes.Get( "smooth" )->Get< bool >();
@@ -84,7 +84,7 @@ void FontParser::HandleElementStart(const String& name, const XMLAttributes& att
     else if ( name == "page" )
     {
         BM_face->PagesInfo[ attributes.Get( "id" )->Get< int >() ].Id = attributes.Get( "id" )->Get< int >();
-        BM_face->PagesInfo[ attributes.Get( "id" )->Get< int >() ].FileName = "Arial_0.tga";//attributes.Get( "file" )->Get< String >();
+        BM_face->PagesInfo[ attributes.Get( "id" )->Get< int >() ].FileName = attributes.Get( "file" )->Get< String >();
     }
     else if ( name == "chars" )
     {

+ 4 - 1
Source/Core/TextureLayoutTexture.cpp

@@ -65,7 +65,10 @@ int TextureLayoutTexture::Generate(TextureLayout& layout, int maximum_dimensions
 
 		if (!rectangle.IsPlaced())
 		{
-			square_pixels += (rectangle.GetDimensions().x + 1) * (rectangle.GetDimensions().y + 1);
+            int x = rectangle.GetDimensions().x + 1;
+            int y = rectangle.GetDimensions().y + 1;
+
+            square_pixels += x*y;
 			++unplaced_rectangles;
 		}
 	}