freetype
[Top][All Lists]
Advanced

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

[ft] Fwd: Calculating terminal emulator cell size


From: Jonathan Glines
Subject: [ft] Fwd: Calculating terminal emulator cell size
Date: Thu, 17 Nov 2016 19:10:18 -0700

I'm using FreeType for a terminal emulator application, and I need
some advice for calculating the appropriate size for cells in the
terminal emulator, given a monospace font.

For bitmap fonts, I'm assuming this is easy (just using
FT_FaceRec.bbox). Let me know if this assumption is incorrect.

For scalable fonts, I'm trying to determine the best way to calculate
terminal cell size given a monospace scalable font of a certain size.
Right now I'm just using FT_FaceRec.bbox as follows:

  double x_pixels_per_unit, y_pixels_per_unit, units_per_em;
  /* Compute a scaling factor to convert from font units to pixels, as
   * described in
   * <https://www.freetype.org/freetype2/docs/tutorial/step2.html> */
  units_per_em = (double)face->units_per_EM;
  x_pixels_per_unit = face->size->metrics.x_ppem / units_per_em;
  y_pixels_per_unit = face->size->metrics.y_ppem / units_per_em;
  cellWidth = (int)ceil(
      (double)(face->bbox.xMax - face->bbox.xMin) * x_pixels_per_unit);
  cellHeight = (int)ceil(
      (double)(face->bbox.yMax - face->bbox.yMin) * y_pixels_per_unit);

My problem is the results appear much too large; with cells this large
there is far too much spacing between glyphs. Assuming my code isn't
buggy, does this mean bbox isn't appropriate for computing terminal
emulator cell size?

I know there is more than one way to do this, but is there a robust
way to calculate the appropriate cell size that will work for most
monospace fonts? Right now I'm only testing with DejaVu Sans Mono, but
I would like to be able to use any font, so I can't use any
font-specific hacks.

Regards,
Jonathan


reply via email to

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