Epub阅读器0.0.1
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// WRChapterPageCount.h
|
||||
// WeRead (微信读书)
|
||||
//
|
||||
// Reverse-engineered header reconstruction.
|
||||
// Pagination calculator. Manages NSRange for each page within a chapter.
|
||||
// Computes page breaks based on the typeset attributed string and the
|
||||
// available drawing area.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// ============================================================================
|
||||
#pragma mark - WRChapterPageCount
|
||||
// ============================================================================
|
||||
|
||||
@interface WRChapterPageCount : NSObject
|
||||
|
||||
// ---- Ivars from binary: NSString, NSString, NSString, NSArray ----
|
||||
|
||||
/// The book identifier this page count data belongs to.
|
||||
@property (nonatomic, copy, nullable) NSString *bookId;
|
||||
|
||||
/// The chapter identifier.
|
||||
@property (nonatomic, copy, nullable) NSString *chapterId;
|
||||
|
||||
/// A cache key string combining book and chapter info for disk caching.
|
||||
@property (nonatomic, copy, nullable) NSString *cacheKey;
|
||||
|
||||
/// Array of NSValue-wrapped NSRange values, one per page.
|
||||
/// Each range is a character range within the chapter's attributed string.
|
||||
@property (nonatomic, strong, nullable) NSArray<NSValue *> *pageRanges;
|
||||
|
||||
/// Total number of pages in this chapter.
|
||||
@property (nonatomic, assign, readonly) NSUInteger totalPages;
|
||||
|
||||
// ============================================================================
|
||||
#pragma mark - Class Methods
|
||||
// ============================================================================
|
||||
|
||||
/// Generates a cache key string for storing/retrieving pagination data
|
||||
/// for the given book. The key encodes the book ID and current typesetter
|
||||
/// settings (font size, line spacing, etc.) so pagination is invalidated
|
||||
/// when settings change.
|
||||
///
|
||||
/// @param bookId The book identifier.
|
||||
/// @return A unique cache key string, e.g., @"weread_pagcount_{bookId}_{fontSize}_{lineSpacing}".
|
||||
+ (NSString *)currentCacheKeyWithBookId:(NSString *)bookId;
|
||||
|
||||
/// Calculates the page ranges from a page info dictionary.
|
||||
/// The page info dictionary typically comes from the server or from local
|
||||
/// layout computation and contains raw range data.
|
||||
///
|
||||
/// @param pageInfo Dictionary with pagination data (e.g., @"ranges" key containing
|
||||
/// an array of {location, length} dictionaries).
|
||||
/// @return An array of NSValue-wrapped NSRange values.
|
||||
+ (NSArray<NSValue *> *)rangeValueWithPageInfo:(NSDictionary *)pageInfo;
|
||||
|
||||
// ============================================================================
|
||||
#pragma mark - Instance Methods
|
||||
// ============================================================================
|
||||
|
||||
/// Returns the character range for the specified page index.
|
||||
- (NSRange)rangeForPageAtIndex:(NSUInteger)pageIndex;
|
||||
|
||||
/// Returns the page index that contains the given character index.
|
||||
- (NSUInteger)pageIndexForCharacterIndex:(NSUInteger)charIndex;
|
||||
|
||||
/// Recalculates page ranges for the given attributed string and drawing area.
|
||||
///
|
||||
/// @param attributedString The typeset chapter content.
|
||||
/// @param drawingSize The available drawing area size (points).
|
||||
/// @param margins Content insets / margins.
|
||||
- (void)recalculatePageRangesForAttributedString:(NSAttributedString *)attributedString
|
||||
drawingSize:(CGSize)drawingSize
|
||||
margins:(UIEdgeInsets)margins;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Reference in New Issue
Block a user