mirror of
https://github.com/gnustep/libs-back.git
synced 2025-05-30 08:51:03 +00:00
First implementation of appendBezierPathWithGlyphs:count:toBezierPath:
for cairo. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@25522 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2050099a6e
commit
901c5b758c
2 changed files with 109 additions and 36 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2007-10-08 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/cairo/CairoFontInfo.m
|
||||||
|
(-appendBezierPathWithGlyphs:count:toBezierPath:): First implemenation.
|
||||||
|
|
||||||
2007-10-07 Fred Kiefer <FredKiefer@gmx.de>
|
2007-10-07 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Headers/gsc/GSFunction.h: Declare the -getsample:: method in
|
* Headers/gsc/GSFunction.h: Declare the -getsample:: method in
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "GNUstepBase/Unicode.h"
|
#include "GNUstepBase/Unicode.h"
|
||||||
#include <AppKit/NSAffineTransform.h>
|
#include <AppKit/NSAffineTransform.h>
|
||||||
|
#include <AppKit/NSBezierPath.h>
|
||||||
#include "cairo/CairoFontInfo.h"
|
#include "cairo/CairoFontInfo.h"
|
||||||
#include "cairo/CairoFontEnumerator.h"
|
#include "cairo/CairoFontEnumerator.h"
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@
|
||||||
* xHeight, pix_width, pix_height
|
* xHeight, pix_width, pix_height
|
||||||
*/
|
*/
|
||||||
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], matrix[2],
|
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], matrix[2],
|
||||||
matrix[3], matrix[4], matrix[5]);
|
matrix[3], matrix[4], matrix[5]);
|
||||||
cairo_matrix_init_identity(&ctm);
|
cairo_matrix_init_identity(&ctm);
|
||||||
// FIXME: Should get default font options from somewhere
|
// FIXME: Should get default font options from somewhere
|
||||||
options = cairo_font_options_create();
|
options = cairo_font_options_create();
|
||||||
|
@ -105,16 +106,16 @@
|
||||||
xHeight = ascender * 0.6;
|
xHeight = ascender * 0.6;
|
||||||
lineHeight = font_extents.height;
|
lineHeight = font_extents.height;
|
||||||
maximumAdvancement = NSMakeSize(font_extents.max_x_advance,
|
maximumAdvancement = NSMakeSize(font_extents.max_x_advance,
|
||||||
font_extents.max_y_advance);
|
font_extents.max_y_advance);
|
||||||
fontBBox = NSMakeRect(0, descender,
|
fontBBox = NSMakeRect(0, descender,
|
||||||
maximumAdvancement.width, ascender - descender);
|
maximumAdvancement.width, ascender - descender);
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithFontName: (NSString *)name
|
- (id) initWithFontName: (NSString *)name
|
||||||
matrix: (const float *)fmatrix
|
matrix: (const float *)fmatrix
|
||||||
screenFont: (BOOL)p_screenFont
|
screenFont: (BOOL)p_screenFont
|
||||||
{
|
{
|
||||||
//NSLog(@"initWithFontName %@",name);
|
//NSLog(@"initWithFontName %@",name);
|
||||||
[super init];
|
[super init];
|
||||||
|
@ -128,9 +129,9 @@
|
||||||
/* Round up; makes the text more legible. */
|
/* Round up; makes the text more legible. */
|
||||||
matrix[0] = ceil(matrix[0]);
|
matrix[0] = ceil(matrix[0]);
|
||||||
if (matrix[3] < 0.0)
|
if (matrix[3] < 0.0)
|
||||||
matrix[3] = floor(matrix[3]);
|
matrix[3] = floor(matrix[3]);
|
||||||
else
|
else
|
||||||
matrix[3] = ceil(matrix[3]);
|
matrix[3] = ceil(matrix[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![self setupAttributes])
|
if (![self setupAttributes])
|
||||||
|
@ -167,7 +168,7 @@
|
||||||
|
|
||||||
static
|
static
|
||||||
BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
||||||
cairo_text_extents_t *ctext)
|
cairo_text_extents_t *ctext)
|
||||||
{
|
{
|
||||||
unichar ustr[2];
|
unichar ustr[2];
|
||||||
char str[4];
|
char str[4];
|
||||||
|
@ -180,10 +181,10 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
||||||
|
|
||||||
b = (unsigned char *)str;
|
b = (unsigned char *)str;
|
||||||
if (!GSFromUnicode(&b, &size, ustr, length,
|
if (!GSFromUnicode(&b, &size, ustr, length,
|
||||||
NSUTF8StringEncoding, NULL, GSUniTerminate))
|
NSUTF8StringEncoding, NULL, GSUniTerminate))
|
||||||
{
|
{
|
||||||
NSLog(@"Conversion failed for %@",
|
NSLog(@"Conversion failed for %@",
|
||||||
[NSString stringWithCharacters: ustr length: length]);
|
[NSString stringWithCharacters: ustr length: length]);
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +222,7 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
||||||
if (_cairo_extents_for_NSGlyph(_scaled, glyph, &ctext))
|
if (_cairo_extents_for_NSGlyph(_scaled, glyph, &ctext))
|
||||||
{
|
{
|
||||||
return NSMakeRect(ctext.x_bearing, ctext.y_bearing,
|
return NSMakeRect(ctext.x_bearing, ctext.y_bearing,
|
||||||
ctext.width, ctext.height);
|
ctext.width, ctext.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NSZeroRect;
|
return NSZeroRect;
|
||||||
|
@ -254,28 +255,95 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* need cairo to export its cairo_path_t first */
|
|
||||||
- (void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
|
- (void) appendBezierPathWithGlyphs: (NSGlyph *)glyphs
|
||||||
count: (int)count
|
count: (int)length
|
||||||
toBezierPath: (NSBezierPath *)path
|
toBezierPath: (NSBezierPath *)path
|
||||||
{
|
{
|
||||||
/* TODO LATER
|
cairo_format_t format = CAIRO_FORMAT_ARGB32;
|
||||||
cairo_t *ct;
|
cairo_surface_t *isurface;
|
||||||
int i;
|
cairo_t *ct;
|
||||||
NSPoint start = [path currentPoint];
|
int ix = 400;
|
||||||
cairo_glyph_t *cairo_glyphs;
|
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;
|
||||||
|
|
||||||
cairo_glyphs = malloc(sizeof(cairo_glyph_t) * count);
|
for (i = 0; i < length; i++)
|
||||||
ct = cairo_create();
|
{
|
||||||
|
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_destroy(ct);
|
cdata = objc_malloc(sizeof(char) * 4 * ix * iy);
|
||||||
*/
|
isurface = cairo_image_surface_create_for_data(cdata, format, ix, iy, 4*ix);
|
||||||
|
status = cairo_surface_status(isurface);
|
||||||
|
if (status != CAIRO_STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
cairo_surface_destroy(isurface);
|
||||||
|
objc_free(cdata);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ct = cairo_create(isurface);
|
||||||
|
|
||||||
|
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], matrix[2],
|
||||||
|
matrix[3], matrix[4], matrix[5]);
|
||||||
|
cairo_set_font_matrix(ct, &font_matrix);
|
||||||
|
|
||||||
|
cairo_text_path(ct, str);
|
||||||
|
status = cairo_status(ct);
|
||||||
|
if (status == 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[1].point.x, data[1].point.y)
|
||||||
|
controlPoint1: NSMakePoint(data[2].point.x, data[2].point.y)
|
||||||
|
controlPoint2: NSMakePoint(data[3].point.x, data[3].point.y)];
|
||||||
|
break;
|
||||||
|
case CAIRO_PATH_CLOSE_PATH:
|
||||||
|
[path closePath];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cairo_path_destroy(cpath);
|
||||||
|
}
|
||||||
|
cairo_destroy(ct);
|
||||||
|
cairo_surface_destroy(isurface);
|
||||||
|
objc_free(cdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawGlyphs: (const NSGlyph*)glyphs
|
- (void) drawGlyphs: (const NSGlyph*)glyphs
|
||||||
length: (int)length
|
length: (int)length
|
||||||
on: (cairo_t*)ct
|
on: (cairo_t*)ct
|
||||||
{
|
{
|
||||||
cairo_matrix_t font_matrix;
|
cairo_matrix_t font_matrix;
|
||||||
unichar ustr[length+1];
|
unichar ustr[length+1];
|
||||||
|
@ -292,35 +360,35 @@ BOOL _cairo_extents_for_NSGlyph(cairo_scaled_font_t *scaled_font, NSGlyph glyph,
|
||||||
|
|
||||||
b = (unsigned char *)str;
|
b = (unsigned char *)str;
|
||||||
if (!GSFromUnicode(&b, &size, ustr, length,
|
if (!GSFromUnicode(&b, &size, ustr, length,
|
||||||
NSUTF8StringEncoding, NULL, GSUniTerminate))
|
NSUTF8StringEncoding, NULL, GSUniTerminate))
|
||||||
{
|
{
|
||||||
NSLog(@"Conversion failed for %@",
|
NSLog(@"Conversion failed for %@",
|
||||||
[NSString stringWithCharacters: ustr length: length]);
|
[NSString stringWithCharacters: ustr length: length]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], matrix[2],
|
cairo_matrix_init(&font_matrix, matrix[0], matrix[1], matrix[2],
|
||||||
matrix[3], matrix[4], matrix[5]);
|
matrix[3], matrix[4], matrix[5]);
|
||||||
cairo_set_font_matrix(ct, &font_matrix);
|
cairo_set_font_matrix(ct, &font_matrix);
|
||||||
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
|
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
NSLog(@"Error while setting font matrix: %s",
|
NSLog(@"Error while setting font matrix: %s",
|
||||||
cairo_status_to_string(cairo_status(ct)));
|
cairo_status_to_string(cairo_status(ct)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cairo_set_font_face(ct, [_faceInfo fontFace]);
|
cairo_set_font_face(ct, [_faceInfo fontFace]);
|
||||||
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
|
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
NSLog(@"Error while setting font face: %s",
|
NSLog(@"Error while setting font face: %s",
|
||||||
cairo_status_to_string(cairo_status(ct)));
|
cairo_status_to_string(cairo_status(ct)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_show_text(ct, str);
|
cairo_show_text(ct, str);
|
||||||
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
|
if (cairo_status(ct) != CAIRO_STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
NSLog(@"Error drawing string: '%s' for string %s",
|
NSLog(@"Error drawing string: '%s' for string %s",
|
||||||
cairo_status_to_string(cairo_status(ct)), str);
|
cairo_status_to_string(cairo_status(ct)), str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue