//
//  GSPDFReader.h
//  GlyphsCore
//
//  Created by Georg Seifert on 20.09.21.
//  Copyright © 2021 Georg Seifert. All rights reserved.
//

NS_ASSUME_NONNULL_BEGIN

@class GSPDFReader;

NSData *CompressZ(NSData *sourceData);
NSData *DecompressZ(NSData *sourceData);

typedef NS_ENUM(uint8_t, GSPDFObjectType) {
	GSPDFObjectTypePage, // pages, mediabox …
	GSPDFObjectTypeProcSet, // pages, mediabox …
	GSPDFObjectTypeContent, // the actual drawings
	GSPDFObjectTypeProfileStream, // << /N 1 /Alternate /DeviceGray /Length 3385 /Filter /FlateDecode >>
	GSPDFObjectTypeProfile, // [ /ICCBased 7 0 R ]
	GSPDFObjectTypeInfo, // << /Producer
	GSPDFObjectTypeCatalog, // /Catalog
	GSPDFObjectTypeImage, // /Subtype /Image
	GSPDFObjectTypeFree, // << /Producer
};

@interface GSPDFObject : NSObject

- (instancetype)initWithData:(NSData *)data;

@property (nonatomic, weak) GSPDFReader *document;

@property (nonatomic, strong, nullable) NSData *content;

@property (nonatomic, readonly) NSString *contentString;

@property (nonatomic) NSUInteger index;

@property (nonatomic) NSUInteger offset;

@property (nonatomic, readonly) NSUInteger writtenOffset;

@property (nonatomic, readonly) GSPDFObjectType objectType;

- (void)setFree;

@end

@interface GSPDFReader : NSObject

@property (nonatomic, strong) NSMutableArray <GSPDFObject *> *objects;

@property (nonatomic, strong) NSString *version;

- (instancetype)initWithContentsOfURL:(NSURL *)url;

- (BOOL)writeToURL:(NSURL *)url error:(NSError **)error;

- (NSData *)composeData;

- (void)slimFit;

- (BOOL)deflate;

- (BOOL)inflate;

@end

NS_ASSUME_NONNULL_END
