Opal backend: Progress on implementing fonts based on Opal's Core Graphics and fontconfig/ classes in gnustep-back.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@37082 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
ivucica 2013-09-16 22:46:45 +00:00
parent 5dd127aec9
commit 5b21bf465d
13 changed files with 697 additions and 144 deletions

View file

@ -1,3 +1,37 @@
2013-09-17 Ivan Vucica <ivan@vucica.net>
* configure:
* configure.ac:
Added fontconfig and freetype as dependencies for Opal. configure
script is not actually regenerated from configure.ac and contains
a simplified piece of code which just appends relevant options to
CPPFLAGS and LIBS.
* Source/opal/GNUmakefile:
Added fontconfig/ implementation files, like it was done in cairo
backend.
* Headers/opal/OpalFaceInfo.h:
* Source/opal/OpalFaceInfo.m:
Now copied from CairoFaceInfo and modified to use Core Graphics.
* Headers/opal/OpalFontInfo.h:
* Source/opal/OpalFontInfo.m:
Now copied from CairoFontInfo. Starting modifying to use the Core
Graphics. Currently font metrics are not correctly scaled.
* Source/opal/OpalFontEnumerator.m:
* Headers/opal/OpalFontEnumerator.h:
Now copied from CairoFaceInfo. Modified to use the classes in the
Opal backend.
* Source/opal/OpalGState.m:
Added DPSrlineto:: and DPSrmoveto::.
* Source/fontconfig/FCFontInfo.m:
* Headers/fontconfig/FCFontInfo.h:
Removed a cairo-backend-specific method.
2013-09-10 Ivan Vucica <ivan@vucica.net>
* Source/fontconfig/FCFontInfo.m:

View file

@ -30,7 +30,6 @@
#include <GNUstepGUI/GSFontInfo.h>
#include "fontconfig/FCFaceInfo.h"
#include <cairo.h>
@interface FCFontInfo : GSFontInfo
{

View file

@ -0,0 +1,42 @@
/*
OpalFaceInfo.h
Copyright (C) 2013 Free Software Foundation, Inc.
Author: Ivan Vucica <ivan@vucica.net>
Date: September 2013
This file is part of GNUstep.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef OpalFaceInfo_h_defined
#define OpalFaceInfo_h_defined
#import "fontconfig/FCFaceInfo.h"
#import <CoreGraphics/CoreGraphics.h>
@interface OpalFaceInfo : FCFaceInfo
{
CGFontRef _fontFace;
}
- (void *) fontFace;
@end
#endif

View file

@ -28,14 +28,15 @@
#ifndef OpalFontEnumerator_h_defined
#define OpalFontEnumerator_h_defined
#import <GNUstepGUI/GSFontInfo.h>
#import "fontconfig/FCFontEnumerator.h"
@interface OpalFontEnumerator : GSFontEnumerator
@class OpalFaceInfo;
@interface OpalFontEnumerator : FCFontEnumerator
{
}
- (void) enumerateFontsAndFamilies;
+ (Class) faceInfoClass;
+ (OpalFaceInfo *) fontWithName: (NSString *)name;
@end
#endif

View file

@ -28,16 +28,28 @@
#ifndef OpalFontInfo_h_defined
#define OpalFontInfo_h_defined
#import <GNUstepGUI/GSFontInfo.h>
@interface OpalFontInfo : GSFontInfo
#include "fontconfig/FCFontInfo.h"
#include "opal/OpalFaceInfo.h"
#if 0
#include <cairo.h>
#endif
@interface OpalFontInfo : FCFontInfo
{
@public
#if 0
cairo_scaled_font_t *_scaled;
#endif
}
/*
- (id) initWithFontName: (NSString *)name
matrix: (const CGFloat *)fmatrix
screenFont: (BOOL)p_screenFont;
*/
#if 0
- (void) drawGlyphs: (const NSGlyph*)glyphs
length: (int)length
on: (cairo_t*)ct;
#endif
@end
#endif

View file

@ -171,11 +171,4 @@
[self subclassResponsibility: _cmd];
}
- (void) drawGlyphs: (const NSGlyph*)glyphs
length: (int)length
on: (cairo_t*)ct
{
[self subclassResponsibility: _cmd];
}
@end

