Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 164 lines (133 sloc) 4.184 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
//
// DTCoreTextLayoutLine.h
// CoreTextExtensions
//
// Created by Oliver Drobnik on 1/24/11.
// Copyright 2011 Drobnik.com. All rights reserved.
//


#if TARGET_OS_IPHONE
#import <CoreText/CoreText.h>
#elif TARGET_OS_MAC
#import <ApplicationServices/ApplicationServices.h>
#endif

@class DTCoreTextLayoutFrame;

/**
This class represents one layouted line and contains a number of glyph runs.
*/
@interface DTCoreTextLayoutLine : NSObject
{
NSInteger _stringLocationOffset; // offset to modify internal string location to get actual location
}

/**
@name Creating Layout Lines
*/

/**
Creates a layout line from a given `CTLine`
@param line The Core Text line to wrap
@returns A prepared layout line
*/
- (id)initWithLine:(CTLineRef)line;

/**
@name Drawing Layout Lines
*/

/**
Draws the receiver in a given graphics context
@param context The graphics context to draw into
*/
- (void)drawInContext:(CGContextRef)context;

/**
@name Getting Information about Layout Lines
*/

/**
The range in the original string that is represented by the receiver
@returns The string strange
*/
- (NSRange)stringRange;

/**
The number of glyphs the receiver consists of
@returns the number of glyphs
*/
- (NSInteger)numberOfGlyphs;

/**
Determines the frame of a specific glyph
@param index The index of the glyph
@return The frame of the glyph
*/
- (CGRect)frameOfGlyphAtIndex:(NSInteger)index;

/**
Retrieves the glyphRuns with a given range
@param range The range
@returns An array of glyph runs
*/
- (NSArray *)glyphRunsWithRange:(NSRange)range;

/**
The frame of a number of glyphs with a given range
@param range The range
@returns The rectangle containing the result
*/
- (CGRect)frameOfGlyphsWithRange:(NSRange)range;

/**
The bounds of an image encompassing the entire run.
@param context The graphics context used for the measurement
@returns The rectangle containing the result
*/
- (CGRect)imageBoundsInContext:(CGContextRef)context;

/**
The string indices of the receiver
@returns An array of string indices
*/
- (NSArray *)stringIndices;

/**
Determins the graphical offset for a given string index
@param index The string index
@returns The offset
*/
- (CGFloat)offsetForStringIndex:(NSInteger)index;

/**
Determines the string index that is closest to a given point
@param position The position to determine the string index for
@returns The string index
*/
- (NSInteger)stringIndexForPosition:(CGPoint)position;

/**
The frame of the receiver relative to the layout frame
*/
@property (nonatomic, assign) CGRect frame;

/**
The glyph runs that the line contains.
*/
@property (nonatomic, readonly) NSArray *glyphRuns;

/**
The ascent (height above the baseline) of the receiver
*/
@property (nonatomic, assign) CGFloat ascent; // needs to be modifyable

/**
The descent (height below the baseline) of the receiver
*/
@property (nonatomic, readonly) CGFloat descent;

/**
The leading (additional space above the ascent) of the receiver
*/
@property (nonatomic, readonly) CGFloat leading;

/**
The width of the traling whitespace of the receiver
*/
@property (nonatomic, readonly) CGFloat trailingWhitespaceWidth;

/**
The baseline origin of the receiver
*/
@property (nonatomic, assign) CGPoint baselineOrigin;

/**
`YES` if the writing direction is Right-to-Left, otherwise `NO`
*/
@property (nonatomic, assign) BOOL writingDirectionIsRightToLeft;


/**
@name Creating Variants
*/

/**
Creates a version of the receiver that is justified to the given width.
@param justificationFactor Full or partial justification. When set to `1.0` or greater, full justification is performed. If this parameter is set to less than `1.0`, varying degrees of partial justification are performed. If it is set to `0` or less, no justification is performed.
@param justificationWidth The width to which the resultant line is justified. If justificationWidth is less than the actual width of the line, then negative justification is performed (that is, glyphs are squeezed together).
*/
- (DTCoreTextLayoutLine *)justifiedLineWithFactor:(CGFloat)justificationFactor justificationWidth:(CGFloat)justificationWidth;

@end
Something went wrong with that request. Please try again.