pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3863 - trunk/fontgen


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3863 - trunk/fontgen
Date: Fri, 18 Jul 2008 13:40:28 +0200

Author: grumbel
Date: 2008-07-18 13:40:28 +0200 (Fri, 18 Jul 2008)
New Revision: 3863

Modified:
   trunk/fontgen/fontgen.cpp
Log:
Some small bug fixes

Modified: trunk/fontgen/fontgen.cpp
===================================================================
--- trunk/fontgen/fontgen.cpp   2008-07-18 02:00:24 UTC (rev 3862)
+++ trunk/fontgen/fontgen.cpp   2008-07-18 11:40:28 UTC (rev 3863)
@@ -14,7 +14,6 @@
 FT_Library library;
 
 void generate_font(const std::string& filename, int px_size, int border, int 
img_width,
-                   std::ostream& image_stream, 
                    std::ostream& metadata_stream)
 {
   // Read the TTF font file content into buffer
@@ -33,7 +32,6 @@
   FT_Set_Pixel_Sizes(face, px_size, px_size);
   FT_Select_Charmap(face,  FT_ENCODING_UNICODE);
 
-
   std::cout << "BBox: " << px_size << " "
             << px_size * face->bbox.xMin/face->units_per_EM << " " 
             << px_size * face->bbox.yMin/face->units_per_EM << " " 
@@ -52,7 +50,8 @@
 
   FT_ULong  charcode;                                              
   FT_UInt   glyph_index;                                                
-  
+  int row_height = 0;
+
   charcode = FT_Get_First_Char( face, &glyph_index );
   while ( glyph_index != 0 )                                            
     {                                                                          
                            
@@ -65,9 +64,9 @@
         {
           FT_GlyphSlot glyph = face->glyph;;
 
-          //int x_offset =  glyph->bitmap_left;
-          //int y_offset = -glyph->bitmap_top;
-          //int advance = (glyph->advance.x >> 6);
+          int x_offset =  glyph->bitmap_left;
+          int y_offset = -glyph->bitmap_top;
+          int advance = (glyph->advance.x >> 6);
           
           Bitmap glyph_bitmap(glyph->bitmap.width, glyph->bitmap.rows);
 
@@ -80,22 +79,34 @@
           if (x_pos + glyph_bitmap.get_width() + 2*border > 
image_bitmap.get_width())
             {
               x_pos = border;
-              y_pos += px_size + 2*border;
+              y_pos += row_height + 2*border;
+              row_height = glyph_bitmap.get_height();
 
               image_bitmap.blit(glyph_bitmap, x_pos+border, y_pos+border);
-              x_pos += glyph_bitmap.get_width() + 2*border;
             }
           else
             {
+              row_height = std::max(row_height, glyph_bitmap.get_height());
+          
               image_bitmap.blit(glyph_bitmap, x_pos+border, y_pos+border);
-              x_pos += glyph_bitmap.get_width() + 2*border;
             }
+
+          std::cout << "(char "
+                    << "(code " << charcode << ") "
+                    << "(offset " << x_offset << " " << y_offset << ") "
+                    << "(advance " << advance << ") "
+                    << "(rect "
+                    << x_pos << " " << y_pos << " " 
+                    << x_pos+glyph_bitmap.get_width()+border*2 << " " << 
y_pos+glyph_bitmap.get_height()+border*2 << ")"
+                    << ")" << std::endl;
+
+          x_pos += glyph_bitmap.get_width() + 2*border;
         }
 
       charcode = FT_Get_Next_Char( face, charcode, &glyph_index );
     }
 
-  image_bitmap.truncate_height(y_pos + px_size + border);
+  image_bitmap.truncate_height(y_pos + row_height + border);
   image_bitmap.write_pgm("/tmp/out.pgm");
 
   FT_Done_Face(face);
@@ -115,7 +126,6 @@
   int  image_width  = atoi(argv[4]);
 
   std::ofstream metadata_stream("/tmp/output.font");
-  std::ofstream image_stream("/tmp/output.pgm");
 
   std::cout << "Generating image from " << ttf_filename << " with size " << 
pixel_size << " and width " << image_width << std::endl;
 
@@ -128,7 +138,8 @@
         throw std::runtime_error("could not initialize FreeType");   
         
       generate_font(ttf_filename, pixel_size, border, image_width, 
-                    image_stream, metadata_stream);
+                    std::cout);
+      //metadata_stream);
         
       FT_Done_FreeType(library);
     } 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]