Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2013, 2014, 2015 Antoine Vianey
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.avianey.androidsvgdrawable;
import fr.avianey.androidsvgdrawable.Qualifier.Type;
import fr.avianey.androidsvgdrawable.batik.DensityAwareUserAgent;
import fr.avianey.androidsvgdrawable.util.Log;
import org.apache.batik.anim.dom.SAXSVGDocumentFactory;
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.DocumentLoader;
import org.apache.batik.bridge.GVTBuilder;
import org.apache.batik.bridge.UserAgent;
import org.apache.batik.gvt.GraphicsNode;
import org.apache.batik.parser.UnitProcessor;
import org.apache.batik.util.XMLResourceDescriptor;
import org.apache.commons.io.FilenameUtils;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.svg.SVGLength;
import org.w3c.dom.svg.SVGSVGElement;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.EnumMap;
import java.util.Map;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.Math.*;
import static org.apache.commons.io.FilenameUtils.getBaseName;
public class QualifiedSVGResourceFactory {
private final Log log;
private final BoundsType boundsType;
public QualifiedSVGResourceFactory(Log log, BoundsType boundsType) {
this.log = log;
this.boundsType = boundsType;
}
public QualifiedResource fromSVGFile(final File file) throws IOException {
checkNotNull(file);
final String fileName = getBaseName(file.getAbsolutePath());
checkArgument(fileName.length() > 0);
checkArgument(fileName.indexOf("-") > 0, "No qualifier for input svg file " + fileName);
// unqualified name
final String unqualifiedName = fileName.substring(0, fileName.indexOf("-"));
checkArgument(unqualifiedName.matches("\\w+"));
// qualifiers
final Map typedQualifiers = Qualifier.fromQualifiedString(fileName.substring(fileName.indexOf("-") + 1));
// a density qualifier must be provided
checkNotNull(typedQualifiers.get(Type.density));
return new QualifiedSVGResource(file, unqualifiedName, typedQualifiers);
}
/**
* Extract the viewbox of the input SVG
* @return
* @throws MalformedURLException
* @throws IOException
*/
private Rectangle extractSVGBounds(QualifiedSVGResource svg) throws IOException {
// check