use of com.larvalabs.svgandroid.SVGParser.SVGHandler in project iosched by google.
the class SVGBuilder method build.
/**
* Loads, reads, parses the SVG (or SVGZ).
*
* @return the parsed SVG.
* @throws SVGParseException if there is an error while parsing.
*/
public SVG build() throws SVGParseException {
if (data == null) {
throw new IllegalStateException("SVG input not specified. Call one of the readFrom...() methods first.");
}
try {
final SVGHandler handler = new SVGHandler();
handler.setColorSwap(searchColor, replaceColor, overideOpacity);
handler.setWhiteMode(whiteMode);
if (strokeColorFilter != null) {
handler.strokePaint.setColorFilter(strokeColorFilter);
}
if (fillColorFilter != null) {
handler.fillPaint.setColorFilter(fillColorFilter);
}
// SVGZ support (based on https://github.com/josefpavlik/svg-android/commit/fc0522b2e1):
if (!data.markSupported())
// decorate stream so we can use mark/reset
data = new BufferedInputStream(data);
try {
data.mark(4);
byte[] magic = new byte[2];
int r = data.read(magic, 0, 2);
int magicInt = (magic[0] + ((magic[1]) << 8)) & 0xffff;
data.reset();
if (r == 2 && magicInt == GZIPInputStream.GZIP_MAGIC) {
// Log.d(SVGParser.TAG, "SVG is gzipped");
GZIPInputStream gin = new GZIPInputStream(data);
data = gin;
}
} catch (IOException ioe) {
throw new SVGParseException(ioe);
}
final SVG svg = SVGParser.parse(new InputSource(data), handler);
return svg;
} finally {
if (closeInputStream) {
try {
data.close();
} catch (IOException e) {
Log.e(SVGParser.TAG, "Error closing SVG input stream.", e);
}
}
}
}
Aggregations