pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2803 - in branches/pingus_sdl: data/images/fonts src


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2803 - in branches/pingus_sdl: data/images/fonts src
Date: Sun, 5 Aug 2007 00:39:43 +0200

Author: grumbel
Date: 2007-08-05 00:39:41 +0200 (Sun, 05 Aug 2007)
New Revision: 2803

Modified:
   branches/pingus_sdl/data/images/fonts/number_fnt.font
   branches/pingus_sdl/data/images/fonts/number_fnt.png
   branches/pingus_sdl/src/font.cpp
   branches/pingus_sdl/src/font_description.cpp
   branches/pingus_sdl/src/font_description.hpp
Log:
- monospace font support

Modified: branches/pingus_sdl/data/images/fonts/number_fnt.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/number_fnt.font       2007-08-04 
21:01:18 UTC (rev 2802)
+++ branches/pingus_sdl/data/images/fonts/number_fnt.font       2007-08-04 
22:39:41 UTC (rev 2803)
@@ -1,6 +1,8 @@
 ;; -*- scheme -*-
 (pingus-font
  (name "LCD")
+ (monospace #t)
+ (char-spacing 0)
  (space-length    9)
  (alpha-threshold  0)
  (characters "0123456789:")

Modified: branches/pingus_sdl/data/images/fonts/number_fnt.png
===================================================================
--- branches/pingus_sdl/data/images/fonts/number_fnt.png        2007-08-04 
21:01:18 UTC (rev 2802)
+++ branches/pingus_sdl/data/images/fonts/number_fnt.png        2007-08-04 
22:39:41 UTC (rev 2803)
@@ -1,5 +1,6 @@
 �PNG
 
-
-A�B�x��ڢ�<7_�Tu�4^�^�8��:w����~}}��>'ջ7�Q��#�vkN^m��^sR���̥�:�$��
-��R���$�����*�ύ�.P�*�I��;�:�J�o]=�՛�=���қ�*����*��x����:address@hidden
\ No newline at end of file
+
+��IZ!��n�q�n�Z�
+����I�
+��Fo������r�-.ҏc�q�W��<_���i�PO�jST 
���MQ���<a�/\���D���]��_���Xq�<�+���,����R���\�T��V����^��؍��8��=��3.�þ�n�M���z��7��yY���f��������U&�
s��\�5���1��B�.}B���_������oJ�9�0
\ No newline at end of file

Modified: branches/pingus_sdl/src/font.cpp
===================================================================
--- branches/pingus_sdl/src/font.cpp    2007-08-04 21:01:18 UTC (rev 2802)
+++ branches/pingus_sdl/src/font.cpp    2007-08-04 22:39:41 UTC (rev 2803)
@@ -54,10 +54,12 @@
   SDL_Surface* surface;
   SDL_Rect chrs[256];
   int space_length;
+  int char_spacing;
   
   FontImpl(const FontDescription& desc)
     : surface(0),
