Skip to content

Commit

Permalink
Merge branch 'release-1.6.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Oct 17, 2014
2 parents d68c443 + 52313e3 commit 10af237
Show file tree
Hide file tree
Showing 20 changed files with 2,244 additions and 207 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ language: objective-c

before_install:
- brew update
- brew upgrade xctool

install:
- brew upgrade xctool
- sudo easy_install cpp-coveralls
- curl -sL https://gist.github.com/henrikhodne/7ac6d02ff9a24a94720c/raw/install_appledoc.sh | sh

script:
- xctool -project DTCoreText.xcodeproj -scheme DemoApp build test -sdk iphonesimulator -arch i386 ONLY_ACTIVE_ARCH=NO
Expand Down
10 changes: 8 additions & 2 deletions Core/Source/DTAttributedTextContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,14 @@ - (NSInteger)accessibilityElementCount

- (id)accessibilityElementAtIndex:(NSInteger)index
{
DTAccessibilityElement *element = [[self accessibilityElements] objectAtIndex:index];
return element;
NSUInteger count = [self accessibilityElementCount];

if (count > 0 && index < count)
{
return [[self accessibilityElements] objectAtIndex:index];
}

return nil;
}

- (NSInteger)indexOfAccessibilityElement:(id)element
Expand Down
46 changes: 23 additions & 23 deletions Core/Source/DTCoreTextFontDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -462,45 +462,45 @@ - (BOOL)supportsNativeSmallCaps
return YES;
}

CTFontRef tmpFont = [self newMatchingFont];

BOOL smallCapsSupported = NO;

// check if this font supports small caps
CFArrayRef fontFeatures = CTFontCopyFeatures(tmpFont);
CTFontRef tmpFont = [self newMatchingFont];

if (fontFeatures)
if (tmpFont)
{
for (NSDictionary *oneFeature in (__bridge NSArray *)fontFeatures)
// check if this font supports small caps
CFArrayRef fontFeatures = CTFontCopyFeatures(tmpFont);

if (fontFeatures)
{
NSInteger featureTypeIdentifier = [[oneFeature objectForKey:(id)kCTFontFeatureTypeIdentifierKey] integerValue];

if (featureTypeIdentifier == 3) // Letter Case
for (NSDictionary *oneFeature in (__bridge NSArray *)fontFeatures)
{
NSArray *featureSelectors = [oneFeature objectForKey:(id)kCTFontFeatureTypeSelectorsKey];
NSInteger featureTypeIdentifier = [[oneFeature objectForKey:(id)kCTFontFeatureTypeIdentifierKey] integerValue];

for (NSDictionary *oneFeatureSelector in featureSelectors)
if (featureTypeIdentifier == 3) // Letter Case
{
NSInteger featureSelectorIdentifier = [[oneFeatureSelector objectForKey:(id)kCTFontFeatureSelectorIdentifierKey] integerValue];
NSArray *featureSelectors = [oneFeature objectForKey:(id)kCTFontFeatureTypeSelectorsKey];

if (featureSelectorIdentifier == 3) // Small Caps
for (NSDictionary *oneFeatureSelector in featureSelectors)
{
// hooray, small caps supported!
smallCapsSupported = YES;
NSInteger featureSelectorIdentifier = [[oneFeatureSelector objectForKey:(id)kCTFontFeatureSelectorIdentifierKey] integerValue];

break;
if (featureSelectorIdentifier == 3) // Small Caps
{
// hooray, small caps supported!
smallCapsSupported = YES;

break;
}
}

break;
}

break;
}

CFRelease(fontFeatures);
}

CFRelease(fontFeatures);
}

if (tmpFont)
{
CFRelease(tmpFont);
}

Expand Down
123 changes: 67 additions & 56 deletions Core/Source/DTHTMLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -867,64 +867,69 @@ - (void)applyStyleDictionary:(NSDictionary *)styles

// check if this is a known font family
CTFontRef font = [_fontDescriptor newMatchingFont];
NSString *foundFamily = CFBridgingRelease(CTFontCopyFamilyName(font));

if ([foundFamily isEqualToString:fontFamily])
if (font)
{
foundFontFamily = YES;
break;
}

NSString *lowercaseFontFamily = [fontFamily lowercaseString];

