Minor tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@24444 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2007-01-31 15:52:53 +00:00
parent 7fe98410a6
commit 00622e1e14
5 changed files with 147 additions and 81 deletions

View file

@ -1,3 +1,11 @@
2007-01-31 Richard Frith-Macdonald <rfm@gnu.org>
* Source/art/ftfont.m: Implement methods to get count of characters
and characterset based on code by Yen-Ju Chen
* Source/cairo/CairoFontEnumerator.m: Tidy layout
* Source/cairo/CairoFaceInfo.m: ditto
* Source/cairo/CairoFontInfo.m: ditto
2007-01-31 Richard Frith-Macdonald <rfm@gnu.org>
* Source/win32/WIN32Server.m:

View file

@ -101,8 +101,8 @@ static BOOL anti_alias_by_default;
BOOL screenFont;
FTFaceInfo *face_info;
FT_Size ft_size;
/*
Profiling (2003-11-14) shows that calls to -advancementForGlyph: accounted
@ -675,7 +675,6 @@ static FT_Error ft_get_face(FTC_FaceID fid, FT_Library lib, FT_Pointer data, FT_
matrix: (const float *)fmatrix
screenFont: (BOOL)p_screenFont
{
FT_Size size;
NSArray *rfi;
FTFaceInfo *font_entry;
FT_Error error;
@ -758,22 +757,22 @@ static FT_Error ft_get_face(FTC_FaceID fid, FT_Library lib, FT_Pointer data, FT_
scaler.height = pix_height;
scaler.pixel = 1;
if ((error = FTC_Manager_LookupSize(ftc_manager, &scaler, &size)))
if ((error = FTC_Manager_LookupSize(ftc_manager, &scaler, &ft_size)))
{
NSLog(@"FTC_Manager_LookupSize() failed for '%@', error %08x!",
name, error);
return self;
}
// xHeight = size->metrics.height / 64.0;
// xHeight = ft_size->metrics.height / 64.0;
/* TODO: these are _really_ messed up when fonts are flipped */
/* TODO: need to look acrefully at these and make sure they are correct */
ascender = fabs(((int)size->metrics.ascender) / 64.0);
descender = fabs(((int)size->metrics.descender) / 64.0);
lineHeight = (int)size->metrics.height / 64.0;
ascender = fabs(((int)ft_size->metrics.ascender) / 64.0);
descender = fabs(((int)ft_size->metrics.descender) / 64.0);
lineHeight = (int)ft_size->metrics.height / 64.0;
xHeight = ascender * 0.5; /* TODO */
maximumAdvancement
= NSMakeSize((size->metrics.max_advance / 64.0), ascender + descender);
= NSMakeSize((ft_size->metrics.max_advance / 64.0), ascender + descender);
fontBBox
= NSMakeRect(0, descender, maximumAdvancement.width, ascender + descender);
@ -787,7 +786,7 @@ static FT_Error ft_get_face(FTC_FaceID fid, FT_Library lib, FT_Pointer data, FT_
{
int i;
FT_Face face = size->face;
FT_Face face = ft_size->face;
FT_CharMap cmap;
FT_Encoding e;
unicodeCmap = 0;
@ -873,12 +872,64 @@ static FT_Error ft_get_face(FTC_FaceID fid, FT_Library lib, FT_Pointer data, FT_
NSLog(@"ignore -set method of font '%@'", fontName);
}
- (NSCharacterSet*) coveredCharacterSet
{
if (coveredCharacterSet == nil)
{
NSMutableCharacterSet *m = [NSMutableCharacterSet new];
unsigned count = 0;
FT_Face face = ft_size->face;
FT_ULong charcode;
FT_UInt glyphindex;
charcode = FT_Get_First_Char(face, &glyphindex);
if (glyphindex != 0)
{
NSRange range;
range.location = charcode;
range.length = 0;
while (glyphindex != 0)
{
count++;
if (charcode == NSMaxRange(range))
{
range.length++;
}
else
{
[m addCharactersInRange: range];
range.location = charcode;
range.length = 0;
}
charcode = FT_Get_Next_Char(face, charcode, &glyphindex);
}
if (range.length > 0)
{
[m addCharactersInRange: range];
}
}
coveredCharacterSet = [m copy];
numberOfGlyphs = count;
RELEASE(m);
}
return coveredCharacterSet;
}
- (float) defaultLineHeightForFont
{
return lineHeight;
}
- (unsigned) numberOfGlyphs
{
if (coveredCharacterSet == nil)
{
[self coveredCharacterSet];
}
return numberOfGlyphs;
}
#include <GNUstepBase/Unicode.h>
@ -2636,7 +2687,7 @@ static int filters[3][7]=
};
+(void) initializeBackend
+ (void) initializeBackend
{
[GSFontEnumerator setDefaultClass: [FTFontEnumerator class]];
[GSFontInfo setDefaultClass: [FTFontInfo class]];

View file

@ -20,7 +20,8 @@
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111 USA.
*/
#include "cairo/CairoFaceInfo.h"
@ -34,8 +35,8 @@
traits: (unsigned int)traits
pattern: (FcPattern *)pattern
{
_pattern = pattern;
FcPatternReference(_pattern);
_pattern = pattern;
FcPatternReference(_pattern);
[self setFamilyName: familyName];
[self setWeight: weight];
@ -50,8 +51,7 @@
{
cairo_font_face_destroy(_fontFace);
}
FcPatternDestroy(_pattern);
FcPatternDestroy(_pattern);
RELEASE(_familyName);
[super dealloc];
@ -96,23 +96,24 @@
{
if (!_fontFace)
{
FcResult result;
FcPattern *resolved;
FcResult result;
FcPattern *resolved;
FcConfigSubstitute (NULL, _pattern, FcMatchPattern);
FcDefaultSubstitute(_pattern);
resolved = FcFontMatch(NULL, _pattern, &result);
FcDefaultSubstitute(_pattern);
resolved = FcFontMatch(NULL, _pattern, &result);
_fontFace = cairo_ft_font_face_create_for_pattern(resolved);
FcPatternDestroy(resolved);
FcPatternDestroy(resolved);
if ((!_fontFace) || (cairo_font_face_status(_fontFace) != CAIRO_STATUS_SUCCESS))
{
NSLog(@"Creating a font face failed %@", _familyName);
cairo_font_face_destroy(_fontFace);
_fontFace = NULL;
return NULL;
}
if ((!_fontFace)
|| (cairo_font_face_status(_fontFace) != CAIRO_STATUS_SUCCESS))
{
NSLog(@"Creating a font face failed %@", _familyName);
cairo_font_face_destroy(_fontFace);
_fontFace = NULL;
return NULL;
}
}
return _fontFace;

View file

@ -20,7 +20,8 @@
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111 USA.
*/
#include <Foundation/NSObject.h>
@ -49,7 +50,7 @@ NSMutableDictionary * __allFonts;
{
CairoFaceInfo *face;
face =[__allFonts objectForKey: name];
face = [__allFonts objectForKey: name];
if (!face)
{
NSLog (@"Font not found %@", name);
@ -65,9 +66,10 @@ static NSArray *faFromFc(FcPattern *pat)
char *family;
NSMutableString *name, *style;
if (FcPatternGetInteger(pat, FC_WEIGHT, 0, &weight) != FcResultMatch ||
FcPatternGetInteger(pat, FC_SLANT, 0, &slant) != FcResultMatch ||
FcPatternGetString(pat, FC_FAMILY, 0, (FcChar8 **)&family) != FcResultMatch)
if (FcPatternGetInteger(pat, FC_WEIGHT, 0, &weight) != FcResultMatch
|| FcPatternGetInteger(pat, FC_SLANT, 0, &slant) != FcResultMatch
|| FcPatternGetString(pat, FC_FAMILY, 0, (FcChar8 **)&family)
!= FcResultMatch)
return nil;
if (FcPatternGetInteger(pat, FC_SPACING, 0, &spacing) == FcResultMatch)
@ -80,43 +82,43 @@ static NSArray *faFromFc(FcPattern *pat)
switch (weight)
{
case FC_WEIGHT_LIGHT:
[style appendString: @"Light"];
nsweight = 3;
break;
case FC_WEIGHT_MEDIUM:
nsweight = 6;
break;
case FC_WEIGHT_DEMIBOLD:
[style appendString: @"Demibold"];
nsweight = 7;
break;
case FC_WEIGHT_BOLD:
[style appendString: @"Bold"];
nsweight = 9;
nstraits |= NSBoldFontMask;
break;
case FC_WEIGHT_BLACK:
[style appendString: @"Black"];
nsweight = 12;
nstraits |= NSBoldFontMask;
break;
default:
nsweight = 6;
case FC_WEIGHT_LIGHT:
[style appendString: @"Light"];
nsweight = 3;
break;
case FC_WEIGHT_MEDIUM:
nsweight = 6;
break;
case FC_WEIGHT_DEMIBOLD:
[style appendString: @"Demibold"];
nsweight = 7;
break;
case FC_WEIGHT_BOLD:
[style appendString: @"Bold"];
nsweight = 9;
nstraits |= NSBoldFontMask;
break;
case FC_WEIGHT_BLACK:
[style appendString: @"Black"];
nsweight = 12;
nstraits |= NSBoldFontMask;
break;
default:
nsweight = 6;
}
switch (slant)
{
case FC_SLANT_ROMAN:
break;
case FC_SLANT_ITALIC:
[style appendString: @"Italic"];
nstraits |= NSItalicFontMask;
break;
case FC_SLANT_OBLIQUE:
[style appendString: @"Oblique"];
nstraits |= NSItalicFontMask;
break;
case FC_SLANT_ROMAN:
break;
case FC_SLANT_ITALIC:
[style appendString: @"Italic"];
nstraits |= NSItalicFontMask;
break;
case FC_SLANT_OBLIQUE:
[style appendString: @"Oblique"];
nstraits |= NSItalicFontMask;
break;
}
if ([style length] > 0)
@ -139,9 +141,9 @@ static NSArray *faFromFc(FcPattern *pat)
- (void) enumerateFontsAndFamilies
{
int i;
NSMutableDictionary *fcxft_allFontFamilies = [[NSMutableDictionary alloc] init];
NSMutableDictionary *fcxft_allFonts = [[NSMutableDictionary alloc] init];
NSMutableArray *fcxft_allFontNames = [[NSMutableArray alloc] init];
NSMutableDictionary *fcxft_allFontFamilies = [NSMutableDictionary new];
NSMutableDictionary *fcxft_allFonts = [NSMutableDictionary new];
NSMutableArray *fcxft_allFontNames = [NSMutableArray new];
FcPattern *pat = FcPatternCreate();
FcObjectSet *os = FcObjectSetBuild(FC_FAMILY, FC_SLANT, FC_WEIGHT, NULL);
@ -150,11 +152,12 @@ static NSArray *faFromFc(FcPattern *pat)
FcPatternDestroy(pat);
FcObjectSetDestroy(os);
for (i=0; i < fs->nfont; i++)
for (i = 0; i < fs->nfont; i++)
{
char *family;
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, (FcChar8 **)&family) == FcResultMatch)
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, (FcChar8 **)&family)
== FcResultMatch)
{
NSArray *fontArray;
@ -166,20 +169,22 @@ static NSArray *faFromFc(FcPattern *pat)
NSString *name = [fontArray objectAtIndex: 0];
familyString = [NSString stringWithUTF8String: family];
if (!(familyArray = [fcxft_allFontFamilies objectForKey: familyString]))
familyArray = [fcxft_allFontFamilies objectForKey: familyString];
if (familyArray == nil)
{
NSDebugLog(@"Found font family %@", familyString);
NSDebugLog(@"Found font family %@", familyString);
familyArray = [[NSMutableArray alloc] init];
[fcxft_allFontFamilies setObject: familyArray forKey: familyString];
[fcxft_allFontFamilies setObject: familyArray
forKey: familyString];
RELEASE(familyArray);
}
NSDebugLog(@"fc enumerator: adding font: %@", name);
[familyArray addObject: fontArray];
[fcxft_allFontNames addObject: name];
aFont = [[CairoFaceInfo alloc] initWithfamilyName: familyString
weight: [[fontArray objectAtIndex: 2] intValue]
traits: [[fontArray objectAtIndex: 3] unsignedIntValue]
pattern: fs->fonts[i]];
weight: [[fontArray objectAtIndex: 2] intValue]
traits: [[fontArray objectAtIndex: 3] unsignedIntValue]
pattern: fs->fonts[i]];
[fcxft_allFonts setObject: aFont forKey: name];
RELEASE(aFont);
}
@ -192,7 +197,7 @@ static NSArray *faFromFc(FcPattern *pat)
__allFonts = fcxft_allFonts;
}
-(NSString *) defaultSystemFontName
- (NSString *) defaultSystemFontName
{
if ([allFontNames containsObject: @"Bitstream Vera Sans"])
return @"Bitstream Vera Sans";
@ -201,7 +206,7 @@ static NSArray *faFromFc(FcPattern *pat)
return @"Helvetica";
}
-(NSString *) defaultBoldSystemFontName
- (NSString *) defaultBoldSystemFontName
{
if ([allFontNames containsObject: @"Bitstream Vera Sans-Bold"])
return @"Bitstream Vera Sans-Bold";
@ -210,7 +215,7 @@ static NSArray *faFromFc(FcPattern *pat)
return @"Helvetica-Bold";
}
-(NSString *) defaultFixedPitchFontName
- (NSString *) defaultFixedPitchFontName
{
if ([allFontNames containsObject: @"Bitstream Vera Sans Mono"])
return @"Bitstream Vera Sans Mono";

View file

@ -17,7 +17,8 @@
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111 USA.
*/
#include "GNUstepBase/Unicode.h"
@ -233,7 +234,7 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
return 0.0;
}
-(NSGlyph) glyphWithName: (NSString *) glyphName
- (NSGlyph) glyphWithName: (NSString *) glyphName
{
/* subclass should override */
/* terrible! FIXME */