//
//  GSDocument+SerialImport.h
//  Glyphs
//
//  Created by Georg Seifert on 12.09.12.
//  Copyright (c) 2012 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GSFont.h>
#import <GlyphsCore/GSFontMaster.h>
#import <GlyphsCore/GSGlyph.h>
#import <GlyphsCore/GSNode.h>
#import <GlyphsCore/GSPath.h>

#import <GlyphsCore/CFOldStylePList.h>

#ifdef GLYPHS_VIEWER_
// to make the objects link property
extern NSString *SerialImportCategory;
#endif

NS_ASSUME_NONNULL_BEGIN

@interface GSFont (SerialImport)

/// Do no use this method directly. Instead, call `-initWithURL:error:`.
- (nullable instancetype)initWithGlyphsFileAtPath:(NSString *)path error:(out NSError **)outError;

/// Creates a new font object from the given byte buffer representing the contents of a `.glyphs` file.
- (nullable instancetype)initWithData:(NSData *)buffer error:(out NSError **)outError;

#ifndef QUICKLOOK
- (BOOL)convertKerning:(NSError**)error;
#endif

@end

@interface GSGlyph (SerialImport)

/// Creates a glyph by reading a `.glyph` file.
///
/// Returns `nil` when the file cannot be read or its contents are invalid.
///
/// - Parameter filePath: The path to the `.glyph` file.
/// - Parameter format: The Glyphs file format version used to interpret the file.
/// - Parameter error: On failure, an error describing the problem.
- (nullable instancetype)initWithFile:(nonnull NSString *)filePath format:(GSFormatVersion)format error:(out NSError **)error;

/// Creates a glyph from a Glyphs file representation at the current parser position.
///
/// Returns `nil` when the representation is invalid.
///
/// - Parameter pInfo: A parser positioned after the opening dictionary delimiter.
/// - Parameter formatVersion: The Glyphs file format version used to interpret the representation.
- (nullable instancetype)initWithGlyphsParser:(GSPlistParseInfo *)pInfo format:(GSFormatVersion)formatVersion;

@end

@interface GSPath (SerialImport)

/// Creates a path from the Glyphs file representation at the current parser position.
///
/// - Parameter formatVersion: The Glyphs file format version used to interpret the representation.
- (nullable instancetype)initWithGlyphsParser:(GSPlistParseInfo *)pInfo format:(GSFormatVersion)formatVersion;

@end

@interface GSNode (SerialImport)

/// Creates a node from the Glyphs file representation at the current parser position.
///
/// - Parameter formatVersion: The Glyphs file format version used to interpret the representation.
- (nullable instancetype)initWithGlyphsParser:(GSPlistParseInfo *)pInfo format:(GSFormatVersion)formatVersion;

@end

@interface GSFontMaster (SerialImport)

- (nullable instancetype)initWithGlyphsParser:(GSPlistParseInfo *)pInfo format:(GSFormatVersion)formatVersion;

- (BOOL)postRead:(out NSError **)error format:(GSFormatVersion)formatVersion;

@end

NS_ASSUME_NONNULL_END
