Skip to content

Commit

Permalink
deprecated method and replaced with one with options bit mask
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Mar 21, 2013
1 parent 45d0ce0 commit 80826ca
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
17 changes: 15 additions & 2 deletions Core/Source/DTAttributedTextContentView.m
Expand Up @@ -408,8 +408,21 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx

DTCoreTextLayoutFrame *theLayoutFrame = self.layoutFrame; // this is synchronized

// construct drawing options
DTCoreTextLayoutFrameDrawingOptions options = DTCoreTextLayoutFrameDrawingDefault;

if (!_shouldDrawImages)
{
options |= DTCoreTextLayoutFrameDrawingOmitAttachments;
}

if (!_shouldDrawImages)
{
options |= DTCoreTextLayoutFrameDrawingOmitLinks;
}

// need to prevent updating of string and drawing at the same time
[theLayoutFrame drawInContext:ctx drawImages:_shouldDrawImages drawLinks:_shouldDrawLinks];
[theLayoutFrame drawInContext:ctx options:options];

if (_delegateFlags.delegateSupportsNotificationAfterDrawing)
{
Expand All @@ -420,7 +433,7 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layoutFrame drawInContext:context drawImages:YES drawLinks:YES];
[self.layoutFrame drawInContext:context options:DTCoreTextLayoutFrameDrawingDefault];
}

- (void)relayoutText
Expand Down
32 changes: 29 additions & 3 deletions Core/Source/DTCoreTextLayoutFrame.h
Expand Up @@ -22,6 +22,15 @@

typedef void (^DTCoreTextLayoutFrameTextBlockHandler)(DTTextBlock *textBlock, CGRect frame, CGContextRef context, BOOL *shouldDrawDefaultBackground);

// the drawing options
typedef enum
{
DTCoreTextLayoutFrameDrawingDefault = 1<<0,
DTCoreTextLayoutFrameDrawingOmitLinks = 1<<1,
DTCoreTextLayoutFrameDrawingOmitAttachments = 1<<2,
DTCoreTextLayoutFrameDrawingDrawLinksHighlighted = 1<<3
} DTCoreTextLayoutFrameDrawingOptions;


@class DTCoreTextLayouter;

Expand Down Expand Up @@ -113,14 +122,31 @@ typedef void (^DTCoreTextLayoutFrameTextBlockHandler)(DTTextBlock *textBlock, CG


/**
Draws the entire layout frame into the given graphics context.
Draws the receiver into the given graphics context.
@warning This method is deprecated, use -[DTCoreTextLayoutFrame drawInContext:options:] instead
@param context A graphics context to draw into
@param drawImages Whether images should be drawn together with the text. If you specify `NO` then space is left blank where images would go and you have to add your own views to display these images.
@param drawLinks Whether hyperlinks should be drawn together with the text. If you specify `NO` then space is left blank where links would go and you have to add your own views to display these images.
@param drawImages Whether hyperlinks should be drawn together with the text. If you specify `NO` then space is left blank where links would go and you have to add your own views to display these links.
*/
- (void)drawInContext:(CGContextRef)context drawImages:(BOOL)drawImages drawLinks:(BOOL)drawLinks;
- (void)drawInContext:(CGContextRef)context drawImages:(BOOL)drawImages drawLinks:(BOOL)drawLinks __attribute__((deprecated("use -[DTCoreTextLayoutFrame drawInContext:options:] instead")));


/**
Draws the receiver into the given graphics context.
Possible options are the following, you may combine them with a binary OR.
- DTCoreTextLayoutFrameDrawingDefault or 0
- DTCoreTextLayoutFrameDrawingOmitLinks
- DTCoreTextLayoutFrameDrawingOmitAttachments
- DTCoreTextLayoutFrameDrawingDrawLinksHighlighted
@param context A graphics context to draw into
@param options The drawing options. Use DTCoreTextLayoutFrameDrawingDefault or 0 to draw everything
*/
- (void)drawInContext:(CGContextRef)context options:(DTCoreTextLayoutFrameDrawingOptions)options;


/**
Expand Down
21 changes: 21 additions & 0 deletions Core/Source/DTCoreTextLayoutFrame.m
Expand Up @@ -822,6 +822,27 @@ - (void)_drawHorizontalRuleFromLine:(DTCoreTextLayoutLine *)line inContext:(CGCo

- (void)drawInContext:(CGContextRef)context drawImages:(BOOL)drawImages drawLinks:(BOOL)drawLinks
{
DTCoreTextLayoutFrameDrawingOptions options = DTCoreTextLayoutFrameDrawingDefault;

if (!drawImages)
{
options |= DTCoreTextLayoutFrameDrawingOmitAttachments;
}

if (!drawLinks)
{
options |= DTCoreTextLayoutFrameDrawingOmitLinks;
}

[self drawInContext:context options:options];
}


- (void)drawInContext:(CGContextRef)context options:(DTCoreTextLayoutFrameDrawingOptions)options
{
BOOL drawLinks = !(options & DTCoreTextLayoutFrameDrawingOmitLinks);
BOOL drawImages = !(options & DTCoreTextLayoutFrameDrawingOmitAttachments);

CGRect rect = CGContextGetClipBoundingBox(context);

if (!context)
Expand Down

0 comments on commit 80826ca

Please sign in to comment.