Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion TPSVG/src/com/trevorpage/tpsvg/SVGParserRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.graphics.Shader;
import android.graphics.Typeface;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;

import com.trevorpage.tpsvg.internal.Gradient;
Expand Down Expand Up @@ -1649,17 +1650,42 @@ private int parseAttributeValuePairsIntoSaxAttributesImpl(
* For convenience, this method may or may not also handle the stripping of
* quotation marks from the value string - this is TBD.
*/
private static float parseCoOrdinate(String value) {
private float parseCoOrdinate(String value) {
float result = 0f;

// Quick and dirty way to determine if the value appears to have a units
// suffix.
if (value.charAt(value.length() - 1) >= 'a') {
if (value.endsWith("px")) {
value = value.substring(0, value.length() - 2);
} else if (value.endsWith("cm")) {
value = value.substring(0, value.length() - 2);
result = Float.parseFloat(value);
result = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, result*10.0f,
mContext.getResources().getDisplayMetrics());
return result;
} else if (value.endsWith("mm")) {
value = value.substring(0, value.length() - 2);
result = Float.parseFloat(value);
result = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, result,
mContext.getResources().getDisplayMetrics());
return result;
} else if (value.endsWith("in")) {
value = value.substring(0, value.length() - 2);
result = Float.parseFloat(value);
result = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_IN, result,
mContext.getResources().getDisplayMetrics());
return result;
} else if (value.endsWith("dp")) {
value = value.substring(0, value.length() - 2);
result = Float.parseFloat(value);
result = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, result,
mContext.getResources().getDisplayMetrics());
return result;
} else {
// TODO: Add support in future for other units here.
// TODO: Call our error reporting function.

}
}
try {
Expand Down