MacArthur, Ian (SELEX GALILEO, UK) wrote:

So - anyone got any useful tips for measuring actual text extents on
win32? (Short of just calling Cairo!)

Answering my own question (see, it's got so bad now, I'm talking to
myself via email, not just verbally) the solution seems to be to do
something compicated... Convert the text string into a series of glyphs,
then measure the glyphs using GetGlyphOutlineW(...) et al. Urgh.

Well, I can't contribute much, but here are my two notes:

(1) IMHO, the "windows fl_measure bug" should be fixed, because measuring text should be as platform neutral as possible, if feasible.

(2) fl_measure should keep delivering a constant height value, as Bill suggested, and as you confirmed by using an alternate approach. IMHO we need to be able to measure multiline text for labels with constant line spacing, and editors should have constant line spacing as well. Maybe lots of code depend on this feature.


FWIW, I wrote a small demonstration program to see how fl_measure works now. I append measure.cxx, together with measure.png that shows the output of the three test versions (from left to right) that are mentioned in measure.txt (the text output of these three versions): Windows, FLTK 1.1 / Linux, FLTK 1.1, non-Xft / Linux, FLTK 1.3, Xft.

Interesting point: the windows version seems to be off by a few pixels for the "off" box width. The text is chosen to demonstrate different glyph ascent and descent values. Maybe you can use the "how" argument to substitute your new functions for testing.

Hth

Albrecht
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl.H>
#include <FL/fl_draw.h>

#include <stdio.h>

#define FONT FL_TIMES
// #define FONT FL_HELVETICA
#define SIZE 24
// #define BOXTYPE FL_DOWN_BOX
#define BOXTYPE FL_FRAME_BOX

void
make_box (int &X, int &Y, int &W, int &H, char *L, int how=0)
{
  fl_font(FONT,SIZE);
  W = H = 0;
  fl_measure(L,W,H);
  int dw = Fl::box_dw(BOXTYPE);
  int dh = Fl::box_dh(BOXTYPE);
  W += dw;
  H += dh;
  printf ("X=%3d, Y=%3d, W=%3d, H=%3d, dw=%d, dh=%d\n",X,Y,W,H,dw,dh);
  Fl_Box *b = new Fl_Box(X,Y,W,H,L);
  b->labelfont(FONT);
  b->labelsize(SIZE);
  b->box(BOXTYPE);
  b->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER);
  
  X += W + 10;
}

int
main (int argc, char **argv)
{
  Fl_Window *w = new Fl_Window (500,500);
  int X=20, Y=20, W, H;
  
  make_box(X,Y,W,H,"on");
  make_box(X,Y,W,H,"off");
  make_box(X,Y,W,H,"toggle");

  X = 20; Y = 100;
  
  make_box(X,Y,W,H,"on\non\non\non\non\non");
  make_box(X,Y,W,H,"off\noff\noff\noff\noff\noff");
  make_box(X,Y,W,H,"toggle\ntoggle\ntoggle\ntoggle\ntoggle\ntoggle");
  
  w->end();
  w->show(argc,argv);
  return Fl::run();
}

<<inline: measure.png>>

Windows, FLTK 1.1:

X= 20, Y= 20, W= 28, H= 31, dw=4, dh=4
X= 58, Y= 20, W= 32, H= 31, dw=4, dh=4
X=100, Y= 20, W= 62, H= 31, dw=4, dh=4
X= 20, Y=100, W= 28, H=166, dw=4, dh=4
X= 58, Y=100, W= 32, H=166, dw=4, dh=4
X=100, Y=100, W= 62, H=166, dw=4, dh=4

Linux, FLTK 1.1, non-Xft:

X= 20, Y= 20, W= 29, H= 30, dw=4, dh=4
X= 59, Y= 20, W= 30, H= 30, dw=4, dh=4
X= 99, Y= 20, W= 64, H= 30, dw=4, dh=4
X= 20, Y=100, W= 29, H=160, dw=4, dh=4
X= 59, Y=100, W= 30, H=160, dw=4, dh=4
X= 99, Y=100, W= 64, H=160, dw=4, dh=4

Linux, FLTK 1.3, Xft:

X= 20, Y= 20, W= 33, H= 33, dw=4, dh=4
X= 63, Y= 20, W= 36, H= 33, dw=4, dh=4
X=109, Y= 20, W= 80, H= 33, dw=4, dh=4
X= 20, Y=100, W= 33, H=178, dw=4, dh=4
X= 63, Y=100, W= 36, H=178, dw=4, dh=4
X=109, Y=100, W= 80, H=178, dw=4, dh=4
_______________________________________________
fltk-dev mailing list
fltk-dev@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to