From 199b32d9213584e232aee11d2a4d16a26f1d508d Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Fri, 18 Feb 2011 13:39:48 +0000 Subject: Added virtual width(), height(), descent() and text_extents() functions to the Fl_Graphics_Driver class to prepare for the future definition of graphics drivers that fully deal with text measurement. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8442 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_Device.H | 36 +++++++++++++++++++++++++++++++++++- FL/Fl_PostScript.H | 7 +++++++ FL/fl_draw.H | 11 ++++++----- 3 files changed, 48 insertions(+), 6 deletions(-) (limited to 'FL') diff --git a/FL/Fl_Device.H b/FL/Fl_Device.H index 6569a8720..c973f73db 100644 --- a/FL/Fl_Device.H +++ b/FL/Fl_Device.H @@ -107,7 +107,7 @@ public: /** \brief A virtual class subclassed for each graphics driver FLTK uses. * - The protected virtual methods of this class are those that a graphics driver should implement to + The virtual methods of this class are those that a graphics driver should implement to support all of FLTK drawing functions.
The public API for drawing operations is functionally presented in \ref drawing and as function lists in the \ref fl_drawings and \ref fl_attributes modules. @@ -156,6 +156,9 @@ 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); @@ -234,6 +237,9 @@ protected: 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) = 0; +#ifdef __APPLE__ + virtual void draw(const char *str, int n, float x, float y) = 0; +#endif /** \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) = 0; /** \brief see fl_rtl_draw(const char *str, int n, int x, int y). */ @@ -357,6 +363,16 @@ public: Fl_Font font() {return font_; } /** \brief see fl_size(). */ Fl_Fontsize size() {return size_; } + /** \brief see fl_width(const char *str, int n). */ + virtual double width(const char *str, int n) = 0; + /** \brief see fl_width(unsigned int n). */ + virtual inline double width(unsigned int c) { char ch = (char)c; return width(&ch, 1); } + /** \brief see fl_text_extents(const char*, int n, int& dx, int& dy, int& w, int& h). */ + virtual void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); + /** \brief see fl_height(). */ + virtual int height() = 0; + /** \brief see fl_descent(). */ + virtual int descent() = 0; /** \brief see fl_color(void). */ Fl_Color color() {return color_;} /** Returns a pointer to the current Fl_Font_Descriptor for the graphics driver */ @@ -381,6 +397,9 @@ public: void color(Fl_Color c); void color(uchar r, uchar g, uchar b); void draw(const char* str, int n, int x, int y); +#ifdef __APPLE__ + void draw(const char *str, int n, float x, float y); +#endif 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); @@ -391,6 +410,11 @@ public: void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3); void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0); void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1); + double width(const char *str, int n); + double width(unsigned int c); + void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); + int height(); + int descent(); }; #endif #if defined(WIN32) || defined(FL_DOXYGEN) @@ -417,6 +441,11 @@ public: void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3); void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0); void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1); + double width(const char *str, int n); + double width(unsigned int c); + void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); + int height(); + int descent(); }; #endif #if !(defined(__APPLE__) || defined(WIN32)) @@ -443,6 +472,11 @@ public: void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3); void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0); void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1); + double width(const char *str, int n); + double width(unsigned int c); + void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); + int height(); + int descent(); }; #endif diff --git a/FL/Fl_PostScript.H b/FL/Fl_PostScript.H index 56b05234e..b03b67c06 100644 --- a/FL/Fl_PostScript.H +++ b/FL/Fl_PostScript.H @@ -116,6 +116,9 @@ class Clip { /* int alpha_mask(const uchar * data, int w, int h, int D, int LD=0); */ void draw(const char* s, int n, int x, int y) {transformed_draw(s,n,x,y); }; +#ifdef __APPLE__ + void draw(const char* s, int n, float x, float y) {transformed_draw(s,n,x,y); }; +#endif void draw(int angle, const char *str, int n, int x, int y); void rtl_draw(const char* s, int n, int x, int y); void transformed_draw(const char* s, int n, double x, double y); //precise text placing @@ -180,6 +183,10 @@ class Clip { void transformed_vertex(double x, double y); void font(int face, int size); + double width(const char *, int); + void text_extents(const char *c, int n, int &dx, int &dy, int &w, int &h); + int height(); + int descent(); 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);}; diff --git a/FL/fl_draw.H b/FL/fl_draw.H index a9651846d..1211c44a7 100644 --- a/FL/fl_draw.H +++ b/FL/fl_draw.H @@ -495,21 +495,21 @@ inline Fl_Fontsize fl_size() {return fl_graphics_driver->size();} Returns the recommended minimum line spacing for the current font. You can also use the value of \p size passed to fl_font() */ -FL_EXPORT int fl_height(); // using "size" should work ok +inline int fl_height() {return fl_graphics_driver->height();} FL_EXPORT int fl_height(int font, int size); /** Returns the recommended distance above the bottom of a fl_height() tall box to draw the text at so it looks centered vertically in that box. */ -FL_EXPORT int fl_descent(); +inline int fl_descent() {return fl_graphics_driver->descent();} /** Return the typographical width of a nul-terminated string */ FL_EXPORT double fl_width(const char* txt); /** Return the typographical width of a sequence of \p n characters */ -FL_EXPORT double fl_width(const char* txt, int n); +inline double fl_width(const char* txt, int n) {return fl_graphics_driver->width(txt, n);} /** Return the typographical width of a single character : \note if a valid fl_gc is NOT found then it uses the first window gc, or the screen gc if no fltk window is available when called. */ -FL_EXPORT double fl_width(unsigned int); +inline double fl_width(unsigned int c) {return fl_graphics_driver->width(c);} /** Determine the minimum pixel dimensions of a nul-terminated string. Usage: given a string "txt" drawn using fl_draw(txt, x, y) you would determine @@ -522,7 +522,8 @@ FL_EXPORT void fl_text_extents(const char*, int& dx, int& dy, int& w, int& h); / /** Determine the minimum pixel dimensions of a sequence of \p n characters. \see fl_text_extents(const char*, int& dx, int& dy, int& w, int& h) */ -FL_EXPORT void fl_text_extents(const char*, int n, int& dx, int& dy, int& w, int& h); +inline void fl_text_extents(const char *t, int n, int& dx, int& dy, int& w, int& h) + {fl_graphics_driver->text_extents(t, n, dx, dy, w, h);} // font encoding: // Note: doxygen comments here to avoid duplication for os-sepecific cases -- cgit v1.2.3