View file

@ -37,6 +37,9 @@ opal_OBJC_FILES = OpalSurface.m \
OpalFaceInfo.m \
OpalPSSurface.m \
OpalPDFSurface.m \
../fontconfig/FCFaceInfo.m \
../fontconfig/FCFontEnumerator.m \
../fontconfig/FCFontInfo.m \
ifeq ($(BUILD_SERVER),x11DISABLED)
ifeq ($(WITH_GLITZ),yes)

View file

@ -0,0 +1,62 @@
/*
OpalFaceInfo.m
Copyright (C) 2013 Free Software Foundation, Inc.
Author: Ivan Vucica <ivan@vucica.net>
Date: September 2013
This file is part of GNUstep.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import "opal/OpalFaceInfo.h"
@implementation OpalFaceInfo
- (void) dealloc
{
if (_fontFace)
{
CGFontRelease(_fontFace);
}
[super dealloc];
}
- (void *)fontFace
{
if (!_fontFace)
{
FcPattern *resolved;
resolved = [self matchedPattern];
_fontFace = OPFontCreateWithFcPattern(resolved);
FcPatternDestroy(resolved);
if (!_fontFace)
{
NSLog(@"Creating a font face failed %@", _familyName);
return NULL;
}
}
return _fontFace;
}
@end

View file

@ -1,11 +1,11 @@
/*
OpalFontEnumerator.m
Copyright (C) 2013 Free Software Foundation, Inc.
Author: Ivan Vucica <ivan@vucica.net>
Date: June 2013
Date: September 2013
This file is part of GNUstep.
This library is free software; you can redistribute it and/or
@ -26,100 +26,19 @@
*/
#import "opal/OpalFontEnumerator.h"
#import "opal/OpalFontInfo.h"
#import <Foundation/Foundation.h>
@implementation OpalFontEnumerator
@interface OpalFaceInfo : NSObject
/* DUMMY interface */
+ (Class) faceInfoClass
{
NSString * _familyName;
int _weight;
unsigned int _traits;
return [OpalFaceInfo class];
}
- (id) initWithFamilyName: (NSString *)familyName
weight: (int)weight
traits: (unsigned int)traits;
- (unsigned int) cacheSize;
- (int) weight;
- (void) setWeight: (int)weight;
- (unsigned int) traits;
- (void) setTraits: (unsigned int)traits;
- (NSString *) familyName;
- (void) setFamilyName: (NSString *)name;
- (NSCharacterSet*)characterSet;
@end
@implementation OpalFaceInfo
/* DUMMY implementation */
- (id) initWithFamilyName: (NSString *)familyName
weight: (int)weight
traits: (unsigned int)traits
{
self = [super init];
if (!self)
return nil;
_familyName = [familyName retain];
_weight = weight;
_traits = traits;
return self;
}
- (int) weight { NSDebugLLog(@"OpalFaceInfo", @"OpalFaceInfo: 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 { NSDebugLLog(@"OpalFaceInfo", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return [NSCharacterSet alphanumericCharacterSet]; }
@end
@implementation OpalFontEnumerator
+ (OpalFaceInfo *) fontWithName: (NSString *) name
{
NSDebugLLog(@"OpalFontEnumerator", @"%p (%@): %s - %@", self, [self class], __PRETTY_FUNCTION__, name);
return [[[OpalFaceInfo alloc] initWithFamilyName:name weight:1 traits:0] autorelease];
return (OpalFaceInfo *) [super fontWithName: name];
}
- (void) enumerateFontsAndFamilies
{
NSDebugLLog(@"OpalFontEnumerator", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
allFontNames = [[NSArray arrayWithObjects: @"FreeSans",
@"FreeSans-Bold", @"FreeMono", nil] retain];
allFontFamilies = [[NSDictionary dictionaryWithObjectsAndKeys:
@"FreeSans", @"FreeSans",
@"FreeMono", @"FreeMono",
nil] retain];
}
- (NSString *) defaultSystemFontName
{
NSDebugLLog(@"OpalFontEnumerator", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return @"FreeSans";
}
- (NSString *) defaultBoldSystemFontName
{
NSDebugLLog(@"OpalFontEnumerator", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return @"FreeSans-Bold";
}
- (NSString *) defaultFixedPitchFontName
{
NSDebugLLog(@"OpalFontEnumerator", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return @"FreeMono";
}
- (NSArray *) matchingFontDescriptorsFor: (NSDictionary *)attributes
{
NSDebugLLog(@"OpalFontEnumerator", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
return [NSArray arrayWithObject:[NSFontDescriptor fontDescriptorWithName:@"FreeSans" size: 10]];
}
@end

View file

@ -1,10 +1,10 @@
/*
OpalFontInfo.m
Copyright (C) 2013 Free Software Foundation, Inc.
Author: Ivan Vucica <ivan@vucica.net>
Date: June 2013
Date: September 2013
This file is part of GNUstep.
@ -25,59 +25,507 @@
Boston, MA 02110-1301, USA.
*/
#import <Foundation/Foundation.h>
#import "opal/OpalFontInfo.h"
#include "GNUstepBase/Unicode.h"
#include <AppKit/NSAffineTransform.h>
#include <AppKit/NSBezierPath.h>
#include "opal/OpalFontInfo.h"
#include "opal/OpalFontEnumerator.h"
@implementation OpalFontInfo
#include <math.h>
/*
#include <cairo-ft.h>
*/
@implementation OpalFontInfo
- (BOOL) setupAttributes
{
/*
cairo_font_extents_t font_extents;
cairo_font_face_t *face;
cairo_matrix_t font_matrix;
cairo_matrix_t ctm;
cairo_font_options_t *options;
*/
CGFontRef face;
CGSize maximumAdvancementCG;
CGRect fontBBoxCG;
if (![super setupAttributes])
{
return NO;
}
#if 0
/* setting GSFontInfo:
* xHeight, pix_width, pix_height
*/
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], -matrix[2],
matrix[3], matrix[4], matrix[5]);
//cairo_matrix_scale(&font_matrix, 0.9, 0.9);
cairo_matrix_init_identity(&ctm);
#endif
face = [_faceInfo fontFace];
if (!face)
{
return NO;
}
ascender = CGFontGetAscent(face);
descender = CGFontGetDescent(face);
xHeight = CGFontGetXHeight(face);
maximumAdvancementCG = OPFontGetMaximumAdvancement(face);
maximumAdvancement = NSMakeSize(maximumAdvancementCG.width,
maximumAdvancementCG.height);
fontBBoxCG = CGFontGetFontBBox(face);
fontBBox = NSMakeRect(fontBBoxCG.origin.x, fontBBoxCG.origin.y,
fontBBoxCG.size.width, fontBBoxCG.size.height);
if (xHeight == 0.0)
xHeight = ascender * 0.6;
// derived from code calculating CGFontGetLeading() value.
// we may instead want to extend Opal to include OPFontGetLineHeight(),
// containing this code:
// cairo_scaled_font_extents(_scaled, &font_extents);
// 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);
CGFloat pointSize = matrix[0]; // from GSFontInfo
ascender /= pointSize;
descender /= pointSize;
xHeight /= pointSize;
fontBBox.origin.x /= pointSize;
fontBBox.origin.y /= pointSize;
fontBBox.size.width /= pointSize;
fontBBox.size.height /= pointSize;
maximumAdvancement.width /= pointSize;
maximumAdvancement.height /= pointSize;
#if 0
// Get default font options
options = cairo_font_options_create();
if (cairo_font_options_status(options) != CAIRO_STATUS_SUCCESS)
{
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);
_scaled = cairo_scaled_font_create(face, &font_matrix, &ctm, options);
cairo_font_options_destroy(options);
if (cairo_scaled_font_status(_scaled) != CAIRO_STATUS_SUCCESS)
{
return NO;
}
cairo_scaled_font_extents(_scaled, &font_extents);
if (cairo_scaled_font_status(_scaled) != CAIRO_STATUS_SUCCESS)
{
return NO;
}
ascender = font_extents.ascent;
descender = -font_extents.descent;
xHeight = ascender * 0.6;
lineHeight = font_extents.height;
maximumAdvancement = NSMakeSize(font_extents.max_x_advance,
font_extents.max_y_advance);
fontBBox = NSMakeRect(0, descender,
maximumAdvancement.width, ascender - descender);
/*
NSLog(@"Font matrix (%g, %g, %g, %g, %g, %g) type %d",
matrix[0], matrix[1], matrix[2],
matrix[3], matrix[4], matrix[5], cairo_scaled_font_get_type(_scaled));
NSLog(@"(%@) h=%g a=%g d=%g max=(%g %g) (%g %g)+(%g %g)\n", fontName,
xHeight, ascender, descender,
maximumAdvancement.width, maximumAdvancement.height,
fontBBox.origin.x, fontBBox.origin.y,
fontBBox.size.width, fontBBox.size.height);
*/
#endif
return YES;
}
- (id) initWithFontName: (NSString *)name
matrix: (const CGFloat *)fmatrix
screenFont: (BOOL)p_screenFont
{
NSDebugLLog(@"OpalFontInfo", @"OpalFontInfo: instantiating font info for %@", name);
return [super init];
self = [super init];
if (!self)
return nil;
_screenFont = p_screenFont;
fontName = [name copy];
memcpy(matrix, fmatrix, sizeof(matrix));
if (_screenFont)
{
/* Round up; makes the text more legible. */
matrix[0] = ceil(matrix[0]);
if (matrix[3] < 0.0)
matrix[3] = floor(matrix[3]);
else
matrix[3] = ceil(matrix[3]);
}
if (![self setupAttributes])
{
RELEASE(self);
return nil;
}
return self;
}
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
- (void) dealloc
{
NSDebugLLog(@"OpalFontInfo", @"OpalFontInfo: %s - %c", __PRETTY_FUNCTION__, glyph);
return NSMakeRect(0, 0, 10, 10);
#if 0
if (_scaled)
{
cairo_scaled_font_destroy(_scaled);
}
#endif
[super dealloc];
}
- (CGFloat) widthOfString: (NSString *)string
- (BOOL) glyphIsEncoded: (NSGlyph)glyph
{
NSDebugLLog(@"OpalFontInfo", @"OpalFontInfo: %s - %@", __PRETTY_FUNCTION__, string);
return [string length] * 10;
/* 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.
return !NSEqualSizes([self advancementForGlyph: glyph], NSZeroSize);
*/
if ((glyph >= 0xFB00) && (glyph <= 0xFB05))
return NO;
else
return YES;
}
#if 0
static
BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
cairo_text_extents_t *ctext)
{
unichar ustr[2];
char str[4];
unsigned char *b;
unsigned int size = 4;
int length = 1;
ustr[0] = glyph;
ustr[1] = 0;
b = (unsigned char *)str;
if (!GSFromUnicode(&b, &size, ustr, length,
NSUTF8StringEncoding, NULL, GSUniTerminate))
{
NSLog(@"Conversion failed for %@",
[NSString stringWithCharacters: ustr length: length]);
return NO;
}
cairo_scaled_font_text_extents(scaled_font, str, ctext);
return cairo_scaled_font_status(scaled_font) == CAIRO_STATUS_SUCCESS;
}
#endif
- (NSSize) advancementForGlyph: (NSGlyph)glyph
{
NSDebugLLog(@"OpalFontInfo", @"OpalFontInfo: %s - %c", __PRETTY_FUNCTION__, glyph);
return NSMakeSize(10,10);
}
- (NSGlyph) glyphWithName: (NSString *) glyphName
{
NSDebugLLog(@"OpalFontInfo", @"OpalFontInfo: %s - %@", __PRETTY_FUNCTION__, glyphName);
#if 0
cairo_text_extents_t ctext;
// FIXME: incorrect
NSGlyph g = [glyphName cString][0];
return g;
if (_cachedSizes)
{
int entry = glyph % _cacheSize;
if (_cachedGlyphs[entry] == glyph)
{
return _cachedSizes[entry];
}
if (_cairo_extents_for_NSGlyph(_scaled, glyph, &ctext))
{
_cachedGlyphs[entry] = glyph;
_cachedSizes[entry] = NSMakeSize(ctext.x_advance, ctext.y_advance);
return _cachedSizes[entry];
}
}
else
{
if (_cairo_extents_for_NSGlyph(_scaled, glyph, &ctext))
{
return NSMakeSize(ctext.x_advance, ctext.y_advance);
}
}
#endif
return NSZeroSize;
}
- (NSGlyph) glyphForCharacter: (unichar)c
- (NSRect) boundingRectForGlyph: (NSGlyph)glyph
{
// FIXME: default in 'gui' uses -glyphIsEncoded: or otherwise
// returns null glyph. the default should be sufficient, and is
// sufficient for cairo backend.
return c;
#if 0
cairo_text_extents_t ctext;
if (_cairo_extents_for_NSGlyph(_scaled, glyph, &ctext))
{
return NSMakeRect(ctext.x_bearing, ctext.y_bearing,
ctext.width, ctext.height);
}
#endif
return NSZeroRect;
}
- (CGFloat) widthOfString: (NSString *)string
{
#if 0
cairo_text_extents_t ctext;
if (!string)
{
return 0.0;
}
cairo_scaled_font_text_extents(_scaled, [string UTF8String], &ctext);
if (cairo_scaled_font_status(_scaled) == CAIRO_STATUS_SUCCESS)
{
return ctext.width;
}
#endif
return 0.0;
}
- (void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
count: (int)length
toBezierPath: (NSBezierPath *)path
{
[path lineToPoint: NSMakePoint(length*10, 10)];
#if 0
cairo_format_t format = CAIRO_FORMAT_ARGB32;
cairo_surface_t *isurface;
cairo_t *ct;
int ix = 400;
int iy = 400;
unsigned char *cdata;
int i;
unichar ustr[length+1];
char str[3*length+1];
unsigned char *b;
unsigned int size = 3*length+1;
cairo_status_t status;
cairo_matrix_t font_matrix;
for (i = 0; i < length; i++)
{
ustr[i] = glyphs[i];
}
ustr[length] = 0;
b = (unsigned char *)str;
if (!GSFromUnicode(&b, &size, ustr, length,
NSUTF8StringEncoding, NULL, GSUniTerminate))
{
NSLog(@"Conversion failed for %@",
[NSString stringWithCharacters: ustr length: length]);
return;
}
cdata = malloc(sizeof(char) * 4 * ix * iy);
if (!cdata)
{
NSLog(@"Could not allocate drawing space for glyphs");
return;
}
isurface = cairo_image_surface_create_for_data(cdata, format, ix, iy, 4*ix);
status = cairo_surface_status(isurface);
if (status != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Error while creating surface: %s",
cairo_status_to_string(status));
cairo_surface_destroy(isurface);
free(cdata);
return;
}
ct = cairo_create(isurface);
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Error while creating context: %s",
cairo_status_to_string(cairo_status(ct)));
cairo_destroy(ct);
cairo_surface_destroy(isurface);
free(cdata);
return;
}
// Use flip matrix
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], matrix[2],
-matrix[3], matrix[4], matrix[5]);
cairo_set_font_matrix(ct, &font_matrix);
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Error while setting font matrix: %s",
cairo_status_to_string(cairo_status(ct)));
cairo_destroy(ct);
cairo_surface_destroy(isurface);
free(cdata);
return;
}
cairo_set_font_face(ct, [_faceInfo fontFace]);
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Error while setting font face: %s",
cairo_status_to_string(cairo_status(ct)));
cairo_destroy(ct);
cairo_surface_destroy(isurface);
free(cdata);
return;
}
// Set font options from the scaled font
// FIXME: Instead of setting the matrix, setting the face, and setting
// the options, we should be using cairo_set_scaled_font
{
cairo_font_options_t *options = cairo_font_options_create();
cairo_scaled_font_get_font_options(_scaled, options);
cairo_set_font_options(ct, options);
cairo_font_options_destroy(options);
}
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Error while setting font options: %s",
cairo_status_to_string(cairo_status(ct)));
cairo_destroy(ct);
cairo_surface_destroy(isurface);
free(cdata);
return;
}
if ([path elementCount] > 0)
{
NSPoint p;
p = [path currentPoint];
cairo_move_to(ct, floorf(p.x), floorf(p.y));
}
cairo_text_path(ct, str);
if (cairo_status(ct) == CAIRO_STATUS_SUCCESS)
{
cairo_path_t *cpath;
cairo_path_data_t *data;
cpath = cairo_copy_path(ct);
for (i = 0; i < cpath->num_data; i += cpath->data[i].header.length)
{
data = &cpath->data[i];
switch (data->header.type)
{
case CAIRO_PATH_MOVE_TO:
[path moveToPoint: NSMakePoint(data[1].point.x, data[1].point.y)];
break;
case CAIRO_PATH_LINE_TO:
[path lineToPoint: NSMakePoint(data[1].point.x, data[1].point.y)];
break;
case CAIRO_PATH_CURVE_TO:
[path curveToPoint: NSMakePoint(data[3].point.x, data[3].point.y)
controlPoint1: NSMakePoint(data[1].point.x, data[1].point.y)
controlPoint2: NSMakePoint(data[2].point.x, data[2].point.y)];
break;
case CAIRO_PATH_CLOSE_PATH:
[path closePath];
break;
}
}
cairo_path_destroy(cpath);
}
cairo_destroy(ct);
cairo_surface_destroy(isurface);
free(cdata);
#endif
}
- (CGFloat) defaultLineHeightForFont
#if 0
- (void) drawGlyphs: (const NSGlyph*)glyphs
length: (int)length
on: (cairo_t*)ct
{
// required for textcontainer->linefrags calculation to work
// without which information supplied in advancementForGlyph: is also not used.
return 10;
cairo_matrix_t font_matrix;
unichar ustr[length+1];
char str[3*length+1];
unsigned char *b;
int i;
unsigned int size = 3*length+1;
for (i = 0; i < length; i++)
{
ustr[i] = glyphs[i];
}
ustr[length] = 0;
b = (unsigned char *)str;
if (!GSFromUnicode(&b, &size, ustr, length,
NSUTF8StringEncoding, NULL, GSUniTerminate))
{
NSLog(@"Conversion failed for %@",
[NSString stringWithCharacters: ustr length: length]);
return;
}
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], -matrix[2],
matrix[3], matrix[4], matrix[5]);
cairo_set_font_matrix(ct, &font_matrix);
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Error while setting font matrix: %s",
cairo_status_to_string(cairo_status(ct)));
return;
}
cairo_set_font_face(ct, [_faceInfo fontFace]);
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Error while setting font face: %s",
cairo_status_to_string(cairo_status(ct)));
return;
}
// Set font options from the scaled font
// FIXME: Instead of setting the matrix, setting the face, and setting
// the options, we should be using cairo_set_scaled_font
{
cairo_font_options_t *options = cairo_font_options_create();
cairo_scaled_font_get_font_options(_scaled, options);
cairo_set_font_options(ct, options);
cairo_font_options_destroy(options);
}
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Error while setting font options: %s",
cairo_status_to_string(cairo_status(ct)));
return;
}
cairo_show_text(ct, str);
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
{
NSLog(@"Error drawing string: '%s' for string %s",
cairo_status_to_string(cairo_status(ct)), str);
}
}
#endif
@end

