Improved calculation of text width and height when using the PostScript graphics context
under X11 or Xft. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8437 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
eb0b154ffd
commit
3adac027c4
@ -272,8 +272,8 @@ static const char * prolog =
|
||||
// show at position with desired width
|
||||
// usage:
|
||||
// width (string) x y show_pos_width
|
||||
"/show_pos_width {GS moveto dup dup stringwidth pop exch length 2 div 1 sub dup 0 eq {pop 1} if "
|
||||
"exch 3 index exch sub exch "
|
||||
"/show_pos_width {GS moveto dup dup stringwidth pop exch length 2 div dup 2 le {pop 9999} if "
|
||||
"1 sub exch 3 index exch sub exch "
|
||||
"div 0 2 index 1 -1 scale ashow pop pop GR} bind def\n" // spacing altered to match desired width
|
||||
//"/show_pos_width {GS moveto dup stringwidth pop 3 2 roll exch div -1 matrix scale concat "
|
||||
//"show GR } bind def\n" // horizontally scaled text to match desired width
|
||||
@ -931,16 +931,17 @@ static const char *_fontNames[] = {
|
||||
};
|
||||
|
||||
void Fl_PostScript_Graphics_Driver::font(int f, int s) {
|
||||
Fl_Display_Device::display_device()->driver()->font(f,s); // Use display fonts for font measurement
|
||||
Fl_Graphics_Driver *driver = Fl_Display_Device::display_device()->driver();
|
||||
driver->font(f,s); // Use display fonts for font measurement
|
||||
Fl_Graphics_Driver::font(f, s);
|
||||
Fl_Font_Descriptor *desc = driver->font_descriptor();
|
||||
this->font_descriptor(desc);
|
||||
if (f < FL_FREE_FONT) {
|
||||
int ps_size = s;
|
||||
fprintf(output, "/%s SF\n" , _fontNames[f]);
|
||||
#if defined(USE_X11) && !USE_XFT
|
||||
// Non-Xft fonts can have a different size from that required.
|
||||
// Give to the PostScript font the same size as that used on the display
|
||||
Fl_Font_Descriptor *desc = Fl_Display_Device::display_device()->driver()->font_descriptor();
|
||||
this->font_descriptor(desc);
|
||||
char *name = desc->font->font_name_list[0];
|
||||
char *p = strstr(name, "--");
|
||||
if (p) {
|
||||
|
@ -278,47 +278,36 @@ void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
|
||||
}
|
||||
}
|
||||
|
||||
#define current_font (fl_graphics_driver->font_descriptor()->font)
|
||||
int fl_height() {
|
||||
Fl_Graphics_Driver *driver = Fl_Display_Device::display_device()->driver();
|
||||
if (driver->font_descriptor()) {
|
||||
XUtf8FontStruct *font = driver->font_descriptor()->font;
|
||||
return (font->ascent + font->descent);
|
||||
}
|
||||
if (fl_graphics_driver->font_descriptor()) return current_font->ascent + current_font->descent;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
int fl_descent() {
|
||||
Fl_Graphics_Driver *driver = Fl_Display_Device::display_device()->driver();
|
||||
if (driver->font_descriptor()) {
|
||||
return driver->font_descriptor()->font->descent;
|
||||
}
|
||||
if (fl_graphics_driver->font_descriptor()) return current_font->descent;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
double fl_width(const char* c, int n) {
|
||||
Fl_Graphics_Driver *driver = Fl_Display_Device::display_device()->driver();
|
||||
if (driver->font_descriptor())
|
||||
return (double) XUtf8TextWidth(driver->font_descriptor()->font, c, n);
|
||||
if (fl_graphics_driver->font_descriptor()) return (double) XUtf8TextWidth(current_font, c, n);
|
||||
else return -1;
|
||||
}
|
||||
|
||||
double fl_width(unsigned int c) {
|
||||
Fl_Graphics_Driver *driver = Fl_Display_Device::display_device()->driver();
|
||||
if (driver->font_descriptor())
|
||||
return (double) XUtf8UcsWidth(driver->font_descriptor()->font, c);
|
||||
if (fl_graphics_driver->font_descriptor()) return (double) XUtf8UcsWidth(current_font, c);
|
||||
else return -1;
|
||||
}
|
||||
|
||||
void fl_text_extents(const char *c, int n, int &dx, int &dy, int &W, int &H) {
|
||||
Fl_Graphics_Driver *driver = Fl_Display_Device::display_device()->driver();
|
||||
if (font_gc != fl_gc) {
|
||||
if (!driver->font_descriptor()) driver->font(FL_HELVETICA, FL_NORMAL_SIZE);
|
||||
if (!fl_graphics_driver->font_descriptor()) fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
|
||||
font_gc = fl_gc;
|
||||
XSetFont(fl_display, fl_gc, driver->font_descriptor()->font->fid);
|
||||
XSetFont(fl_display, fl_gc, current_font->fid);
|
||||
}
|
||||
int xx, yy, ww, hh;
|
||||
xx = yy = ww = hh = 0;
|
||||
if (fl_gc) XUtf8_measure_extents(fl_display, fl_window, driver->font_descriptor()->font, fl_gc, &xx, &yy, &ww, &hh, c, n);
|
||||
if (fl_gc) XUtf8_measure_extents(fl_display, fl_window, current_font, fl_gc, &xx, &yy, &ww, &hh, c, n);
|
||||
|
||||
W = ww; H = hh; dx = xx; dy = yy;
|
||||
// This is the safe but mostly wrong thing we used to do...
|
||||
@ -326,7 +315,7 @@ void fl_text_extents(const char *c, int n, int &dx, int &dy, int &W, int &H) {
|
||||
// fl_measure(c, W, H, 0);
|
||||
// dx = 0;
|
||||
// dy = fl_descent() - H;
|
||||
} // fl_text_extents
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::draw(const char* c, int n, int x, int y) {
|
||||
if (font_gc != fl_gc) {
|
||||
|
@ -115,15 +115,15 @@ void *fl_xftfont = 0;
|
||||
//const char* fl_encoding_ = "iso8859-1";
|
||||
const char* fl_encoding_ = "iso10646-1";
|
||||
|
||||
static void fl_font(Fl_Font fnum, Fl_Fontsize size, int angle) {
|
||||
static void fl_font(Fl_Xlib_Graphics_Driver *driver, Fl_Font fnum, Fl_Fontsize size, int angle) {
|
||||
if (fnum==-1) { // special case to stop font caching
|
||||
fl_graphics_driver->Fl_Graphics_Driver::font(0, 0);
|
||||
driver->Fl_Graphics_Driver::font(0, 0);
|
||||
return;
|
||||
}
|
||||
Fl_Font_Descriptor* f = fl_graphics_driver->font_descriptor();
|
||||
if (fnum == fl_graphics_driver->font() && size == fl_graphics_driver->size() && f && f->angle == angle)
|
||||
Fl_Font_Descriptor* f = driver->font_descriptor();
|
||||
if (fnum == driver->Fl_Graphics_Driver::font() && size == driver->size() && f && f->angle == angle)
|
||||
return;
|
||||
fl_graphics_driver->Fl_Graphics_Driver::font(fnum, size);
|
||||
driver->Fl_Graphics_Driver::font(fnum, size);
|
||||
Fl_Fontdesc *font = fl_fonts + fnum;
|
||||
// search the fontsizes we have generated already
|
||||
for (f = font->first; f; f = f->next) {
|
||||
@ -135,7 +135,7 @@ static void fl_font(Fl_Font fnum, Fl_Fontsize size, int angle) {
|
||||
f->next = font->first;
|
||||
font->first = f;
|
||||
}
|
||||
fl_graphics_driver->font_descriptor(f);
|
||||
driver->font_descriptor(f);
|
||||
#if XFT_MAJOR < 2
|
||||
fl_xfont = f->font->u.core.font;
|
||||
#else
|
||||
@ -145,7 +145,7 @@ static void fl_font(Fl_Font fnum, Fl_Fontsize size, int angle) {
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
|
||||
fl_font(fnum,size,0);
|
||||
fl_font(this,fnum,size,0);
|
||||
}
|
||||
|
||||
static XftFont* fontopen(const char* name, bool core, int angle) {
|
||||
@ -580,8 +580,8 @@ void fl_destroy_xft_draw(Window id) {
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::draw(const char *str, int n, int x, int y) {
|
||||
if ( !fl_graphics_driver->font_descriptor() ) {
|
||||
fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
|
||||
if ( !this->font_descriptor() ) {
|
||||
this->font(FL_HELVETICA, FL_NORMAL_SIZE);
|
||||
}
|
||||
#if USE_OVERLAY
|
||||
XftDraw*& draw_ = fl_overlay ? draw_overlay : ::draw_;
|
||||
@ -622,9 +622,9 @@ void Fl_Xlib_Graphics_Driver::draw(const char *str, int n, int x, int y) {
|
||||
}
|
||||
|
||||
void Fl_Xlib_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) {
|
||||
fl_font(fl_graphics_driver->font(), fl_graphics_driver->size(), angle);
|
||||
fl_draw(str, n, (int)x, (int)y);
|
||||
fl_font(fl_graphics_driver->font(), fl_graphics_driver->size());
|
||||
fl_font(this, this->Fl_Graphics_Driver::font(), this->size(), angle);
|
||||
this->draw(str, n, (int)x, (int)y);
|
||||
this->font(this->Fl_Graphics_Driver::font(), this->size());
|
||||
}
|
||||
|
||||
static void fl_drawUCS4(const FcChar32 *str, int n, int x, int y) {
|
||||
|
Loading…
Reference in New Issue
Block a user