diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Font.H | 5 | ||||
| -rw-r--r-- | src/fl_font_mac.cxx | 66 | ||||
| -rw-r--r-- | src/fl_set_fonts_mac.cxx | 53 |
3 files changed, 106 insertions, 18 deletions
diff --git a/src/Fl_Font.H b/src/Fl_Font.H index bca85a1ea..4918f9f3f 100644 --- a/src/Fl_Font.H +++ b/src/Fl_Font.H @@ -1,5 +1,5 @@ // -// "$Id: Fl_Font.H,v 1.6.2.3.2.7 2004/08/26 00:18:42 matthiaswm Exp $" +// "$Id: Fl_Font.H,v 1.6.2.3.2.8 2004/09/09 00:55:41 matthiaswm Exp $" // // Font definitions for the Fast Light Tool Kit (FLTK). // @@ -57,7 +57,6 @@ public: short width[256]; bool knowMetrics; # elif defined(__APPLE_QUARTZ__) -#warning : minimal quartz, use ATS instead! FL_EXPORT Fl_FontSize(const char* fontname, int size); char *q_name; int size; @@ -102,5 +101,5 @@ FL_EXPORT char *fl_find_fontsize(char *name); #endif // -// End of "$Id: Fl_Font.H,v 1.6.2.3.2.7 2004/08/26 00:18:42 matthiaswm Exp $". +// End of "$Id: Fl_Font.H,v 1.6.2.3.2.8 2004/09/09 00:55:41 matthiaswm Exp $". // diff --git a/src/fl_font_mac.cxx b/src/fl_font_mac.cxx index 0fc0f3a8e..5ddf479f0 100644 --- a/src/fl_font_mac.cxx +++ b/src/fl_font_mac.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_font_mac.cxx,v 1.1.2.20 2004/09/07 20:59:17 easysw Exp $" +// "$Id: fl_font_mac.cxx,v 1.1.2.21 2004/09/09 00:55:41 matthiaswm Exp $" // // MacOS font selection routines for the Fast Light Tool Kit (FLTK). // @@ -25,10 +25,6 @@ #include <config.h> -#ifdef __APPLE_QUARTZ__ -#warning quartz -#endif - //: MeasureText, FontMetrics, WidthTabHandle, GetSysFont, SysFontSize //: TextSize, TextFont //: GetFNum (theName: Str255; VAR familyID: Integer); @@ -58,12 +54,24 @@ Fl_FontSize::Fl_FontSize(const char* name, int Size) { #endif minsize = maxsize = size; #elif defined(__APPLE_QUARTZ__) - q_name = strdup(name+1); + q_name = strdup(name); size = Size; ascent = Size*3/4; descent = Size-ascent; q_width = Size*2/3; minsize = maxsize = Size; + // Using ATS to get the genral Glyph size information + CFStringRef cfname = CFStringCreateWithCString(0L, q_name, kCFStringEncodingASCII); + ATSFontRef font = ATSFontFindFromName(cfname, kATSOptionFlagsDefault); + if (font) { + ATSFontMetrics m = { 0 }; + ATSFontGetHorizontalMetrics(font, kATSOptionFlagsDefault, &m); + if (m.avgAdvanceWidth) q_width = int(m.avgAdvanceWidth*size); + // playing with the offsets a little to make standard sizes fit + if (m.ascent) ascent = int(m.ascent*size-0.5f); + if (m.descent) descent = -int(m.descent*size-1.5f); + } + CFRelease(cfname); #endif } @@ -93,6 +101,7 @@ Fl_FontSize::~Fl_FontSize() { //////////////////////////////////////////////////////////////// static Fl_Fontdesc built_in_table[] = { +#ifdef __APPLE_QD__ {" Arial"}, {"BArial"}, {"IArial"}, @@ -109,6 +118,24 @@ static Fl_Fontdesc built_in_table[] = { {" Chicago"}, {"BChicago"}, {" Webdings"}, +#elif defined(__APPLE_QUARTZ__) +{"Arial"}, +{"Arial Bold"}, +{"Arial Italic"}, +{"Arial Bold Italic"}, +{"Courier New"}, +{"Courier New Bold"}, +{"Courier New Italic"}, +{"Courier New Bold Italic"}, +{"Times New Roman"}, +{"Times New Roman Bold"}, +{"Times New Roman Italic"}, +{"Times New Roman Bold Italic"}, +{"Symbol"}, +{"Monaco"}, +{"Andale Mono"}, // there is no bold Monaco font on standard Mac +{"Webdings"}, +#endif }; Fl_Fontdesc* fl_fonts = built_in_table; @@ -120,7 +147,8 @@ void fl_font(Fl_FontSize* s) { TextFont(fl_fontsize->font); //: select font into current QuickDraw GC TextFace(fl_fontsize->face); TextSize(fl_fontsize->size); - if (!fl_fontsize->knowMetrics) { //: get the true metrics for the currnet GC (fails on multiple monitors with different dpi's!) + if (!fl_fontsize->knowMetrics) { //: get the true metrics for the currnet GC + //: (fails on multiple monitors with different dpi's!) FontInfo fi; GetFontInfo(&fi); fl_fontsize->ascent = fi.ascent; fl_fontsize->descent = fi.descent; @@ -172,13 +200,35 @@ int fl_descent() { else return -1; } +// TODO: the text has to be translated according to the macroman_lut to give +// the correct result! double fl_width(const char* c, int n) { +#ifdef __APPLE_QD__ return (double)TextWidth( c, 0, n ); +#else + if (!fl_gc) { + Fl_Window *w = Fl::first_window(); + if (w) w->make_current(); + if (!fl_gc) return -1; + } + // according to the Apple developer docs, this is the correct way to + // find the length of a rendered text... + CGContextSetTextPosition(fl_gc, 0, 0); + CGContextSetTextDrawingMode(fl_gc, kCGTextInvisible); + CGContextShowText(fl_gc, c, n); + CGContextSetTextDrawingMode(fl_gc, kCGTextFill); + CGPoint p = CGContextGetTextPosition(fl_gc); + return p.x; +#endif } // todo : fl_width returns wrong results for OS X double fl_width(uchar c) { +#ifdef __APPLE_QD__ return (double)TextWidth( &c, 0, 1 ); +#else + return fl_width((const char*)&c, 1); +#endif } // MRS: The default character set is MacRoman, which is different from @@ -228,5 +278,5 @@ void fl_draw(const char* str, int n, int x, int y) { // -// End of "$Id: fl_font_mac.cxx,v 1.1.2.20 2004/09/07 20:59:17 easysw Exp $". +// End of "$Id: fl_font_mac.cxx,v 1.1.2.21 2004/09/09 00:55:41 matthiaswm Exp $". // diff --git a/src/fl_set_fonts_mac.cxx b/src/fl_set_fonts_mac.cxx index ee03c7d9f..8b49c2efe 100644 --- a/src/fl_set_fonts_mac.cxx +++ b/src/fl_set_fonts_mac.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_set_fonts_mac.cxx,v 1.1.2.11 2004/08/25 00:20:27 matthiaswm Exp $" +// "$Id: fl_set_fonts_mac.cxx,v 1.1.2.12 2004/09/09 00:55:41 matthiaswm Exp $" // // MacOS font utilities for the Fast Light Tool Kit (FLTK). // @@ -25,10 +25,6 @@ #include <config.h> -#ifdef __APPLE_QUARTZ__ -#warning quartz -#endif - // This function fills in the fltk font table with all the fonts that // are found on the X server. It tries to place the fonts into families // and to sort them so the first 4 in a family are normal, bold, italic, @@ -42,6 +38,7 @@ // turn a stored font name into a pretty name: const char* Fl::get_font_name(Fl_Font fnum, int* ap) { +#ifdef __APPLE_QD__ Fl_Fontdesc *f = fl_fonts + fnum; if (!f->fontname[0]) { const char* p = f->name; @@ -60,12 +57,27 @@ const char* Fl::get_font_name(Fl_Font fnum, int* ap) { } if (ap) *ap = f->fontname[ENDOFBUFFER]; return f->fontname; +#elif defined(__APPLE_QUARTZ__) + Fl_Fontdesc *f = fl_fonts + fnum; + if (!f->fontname[0]) { + const char* p = f->name; + if (!p || !*p) {if (ap) *ap = 0; return "";} + strlcpy(f->fontname, p, ENDOFBUFFER); + int type = 0; + if (strstr(f->name, "Bold")) type |= FL_BOLD; + if (strstr(f->name, "Italic")) type |= FL_ITALIC; + f->fontname[ENDOFBUFFER] = (char)type; + } + if (ap) *ap = f->fontname[ENDOFBUFFER]; + return f->fontname; +#endif } static int fl_free_font = FL_FREE_FONT; Fl_Font Fl::set_fonts(const char* xstarname) { #pragma unused ( xstarname ) +#ifdef __APPLE_QD__ if (fl_free_font != FL_FREE_FONT) return (Fl_Font)fl_free_font; static char styleLU[] = " BIP"; @@ -113,13 +125,35 @@ Fl_Font Fl::set_fonts(const char* xstarname) { } FMDisposeFontFamilyIterator( &ffIterator ); return (Fl_Font)fl_free_font; +#elif defined(__APPLE_QUARTZ__) + ATSFontIterator it; + ATSFontIteratorCreate(kATSFontContextGlobal, 0L, 0L, kATSOptionFlagsRestrictedScope, &it); + for (;;) { + ATSFontRef font; + CFStringRef fname = 0; + OSStatus err = ATSFontIteratorNext(it, &font); + if (err!=noErr) break; + ATSFontGetName(font, kATSOptionFlagsDefault, &fname); + char buf[1024]; + CFStringGetCString(fname, buf, 1024, kCFStringEncodingASCII); + int i; + for (i=0; i<FL_FREE_FONT; i++) // skip if one of our built-in fonts + if (!strcmp(Fl::get_font_name((Fl_Font)i),buf)) break; + if ( i < FL_FREE_FONT ) continue; + Fl::set_font((Fl_Font)(fl_free_font++), strdup((char*)buf)); + } + ATSFontIteratorRelease(&it); + return (Fl_Font)fl_free_font; +#endif } static int array[128]; int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { Fl_Fontdesc *s = fl_fonts+fnum; if (!s->name) s = fl_fonts; // empty slot in table, use entry 0 + int cnt = 0; +#ifdef __APPLE_QD__ Str255 name; int len = strlen( s->name ); memcpy(((char*)name)+1, s->name+1, len ); @@ -147,7 +181,6 @@ int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { FMFontSize size, pSize = -1; FMFontFamilyInstanceIterator ffiIterator; FMCreateFontFamilyInstanceIterator( family, &ffiIterator ); - int cnt = 0; OSStatus listInstances; for (;;) { @@ -163,10 +196,16 @@ int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) { } } FMDisposeFontFamilyInstanceIterator( &ffiIterator ); +#elif defined(__APPLE_QUARTZ__) + // ATS supports all font size + array[0] = 0; + sizep = array; + cnt = 1; +#endif return cnt; } // -// End of "$Id: fl_set_fonts_mac.cxx,v 1.1.2.11 2004/08/25 00:20:27 matthiaswm Exp $". +// End of "$Id: fl_set_fonts_mac.cxx,v 1.1.2.12 2004/09/09 00:55:41 matthiaswm Exp $". // |
