Skip to content

Commit

Permalink
Merge branch 'cl3m-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
arielelkin committed Jun 25, 2018
2 parents c441d25 + 5177ec6 commit 708c8b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. Items under

### New Features
### Fixes
- Add support for integer function SVG colors: rgb(int, int, int). Clément Beffa
### Internal Changes
- Add unit tests. Ariel Elkin.
- Deal with optional transformation arguments. Scott Talbot [#122](https://github.com/pocketsvg/PocketSVG/pull/122)
Expand Down
29 changes: 18 additions & 11 deletions SVGEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -842,17 +842,24 @@ static CGPoint mapToEllipse(double x, double y, double rx, double ry, double cos
str = mapped;
}

NSCParameterAssert([str hasPrefix:@"#"]);
NSCParameterAssert([str length] == 4 || [str length] == 7);
if([str length] == 4) {
str = [str mutableCopy];
[(NSMutableString *)str insertString:[str substringWithRange:(NSRange) { 3, 1 }]
atIndex:3];
[(NSMutableString *)str insertString:[str substringWithRange:(NSRange) { 2, 1 }]
atIndex:2];
[(NSMutableString *)str insertString:[str substringWithRange:(NSRange) { 1, 1 }]
atIndex:1];
}
if ([str hasPrefix:@"rgb("]) {
NSCParameterAssert([str hasSuffix:@")"]);
NSArray<NSString*>* parts = [[str substringWithRange:(NSRange) { 4, str.length-5 }] componentsSeparatedByString:@","];
NSCParameterAssert([parts count] == 3);
str = [NSString stringWithFormat:@"#%02x%02x%02x", (unsigned int)parts[0].integerValue, (unsigned int)parts[1].integerValue, (unsigned int)parts[2].integerValue];
} else {
NSCParameterAssert([str hasPrefix:@"#"]);
NSCParameterAssert([str length] == 4 || [str length] == 7);
if([str length] == 4) {
str = [str mutableCopy];
[(NSMutableString *)str insertString:[str substringWithRange:(NSRange) { 3, 1 }]
atIndex:3];
[(NSMutableString *)str insertString:[str substringWithRange:(NSRange) { 2, 1 }]
atIndex:2];
[(NSMutableString *)str insertString:[str substringWithRange:(NSRange) { 1, 1 }]
atIndex:1];
}
}
_data = (uint32_t)strtol([str cStringUsingEncoding:NSASCIIStringEncoding]+1, NULL, 16);
}

Expand Down

0 comments on commit 708c8b4

Please sign in to comment.