Use device abstraction for font and text drawing.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8126 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2010-12-28 12:02:23 +00:00
parent f3e04b8b87
commit b431c1e0e7
6 changed files with 34 additions and 33 deletions

View File

@ -122,9 +122,6 @@ protected:
friend void fl_line(int x, int y, int x1, int y1);
friend void fl_line(int x, int y, int x1, int y1, int x2, int y2);
friend void fl_draw(const char *str, int n, int x, int y);
#ifdef __APPLE__
friend void fl_draw(const char *str, int n, float x, float y);
#endif
friend void fl_draw(int angle, const char *str, int n, int x, int y);
friend void fl_rtl_draw(const char *str, int n, int x, int y);
friend void fl_font(Fl_Font face, Fl_Fontsize size);
@ -188,13 +185,13 @@ protected:
/** \brief see fl_line(int x, int y, int x1, int y1, int x2, int y2). */
virtual void line(int x, int y, int x1, int y1, int x2, int y2);
/** \brief see fl_draw(const char *str, int n, int x, int y). */
virtual void draw(const char *str, int n, int x, int y);
virtual void draw(const char *str, int n, int x, int y) {};
/** \brief see fl_draw(int angle, const char *str, int n, int x, int y). */
virtual void draw(int angle, const char *str, int n, int x, int y);
virtual void draw(int angle, const char *str, int n, int x, int y) {};
/** \brief see fl_rtl_draw(const char *str, int n, int x, int y). */
virtual void rtl_draw(const char *str, int n, int x, int y);
virtual void rtl_draw(const char *str, int n, int x, int y) {};
/** \brief see fl_font(Fl_Font face, Fl_Fontsize size). */
virtual void font(Fl_Font face, Fl_Fontsize size);
virtual void font(Fl_Font face, Fl_Fontsize size) {};
/** \brief see fl_color(Fl_Color c). */
virtual void color(Fl_Color c);
/** \brief see fl_color(uchar r, uchar g, uchar b). */
@ -301,6 +298,10 @@ public:
/** \brief The constructor. */
Fl_Quartz_Graphics_Driver() { type_ = device_type; };
static const char *device_type;
void draw(const char* str, int n, int x, int y);
void draw(int angle, const char *str, int n, int x, int y);
void rtl_draw(const char* str, int n, int x, int y);
void font(Fl_Font face, Fl_Fontsize size);
void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
@ -317,6 +318,10 @@ public:
/** \brief The constructor. */
Fl_GDI_Graphics_Driver() { type_ = device_type; };
static const char *device_type;
void draw(const char* str, int n, int x, int y);
void draw(int angle, const char *str, int n, int x, int y);
void rtl_draw(const char* str, int n, int x, int y);
void font(Fl_Font face, Fl_Fontsize size);
void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
@ -333,6 +338,10 @@ public:
/** \brief The constructor. */
Fl_Xlib_Graphics_Driver() { type_ = device_type; };
static const char *device_type;
void draw(const char* str, int n, int x, int y);
void draw(int angle, const char *str, int n, int x, int y);
void rtl_draw(const char* str, int n, int x, int y);
void font(Fl_Font face, Fl_Fontsize size);
void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);

View File

@ -81,7 +81,7 @@ void fl_text_extents(const char *c, int &dx, int &dy, int &w, int &h) {
} // fl_text_extents
#if !USE_XFT && !__APPLE__
#ifndef __APPLE__
void fl_draw(const char* str, int l, float x, float y) {
fl_draw(str, l, (int)x, (int)y);
}

View File

@ -237,7 +237,7 @@ Fl_Font fl_font_ = 0;
Fl_Fontsize fl_size_ = 0;
void Fl_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
void Fl_Quartz_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
if (fnum==-1) {
fl_font_ = 0;
fl_size_ = 0;
@ -400,7 +400,7 @@ void fl_text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h) {
void fl_draw(const char *str, int n, float x, float y);
void Fl_Graphics_Driver::draw(const char* str, int n, int x, int y) {
void Fl_Quartz_Graphics_Driver::draw(const char* str, int n, int x, int y) {
fl_draw(str, n, (float)x-0.0f, (float)y+0.5f);
}
@ -476,7 +476,7 @@ void fl_draw(const char *str, int n, float x, float y) {
#endif
}
void Fl_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) {
void Fl_Quartz_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) {
CGContextSaveGState(fl_gc);
CGContextTranslateCTM(fl_gc, x, y);
CGContextRotateCTM(fl_gc, - angle*(M_PI/180) );
@ -484,7 +484,7 @@ void Fl_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) {
CGContextRestoreGState(fl_gc);
}
void Fl_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
void Fl_Quartz_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
draw(c, n, int(x - fl_width(c, n)), y);
}

