News from FLTK1.1 and Quartz
- listing fonts using ATS instead of QD - made bold and italic fonts work - returning correct font metrics One problem came up though: Quartz renders fonts at subpixel positions, which is great for the overall look, but unfortunatly 'fl_draw' supports only integer coordinates for printing. As a result, marking a line of text makes the rest of the line jump by a fractional pixel. Any suggestions to solve this problem are greatly appreciated! git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@3810 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
88ff012c44
commit
b90f593ae6
6
FL/mac.H
6
FL/mac.H
@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// "$Id: mac.H,v 1.1.2.15 2004/08/31 22:00:44 matthiaswm Exp $"
|
// "$Id: mac.H,v 1.1.2.16 2004/09/09 00:55:41 matthiaswm Exp $"
|
||||||
//
|
//
|
||||||
// Mac header file for the Fast Light Tool Kit (FLTK).
|
// Mac header file for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@ -79,6 +79,8 @@ public:
|
|||||||
void flush();
|
void flush();
|
||||||
// Quartz additions:
|
// Quartz additions:
|
||||||
CGContextRef gc; // graphics context (NULL when using QD)
|
CGContextRef gc; // graphics context (NULL when using QD)
|
||||||
|
static ATSUTextLayout atsu_layout; // windows share a global font
|
||||||
|
static ATSUStyle atsu_style;
|
||||||
static void q_fill_context(); // fill a Quartz context with current FLTK state
|
static void q_fill_context(); // fill a Quartz context with current FLTK state
|
||||||
static void q_clear_clipping(); // remove all clipping from a Quartz context
|
static void q_clear_clipping(); // remove all clipping from a Quartz context
|
||||||
static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
|
static void q_release_context(Fl_X *x=0); // free all resources associated with fl_gc
|
||||||
@ -126,6 +128,6 @@ extern void fl_open_callback(void (*cb)(const char *));
|
|||||||
extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
|
extern FL_EXPORT int fl_parse_color(const char* p, uchar& r, uchar& g, uchar& b);
|
||||||
|
|
||||||
//
|
//
|
||||||
// End of "$Id: mac.H,v 1.1.2.15 2004/08/31 22:00:44 matthiaswm Exp $".
|
// End of "$Id: mac.H,v 1.1.2.16 2004/09/09 00:55:41 matthiaswm Exp $".
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -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).
|
// Font definitions for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@ -57,7 +57,6 @@ public:
|
|||||||
short width[256];
|
short width[256];
|
||||||
bool knowMetrics;
|
bool knowMetrics;
|
||||||
# elif defined(__APPLE_QUARTZ__)
|
# elif defined(__APPLE_QUARTZ__)
|
||||||
#warning : minimal quartz, use ATS instead!
|
|
||||||
FL_EXPORT Fl_FontSize(const char* fontname, int size);
|
FL_EXPORT Fl_FontSize(const char* fontname, int size);
|
||||||
char *q_name;
|
char *q_name;
|
||||||
int size;
|
int size;
|
||||||
@ -102,5 +101,5 @@ FL_EXPORT char *fl_find_fontsize(char *name);
|
|||||||
#endif
|
#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 $".
|
||||||
//
|
//
|
||||||
|
@ -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).
|
// MacOS font selection routines for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@ -25,10 +25,6 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#ifdef __APPLE_QUARTZ__
|
|
||||||
#warning quartz
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//: MeasureText, FontMetrics, WidthTabHandle, GetSysFont, SysFontSize
|
//: MeasureText, FontMetrics, WidthTabHandle, GetSysFont, SysFontSize
|
||||||
//: TextSize, TextFont
|
//: TextSize, TextFont
|
||||||
//: GetFNum (theName: Str255; VAR familyID: Integer);
|
//: GetFNum (theName: Str255; VAR familyID: Integer);
|
||||||
@ -58,12 +54,24 @@ Fl_FontSize::Fl_FontSize(const char* name, int Size) {
|
|||||||
#endif
|
#endif
|
||||||
minsize = maxsize = size;
|
minsize = maxsize = size;
|
||||||
#elif defined(__APPLE_QUARTZ__)
|
#elif defined(__APPLE_QUARTZ__)
|
||||||
q_name = strdup(name+1);
|
q_name = strdup(name);
|
||||||
size = Size;
|
size = Size;
|
||||||
ascent = Size*3/4;
|
ascent = Size*3/4;
|
||||||
descent = Size-ascent;
|
descent = Size-ascent;
|
||||||
q_width = Size*2/3;
|
q_width = Size*2/3;
|
||||||
minsize = maxsize = Size;
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +101,7 @@ Fl_FontSize::~Fl_FontSize() {
|
|||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static Fl_Fontdesc built_in_table[] = {
|
static Fl_Fontdesc built_in_table[] = {
|
||||||
|
#ifdef __APPLE_QD__
|
||||||
{" Arial"},
|
{" Arial"},
|
||||||
{"BArial"},
|
{"BArial"},
|
||||||
{"IArial"},
|
{"IArial"},
|
||||||
@ -109,6 +118,24 @@ static Fl_Fontdesc built_in_table[] = {
|
|||||||
{" Chicago"},
|
{" Chicago"},
|
||||||
{"BChicago"},
|
{"BChicago"},
|
||||||
{" Webdings"},
|
{" 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;
|
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
|
TextFont(fl_fontsize->font); //: select font into current QuickDraw GC
|
||||||
TextFace(fl_fontsize->face);
|
TextFace(fl_fontsize->face);
|
||||||
TextSize(fl_fontsize->size);
|
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);
|
FontInfo fi; GetFontInfo(&fi);
|
||||||
fl_fontsize->ascent = fi.ascent;
|
fl_fontsize->ascent = fi.ascent;
|
||||||
fl_fontsize->descent = fi.descent;
|
fl_fontsize->descent = fi.descent;
|
||||||
@ -172,13 +200,35 @@ int fl_descent() {
|
|||||||
else return -1;
|
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) {
|
double fl_width(const char* c, int n) {
|
||||||
|
#ifdef __APPLE_QD__
|
||||||
return (double)TextWidth( c, 0, n );
|
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
|
// todo : fl_width returns wrong results for OS X
|
||||||
double fl_width(uchar c) {
|
double fl_width(uchar c) {
|
||||||
|
#ifdef __APPLE_QD__
|
||||||
return (double)TextWidth( &c, 0, 1 );
|
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
|
// 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 $".
|
||||||
//
|
//
|
||||||
|
@ -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).
|
// MacOS font utilities for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@ -25,10 +25,6 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#ifdef __APPLE_QUARTZ__
|
|
||||||
#warning quartz
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// This function fills in the fltk font table with all the fonts that
|
// 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
|
// 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,
|
// 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:
|
// turn a stored font name into a pretty name:
|
||||||
const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
|
const char* Fl::get_font_name(Fl_Font fnum, int* ap) {
|
||||||
|
#ifdef __APPLE_QD__
|
||||||
Fl_Fontdesc *f = fl_fonts + fnum;
|
Fl_Fontdesc *f = fl_fonts + fnum;
|
||||||
if (!f->fontname[0]) {
|
if (!f->fontname[0]) {
|
||||||
const char* p = f->name;
|
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];
|
if (ap) *ap = f->fontname[ENDOFBUFFER];
|
||||||
return f->fontname;
|
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;
|
static int fl_free_font = FL_FREE_FONT;
|
||||||
|
|
||||||
Fl_Font Fl::set_fonts(const char* xstarname) {
|
Fl_Font Fl::set_fonts(const char* xstarname) {
|
||||||
#pragma unused ( xstarname )
|
#pragma unused ( xstarname )
|
||||||
|
#ifdef __APPLE_QD__
|
||||||
if (fl_free_font != FL_FREE_FONT)
|
if (fl_free_font != FL_FREE_FONT)
|
||||||
return (Fl_Font)fl_free_font;
|
return (Fl_Font)fl_free_font;
|
||||||
static char styleLU[] = " BIP";
|
static char styleLU[] = " BIP";
|
||||||
@ -113,13 +125,35 @@ Fl_Font Fl::set_fonts(const char* xstarname) {
|
|||||||
}
|
}
|
||||||
FMDisposeFontFamilyIterator( &ffIterator );
|
FMDisposeFontFamilyIterator( &ffIterator );
|
||||||
return (Fl_Font)fl_free_font;
|
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];
|
static int array[128];
|
||||||
int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
|
int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
|
||||||
Fl_Fontdesc *s = fl_fonts+fnum;
|
Fl_Fontdesc *s = fl_fonts+fnum;
|
||||||
if (!s->name) s = fl_fonts; // empty slot in table, use entry 0
|
if (!s->name) s = fl_fonts; // empty slot in table, use entry 0
|
||||||
|
int cnt = 0;
|
||||||
|
|
||||||
|
#ifdef __APPLE_QD__
|
||||||
Str255 name;
|
Str255 name;
|
||||||
int len = strlen( s->name );
|
int len = strlen( s->name );
|
||||||
memcpy(((char*)name)+1, s->name+1, len );
|
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;
|
FMFontSize size, pSize = -1;
|
||||||
FMFontFamilyInstanceIterator ffiIterator;
|
FMFontFamilyInstanceIterator ffiIterator;
|
||||||
FMCreateFontFamilyInstanceIterator( family, &ffiIterator );
|
FMCreateFontFamilyInstanceIterator( family, &ffiIterator );
|
||||||
int cnt = 0;
|
|
||||||
OSStatus listInstances;
|
OSStatus listInstances;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
@ -163,10 +196,16 @@ int Fl::get_font_sizes(Fl_Font fnum, int*& sizep) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
FMDisposeFontFamilyInstanceIterator( &ffiIterator );
|
FMDisposeFontFamilyInstanceIterator( &ffiIterator );
|
||||||
|
#elif defined(__APPLE_QUARTZ__)
|
||||||
|
// ATS supports all font size
|
||||||
|
array[0] = 0;
|
||||||
|
sizep = array;
|
||||||
|
cnt = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
return cnt;
|
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 $".
|
||||||
//
|
//
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// "$Id: fonts.cxx,v 1.5.2.3.2.4 2004/04/11 04:39:01 easysw Exp $"
|
// "$Id: fonts.cxx,v 1.5.2.3.2.5 2004/09/09 00:55:41 matthiaswm Exp $"
|
||||||
//
|
//
|
||||||
// Font demo program for the Fast Light Tool Kit (FLTK).
|
// Font demo program for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@ -133,7 +133,11 @@ void create_the_forms() {
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
Fl::scheme(NULL);
|
Fl::scheme(NULL);
|
||||||
create_the_forms();
|
create_the_forms();
|
||||||
|
#ifdef __APPLE__
|
||||||
|
int i = 0;
|
||||||
|
#else
|
||||||
int i = fl_choice("Which fonts:","-*","iso8859","All");
|
int i = fl_choice("Which fonts:","-*","iso8859","All");
|
||||||
|
#endif
|
||||||
int k = Fl::set_fonts(i ? (i>1 ? "*" : 0) : "-*");
|
int k = Fl::set_fonts(i ? (i>1 ? "*" : 0) : "-*");
|
||||||
for (i = 0; i < k; i++) {
|
for (i = 0; i < k; i++) {
|
||||||
int t; const char *name = Fl::get_font_name((Fl_Font)i,&t);
|
int t; const char *name = Fl::get_font_name((Fl_Font)i,&t);
|
||||||
@ -165,5 +169,5 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// End of "$Id: fonts.cxx,v 1.5.2.3.2.4 2004/04/11 04:39:01 easysw Exp $".
|
// End of "$Id: fonts.cxx,v 1.5.2.3.2.5 2004/09/09 00:55:41 matthiaswm Exp $".
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user