1
/* $Id: GVTextLayout.m,v 1.4 2009/06/03 01:10:57 ellson Exp $ $Revision: 1.4 $ */
2
/* vim:set shiftwidth=4 ts=8: */
4
/**********************************************************
5
* This software is part of the graphviz package *
6
* http://www.graphviz.org/ *
8
* Copyright (c) 1994-2008 AT&T Corp. *
9
* and is licensed under the *
10
* Common Public License, Version 1.0 *
13
* Information and Software Systems Research *
14
* AT&T Research, Florham Park NJ *
15
**********************************************************/
27
#include "gvplugin_quartz.h"
29
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 20000
31
#import "GVTextLayout.h"
33
boolean quartz_textlayout(textpara_t *para, char **fontpath)
35
GVTextLayout* layout = [[GVTextLayout alloc] initWithFontName:para->fontname fontSize:para->fontsize text:para->str];
36
CGSize size = layout.size;
38
para->layout = layout;
39
para->free_layout = &quartz_free_layout;
40
para->width = size.width;
41
para->height = size.height;
42
para->yoffset_layout = layout.font.ascender;
43
para->yoffset_centerline = 0;
48
void quartz_free_layout(void *layout)
50
[(GVTextLayout*)layout release];
53
void quartzgen_textpara(GVJ_t *job, pointf p, textpara_t *para)
55
CGContextRef context = (CGContextRef)job->context;
57
/* adjust text position */
67
p.x -= para->width / 2.0;
70
p.y += para->yoffset_centerline;
73
if (para->free_layout == &quartz_free_layout)
74
layout = (GVTextLayout*)para->layout;
76
layout = [[GVTextLayout alloc] initWithFontName:para->fontname fontSize:para->fontsize text:para->str];
78
CGContextSaveGState(context);
79
CGContextScaleCTM(context, 1.0, -1.0);
80
CGContextSetRGBFillColor(context, job->obj->pencolor.u.RGBA [0], job->obj->pencolor.u.RGBA [1], job->obj->pencolor.u.RGBA [2], job->obj->pencolor.u.RGBA [3]);
81
[layout drawAtPoint:CGPointMake(p.x, -p.y - para->yoffset_layout) inContext:context];
82
CGContextRestoreGState(context);
84
if (para->free_layout != &quartz_free_layout)
88
static NSString* _defaultFontName = @"TimesNewRomanPSMT";
90
@implementation GVTextLayout
92
@synthesize font = _font;
93
@synthesize text = _text;
95
- (id)initWithFontName:(char*)fontName fontSize:(CGFloat)fontSize text:(char*)text
97
if (self = [super init])
101
_font = [[UIFont fontWithName:[NSString stringWithUTF8String:fontName] size:fontSize] retain];
103
_font = [[UIFont fontWithName:_defaultFontName size:fontSize] retain];
105
_text = text ? [[NSString alloc] initWithUTF8String:text] : nil;
110
- (void)drawAtPoint:(CGPoint)point inContext:(CGContextRef)context
112
UIGraphicsPushContext(context);
113
[_text drawAtPoint:point withFont:_font];
114
UIGraphicsPopContext();
119
return [_text sizeWithFont:_font];