Skip to content

Commit

Permalink
[react-native] Remove iOS-specific attributes from ART text
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiebits committed Apr 30, 2015
1 parent 4f70e58 commit 63ab6e8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 41 deletions.
1 change: 0 additions & 1 deletion Libraries/ART/RCTConvert+ART.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
@interface RCTConvert (ART)

+ (CGPathRef)CGPath:(id)json;
+ (CTFontRef)CTFont:(id)json;
+ (CTTextAlignment)CTTextAlignment:(id)json;
+ (ARTTextFrame)ARTTextFrame:(id)json;
+ (ARTCGFloatArray)ARTCGFloatArray:(id)json;
Expand Down
15 changes: 2 additions & 13 deletions Libraries/ART/RCTConvert+ART.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ + (CGPathRef)CGPath:(id)json
return (CGPathRef)CFAutorelease(path);
}

+ (CTFontRef)CTFont:(id)json
{
NSDictionary *dict = [self NSDictionary:json];
if (!dict) {
return nil;
}
CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)dict);
CTFontRef font = CTFontCreateWithFontDescriptor(fontDescriptor, 0.0, NULL);
CFRelease(fontDescriptor);
return (CTFontRef)CFAutorelease(font);
}

RCT_ENUM_CONVERTER(CTTextAlignment, (@{
@"auto": @(kCTTextAlignmentNatural),
@"left": @(kCTTextAlignmentLeft),
Expand All @@ -98,7 +86,8 @@ + (ARTTextFrame)ARTTextFrame:(id)json
return frame;
}

CTFontRef font = [self CTFont:dict[@"font"]];
NSDictionary *fontDict = dict[@"font"];
CTFontRef font = (__bridge CTFontRef)[self UIFont:nil withFamily:fontDict[@"fontFamily"] size:fontDict[@"fontSize"] weight:fontDict[@"fontWeight"] style:fontDict[@"fontStyle"]];
if (!font) {
return frame;
}
Expand Down
28 changes: 1 addition & 27 deletions Libraries/ART/ReactIOSART.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,11 @@ function fontAndLinesDiffer(a, b) {
return true;
}

var aTraits = a.font.NSCTFontTraitsAttribute;
var bTraits = b.font.NSCTFontTraitsAttribute;

if (
a.font.fontFamily !== b.font.fontFamily ||
a.font.fontSize !== b.font.fontSize ||
a.font.fontWeight !== b.font.fontWeight ||
a.font.fontStyle !== b.font.fontStyle ||
// TODO(6364240): remove iOS-specific attrs
a.font.NSFontFamilyAttribute !== b.font.NSFontFamilyAttribute ||
a.font.NSFontSizeAttribute !== b.font.NSFontSizeAttribute ||
aTraits.NSCTFontSymbolicTrait !== bTraits.NSCTFontSymbolicTrait
a.font.fontStyle !== b.font.fontStyle
) {
return true;
}
Expand Down Expand Up @@ -418,14 +411,6 @@ var Shape = React.createClass({

var cachedFontObjectsFromString = {};

function extractFontTraits(isBold, isItalic) {
var italic = isItalic ? 1 : 0;
var bold = isBold ? 2 : 0;
return {
NSCTFontSymbolicTrait: italic | bold
};
}

var fontFamilyPrefix = /^[\s"']*/;
var fontFamilySuffix = /[\s"']*$/;

Expand Down Expand Up @@ -456,10 +441,6 @@ function parseFontString(font) {
fontSize: fontSize,
fontWeight: isBold ? 'bold' : 'normal',
fontStyle: isItalic ? 'italic' : 'normal',
// TODO(6364240): remove iOS-specific attrs
NSFontFamilyAttribute: fontFamily,
NSFontSizeAttribute: fontSize,
NSCTFontTraitsAttribute: extractFontTraits(isBold, isItalic)
};
return cachedFontObjectsFromString[font];
}
Expand All @@ -479,13 +460,6 @@ function extractFont(font) {
fontSize: fontSize,
fontWeight: font.fontWeight,
fontStyle: font.fontStyle,
// TODO(6364240): remove iOS-specific attrs
NSFontFamilyAttribute: fontFamily,
NSFontSizeAttribute: fontSize,
NSCTFontTraitsAttribute: extractFontTraits(
font.fontWeight === 'bold',
font.fontStyle === 'italic'
)
};
}

Expand Down

0 comments on commit 63ab6e8

Please sign in to comment.