pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3966 - trunk/pingus/src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3966 - trunk/pingus/src
Date: Wed, 25 Feb 2009 21:35:36 +0100

Author: grumbel
Date: 2009-02-25 21:35:36 +0100 (Wed, 25 Feb 2009)
New Revision: 3966

Modified:
   trunk/pingus/src/font.cpp
   trunk/pingus/src/font_description.cpp
   trunk/pingus/src/font_description.hpp
Log:
Finished support for multiple images per font file

Modified: trunk/pingus/src/font.cpp
===================================================================
--- trunk/pingus/src/font.cpp   2009-02-25 20:00:08 UTC (rev 3965)
+++ trunk/pingus/src/font.cpp   2009-02-25 20:35:36 UTC (rev 3966)
@@ -30,7 +30,7 @@
 class FontImpl
 {
 public:
-  FramebufferSurface framebuffer_surface;
+  std::vector<FramebufferSurface> framebuffer_surfaces;
   typedef std::vector<GlyphDescription*> Glyphs;
   Glyphs glyphs;
   int    space_length;
@@ -42,23 +42,42 @@
     : char_spacing(desc.char_spacing),
       size(desc.size)
   {
-    framebuffer_surface = 
Display::get_framebuffer().create_surface(Surface(desc.images[0].pathname));
-
-    if (!framebuffer_surface)
-      {
-        std::cout << "IMG: " << desc.images[0].pathname.str() << std::endl;
-        assert(false);
-      }
-
     vertical_spacing = size * desc.vertical_spacing;
    
-    glyphs.resize(65536); // 16bit ought to be enough for everybody
+    glyphs.resize(65536, 0); // 16bit ought to be enough for everybody
 
     // Copyh Unicode -> Glyph mapping 
-    for(std::vector<GlyphDescription>::const_iterator i = 
desc.images[0].glyphs.begin(); i != desc.images[0].glyphs.end(); ++i)
+    for(std::vector<GlyphImageDescription>::size_type j = 0; j < 
desc.images.size(); ++j)
       {
-        if (i->unicode < glyphs.size())
-          glyphs[i->unicode] = new GlyphDescription(*i);
+        
framebuffer_surfaces.push_back(Display::get_framebuffer().create_surface(Surface(desc.images[j].pathname)));
+
+        if (!framebuffer_surfaces.back())
+          {
+            std::cout << "IMG: " << desc.images[j].pathname.str() << std::endl;
+            assert(false);
+          }
+
+        for(std::vector<GlyphDescription>::const_iterator i = 
desc.images[j].glyphs.begin();
+            i != desc.images[j].glyphs.end();
+            ++i)
+          {
+            if (i->unicode < glyphs.size())
+              {
+                if (glyphs[i->unicode] == 0)
+                  {
+                    glyphs[i->unicode] = new GlyphDescription(*i);
+                    glyphs[i->unicode]->image = framebuffer_surfaces.size()-1;
+                  }
+                else
+                  {
+                    std::cout << "Warning: unicode collision on " << 
i->unicode << std::endl;
+                  }            
+              }
+            else
+              {
+                std::cout << "Warning: unicode out of range: " << i->unicode 
<< std::endl;
+              }
+          }
       }
   }
 
@@ -97,7 +116,8 @@
         if (unicode < glyphs.size() && glyphs[unicode])
           {
             const GlyphDescription& glyph = *glyphs[unicode];
-            fb.draw_surface(framebuffer_surface, glyph.rect, 
Vector2i(static_cast<int>(dstx), static_cast<int>(dsty)) + glyph.offset);
+            fb.draw_surface(framebuffer_surfaces[glyph.image],
+                            glyph.rect, Vector2i(static_cast<int>(dstx), 
static_cast<int>(dsty)) + glyph.offset);
             dstx += glyph.advance + char_spacing;
           }
         else

Modified: trunk/pingus/src/font_description.cpp
===================================================================
--- trunk/pingus/src/font_description.cpp       2009-02-25 20:00:08 UTC (rev 
3965)
+++ trunk/pingus/src/font_description.cpp       2009-02-25 20:35:36 UTC (rev 
3966)
@@ -20,13 +20,14 @@
 
 
 GlyphDescription::GlyphDescription()
-  : unicode(0), advance(0)
+  : image(0), unicode(0), advance(0)
 {
   
 }
 
 GlyphDescription::GlyphDescription(FileReader& reader)
 {
+  image = 0;
   int lazy = 0; // FIXME: implement read_uint32
   reader.read_int("unicode", lazy);
   unicode = lazy;

Modified: trunk/pingus/src/font_description.hpp
===================================================================
--- trunk/pingus/src/font_description.hpp       2009-02-25 20:00:08 UTC (rev 
3965)
+++ trunk/pingus/src/font_description.hpp       2009-02-25 20:35:36 UTC (rev 
3966)
@@ -27,6 +27,7 @@
 class GlyphDescription
 {
 public:
+  int      image;
   uint32_t unicode; 
   Vector2i offset;
   int      advance; 
@@ -43,7 +44,7 @@
   Pathname pathname;
 
   /** Characters in the font image */
-  std::vector<GlyphDescription> glyphs;  
+  std::vector<GlyphDescription> glyphs;
 };
 
 /** */





reply via email to

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