mirror of
https://github.com/gnustep/libs-back.git
synced 2025-04-22 15:31:14 +00:00
* Source/opal/OpalFontInfo.m: Move font space to user space conversion
to a separate method. Implement -glyphIsEncoded:, -advancementForGlyph:, -glyphForCharacter:, -glyphWithName:. For -boundingRectForGlyph:, and -widthOfString:, return fake, fixed values. * Source/opal/OpalContext.m: Fix -isDrawingToScreen implementation; it now returns YES. This has the unfortunate side effect of breaking image drawing... but, on the positive side, causes NSLayoutManager to make calls to GSShowGlyphsWithAdvances in batches of up to 16 glyphs, instead of one at a time...! * Source/opal/OpalGState.m: Implement -GSSetFont:, and make -GSShowGlyphsWithAdvances: call CGContextShowGlyphsWithAdvances Overall state is glyphs are drawn.. they appear upside down, and the glyph runs only seem to draw at (0, 0). git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@37087 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0027a8bd8b
commit
7b4690c515
4 changed files with 106 additions and 28 deletions
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
|||
2013-09-17 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Source/opal/OpalFontInfo.m: Move font space to user space conversion
|
||||
to a separate method. Implement -glyphIsEncoded:, -advancementForGlyph:,
|
||||
-glyphForCharacter:, -glyphWithName:.
|
||||
|
||||
For -boundingRectForGlyph:, and -widthOfString:, return fake, fixed
|
||||
values.
|
||||
* Source/opal/OpalContext.m: Fix -isDrawingToScreen implementation;
|
||||
it now returns YES. This has the unfortunate side effect of breaking
|
||||
image drawing... but, on the positive side, causes NSLayoutManager
|
||||
to make calls to GSShowGlyphsWithAdvances in batches of up to
|
||||
16 glyphs, instead of one at a time...!
|
||||
* Source/opal/OpalGState.m: Implement -GSSetFont:, and make
|
||||
-GSShowGlyphsWithAdvances: call CGContextShowGlyphsWithAdvances
|
||||
|
||||
Overall state is glyphs are drawn.. they appear upside down,
|
||||
and the glyph runs only seem to draw at (0, 0).
|
||||
|
||||
2013-09-17 Ivan Vucica <ivan@vucica.net>
|
||||
|
||||
* Source/opal/OpalFontInfo.m:
|
||||
|
|
|
@ -65,8 +65,11 @@
|
|||
|
||||
- (BOOL) isDrawingToScreen
|
||||
{
|
||||
OpalSurface *surface = nil;
|
||||
[OGSTATE GSCurrentSurface: &surface : NULL : NULL];
|
||||
// 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: NULL : NULL : NULL];
|
||||
|
||||
return [surface isDrawingToScreen];
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,16 @@
|
|||
|
||||
@implementation OpalFontInfo
|
||||
|
||||
- (CGFloat) _fontUnitToUserSpace: (CGFloat)fontDimension
|
||||
{
|
||||
CGFontRef face = [_faceInfo fontFace];
|
||||
CGFloat unitsPerEm = CGFontGetUnitsPerEm(face);
|
||||
|
||||
CGFloat pointSize = matrix[0]; // from GSFontInfo
|
||||
|
||||
return (fontDimension / unitsPerEm) * pointSize;
|
||||
}
|
||||
|
||||
- (BOOL) setupAttributes
|
||||
{
|
||||
/*
|
||||
|
@ -50,8 +60,6 @@
|
|||
CGFontRef face;
|
||||
CGSize maximumAdvancementCG;
|
||||
CGRect fontBBoxCG;
|
||||
CGFloat unitsPerEm;
|
||||
CGFloat pointSize;
|
||||
|
||||
if (![super setupAttributes])
|
||||
{
|
||||
|
@ -72,17 +80,23 @@
|
|||
return NO;
|
||||
}
|
||||
|
||||
ascender = CGFontGetAscent(face);
|
||||
descender = CGFontGetDescent(face);
|
||||
xHeight = CGFontGetXHeight(face);
|
||||
ascender = [self _fontUnitToUserSpace: CGFontGetAscent(face)];
|
||||
descender = [self _fontUnitToUserSpace: CGFontGetDescent(face)];
|
||||
xHeight = [self _fontUnitToUserSpace: CGFontGetXHeight(face)];
|
||||
|
||||
CGFloat pointSize = matrix[0];
|
||||
|
||||
maximumAdvancementCG = OPFontGetMaximumAdvancement(face);
|
||||
maximumAdvancement = NSMakeSize(maximumAdvancementCG.width,
|
||||
maximumAdvancementCG.height);
|
||||
maximumAdvancement = NSMakeSize(maximumAdvancementCG.width * pointSize,
|
||||
maximumAdvancementCG.height * pointSize);
|
||||
|
||||
fontBBoxCG = CGFontGetFontBBox(face);
|
||||
fontBBox = NSMakeRect(fontBBoxCG.origin.x, fontBBoxCG.origin.y,
|
||||
fontBBoxCG.size.width, fontBBoxCG.size.height);
|
||||
fontBBox = NSMakeRect([self _fontUnitToUserSpace: fontBBoxCG.origin.x],
|
||||
[self _fontUnitToUserSpace: fontBBoxCG.origin.y],
|
||||
[self _fontUnitToUserSpace: fontBBoxCG.size.width],
|
||||
[self _fontUnitToUserSpace: fontBBoxCG.size.height]);
|
||||
|
||||
CGFloat leading = [self _fontUnitToUserSpace: CGFontGetLeading(face)];
|
||||
|
||||
if (xHeight == 0.0)
|
||||
xHeight = ascender * 0.6;
|
||||
|
@ -94,20 +108,7 @@
|
|||
// lineHeight = font_extents.height
|
||||
// alternatively: line spacing = (ascent + descent + "external leading")
|
||||
// (internal discussion between ivucica and ericwa, 2013-09-17)
|
||||
lineHeight = CGFontGetLeading(face) + CGFontGetAscent(face) - CGFontGetDescent(face);
|
||||
|
||||
pointSize = matrix[0]; // from GSFontInfo
|
||||
unitsPerEm = CGFontGetUnitsPerEm(face);
|
||||
#define ratio pointSize / unitsPerEm
|
||||
ascender *= ratio; // ascender = scaleEmToUnits(ascender) * pointSize;
|
||||
descender *= ratio;
|
||||
xHeight *= ratio;
|
||||
fontBBox.origin.x *= ratio;
|
||||
fontBBox.origin.y *= ratio;
|
||||
fontBBox.size.width *= ratio;
|
||||
fontBBox.size.height *= ratio;
|
||||
maximumAdvancement.width *= ratio;
|
||||
maximumAdvancement.height *= ratio;
|
||||
lineHeight = leading + ascender - descender;
|
||||
|
||||
#if 0
|
||||
// Get default font options
|
||||
|
@ -207,6 +208,12 @@
|
|||
|
||||
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
|
||||
{
|
||||
CGFontRef face = [_faceInfo fontFace];
|
||||
size_t numGlyphs = CGFontGetNumberOfGlyphs(face);
|
||||
|
||||
return glyph < numGlyphs;
|
||||
|
||||
#if 0
|
||||
/* FIXME: There is no proper way to determine with the toy font API,
|
||||
whether a glyph is supported or not. We will just ignore ligatures
|
||||
and report all other glyph as existing.
|
||||
|
@ -216,6 +223,7 @@
|
|||
return NO;
|
||||
else
|
||||
return YES;
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
static
|
||||
|
@ -244,8 +252,17 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
|||
return cairo_scaled_font_status(scaled_font) == CAIRO_STATUS_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
- (NSSize) advancementForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
CGFontRef face = [_faceInfo fontFace];
|
||||
int advance = 0;
|
||||
CGFontGetGlyphAdvances(face, &glyph, 1, &advance);
|
||||
|
||||
CGFloat advanceUserSpace = [self _fontUnitToUserSpace: advance];
|
||||
|
||||
return NSMakeSize(advanceUserSpace, 0);
|
||||
|
||||
#if 0
|
||||
cairo_text_extents_t ctext;
|
||||
|
||||
|
@ -277,6 +294,22 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
|||
return NSZeroSize;
|
||||
}
|
||||
|
||||
- (NSGlyph) glyphForCharacter: (unichar)theChar
|
||||
{
|
||||
CGFontRef face = [_faceInfo fontFace];
|
||||
CGGlyph result = CGFontGetGlyphWithGlyphName(face, [NSString stringWithCharacters: &theChar length: 1]);
|
||||
// NSLog(@"%s: Mapped '%x' to glyph # %d", __PRETTY_FUNCTION__, (int)theChar, (int)result);
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSGlyph) glyphWithName: (NSString *) glyphName
|
||||
{
|
||||
CGFontRef face = [_faceInfo fontFace];
|
||||
CGGlyph result = CGFontGetGlyphWithGlyphName(face, glyphName);
|
||||
// NSLog(@"%s: Mapped '%@' to glyph # %d", __PRETTY_FUNCTION__, glyphName, (int)result);
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
|
||||
{
|
||||
#if 0
|
||||
|
@ -288,7 +321,7 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
|||
ctext.width, ctext.height);
|
||||
}
|
||||
#endif
|
||||
return NSZeroRect;
|
||||
return NSMakeRect(0,0,10,10);
|
||||
}
|
||||
|
||||
- (CGFloat) widthOfString: (NSString *)string
|
||||
|
@ -307,7 +340,7 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
|||
return ctext.width;
|
||||
}
|
||||
#endif
|
||||
return 0.0;
|
||||
return 100.0;
|
||||
}
|
||||
|
||||
- (void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#import <AppKit/NSGraphics.h> // NS*ColorSpace
|
||||
#import "opal/OpalGState.h"
|
||||
#import "opal/OpalSurface.h"
|
||||
#import "opal/OpalFontInfo.h"
|
||||
#import "x11/XGServerWindow.h"
|
||||
|
||||
#define CGCTX [self cgContext]
|
||||
|
@ -531,14 +532,36 @@ static CGFloat theAlpha = 1.; // TODO: removeme
|
|||
CGContextRestoreGState(CGCTX);
|
||||
// free(s2);
|
||||
}
|
||||
- (void) GSSetFont: (GSFontInfo *)fontref
|
||||
{
|
||||
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||
[super GSSetFont: fontref];
|
||||
|
||||
CGFontRef opalFont = (CGFontRef)[((OpalFontInfo *)fontref)->_faceInfo fontFace];
|
||||
CGContextSetFont(CGCTX, opalFont);
|
||||
|
||||
CGContextSetFontSize(CGCTX, [fontref matrix][0]);
|
||||
}
|
||||
- (void) GSShowGlyphsWithAdvances: (const NSGlyph *)glyphs : (const NSSize *)advances : (size_t) length
|
||||
{
|
||||
size_t i;
|
||||
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||
CGContextSaveGState(CGCTX);
|
||||
CGContextSetRGBFillColor(CGCTX, 0, 1, 0, 1);
|
||||
CGContextFillRect(CGCTX, CGRectMake(0, 0, 12, length * 12));
|
||||
CGContextRestoreGState(CGCTX);
|
||||
|
||||
|
||||
// NSGlyph = unsigned int, CGGlyph = unsigned short
|
||||
|
||||
CGGlyph cgglyphs[length];
|
||||
for (i=0; i<length; i++)
|
||||
{
|
||||
cgglyphs[i] = glyphs[i];
|
||||
}
|
||||
|
||||
CGPoint pt = CGContextGetPathCurrentPoint(CGCTX);
|
||||
CGContextSetTextPosition(CGCTX, pt.x, pt.y);
|
||||
CGContextShowGlyphsWithAdvances(CGCTX, cgglyphs, (const CGSize *)advances, length);
|
||||
}
|
||||
#if 1
|
||||
- (void) DPSrlineto: (CGFloat) x
|
||||
|
|
Loading…
Reference in a new issue