Permalink
Browse files

Merge branch 'od/issue_649' into develop

  • Loading branch information...
2 parents 0d556dc + 2a41112 commit 565f5ea94246d623a1fe110a8ea81694a3c1f175 @odrobnik odrobnik committed Nov 15, 2013
@@ -277,10 +277,10 @@ - (void)layoutSubviewsInRect:(CGRect)rect
}
// round frame
- frameForSubview.origin.x = floorf(frameForSubview.origin.x);
- frameForSubview.origin.y = ceilf(frameForSubview.origin.y);
- frameForSubview.size.width = roundf(frameForSubview.size.width);
- frameForSubview.size.height = roundf(frameForSubview.size.height);
+ frameForSubview.origin.x = floor(frameForSubview.origin.x);
+ frameForSubview.origin.y = ceil(frameForSubview.origin.y);
+ frameForSubview.size.width = round(frameForSubview.size.width);
+ frameForSubview.size.height = round(frameForSubview.size.height);
if (CGRectGetMinY(frameForSubview)> CGRectGetMaxY(rect) || CGRectGetMaxY(frameForSubview) < CGRectGetMinY(rect))
{
@@ -350,8 +350,8 @@ - (void)layoutSubviewsInRect:(CGRect)rect
// make sure that the frame height is no less than the line height for hyperlinks
if (frameForSubview.size.height < oneLine.frame.size.height)
{
- frameForSubview.origin.y = truncf(oneLine.frame.origin.y);
- frameForSubview.size.height = ceilf(oneLine.frame.size.height);
+ frameForSubview.origin.y = trunc(oneLine.frame.origin.y);
+ frameForSubview.size.height = ceil(oneLine.frame.size.height);
}
if (existingLinkView)
@@ -366,8 +366,8 @@ - (void)layoutSubviewsInRect:(CGRect)rect
// make sure that the frame height is no less than the line height for hyperlinks
if (frameForSubview.size.height < oneLine.frame.size.height)
{
- frameForSubview.origin.y = truncf(oneLine.frame.origin.y);
- frameForSubview.size.height = ceilf(oneLine.frame.size.height);
+ frameForSubview.origin.y = trunc(oneLine.frame.origin.y);
+ frameForSubview.size.height = ceil(oneLine.frame.size.height);
}
if (_delegateFlags.delegateSupportsCustomViewsForLinks)
@@ -70,8 +70,7 @@
@param matchedSelectors The CSS selectors that caused a match
@returns The merged style dictionary containing only styles which selector matches the element
*/
-- (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element matchedSelectors:(NSSet **)matchedSelectors;
-
+- (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element matchedSelectors:(NSSet **)matchedSelectors ignoreInlineStyle:(BOOL)ignoreInlineStyle;
/**
Returns a dictionary of the styles of the receiver
@@ -660,7 +660,7 @@ - (void)_addStyles:(NSDictionary *)styles withSelector:(NSString *)selector {
#pragma mark Accessing Style Information
-- (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element matchedSelectors:(NSSet **)matchedSelectors
+- (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element matchedSelectors:(NSSet **)matchedSelectors ignoreInlineStyle:(BOOL)ignoreInlineStyle
{
// We are going to combine all the relevant styles for this tag.
// (Note that when styles are applied, the later styles take precedence,
@@ -753,17 +753,20 @@ - (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element match
[tmpMatchedSelectors addObject:idRule];
}
- // Get tag's local style attribute
- NSString *styleString = [element.attributes objectForKey:@"style"];
-
- if ([styleString length])
+ if (!ignoreInlineStyle)
{
- NSMutableDictionary *localStyles = [[styleString dictionaryOfCSSStyles] mutableCopy];
-
- // need to uncompress because otherwise we might get shorthands and non-shorthands together
- [self _uncompressShorthands:localStyles];
+ // Get tag's local style attribute
+ NSString *styleString = [element.attributes objectForKey:@"style"];
- [tmpDict addEntriesFromDictionary:localStyles];
+ if ([styleString length])
+ {
+ NSMutableDictionary *localStyles = [[styleString dictionaryOfCSSStyles] mutableCopy];
+
+ // need to uncompress because otherwise we might get shorthands and non-shorthands together
+ [self _uncompressShorthands:localStyles];
+
+ [tmpDict addEntriesFromDictionary:localStyles];
+ }
}
if ([tmpDict count])
@@ -58,6 +58,12 @@
return NO;
}
+#if TARGET_CPU_ARM64
+ #define DTNSNumberFromCGFloat(x) [NSNumber numberWithDouble:x]
+#else
+ #define DTNSNumberFromCGFloat(x) [NSNumber numberWithFloat:x]
+#endif
+
#endif
@@ -108,4 +114,9 @@
{
return YES;
}
-#endif
+
+ #define DTNSNumberFromCGFloat(x) [NSNumber numberWithDouble:x]
+#endif
+
+// this enables generic ceil, floor, abs, round functions that work for 64 and 32 bit
+#include <tgmath.h>
@@ -53,6 +53,8 @@ extern NSString * const DTDefaultStyleSheet;
extern NSString * const DTUseiOS6Attributes;
extern NSString * const DTWillFlushBlockCallBack;
extern NSString * const DTProcessCustomHTMLAttributes;
+extern NSString * const DTIgnoreInlineStylesOption;
+
// attributed string attribute constants
@@ -26,6 +26,7 @@
NSString * const DTUseiOS6Attributes = @"DTUseiOS6Attributes";
NSString * const DTWillFlushBlockCallBack = @"DTWillFlushBlockCallBack";
NSString * const DTProcessCustomHTMLAttributes = @"DTProcessCustomHTMLAttributes";
+NSString * const DTIgnoreInlineStylesOption = @"DTIgnoreInlineStyles";
// attributed string attribute constants
@@ -415,8 +415,7 @@ - (NSDictionary *)fontAttributes
}
// we need size because that's what makes a font unique, for searching it's ignored anyway
- [tmpDict setObject:[NSNumber numberWithFloat:_pointSize] forKey:(id)kCTFontSizeAttribute];
-
+ [tmpDict setObject:DTNSNumberFromCGFloat(_pointSize) forKey:(id)kCTFontSizeAttribute];
if (_smallCapsFeature)
{
@@ -993,7 +992,7 @@ - (BOOL)UIoptimizedTrait
- (void)setPointSize:(CGFloat)pointSize
{
- _pointSize = roundf(pointSize);
+ _pointSize = round(pointSize);
}
@synthesize fontFamily = _fontFamily;
@@ -47,17 +47,17 @@ CTLineTruncationType DTCTLineTruncationTypeFromNSLineBreakMode(NSLineBreakMode l
CGFloat DTRoundWithContentScale(CGFloat value, CGFloat contentScale)
{
- return roundf(value*contentScale)/contentScale;
+ return round(value*contentScale)/contentScale;
}
CGFloat DTCeilWithContentScale(CGFloat value, CGFloat contentScale)
{
- return ceilf(value*contentScale)/contentScale;
+ return ceil(value*contentScale)/contentScale;
}
CGFloat DTFloorWithContentScale(CGFloat value, CGFloat contentScale)
{
- return floorf(value*contentScale)/contentScale;
+ return floor(value*contentScale)/contentScale;
}
#pragma mark - Alignment Functions
@@ -86,7 +86,7 @@ - (void)dealloc
- (NSString *)description
{
- return [NSString stringWithFormat:@"<%@ glyphs=%d %@>", [self class], [self numberOfGlyphs], NSStringFromCGRect(_frame)];
+ return [NSString stringWithFormat:@"<%@ glyphs=%ld %@>", [self class], (long)[self numberOfGlyphs], NSStringFromCGRect(_frame)];
}
#endif
@@ -25,7 +25,7 @@ @implementation DTCoreTextLayoutFrame
CGFloat _additionalPaddingAtBottom; // when last line in a text block with padding
- int _numberLinesFitInFrame;
+ NSInteger _numberLinesFitInFrame;
DTCoreTextLayoutFrameTextBlockHandler _textBlockHandler;
CGFloat _longestLayoutLineWidth;
@@ -143,7 +143,7 @@ - (CGPoint)_algorithmLegacy_BaselineOriginToPositionLine:(DTCoreTextLayoutLine *
lineOrigin.x = line.baselineOrigin.x;
// origins are rounded
- lineOrigin.y = ceilf(lineOrigin.y);
+ lineOrigin.y = ceil(lineOrigin.y);
return lineOrigin;
@@ -163,7 +163,7 @@ - (CGPoint)_algorithmLegacy_BaselineOriginToPositionLine:(DTCoreTextLayoutLine *
{
// font has no leading, so we fake one (e.g. Helvetica)
CGFloat tmpHeight = line.ascent + line.descent;
- usedLeading = ceilf(0.2f * tmpHeight);
+ usedLeading = ceil(0.2f * tmpHeight);
if (usedLeading>20)
{
@@ -174,7 +174,7 @@ - (CGPoint)_algorithmLegacy_BaselineOriginToPositionLine:(DTCoreTextLayoutLine *
else
{
// make sure that we don't have less than 10% of line height as leading
- usedLeading = ceilf(MAX((line.ascent + line.descent)*0.1f, usedLeading));
+ usedLeading = ceil(MAX((line.ascent + line.descent)*0.1f, usedLeading));
}
if (CTParagraphStyleGetValueForSpecifier(lineParagraphStyle, kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(minLineHeight), &minLineHeight))
@@ -254,7 +254,7 @@ - (CGPoint)_algorithmLegacy_BaselineOriginToPositionLine:(DTCoreTextLayoutLine *
}
// origins are rounded
- lineOrigin.y = ceilf(lineOrigin.y);
+ lineOrigin.y = ceil(lineOrigin.y);
return lineOrigin;
}
@@ -375,7 +375,7 @@ - (CGPoint)_algorithmWebKit_BaselineOriginToPositionLine:(DTCoreTextLayoutLine *
}
// origins are rounded
- baselineOrigin.y = ceilf(baselineOrigin.y);
+ baselineOrigin.y = ceil(baselineOrigin.y);
return baselineOrigin;
}
@@ -544,7 +544,7 @@ - (void)_buildLinesWithTypesetter
if(attribStr == nil)
{
NSRange range;
- int index = oldLineRange.location;
+ NSInteger index = oldLineRange.location;
if (truncationType == kCTLineTruncationEnd)
{
index += (oldLineRange.length > 0 ? oldLineRange.length - 1 : 0);
@@ -891,7 +891,7 @@ - (CGRect)_blockFrameForEffectiveRange:(NSRange)effectiveRange level:(NSUInteger
blockFrame.size.height = CGRectGetMaxY(lastBlockLine.frame) - blockFrame.origin.y;
// top paddings we get from first line
- for (int i = [firstBlockLine.textBlocks count]-1; i>=level;i--)
+ for (NSInteger i = [firstBlockLine.textBlocks count]-1; i>=level;i--)
{
if (i<0)
{
@@ -905,7 +905,7 @@ - (CGRect)_blockFrameForEffectiveRange:(NSRange)effectiveRange level:(NSUInteger
}
// top padding we get from last line
- for (int i = [lastBlockLine.textBlocks count]-1; i>=level;i--)
+ for (NSInteger i = [lastBlockLine.textBlocks count]-1; i>=level;i--)
{
if (i<0)
{
@@ -1118,7 +1118,7 @@ - (void)_drawHorizontalRuleFromLine:(DTCoreTextLayoutLine *)line inContext:(CGCo
CGRect nrect = self.frame;
nrect.origin = line.frame.origin;
nrect.size.height = oneRun.frame.size.height;
- nrect.origin.y = roundf(nrect.origin.y + oneRun.frame.size.height/2.0f)+0.5f;
+ nrect.origin.y = round(nrect.origin.y + oneRun.frame.size.height/2.0f)+0.5f;
DTTextBlock *textBlock = [[oneRun.attributes objectForKey:DTTextBlocksAttribute] lastObject];
@@ -1564,7 +1564,7 @@ - (CGRect)frame
// actual frame is spanned between first and last lines
DTCoreTextLayoutLine *lastLine = [_lines lastObject];
- _frame.size.height = ceilf((CGRectGetMaxY(lastLine.frame) - _frame.origin.y + 1.5f + _additionalPaddingAtBottom));
+ _frame.size.height = ceil((CGRectGetMaxY(lastLine.frame) - _frame.origin.y + 1.5f + _additionalPaddingAtBottom));
}
if (_frame.size.width == CGFLOAT_WIDTH_UNKNOWN)
@@ -1578,7 +1578,7 @@ - (CGRect)frame
maxWidth = MAX(maxWidth, lineWidthFromFrameOrigin);
}
- _frame.size.width = ceilf(maxWidth);
+ _frame.size.width = ceil(maxWidth);
}
return _frame;
@@ -1614,7 +1614,7 @@ - (CGRect)intrinsicContentFrame
}
// extend height same method as frame
- frameOverAllLines.size.height = ceilf(frameOverAllLines.size.height + 1.5f + _additionalPaddingAtBottom);
+ frameOverAllLines.size.height = ceil(frameOverAllLines.size.height + 1.5f + _additionalPaddingAtBottom);
return CGRectIntegral(frameOverAllLines);
}
@@ -14,7 +14,7 @@
#import "NSDictionary+DTCoreText.h"
#import "DTTextBlock.h"
#import "DTCoreTextConstants.h"
-#import <UIKit/UIKit.h>
+#import "DTCoreTextFunctions.h"
@interface DTCoreTextLayoutLine ()
@@ -318,7 +318,7 @@ - (void)_scanGlyphRunsForValues
if (usedFont)
{
- maxOffset = MAX(maxOffset, fabsf(CTFontGetUnderlinePosition(usedFont)));
+ maxOffset = MAX(maxOffset, fabs(CTFontGetUnderlinePosition(usedFont)));
maxFontSize = MAX(maxFontSize, CTFontGetSize(usedFont));
}
@@ -58,7 +58,7 @@ - (DTCoreTextLayoutFrame *)layoutFrameWithRect:(CGRect)frame range:(NSRange)rang
if (_shouldCacheLayoutFrames)
{
- cacheKey = [NSString stringWithFormat:@"%ud-%@-%@", [_attributedString hash], NSStringFromCGRect(frame), NSStringFromRange(range)];
+ cacheKey = [NSString stringWithFormat:@"%lud-%@-%@", (unsigned long)[_attributedString hash], NSStringFromCGRect(frame), NSStringFromRange(range)];
DTCoreTextLayoutFrame *cachedLayoutFrame = [_layoutFrameCache objectForKey:cacheKey];
@@ -323,7 +323,7 @@ - (NSString *)cssStyleRepresentation
if (_lineHeightMultiple && _lineHeightMultiple!=1.0f)
{
- NSNumber *number = [NSNumber numberWithFloat:_lineHeightMultiple];
+ NSNumber *number = DTNSNumberFromCGFloat(_lineHeightMultiple);
[retString appendFormat:@"line-height:%@em;", number];
}
@@ -343,29 +343,29 @@ - (NSString *)cssStyleRepresentation
// Spacing at the bottom
if (_paragraphSpacing!=0.0f)
{
- NSNumber *number = [NSNumber numberWithFloat:_paragraphSpacing];
+ NSNumber *number = DTNSNumberFromCGFloat(_paragraphSpacing);
[retString appendFormat:@"margin-bottom:%@px;", number];
}
// Spacing at the top
if (_paragraphSpacingBefore!=0.0f)
{
- NSNumber *number = [NSNumber numberWithFloat:_paragraphSpacingBefore];
+ NSNumber *number = DTNSNumberFromCGFloat(_paragraphSpacingBefore);
[retString appendFormat:@"margin-top:%@px;", number];
}
// Spacing at the left
if (_headIndent!=0.0f)
{
- NSNumber *number = [NSNumber numberWithFloat:_headIndent];
+ NSNumber *number = DTNSNumberFromCGFloat(_headIndent);
[retString appendFormat:@"margin-left:%@px;", number];
}
// Spacing at the right
if (_tailIndent!=0.0f)
{
// tail indent is negative if from trailing margin
- NSNumber *number = [NSNumber numberWithFloat:-_tailIndent];
+ NSNumber *number = DTNSNumberFromCGFloat(-_tailIndent);
[retString appendFormat:@"margin-right:%@px;", number];
}
@@ -42,6 +42,7 @@ typedef void(^DTHTMLAttributedStringBuilderWillFlushCallback)(DTHTMLElement *);
- DTDefaultStyleSheet: The default style sheet to use
- DTUseiOS6Attributes: use iOS 6 attributes for building (UITextView compatible)
- DTWillFlushBlockCallBack: a block to be executed whenever content is flushed to the output string
+ - DTIgnoreInlineStylesOption: All inline style information is being ignored and only style blocks used
@param data The data in HTML format from which to create the attributed string.
@param options Specifies how the document should be loaded. Contains values described in NSAttributedString(HTML).
@@ -67,6 +67,7 @@ @implementation DTHTMLAttributedStringBuilder
DTHTMLElement *_bodyElement;
DTHTMLElement *_currentTag;
BOOL _ignoreParseEvents; // ignores events from parser after first HTML tag was finished
+ BOOL _ignoreInlineStyles; // ignores style blocks attached on elements
}
- (id)initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary **)docAttributes
@@ -311,6 +312,9 @@ - (BOOL)_buildString
_shouldProcessCustomHTMLAttributes = [[_options objectForKey:DTProcessCustomHTMLAttributes] boolValue];
+ // ignore inline styles if option is passed
+ _ignoreInlineStyles = [[_options objectForKey:DTIgnoreInlineStylesOption] boolValue];
+
// create a parser
DTHTMLParser *parser = [[DTHTMLParser alloc] initWithData:_data encoding:encoding];
parser.delegate = (id)self;
@@ -712,7 +716,7 @@ - (void)parser:(DTHTMLParser *)parser didStartElement:(NSString *)elementName at
// apply style from merged style sheet
NSSet *matchedSelectors;
- NSDictionary *mergedStyles = [_globalStyleSheet mergedStyleDictionaryForElement:newNode matchedSelectors:&matchedSelectors];
+ NSDictionary *mergedStyles = [_globalStyleSheet mergedStyleDictionaryForElement:newNode matchedSelectors:&matchedSelectors ignoreInlineStyle:_ignoreInlineStyles];
if (mergedStyles)
{
Oops, something went wrong.

0 comments on commit 565f5ea

Please sign in to comment.