Support for loading a scalable graphics font.
authorTimo Korvola <tkorvola@iki.fi>
Thu, 8 Mar 2018 20:43:35 +0000 (22:43 +0200)
committerDavid Griffith <dave@661.org>
Sun, 11 Mar 2018 11:48:50 +0000 (04:48 -0700)
A graphics font can be specified with the "graphics" option
(Fonts section) of .sfrotzrc.  The font is assumed to have fixed width
equal to height and em size (no line gap).  It is scaled to match the
width and height of the fixed width text font (not usually equal,
so the graphics font gets stretched).  Any size specification in the
option is ignored.

Now someone just needs to draw that font.  I made a quick autotrace
in Fontforge but it is rather hideous.

src/sdl/sf_fonts.c
src/sdl/sf_frotz.h
src/sdl/sf_ftype.c
src/sdl/sf_resource.c

index 2a2a0398b2b6c40e74e8464f066bf5b93a270bcc..19638753102e48f5b0cad36db9fe52830f6cc7b9 100644 (file)
@@ -27,7 +27,7 @@ typedef struct {
   int glyphs[0];        // offsets to glyphs from start of rec
   } SF_bdffont;
 
-char * m_fontfiles[8];
+char * m_fontfiles[9];
 
 static char s[1026];
 
@@ -710,10 +710,10 @@ static void destroySFonly( SFONT *f)
 
 extern SFONT *SF_font3, *SF_font3double;
 
-SFONT * (*ttfontloader)( char *fspec, int *err) = NULL;
+SFONT * (*ttfontloader)( char *fspec, SFONT *like, int *err) = NULL;
 void (*ttfontsdone)() = NULL;
 
-static SFONT *tryloadfont( char *fspec)
+static SFONT *tryloadfont( char *fspec, SFONT *like)
   {
   int err,size;
   char *p;
@@ -722,7 +722,7 @@ static SFONT *tryloadfont( char *fspec)
     p = strchr(fspec,'|');
     if (p) *p = 0;
     if (ttfontloader)
-       b = ttfontloader(fspec,&err);
+       b = ttfontloader(fspec, like, &err);
     if (!b)
        b = loadfont(fspec,&err,&size);
     if (b) break;
@@ -824,10 +824,11 @@ void sf_initfonts()
 
   if (!m_vga_fonts)
     {
-    for (i=0;i<8;i++)
+    for (i = 0; i <= 8; i++)
       if (m_fontfiles[i])
        {
-       SFONT *b = tryloadfont(m_fontfiles[i]);
+       SFONT *b = tryloadfont(m_fontfiles[i],
+                              i == 8 ? myfonts[FIXED_WIDTH_FONT] : NULL);
        if (!b) fprintf(stderr,"WARNING: could not load font%d [%s]\n",i,m_fontfiles[i]);
        else
                {
@@ -839,10 +840,11 @@ void sf_initfonts()
 
   if (ttfontsdone) ttfontsdone();
        // now set the graphics font
-  if (myfonts[4]->height(myfonts[4]) < 16)
-       myfonts[8] = SF_font3;
-  else
-       myfonts[8] = SF_font3double;
+  if (!myfonts[8])
+      if (myfonts[4]->height(myfonts[4]) < 16)
+          myfonts[8] = SF_font3;
+      else
+          myfonts[8] = SF_font3double;
 
 //for (i=0;i<8;i++){ SFONT *s = myfonts[i]; printf("%d %p %d %d %d %d %d\n",
 //i,s,s->minchar(s),s->maxchar(s),s->ascent(s),s->descent(s),s->height(s));}
index 50acf920a129d9d506bf2e5d6f4f7337c5fbeb86..8e706f64aaca91ce9cb79e743e7fe6186b8c2198 100644 (file)
@@ -86,7 +86,7 @@ extern int    AcHeight;
 extern int     m_random_seed;
 extern int     m_fullscreen;
 extern int     m_reqW, m_reqH;
-extern char *  m_fontfiles[8];
+extern char *  m_fontfiles[9];
 extern bool    m_localfiles;
 extern int     m_no_sound;
 extern int     m_vga_fonts;
@@ -131,7 +131,7 @@ typedef struct {
 
 typedef struct sfontstruct SFONT;
 
-extern SFONT * (*ttfontloader)( char *fspec, int *err);
+extern SFONT * (*ttfontloader)( char *fspec, SFONT *like, int *err);
 extern void    (*ttfontsdone)();
 
 struct sfontstruct {
index e17de931f24e7169a5ae655c74fc7fba4018216a..8d4457db6c0dd5ddc149e1921985e961aefc9878 100644 (file)
@@ -202,7 +202,7 @@ static void setglyph( MYFONT *f, FT_Face face, int ch)
   f->glyphs[ch] = res;
   }
 
-static SFONT * loadftype( char *fname, int size, int *err)
+static SFONT * loadftype( char *fname, int size, SFONT *like, int *err)
   {
   MYFONT *res;
   FT_Face face;
@@ -219,7 +219,11 @@ static SFONT * loadftype( char *fname, int size, int *err)
   *err = FT_New_Face( library, fname, 0, &face ); /* create face object */
   if (*err){ res->sfont.destroy(&res->sfont); return NULL; }
 
-  *err = FT_Set_Pixel_Sizes( face, size, size);
+  if (like) {
+      SF_glyph *zero = like->getglyph(like, '0', TRUE);
+      *err = FT_Set_Pixel_Sizes( face, zero->dx, like->height(like));
+  } else
+      *err = FT_Set_Pixel_Sizes( face, size, size);
   if (*err){ res->sfont.destroy(&res->sfont); return NULL; }
 
   res->ascent = face->size->metrics.ascender/64;
@@ -247,7 +251,7 @@ static SFONT * loadftype( char *fname, int size, int *err)
 #define SYSFONTS "/usr/share/fonts/freetype"
 #endif
 
-SFONT * sf_loadftype( char *fspec, int *err)
+SFONT * sf_loadftype( char *fspec, SFONT *like, int *err)
   {
   char buf[FILENAME_MAX], *fn, *at, *fenv;
   int size = DEFSIZE, fnlen=-1;
@@ -273,7 +277,7 @@ SFONT * sf_loadftype( char *fspec, int *err)
 
   if (!fn) return NULL;
 
-  return loadftype(fn,size,err);
+  return loadftype(fn, size, like, err);
   }
 
 //////////////////////////////////////////
index f80f5da2a38483e2d2ed7e580393706d7c4427b6..2ea3ec777b97d20c2cc1f15ac316db6c36ef1927 100644 (file)
@@ -442,6 +442,7 @@ void sf_readsettings(void)
   m_fontfiles[5] = sf_GetProfileString("Fonts","fixedbold",NULL);
   m_fontfiles[6] = sf_GetProfileString("Fonts","fixeditalic",NULL);
   m_fontfiles[7] = sf_GetProfileString("Fonts","fixedbolditalic",NULL);
+  m_fontfiles[8] = sf_GetProfileString("Fonts","graphics",NULL);
 
   ResDir = sf_GetProfileString("Resources","Dir",ResDir);
   ResPict = sf_GetProfileString("Resources","Pict",ResPict);