Re: [AD] load_font patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Sunday 16 January 2005 18:18, Evert Glebbeek wrote:
> Update #1
> This doesn't yet add the scripted font loading, 

Update #2, the scripted (.txt) font loader is attached. Really a lot 
simpler than the old code in the datfont.c plugin, if you ask me. More 
flexibel too, since the old one only really worked with bitmaps.
As yet untested, but I'm going to sleep now.

Evert
/*         ______   ___    ___ 
 *        /\  _  \ /\_ \  /\_ \ 
 *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___ 
 *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
 *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
 *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
 *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
 *                                           /\____/
 *                                           \_/__/
 *
 *
 *      TXT font file reader.
 *
 *      See readme.txt for copyright information.
 */
#include <string.h>
#include "allegro.h"
#include "allegro/internal/aintern.h"




/* load_txt_font:
 *  Loads a scripted font.
 */
FONT *load_txt_font(AL_CONST char *filename, RGB *pal, void *param)
{
   char buf[1024], *font_str, *start_str = 0, *end_str = 0;
   FONT *f, *f2, *f3, *f4;
   PACKFILE *pack;
   int begin, end;

   pack = pack_fopen(filename, F_READ);
   if (!pack) 
      return NULL;

   f = f2 = f3 = NULL;

   while(pack_fgets(buf, sizeof(buf)-1, pack)) {
      font_str = strtok(buf, " \t");
      if (font_str) 
         start_str = strtok(0, " \t");
      if (start_str) 
         end_str = strtok(0, " \t");

      if(!font_str || !start_str || !end_str) {
         _al_free(f);
         pack_fclose(pack);
         return NULL;
      }

      if(font_str[0] == '-')
         font_str = '\0';
         
      begin = strtol(start_str, 0, 0);
        
      if (end_str)
         end = strtol(end_str, 0, 0) + 1;
      else 
         end = -1;

      if(begin <= 0 || (end > 0 && end < begin)) {
         _al_free(f);
         pack_fclose(pack);

         return NULL;
      }

      f2 = load_font(font_str, pal, param);
      if(!f2) {
         _al_free(f);
         pack_fclose(pack);

         return NULL;
      }
      
      f3 = f;
      if (f3) {
         f4 = extract_font_range(f2, begin, end);
         if (f4) {
            f = merge_fonts(f4, f3);
            destroy_font(f4);
         }
         destroy_font(f2);
         destroy_font(f3);
      }
      if (!f)
         f = f2;
    }

    pack_fclose(pack);
    return f;
}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/