opal: Various fonts related hacks, as well as further attempts to figure out what's going wrong with painting.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@36910 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Ivan Vučica 2013-07-21 11:58:05 +00:00
parent fbe9ad1032
commit a64b9f9058
5 changed files with 159 additions and 31 deletions

View file

@ -1,3 +1,19 @@
2013-07-21 Ivan Vucica <ivan@vucica.net>
* Source/opal/OpalFontInfo.m:
* Source/opal/OpalFontEnumerator.m:
Some hacks to figure out how NSMenuItem's width is determined,
and how the supported glyphs are determined.
* Source/opal/OpalGState.m:
Various method implementations and fixes.
* Source/opal/OpalSurface.m:
Enabled doublebuffered code path, now that Opal's endianess
problem is fixed. Creation of CGContext factored out of
initializer into a method that can be called whenever needed
to recreate the context.
2013-07-15 Ivan Vucica <ivan@vucica.net>
* Source/opal/OpalFontEnumerator.m:

View file

@ -68,14 +68,15 @@
return self;
}
- (int) weight { return _weight; }
- (int) weight { NSLog(@"OpalFontEnumerator: Weight %d", _weight); return _weight; }
- (void) setWeight: (int)weight { _weight = weight; }
- (unsigned int) traits { return _traits; }
- (void) setTraits: (unsigned int)traits { _traits = traits; }
- (NSString *)familyName { return _familyName; }
- (void) setFamilyName: (NSString *)name { [_familyName release]; _familyName = [name retain]; }
- (NSCharacterSet *) characterSet { return nil; }
- (NSCharacterSet *) characterSet { NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return [NSCharacterSet alphanumericCharacterSet]; }
@end
@ -84,11 +85,15 @@
+ (OpalFaceInfo *) fontWithName: (NSString *) name
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSLog(@"Font with name %@", name);
return [[[OpalFaceInfo alloc] initWithFamilyName:name weight:1 traits:0] autorelease];
}
- (void) enumerateFontsAndFamilies
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
allFontNames = [[NSArray arrayWithObjects: @"FreeSans",
@"FreeSans-Bold", @"FreeMono", nil] retain];
allFontFamilies = [[NSDictionary dictionaryWithObjectsAndKeys:
@ -100,15 +105,23 @@
- (NSString *) defaultSystemFontName
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return @"FreeSans";
}
- (NSString *) defaultBoldSystemFontName
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return @"FreeSans-Bold";
}
- (NSString *) defaultFixedPitchFontName
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return @"FreeMono";
}
- (NSArray *) matchingFontDescriptorsFor: (NSDictionary *)attributes
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return [NSArray arrayWithObject:[NSFontDescriptor fontDescriptorWithName:@"FreeSans" size: 10]];
}
@end

View file

