File: GVTextLayout.m

package info (click to toggle)
graphviz 2.38.0-17
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 80,692 kB
  • ctags: 27,194
  • sloc: ansic: 1,038,718; sh: 14,765; cpp: 11,377; makefile: 4,480; yacc: 3,339; xml: 2,466; tcl: 1,950; cs: 1,890; objc: 1,157; perl: 422; lex: 375; awk: 241; python: 45; ruby: 41; php: 26
file content (100 lines) | stat: -rw-r--r-- 2,618 bytes parent folder | download | duplicates (2)
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
/* $Id$ $Revision$ */
/* vim:set shiftwidth=4 ts=8: */

/*************************************************************************
 * Copyright (c) 2011 AT&T Intellectual Property 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: See CVS logs. Details at http://www.graphviz.org/
 *************************************************************************/

#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 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 20000 && __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 30200

#import "GVTextLayout.h"

void *quartz_new_layout(char* fontname, double fontsize, char* text)
{
	return [[GVTextLayout alloc] initWithFontName:fontname fontSize:fontsize text:text];
}

void quartz_size_layout(void *layout, double* width, double* height, double* yoffset_layout)
{
	[(GVTextLayout*)layout sizeUpWidth:width height:height yoffset:yoffset_layout];
}

void quartz_draw_layout(void *layout, CGContextRef context, CGPoint position)
{
	[(GVTextLayout*)layout drawInContext:context atPosition:position];	
}

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

static NSString* _defaultFontName = @"TimesNewRomanPSMT";

@implementation GVTextLayout

- (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)sizeUpWidth:(double*)width height:(double*)height yoffset:(double*)yoffset
{
	CGSize size = [_text sizeWithFont:_font];
	CGFloat ascender = _font.ascender;
	
	*width = size.width;
	*height = size.height;
	*yoffset = ascender;
}

- (void)drawInContext:(CGContextRef)context atPosition:(CGPoint)position
{
	UIGraphicsPushContext(context);
	CGContextSaveGState(context);
	CGContextScaleCTM(context, 1.0, -1.0);
	[_text drawAtPoint:CGPointMake(position.x, -position.y - _font.ascender) withFont:_font];
	CGContextRestoreGState(context);
	UIGraphicsPopContext();
}

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


@end

#endif