2004-08-02 21:50:17 +00:00
|
|
|
/*
|
2007-10-29 23:25:10 +00:00
|
|
|
CairoFaceInfo.m
|
|
|
|
|
|
|
|
Copyright (C) 2003 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
August 31, 2003
|
|
|
|
Written by Banlu Kemiyatorn <object at gmail dot com>
|
|
|
|
Base on original code of Alex Malmberg
|
|
|
|
Rewrite: Fred Kiefer <fredkiefer@gmx.de>
|
|
|
|
Date: Jan 2006
|
|
|
|
|
|
|
|
This file is part of GNUstep.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
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
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
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.
|
|
|
|
*/
|
2004-08-02 21:50:17 +00:00
|
|
|
|
|
|
|
#include "cairo/CairoFaceInfo.h"
|
2011-03-28 04:19:41 +00:00
|
|
|
#include "cairo/CairoFontEnumerator.h"
|
2005-07-27 23:25:32 +00:00
|
|
|
#include <cairo-ft.h>
|
|
|
|
#include <AppKit/NSFontManager.h>
|
2004-08-02 21:50:17 +00:00
|
|
|
|
2008-03-29 13:16:58 +00:00
|
|
|
@implementation CairoFaceInfo
|
2004-08-02 21:50:17 +00:00
|
|
|
|
2007-12-11 12:06:42 +00:00
|
|
|
- (id) initWithfamilyName: (NSString *)familyName
|
2006-01-23 20:51:40 +00:00
|
|
|
weight: (int)weight
|
|
|
|
traits: (unsigned int)traits
|
2007-12-11 12:06:42 +00:00
|
|
|
pattern: (FcPattern *)pattern
|
2004-08-02 21:50:17 +00:00
|
|
|
{
|
2007-12-11 12:06:42 +00:00
|
|
|
_pattern = pattern;
|
|
|
|
FcPatternReference(_pattern);
|
2006-01-23 20:51:40 +00:00
|
|
|
|
2004-08-02 21:50:17 +00:00
|
|
|
[self setFamilyName: familyName];
|
|
|
|
[self setWeight: weight];
|
|
|
|
[self setTraits: traits];
|
2007-12-11 12:06:42 +00:00
|
|
|
|
|
|
|
return self;
|
2004-08-02 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
2005-07-27 23:25:32 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2005-07-27 23:29:51 +00:00
|
|
|
if (_fontFace)
|
|
|
|
{
|
|
|
|
cairo_font_face_destroy(_fontFace);
|
|
|
|
}
|
2007-12-11 12:06:42 +00:00
|
|
|
FcPatternDestroy(_pattern);
|
2005-07-27 23:25:32 +00:00
|
|
|
RELEASE(_familyName);
|
2006-01-23 20:51:40 +00:00
|
|
|
|
2005-07-27 23:25:32 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2004-08-02 21:50:17 +00:00
|
|
|
- (void) setFamilyName: (NSString *)name
|
|
|
|
{
|
|
|
|
ASSIGN(_familyName, name);
|
|
|
|
}
|
|
|
|
|
2007-12-11 12:06:42 +00:00
|
|
|
- (NSString *)familyName
|
2007-12-11 00:14:01 +00:00
|
|
|
{
|
2007-12-11 12:06:42 +00:00
|
|
|
return _familyName;
|
2004-08-02 21:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) weight
|
|
|
|
{
|
|
|
|
return _weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setWeight: (int)weight
|
|
|
|
{
|
|
|
|
_weight = weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) traits
|
|
|
|
{
|
|
|
|
return _traits;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTraits: (unsigned int)traits
|
|
|
|
{
|
|
|
|
_traits = traits;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) cacheSize
|
|
|
|
{
|
|
|
|
return 257;
|
|
|
|
}
|
|
|
|
|
2007-12-11 00:14:01 +00:00
|
|
|
- (cairo_font_face_t *)fontFace
|
|
|
|
{
|
|
|
|
if (!_fontFace)
|
|
|
|
{
|
2007-12-11 12:06:42 +00:00
|
|
|
FcResult result;
|
|
|
|
FcPattern *resolved;
|
|
|
|
|
2008-03-29 13:16:58 +00:00
|
|
|
FcConfigSubstitute(NULL, _pattern, FcMatchPattern);
|
2007-12-11 12:06:42 +00:00
|
|
|
FcDefaultSubstitute(_pattern);
|
|
|
|
resolved = FcFontMatch(NULL, _pattern, &result);
|
|
|
|
|
|
|
|
_fontFace = cairo_ft_font_face_create_for_pattern(resolved);
|
|
|
|
FcPatternDestroy(resolved);
|
|
|
|
|
2008-03-29 13:16:58 +00:00
|
|
|
if (cairo_font_face_status(_fontFace) != CAIRO_STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
NSLog(@"Creating a font face failed %@", _familyName);
|
|
|
|
cairo_font_face_destroy(_fontFace);
|
|
|
|
_fontFace = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-07-27 23:29:51 +00:00
|
|
|
}
|
2005-07-27 23:25:32 +00:00
|
|
|
|
|
|
|
return _fontFace;
|
|
|
|
}
|
|
|
|
|
2011-03-28 04:19:41 +00:00
|
|
|
- (NSCharacterSet*)characterSet
|
|
|
|
{
|
2011-05-05 19:18:43 +00:00
|
|
|
FcCharSet *fcCharset;
|
2011-03-28 04:19:41 +00:00
|
|
|
NSCharacterSet *characterSet = nil;
|
|
|
|
|
2011-05-05 19:18:43 +00:00
|
|
|
if (FcResultMatch == FcPatternGetCharSet(_pattern, FC_CHARSET, 0, &fcCharset))
|
2011-03-28 04:19:41 +00:00
|
|
|
{
|
2011-05-05 19:18:43 +00:00
|
|
|
characterSet = [[[FontconfigCharacterSet alloc] initWithFontconfigCharSet: fcCharset] autorelease];
|
2011-03-28 04:19:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return characterSet;
|
|
|
|
}
|
|
|
|
|
2004-08-02 21:50:17 +00:00
|
|
|
@end
|