From 0b2c1942c182f2685d872ab1596cd144667f7eb8 Mon Sep 17 00:00:00 2001 From: Adam Fedor Date: Wed, 8 May 2002 03:28:09 +0000 Subject: [PATCH] Flip font on set if needed git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@13605 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/NSFont.m | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4e6620b26..e6197fca0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2002-05-07 Adam Fedor + + * Source/NSFont.m (-initWithName:matrix:): If matrix + is ident, set matrixExplicitlySet to NO + (-set): If the focus view is flipped and matrix not set, set our + flipped font equivalent. + 2002-05-06 Adam Fedor * Source/NSGraphicsContext.m: More documentation. diff --git a/Source/NSFont.m b/Source/NSFont.m index 829e6fadc..964aff182 100644 --- a/Source/NSFont.m +++ b/Source/NSFont.m @@ -35,6 +35,7 @@ #include #include #include +#include /* We cache all the 4 default fonts after we first get them. But when a default font is changed, the variable is set to YES @@ -374,6 +375,13 @@ setNSFont(NSString* key, NSFont* font) return 12.0; } +/** Creates a new font with name aFontName and matrix fontMatrix. The + fontMatrix is a standard size element matrix as used in PostScript + to describe the scaling of the font, typically it just includes + the font size as [fontSize 0 0 fontSize 0 0]. You can use the constant + NSFontIdentityMatrix in place of [1 0 0 1 0 0]. If NSFontIdentityMatrix, + then the font will automatically flip itself when set in a + flipped view */ + (NSFont*) fontWithName: (NSString*)aFontName matrix: (const float*)fontMatrix { @@ -381,6 +389,9 @@ setNSFont(NSString* key, NSFont* font) matrix: fontMatrix]); } +/** Creates a new font with name aFontName and size fontSize. Fonts created + using this method will automatically flip themselves when set in a flipped + view */ + (NSFont*) fontWithName: (NSString*)aFontName size: (float)fontSize { @@ -411,6 +422,12 @@ setNSFont(NSString* key, NSFont* font) // // Instance methods // +/** Initializes a newly created font class from the name and + information given in the fontMatrix. The fontMatrix is a standard + size element matrix as used in PostScript to describe the scaling + of the font, typically it just includes the font size as + [fontSize 0 0 fontSize 0 0]. +*/ - (id) initWithName: (NSString*)name matrix: (const float*)fontMatrix { NSFont *font; @@ -435,6 +452,10 @@ setNSFont(NSString* key, NSFont* font) fontName = [name copy]; memcpy(matrix, fontMatrix, sizeof(matrix)); + if (fontMatrix == NSFontIdentityMatrix) + matrixExplicitlySet = NO; + else + matrixExplicitlySet = YES; fontInfo = RETAIN([GSFontInfo fontInfoForFontName: fontName matrix: fontMatrix]); return self; @@ -498,14 +519,30 @@ setNSFont(NSString* key, NSFont* font) return new_font; } +- (NSFont *)_flippedViewFont +{ + float fontMatrix[6]; + memcpy(fontMatrix, matrix, sizeof(matrix)); + fontMatrix[3] *= -1; + return [NSFont fontWithName: fontName matrix: fontMatrix]; +} + // // Setting the Font // +/** Sets the receiver as the font used for text drawing operations. If the + current view is a flipped view, the reciever automatically flips itself + to display correctly in the flipped view, as long as the font was created + without explicitly setting the font matrix */ - (void) set { NSGraphicsContext *ctxt = GSCurrentContext(); - [ctxt GSSetFont: self]; + if (matrixExplicitlySet == NO && [[NSView focusView] isFlipped]) + [ctxt GSSetFont: [self _flippedViewFont]]; + else + [ctxt GSSetFont: self]; + [ctxt useFont: fontName]; }