-      space_length(desc.space_length)
+      space_length(desc.space_length),
+      char_spacing(desc.char_spacing)
   {
     //std::cout << "desc.image: " << desc.image << std::endl;
     //std::cout << "desc.space: " << desc.space_length << std::endl;
@@ -66,9 +68,9 @@
     for(int i = 0; i < 256; ++i)
       chrs[i].x = chrs[i].y = chrs[i].w = chrs[i].h = 0;
 
-    // FIXME: Need monospace support
     surface = IMG_Load(desc.image.c_str());
     assert(surface);
+
     if (surface->format->BitsPerPixel != 32)
       {
         std::cout << "Error: '" << desc.filename << "' invalid, fonts need to 
be RGBA, but is "
@@ -78,61 +80,80 @@
         
     SDL_LockSurface(surface);
     
-    int first = -1; // -1 signals no character start found yet
-    int idx = 0;
-    for(int x = 0; x <= surface->w; ++x) // '<=' so we scan one past
-                                         // the last line, to catch
-                                         // the last character
+    if (!desc.monospace)
       {
-        if (!vline_empty(surface, x, desc.alpha_threshold))
-          { // line contains a character
-            if (first == -1) 
-              { // found the start of a character
-                first = x;
-              } 
-            else 
-              {
-                // do nothing and continue to search for an end
+        int first = -1; // -1 signals no character start found yet
+        int idx = 0;
+        for(int x = 0; x <= surface->w; ++x) // '<=' so we scan one past
+          // the last line, to catch
+          // the last character
+          {
+            if (!vline_empty(surface, x, desc.alpha_threshold))
+              { // line contains a character
+                if (first == -1) 
+                  { // found the start of a character
+                    first = x;
+                  } 
+                else 
+                  {
+                    // do nothing and continue to search for an end
+                  }
               }
-          }
-        else
-          { // line doesn't contain a character
-            if (first != -1) 
-              { // we have a start and a end, so lets construct a char
+            else
+              { // line doesn't contain a character
+                if (first != -1) 
+                  { // we have a start and a end, so lets construct a char
 
-                if (idx < int(desc.characters.size()))
-                  {
-                    //std::cout << idx << " '" << desc.characters[idx] << "' " 
-                    //          <<  " glyph: " << first << " - " << x << 
std::endl;
+                    if (idx < int(desc.characters.size()))
+                      {
+                        //std::cout << idx << " '" << desc.characters[idx] << 
"' " 
+                        //          <<  " glyph: " << first << " - " << x << 
std::endl;
 
-                    SDL_Rect& rect = chrs[static_cast<unsigned 
char>(desc.characters[idx])];
-                    rect.x = first;
-                    rect.y = 0;
-                    rect.w = x - first;
-                    rect.h = surface->h;
+                        SDL_Rect& rect = chrs[static_cast<unsigned 
char>(desc.characters[idx])];
+                        rect.x = first;
+                        rect.y = 0;
+                        rect.w = x - first;
+                        rect.h = surface->h;
+                      }
+                    else
+                      {
+                        std::cout << "Error: Found more desc.characters then 
are mapped" << std::endl;
+                      }
+
+                    idx += 1;
+                    first = -1;
                   }
-                else
-                  {
-                    std::cout << "Error: Found more desc.characters then are 
mapped" << std::endl;
-                  }
-
-                idx += 1;
-                first = -1;
               }
           }
+
+        if (idx != int(desc.characters.size())) 
+          {
+            std::cout << "Font: " << desc.image << "\n"
+                      << "  Error: glyphs found: " << idx << ", expected "  << 
desc.characters.size() << "\n"
+                      << "  Format: bpp: " << 
int(surface->format->BitsPerPixel) << "\n"
+                      << "  Size: " << surface->w << "x" << surface->h
+              //      << "  RMask: " << hex << surface->format->Rmask << "\n"
+              //      << "  GMask: " << hex << surface->format->Gmask << "\n"
+              //      << "  BMask: " << hex << surface->format->Bmask << "\n"
+              //      << "  AMask: " << hex << surface->format->Amask << "\n"
+                      << std::endl;
+          }
       }
-    
-    if (idx != int(desc.characters.size())) 
+    else // monospace
       {
-        std::cout << "Font: " << desc.image << "\n"
-                  << "  Error: glyphs found: " << idx << ", expected "  << 
desc.characters.size() << "\n"
-                  << "  Format: bpp: " << int(surface->format->BitsPerPixel) 
<< "\n"
-                  << "  Size: " << surface->w << "x" << surface->h
-          //      << "  RMask: " << hex << surface->format->Rmask << "\n"
-          //      << "  GMask: " << hex << surface->format->Gmask << "\n"
-          //      << "  BMask: " << hex << surface->format->Bmask << "\n"
-          //      << "  AMask: " << hex << surface->format->Amask << "\n"
-                  << std::endl;
+        assert(surface->w % desc.characters.size() == 0);
+
+        space_length = surface->w / desc.characters.size();
+        
+        for(int i = 0; i < int(desc.characters.size()); ++i)
+          {
+            SDL_Rect& rect = chrs[static_cast<unsigned 
char>(desc.characters[i])];
+            
+            rect.x = i * space_length;
+            rect.y = 0;
+            rect.w = space_length;
+            rect.h = surface->h;
+          }
       }
 
     SDL_UnlockSurface(surface);
@@ -168,7 +189,7 @@
               {
                SDL_Rect dstrect = { dstx, dsty, 0, 0 };
                 SDL_BlitSurface(surface, &srcrect, target, &dstrect);
-                dstx += srcrect.w+1;
+                dstx += srcrect.w + char_spacing;
               }
             else
               {

Modified: branches/pingus_sdl/src/font_description.cpp
===================================================================
--- branches/pingus_sdl/src/font_description.cpp        2007-08-04 21:01:18 UTC 
(rev 2802)
+++ branches/pingus_sdl/src/font_description.cpp        2007-08-04 22:39:41 UTC 
(rev 2803)
@@ -31,12 +31,13 @@
   : filename(filename_)
 {
   name            = "<unknown>";
+  monospace       = false;
   space_length    = 20;
   alpha_threshold = 0;
+  char_spacing    = 1;
 
   FileReader reader = FileReader::parse(filename);
 
-  // FIXME: We need support for monospace fonts
   if (reader.get_name() != "pingus-font")
     {
       PingusError::raise("FontDescription: not a pingus-font file");
@@ -46,6 +47,8 @@
       reader.read_string("name",         name);
       reader.read_string("image",        image);
       reader.read_string("characters",   characters);
+      reader.read_bool("monospace",      monospace);
+      reader.read_int("char-spacing",   char_spacing);
       reader.read_int("space-length",    space_length);
       reader.read_int("alpha-threshold", alpha_threshold);
     }

Modified: branches/pingus_sdl/src/font_description.hpp
===================================================================
--- branches/pingus_sdl/src/font_description.hpp        2007-08-04 21:01:18 UTC 
(rev 2802)
+++ branches/pingus_sdl/src/font_description.hpp        2007-08-04 22:39:41 UTC 
(rev 2803)
@@ -38,9 +38,17 @@
   /** Image file from which the basic surface is loaded */
   std::string image;
 
-  int space_length; 
-  int alpha_threshold;
+  bool monospace;
+  
+  /** Length of the space character, ignored with monospace fonts */
+  int  space_length; 
 
+  /** Space between two characters */
+  int char_spacing;
+
+  /** Minimum amount of alpha that is handled as character seperator */
+  int  alpha_threshold;
+
   /** Characters in the font image */
   std::string characters;
 





reply via email to

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