ReadViewSDK/Doc/WXRead/decompiled/DTCoreTextLayouter.h
2026-05-21 19:40:51 +08:00

126 lines
3.3 KiB
Objective-C

//
// DTCoreTextLayouter.h
// WeRead
//
// Reverse-engineered from binary analysis
// Based on DTCoreText open-source library, customized by WeRead
//
// DTCoreText is an open-source library for rendering HTML with CoreText.
// WeRead has customized it for their reading engine.
//
#import <Foundation/Foundation.h>
#import <CoreText/CoreText.h>
@class DTCoreTextLayoutFrame;
@class NSAttributedString;
NS_ASSUME_NONNULL_BEGIN
/**
* DTCoreTextLayouter - CoreText typesetter wrapper.
*
* This is the original DTCoreText layouter class, customized by WeRead.
* It wraps CTTypesetter and CTFramesetter to provide high-level
* text layout functionality.
*
* Key features:
* - Creates CTTypesetter from attributed string
* - Manages typesetter lifecycle
* - Produces DTCoreTextLayoutFrame objects
* - Supports caching of layout frames
* - Handles string updates efficiently
*/
@interface DTCoreTextLayouter : NSObject
#pragma mark - Properties
/** The attributed string to be laid out */
@property (nonatomic, strong, nullable) NSAttributedString *attributedString;
/** Cache for layout frames */
@property (nonatomic, strong, readonly) NSCache *layoutFrameCache;
/** Array of created layout frames */
@property (nonatomic, strong, readonly) NSMutableArray<DTCoreTextLayoutFrame *> *layoutFrames;
#pragma mark - Initialization
/**
* Initialize with an attributed string.
*
* @param attributedString The text with styling attributes
* @return Initialized layouter instance
*/
- (instancetype)initWithAttributedString:(NSAttributedString *)attributedString;
#pragma mark - Typesetter Management
/**
* Returns the internal CTTypesetter.
* Creates one if it doesn't exist.
*
* @return The CTTypesetter reference
*/
- (CTTypesetterRef)typesetter;
/**
* Invalidates the current typesetter.
* Called when the attributed string changes.
*/
- (void)invalidateTypesetter;
#pragma mark - Layout Frame Creation
/**
* Create a layout frame for a given string range within the specified rect.
*
* @param range The range of the attributed string to lay out
* @param frame The bounding rectangle for the layout
* @return A new DTCoreTextLayoutFrame
*/
- (DTCoreTextLayoutFrame *)layoutFrameWithRange:(NSRange)range
frame:(CGRect)frame;
/**
* Suggest a line break for the given range and width.
*
* @param startIndex The starting index
* @param width The available width
* @return The suggested line break index
*/
- (NSUInteger)suggestLineBreakStartIndex:(NSUInteger)startIndex
width:(CGFloat)width;
/**
* Suggest a fitting string length for pagination.
*
* @param startIndex The starting index
* @param constraints Size constraints
* @return The suggested fitting length
*/
- (NSUInteger)stringIndexFittingLengthForWidth:(CGFloat)width
startIndex:(NSUInteger)startIndex;
#pragma mark - Frame Caching
/**
* Returns a cached layout frame for the given key.
*/
- (nullable DTCoreTextLayoutFrame *)cachedLayoutFrameForKey:(NSString *)key;
/**
* Caches a layout frame with the given key.
*/
- (void)cacheLayoutFrame:(DTCoreTextLayoutFrame *)frame
forKey:(NSString *)key;
/**
* Clears the layout frame cache.
*/
- (void)clearLayoutFrameCache;
@end
NS_ASSUME_NONNULL_END