2002-04-21 22:51:21 +00:00
|
|
|
/* Win32FontInfo - Implements font enumerator for MSWindows
|
|
|
|
|
|
|
|
Copyright (C) 2002 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Fred Kiefer <FredKiefer@gmx.de>
|
|
|
|
Date: March 2002
|
|
|
|
|
|
|
|
This file is part of the GNU Objective C User Interface Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 23:25:10 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2002-04-21 22:51:21 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:12:46 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 23:25:10 +00:00
|
|
|
|
2002-04-21 22:51:21 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 23:25:10 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
2002-04-21 22:51:21 +00:00
|
|
|
*/
|
|
|
|
|
2007-01-31 17:15:27 +00:00
|
|
|
#include <Foundation/NSCharacterSet.h>
|
2002-04-21 22:51:21 +00:00
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSValue.h>
|
2008-04-04 22:07:03 +00:00
|
|
|
#include <AppKit/NSBezierPath.h>
|
2002-04-21 22:51:21 +00:00
|
|
|
|
|
|
|
#include "winlib/WIN32FontInfo.h"
|
|
|
|
|
2003-12-23 16:42:40 +00:00
|
|
|
int win32_font_weight(LONG tmWeight);
|
|
|
|
NSString *win32_font_family(NSString *fontName);
|
|
|
|
|
2002-04-21 22:51:21 +00:00
|
|
|
@interface WIN32FontInfo (Private)
|
|
|
|
- (BOOL) setupAttributes;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation WIN32FontInfo
|
|
|
|
|
2003-01-26 19:07:53 +00:00
|
|
|
- initWithFontName: (NSString*)name
|
|
|
|
matrix: (const float *)fmatrix
|
|
|
|
screenFont: (BOOL)screenFont
|
2002-04-21 22:51:21 +00:00
|
|
|
{
|
2003-01-26 19:07:53 +00:00
|
|
|
if (screenFont)
|
|
|
|
{
|
|
|
|
RELEASE(self);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2002-04-21 22:51:21 +00:00
|
|
|
[super init];
|
|
|
|
ASSIGN(fontName, name);
|
|
|
|
memcpy(matrix, fmatrix, sizeof(matrix));
|
|
|
|
|
|
|
|
if (![self setupAttributes])
|
|
|
|
{
|
|
|
|
RELEASE(self);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2002-06-09 15:45:13 +00:00
|
|
|
if (hFont)
|
|
|
|
{
|
|
|
|
DeleteObject(hFont);
|
|
|
|
hFont = NULL;
|
|
|
|
}
|
2002-04-21 22:51:21 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-01-31 11:03:42 +00:00
|
|
|
- (float) widthOfString: (NSString*)string
|
2002-04-21 22:51:21 +00:00
|
|
|
{
|
|
|
|
SIZE size;
|
|
|
|
HDC hdc;
|
2002-06-09 15:45:13 +00:00
|
|
|
HFONT old;
|
2002-04-21 22:51:21 +00:00
|
|
|
|
2008-04-04 22:07:03 +00:00
|
|
|
hdc = CreateCompatibleDC(NULL);
|
2002-06-09 15:45:13 +00:00
|
|
|
old = SelectObject(hdc, hFont);
|
2007-01-31 11:03:42 +00:00
|
|
|
GetTextExtentPoint32W(hdc,
|
|
|
|
(const unichar*)[string cStringUsingEncoding: NSUnicodeStringEncoding],
|
|
|
|
[string length],
|
|
|
|
&size);
|
2002-06-09 15:45:13 +00:00
|
|
|
SelectObject(hdc, old);
|
2008-04-04 22:07:03 +00:00
|
|
|
DeleteDC(hdc);
|
2002-04-21 22:51:21 +00:00
|
|
|
|
|
|
|
return size.cx;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMultibyteGlyphPacking)glyphPacking
|
|
|
|
{
|
|
|
|
return NSOneByteGlyphPacking;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize) advancementForGlyph: (NSGlyph)glyph
|
|
|
|
{
|
2007-02-08 09:30:51 +00:00
|
|
|
unichar u = (unichar)glyph;
|
2002-04-21 22:51:21 +00:00
|
|
|
HDC hdc;
|
|
|
|
float w;
|
|
|
|
ABCFLOAT abc;
|
2002-06-09 15:45:13 +00:00
|
|
|
HFONT old;
|
2002-04-21 22:51:21 +00:00
|
|
|
|
2008-04-04 22:07:03 +00:00
|
|
|
hdc = CreateCompatibleDC(NULL);
|
2002-06-09 15:45:13 +00:00
|
|
|
old = SelectObject(hdc, hFont);
|
2007-02-08 09:30:51 +00:00
|
|
|
// FIXME ... currently a gnustep glyph is a unichar ... what if that changes.
|
|
|
|
GetCharABCWidthsFloatW(hdc, u, u, &abc);
|
2002-06-09 15:45:13 +00:00
|
|
|
SelectObject(hdc, old);
|
2008-04-04 22:07:03 +00:00
|
|
|
DeleteDC(hdc);
|
2002-04-21 22:51:21 +00:00
|
|
|
|
|
|
|
//NSLog(@"Width for %d is %f or %f", glyph, w, (abc.abcfA + abc.abcfB + abc.abcfC));
|
|
|
|
w = abc.abcfA + abc.abcfB + abc.abcfC;
|
|
|
|
return NSMakeSize(w, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
|
|
|
|
{
|
2007-02-01 08:06:45 +00:00
|
|
|
WORD c = (WORD)glyph;
|
2007-02-01 07:09:35 +00:00
|
|
|
WORD windowsGlyph;
|
2002-06-09 15:45:13 +00:00
|
|
|
HDC hdc;
|
|
|
|
HFONT old;
|
|
|
|
GLYPHMETRICS gm;
|
|
|
|
NSRect rect;
|
|
|
|
|
2008-04-04 22:07:03 +00:00
|
|
|
hdc = CreateCompatibleDC(NULL);
|
2002-06-09 15:45:13 +00:00
|
|
|
old = SelectObject(hdc, hFont);
|
2007-02-01 07:09:35 +00:00
|
|
|
// Convert from GNUstep glyph (unichar) to windows glyph.
|
2007-02-08 09:30:51 +00:00
|
|
|
if (GetGlyphIndicesW(hdc, &c, 1, &windowsGlyph, 0) == GDI_ERROR)
|
2007-02-01 07:09:35 +00:00
|
|
|
{
|
|
|
|
SelectObject(hdc, old);
|
2008-04-04 22:07:03 +00:00
|
|
|
DeleteDC(hdc);
|
2007-02-01 08:06:45 +00:00
|
|
|
NSLog(@"No glyph for U%d", c);
|
2007-02-01 07:09:35 +00:00
|
|
|
return NSMakeRect(0, 0, 0, 0); // No such glyph
|
|
|
|
}
|
|
|
|
if (GDI_ERROR != GetGlyphOutlineW(hdc, windowsGlyph,
|
2002-06-09 15:45:13 +00:00
|
|
|
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);
|
2008-04-04 22:07:03 +00:00
|
|
|
DeleteDC(hdc);
|
2002-06-09 15:45:13 +00:00
|
|
|
|
|
|
|
return rect;
|
2002-04-21 22:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
|
|
|
|
{
|
2008-04-04 22:07:03 +00:00
|
|
|
WORD c = (WORD)glyph;
|
|
|
|
WORD windowsGlyph;
|
|
|
|
HDC hdc;
|
|
|
|
HFONT old;
|
|
|
|
BOOL result = YES;
|
|
|
|
|
|
|
|
hdc = CreateCompatibleDC(NULL);
|
|
|
|
old = SelectObject(hdc, hFont);
|
|
|
|
// Convert from GNUstep glyph (unichar) to windows glyph.
|
2008-04-13 19:39:33 +00:00
|
|
|
if ((GetGlyphIndicesW(hdc, &c, 1, &windowsGlyph,
|
|
|
|
GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR)
|
2008-04-04 22:07:03 +00:00
|
|
|
|| (windowsGlyph == 0xFFFF))
|
|
|
|
{
|
|
|
|
result = NO;
|
|
|
|
}
|
|
|
|
SelectObject(hdc, old);
|
|
|
|
DeleteDC(hdc);
|
|
|
|
return result;
|
2002-04-21 22:51:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSGlyph) glyphWithName: (NSString*)glyphName
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPoint) positionOfGlyph: (NSGlyph)curGlyph
|
|
|
|
precededByGlyph: (NSGlyph)prevGlyph
|
|
|
|
isNominal: (BOOL*)nominal
|
|
|
|
{
|
|
|
|
return NSMakePoint(0, 0);
|
|
|
|
}
|
|
|
|
|
2007-01-31 17:15:27 +00:00
|
|
|
- (NSCharacterSet*) coveredCharacterSet
|
|
|
|
{
|
|
|
|
if (coveredCharacterSet == nil)
|
|
|
|
{
|
|
|
|
NSMutableCharacterSet *ms;
|
|
|
|
unsigned count;
|
|
|
|
GLYPHSET *gs = 0;
|
|
|
|
HDC hdc;
|
|
|
|
HFONT old;
|
|
|
|
|
2007-09-04 08:17:54 +00:00
|
|
|
ms = [NSMutableCharacterSet new];
|
2008-12-17 20:40:25 +00:00
|
|
|
if (!ms)
|
|
|
|
return nil;
|
|
|
|
|
2008-04-04 22:07:03 +00:00
|
|
|
hdc = CreateCompatibleDC(NULL);
|
2007-01-31 17:15:27 +00:00
|
|
|
old = SelectObject(hdc, hFont);
|
|
|
|
count = (unsigned)GetFontUnicodeRanges(hdc, 0);
|
|
|
|
if (count > 0)
|
2007-09-04 08:17:54 +00:00
|
|
|
{
|
2007-01-31 17:15:27 +00:00
|
|
|
gs = (GLYPHSET*)objc_malloc(count);
|
2008-12-17 20:40:25 +00:00
|
|
|
if (!gs)
|
|
|
|
{
|
|
|
|
SelectObject(hdc, old);
|
|
|
|
DeleteDC(hdc);
|
|
|
|
RELEASE(ms);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
gs->cbThis = count;
|
2007-01-31 17:15:27 +00:00
|
|
|
if ((unsigned)GetFontUnicodeRanges(hdc, gs) == count)
|
2007-09-04 08:17:54 +00:00
|
|
|
{
|
|
|
|
numberOfGlyphs = gs->cGlyphsSupported;
|
|
|
|
if (gs->flAccel == 1 /* GS_8BIT_INDICES */)
|
|
|
|
{
|
|
|
|
for (count = 0; count < gs->cRanges; count++)
|
|
|
|
{
|
|
|
|
NSRange range;
|
|
|
|
|
|
|
|
range.location = gs->ranges[count].wcLow & 0xff;
|
|
|
|
range.length = gs->ranges[count].cGlyphs;
|
|
|
|
[ms addCharactersInRange: range];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (count = 0; count < gs->cRanges; count++)
|
|
|
|
{
|
|
|
|
NSRange range;
|
|
|
|
|
|
|
|
range.location = gs->ranges[count].wcLow;
|
|
|
|
range.length = gs->ranges[count].cGlyphs;
|
|
|
|
[ms addCharactersInRange: range];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-31 17:15:27 +00:00
|
|
|
objc_free(gs);
|
2007-09-04 08:17:54 +00:00
|
|
|
}
|
2007-01-31 17:15:27 +00:00
|
|
|
SelectObject(hdc, old);
|
2008-04-04 22:07:03 +00:00
|
|
|
DeleteDC(hdc);
|
2007-01-31 17:15:27 +00:00
|
|
|
coveredCharacterSet = [ms copy];
|
|
|
|
RELEASE(ms);
|
|
|
|
}
|
2007-09-04 08:17:54 +00:00
|
|
|
|
2007-01-31 17:15:27 +00:00
|
|
|
return coveredCharacterSet;
|
|
|
|
}
|
|
|
|
|
2007-02-01 07:09:35 +00:00
|
|
|
- (void) drawString: (NSString*)string
|
2008-04-04 22:07:03 +00:00
|
|
|
onDC: (HDC)hdc
|
|
|
|
at: (POINT)p
|
2002-04-21 22:51:21 +00:00
|
|
|
{
|
2007-01-31 14:05:19 +00:00
|
|
|
HFONT old;
|
|
|
|
|
|
|
|
old = SelectObject(hdc, hFont);
|
|
|
|
TextOutW(hdc,
|
|
|
|
p.x,
|
|
|
|
p.y - ascender,
|
|
|
|
(const unichar*)[string cStringUsingEncoding: NSUnicodeStringEncoding],
|
|
|
|
[string length]);
|
|
|
|
SelectObject(hdc, old);
|
2002-04-21 22:51:21 +00:00
|
|
|
}
|
|
|
|
|
2006-05-16 13:22:10 +00:00
|
|
|
- (void) draw:(const char*)s length: (int)len
|
2002-04-21 22:51:21 +00:00
|
|
|
onDC: (HDC)hdc at: (POINT)p
|
|
|
|
{
|
2002-06-09 15:45:13 +00:00
|
|
|
HFONT old;
|
|
|
|
|
|
|
|
old = SelectObject(hdc, hFont);
|
2002-04-21 22:51:21 +00:00
|
|
|
TextOut(hdc, p.x, p.y - ascender, s, len);
|
2002-06-09 15:45:13 +00:00
|
|
|
SelectObject(hdc, old);
|
2002-04-21 22:51:21 +00:00
|
|
|
}
|
|
|
|
|
2003-02-06 12:09:17 +00:00
|
|
|
- (void) drawGlyphs: (const NSGlyph*)s
|
2008-04-04 22:07:03 +00:00
|
|
|
length: (int)len
|
|
|
|
onDC: (HDC)hdc
|
|
|
|
at: (POINT)p
|
2003-02-06 12:09:17 +00:00
|
|
|
{
|
2007-02-01 07:09:35 +00:00
|
|
|
WORD buf[len];
|
2003-02-06 12:09:17 +00:00
|
|
|
HFONT old;
|
2007-02-01 07:09:35 +00:00
|
|
|
int i;
|
2003-02-06 12:09:17 +00:00
|
|
|
|
2007-02-01 07:09:35 +00:00
|
|
|
old = SelectObject(hdc, hFont);
|
2003-02-06 12:09:17 +00:00
|
|
|
/*
|
|
|
|
* For now, assume that a glyph is a unicode character and can be
|
|
|
|
* stored in a windows WORD
|
|
|
|
*/
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
2007-02-01 07:09:35 +00:00
|
|
|
buf[i] = (WORD)s[i];
|
2003-02-06 12:09:17 +00:00
|
|
|
}
|
|
|
|
TextOutW(hdc, p.x, p.y - ascender, buf, len);
|
|
|
|
SelectObject(hdc, old);
|
|
|
|
}
|
|
|
|
|
2007-01-31 17:15:27 +00:00
|
|
|
- (unsigned) numberOfglyphs
|
|
|
|
{
|
|
|
|
if (coveredCharacterSet == nil)
|
|
|
|
{
|
|
|
|
[self coveredCharacterSet];
|
|
|
|
}
|
|
|
|
return numberOfGlyphs;
|
|
|
|
}
|
|
|
|
|
2008-04-04 22:07:03 +00:00
|
|
|
- (void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
|
|
|
|
count: (int)length
|
|
|
|
toBezierPath: (NSBezierPath *)path
|
|
|
|
{
|
|
|
|
WORD buf[length];
|
|
|
|
int i;
|
|
|
|
SIZE sBoundBox;
|
|
|
|
int h;
|
|
|
|
int iPoints;
|
|
|
|
POINT *ptPoints;
|
|
|
|
BYTE *bTypes;
|
|
|
|
NSPoint startPoint;
|
|
|
|
HDC hDC = CreateCompatibleDC(NULL);
|
|
|
|
|
|
|
|
if (!hDC)
|
|
|
|
{
|
|
|
|
NSDebugLLog(@"WIN32FontInfo",
|
|
|
|
@"Problem creating HDC for appendBezierPathWithGlyphs:");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetGraphicsMode(hDC, GM_ADVANCED);
|
|
|
|
SetMapMode(hDC, MM_ANISOTROPIC);
|
|
|
|
SetWindowExtEx(hDC, 1, 1, NULL);
|
|
|
|
SetViewportExtEx(hDC, 1, -1, NULL);
|
|
|
|
SetViewportOrgEx(hDC, 0, 0, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For now, assume that a glyph is a unicode character and can be
|
|
|
|
* stored in a windows WORD
|
|
|
|
*/
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
buf[i] = glyphs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectObject(hDC, hFont);
|
|
|
|
GetTextExtentPoint32W(hDC, buf, length, &sBoundBox);
|
|
|
|
h = sBoundBox.cy;
|
|
|
|
|
|
|
|
if ([path elementCount] > 0)
|
|
|
|
{
|
|
|
|
startPoint = [path currentPoint];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
startPoint = NSZeroPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetBkMode(hDC, TRANSPARENT);
|
|
|
|
BeginPath(hDC);
|
|
|
|
SetTextAlign(hDC, TA_LEFT | TA_TOP);
|
|
|
|
TextOutW(hDC, startPoint.x, -startPoint.y, buf, length);
|
|
|
|
EndPath(hDC);
|
|
|
|
|
|
|
|
iPoints = GetPath(hDC, NULL, NULL, 0);
|
|
|
|
if (iPoints == 0)
|
|
|
|
{
|
|
|
|
DeleteDC(hDC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptPoints = objc_malloc(sizeof(POINT) * iPoints);
|
|
|
|
if (!ptPoints)
|
|
|
|
{
|
|
|
|
DeleteDC(hDC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bTypes = objc_malloc(sizeof(BYTE) * iPoints);
|
|
|
|
if (!bTypes)
|
|
|
|
{
|
|
|
|
objc_free(ptPoints);
|
|
|
|
DeleteDC(hDC);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetPath(hDC, ptPoints, bTypes, iPoints);
|
|
|
|
|
|
|
|
// Now append the glyphs to the path
|
|
|
|
i = 0;
|
|
|
|
while (i < iPoints)
|
|
|
|
{
|
|
|
|
if (bTypes[i] == PT_MOVETO)
|
|
|
|
{
|
|
|
|
[path moveToPoint: NSMakePoint(ptPoints[i].x, h - ptPoints[i].y)];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else if (bTypes[i] & PT_LINETO)
|
|
|
|
{
|
|
|
|
[path lineToPoint: NSMakePoint(ptPoints[i].x, h - ptPoints[i].y)];
|
|
|
|
if (bTypes[i] & PT_CLOSEFIGURE)
|
|
|
|
[path closePath];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else if (bTypes[i] & PT_BEZIERTO)
|
|
|
|
{
|
|
|
|
// FIXME: We assume windows isn't lying here about the bezier points
|
|
|
|
[path curveToPoint: NSMakePoint(ptPoints[i+2].x, h - ptPoints[i+2].y)
|
|
|
|
controlPoint1: NSMakePoint(ptPoints[i].x, h - ptPoints[i].y)
|
|
|
|
controlPoint2: NSMakePoint(ptPoints[i+1].x, h - ptPoints[i+1].y)];
|
|
|
|
if ((bTypes[i] & PT_CLOSEFIGURE) || (bTypes[i+1] & PT_CLOSEFIGURE)
|
|
|
|
|| (bTypes[i+2] & PT_CLOSEFIGURE))
|
|
|
|
[path closePath];
|
|
|
|
i += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
objc_free(bTypes);
|
|
|
|
objc_free(ptPoints);
|
|
|
|
DeleteDC(hDC);
|
|
|
|
}
|
|
|
|
|
2002-04-21 22:51:21 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation WIN32FontInfo (Private)
|
|
|
|
|
|
|
|
- (BOOL) setupAttributes
|
|
|
|
{
|
|
|
|
HDC hdc;
|
2007-01-31 12:43:55 +00:00
|
|
|
TEXTMETRICW metric;
|
2002-06-09 15:45:13 +00:00
|
|
|
HFONT old;
|
2007-01-31 11:03:42 +00:00
|
|
|
LOGFONTW logfont;
|
2002-06-09 15:45:13 +00:00
|
|
|
NSRange range;
|
|
|
|
|
|
|
|
//NSLog(@"Creating Font %@ of size %f", fontName, matrix[0]);
|
2003-12-23 16:42:40 +00:00
|
|
|
ASSIGN(familyName, win32_font_family(fontName));
|
2002-06-09 15:45:13 +00:00
|
|
|
memset(&logfont, 0, sizeof(LOGFONT));
|
2008-04-04 22:07:03 +00:00
|
|
|
hdc = CreateCompatibleDC(NULL);
|
2002-06-09 15:45:13 +00:00
|
|
|
// FIXME This hack gets the font size about right, but what is the real solution?
|
|
|
|
logfont.lfHeight = (int)(matrix[0] * 4 / 3);
|
2003-12-23 16:42:40 +00:00
|
|
|
//logfont.lfHeight = -MulDiv(matrix[0], GetDeviceCaps(hdc, LOGPIXELSY), 72);
|
2002-06-09 15:45:13 +00:00
|
|
|
|
|
|
|
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;
|
2007-01-31 11:03:42 +00:00
|
|
|
wcsncpy(logfont.lfFaceName,
|
|
|
|
(const unichar*)[familyName cStringUsingEncoding: NSUnicodeStringEncoding],
|
|
|
|
LF_FACESIZE);
|
|
|
|
hFont = CreateFontIndirectW(&logfont);
|
2002-06-09 15:45:13 +00:00
|
|
|
if (!hFont)
|
|
|
|
{
|
|
|
|
NSLog(@"Could not create font %@", fontName);
|
2008-04-04 22:07:03 +00:00
|
|
|
DeleteDC(hdc);
|
2002-06-09 15:45:13 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2002-04-21 22:51:21 +00:00
|
|
|
|
2002-06-09 15:45:13 +00:00
|
|
|
old = SelectObject(hdc, hFont);
|
2007-01-31 12:43:55 +00:00
|
|
|
GetTextMetricsW(hdc, &metric);
|
2002-06-09 15:45:13 +00:00
|
|
|
SelectObject(hdc, old);
|
2008-04-04 22:07:03 +00:00
|
|
|
DeleteDC(hdc);
|
2002-04-21 22:51:21 +00:00
|
|
|
|
2003-04-27 15:49:27 +00:00
|
|
|
// Fill the ivars
|
2002-04-21 22:51:21 +00:00
|
|
|
isFixedPitch = TMPF_FIXED_PITCH & metric.tmPitchAndFamily;
|
|
|
|
isBaseFont = NO;
|
|
|
|
ascender = metric.tmAscent;
|
2002-06-09 15:45:13 +00:00
|
|
|
//NSLog(@"Resulted in height %d and ascent %d", metric.tmHeight, metric.tmAscent);
|
2002-04-21 22:51:21 +00:00
|
|
|
descender = -metric.tmDescent;
|
2007-02-27 16:35:31 +00:00
|
|
|
/* TODO */
|
|
|
|
xHeight = ascender * 0.5;
|
|
|
|
maximumAdvancement = NSMakeSize((float)metric.tmMaxCharWidth, 0.0);
|
2002-04-21 22:51:21 +00:00
|
|
|
|
|
|
|
fontBBox = NSMakeRect((float)(0),
|
|
|
|
(float)(0 - metric.tmAscent),
|
|
|
|
(float)metric.tmMaxCharWidth,
|
|
|
|
(float)metric.tmHeight);
|
|
|
|
|
2003-12-23 16:42:40 +00:00
|
|
|
weight = win32_font_weight(metric.tmWeight);
|
2002-06-09 15:45:13 +00:00
|
|
|
|
2003-12-23 16:42:40 +00:00
|
|
|
traits = 0;
|
2002-06-09 15:45:13 +00:00
|
|
|
if (weight >= 9)
|
|
|
|
traits |= NSBoldFontMask;
|
|
|
|
else
|
|
|
|
traits |= NSUnboldFontMask;
|
|
|
|
|
|
|
|
if (metric.tmItalic)
|
|
|
|
traits |= NSItalicFontMask;
|
|
|
|
else
|
|
|
|
traits |= NSUnitalicFontMask;
|
|
|
|
|
2003-12-23 16:42:40 +00:00
|
|
|
// FIXME Should come from metric.tmCharSet
|
2002-04-21 22:51:21 +00:00
|
|
|
mostCompatibleStringEncoding = NSISOLatin1StringEncoding;
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|