View file

@ -540,25 +540,45 @@ static CGFloat theAlpha = 1.; // TODO: removeme
CGContextRestoreGState(CGCTX);
}
#if 0
#if 1
- (void) DPSrlineto: (CGFloat) x
: (CGFloat) y
{
CGFloat x2, y2;
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
CGContextAddRelativeLine(CGCTX, x, y);
[self DPScurrentpoint: &x2 : &y2];
x2 += x;
y2 += y;
CGContextAddLineToPoint(CGCTX, x, y);
}
#else
#warning -DPSrlineto:: not implemented directly
#endif
#if 1
- (void) DPSrmoveto: (CGFloat) x
: (CGFloat) y
{
CGFloat x2, y2;
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
[self DPScurrentpoint: &x2 : &y2];
x2 += x;
y2 += y;
CGContextMoveToPoint(CGCTX, x2, y2);
}
#else
#warning -DPSrmoveto:: not implemented directly
#endif
- (void) DPScurrentpoint: (CGFloat *)x
: (CGFloat *)y
{
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
CGPoint currentPoint = CGContextGetPathCurrentPoint(CGCTX);
*x = currentPoint.x;
*y = currentPoint.y;
NSDebugLLog(@"OpalGState", @" %p (%@): %s (returning: %f %f)", self, [self class], __PRETTY_FUNCTION__, *x, *y);
}
@end

