Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 717198457b | |||
| e2991ab8b0 | |||
| dda3e5ed8c |
@@ -251,14 +251,15 @@ CGFloat* IJSVGColorCSSHSLToHSB(CGFloat hue, CGFloat saturation, CGFloat lightnes
|
||||
return nil;
|
||||
}
|
||||
|
||||
char* str = (char*)string.UTF8String;
|
||||
if(strlen(str) == 0) {
|
||||
const char* oString = string.UTF8String;
|
||||
if(strlen(oString) == 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
IJSVGTrimCharBuffer(str);
|
||||
char* str = IJSVGTimmedCharBufferCreate(oString);
|
||||
if (IJSVGCharBufferIsHEX(str) == YES) {
|
||||
return [self.class colorFromHEXString:string];
|
||||
(void)free(str), str = NULL;
|
||||
return [self.class colorFromHEXString:string];
|
||||
}
|
||||
|
||||
// is it RGB?
|
||||
@@ -268,6 +269,9 @@ CGFloat* IJSVGColorCSSHSLToHSB(CGFloat hue, CGFloat saturation, CGFloat lightnes
|
||||
methods = IJSVGParsingMethodParseString(str, &count);
|
||||
IJSVGParsingStringMethod* method = methods[0];
|
||||
|
||||
// memory clean for the string
|
||||
(void)free(str), str = NULL;
|
||||
|
||||
// nothing to return, just mem clean and get out of here
|
||||
if(count == 0 || methods == NULL) {
|
||||
if(methods != NULL) {
|
||||
@@ -313,6 +317,7 @@ CGFloat* IJSVGColorCSSHSLToHSB(CGFloat hue, CGFloat saturation, CGFloat lightnes
|
||||
color = [self computeColorSpace:color];
|
||||
|
||||
// memory clean!
|
||||
(void)free(str), str = NULL;
|
||||
(void)free(hsb), hsb = NULL;
|
||||
(void)free(params), params = NULL;
|
||||
return color;
|
||||
@@ -321,10 +326,12 @@ CGFloat* IJSVGColorCSSHSLToHSB(CGFloat hue, CGFloat saturation, CGFloat lightnes
|
||||
// is simply a clear color, dont fill
|
||||
if (strcmp(str, "none") == 0 ||
|
||||
strcmp(str, "transparent") == 0) {
|
||||
(void)free(str), str = NULL;
|
||||
return [self computeColorSpace:NSColor.clearColor];
|
||||
}
|
||||
|
||||
// could return nil
|
||||
(void)free(str), str = NULL;
|
||||
return [self.class colorFromPredefinedColorName:string];
|
||||
}
|
||||
|
||||
|
||||
@@ -364,16 +364,16 @@ void IJSVGExporterPathInstructionRoundData(CGFloat* data, NSInteger length,
|
||||
IJSVGExporterPathInstruction* nInstruction = nil;
|
||||
nInstruction = [[[IJSVGExporterPathInstruction alloc] initWithInstruction:'t'
|
||||
dataCount:2] autorelease];
|
||||
nInstruction.data[0] = instruction.data[3];
|
||||
nInstruction.data[1] = instruction.data[4];
|
||||
nInstruction.data[0] = instruction.data[2];
|
||||
nInstruction.data[1] = instruction.data[3];
|
||||
[nInstructions addObject:nInstruction];
|
||||
continue;
|
||||
} else if (lastInstruction.instruction == 't' && instruction.data[2] == lastInstruction.data[0] && instruction.data[3] == lastInstruction.data[1]) {
|
||||
IJSVGExporterPathInstruction* nInstruction = nil;
|
||||
nInstruction = [[[IJSVGExporterPathInstruction alloc] initWithInstruction:'t'
|
||||
dataCount:2] autorelease];
|
||||
nInstruction.data[0] = instruction.data[3];
|
||||
nInstruction.data[1] = instruction.data[4];
|
||||
nInstruction.data[0] = instruction.data[2];
|
||||
nInstruction.data[1] = instruction.data[3];
|
||||
[nInstructions addObject:nInstruction];
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ typedef struct {
|
||||
|
||||
IJSVGParsingStringMethod* IJSVGParsingStringMethodCreate(void);
|
||||
void IJSVGParsingStringMethodRelease(IJSVGParsingStringMethod* stringMethod);
|
||||
IJSVGParsingStringMethod** IJSVGParsingMethodParseString(char* string,
|
||||
IJSVGParsingStringMethod** IJSVGParsingMethodParseString(const char* string,
|
||||
NSUInteger* count);
|
||||
void IJSVGParsingStringMethodsRelease(IJSVGParsingStringMethod** methods,
|
||||
NSUInteger count);
|
||||
|
||||
@@ -39,10 +39,10 @@ void IJSVGParsingStringMethodsRelease(IJSVGParsingStringMethod** methods,
|
||||
(void)free(methods), methods = NULL;
|
||||
}
|
||||
|
||||
IJSVGParsingStringMethod** IJSVGParsingMethodParseString(char* string,
|
||||
IJSVGParsingStringMethod** IJSVGParsingMethodParseString(const char* string,
|
||||
NSUInteger* count)
|
||||
{
|
||||
char* charString = string;
|
||||
const char* charString = string;
|
||||
unsigned long length = strlen(string);
|
||||
char* buffer = (char*)calloc(sizeof(char), length);
|
||||
char* originBuffer = buffer;
|
||||
|
||||
@@ -171,9 +171,8 @@ void IJSVGApplyTransform(NSArray<IJSVGTransform*>* transforms, IJSVGTransformApp
|
||||
const char* charString = string.UTF8String;
|
||||
IJSVGParsingStringMethod** methods = NULL;
|
||||
NSUInteger count = 0;
|
||||
methods = IJSVGParsingMethodParseString((char*)charString, &count);
|
||||
methods = IJSVGParsingMethodParseString(charString, &count);
|
||||
for(int i = 0; i < count; i++) {
|
||||
|
||||
IJSVGParsingStringMethod* method = methods[i];
|
||||
IJSVGTransformCommand commandType;
|
||||
commandType = [self.class commandForCommandCString:method->name];
|
||||
|
||||
@@ -143,12 +143,12 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
const char* chars = string.UTF8String;
|
||||
IJSVGTrimCharBuffer((char*)chars);
|
||||
char* chars = IJSVGTimmedCharBufferCreate(string.UTF8String);
|
||||
|
||||
// is inherit or just nothing
|
||||
size_t strl = strlen(chars);
|
||||
if (strcmp(chars, "inherit") == 0 || strl == 0) {
|
||||
(void)free(chars), chars = NULL;
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -158,7 +158,6 @@
|
||||
floatCount:1
|
||||
charCount:(NSUInteger)strl
|
||||
size:&length];
|
||||
|
||||
// not sure how this ended up but nothing returned
|
||||
// even though there should had been
|
||||
if(length == 0) {
|
||||
@@ -170,12 +169,14 @@
|
||||
unit.value = floats[0];
|
||||
unit.type = IJSVGUnitLengthTypeNumber;
|
||||
|
||||
// memory free
|
||||
(void)(free(floats)), floats = NULL;
|
||||
|
||||
IJSVGUnitLengthType type = [self typeForCString:chars];
|
||||
unit.originalType = type;
|
||||
|
||||
// memory free
|
||||
(void)(free(floats)), floats = NULL;
|
||||
(void)free(chars), chars = NULL;
|
||||
|
||||
switch(type) {
|
||||
case IJSVGUnitLengthTypePercentage: {
|
||||
unit.value = [self convertUnitValue:unit.value
|
||||
|
||||
@@ -24,6 +24,7 @@ CGFloat degrees_to_radians(CGFloat degrees);
|
||||
BOOL IJSVGCharBufferIsHEX(char* buffer);
|
||||
BOOL IJSVGCharBufferHasPrefix(char* pre, char* str);
|
||||
BOOL IJSVGCharBufferHasSuffix(char* s1, char* s2);
|
||||
char* IJSVGTimmedCharBufferCreate(const char* buffer);
|
||||
void IJSVGTrimCharBuffer(char* buffer);
|
||||
void IJSVGCharBufferToLower(char* buffer);
|
||||
size_t IJSVGCharBufferHash(char* buffer);
|
||||
|
||||
@@ -43,8 +43,23 @@ BOOL IJSVGCharBufferHasSuffix(char* s1, char* s2)
|
||||
return strcmp(s1 + slen - tlen, s2) == 0;
|
||||
}
|
||||
|
||||
void IJSVGTrimCharBuffer(char* buffer)
|
||||
char* IJSVGTimmedCharBufferCreate(const char* buffer)
|
||||
{
|
||||
unsigned long start = 0;
|
||||
unsigned long length = strlen(buffer);
|
||||
while(length-1 > 0 && isspace(buffer[length-1])) {
|
||||
length--;
|
||||
}
|
||||
while(isspace(buffer[start])) {
|
||||
start++;
|
||||
}
|
||||
char* chars = (char*)malloc(sizeof(char)*((length-start)+1) ?: sizeof(char));
|
||||
memcpy(chars, &buffer[start], length-start);
|
||||
chars[length] = '\0';
|
||||
return chars;
|
||||
}
|
||||
|
||||
void IJSVGTrimCharBuffer(char* buffer) {
|
||||
char* ptr = buffer;
|
||||
unsigned long length = strlen(ptr);
|
||||
while(length-1 > 0 && isspace(ptr[length-1])) {
|
||||
@@ -235,7 +250,7 @@ CGFloat degrees_to_radians(CGFloat degrees)
|
||||
const char* str = string.UTF8String;
|
||||
NSUInteger count = 0;
|
||||
IJSVGParsingStringMethod** methods;
|
||||
methods = IJSVGParsingMethodParseString((char*)str, &count);
|
||||
methods = IJSVGParsingMethodParseString(str, &count);
|
||||
if(count == 0) {
|
||||
IJSVGParsingStringMethodsRelease(methods, count);
|
||||
return nil;
|
||||
|
||||
Reference in New Issue
Block a user