Permalink
Browse files

Correct image size of local images if one dimension of display size i…

…s missing.

Previously if either width or height was missing then the original image size was used. Now the missing dimension is scaled proportionally. Closes #235
  • Loading branch information...
1 parent 233ffc5 commit 5ba2316b16b58fb4dcb22e27515c8358cada39ff @odrobnik odrobnik committed Oct 30, 2012
Showing with 12 additions and 1 deletion.
  1. +12 −1 Core/Source/DTTextAttachment.m
@@ -137,10 +137,21 @@ + (DTTextAttachment *)textAttachmentWithElement:(DTHTMLElement *)element options
DTImage *image = [[DTImage alloc] initWithContentsOfFile:[contentURL path]];
originalSize = image.size;
- if (!displaySize.width || !displaySize.height)
+ // width and/or height missing
+ if (displaySize.width==0 && displaySize.height==0)
{
displaySize = originalSize;
}
+ else if (!displaySize.width && displaySize.height)
+ {
+ CGFloat factor = image.size.height / displaySize.height;
+ displaySize.width = roundf(image.size.width / factor);
+ }
+ else if (displaySize.width>0 && displaySize.height==0)
+ {
+ CGFloat factor = image.size.width / displaySize.width;
+ displaySize.height = roundf(image.size.height / factor);
+ }
}
else
{

0 comments on commit 5ba2316

Please sign in to comment.