//
//  XMLReader.h
//  GSFontTools
//
//  Objective-C port of fontTools/xmlReader.py
//

#import <Foundation/Foundation.h>

@class TTFont;

NS_ASSUME_NONNULL_BEGIN

/**
 XMLReader parses a TTX (XML) file and populates a TTFont instance.

 The content of each table element is collected into a nested structure of
 arrays:  each element is represented as an @[name, attrs, content] tuple
 (an NSArray with 3 items), where 'content' is an NSMutableArray that may
 contain further such tuples or plain NSString character-data nodes.
 Once the closing tag of a table-level element is reached,
 -fromXML:attrs:content:font: is called on the corresponding TTTable.
 */
@interface XMLReader : NSObject <NSXMLParserDelegate>

/**
 Initialise with a file-system path and a font object.
 Equivalent to Python's XMLReader(fileOrPath, ttFont).
 */
- (instancetype)initWithPath:(NSString *)path font:(TTFont *)ttFont;

/**
 Designated initialiser.
 @param contentOnly  When YES the parser skips the outermost table element and
                     starts collecting from the first child, mirroring the
                     Python 'contentOnly' flag used for sub-file reading.
 */
- (instancetype)initWithPath:(NSString *)path
                        font:(TTFont *)ttFont
                 contentOnly:(BOOL)contentOnly NS_DESIGNATED_INITIALIZER;

- (instancetype)init NS_UNAVAILABLE;

/** Parse the file.  Equivalent to Python's XMLReader.read(). */
- (void)read;

/**
 Parse the file, optionally treating it as if we are already inside the root
 element.  Mirrors Python's XMLReader.read(rootless=True).
 */
- (void)readRootless:(BOOL)rootless;

@end

NS_ASSUME_NONNULL_END
