diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2010-03-29 10:35:00 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2010-03-29 10:35:00 +0000 |
| commit | 941901e273319ce152523af7fa079a6f5cf89d68 (patch) | |
| tree | 9d70b82fa54d81607a0022f14a0518c47805a796 /src/fl_font_mac.cxx | |
| parent | b77071a3de3593ea482aa7ea0a442c7fc888a2e2 (diff) | |
OS X: removed all Carbon and Quickdraw references. Starting with 1.3, we only support Cocoa and Quartz.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7351 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/fl_font_mac.cxx')
| -rw-r--r-- | src/fl_font_mac.cxx | 72 |
1 files changed, 9 insertions, 63 deletions
diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx index 634e68dec..1832edb8c 100644 --- a/src/fl_font_mac.cxx +++ b/src/fl_font_mac.cxx @@ -34,9 +34,7 @@ extern unsigned fl_utf8toUtf16(const char* src, unsigned srclen, unsigned short* #define check_default_font() {if (!fl_fontsize) fl_font(0, 12);} static const CGAffineTransform font_mx = { 1, 0, 0, -1, 0, 0 }; -#if defined(__APPLE_COCOA__) static SInt32 MACsystemVersion = 0; -#endif Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) { next = 0; @@ -49,7 +47,7 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) { q_name = strdup(name); size = Size; minsize = maxsize = Size; -#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 if(MACsystemVersion == 0) Gestalt(gestaltSystemVersion, &MACsystemVersion); if(MACsystemVersion >= 0x1050) {//unfortunately, CTFontCreateWithName != NULL on 10.4 also! @@ -146,7 +144,7 @@ else { ATSUSetTransientFontMatching (layout, true); # endif #endif//__LP64__ -#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 } #endif } @@ -169,7 +167,7 @@ Fl_Font_Descriptor::~Fl_Font_Descriptor() { #endif */ if (this == fl_fontsize) fl_fontsize = 0; -#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 if(MACsystemVersion >= 0x1050) CFRelease(fontref); #else /* ATSUDisposeTextLayout(layout); @@ -219,11 +217,7 @@ Fl_Fontdesc* fl_fonts = built_in_table; void fl_font(Fl_Font_Descriptor* s) { fl_fontsize = s; -#if defined(__APPLE_QUARTZ__) // we will use fl_fontsize later to access the required style and layout -#else -# error : need to defined either Quartz or Quickdraw -#endif } static Fl_Font_Descriptor* find(Fl_Font fnum, Fl_Fontsize size) { @@ -276,7 +270,7 @@ double fl_width(const UniChar* txt, int n) { if (!fl_fontsize) return 8*n; // user must select a font first! } -#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 if(MACsystemVersion >= 0x1050) { CTFontRef fontref = fl_fontsize->fontref; CFStringRef str = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n * sizeof(UniChar), kCFStringEncodingUTF16, false); @@ -316,7 +310,7 @@ else { int len = FixedToInt(bAfter); return len; #endif -#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 } #endif return 0; // FIXME: I do not understand the shuffeling of the above ifdef's and why they are here! @@ -345,7 +339,7 @@ void fl_text_extents(const UniChar* txt, int n, int &dx, int &dy, int &w, int &h h = 8.0; return; } -#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 if(MACsystemVersion >= 0x1050) { CTFontRef fontref = fl_fontsize->fontref; CFStringRef str16 = CFStringCreateWithBytes(NULL, (const UInt8*)txt, n *sizeof(UniChar), kCFStringEncodingUTF16, false); @@ -393,7 +387,7 @@ else { dy = -bbox.bottom; //printf("r: %d l: %d t: %d b: %d w: %d h: %d\n", bbox.right, bbox.left, bbox.top, bbox.bottom, w, h); #endif -#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 } #endif return; @@ -413,7 +407,6 @@ void Fl_Device::draw(const char* str, int n, int x, int y) { } -#if defined(__APPLE_COCOA__) static CGColorRef flcolortocgcolor(Fl_Color i) { uchar r, g, b; @@ -429,7 +422,6 @@ static CGColorRef flcolortocgcolor(Fl_Color i) } return CGColorCreate(cspace, components); } -#endif void fl_draw(const char *str, int n, float x, float y) { @@ -437,7 +429,7 @@ void fl_draw(const char *str, int n, float x, float y) { check_default_font(); // convert to UTF-16 first UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n); -#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 if(MACsystemVersion >= 0x1050) { CFStringRef keys[2]; CFTypeRef values[2]; @@ -479,71 +471,25 @@ void fl_draw(const char *str, int n, float x, float y) { ATSUSetLayoutControls(layout, 1, &iTag, &iSize, &iValuePtr); err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n); -#if defined(__APPLE_COCOA__) CGContextSetShouldAntialias(fl_gc, true); -#endif err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x), FloatToFixed(y)); -#if defined(__APPLE_COCOA__) CGContextSetShouldAntialias(fl_gc, false); #endif -#endif -#if defined(__APPLE_COCOA__) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 } #endif } void Fl_Device::draw(int angle, const char *str, int n, int x, int y) { -#if defined(__APPLE_COCOA__) CGContextSaveGState(fl_gc); CGContextTranslateCTM(fl_gc, x, y); CGContextRotateCTM(fl_gc, - angle*(M_PI/180) ); fl_draw(str, n, (float)0., (float)0.); CGContextRestoreGState(fl_gc); -#else - OSStatus err; - // convert to UTF-16 first - UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n); - - // avoid a crash if no font has been selected by user yet ! - check_default_font(); - // now collect our ATSU resources - ATSUTextLayout layout = fl_fontsize->layout; - - Fixed ang = IntToFixed(-angle); - ByteCount iSize[] = {sizeof(Fixed), sizeof(CGContextRef)}; - ATSUAttributeTag iTag[] = {kATSULineRotationTag, kATSUCGContextTag}; - ATSUAttributeValuePtr aAttr[] = { &ang, &fl_gc}; - ATSUSetLayoutControls(layout, 2, iTag, iSize, aAttr); - - err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n); - err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x), FloatToFixed(y)); - //restore layout baseline - ang = IntToFixed(0); - ATSUSetLayoutControls(layout, 2, iTag, iSize, aAttr); -#endif } void fl_rtl_draw(const char* c, int n, int x, int y) { -#if defined(__APPLE_COCOA__) fl_draw(c, n, x - fl_width(c, n), y); //to check; -#else - // I guess with ATSU the thing to do is force the layout mode to RTL and let ATSU draw the text... - double offs = fl_width(c, n); - OSStatus err; - // convert to UTF-16 first - UniChar *uniStr = mac_Utf8_to_Utf16(c, n, &n); - // now collect our ATSU resources - ATSUTextLayout layout = fl_fontsize->layout; - // reverse the layout direction - ATSUAttributeTag llo = kATSURightToLeftBaseDirection; // layout option - ByteCount iSize[] = {sizeof(ATSUAttributeTag), sizeof(CGContextRef)}; - ATSUAttributeTag iTag[] = {kATSULineDirectionTag, kATSUCGContextTag}; - ATSUAttributeValuePtr aAttr[] = { &llo, &fl_gc}; - ATSUSetLayoutControls (layout, 2, iTag, iSize, aAttr ); - - err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n); - err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x-offs), FloatToFixed(y)); -#endif } // |
