File: GVTextLayout.m

package info (click to toggle)
graphviz 2.26.3-5%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 63,044 kB
  • ctags: 25,930
  • sloc: ansic: 212,134; sh: 20,316; cpp: 7,239; makefile: 4,211; yacc: 3,335; xml: 2,450; tcl: 1,900; cs: 1,890; objc: 1,149; perl: 829; lex: 364; awk: 171; python: 41; ruby: 35; php: 26
file content (133 lines) | stat: -rw-r--r-- 3,475 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* $Id: GVTextLayout.m,v 1.4 2009/06/03 01:10:57 ellson Exp $ $Revision: 1.4 $ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
 *      This software is part of the graphviz package      *
 *                http://www.graphviz.org/                 *
 *                                                         *
 *            Copyright (c) 1994-2008 AT&T Corp.           *
 *                and is licensed under the                *
 *            Common Public License, Version 1.0           *
 *                      by AT&T Corp.                      *
 *                                                         *
 *        Information and Software Systems Research        *
 *              AT&T Research, Florham Park NJ             *
 **********************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <string.h>

#include "types.h"
#include "gvcjob.h"

#include "gvplugin_quartz.h"

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 20000

#import "GVTextLayout.h"

boolean quartz_textlayout(textpara_t *para, char **fontpath)
{
	GVTextLayout* layout = [[GVTextLayout alloc] initWithFontName:para->fontname fontSize:para->fontsize text:para->str];
	CGSize size = layout.size;
	
	para->layout = layout;
	para->free_layout = &quartz_free_layout;
	para->width = size.width;
	para->height = size.height;
	para->yoffset_layout = layout.font.ascender;
	para->yoffset_centerline = 0;
	
	return TRUE;
}

void quartz_free_layout(void *layout)
{
	[(GVTextLayout*)layout release];
}

void quartzgen_textpara(GVJ_t *job, pointf p, textpara_t *para)
{
	CGContextRef context = (CGContextRef)job->context;

	/* adjust text position */
	switch (para->just) {
		case 'r':
			p.x -= para->width;
			break;
		case 'l':
			p.x -= 0.0;
			break;
		case 'n':
		default:
			p.x -= para->width / 2.0;
			break;
		}
	p.y += para->yoffset_centerline;
	
	GVTextLayout* layout;
	if (para->free_layout == &quartz_free_layout)
		layout = (GVTextLayout*)para->layout;
	else
		layout = [[GVTextLayout alloc] initWithFontName:para->fontname fontSize:para->fontsize text:para->str];
		
	CGContextSaveGState(context);
	CGContextScaleCTM(context, 1.0, -1.0);
	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]);
	[layout drawAtPoint:CGPointMake(p.x, -p.y - para->yoffset_layout) inContext:context];
	CGContextRestoreGState(context);
	
	if (para->free_layout != &quartz_free_layout)
		[layout release];
}

static NSString* _defaultFontName = @"TimesNewRomanPSMT";

@implementation GVTextLayout

@synthesize font = _font;
@synthesize text = _text;

- (id)initWithFontName:(char*)fontName fontSize:(CGFloat)fontSize text:(char*)text
{
	if (self = [super init])
	{
		_font = nil;
		if (fontName)
			_font = [[UIFont fontWithName:[NSString stringWithUTF8String:fontName] size:fontSize] retain];
		if (!_font)
			_font = [[UIFont fontWithName:_defaultFontName size:fontSize] retain];
			
		_text = text ? [[NSString alloc] initWithUTF8String:text] : nil;
	}
	return self;
}

- (void)drawAtPoint:(CGPoint)point inContext:(CGContextRef)context
{
	UIGraphicsPushContext(context);
	[_text drawAtPoint:point withFont:_font];
	UIGraphicsPopContext();
}

- (CGSize)size
{
	return [_text sizeWithFont:_font];
}

- (void)dealloc
{
	[_font release];
	[_text release];
	
	[super dealloc];
}


@end

#endif