mirror of
https://github.com/gnustep/libs-back.git
synced 2025-06-01 01:41:00 +00:00
Implemented code to support different fonts.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@13813 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3025b25c61
commit
bbafa3d2cd
1 changed files with 120 additions and 2 deletions
|
@ -53,7 +53,11 @@
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
|
if (hFont)
|
||||||
|
{
|
||||||
|
DeleteObject(hFont);
|
||||||
|
hFont = NULL;
|
||||||
|
}
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,9 +65,12 @@
|
||||||
{
|
{
|
||||||
SIZE size;
|
SIZE size;
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
|
HFONT old;
|
||||||
|
|
||||||
hdc = GetDC(NULL);
|
hdc = GetDC(NULL);
|
||||||
|
old = SelectObject(hdc, hFont);
|
||||||
GetTextExtentPoint32(hdc, s, len, &size);
|
GetTextExtentPoint32(hdc, s, len, &size);
|
||||||
|
SelectObject(hdc, old);
|
||||||
ReleaseDC(NULL, hdc);
|
ReleaseDC(NULL, hdc);
|
||||||
|
|
||||||
return size.cx;
|
return size.cx;
|
||||||
|
@ -90,10 +97,13 @@
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
float w;
|
float w;
|
||||||
ABCFLOAT abc;
|
ABCFLOAT abc;
|
||||||
|
HFONT old;
|
||||||
|
|
||||||
hdc = GetDC(NULL);
|
hdc = GetDC(NULL);
|
||||||
|
old = SelectObject(hdc, hFont);
|
||||||
//GetCharWidthFloat(hdc, glyph, glyph, &w);
|
//GetCharWidthFloat(hdc, glyph, glyph, &w);
|
||||||
GetCharABCWidthsFloat(hdc, glyph, glyph, &abc);
|
GetCharABCWidthsFloat(hdc, glyph, glyph, &abc);
|
||||||
|
SelectObject(hdc, old);
|
||||||
ReleaseDC(NULL, hdc);
|
ReleaseDC(NULL, hdc);
|
||||||
|
|
||||||
//NSLog(@"Width for %d is %f or %f", glyph, w, (abc.abcfA + abc.abcfB + abc.abcfC));
|
//NSLog(@"Width for %d is %f or %f", glyph, w, (abc.abcfA + abc.abcfB + abc.abcfC));
|
||||||
|
@ -103,7 +113,30 @@
|
||||||
|
|
||||||
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
|
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
|
||||||
{
|
{
|
||||||
return NSMakeRect(0, 0, 0, 0);
|
HDC hdc;
|
||||||
|
HFONT old;
|
||||||
|
GLYPHMETRICS gm;
|
||||||
|
NSRect rect;
|
||||||
|
|
||||||
|
hdc = GetDC(NULL);
|
||||||
|
old = SelectObject(hdc, hFont);
|
||||||
|
if (GDI_ERROR != GetGlyphOutline(hdc, glyph,
|
||||||
|
GGO_METRICS, // || GGO_GLYPH_INDEX
|
||||||
|
&gm, 0, NULL, NULL))
|
||||||
|
{
|
||||||
|
rect = NSMakeRect(gm.gmptGlyphOrigin.x,
|
||||||
|
gm.gmptGlyphOrigin.y - gm.gmBlackBoxY,
|
||||||
|
gm.gmCellIncX, gm.gmCellIncY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rect = NSMakeRect(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectObject(hdc, old);
|
||||||
|
ReleaseDC(NULL, hdc);
|
||||||
|
|
||||||
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
|
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
|
||||||
|
@ -131,7 +164,11 @@
|
||||||
- (void) draw:(const char*)s lenght: (int)len
|
- (void) draw:(const char*)s lenght: (int)len
|
||||||
onDC: (HDC)hdc at: (POINT)p
|
onDC: (HDC)hdc at: (POINT)p
|
||||||
{
|
{
|
||||||
|
HFONT old;
|
||||||
|
|
||||||
|
old = SelectObject(hdc, hFont);
|
||||||
TextOut(hdc, p.x, p.y - ascender, s, len);
|
TextOut(hdc, p.x, p.y - ascender, s, len);
|
||||||
|
SelectObject(hdc, old);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -142,9 +179,37 @@
|
||||||
{
|
{
|
||||||
HDC hdc;
|
HDC hdc;
|
||||||
TEXTMETRIC metric;
|
TEXTMETRIC metric;
|
||||||
|
HFONT old;
|
||||||
|
LOGFONT logfont;
|
||||||
|
NSString *weightString;
|
||||||
|
NSRange range;
|
||||||
|
|
||||||
|
//NSLog(@"Creating Font %@ of size %f", fontName, matrix[0]);
|
||||||
|
memset(&logfont, 0, sizeof(LOGFONT));
|
||||||
|
// FIXME This hack gets the font size about right, but what is the real solution?
|
||||||
|
logfont.lfHeight = (int)(matrix[0] * 4 / 3);
|
||||||
|
|
||||||
|
range = [fontName rangeOfString: @"Bold"];
|
||||||
|
if (range.length)
|
||||||
|
logfont.lfWeight = FW_BOLD;
|
||||||
|
|
||||||
|
range = [fontName rangeOfString: @"Italic"];
|
||||||
|
if (range.length)
|
||||||
|
logfont.lfItalic = 1;
|
||||||
|
|
||||||
|
logfont.lfQuality = ANTIALIASED_QUALITY;
|
||||||
|
strncpy(logfont.lfFaceName, [fontName cString], LF_FACESIZE);
|
||||||
|
hFont = CreateFontIndirect(&logfont);
|
||||||
|
if (!hFont)
|
||||||
|
{
|
||||||
|
NSLog(@"Could not create font %@", fontName);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
hdc = GetDC(NULL);
|
hdc = GetDC(NULL);
|
||||||
|
old = SelectObject(hdc, hFont);
|
||||||
GetTextMetrics(hdc, &metric);
|
GetTextMetrics(hdc, &metric);
|
||||||
|
SelectObject(hdc, old);
|
||||||
ReleaseDC(NULL, hdc);
|
ReleaseDC(NULL, hdc);
|
||||||
|
|
||||||
// Fill the afmDitionary and ivars
|
// Fill the afmDitionary and ivars
|
||||||
|
@ -154,6 +219,7 @@
|
||||||
isFixedPitch = TMPF_FIXED_PITCH & metric.tmPitchAndFamily;
|
isFixedPitch = TMPF_FIXED_PITCH & metric.tmPitchAndFamily;
|
||||||
isBaseFont = NO;
|
isBaseFont = NO;
|
||||||
ascender = metric.tmAscent;
|
ascender = metric.tmAscent;
|
||||||
|
//NSLog(@"Resulted in height %d and ascent %d", metric.tmHeight, metric.tmAscent);
|
||||||
[fontDictionary setObject: [NSNumber numberWithFloat: ascender]
|
[fontDictionary setObject: [NSNumber numberWithFloat: ascender]
|
||||||
forKey: NSAFMAscender];
|
forKey: NSAFMAscender];
|
||||||
descender = -metric.tmDescent;
|
descender = -metric.tmDescent;
|
||||||
|
@ -165,6 +231,58 @@
|
||||||
(float)metric.tmMaxCharWidth,
|
(float)metric.tmMaxCharWidth,
|
||||||
(float)metric.tmHeight);
|
(float)metric.tmHeight);
|
||||||
|
|
||||||
|
// The MS names are a bit different from the NS ones!
|
||||||
|
switch (metric.tmWeight)
|
||||||
|
{
|
||||||
|
case FW_THIN:
|
||||||
|
weight = 1;
|
||||||
|
break;
|
||||||
|
case FW_EXTRALIGHT:
|
||||||
|
weight = 2;
|
||||||
|
break;
|
||||||
|
case FW_LIGHT:
|
||||||
|
weight = 3;
|
||||||
|
break;
|
||||||
|
case FW_REGULAR:
|
||||||
|
weight = 5;
|
||||||
|
break;
|
||||||
|
case FW_MEDIUM:
|
||||||
|
weight = 6;
|
||||||
|
break;
|
||||||
|
case FW_DEMIBOLD:
|
||||||
|
weight = 7;
|
||||||
|
break;
|
||||||
|
case FW_BOLD:
|
||||||
|
weight = 9;
|
||||||
|
break;
|
||||||
|
case FW_EXTRABOLD:
|
||||||
|
weight = 10;
|
||||||
|
break;
|
||||||
|
case FW_BLACK:
|
||||||
|
weight = 12;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Try to map the range 0 to 1000 into 1 to 14.
|
||||||
|
weight = (int)(metric.tmWeight * 14 / 1000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (weight >= 9)
|
||||||
|
traits |= NSBoldFontMask;
|
||||||
|
else
|
||||||
|
traits |= NSUnboldFontMask;
|
||||||
|
|
||||||
|
if (metric.tmItalic)
|
||||||
|
traits |= NSItalicFontMask;
|
||||||
|
else
|
||||||
|
traits |= NSUnitalicFontMask;
|
||||||
|
|
||||||
|
weightString = [GSFontInfo stringForWeight: weight];
|
||||||
|
if (weightString != nil)
|
||||||
|
{
|
||||||
|
[fontDictionary setObject: weightString forKey: NSAFMWeight];
|
||||||
|
}
|
||||||
|
|
||||||
// Should come from metric.tmCharSet
|
// Should come from metric.tmCharSet
|
||||||
mostCompatibleStringEncoding = NSISOLatin1StringEncoding;
|
mostCompatibleStringEncoding = NSISOLatin1StringEncoding;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue