//
//  otConverters.h
//  GSFontTools
//
//  Created by Georg Seifert on 13.08.11.
//  Copyright 2011 schriftgestaltung.de. All rights reserved.
//

@class TTFont;
@class OTTableReader;
@class GSXMLWriter;

NSString *nearestMultipleShortestRepr(double value, double factor);

@interface BaseConverter : NSObject
// class BaseConverter:
/*
 Base class for converter objects. Apart from the constructor, this
 is an abstract class.
 */
{
	NSString *_name;
	NSString *_repeat;
	NSString *_elementSize;
	NSUInteger _repeatOffset;
	NSString *_aux;
	BOOL _isCount;
	BOOL _isLookupType;
	BOOL _isPropagated;
}
@property (retain, nonatomic) NSString *name;
@property (retain, nonatomic) NSString *repeat;
@property (retain, nonatomic) NSString *elementSize;
@property (retain, nonatomic) NSString *aux;
@property (nonatomic) NSUInteger repeatOffset;
@property (nonatomic) BOOL isCount;
@property (nonatomic) BOOL isLookupType;
@property (readonly) uint8_t staticSize;

- (instancetype)initWithName:(NSString *)name;

@property (nonatomic) BOOL isPropagated;

// FIXME: The `tableClass` parameter is not actually used!
- (instancetype)initWithName:(NSString *)name repeat:(NSString *)repeat repeatOffset:(NSUInteger)repeatOffset tableClass:(Class)tableClass;

- (id)readWithReader:(OTTableReader *)reader font:(TTFont *)font table:(NSMutableDictionary *)table;

- (void)writeWithWriter:(id)writer font:(TTFont *)font table:(NSDictionary *)table value:(id)value repeatIndex:(NSUInteger)repeatIndex;

- (id)xmlRead:(NSString *)name attrs:(NSDictionary *)attrs content:(id)content font:(id)font;

- (void)xmlWrite:(GSXMLWriter *)writer font:(TTFont *)font value:(id)value name:(NSString *)name attrs:(id)attrs;

- (uint8_t)staticSize;
@end

@interface SimpleValueConverter : BaseConverter
// class SimpleValue(BaseConverter):

- (NSString *)toString:(id)value;
@end

@interface IntValueConverter : SimpleValueConverter
// class IntValue(SimpleValue):
@end

@interface Int32Converter : IntValueConverter
// class Long(IntValue):
@end

@interface UInt32Converter : IntValueConverter
@end

@interface FixedConverter : IntValueConverter
// class Fixed(IntValue):
@end

@interface UInt8Converter : IntValueConverter
@end

@interface Int16Converter : IntValueConverter
// class Short(IntValue):
@end

@interface UInt16Converter : IntValueConverter
// class UShort(IntValue):
@end

@interface UInt24Converter : IntValueConverter
// class UInt24(IntValue):
@end

@interface ComputedUInt8Converter : UInt8Converter
// class ComputedInt(IntValue):
@end

@interface ComputedUInt16Converter : UInt16Converter
// class ComputedInt(IntValue):
@end

@interface ComputedUInt32Converter : UInt32Converter
// class ComputedInt(IntValue):
@end

@interface DeciPointsConverter : IntValueConverter
// class DeciPoints(FloatValue):
@end

@interface CountConverter : UInt16Converter
// class Count(Short):
@end

@interface LCountConverter : UInt32Converter
@end

@interface TagConverter : SimpleValueConverter
// class Tag(SimpleValue):
@end

@interface GlyphIDConverter : SimpleValueConverter
// class GlyphID(SimpleValue):
@end

@interface NameIDConverter : UInt16Converter
// class NameID(UShort):
@end

@interface VarIndexConverter : UInt32Converter
// class VarIndex(OptionalValue, ULong):
@end

@interface StructConverter : BaseConverter {
	// class Struct(BaseConverter):
	// Class _tableClass;
}

@property (retain, nonatomic) Class tableClass;
// class Struct(BaseConverter):

- (instancetype)initWithName:(NSString *)name repeat:(NSString *)repeat repeatOffset:(NSUInteger)repeatOffset tableClass:(Class)tableClass;
@end

@interface TableConverter : StructConverter
// class Table(Struct):
@property (nonatomic) NSUInteger baseOffset;
@end

@interface LTableConverter : TableConverter
@end

@interface Table24Converter : TableConverter
// class Table24(Table):
@end

@interface SubTableConverter : TableConverter
// class SubTable(Table):
- (void)converterForTableType:(NSString *)tableType lookupType:(NSUInteger)lookupType;
@end

@interface ExtSubTableConverter : LTableConverter
// class ExtSubTable(Table):
- (id)converterForTableType:(NSString *)tableType lookupType:(NSUInteger)lookupType;
@end

@interface FeatureParamsConverter : TableConverter
- (BaseConverter *)converterForFeatureTag:(NSString *)featureTag;
@end

@interface ValueFormatConverter : IntValueConverter {
  @public
	int _which;
}

- (instancetype)initWithName:(NSString *)name which:(int)which repeat:(NSString *)repeat;
// class ValueFormat(IntValue):
@end

@interface VarIdxMapValueConverter : ValueFormatConverter
@end

@interface VarDataValueConverter : BaseConverter
@end

@interface ValueRecordConverter : ValueFormatConverter
// class ValueRecord(ValueFormat):
@end

@interface DeltaValueConverter : BaseConverter
// class DeltaValue(BaseConverter):
@end

@interface F2Dot14FloatConverter : SimpleValueConverter // FloatConverter not yet implemented, would only have method ‘xmlRead’
// class F2Dot14(FloatValue):
@end

@interface F2Dot14Converter : SimpleValueConverter // This stores the values as F2dot14 instead of converting it to float to avoid rounding issues.

@end

@interface AngleConverter : F2Dot14FloatConverter

@end

@interface LookupFlagConverter : UInt16Converter
// class LookupFlag(UShort):
@end