View File

@ -146,7 +146,7 @@ void fl_font(Fl_Font fnum, Fl_Fontsize size, int angle) {
fl_fontsize = find(fnum, size, angle);
}
void Fl_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
void Fl_GDI_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
fl_font(fnum, size, 0);
}
@ -334,7 +334,7 @@ exit_error:
return;
} // fl_text_extents
void Fl_Graphics_Driver::draw(const char* str, int n, int x, int y) {
void Fl_GDI_Graphics_Driver::draw(const char* str, int n, int x, int y) {
int i = 0;
int lx = 0;
char *end = (char *)&str[n];
@ -362,7 +362,7 @@ void Fl_Graphics_Driver::draw(const char* str, int n, int x, int y) {
SetTextColor(fl_gc, oldColor);
}
void Fl_Graphics_Driver::draw(int angle, const char* str, int n, int x, int y) {
void Fl_GDI_Graphics_Driver::draw(int angle, const char* str, int n, int x, int y) {
fl_font(fl_font_, fl_size_, angle);
// fl_draw(str, n, (int)x, (int)y);
int i = 0, i2=0;
@ -386,7 +386,7 @@ void Fl_Graphics_Driver::draw(int angle, const char* str, int n, int x, int y) {
fl_font(fl_font_, fl_size_);
}
void Fl_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
void Fl_GDI_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
int wn;
int i = 0;
int lx = 0;

View File

@ -269,7 +269,7 @@ XFontStruct* Fl_XFont_On_Demand::value() {
return ptr;
}
void Fl_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
if (fnum==-1) {
fl_font_ = 0; fl_size_ = 0;
return;
@ -318,24 +318,20 @@ void fl_text_extents(const char *c, int n, int &dx, int &dy, int &W, int &H) {
} // fl_text_extents
void Fl_Graphics_Driver::draw(const char* c, int n, int x, int y) {
void Fl_Xlib_Graphics_Driver::draw(const char* c, int n, int x, int y) {
if (font_gc != fl_gc) {
if (!current_font) fl_font(FL_HELVETICA, 14);
font_gc = fl_gc;
XSetFont(fl_display, fl_gc, current_font->fid);
}
// XDrawString(fl_display, fl_window, fl_gc, x, y, c, n);
XUtf8DrawString(fl_display, fl_window, current_font, fl_gc, x, y, c, n);
}
void Fl_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) {
fprintf(stderr,"ROTATING TEXT NOT IMPLIMENTED\n");
void Fl_Xlib_Graphics_Driver::draw(int angle, const char *str, int n, int x, int y) {
fprintf(stderr,"ROTATING TEXT NOT IMPLEMENTED\n");
fl_draw(str, n, (int)x, (int)y);
}
//void fl_draw(const char* str, int n, float x, float y) {
// fl_draw(str, n, (int)x, (int)y);
//}
void Fl_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
void Fl_Xlib_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
if (font_gc != fl_gc) {
if (!current_font) fl_font(FL_HELVETICA, 12);
font_gc = fl_gc;

View File

@ -152,7 +152,7 @@ void fl_font(Fl_Font fnum, Fl_Fontsize size, int angle) {
fl_xftfont = (void*)f->font;
}
void Fl_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
void Fl_Xlib_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
fl_font(fnum,size,0);
}
@ -552,7 +552,7 @@ void fl_destroy_xft_draw(Window id) {
#endif
}
void Fl_Graphics_Driver::draw(const char *str, int n, int x, int y) {
void Fl_Xlib_Graphics_Driver::draw(const char *str, int n, int x, int y) {
if ( !current_font ) {
fl_font(FL_HELVETICA, 14);
}
@ -589,16 +589,12 @@ void Fl_Graphics_Driver::draw(const char *str, int n, int x, int y) {
XftDrawStringUtf8(draw_, &color, current_font, x, y, (XftChar8 *)str, n);
}
void Fl_Graphics_Driver::draw(int angle, 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_font_, fl_size_, angle);
fl_draw(str, n, (int)x, (int)y);
fl_font(fl_font_, fl_size_);
}
void fl_draw(const char* str, int n, float x, float y) {
fl_draw(str, n, (int)x, (int)y);
}
static void fl_drawUCS4(const FcChar32 *str, int n, int x, int y) {
#if USE_OVERLAY
XftDraw*& draw_ = fl_overlay ? draw_overlay : ::draw_;
@ -634,7 +630,7 @@ static void fl_drawUCS4(const FcChar32 *str, int n, int x, int y) {
}
void Fl_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
void Fl_Xlib_Graphics_Driver::rtl_draw(const char* c, int n, int x, int y) {
#if defined(__GNUC__)
// FIXME: warning Need to improve this XFT right to left draw function