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
|
/*************************************************************************
* 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
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors: Details at https://graphviz.org
*************************************************************************/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <common/types.h>
#include <gvc/gvcjob.h>
#include "gvplugin_quartz.h"
#ifdef __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
#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
#endif
|