Permalink
Browse files

adjust subview frame for custom subview and image drawing

if the image is not baseline aligned then the subview frame is different then the run frame.
  • Loading branch information...
1 parent 300a8d8 commit 491333e95c1f2bfdb1d083e394ab9bb7cd7ffab9 @odrobnik odrobnik committed Apr 18, 2012
Showing with 18 additions and 2 deletions.
  1. +13 −1 Core/Source/DTAttributedTextContentView.m
  2. +5 −1 Core/Source/DTCoreTextLayoutFrame.m
View
14 Core/Source/DTAttributedTextContentView.m
@@ -219,7 +219,19 @@ - (void)layoutSubviewsInRect:(CGRect)rect
else
{
// individual glyph run
- frameForSubview = oneRun.frame;
+
+ if (attachment)
+ {
+ // frame might be different due to image vertical alignment
+ CGFloat ascender = [attachment ascentForLayout];
+ CGFloat descender = [attachment descentForLayout];
+
+ frameForSubview = CGRectMake(oneRun.frame.origin.x, oneLine.baselineOrigin.y - ascender, oneRun.frame.size.width, ascender+descender);
+ }
+ else
+ {
+ frameForSubview = oneRun.frame;
+ }
}
if (CGRectIsEmpty(frameForSubview))
View
6 Core/Source/DTCoreTextLayoutFrame.m
@@ -975,8 +975,12 @@ - (void)drawInContext:(CGContextRef)context drawImages:(BOOL)drawImages
{
DTImage *image = (id)attachment.contents;
+ // frame might be different due to image vertical alignment
+ CGFloat ascender = [attachment ascentForLayout];
+ CGFloat descender = [attachment descentForLayout];
+
CGPoint origin = oneRun.frame.origin;
- origin.y = self.frame.size.height - origin.y - oneRun.ascent;
+ origin.y = self.frame.size.height - origin.y - ascender - descender;
CGRect flippedRect = CGRectMake(roundf(origin.x), roundf(origin.y), attachment.displaySize.width, attachment.displaySize.height);
CGContextDrawImage(context, flippedRect, image.CGImage);

0 comments on commit 491333e

Please sign in to comment.