Skip to content

Commit

Permalink
Add support for width / height to the SvgDecoder
Browse files Browse the repository at this point in the history
The sample SvgDecoder does not currently use parameters with and height
that are passed into the decode() method. This can be misleading for
Glide users and causes basic functionality such as image scaling to not
work properly. This change adds code to change the SVG document width
and height according to the provided parameters.
  • Loading branch information
chggr committed May 11, 2020
1 parent 1caeff4 commit 5a814a1
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bumptech.glide.samples.svg;

import static com.bumptech.glide.request.target.Target.SIZE_ORIGINAL;

import androidx.annotation.NonNull;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.ResourceDecoder;
Expand All @@ -24,6 +26,12 @@ public Resource<SVG> decode(
throws IOException {
try {
SVG svg = SVG.getFromInputStream(source);
if (width != SIZE_ORIGINAL) {
svg.setDocumentWidth(width);
}
if (height != SIZE_ORIGINAL) {
svg.setDocumentHeight(height);
}
return new SimpleResource<>(svg);
} catch (SVGParseException ex) {
throw new IOException("Cannot load SVG from stream", ex);
Expand Down

0 comments on commit 5a814a1

Please sign in to comment.