pingus-cvs
[Top][All Lists]
Advanced

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

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


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2693 - in branches/pingus_sdl: data/images/fonts src
Date: Thu, 18 Jan 2007 20:23:39 +0100

Author: grumbel
Date: 2007-01-18 20:23:38 +0100 (Thu, 18 Jan 2007)
New Revision: 2693

Added:
   branches/pingus_sdl/data/images/fonts/chalk_large-iso-8859-1.font
   branches/pingus_sdl/data/images/fonts/chalk_normal-iso-8859-1.font
   branches/pingus_sdl/data/images/fonts/chalk_small-iso-8859-1.font
   branches/pingus_sdl/data/images/fonts/courier_small-iso-8859-1.font
   branches/pingus_sdl/data/images/fonts/pingus-iso-8859-1.font
   branches/pingus_sdl/data/images/fonts/pingus_large.font
   branches/pingus_sdl/data/images/fonts/pingus_small-iso-8859-1.font
   branches/pingus_sdl/data/images/fonts/pingus_small_fix_num-iso-8859-1.font
   branches/pingus_sdl/src/font_description.cpp
   branches/pingus_sdl/src/font_description.hpp
Modified:
   branches/pingus_sdl/src/SConscript
   branches/pingus_sdl/src/font.cpp
   branches/pingus_sdl/src/font.hpp
   branches/pingus_sdl/src/resource.cpp
   branches/pingus_sdl/src/sexpr_file_reader.cpp
Log:
- added some font resource handling

Added: branches/pingus_sdl/data/images/fonts/chalk_large-iso-8859-1.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/chalk_large-iso-8859-1.font   
2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/data/images/fonts/chalk_large-iso-8859-1.font   
2007-01-18 19:23:38 UTC (rev 2693)
@@ -0,0 +1,11 @@
+;; -*- scheme -*-
+(pingus-font
+ (name "Chalk Large")
+ (space-length    20)
+ (alpha-threshold  0)
+ (characters "!\"#$%&'()*+,-./0123456789:;<=>?@"
+             "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+             
"���������������������������������������������������������������������������������������������")
+ (image "data/images/fonts/chalk_large-iso-8859-1.png"))
+
+;; EOF ;;

Added: branches/pingus_sdl/data/images/fonts/chalk_normal-iso-8859-1.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/chalk_normal-iso-8859-1.font  
2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/data/images/fonts/chalk_normal-iso-8859-1.font  
2007-01-18 19:23:38 UTC (rev 2693)
@@ -0,0 +1,11 @@
+;; -*- scheme -*-
+(pingus-font
+ (name "Chalk Normal")
+ (space-length    20)
+ (alpha-threshold  0)
+ (characters "!\"#$%&'()*+,-./0123456789:;<=>?@"
+             "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+             
"���������������������������������������������������������������������������������������������")
+ (image "data/images/fonts/chalk_normal-iso-8859-1.png"))
+
+;; EOF ;;

Added: branches/pingus_sdl/data/images/fonts/chalk_small-iso-8859-1.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/chalk_small-iso-8859-1.font   
2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/data/images/fonts/chalk_small-iso-8859-1.font   
2007-01-18 19:23:38 UTC (rev 2693)
@@ -0,0 +1,11 @@
+;; -*- scheme -*-
+(pingus-font
+ (name "Chalk Small")
+ (space-length    20)
+ (alpha-threshold  0)
+ (characters "!\"#$%&'()*+,-./0123456789:;<=>?@"
+             "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+             
"���������������������������������������������������������������������������������������������")
+ (image "data/images/fonts/chalk_small-iso-8859-1.png"))
+
+;; EOF ;;

Added: branches/pingus_sdl/data/images/fonts/courier_small-iso-8859-1.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/courier_small-iso-8859-1.font 
2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/data/images/fonts/courier_small-iso-8859-1.font 
2007-01-18 19:23:38 UTC (rev 2693)
@@ -0,0 +1,11 @@
+;; -*- scheme -*-
+(pingus-font
+ (name "Pingus Small")
+ (space-length    20)
+ (alpha-threshold  0)
+ (characters "!\"#$%&'()*+,-./0123456789:;<=>?@"
+             "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+             
"���������������������������������������������������������������������������������������������")
+ (image "data/images/fonts/pingus_small-iso-8859-1.png"))
+
+;; EOF ;;

