Skip to content

Commit

Permalink
Removed global variables fl_font_ and fl_size_ that are now distinct …
Browse files Browse the repository at this point in the history
…for each graphics device.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8374 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Feb 5, 2011
1 parent 668dfd1 commit 777ee1b
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 40 deletions.
12 changes: 10 additions & 2 deletions FL/Fl_Device.H
Expand Up @@ -59,6 +59,8 @@ typedef void (*Fl_Draw_Image_Cb)(void* data,int x,int y,int w,uchar* buf);

#define MATRIX_STACK_SIZE 32
#define MATRIX_STACK_MAX (MATRIX_STACK_SIZE - 1)
/** A 2D coordinate transformation matrix
*/
struct matrix {double a, b, c, d, x, y;};

// typedef what the x,y fields in a point are:
Expand Down Expand Up @@ -110,6 +112,8 @@ public:
in the \ref fl_drawings and \ref fl_attributes modules.
*/
class FL_EXPORT Fl_Graphics_Driver : public Fl_Device {
Fl_Font font_; // current font
Fl_Fontsize size_; // current font size
enum {LINE, LOOP, POLYGON, POINT_};
int sptr;
matrix stack[MATRIX_STACK_SIZE];
Expand Down Expand Up @@ -199,7 +203,7 @@ protected:
friend FL_EXPORT void fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D);
friend void gl_start();

matrix *fl_matrix;
matrix *fl_matrix; /**< Points to the current coordinate transformation matrix */

