/***************************************************************************
                            QFontMetrics.m -  description
                             -------------------
    begin                : Wed Nov 21 12:08:37 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 12:08:37 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <qtc/qt_QFontMetrics.h>
#include <qtobjc/QFontMetrics.h>

@implementation  QFontMetrics

- (void *) qt
{
	return _qt;
}

- setQt: (void *) qt
{
	_qt = qt;
	return self;
}

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

- setAllocatedInObjcWorld: (BOOL) yn
{
	_allocatedInObjcWorld = yn;
	return self;
}


- initWithFont: (QFont *)arg1
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QFontMetrics((qt_QFont *) [arg1 qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- copyWithZone: (NSZone *) zone
{
	QFontMetrics * aCopy;
	aCopy = [[(QFontMetrics *)[[self class] allocWithZone: zone] setQt: qt_new_QFontMetrics1([self qt])] init];
	[aCopy setAllocatedInObjcWorld: YES];
	[QtSupport setObject: aCopy forQtKey: [aCopy qt]];
	return aCopy;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld]) {
			qt_del_QFontMetrics((qt_QFontMetrics *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (int) ascent
{
	return (int) qt_QFontMetrics_ascent((qt_QFontMetrics *)[self qt]);
}

- (int) descent
{
	return (int) qt_QFontMetrics_descent((qt_QFontMetrics *)[self qt]);
}

- (int) height
{
	return (int) qt_QFontMetrics_height((qt_QFontMetrics *)[self qt]);
}

- (int) leading
{
	return (int) qt_QFontMetrics_leading((qt_QFontMetrics *)[self qt]);
}

- (int) lineSpacing
{
	return (int) qt_QFontMetrics_lineSpacing((qt_QFontMetrics *)[self qt]);
}

- (int) minLeftBearing
{
	return (int) qt_QFontMetrics_minLeftBearing((qt_QFontMetrics *)[self qt]);
}

- (int) minRightBearing
{
	return (int) qt_QFontMetrics_minRightBearing((qt_QFontMetrics *)[self qt]);
}

- (int) maxWidth
{
	return (int) qt_QFontMetrics_maxWidth((qt_QFontMetrics *)[self qt]);
}

- (BOOL) inFont: (unichar *)arg1
{
	return (BOOL) qt_QFontMetrics_inFont((qt_QFontMetrics *)[self qt], (qt_QChar*)arg1);
}

- (int) leftBearing: (unichar *)arg1
{
	return (int) qt_QFontMetrics_leftBearing((qt_QFontMetrics *)[self qt], (qt_QChar*)arg1);
}

- (int) rightBearing: (unichar *)arg1
{
	return (int) qt_QFontMetrics_rightBearing((qt_QFontMetrics *)[self qt], (qt_QChar*)arg1);
}

- (int) width: (NSString *)arg1 len: (int)len
{
static qt_QString * _qstring_arg1 = 0L;
	return (int) qt_QFontMetrics_width((qt_QFontMetrics *)[self qt], (qt_QString *) [arg1 toQString: &_qstring_arg1], (int)len);
}

- (int) width: (NSString *)arg1 
{
static qt_QString * _qstring_arg1 = 0L;
	return (int) qt_QFontMetrics_width((qt_QFontMetrics *)[self qt], (qt_QString *) [arg1 toQString: &_qstring_arg1], -1);
}

- (int) unicharWidth: (unichar *)arg1
{
	return (int) qt_QFontMetrics_width1((qt_QFontMetrics *)[self qt], (qt_QChar*)arg1);
}

- (int) charWidth: (char)c
{
	return (int) qt_QFontMetrics_width2((qt_QFontMetrics *)[self qt], (char)c);
}

- (int) charWidth: (NSString *)str pos: (int)pos
{
static qt_QString * _qstring_str = 0L;
	return (int) qt_QFontMetrics_charWidth((qt_QFontMetrics *)[self qt], (qt_QString *) [str toQString: &_qstring_str], (int)pos);
}

- (QRect*) boundingRect: (NSString *)arg1 len: (int)len
{
static qt_QString * _qstring_arg1 = 0L;
	return (QRect*) [QtSupport objectForQtKey: qt_QFontMetrics_boundingRect((qt_QFontMetrics *)[self qt], (qt_QString *) [arg1 toQString: &_qstring_arg1], (int)len) withClass: [QRect class] allocatedInObjcWorld: YES];
}

- (QRect*) boundingRect: (NSString *)arg1 
{
static qt_QString * _qstring_arg1 = 0L;
	return (QRect*) [QtSupport objectForQtKey: qt_QFontMetrics_boundingRect((qt_QFontMetrics *)[self qt], (qt_QString *) [arg1 toQString: &_qstring_arg1], -1) withClass: [QRect class] allocatedInObjcWorld: YES];
}

- (QRect*) unicharBoundingRect: (unichar *)arg1
{
	return (QRect*) [QtSupport objectForQtKey: qt_QFontMetrics_boundingRect1((qt_QFontMetrics *)[self qt], (qt_QChar*)arg1) withClass: [QRect class] allocatedInObjcWorld: YES];
}

//- (QRect*) boundingRect: (int)x y: (int)y w: (int)w h: (int)h flags: (int)flags str: (NSString *)str len: (int)len tabstops: (int)tabstops tabarray: (int*)tabarray intern: (QTextParag**)intern
//{
//static qt_QString * _qstring_str = 0L;
//	return (QRect*) [QtSupport objectForQtKey: qt_QFontMetrics_boundingRect2((qt_QFontMetrics *)[self qt], (int)x, (int)y, (int)w, (int)h, (int)flags, (qt_QString *) [str toQString: &_qstring_str], (int)len, (int)tabstops, (int*)tabarray, (qt_QTextParag**) [intern qt]) withClass: [QRect class] allocatedInObjcWorld: YES];
//}

//- (QRect*) boundingRect: (int)x y: (int)y w: (int)w h: (int)h flags: (int)flags str: (NSString *)str
//{
//static qt_QString * _qstring_str = 0L;
//	return (QRect*) [QtSupport objectForQtKey: qt_QFontMetrics_boundingRect2((qt_QFontMetrics *)[self qt], (int)x, (int)y, (int)w, (int)h, (int)flags, (qt_QString *) [str toQString: &_qstring_str], -1, 0, 0, 0) withClass: [QRect class] allocatedInObjcWorld: YES];
//}

//- (QSize*) size: (int)flags str: (NSString *)str len: (int)len tabstops: (int)tabstops tabarray: (int*)tabarray intern: (QTextParag**)intern
//{
//static qt_QString * _qstring_str = 0L;
//	return (QSize*) [QtSupport objectForQtKey: qt_QFontMetrics_size((qt_QFontMetrics *)[self qt], (int)flags, (qt_QString *) [str toQString: &_qstring_str], (int)len, (int)tabstops, (int*)tabarray, (qt_QTextParag**) [intern qt]) withClass: [QSize class] allocatedInObjcWorld: YES];
//}

//- (QSize*) size: (int)flags str: (NSString *)str
//{
//static qt_QString * _qstring_str = 0L;
//	return (QSize*) [QtSupport objectForQtKey: qt_QFontMetrics_size((qt_QFontMetrics *)[self qt], (int)flags, (qt_QString *) [str toQString: &_qstring_str], -1, 0, 0, 0) withClass: [QSize class] allocatedInObjcWorld: YES];
//}

- (int) underlinePos
{
	return (int) qt_QFontMetrics_underlinePos((qt_QFontMetrics *)[self qt]);
}

- (int) strikeOutPos
{
	return (int) qt_QFontMetrics_strikeOutPos((qt_QFontMetrics *)[self qt]);
}

- (int) lineWidth
{
	return (int) qt_QFontMetrics_lineWidth((qt_QFontMetrics *)[self qt]);
}

@end