Added: branches/pingus_sdl/data/images/fonts/pingus-iso-8859-1.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/pingus-iso-8859-1.font        
2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/data/images/fonts/pingus-iso-8859-1.font        
2007-01-18 19:23:38 UTC (rev 2693)
@@ -0,0 +1,11 @@
+;; -*- scheme -*-
+(pingus-font
+ (name "Pingus Small")
+ (space-length    20)
+ (alpha-threshold  0)
+ (characters "!\"#$%&'()*+,-./0123456789:;<=>?@"
+             "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+             
"���������������������������������������������������������������������������������������������")
+ (image "data/images/fonts/pingus-iso-8859-1.png"))
+
+;; EOF ;;

Added: branches/pingus_sdl/data/images/fonts/pingus_large.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/pingus_large.font     2007-01-18 
15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/data/images/fonts/pingus_large.font     2007-01-18 
19:23:38 UTC (rev 2693)
@@ -0,0 +1,11 @@
+;; -*- scheme -*-
+(pingus-font
+ (name "Pingus Small")
+ (space-length    20)
+ (alpha-threshold  0)
+ (characters "!\"#$%&'()*+,-./0123456789:;<=>?@"
+             "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+             
"���������������������������������������������������������������������������������������������")
+ (image "data/images/fonts/pingus_large.png"))
+
+;; EOF ;;

Added: branches/pingus_sdl/data/images/fonts/pingus_small-iso-8859-1.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/pingus_small-iso-8859-1.font  
2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/data/images/fonts/pingus_small-iso-8859-1.font  
2007-01-18 19:23:38 UTC (rev 2693)
@@ -0,0 +1,11 @@
+;; -*- scheme -*-
+(pingus-font
+ (name "Pingus Small")
+ (space-length    20)
+ (alpha-threshold  0)
+ (characters "!\"#$%&'()*+,-./0123456789:;<=>?@"
+             "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+             
"���������������������������������������������������������������������������������������������")
+ (image "data/images/fonts/pingus_small-iso-8859-1.png"))
+
+;; EOF ;;

Added: 
branches/pingus_sdl/data/images/fonts/pingus_small_fix_num-iso-8859-1.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/pingus_small_fix_num-iso-8859-1.font  
2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/data/images/fonts/pingus_small_fix_num-iso-8859-1.font  
2007-01-18 19:23:38 UTC (rev 2693)
@@ -0,0 +1,11 @@
+;; -*- scheme -*-
+(pingus-font
+ (name "Pingus Small")
+ (space-length    20)
+ (alpha-threshold  0)
+ (characters "!\"#$%&'()*+,-./0123456789:;<=>?@"
+             "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+             
"���������������������������������������������������������������������������������������������")
+ (image "data/images/fonts/pingus_small-iso-8859-1.png"))
+
+;; EOF ;;

Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript  2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/src/SConscript  2007-01-18 19:23:38 UTC (rev 2693)
@@ -140,6 +140,7 @@
 'sexpr_file_reader.cpp', 
 'fonts.cpp',
 'font.cpp',
+'font_description.cpp',
 'sprite.cpp',
 'fps_counter.cpp', 
 'game_session.cpp', 

Modified: branches/pingus_sdl/src/font.cpp
===================================================================
--- branches/pingus_sdl/src/font.cpp    2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/src/font.cpp    2007-01-18 19:23:38 UTC (rev 2693)
@@ -28,6 +28,7 @@
 #include "SDL.h"
 #include "SDL_image.h"
 #include "font.hpp"