@ -33,15 +33,44 @@
matrix: (const CGFloat *)fmatrix
screenFont: (BOOL)p_screenFont
{
NSLog(@"OpalFontInfo: FONT INFO FOR %@", name);
return [super init];
}
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
{
NSLog(@"OpalFontInfo: BOUNDING RECT FOR GLYPTH %c", glyph);
return NSMakeRect(0, 0, 10, 10);
}
- (CGFloat) widthOfString: (NSString *)string
{
NSLog(@"WIDTH OF %@", string);
NSLog(@"OpalFontInfo: WIDTH OF %@", string);
return [string length] * 10;
}
- (NSSize) advancementForGlyph: (NSGlyph)glyph
{
NSLog(@"OpalFontInfo: ADVANCEMENT FOR %d", glyph);
return NSMakeSize(100,100);
}
- (NSGlyph) glyphWithName: (NSString *) glyphName
{
NSLog(@"OpalFontInfo: GLYPH WITH NAME %s", glyphName);
// FIXME: incorrect
NSGlyph g = [glyphName cString][0];
return g;
}
- (NSGlyph) glyphForCharacter: (unichar)c
{
// FIXME: default in 'gui' uses -glyphIsEncoded: or otherwise
// returns null glyph. the default should be sufficient, and is
// sufficient for cairo backend.
return c;
}
- (void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
count: (int)length
toBezierPath: (NSBezierPath *)path
{
[path lineToPoint: NSMakePoint(length*10, 10)];
}
@end

View file

@ -71,8 +71,13 @@
: (NSString *)colorSpaceName
: (const unsigned char *const[5])data
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGContextSaveGState(CGCTX);
CGContextSetRGBFillColor(CGCTX, 1, 0, 0, 1);
CGContextConcatCTM(CGCTX, *(CGAffineTransform*)matrix);
CGContextFillRect(CGCTX, CGRectMake(0, 0, pixelsWide, pixelsHigh));
CGContextRestoreGState(CGCTX);
}
- (void) compositeGState: (OpalGState *)source
@ -82,15 +87,34 @@
fraction: (CGFloat)delta
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
#if 1
CGContextSaveGState(CGCTX);
CGContextSetRGBFillColor(CGCTX, 1, 1, 0, 1);
CGContextFillRect(CGCTX, CGRectMake(destPoint.x, destPoint.y, srcRect.size.width, srcRect.size.height));
CGContextRestoreGState(CGCTX);
#else
CGRect srcCGRect = CGRectMake(srcRect.origin.x, srcRect.origin.y,
srcRect.size.width, srcRect.size.height);
// FIXME: this presumes that the backing cgContext of 'source' is
// an OpalSurface with a backing CGBitmapContext
CGImageRef backingImage = CGBitmapContextCreateImage([source cgContext]);
CGContextMoveToPoint(CGCTX, destPoint.x, destPoint.y);
// TODO: this ignores op
// TODO: this ignores delta
CGContextDrawImage(CGCTX, srcCGRect, backingImage);
CGImageRelease(backingImage);
#endif
}
- (void) compositerect: (NSRect)aRect
op: (NSCompositingOperation)op
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSLog(@"%p (%@): %s - %@", self, [self class], __PRETTY_FUNCTION__, NSStringFromRect(aRect));
CGContextSaveGState(CGCTX);
CGContextFillRect(CGCTX, CGRectMake(aRect.origin.x, aRect.origin.y,
[self DPSinitmatrix];
CGContextFillRect(CGCTX, CGRectMake(aRect.origin.x, [_opalSurface device]->buffer_height - aRect.origin.y,
aRect.size.width, aRect.size.height));
CGContextRestoreGState(CGCTX);
}
@ -134,21 +158,23 @@
/**
Makes the specified surface active in the current graphics state,
ready for use in methods such as -DPSinitgraphics. Also, sets the
device offset to specified coordinates.
ready for use. Also, sets the device offset to specified coordinates.
**/
- (void) GSSetSurface: (OpalSurface *)opalSurface
: (int)x
: (int)y
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
// FIXME: improper setter
[_opalSurface release];
_opalSurface = [opalSurface retain];
// TODO: apply offset using [self setOffset:]
if(_opalSurface != opalSurface)
{
id old = _opalSurface;
_opalSurface = [opalSurface retain];
[old release];
}
[self setOffset: NSMakePoint(x, y)];
[self DPSinitgraphics];
}
- (id) GSCurrentSurface: (OpalSurface **)surface
: (int *)x
@ -169,7 +195,7 @@
[super DPSinitgraphics];
[_opalSurface dummyDraw];
[_opalSurface createCGContexts];
}
@ -197,20 +223,21 @@ static CGFloat theAlpha = 1.; // TODO: removeme
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
const CGFloat alpha = 1; // TODO: is this correct?
if(!CGCTX)
return;
CGContextSetRGBFillColor(CGCTX, r, g, b, alpha);
}
- (void) DPSrectfill: (CGFloat)x : (CGFloat)y : (CGFloat)w : (CGFloat)h
{
NSLog(@"%p (%@): %s - rect %g %g %g %g", self, [self class], __PRETTY_FUNCTION__, x, y, w, h);
if (theAlpha == 0)
return;
CGContextFillRect(CGCTX, CGRectMake(x, y, w, h));
}
- (void) DPSrectclip: (CGFloat)x : (CGFloat)y : (CGFloat)w : (CGFloat)h
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSLog(@"%p (%@): %s - %g %g %g %g", self, [self class], __PRETTY_FUNCTION__, x, y, w, h);
[self DPSinitclip];
CGContextClipToRect(CGCTX, CGRectMake(x, y, w, h));
}
- (void) DPSsetgray: (CGFloat)gray
@ -232,44 +259,79 @@ static CGFloat theAlpha = 1.; // TODO: removeme
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
OPContextSetIdentityCTM(CGCTX);
#if 0
// Flipping the coordinate system is NOT required
CGContextTranslateCTM(CGCTX, 0, [_opalSurface device]->buffer_height);
CGContextScaleCTM(CGCTX, 1, -1);
#endif
[super DPSinitmatrix];
}
- (void)DPSconcat: (const CGFloat *)m
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSLog(@"%p (%@): %s - %g %g %g %g %g %g", self, [self class], __PRETTY_FUNCTION__, m[0], m[1], m[2], m[3], m[4], m[5]);
CGContextConcatCTM(CGCTX, CGAffineTransformMake(
m[0], m[1], m[2],
m[3], m[4], m[5]));
[super DPSconcat:m];
}
- (void)DPSscale: (CGFloat)x
: (CGFloat)y
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSLog(@"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
CGContextScaleCTM(CGCTX, x, y);
}
- (void)DPStranslate: (CGFloat)x
: (CGFloat)y
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSLog(@"%p (%@): %s - x %g y %g", self, [self class], __PRETTY_FUNCTION__, x, y);
CGContextTranslateCTM(CGCTX, x, y);
[super DPStranslate:x:y];
}
- (void) DPSmoveto: (CGFloat) x
: (CGFloat) y
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSLog(@"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
CGContextMoveToPoint(CGCTX, x, y);
}
- (void) DPSlineto: (CGFloat) x
: (CGFloat) y
{
NSLog(@"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
NSLog(@"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
CGContextAddLineToPoint(CGCTX, x, y);
}
- (void) setOffset: (NSPoint)theOffset
{
NSLog(@"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, theOffset.x, theOffset.y);
#if 1
if (CGCTX != nil)
{
#if 1
OPContextSetCairoDeviceOffset(CGCTX, -theOffset.x,
theOffset.y - [_opalSurface device]->buffer_height);
#else
OPContextSetCairoDeviceOffset(CGCTX, theOffset.x,
theOffset.y);
#endif
}
#else
// This is a BAD hack using transform matrix.
// It'll break horribly when Opal state is saved and restored.
static NSPoint OFFSET = { 0, 0 };
//CGContextTranslateCTM(CGCTX, -(-OFFSET.x),
// -(OFFSET.y - [_opalSurface device]->buffer_height));
CGContextTranslateCTM(CGCTX, -theOffset.x,
theOffset.y - [_opalSurface device]->buffer_height);
OFFSET = theOffset;
#endif
[super setOffset: theOffset];
}
/*
- (void) setColor: (device_color_t *)color state: (color_state_t)cState
{

View file

@ -104,8 +104,19 @@ static CGContextRef createCGBitmapContext (int pixelsWide,
// a window device.
_gsWindowDevice = (gswindow_device_t *) device;
[self createCGContexts];
return self;
}
- (void) createCGContexts
{
// FIXME: this method and class presumes we are being passed
// a window device.
Display * display = _gsWindowDevice->display;
Window window = _gsWindowDevice->ident;
_x11CGContext = OPX11ContextCreate(display, window);
if (_gsWindowDevice->type == NSBackingStoreNonretained)
@ -123,16 +134,13 @@ static CGContextRef createCGBitmapContext (int pixelsWide,
_gsWindowDevice->gdriverProtocol |= GDriverHandlesExpose | GDriverHandlesBacking;
_gsWindowDevice->gdriver = self;
#if 0
// Disabled because when the content is blitted onto the screen,
// we get just yellow blots instead of actual content.
_backingCGContext = createCGBitmapContext(
_gsWindowDevice->buffer_width,
_gsWindowDevice->buffer_height);
#endif
}
return self;
}
- (gswindow_device_t *) device
@ -162,8 +170,8 @@ static CGContextRef createCGBitmapContext (int pixelsWide,
CGImageDestinationRef outfile = CGImageDestinationCreateWithURL(fileUrl, @"public.jpeg"/*kUTTypeJPEG*/, 1, NULL);
CGImageDestinationAddImage(outfile, backingImage, NULL);
CGImageDestinationFinalize(outfile);
CFRelease(fileUrl);
CFRelease(outfile);
//CFRelease(fileUrl);
//CFRelease(outfile);
CGImageRelease(backingImage);