// // MPLayout.h // MathPad // // Created by Kim Wittenburg on 07.08.14. // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // #define kMPEmptyBoxWidth (self.usesSmallSize ? 2.0 : 3.0) #define kMPEmptyBoxHeight (CTFontGetDescent((CTFontRef)self.font) + CTFontGetAscent((CTFontRef)self.font) + CTFontGetLeading((CTFontRef)self.font)) #define kMPEmptyBoxYOrigin (-(CTFontGetDescent((CTFontRef)self.font) + CTFontGetLeading((CTFontRef)self.font))) #define kMPEmptyBoxDrawingWidth kMPEmptyBoxWidth #define kMPEmptyBoxDrawingHeight (CTFontGetDescent((CTFontRef)self.font) + CTFontGetAscent((CTFontRef)self.font)) #define kMPEmptyBoxDrawingYOrigin (-(CTFontGetDescent((CTFontRef)self.font) + CTFontGetLeading((CTFontRef)self.font)/2)) @class MPLayout, MPRangePath; @interface MPLayout : NSObject #pragma mark Creation Methods - (instancetype)init; - (instancetype)initWithParent:(MPLayout *)parent; #pragma mark Properties - (NSFont *)font; - (CGFloat)fontSize; - (NSFont *)normalFont; - (CGFloat)normalFontSize; - (NSFont *)smallFont; - (CGFloat)smallFontSize; #pragma mark Cache Tree @property (readonly, nonatomic, weak) MPLayout *parent; #pragma mark Cache Methods // Querying Caches - (id)cachableObjectForIndex:(NSUInteger)index generator:(id(^)())generator; // Clearing Caches - (void)clearCacheInRange:(NSRange)range replacementLength:(NSUInteger)replacementLength; - (void)invalidate; - (MPLayout *)childLayoutAtIndexPath:(NSIndexPath *)indexPath; #pragma mark Calculation and Drawing Methods - (CTLineRef)createLineForString:(NSString *)aString; - (CTLineRef)createLineForString:(NSString *)aString emphasize:(BOOL)emphasize; - (CTLineRef)createLineForString:(NSString *)aString usingFont:(NSFont *)font; @property (nonatomic, getter = isFlipped) BOOL flipped; @property (nonatomic) BOOL usesSmallSize; - (NSRect)bounds; - (NSRect)boundingRectForRangePath:(MPRangePath *)rangePath; /* if rangePath.length is 0 the returned rect will have a width of 0 */ - (void)drawAtPoint:(NSPoint)point; @end @interface MPLayout (MPSubclassImplement) - (NSUInteger)numberOfChildren; - (BOOL)drawsChildrenManually; - (MPLayout *)childLayoutAtIndex:(NSUInteger)index; // To be implemented - (NSRect)generateBounds; // To be implemented - (NSRect)boundingRectForRange:(NSRange)range; // To be implemented, use rangePath instead, this one has wrong origin - (NSPoint)offsetOfChildLayoutAtIndex:(NSUInteger)index; - (NSIndexPath *)indexPathForMousePoint:(NSPoint)point; - (void)draw; // To be implemented @end