~ubuntu-branches/ubuntu/precise/graphviz/precise-security

« back to all changes in this revision

Viewing changes to plugin/quartz/GVTextLayout.m

  • Committer: Bazaar Package Importer
  • Author(s): David Claughton
  • Date: 2010-03-24 22:45:18 UTC
  • mfrom: (1.2.7 upstream) (6.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100324224518-do441tthbqjaqjzd
Tags: 2.26.3-4
Add patch to fix segfault in circo. Backported from upstream snapshot
release.  Thanks to Francis Russell for his work on this.
(Closes: #575255)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: */
 
3
 
 
4
/**********************************************************
 
5
 *      This software is part of the graphviz package      *
 
6
 *                http://www.graphviz.org/                 *
 
7
 *                                                         *
 
8
 *            Copyright (c) 1994-2008 AT&T Corp.           *
 
9
 *                and is licensed under the                *
 
10
 *            Common Public License, Version 1.0           *
 
11
 *                      by AT&T Corp.                      *
 
12
 *                                                         *
 
13
 *        Information and Software Systems Research        *
 
14
 *              AT&T Research, Florham Park NJ             *
 
15
 **********************************************************/
 
16
 
 
17
#ifdef HAVE_CONFIG_H
 
18
#include "config.h"
 
19
#endif
 
20
 
 
21
#include <stdlib.h>
 
22
#include <string.h>
 
23
 
 
24
#include "types.h"
 
25
#include "gvcjob.h"
 
26
 
 
27
#include "gvplugin_quartz.h"
 
28
 
 
29
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 20000
 
30
 
 
31
#import "GVTextLayout.h"
 
32
 
 
33
boolean quartz_textlayout(textpara_t *para, char **fontpath)
 
34
{
 
35
        GVTextLayout* layout = [[GVTextLayout alloc] initWithFontName:para->fontname fontSize:para->fontsize text:para->str];
 
36
        CGSize size = layout.size;
 
37
        
 
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;
 
44
        
 
45
        return TRUE;
 
46
}
 
47
 
 
48
void quartz_free_layout(void *layout)
 
49
{
 
50
        [(GVTextLayout*)layout release];
 
51
}
 
52
 
 
53
void quartzgen_textpara(GVJ_t *job, pointf p, textpara_t *para)
 
54
{
 
55
        CGContextRef context = (CGContextRef)job->context;
 
56
 
 
57
        /* adjust text position */
 
58
        switch (para->just) {
 
59
                case 'r':
 
60
                        p.x -= para->width;
 
61
                        break;
 
62
                case 'l':
 
63
                        p.x -= 0.0;
 
64
                        break;
 
65
                case 'n':
 
66
                default:
 
67
                        p.x -= para->width / 2.0;
 
68
                        break;
 
69
                }
 
70
        p.y += para->yoffset_centerline;
 
71
        
 
72
        GVTextLayout* layout;
 
73
        if (para->free_layout == &quartz_free_layout)
 
74
                layout = (GVTextLayout*)para->layout;
 
75
        else
 
76
                layout = [[GVTextLayout alloc] initWithFontName:para->fontname fontSize:para->fontsize text:para->str];
 
77
                
 
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);
 
83
        
 
84
        if (para->free_layout != &quartz_free_layout)
 
85
                [layout release];
 
86
}
 
87
 
 
88
static NSString* _defaultFontName = @"TimesNewRomanPSMT";
 
89
 
 
90
@implementation GVTextLayout
 
91
 
 
92
@synthesize font = _font;
 
93
@synthesize text = _text;
 
94
 
 
95
- (id)initWithFontName:(char*)fontName fontSize:(CGFloat)fontSize text:(char*)text
 
96
{
 
97
        if (self = [super init])
 
98
        {
 
99
                _font = nil;
 
100
                if (fontName)
 
101
                        _font = [[UIFont fontWithName:[NSString stringWithUTF8String:fontName] size:fontSize] retain];
 
102
                if (!_font)
 
103
                        _font = [[UIFont fontWithName:_defaultFontName size:fontSize] retain];
 
104
                        
 
105
                _text = text ? [[NSString alloc] initWithUTF8String:text] : nil;
 
106
        }
 
107
        return self;
 
108
}
 
109
 
 
110
- (void)drawAtPoint:(CGPoint)point inContext:(CGContextRef)context
 
111
{
 
112
        UIGraphicsPushContext(context);
 
113
        [_text drawAtPoint:point withFont:_font];
 
114
        UIGraphicsPopContext();
 
115
}
 
116
 
 
117
- (CGSize)size
 
118
{
 
119
        return [_text sizeWithFont:_font];
 
120
}
 
121
 
 
122
- (void)dealloc
 
123
{
 
124
        [_font release];
 
125
        [_text release];
 
126
        
 
127
        [super dealloc];
 
128
}
 
129
 
 
130
 
 
131
@end
 
132
 
 
133
#endif