Epub阅读器0.0.1
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
//
|
||||
// DTHTMLAttributedStringBuilder.h
|
||||
// DTCoreText (WeRead custom fork)
|
||||
//
|
||||
// Reverse-engineered from WeChat Reading (微信读书) binary.
|
||||
// This class converts HTML DOM into NSAttributedString via SAX-style parsing.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class DTHTMLParserDelegate;
|
||||
@class DTHTMLElement;
|
||||
@class DTCSSStylesheet;
|
||||
@class DTCoreTextFontDescriptor;
|
||||
@class DTCoreTextParagraphStyle;
|
||||
@class WRBook;
|
||||
@class WRChapter;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// WeRead custom NSAttributedString attribute keys
|
||||
// ---------------------------------------------------------------------------
|
||||
// These keys are used in the resulting attributed string to carry page layout
|
||||
// and presentation metadata that goes beyond standard DTCoreText attributes.
|
||||
|
||||
extern NSString *const DTPageBackgroundColorAttribute;
|
||||
extern NSString *const DTPageBackgroundImageAttribute;
|
||||
extern NSString *const DTPageBackgroundImagePathAttribute;
|
||||
extern NSString *const DTPageBreakAfterAttribute;
|
||||
extern NSString *const DTPageBreakBeforeAttribute;
|
||||
extern NSString *const DTPageBreakInsideAvoidAttribute;
|
||||
extern NSString *const DTPageRelateAttribute;
|
||||
extern NSString *const DTPageSize;
|
||||
extern NSString *const DTPageFlippingStyle;
|
||||
extern NSString *const DTHTMLVerticalCenterAttribute;
|
||||
extern NSString *const DTHTMLTranslateTagAttribute;
|
||||
extern NSString *const DTHTMLTranslateNoStyleAttribute;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// DTHTMLAttributedStringBuilder
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@interface DTHTMLAttributedStringBuilder : NSObject
|
||||
|
||||
// --- Initializers ---
|
||||
|
||||
/**
|
||||
Designated initializer.
|
||||
@param htmlData Raw HTML data (UTF-8 encoded).
|
||||
@param options Dictionary of build options (base URL, CSS stylesheet, etc.).
|
||||
*/
|
||||
- (instancetype)initWithHTML:(NSData *)htmlData
|
||||
options:(NSDictionary *)options;
|
||||
|
||||
/**
|
||||
Convenience initializer that also supplies a CSS stylesheet.
|
||||
*/
|
||||
- (instancetype)initWithHTML:(NSData *)htmlData
|
||||
cssStyleSheet:(DTCSSStylesheet *)styleSheet
|
||||
options:(NSDictionary *)options;
|
||||
|
||||
// --- Building ---
|
||||
|
||||
/**
|
||||
Triggers the full HTML parse → DOM tree → NSAttributedString pipeline.
|
||||
Must be called before -generatedAttributedString.
|
||||
*/
|
||||
- (void)buildString;
|
||||
|
||||
/**
|
||||
Returns the attributed string produced by the most recent -buildString call.
|
||||
*/
|
||||
- (NSAttributedString *)generatedAttributedString;
|
||||
|
||||
// --- DTHTMLParser delegate (SAX callbacks) ---
|
||||
|
||||
- (void)parser:(id)parser
|
||||
didStartElement:(NSString *)elementName
|
||||
attributes:(NSDictionary *)attributeDict
|
||||
position:(NSUInteger)position;
|
||||
|
||||
- (void)parser:(id)parser
|
||||
foundCDATA:(NSData *)CDATABlock;
|
||||
|
||||
- (void)parser:(id)parser
|
||||
foundCharacters:(NSString *)string
|
||||
position:(NSUInteger)position;
|
||||
|
||||
- (void)parserDidEndDocument:(id)parser;
|
||||
|
||||
// --- Tag handler registration (internal) ---
|
||||
|
||||
- (void)_registerTagStartHandlers;
|
||||
- (void)_registerTagEndHandlers;
|
||||
|
||||
// --- Properties ---
|
||||
|
||||
@property (nonatomic, strong, readonly) NSData *htmlData;
|
||||
@property (nonatomic, strong, readonly) DTCSSStylesheet *cssStyleSheet;
|
||||
@property (nonatomic, strong, readonly) NSDictionary *options;
|
||||
@property (nonatomic, strong, readonly) NSAttributedString *generatedAttributedString;
|
||||
|
||||
// WeRead-specific: the book / chapter context used during rendering.
|
||||
@property (nonatomic, strong) WRBook *book;
|
||||
@property (nonatomic, strong) WRChapter *chapter;
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user