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
This commit is contained in:
Adam Fedor 2002-05-08 03:28:09 +00:00
parent c629ab8ec2
commit 0b2c1942c1
2 changed files with 45 additions and 1 deletions

View file

@ -1,3 +1,10 @@
2002-05-07 Adam Fedor <fedor@gnu.org>
* 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 <fedor@gnu.org> 2002-05-06 Adam Fedor <fedor@gnu.org>
* Source/NSGraphicsContext.m: More documentation. * Source/NSGraphicsContext.m: More documentation.

View file

@ -35,6 +35,7 @@
#include <AppKit/NSFont.h> #include <AppKit/NSFont.h>
#include <AppKit/NSFontManager.h> #include <AppKit/NSFontManager.h>
#include <AppKit/GSFontInfo.h> #include <AppKit/GSFontInfo.h>
#include <AppKit/NSView.h>
/* We cache all the 4 default fonts after we first get them. /* 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 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; 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 + (NSFont*) fontWithName: (NSString*)aFontName
matrix: (const float*)fontMatrix matrix: (const float*)fontMatrix
{ {
@ -381,6 +389,9 @@ setNSFont(NSString* key, NSFont* font)
matrix: fontMatrix]); 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 + (NSFont*) fontWithName: (NSString*)aFontName
size: (float)fontSize size: (float)fontSize
{ {
@ -411,6 +422,12 @@ setNSFont(NSString* key, NSFont* font)
// //
// Instance methods // Instance methods
// //
/** <init /> 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 - (id) initWithName: (NSString*)name matrix: (const float*)fontMatrix
{ {
NSFont *font; NSFont *font;
@ -435,6 +452,10 @@ setNSFont(NSString* key, NSFont* font)
fontName = [name copy]; fontName = [name copy];
memcpy(matrix, fontMatrix, sizeof(matrix)); memcpy(matrix, fontMatrix, sizeof(matrix));
if (fontMatrix == NSFontIdentityMatrix)
matrixExplicitlySet = NO;
else
matrixExplicitlySet = YES;
fontInfo = RETAIN([GSFontInfo fontInfoForFontName: fontName fontInfo = RETAIN([GSFontInfo fontInfoForFontName: fontName
matrix: fontMatrix]); matrix: fontMatrix]);
return self; return self;
@ -498,14 +519,30 @@ setNSFont(NSString* key, NSFont* font)
return new_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 // 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 - (void) set
{ {
NSGraphicsContext *ctxt = GSCurrentContext(); NSGraphicsContext *ctxt = GSCurrentContext();
[ctxt GSSetFont: self]; if (matrixExplicitlySet == NO && [[NSView focusView] isFlipped])
[ctxt GSSetFont: [self _flippedViewFont]];
else
[ctxt GSSetFont: self];
[ctxt useFont: fontName]; [ctxt useFont: fontName];
} }