(InputStream _is, int fillColor, int scaleToPixels)
| 279 | } |
| 280 | |
| 281 | @NonNull |
| 282 | static Bitmap renderSvg(InputStream _is, int fillColor, int scaleToPixels) throws IOException { |
| 283 | // https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/ |
| 284 | try (InputStream is = new Helper.MaximumLengthStream(_is, MAX_SVG_SIZE)) { |
| 285 | // https://bugzilla.mozilla.org/show_bug.cgi?id=455100 |
| 286 | // https://bug1105796.bmoattachments.org/attachment.cgi?id=8529795 |
| 287 | // https://github.com/BigBadaboom/androidsvg/issues/122#issuecomment-361902061 |
| 288 | SVG.setInternalEntitiesEnabled(false); |
| 289 | |
| 290 | SVG svg = SVG.getFromInputStream(is); |
| 291 | float dw = svg.getDocumentWidth(); |
| 292 | float dh = svg.getDocumentHeight(); |
| 293 | if (dw <= 0 || dh <= 0) { |
| 294 | dw = scaleToPixels; |
| 295 | dh = scaleToPixels; |
| 296 | } |
| 297 | |
| 298 | int w, h; |
| 299 | if (dw > scaleToPixels || dh > scaleToPixels) { |
| 300 | w = scaleToPixels; |
| 301 | h = Math.round(scaleToPixels * dh / dw); |
| 302 | } else { |
| 303 | w = Math.round(dw); |
| 304 | h = Math.round(dh); |
| 305 | } |
| 306 | |
| 307 | svg.setDocumentWidth("100%"); |
| 308 | svg.setDocumentHeight("100%"); |
| 309 | |
| 310 | Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
| 311 | bm.eraseColor(fillColor); |
| 312 | Canvas canvas = new Canvas(bm); |
| 313 | svg.renderToCanvas(canvas); |
| 314 | return bm; |
| 315 | } catch (Throwable ex) { |
| 316 | throw new IOException("SVG, ex", ex); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | static Drawable decodeImage(final Context context, final long id, String source, boolean show, int zoom, final float scale, final TextView view) { |
| 321 | Drawable d = decodeImage(context, id, source, 0, 0, false, show, zoom, scale, view); |
no outgoing calls
no test coverage detected