diff --git a/TPSVG/src/com/trevorpage/tpsvg/SVGParserRenderer.java b/TPSVG/src/com/trevorpage/tpsvg/SVGParserRenderer.java index a2d5ef6..f6d311c 100644 --- a/TPSVG/src/com/trevorpage/tpsvg/SVGParserRenderer.java +++ b/TPSVG/src/com/trevorpage/tpsvg/SVGParserRenderer.java @@ -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; @@ -1649,7 +1650,7 @@ 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 @@ -1657,9 +1658,34 @@ private static float parseCoOrdinate(String value) { 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 {