fixed max os x QD mode would not compile. Got back all the QD font drawing code from 1.1.9. the labels draw but are uncorrectly shifted to the right.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6357 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
b53ea22a59
commit
cccbaca0c5
@ -35,6 +35,25 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
|
||||
# if HAVE_GL
|
||||
listbase = 0;
|
||||
# endif
|
||||
#if defined(__APPLE_QD__)
|
||||
knowMetrics = 0;
|
||||
switch (*name++) {
|
||||
case 'I': face = italic; break;
|
||||
case 'P': face = italic | bold; break;
|
||||
case 'B': face = bold; break;
|
||||
default: face = 0; break;
|
||||
}
|
||||
unsigned char fn[80];
|
||||
fn[0] = strlen(name); strcpy((char*)(fn+1), name);
|
||||
GetFNum(fn, &font);
|
||||
size = Size;
|
||||
FMInput fIn = { font, size, face, 0, 0, { 1, 1}, { 1, 1} };
|
||||
FMOutput *fOut = FMSwapFont(&fIn);
|
||||
ascent = fOut->ascent; //: the following three lines give only temporary aproimations
|
||||
descent = fOut->descent;
|
||||
for (int i=0; i<256; i++) width[i] = fOut->widMax;
|
||||
minsize = maxsize = size;
|
||||
#elif defined(__APPLE_QUARTZ__)
|
||||
// knowWidths = 0;
|
||||
// OpenGL needs those for its font handling
|
||||
q_name = strdup(name);
|
||||
@ -101,13 +120,14 @@ Fl_Font_Descriptor::Fl_Font_Descriptor(const char* name, Fl_Fontsize Size) {
|
||||
if (w)
|
||||
q_width = FixedToInt(bAfter);
|
||||
|
||||
#define ENABLE_TRANSIENT_FONTS 1
|
||||
# define ENABLE_TRANSIENT_FONTS 1
|
||||
|
||||
#ifdef ENABLE_TRANSIENT_FONTS
|
||||
# ifdef ENABLE_TRANSIENT_FONTS
|
||||
// Now, by way of experiment, try enabling Transient Font Matching, this will
|
||||
// cause ATSU to find a suitable font to render any chars the current font can't do...
|
||||
ATSUSetTransientFontMatching (layout, true);
|
||||
#endif
|
||||
# endif
|
||||
#endif // defined(__APPLE_QD__)
|
||||
}
|
||||
|
||||
Fl_Font_Descriptor* fl_fontsize = 0L;
|
||||
@ -128,13 +148,33 @@ Fl_Font_Descriptor::~Fl_Font_Descriptor() {
|
||||
#endif
|
||||
*/
|
||||
if (this == fl_fontsize) fl_fontsize = 0;
|
||||
#ifdef __APPLE_QUARTZ__
|
||||
ATSUDisposeTextLayout(layout);
|
||||
ATSUDisposeStyle(style);
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
static Fl_Fontdesc built_in_table[] = {
|
||||
#ifdef __APPLE_QD__
|
||||
{" Arial"},
|
||||
{"BArial"},
|
||||
{"IArial"},
|
||||
{"PArial"},
|
||||
{" Courier New"},
|
||||
{"BCourier New"},
|
||||
{"ICourier New"},
|
||||
{"PCourier New"},
|
||||
{" Times New Roman"},
|
||||
{"BTimes New Roman"},
|
||||
{"ITimes New Roman"},
|
||||
{"PTimes New Roman"},
|
||||
{" Symbol"},
|
||||
{" Chicago"},
|
||||
{"BChicago"},
|
||||
{" Webdings"},
|
||||
#elif defined(__APPLE_QUARTZ__)
|
||||
{"Arial"},
|
||||
{"Arial Bold"},
|
||||
{"Arial Italic"},
|
||||
@ -151,6 +191,7 @@ static Fl_Fontdesc built_in_table[] = {
|
||||
{"Monaco"},
|
||||
{"Andale Mono"}, // there is no bold Monaco font on standard Mac
|
||||
{"Webdings"},
|
||||
#endif
|
||||
};
|
||||
|
||||
static UniChar *utfWbuf = 0;
|
||||
@ -174,7 +215,26 @@ Fl_Fontdesc* fl_fonts = built_in_table;
|
||||
|
||||
void fl_font(Fl_Font_Descriptor* s) {
|
||||
fl_fontsize = s;
|
||||
#ifdef __APPLE_QD__
|
||||
if (fl_window) SetPort( GetWindowPort(fl_window) );
|
||||
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 current GC
|
||||
//: (fails on multiple monitors with different dpi's!)
|
||||
FontInfo fi; GetFontInfo(&fi);
|
||||
fl_fontsize->ascent = fi.ascent;
|
||||
fl_fontsize->descent = fi.descent;
|
||||
FMetricRec mr; FontMetrics(&mr);
|
||||
short *f = (short*)*mr.wTabHandle; //: get the char size table
|
||||
for (int i=0; i<256; i++) fl_fontsize->width[i] = f[2*i];
|
||||
fl_fontsize->knowMetrics = 1;
|
||||
}
|
||||
#elif 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) {
|
||||
@ -217,6 +277,9 @@ int fl_descent() {
|
||||
}
|
||||
|
||||
double fl_width(const UniChar* txt, int n) {
|
||||
#ifdef __APPLE_QD__
|
||||
return (double)TextWidth( txt, 0, n );
|
||||
#else
|
||||
if (!fl_fontsize) {
|
||||
fl_font(0, 12); // avoid a crash!
|
||||
if (!fl_fontsize)
|
||||
@ -243,6 +306,7 @@ double fl_width(const UniChar* txt, int n) {
|
||||
// If err is OK then return length, else return 0. Or something...
|
||||
int len = FixedToInt(bAfter);
|
||||
return len;
|
||||
#endif
|
||||
}
|
||||
|
||||
double fl_width(const char* txt, int n) {
|
||||
@ -262,10 +326,18 @@ double fl_width(unsigned int wc) {
|
||||
void fl_draw(const char *str, int n, float x, float y);
|
||||
|
||||
void fl_draw(const char* str, int n, int x, int y) {
|
||||
#ifdef __APPLE_QD__
|
||||
MoveTo(x, y);
|
||||
DrawText((const char *)str, 0, n);
|
||||
#elif defined(__APPLE_QUARTZ__)
|
||||
fl_draw(str, n, (float)x-0.0f, (float)y-0.5f);
|
||||
#endif
|
||||
}
|
||||
|
||||
void fl_draw(const char *str, int n, float x, float y) {
|
||||
#ifdef __APPLE_QD__
|
||||
fl_draw(str, n, (int)x, (int)y); // FIXME no utf8 rtl impl for QD
|
||||
#elif defined(__APPLE_QUARTZ__)
|
||||
OSStatus err;
|
||||
// convert to UTF-16 first
|
||||
UniChar *uniStr = mac_Utf8_to_Utf16(str, n, &n);
|
||||
@ -279,9 +351,15 @@ void fl_draw(const char *str, int n, float x, float y) {
|
||||
|
||||
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
|
||||
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x), FloatToFixed(y));
|
||||
#else
|
||||
# error : neither Quartz no Quickdraw chosen
|
||||
#endif
|
||||
}
|
||||
|
||||
void fl_rtl_draw(const char* c, int n, int x, int y) {
|
||||
#if defined __APPLE_QD__
|
||||
fl_draw(c, n, x, y);
|
||||
#elif defined __APPLE_QUARTZ__
|
||||
// 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;
|
||||
@ -298,7 +376,11 @@ void fl_rtl_draw(const char* c, int n, int x, int y) {
|
||||
|
||||
err = ATSUSetTextPointerLocation(layout, uniStr, kATSUFromTextBeginning, n, n);
|
||||
err = ATSUDrawText(layout, kATSUFromTextBeginning, n, FloatToFixed(x-offs), FloatToFixed(y));
|
||||
#else
|
||||
# error : neither Quartz no Quickdraw chosen
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user