[gl2ps] Font Changes

Christophe Geuzaine geuzaine at acm.caltech.edu
Fri Jul 16 16:56:26 CEST 2004


Shai Ayal wrote:
> I too use fltk. Can you ngive me some hints on the "close enough font" 
> you use ?, or Can you just point me ot the relevant code in gmsh ?
> 

Sure: I use the following correspondance table between PostScript font
names and FLTK fonts (in gmsh/Fltk/GUI.cpp):

Fl_Menu_Item menu_font_names[] = {
   {"Times-Roman",           0, 0, (void*)FL_TIMES},
   {"Times-Bold",            0, 0, (void*)FL_TIMES_BOLD},
   {"Times-Italic",          0, 0, (void*)FL_TIMES_ITALIC},
   {"Times-BoldItalic",      0, 0, (void*)FL_TIMES_BOLD_ITALIC},
   {"Helvetica",             0, 0, (void*)FL_HELVETICA},
   {"Helvetica-Bold",        0, 0, (void*)FL_HELVETICA_BOLD},
   {"Helvetica-Oblique",     0, 0, (void*)FL_HELVETICA_ITALIC},
   {"Helvetica-BoldOblique", 0, 0, (void*)FL_HELVETICA_BOLD_ITALIC},
   {"Courier",               0, 0, (void*)FL_COURIER},
   {"Courier-Bold",          0, 0, (void*)FL_COURIER_BOLD},
   {"Courier-Oblique",       0, 0, (void*)FL_COURIER_ITALIC},
   {"Courier-BoldOblique",   0, 0, (void*)FL_COURIER_BOLD_ITALIC},
   {"Symbol",                0, 0, (void*)FL_SYMBOL},
   {"ZapfDingbats",          0, 0, (void*)FL_ZAPF_DINGBATS},
   {0}
};

and use the following routine to draw text (in Fltk/Opengl.cpp;
CTX.gl_font_enum contains the FLTK font and CTX.gl_font the PostScript
font name):

void Draw_String(char *s)
{
   if(CTX.print.gl_fonts) {
     gl_font(CTX.gl_font_enum, CTX.gl_fontsize);
     gl_draw(s);
   }
   else {
     if(CTX.print.format == FORMAT_JPEGTEX ||
        CTX.print.format == FORMAT_PNGTEX)
       return;
     gl2psText(s, CTX.gl_font, CTX.gl_fontsize);
   }
}

To compute the width of a string in order to position it, I then just
gl_width(string).

Hope this helps,

C.


>     Shai
> 
> Christophe Geuzaine wrote:
> 
>> Shai Ayal wrote:
>>
>>> Hi
>>>
>>> first, thank you for the alignment code. Now OctPlot's hardcopy is 
>>> in-par with it's screen output (not very nice, but it works :) ).
>>>
>>> My future plans are to implement TeX like support. This means the I 
>>> will have to change font/size in the middle of a string. Do you have 
>>> any ideas on how this could be implemented in gl2ps? I understand 
>>> that currently gl2ps has no knowledge of the font metrics, all is 
>>> done by the ps/pdf/tex parser. Can you think of any way to implement 
>>> this (i.e. gl2psText returning the new raster position?).
>>>
>>> The easiest way I can think of (easy for gl3ps) is add a 
>>> gl2psRawPS(char*) function which will allow you to emit raw 
>>> postscript at the current raster position. This approach has a major 
>>> drawback: It will break the abstraction of gl2ps in respect to which 
>>> back-end is used.
>>>
>>> I am eager to hear your thoughts on this
>>>
>>
>> It's a complicated issue... The main question is: do we only want to 
>> reproduce what's on screen, or do we want to have additional features 
>> in the printed output?
>>
>> In the first case, I like the approach followed by the folks that
>> develop FLTK (http://www.fltk.org). They have routines that compute 
>> the font metrics on all platforms (X11, Win32 and Carbon) and you can 
>> use that to position the text accurately in the OpenGL window. All 
>> gl2ps has to do is use a font that is "close enough", and you're all 
>> set--you don't even need the new "align" flags... (I use this approach 
>> in my code: http://geuz.org/gmsh/.)
>>
>> In the second case, you are right: there is no easy way to abstract 
>> the text handling anymore (unless we parse some higher level markup 
>> language!), and we need some mechanism to let users manipulate the 
>> underlying output stream directly. This is in fact what we already do 
>> for LaTeX output, and what a gl2psRawPS(char*) function would do for 
>> PostScript. Not sure if we need a new interface for this, though: we 
>> could for example just use a special font name ("RawPostScript"?) in 
>> gl2psText()...
>>
>> Best,
>>
>> Christophe
>>
> 


-- 
Christophe Geuzaine
Applied and Computational Mathematics, Caltech
geuzaine at acm.caltech.edu - http://geuz.org