Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounded Rectangles & Ellipses Can Specify either or rx ry #120

Merged
merged 2 commits into from Mar 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions SVGEngine.mm
Expand Up @@ -38,6 +38,7 @@

NSDictionary *readAttributes();
float readFloatAttribute(NSString *aName);
bool hasAttribute(NSString * const aName);
NSString *readStringAttribute(NSString *aName);

private:
Expand Down Expand Up @@ -182,11 +183,19 @@ @interface SVGAttributeSet () {
readFloatAttribute(@"x"), readFloatAttribute(@"y"),
readFloatAttribute(@"width"), readFloatAttribute(@"height")
};

float rx = readFloatAttribute(@"rx");
float ry = readFloatAttribute(@"ry");


if (!hasAttribute(@"rx")) {
rx = ry;
}
if (!hasAttribute(@"ry")) {
ry = rx;
}

CGMutablePathRef rectPath = CGPathCreateMutable();
CGPathAddRoundedRect(rectPath, NULL, rect, rx, ry);
CGPathAddRoundedRect(rectPath, NULL, rect, MIN(rx, rect.size.width/2), MIN(ry, rect.size.height/2));
return rectPath;
}

Expand Down Expand Up @@ -250,8 +259,17 @@ @interface SVGAttributeSet () {
CGPoint const center = {
readFloatAttribute(@"cx"), readFloatAttribute(@"cy")
};

float rx = readFloatAttribute(@"rx");
float ry = readFloatAttribute(@"ry");

if (!hasAttribute(@"rx")) {
rx = ry;
}
if (!hasAttribute(@"ry")) {
ry = rx;
}

CGMutablePathRef ellipse = CGPathCreateMutable();
CGPathAddEllipseInRect(ellipse, NULL, CGRectMake(center.x - rx, center.y - ry, rx * 2.0, ry * 2.0));
return ellipse;
Expand Down Expand Up @@ -363,6 +381,12 @@ @interface SVGAttributeSet () {
return value ? strtof(value, NULL) : 0.0;
}

bool svgParser::hasAttribute(NSString * const aName)
{
xmlAutoFree char *value = (char *)xmlTextReaderGetAttribute(_xmlReader, (xmlChar*)[aName UTF8String]);
return value != NULL;
}

NSString *svgParser::readStringAttribute(NSString * const aName)
{
xmlAutoFree char *value = (char *)xmlTextReaderGetAttribute(_xmlReader, (xmlChar*)[aName UTF8String]);
Expand Down