Fl_Quartz_Graphics_Driver: separate CoreText- and ATSU-based code using new, derived classes.

FLTK for the Mac OS platform draws text using 2 distinct system APIs depending on the 
version of the running OS. Classes Fl_CoreText_Graphics_Driver and Fl_ATSU_Graphics_Driver are defined
and implement the same virtual functions of class Fl_Quartz_Graphics_Driver using
CoreText and ATSU, respectively. The app allocates an object of one of these derived
classes according to the running OS version.



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11967 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-09-23 07:47:57 +00:00
parent 0e33655853
commit 63e33b1be3
5 changed files with 502 additions and 449 deletions

View File

@ -30,7 +30,7 @@ Fl_Copy_Surface_Driver *Fl_Copy_Surface_Driver::newCopySurfaceDriver(int w, int
}
Fl_Quartz_Copy_Surface_Driver::Fl_Quartz_Copy_Surface_Driver(int w, int h) : Fl_Copy_Surface_Driver(w, h) {
driver(new Fl_Quartz_Graphics_Driver);
driver(Fl_Graphics_Driver::newMainGraphicsDriver());
prepare_copy_pdf_and_tiff(w, h);
}

View File

@ -25,9 +25,15 @@
#ifndef FL_QUARTZ_GRAPHICS_DRIVER_H
#define FL_QUARTZ_GRAPHICS_DRIVER_H
#include <FL/x.H>
#include <FL/Fl_Graphics_Driver.H>
#include <ApplicationServices/ApplicationServices.h>
// condition for the ATSU API to be available at compile time
#define HAS_ATSU (!defined(__LP64__) || !__LP64__) && MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_11
struct Fl_Fontdesc;
/**
\brief The Mac OS X-specific graphics class.
*
@ -40,10 +46,12 @@ protected:
typedef struct { float x; float y; } XPOINT;
XPOINT *p;
bool high_resolution_;
public:
// protected constructor to ensure only derived classes are allocated
Fl_Quartz_Graphics_Driver() : Fl_Graphics_Driver(), gc_(NULL), p_size(0), p(NULL) {
high_resolution_ = false;
}
public:
static const int CoreText_threshold; // min Mac OS version for CoreText
virtual ~Fl_Quartz_Graphics_Driver() { if (p) free(p); }
virtual int has_feature(driver_feature mask) { return mask & NATIVE; }
virtual void gc(void *ctxt) {if (ctxt != gc_) global_gc(); gc_ = (CGContextRef)ctxt; }
@ -128,13 +136,45 @@ protected:
void font(Fl_Font face, Fl_Fontsize fsize);
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();
virtual bool high_resolution() { return high_resolution_; }
virtual void global_gc();
// Next group of virtual functions have at least one alternative
// CoreText- or ATSU-based implementation.
virtual void draw_float(float x, float y, const char *str, int n) {}
virtual double width(const UniChar* txt, int n, Fl_Font_Descriptor *fl_fontsize) {return 0;}
public:
virtual Fl_Font set_fonts(const char* xstarname) {return 0;}
virtual Fl_Fontdesc* calc_fl_fonts(void) {return NULL;}
virtual void set_fontname_in_fontdesc(Fl_Fontdesc *f);
virtual void descriptor_init(const char* name, Fl_Fontsize Size, Fl_Font_Descriptor *d) {}
// end of function group
};
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
class Fl_CoreText_Graphics_Driver : public Fl_Quartz_Graphics_Driver {
void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
virtual void draw_float(float x, float y, const char *str, int n);
virtual double width(const UniChar* txt, int n, Fl_Font_Descriptor *fl_fontsize);
Fl_Font set_fonts(const char* xstarname);
virtual Fl_Fontdesc* calc_fl_fonts(void);
virtual void set_fontname_in_fontdesc(Fl_Fontdesc *f);
virtual void descriptor_init(const char* name, Fl_Fontsize Size, Fl_Font_Descriptor *d);
};
#endif
#ifdef HAS_ATSU
class Fl_ATSU_Graphics_Driver : public Fl_Quartz_Graphics_Driver {
void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
virtual void draw_float(float x, float y, const char *str, int n);
virtual double width(const UniChar* txt, int n, Fl_Font_Descriptor *fl_fontsize);
Fl_Font set_fonts(const char* xstarname);
virtual Fl_Fontdesc* calc_fl_fonts(void);
virtual void descriptor_init(const char* name, Fl_Fontsize Size, Fl_Font_Descriptor *d);
};
#endif
extern float fl_quartz_line_width_;
#endif // FL_QUARTZ_GRAPHICS_DRIVER_H

View File

@ -19,6 +19,7 @@
#include "../../config_lib.h"
#include "Fl_Quartz_Graphics_Driver.H"
#include "../Darwin/Fl_Darwin_System_Driver.H"
#include <FL/x.H>
/*
@ -27,7 +28,20 @@
*/
Fl_Graphics_Driver *Fl_Graphics_Driver::newMainGraphicsDriver()
{
return new Fl_Quartz_Graphics_Driver();
#if HAS_ATSU
static int option = 0; // 0: not initialized, 1: use CoreText, 2: use ATSU
if (!option) {
option = 2;
if (Fl_Darwin_System_Driver::calc_mac_os_version() >= Fl_Quartz_Graphics_Driver::CoreText_threshold) {
option = 1;
}
}
if (option == 2) return new Fl_ATSU_Graphics_Driver();
#endif // HAS_ATSU
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
return new Fl_CoreText_Graphics_Driver();
#endif
return NULL; // should not happen
}
char Fl_Quartz_Graphics_Driver::can_do_alpha_blending() {

File diff suppressed because it is too large Load Diff

View File

@ -53,7 +53,7 @@ Fl_Quartz_Image_Surface_Driver::Fl_Quartz_Image_Surface_Driver(int w, int h, int
CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
offscreen = CGBitmapContextCreate(calloc(W*H,4), W, H, 8, W*4, lut, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(lut);
driver(new Fl_Quartz_Graphics_Driver);
driver(Fl_Graphics_Driver::newMainGraphicsDriver());
CGContextTranslateCTM(offscreen, 0.5, -0.5); // as when drawing to a window
if (high_res) {
CGContextScaleCTM(offscreen, 2, 2);