Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Headers/opal/OpalSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

- (CGContextRef) backingCGContext;
- (CGContextRef) x11CGContext;
- (void) ensureX11Context;
- (void) handleExposeRect: (NSRect)rect;
- (BOOL) isDrawingToScreen;
@end
21 changes: 6 additions & 15 deletions Source/opal/OpalContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ @implementation OpalContext

+ (void) initializeBackend
{
NSLog(@"OpalContext: initializeBackend called");
[NSGraphicsContext setDefaultContextClass: self];

[GSFontEnumerator setDefaultClass: [OpalFontEnumerator class]];
Expand All @@ -63,16 +64,8 @@ - (BOOL) supportsDrawGState

- (BOOL) isDrawingToScreen
{
#warning isDrawingToScreen returning NO to fix DPSimage
return NO;

// NOTE: This was returning NO because it was not looking at the
// return value of GSCurrentSurface. Now it returns YES, which
// seems to have broken image drawing (yellow rectangles are drawn instead)
OpalSurface *surface;

[OGSTATE GSCurrentSurface: &surface : NULL : NULL];

return [surface isDrawingToScreen];
}

Expand Down Expand Up @@ -150,17 +143,15 @@ - (BOOL) isCompatibleBitmap: (NSBitmapImageRep*)bitmap
return NO;
}

// FIXME: Allow more image types as soon as the Opal backend handles them correctly
colorSpaceName = [bitmap colorSpaceName];
if (![colorSpaceName isEqualToString: NSDeviceRGBColorSpace] &&
![colorSpaceName isEqualToString: NSCalibratedRGBColorSpace])
{
return NO;
}
else
if ([colorSpaceName isEqualToString: NSDeviceRGBColorSpace] ||
[colorSpaceName isEqualToString: NSCalibratedRGBColorSpace] ||
[colorSpaceName isEqualToString: NSDeviceWhiteColorSpace] ||
[colorSpaceName isEqualToString: NSCalibratedWhiteColorSpace])
{
return YES;
}
return NO;
}

- (void) GSCurrentDevice: (void **)device : (int *)x : (int *)y
Expand Down
88 changes: 58 additions & 30 deletions Source/opal/OpalFontInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,40 @@ - (BOOL) setupAttributes
return NO;
}

// We must not leave the hinting settings as their defaults,
// because if we did, that would mean using the surface defaults
// which might or might not use hinting (xlib does by default.)
//
// Since we make measurements outside of the context of a surface
// (-advancementForGlyph:), we need to ensure that the same
// hinting settings are used there as when we draw. For now,
// just force hinting to be off.
cairo_font_options_set_hint_metrics(options, CAIRO_HINT_METRICS_ON);
cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE);
{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
cairo_hint_metrics_t metrics = CAIRO_HINT_METRICS_ON;
cairo_hint_style_t style = CAIRO_HINT_STYLE_NONE;
int hinting = [ud integerForKey: @"GSFontHinting"];
cairo_antialias_t antialias = CAIRO_ANTIALIAS_DEFAULT;
if (hinting == 0)
{
float scaleFactor = [ud floatForKey: @"GSScaleFactor"];
if (scaleFactor != 0.0 && scaleFactor != 1.0)
hinting = 33;
else
hinting = 17;
}
switch (hinting >> 4)
{
case 0: metrics = CAIRO_HINT_METRICS_DEFAULT; break;
case 1: metrics = CAIRO_HINT_METRICS_ON; break;
case 2: metrics = CAIRO_HINT_METRICS_OFF; break;
}
switch (hinting & 0x0f)
{
case 0: style = CAIRO_HINT_STYLE_DEFAULT; break;
case 1: style = CAIRO_HINT_STYLE_NONE; break;
case 2: style = CAIRO_HINT_STYLE_SLIGHT; break;
case 3: style = CAIRO_HINT_STYLE_MEDIUM; break;
case 4: style = CAIRO_HINT_STYLE_FULL; break;
}
cairo_font_options_set_hint_metrics(options, metrics);
cairo_font_options_set_hint_style(options, style);
if ([ud objectForKey: @"back_art_subpixel_text"])
antialias = CAIRO_ANTIALIAS_SUBPIXEL;
cairo_font_options_set_antialias(options, antialias);
}

_scaled = cairo_scaled_font_create(face, &font_matrix, &ctm, options);
cairo_font_options_destroy(options);
Expand Down Expand Up @@ -302,35 +326,39 @@ - (NSGlyph) glyphWithName: (NSString *) glyphName

- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
{
#if 0
cairo_text_extents_t ctext;

if (_cairo_extents_for_NSGlyph(_scaled, glyph, &ctext))
// Use glyph advance as approximation for bounding rect
CGGlyph cgGlyph = (CGGlyph)glyph;
int advance = 0;
if (_faceInfo && [_faceInfo fontFace])
{
return NSMakeRect(ctext.x_bearing, ctext.y_bearing,
ctext.width, ctext.height);
CGFontGetGlyphAdvances([_faceInfo fontFace], &cgGlyph, 1, &advance);
int unitsPerEm = CGFontGetUnitsPerEm([_faceInfo fontFace]);
if (unitsPerEm > 0)
{
CGFloat scale = matrix[0] / (CGFloat)unitsPerEm;
CGFloat w = advance * scale;
return NSMakeRect(0, descender, w, ascender - descender);
}
}
#endif
return NSMakeRect(0,0,10,10);
return NSMakeRect(0, descender, matrix[0] * 0.6, ascender - descender);
}

- (CGFloat) widthOfString: (NSString *)string
{
#if 0
cairo_text_extents_t ctext;
if (!string || [string length] == 0)
return 0.0;

if (!string)
// Sum glyph advances for the string
CGFloat totalWidth = 0;
NSUInteger len = [string length];
for (NSUInteger i = 0; i < len; i++)
{
return 0.0;
unichar ch = [string characterAtIndex: i];
NSGlyph g = [self glyphForCharacter: ch];
NSSize adv = [self advancementForGlyph: g];
totalWidth += adv.width;
}

cairo_scaled_font_text_extents(_scaled, [string UTF8String], &ctext);
if (cairo_scaled_font_status(_scaled) == CAIRO_STATUS_SUCCESS)
{
return ctext.width;
}
#endif
return 100.0;
return totalWidth;
}

- (void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
Expand Down
Loading
Loading