com.android.ide.common.vectordrawable
Class VdPreview

java.lang.Object
  extended by com.android.ide.common.vectordrawable.VdPreview

public class VdPreview
extends java.lang.Object

Generate a Image based on the VectorDrawable's XML content.

This class also contains a main method, which can be used to preview a vector drawable file.


Nested Class Summary
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.
 
Field Summary
static int MAX_PREVIEW_IMAGE_SIZE
           
static int MIN_PREVIEW_IMAGE_SIZE
           
 
Constructor Summary
VdPreview()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PREVIEW_IMAGE_SIZE

public static final int MAX_PREVIEW_IMAGE_SIZE
See Also:
Constant Field Values

MIN_PREVIEW_IMAGE_SIZE

public static final int MIN_PREVIEW_IMAGE_SIZE
See Also:
Constant Field Values
Constructor Detail

VdPreview

public VdPreview()
Method Detail

parseVdStringIntoDocument

@Nullable
public static org.w3c.dom.Document parseVdStringIntoDocument(@NonNull
                                                                      java.lang.String xmlFileContent,
                                                                      @Nullable
                                                                      java.lang.StringBuilder errorLog)
Parse the VectorDrawable's XML file into a document object.

Parameters:
xmlFileContent - the content of the VectorDrawable's XML file.
errorLog - when errors were found, log them in this builder if it is not null.
Returns:
parsed document or null if errors happened.

getVdOriginalSize

public static VdPreview.SourceSize getVdOriginalSize(@NonNull
                                                     org.w3c.dom.Document document)
Get the vector drawable's original size.


overrideXmlContent

@Nullable
public static java.lang.String overrideXmlContent(@NonNull
                                                           org.w3c.dom.Document document,
                                                           @NonNull
                                                           VdOverrideInfo info,
                                                           @Nullable
                                                           java.lang.StringBuilder errorLog)
The UI can override some properties of the Vector drawable. In order to override in an uniform way, we re-parse the XML file and pick the appropriate attributes to override.

Parameters:
document - the parsed document of original VectorDrawable's XML file.
info - incoming override information for VectorDrawable.
errorLog - log for the parsing errors and warnings.
Returns:
the overridden XML file in one string. If exception happens or no attributes needs to be overriden, return null.

getPreviewFromVectorXml

@Nullable
public static java.awt.image.BufferedImage getPreviewFromVectorXml(@NonNull
                                                                            VdPreview.TargetSize targetSize,
                                                                            @Nullable
                                                                            java.lang.String xmlFileContent,
                                                                            @Nullable
                                                                            java.lang.StringBuilder vdErrorLog)
This generates an image according to the VectorDrawable's content xmlFileContent. At the same time, captures all the errors found during parsing. The size of image is determined by the size.

Parameters:
targetSize - the size of result image.
xmlFileContent - VectorDrawable's XML file's content.
vdErrorLog - log for the parsing errors and warnings.
Returns:
an preview image according to the VectorDrawable's XML