public class VdPreview
extends java.lang.Object
This class also contains a main method, which can be used to preview a vector drawable file.
Modifier and Type | Class and Description |
---|---|
static class |
VdPreview.SourceSize
Since we allow overriding the vector drawable's size, we also need to keep
the original size and aspect ratio.
|
static class |
VdPreview.TargetSize
This encapsulates the information used to determine the preview image size.
|
Modifier and Type | Field and Description |
---|---|
static int |
MAX_PREVIEW_IMAGE_SIZE |
static int |
MIN_PREVIEW_IMAGE_SIZE |
Constructor and Description |
---|
VdPreview() |
Modifier and Type | Method and Description |
---|---|
static java.awt.image.BufferedImage |
getPreviewFromVectorDocument(VdPreview.TargetSize targetSize,
org.w3c.dom.Document xml,
java.lang.StringBuilder vdErrorLog)
This generates an image from a vector tree.
|
static java.awt.image.BufferedImage |
getPreviewFromVectorTree(VdPreview.TargetSize targetSize,
com.android.ide.common.vectordrawable.VdTree vdTree,
java.lang.StringBuilder vdErrorLog)
This generates an image from a vector tree.
|
static java.awt.image.BufferedImage |
getPreviewFromVectorXml(VdPreview.TargetSize targetSize,
java.lang.String xmlFileContent,
java.lang.StringBuilder vdErrorLog)
This generates an image according to the VectorDrawable's content
xmlFileContent . |
static VdPreview.SourceSize |
getVdOriginalSize(org.w3c.dom.Document document)
Get the vector drawable's original size.
|
static java.lang.String |
overrideXmlContent(org.w3c.dom.Document document,
VdOverrideInfo info,
java.lang.StringBuilder errorLog)
The UI can override some properties of the Vector drawable.
|
static org.w3c.dom.Document |
parseVdStringIntoDocument(java.lang.String xmlFileContent,
java.lang.StringBuilder errorLog)
Parse the VectorDrawable's XML file into a document object.
|
public static final int MAX_PREVIEW_IMAGE_SIZE
public static final int MIN_PREVIEW_IMAGE_SIZE
@Nullable public static org.w3c.dom.Document parseVdStringIntoDocument(@NonNull java.lang.String xmlFileContent, @Nullable java.lang.StringBuilder errorLog)
xmlFileContent
- the content of the VectorDrawable's XML file.errorLog
- when errors were found, log them in this builder if it is not null.public static VdPreview.SourceSize getVdOriginalSize(@NonNull org.w3c.dom.Document document)
@Nullable public static java.lang.String overrideXmlContent(@NonNull org.w3c.dom.Document document, @NonNull VdOverrideInfo info, @Nullable java.lang.StringBuilder errorLog)
document
- the parsed document of original VectorDrawable's XML file.info
- incoming override information for VectorDrawable.errorLog
- log for the parsing errors and warnings.@Nullable public static java.awt.image.BufferedImage getPreviewFromVectorXml(@NonNull VdPreview.TargetSize targetSize, @Nullable java.lang.String xmlFileContent, @Nullable java.lang.StringBuilder vdErrorLog)
xmlFileContent
.
At the same time, vdErrorLog
captures all the errors found during parsing.
The size of image is determined by the size
.targetSize
- the size of result image.xmlFileContent
- VectorDrawable's XML file's content.vdErrorLog
- log for the parsing errors and warnings.@Nullable public static java.awt.image.BufferedImage getPreviewFromVectorDocument(@NonNull VdPreview.TargetSize targetSize, @NonNull org.w3c.dom.Document xml, @Nullable java.lang.StringBuilder vdErrorLog)
size
.targetSize
- the size of result image.xml
- The vector drawable XML documentvdErrorLog
- log for the errors and warnings.@Nullable public static java.awt.image.BufferedImage getPreviewFromVectorTree(@NonNull VdPreview.TargetSize targetSize, @NonNull com.android.ide.common.vectordrawable.VdTree vdTree, @Nullable java.lang.StringBuilder vdErrorLog)
size
.targetSize
- the size of result image.vdTree
- The vector drawablevdErrorLog
- log for the errors and warnings.