freetype
[Top][All Lists]
Advanced

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

Re: [ft] Getting width of space


From: Peter Weilbacher
Subject: Re: [ft] Getting width of space
Date: Sun, 20 May 2007 00:09:21 +0200
User-agent: Mozilla/5.0 (OS/2; U; Warp 4.5; en-US; rv:1.8.1.3pre) Gecko/20070307 SeaMonkey/1.1.1+ Mnenhy/0.7.4.10002

Werner LEMBERG wrote:

>> Could you otherwise give me a hint where in FT I could start
>> debugging, i.e. where the width is calculated?
> 
> Please read the file docs/DEBUG and try those environment variables.

OK, done that and found that I don't understand much of what a run
with FT2_DEBUG=any:5 prints out...

I somehow get the feeling that the problem has not become fully clear.
So I attach a self-contained test program that shows the problem on
both OS/2 and Linux. OS/2 has FT 2.3.4 installed, Linux 2.1.9. So it
should be easily reproducible for everybody, I see the problem with
all .ttf font files that I have tried, including the MS web fonts,
the Bitstream Vera fonts from
<http://ftp.gnome.org/pub/GNOME/sources/ttf-bitstream-vera/1.10/>
and the Workplace Sans font from
<http://www.cs-club.org/~alex/creative/fonts/index.html>.

The output I get when running the program on the Arial font of the
MS web fonts package is this:

   $ ./space_glyph_test ARIAL.TTF
   select 'x'
   gid(x)=91
   loaded 'x'
   width('x')=384/1.500000 (advance=384/1.500000)

   select ' '
   gid(x)=3
   loaded ' '
   width(' ')=0/0.000000 (advance=192/0.750000)

The width for spaces is always zero.

The only thing that I notice when running with FT2_DEBUG=any:5 is
that it prints lots of information about different glyphs before
printing "loaded 'x'" but before printing "loaded ' '" it just says
   tt_face_lookup_table: 0x1bad00, `glyf' -- found table.
but nothing else.

   Peter.
#include <stdio.h>
#include <ft2build.h>
#include FT_FREETYPE_H

int show_widths(FT_Face f, char ch)
{
  FT_UInt gid;
  char *gname[200];
  long w, a;
  double wd, ad;
  double scale = f->units_per_EM / 8; // hack!
  int error = 0;

  printf("select \'%c\'\n", ch);
  gid = FT_Get_Char_Index(f, ch); // select the glyph
  FT_Get_Glyph_Name(f, gid, gname, 200);
  printf("gid(x)=%d, %s\n", gid, gname);
  error = FT_Load_Glyph(f, gid, FT_LOAD_DEFAULT); // load it into the slot
  printf("loaded \'%c\'\n", ch);
  w = f->glyph->metrics.width;
  wd = f->glyph->metrics.width / scale;
  a = f->glyph->advance.x;
  ad = f->glyph->advance.x / scale;

  printf("width(\'%c\')=%ld/%f (advance=%ld/%f)\n\n", ch, w, wd, a, ad);

  return error;
}

// pass a font file on the command line
// e.g.
//    Bitstream-Vera/Vera.ttf
//    WebFonts/ARIAL.TTF
//    WebFonts/VERDANA.TTF
//    wpsu.ttf
int main(int argc, char **argv)
{
  /* startup */
  FT_Library library;
  FT_Init_FreeType(&library);
  FT_Face face;
  int error = FT_New_Face(library, argv[1], 0, &face);
  if (error) {
    printf("error=%d\n", error);
    exit(1);
  }

  error = FT_Set_Char_Size(face, 0, 12 << 6, 0, 120);
  if (error) {
    printf("error=%d\n", error);
    exit(11);
  }

  /* the actual tests */
  error = show_widths(face, '.');
  if (error) {
    printf("xerror=%d\n", error);
    exit(2);
  }
  error = show_widths(face, ' ');
  if (error) {
    printf(" error=%d\n", error);
    exit(3);
  }
  
  /* cleanup */
  error = FT_Done_Face(face);
  if (error) {
    printf("error=%d\n", error);
    exit(4);
  }
  error = FT_Done_FreeType(library);
  if (error) {
    printf("error=%d\n", error);
    exit(5);
  }

  return 0;
}

reply via email to

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