3
* Font handling routines for Mac OS X.
5
* Copyright (c) 1999. See accompanying LEGAL file for details.
10
static char* families[5][4] =
12
"CourierNewPS-BoldMT",
13
"CourierNewPS-ItalicMT",
14
"CourierNewPS-BoldItalicMT"},
22
"Arial-BoldItalicMT"},
28
"CenturySchoolbook-Bold",
29
"CenturySchoolbook-Italic",
30
"CenturySchoolbook-BoldItalic"}};
33
m_font(p_scr* s, int fontid, CGFontRef* fontref, ATSFontMetrics** metric);
36
p_font(p_win *w, int fontid, int pixsize, int orient)
38
CGContextRef cr = w->cr;
43
if (fontid != w->fontid)
44
{ m_font(s, fontid, &(w->fontref), NULL);
48
CGContextSetFont(cr, w->fontref);
49
CGContextSetFontSize(cr, (float) pixsize);
53
p_txheight(p_scr *s, int fontid, int pixsize, int *baseline)
54
{ ATSFontMetrics* metric;
58
float ascent, descent;
59
m_font(s, fontid, NULL, &metric);
60
ascent = pixsize * (metric->ascent);
61
descent = pixsize * (metric->descent);
63
height = (int) (ascent - descent);
67
if (baseline) *baseline = base;
72
p_txwidth(p_scr *s, const char *text, int n, int fontid, int pixsize)
73
{ int width = pixsize;
77
CGContextRef cr = s->scratch;
79
m_font(s, fontid, &font, NULL);
80
CGContextSetFont(cr, font);
81
CGContextSetFontSize(cr, (float) pixsize);
82
CGContextSetTextPosition(cr, 0.0, 0.0);
83
for (i = 0; i < n; i++)
84
{ CGGlyph c = (unsigned short)(text[i]) - 29;
85
CGContextShowGlyphs(cr, &c, 1);
87
point = CGContextGetTextPosition(cr);
88
width = (int) (point.x);
96
m_font(p_scr* s, int fontid, CGFontRef* fontref, ATSFontMetrics** metric)
98
int face = ((unsigned int)(fontid&0x1c))>>2;
100
if(fontref) *fontref = s->font;
101
if(metric) *metric = &(s->metric);
104
else index = (fontid&P_ITALIC) + (fontid&P_BOLD);
105
if (!(s->fonts[face][index]))
106
{ CFStringRef family = CFStringCreateWithCString(kCFAllocatorDefault,
107
families[face][index],
108
kCFStringEncodingMacRoman);
109
ATSFontRef atsfont = ATSFontFindFromPostScriptName(family,
110
kATSOptionFlagsDefault);
111
/* Some fonts are not found, although the family name is correct and
112
* the font can be found with [NSFont fontWithName: size:] */
113
ATSFontMetrics* newmetric = &(s->metrics[face][index]);
114
ATSFontGetHorizontalMetrics(atsfont, kATSOptionFlagsDefault, newmetric);
115
s->fonts[face][index] = CGFontCreateWithPlatformFont((void*)&atsfont);
117
/* atsfont is an unsigned integer (UInt32); I assume it should not be
120
if(fontref) *fontref = s->fonts[face][index];
121
if(metric) *metric = &(s->metrics[face][index]);