if ([lowercaseFontFamily rangeOfString:@"geneva"].length)
{
_fontDescriptor.fontFamily = @"Helvetica";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"cursive"].length)
{
_fontDescriptor.stylisticClass = kCTFontScriptsClass;
_fontDescriptor.fontFamily = nil;
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"sans-serif"].length)
{
// too many matches (24)
// fontDescriptor.stylisticClass = kCTFontSansSerifClass;
_fontDescriptor.fontFamily = @"Helvetica";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"serif"].length)
{
// kCTFontTransitionalSerifsClass = Baskerville
// kCTFontClarendonSerifsClass = American Typewriter
// kCTFontSlabSerifsClass = Courier New
//
// strangely none of the classes yields Times
_fontDescriptor.fontFamily = @"Times New Roman";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"fantasy"].length)
{
_fontDescriptor.fontFamily = @"Papyrus"; // only available on iPad
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"monospace"].length)
{
_fontDescriptor.monospaceTrait = YES;
_fontDescriptor.fontFamily = @"Courier";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"times"].length)
{
_fontDescriptor.fontFamily = @"Times New Roman";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily isEqualToString:@"inherit"])
{
_fontDescriptor.fontFamily = self.parentElement.fontDescriptor.fontFamily;
foundFontFamily = YES;
NSString *foundFamily = CFBridgingRelease(CTFontCopyFamilyName(font));
CFRelease(font);

if ([foundFamily isEqualToString:fontFamily])
{
foundFontFamily = YES;
break;
}

NSString *lowercaseFontFamily = [fontFamily lowercaseString];

if ([lowercaseFontFamily rangeOfString:@"geneva"].length)
{
_fontDescriptor.fontFamily = @"Helvetica";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"cursive"].length)
{
_fontDescriptor.stylisticClass = kCTFontScriptsClass;
_fontDescriptor.fontFamily = nil;
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"sans-serif"].length)
{
// too many matches (24)
// fontDescriptor.stylisticClass = kCTFontSansSerifClass;
_fontDescriptor.fontFamily = @"Helvetica";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"serif"].length)
{
// kCTFontTransitionalSerifsClass = Baskerville
// kCTFontClarendonSerifsClass = American Typewriter
// kCTFontSlabSerifsClass = Courier New
//
// strangely none of the classes yields Times
_fontDescriptor.fontFamily = @"Times New Roman";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"fantasy"].length)
{
_fontDescriptor.fontFamily = @"Papyrus"; // only available on iPad
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"monospace"].length)
{
_fontDescriptor.monospaceTrait = YES;
_fontDescriptor.fontFamily = @"Courier";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily rangeOfString:@"times"].length)
{
_fontDescriptor.fontFamily = @"Times New Roman";
foundFontFamily = YES;
}
else if ([lowercaseFontFamily isEqualToString:@"inherit"])
{
_fontDescriptor.fontFamily = self.parentElement.fontDescriptor.fontFamily;
foundFontFamily = YES;
}
}

if (foundFontFamily)
Expand Down Expand Up @@ -1329,6 +1334,12 @@ - (void)applyStyleDictionary:(NSDictionary *)styles
{
self.paragraphStyle.paragraphSpacing = _margins.bottom;
}

NSString *coretextFontString = [styles objectForKey:@"-coretext-fontname"];
if (coretextFontString)
{
_fontDescriptor.fontName = [styles objectForKey:@"-coretext-fontname"];
}
}

- (DTCSSListStyle *)listStyle
Expand Down
59 changes: 52 additions & 7 deletions Core/Source/DTImageTextAttachment.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ - (id)initWithElement:(DTHTMLElement *)element options:(NSDictionary *)options

if (self)
{
// get base URL
NSURL *baseURL = [options objectForKey:NSBaseURLDocumentOption];
NSString *src = [element.attributes objectForKey:@"src"];

[self _decodeImageSrc:src relativeToBaseURL:baseURL];
[self _decodeImageFromElement:element options:options];
}

return self;
Expand All @@ -69,8 +65,12 @@ - (id)initWithImage:(DTImage *)image
}