3
configure vendored
View file

@ -7158,7 +7158,8 @@ elif test x"$BUILD_GRAPHICS" = "xxlib"; then
elif test x"$BUILD_GRAPHICS" = "xwinlib"; then
: # Nothing to do
elif test x"$BUILD_GRAPHICS" = "xopal"; then
LIBS="-lopal -lgnustep-corebase $LIBS"
LIBS="-lopal -lgnustep-corebase $FONTCONFIG_LIBS $FREETYPE_LIBS $LIBS"
CPPFLAGS="$FONTCONFIG_CFLAGS $FREETYPE_CFLAGS $CPPFLAGS"
else
as_fn_error $? "Invalid graphics backend $BUILD_GRAPHICS" "$LINENO" 5
fi

View file

@ -642,7 +642,26 @@ elif test x"$BUILD_GRAPHICS" = "xxlib"; then
elif test x"$BUILD_GRAPHICS" = "xwinlib"; then
: # Nothing to do
elif test x"$BUILD_GRAPHICS" = "xopal"; then
CPPFLAGS="$FONTCONFIG_CFLAGS $FREETYPE_CFLAGS $CPPFLAGS"
LIBS="-lopal -lgnustep-corebase $LIBS"
LIBS="$FONTCONFIG_LIBS $FREETYPE_LIBS $LIBS"
if test "$have_freetype" = no ; then # FCFaceInfo requires this
AC_MSG_WARN([can't find freetype, required for graphics=opal!])
if test $BUILD_SERVER = win32; then
BUILD_GRAPHICS=winlib
else
BUILD_GRAPHICS=xlib
fi
AC_MSG_NOTICE([Switching to $BUILD_GRAPHICS])
elif test "$have_fontconfig" = no ; then
AC_MSG_WARN([can't find fontconfig, required for graphics=opal!])
if test $BUILD_SERVER = win32; then
BUILD_GRAPHICS=winlib
else
BUILD_GRAPHICS=xlib
fi
AC_MSG_NOTICE([Switching to $BUILD_GRAPHICS])
fi
else
AC_MSG_ERROR([Invalid graphics backend $BUILD_GRAPHICS])
fi