/** \brief The constructor. */
Fl_Graphics_Driver();
Expand Down Expand Up @@ -345,7 +349,11 @@ protected:
public:
static const char *class_id;
/** \brief see fl_font(Fl_Font face, Fl_Fontsize size). */
virtual void font(Fl_Font face, Fl_Fontsize size) = 0;
virtual void font(Fl_Font face, Fl_Fontsize size) {font_ = face; size_ = size;}
/** \brief see fl_font(). */
Fl_Font font() {return font_; }
/** \brief see fl_size(). */
Fl_Fontsize size() {return size_; }
/** \brief The destructor */
virtual ~Fl_Graphics_Driver() {};
};
Expand Down
4 changes: 0 additions & 4 deletions FL/Fl_PostScript.H
Expand Up @@ -76,8 +76,6 @@ class Clip {
Clip * clip_;

int lang_level_;
int font_;
int size_;
int gap_;
int pages_;

Expand Down Expand Up @@ -182,8 +180,6 @@ class Clip {
void transformed_vertex(double x, double y);

void font(int face, int size);
int font(){return font_;};
int size(){return size_;};

void draw_image(const uchar* d, int x,int y,int w,int h, int delta=3, int ldelta=0){draw_scaled_image(d,x,y,w,h,w,h,delta,ldelta);};
void draw_image_mono(const uchar* d, int x,int y,int w,int h, int delta=1, int ld=0){draw_scaled_image_mono(d,x,y,w,h,w,h,delta,ld);};
Expand Down
7 changes: 2 additions & 5 deletions FL/fl_draw.H
Expand Up @@ -480,20 +480,17 @@ inline void fl_transformed_vertex(double xf, double yf) {fl_graphics_driver->tra
Lines should be spaced \p size pixels apart or more.
*/
inline void fl_font(Fl_Font face, Fl_Fontsize size) { fl_graphics_driver->font(face,size); }
extern FL_EXPORT Fl_Font fl_font_; ///< current font index

/**
Returns the \p face set by the most recent call to fl_font().
This can be used to save/restore the font.
*/
inline Fl_Font fl_font() {return fl_font_;}
/** \brief current font size */
extern FL_EXPORT Fl_Fontsize fl_size_;
inline Fl_Font fl_font() {return fl_graphics_driver->font();}
/**
Returns the \p size set by the most recent call to fl_font().
This can be used to save/restore the font.
*/
inline Fl_Fontsize fl_size() {return fl_size_;}
inline Fl_Fontsize fl_size() {return fl_graphics_driver->size();}

// information you can get about the current font:
/**
Expand Down
12 changes: 7 additions & 5 deletions src/Fl_Device.cxx
Expand Up @@ -54,11 +54,13 @@ void Fl_Surface_Device::set_current(void)
static matrix m0 = {1, 0, 0, 1, 0, 0};

Fl_Graphics_Driver::Fl_Graphics_Driver() {
sptr=0; rstackptr=0;
fl_clip_state_number=0;
m = m0;
fl_matrix = &m;
p = (XPOINT *)0;
font_ = 0;
size_ = 0;
sptr=0; rstackptr=0;
fl_clip_state_number=0;
m = m0;
fl_matrix = &m;
p = (XPOINT *)0;
};

//
Expand Down
7 changes: 3 additions & 4 deletions src/Fl_PostScript.cxx
Expand Up @@ -589,15 +589,14 @@ int Fl_PostScript_Graphics_Driver::start_postscript (int pagecount,
void Fl_PostScript_Graphics_Driver::recover(){
color(cr_,cg_,cb_);
line_style(linestyle_,linewidth_,linedash_);
font(font_,size_);
font(Fl_Graphics_Driver::font(), Fl_Graphics_Driver::size());
}

void Fl_PostScript_Graphics_Driver::reset(){
gap_=1;
clip_=0;
cr_=cg_=cb_=0;
font_=FL_HELVETICA;
size_=12;
Fl_Graphics_Driver::font(FL_HELVETICA, 12);
linewidth_=0;
linestyle_=FL_SOLID;
strcpy(linedash_,"");
Expand Down Expand Up @@ -932,7 +931,7 @@ void Fl_PostScript_Graphics_Driver::font(int f, int s) {
fprintf(output, "/%s SF\n" , _fontNames[f]);
fprintf(output,"%i FS\n", s);
Fl_Display_Device::display_device()->driver()->font(f,s); // Use display fonts for font measurement
font_ = f; size_ = s;
Fl_Graphics_Driver::font(f, s);
}

void Fl_PostScript_Graphics_Driver::color(Fl_Color c) {
Expand Down
10 changes: 2 additions & 8 deletions src/fl_font_mac.cxx
Expand Up @@ -250,18 +250,12 @@ static Fl_Font_Descriptor* find(Fl_Font fnum, Fl_Fontsize size) {
////////////////////////////////////////////////////////////////
// Public interface:

Fl_Font fl_font_ = 0;
Fl_Fontsize fl_size_ = 0;


void Fl_Quartz_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
if (fnum==-1) {
fl_font_ = 0;
fl_size_ = 0;
Fl_Graphics_Driver::font(0, 0);
return;
}
fl_font_ = fnum;
fl_size_ = size;
Fl_Graphics_Driver::font(fnum, size);
fl_font(find(fnum, size));
}

Expand Down
7 changes: 4 additions & 3 deletions src/fl_font_win32.cxx
Expand Up @@ -132,11 +132,11 @@ static Fl_Font_Descriptor* find(Fl_Font fnum, Fl_Fontsize size, int angle) {
////////////////////////////////////////////////////////////////
// Public interface:

Fl_Font fl_font_ = 0;
Fl_Fontsize fl_size_ = 0;
static Fl_Font fl_font_ = 0;
static Fl_Fontsize fl_size_ = 0;
//static HDC font_gc;

void fl_font(Fl_Font fnum, Fl_Fontsize size, int angle) {
static void fl_font(Fl_Font fnum, Fl_Fontsize size, int angle) {
if (fnum==-1) { // just make sure that we will load a new font next time
fl_font_ = 0; fl_size_ = 0; fl_angle_ = 0;
return;
Expand All @@ -148,6 +148,7 @@ void fl_font(Fl_Font fnum, Fl_Fontsize size, int angle) {

void Fl_GDI_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
fl_font(fnum, size, 0);
Fl_Graphics_Driver::font(fl_font_, fl_size_);
}

int fl_height() {
Expand Down
8 changes: 3 additions & 5 deletions src/fl_font_x.cxx
Expand Up @@ -260,8 +260,6 @@ static Fl_Font_Descriptor* find(int fnum, int size) {
////////////////////////////////////////////////////////////////
// Public interface:

Fl_Font fl_font_ = 0;
Fl_Fontsize fl_size_ = 0;
void *fl_xftfont = 0;
static GC font_gc;

Expand All @@ -271,11 +269,11 @@ XFontStruct* Fl_XFont_On_Demand::value() {

void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
if (fnum==-1) {
fl_font_ = 0; fl_size_ = 0;
Fl_Graphics_Driver::font(0, 0);
return;
}
if (fnum == fl_font_ && size == fl_size_) return;
fl_font_ = fnum; fl_size_ = size;
if (fnum == Fl_Graphics_Driver::font() && size == Fl_Graphics_Driver::size()) return;
Fl_Graphics_Driver::font(fnum, size);
Fl_Font_Descriptor* f = find(fnum, size);
if (f != fl_fontsize) {
fl_fontsize = f;
Expand Down
5 changes: 3 additions & 2 deletions src/fl_font_xft.cxx
Expand Up @@ -110,8 +110,8 @@ Fl_Fontdesc* fl_fonts = built_in_table;

#define current_font (fl_fontsize->font)

Fl_Font fl_font_ = 0;
Fl_Fontsize fl_size_ = 0;
static Fl_Font fl_font_ = 0;
static Fl_Fontsize fl_size_ = 0;
int fl_angle_ = 0; // internal for rotating text support
Fl_XFont_On_Demand fl_xfont;
void *fl_xftfont = 0;
Expand Down Expand Up @@ -154,6 +154,7 @@ 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_Graphics_Driver::font(fl_font_, fl_size_);
}

static XftFont* fontopen(const char* name, bool core, int angle) {
Expand Down
4 changes: 2 additions & 2 deletions src/gl_draw.cxx
Expand Up @@ -35,6 +35,7 @@
#include <FL/gl.h>
#include <FL/x.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Device.H>
#include "Fl_Gl_Choice.H"
#include "Fl_Font.H"
#include <FL/fl_utf8.h>
Expand Down Expand Up @@ -161,8 +162,7 @@ void gl_remove_displaylist_fonts()
# if HAVE_GL

// clear variables used mostly in fl_font
fl_font_ = 0;
fl_size_ = 0;
fl_graphics_driver->font(0, 0);

for (int j = 0 ; j < FL_FREE_FONT ; ++j)
{
Expand Down

0 comments on commit 777ee1b

Please sign in to comment.