- (void)_decodeImageSrc:(NSString *)src relativeToBaseURL:(NSURL *)baseURL
- (void)_decodeImageFromElement:(DTHTMLElement *)element options:(NSDictionary *)options
{
// get base URL
NSURL *baseURL = [options objectForKey:NSBaseURLDocumentOption];
NSString *src = [element.attributes objectForKey:@"src"];

NSURL *contentURL = nil;

// decode content URL
Expand Down Expand Up @@ -101,7 +101,52 @@ - (void)_decodeImageSrc:(NSString *)src relativeToBaseURL:(NSURL *)baseURL
// if we have image data, get the default display size
if (decodedData)
{
self.image = [[DTImage alloc] initWithData:decodedData];
DTImage *decodedImage = [[DTImage alloc] initWithData:decodedData];

// we don't know the content scale from such images, need to infer it from size in style
NSString *styles = [element.attributes objectForKey:@"style"];

// that only works if there is a style dictionary
if (styles)
{
NSDictionary *attributes = [styles dictionaryOfCSSStyles];

NSString *widthStr = attributes[@"width"];
NSString *heightStr = attributes[@"height"];

if ([widthStr hasSuffix:@"px"] && [heightStr hasSuffix:@"px"])
{
CGSize sizeAccordingToStyle;

// those style size values are the original image size
sizeAccordingToStyle.width = [widthStr pixelSizeOfCSSMeasureRelativeToCurrentTextSize:0 textScale:1];
sizeAccordingToStyle.height = [heightStr pixelSizeOfCSSMeasureRelativeToCurrentTextSize:0 textScale:1];

// if _orgiginal width and height are a fraction of decode image size, it must be a scaled image
if (sizeAccordingToStyle.width && sizeAccordingToStyle.width < decodedImage.size.width &&
sizeAccordingToStyle.height && sizeAccordingToStyle.height < decodedImage.size.height)
{
// determine image scale
CGFloat scale = round(decodedImage.size.width/sizeAccordingToStyle.width);

// sanity check, accept from @2x - @5x
if (scale>=2.0 && scale<=5.0)
{
#if TARGET_OS_IPHONE
// on iOS change the scale by making a new image with same pixels
decodedImage = [DTImage imageWithCGImage:decodedImage.CGImage scale:scale orientation:decodedImage.imageOrientation];
#else
// on OS X we can set the size
[decodedImage setSize:sizeAccordingToStyle];
#endif
}
}
}
}

self.image = decodedImage;

// prevent remote loading of image
_contentURL = nil;
}
}
Expand Down
23 changes: 13 additions & 10 deletions Core/Source/DTListItemHTMLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,21 @@ - (NSAttributedString *)_listPrefix

CTFontRef font = [fontDescriptor newMatchingFont];

#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
if (___useiOS6Attributes)
if (font)
{
UIFont *uiFont = [UIFont fontWithCTFont:font];
[newAttributes setObject:uiFont forKey:NSFontAttributeName];

CFRelease(font);
}
else
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
if (___useiOS6Attributes)
{
UIFont *uiFont = [UIFont fontWithCTFont:font];
[newAttributes setObject:uiFont forKey:NSFontAttributeName];

CFRelease(font);
}
else
#endif
{
[newAttributes setObject:CFBridgingRelease(font) forKey:(id)kCTFontAttributeName];
{
[newAttributes setObject:CFBridgingRelease(font) forKey:(id)kCTFontAttributeName];
}
}

CGColorRef textColor = (__bridge CGColorRef)[attributes objectForKey:(id)kCTForegroundColorAttributeName];
Expand Down
30 changes: 17 additions & 13 deletions Core/Source/DTTextHTMLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,26 @@ - (NSAttributedString *)attributedString
{
DTCoreTextFontDescriptor *smallDesc = [self.fontDescriptor copy];
smallDesc.smallCapsFeature = YES;

CTFontRef smallerFont = [smallDesc newMatchingFont];

NSMutableDictionary *smallAttributes = [attributes mutableCopy];

#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && TARGET_OS_IPHONE
if (___useiOS6Attributes)

CTFontRef smallerFont = [smallDesc newMatchingFont];

if (smallerFont)
{
UIFont *font = [UIFont fontWithCTFont:smallerFont];

[smallAttributes setObject:font forKey:NSFontAttributeName];
CFRelease(smallerFont);
}
else
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && TARGET_OS_IPHONE
if (___useiOS6Attributes)
{
UIFont *font = [UIFont fontWithCTFont:smallerFont];

[smallAttributes setObject:font forKey:NSFontAttributeName];
CFRelease(smallerFont);
}
else
#endif
{
[smallAttributes setObject:CFBridgingRelease(smallerFont) forKey:(id)kCTFontAttributeName];
{
[smallAttributes setObject:CFBridgingRelease(smallerFont) forKey:(id)kCTFontAttributeName];
}
}

return [[NSAttributedString alloc] initWithString:_text attributes:smallAttributes];
Expand Down
Loading

0 comments on commit 10af237

Please sign in to comment.