+#include "font_description.hpp"
 
 static bool vline_empty(SDL_Surface* surface, int x, Uint8 threshold)
 {
@@ -49,45 +50,48 @@
 public:
   SDL_Surface* surface;
   SDL_Rect chrs[256];
-  int spacing;
+  int space_length;
   
-  FontImpl(const std::string& name)
+  FontImpl(const FontDescription& desc)
     : surface(0),
-      spacing(20)
+      space_length(desc.space_length)
   {
+    std::cout << "desc.image: " << desc.image << std::endl;
+    std::cout << "desc.space: " << desc.space_length << std::endl;
+    std::cout << "Characters: " << desc.characters << std::endl;
+
     for(int i = 0; i < 256; ++i)
       chrs[i].x = chrs[i].y = chrs[i].w = chrs[i].h = 0;
 
-    std::cout << "Font: Trying to load: " << name << std::endl;
-    surface = IMG_Load("data/images/fonts/chalk_large-iso-8859-1.png"); 
//name.c_str());
+    std::cout << "Font: Trying to load: " << desc.image << std::endl;
+    surface = IMG_Load(desc.image.c_str());
     assert(surface);
 
     SDL_LockSurface(surface);
     
-    std::string characters = 
"!\"#$%&'()*+,-./0123456789:;<=>address@hidden|}~�����������������������������������������������������������������������������������������������";
     std::cout << "Surface: " << surface->w << std::endl;
     int first = -1; // -1 signals no character start found yet
     int chr = 0;
     for(int x = 0; x < surface->w; ++x)
       {
         ///std::cout << x << " " << surface->w << std::endl;
-        if (vline_empty(surface, x, 0))
+        if (vline_empty(surface, x, desc.alpha_threshold))
           {
             if (first != -1) // skipping empty space
               {
-                if (chr < int(characters.size()))
+                if (chr < int(desc.characters.size()))
                   {
-                    std::cout << chr << " " << characters[chr]
+                    std::cout << chr << " " << desc.characters[chr]
                               << " Empty: " << first << " - " << x << 
std::endl;
 
-                    SDL_Rect& rect = chrs[static_cast<unsigned 
char>(characters[chr])];
+                    SDL_Rect& rect = chrs[static_cast<unsigned 
char>(desc.characters[chr])];
                     rect.x = first;
                     rect.y = 0;
                     rect.w = x - first;
                     rect.h = surface->h;
                   }
                 else
-                  std::cout << "Error: Found more characters then are mapped" 
<< std::endl;
+                  std::cout << "Error: Found more desc.characters then are 
mapped" << std::endl;
 
                 chr += 1;
                 
@@ -100,7 +104,7 @@
               first = x;
           }
       }
-    std::cout << "Font: Found " << chr << " expected "  << characters.size() 
<< std::endl;
+    std::cout << "Font: Found " << chr << " expected "  << 
desc.characters.size() << std::endl;
 
     SDL_UnlockSurface(surface);
     std::cout << "Font created successfully" << std::endl;
@@ -120,7 +124,7 @@
       {
         if (text[i] == ' ')
           {
-            dstrect.x += spacing;
+            dstrect.x += space_length;
           }
         else
           {
@@ -132,7 +136,7 @@
               }
             else
               {
-                std::cout << "Font: character " << static_cast<unsigned 
char>(text[i]) << " missing in font" << std::endl;
+                //std::cout << "Font: character " << static_cast<unsigned 
char>(text[i]) << " missing in font" << std::endl;
               }
           }
       }
@@ -169,8 +173,8 @@
 {
 }
 
-Font::Font(const std::string& name)
-  : impl(new FontImpl(name))
+Font::Font(const FontDescription& desc)
+  : impl(new FontImpl(desc))
 {
 }
 

Modified: branches/pingus_sdl/src/font.hpp
===================================================================
--- branches/pingus_sdl/src/font.hpp    2007-01-18 15:43:08 UTC (rev 2692)
+++ branches/pingus_sdl/src/font.hpp    2007-01-18 19:23:38 UTC (rev 2693)
@@ -34,13 +34,14 @@
 #include "shared_ptr.hpp"
 
 class FontImpl;
+class FontDescription;
 
 /** */
 class Font
 {
 public:
   Font();
-  Font(const std::string& name);
+  Font(const FontDescription& desc);
 
   void draw(int, int, const std::string& text, SDL_Surface* target = 0);
   void set_alignment(Origin origin);

Added: branches/pingus_sdl/src/font_description.cpp
===================================================================
--- branches/pingus_sdl/src/font_description.cpp        2007-01-18 15:43:08 UTC 
(rev 2692)
+++ branches/pingus_sdl/src/font_description.cpp        2007-01-18 19:23:38 UTC 
(rev 2693)
@@ -0,0 +1,47 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include "pingus_error.hpp"
+#include "file_reader.hpp"
+#include "font_description.hpp"
+
+FontDescription::FontDescription(const std::string& filename)
+{
+  FileReader reader = FileReader::parse(filename);
+
+  if (reader.get_name() != "pingus-font")
+    {
+      PingusError::raise("FontDescription: not a pingus-font file");
+    }
+  else
+    {
+      reader.read_string("image",        image);
+      reader.read_string("characters",   characters);
+      reader.read_int("space-length",    space_length);
+      reader.read_int("alpha-threshold", alpha_threshold);
+    }
+}
+
+/* EOF */

Added: branches/pingus_sdl/src/font_description.hpp
===================================================================
--- branches/pingus_sdl/src/font_description.hpp        2007-01-18 15:43:08 UTC 
(rev 2692)
+++ branches/pingus_sdl/src/font_description.hpp        2007-01-18 19:23:38 UTC 
(rev 2693)
@@ -0,0 +1,47 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2005 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#ifndef HEADER_FONT_DESCRIPTION_HPP
+#define HEADER_FONT_DESCRIPTION_HPP
+
+/** */
+class FontDescription
+{
+public:
+  /** Image file from which the basic surface is loaded */
+  std::string image;
+
+  int space_length; 
+  int alpha_threshold;
+
+  /** Characters in the font image */
+  std::string characters;
+
+  FontDescription(const std::string& filename);
+};
+
+#endif
+
+/* EOF */

Modified: branches/pingus_sdl/src/resource.cpp
===================================================================
--- branches/pingus_sdl/src/resource.cpp        2007-01-18 15:43:08 UTC (rev 
2692)
+++ branches/pingus_sdl/src/resource.cpp        2007-01-18 19:23:38 UTC (rev 
2693)
@@ -28,6 +28,7 @@
 #include "system.hpp"
 #include "path_manager.hpp"
 #include "globals.hpp"
+#include "font_description.hpp"
 #include "resource.hpp"
 #include "blitter.hpp"
 #include "debug.hpp"
@@ -312,8 +313,9 @@
 Font
 Resource::load_font(const std::string& res_name)
 {
-  ////return Font(res_name, &resmgr);
-  return Font("data/images/" + res_name + ".png");
+  FontDescription desc("data/images/" + res_name + ".font");
+  //("data/images/fonts/chalk_large-iso-8859-1.font");
+  return Font(desc);
 }
 
 void

Modified: branches/pingus_sdl/src/sexpr_file_reader.cpp
===================================================================
--- branches/pingus_sdl/src/sexpr_file_reader.cpp       2007-01-18 15:43:08 UTC 
(rev 2692)
+++ branches/pingus_sdl/src/sexpr_file_reader.cpp       2007-01-18 19:23:38 UTC 
(rev 2693)
@@ -107,20 +107,29 @@
 
   bool read_string(const char* name, std::string& v) const 
   {
+    lisp::Lisp* sub = get_subsection(name);
+    if (sub)
+      {
+        v = "";
+        for(size_t i = 1; i < sub->get_list_size(); ++i)
+          {
+            lisp::Lisp* item = sub->get_list_elem(i);
+            if (item->get_type() == lisp::Lisp::TYPE_STRING)
+              {
+                v += item->get_string();
+              }
+            else if (item->get_type() == lisp::Lisp::TYPE_SYMBOL)
+              {
+                v += item->get_symbol();
+              }
+          }
+      }
+
     // FIXME: add multiline reading here
     lisp::Lisp* item = get_subsection_item(name);
     if (item)
       {
-        if (item->get_type() == lisp::Lisp::TYPE_STRING)
-          {
-            v = item->get_string();
-            return true;
-          }
-        else if (item->get_type() == lisp::Lisp::TYPE_SYMBOL)
-          {
-            v = item->get_symbol();
-            return true;
-          }
+
       }
     return false;
   }
@@ -147,8 +156,6 @@
         v.height = sub->get_list_elem(2)->get_int();
         return true;
       }    
-    std::cout << "Reading size: " << v.width << " " << v.height << std::endl;
-
     return false;
   }
 





reply via email to

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