Work with SVG images and applying font settings for EMF files with Aspose.Imaging for Java 3.7.0

Share on FacebookTweet about this on TwitterShare on LinkedIn

Aspose.Imaging for Java logo We are pleased to announce the release of Aspose.Imaging for Java 3.7.0. The major development in this release is support for Scalable Vector Graphics image. Support to apply font setting for metafiles (EMF) has also been incorporated in this release.

Support for SVG image

Aspose.Imaging for Java now supports the SVG image format (.svg). SVG stands for Scalable Vector Graphics. Aspose.Imaging for Java provides the SvgImage class to load SVG files and same can be used to convert the SVG to raster formats. Below provided sample code demonstrate how to convert a SVG file to PNG format.



//Declare variables to store file paths for input and output images
String sourceFiles = "Path_to_source_folder\\Source\\sample.svg";
String destPath = "Path_to_results_folder\\Results\\out.png";
        
// Create an instance of Image class and load an exiting SVG file.
com.aspose.imaging.Image image = com.aspose.imaging.Image.load(sourceFileName);
        
// Cast image object to SVG image
com.aspose.imaging.fileformats.svg.SvgImage svgImage = (com.aspose.imaging.fileformats.svg.SvgImage)image;
    
// Create an instance of PngOptions class
com.aspose.imaging.imageoptions.PngOptions pngOptions = new com.aspose.imaging.imageoptions.PngOptions();


// convert and save to disk in PNG file format.
svgImage.save(destPath, pngOptions);

Applying Font Settings For Metafiles

Using Aspose.Imaging for Java API, developers can apply font settings for metafiles (EMF). Following is the code demonstrates how to specify font folder settings for EMF image while converting it to PNG image.



// Create an instance of EmfRasterizationOptions class
com.aspose.imaging.imageoptions.EmfRasterizationOptions emfRasterizationOptions = 
        new com.aspose.imaging.imageoptions.EmfRasterizationOptions();

// Set different properties
emfRasterizationOptions.setBackgroundColor(com.aspose.imaging.Color.getWhiteSmoke());

// Create an instance of PngOptions class
PngOptions pngOptions = new PngOptions();

// Pass the instance of EmfRasterizationOptions class
pngOptions.setVectorRasterizationOptions(emfRasterizationOptions);

//Declare variables to store file path
String filePath = ".\\alphabet.emf";

// Create an instance of EmfImage class and Load an existing EMF image.
com.aspose.imaging.fileformats.emf.EmfImage image = 
        (com.aspose.imaging.fileformats.emf.EmfImage)com.aspose.imaging.fileformats.emf.EmfImage.load(filePath);
try
{
    // Cache the image data for speed
    image.cacheData();

    // Set width & height of resultant image
    pngOptions.getVectorRasterizationOptions().setPageWidth(300);
    pngOptions.getVectorRasterizationOptions().setPageHeight(350);

    // Reset font font settings
    com.aspose.imaging.FontSettings.reset();

    // Call the Image.save() method to create the resultant image with default settings.
    // image.save(filePath + "_default_fonts.png", pngOptions); // un-comment this line for testing

    //Declare variable to store font file path
    String fontPath = ".\\Fonts";

    // Create an instance of Array list and add all default font paths to it.
    List fonts = new ArrayList();
    java.util.Collections.addAll(fonts, com.aspose.imaging.FontSettings.getDefaultFontsFolders());

    // Now add the new font path
    fonts.add(fontPath);

    // Call the setFontsFolders method of the FontSettings class and supply the array of font paths
    com.aspose.imaging.FontSettings.setFontsFolders(fonts.toArray(new String[0]), true);

    // Save the results to disk with new fonts
    image.save(filePath + "_with_my_fonts.png", pngOptions);
}
finally
{
    image.dispose();
}

Enhancements

Following enhancements have been introduced in this release.

  • Process of loading WMF files has been improved.

  • Aspose.Imaging drawing engine has been improved.

  • Calculation process of Horizontal and Vertical resolution values has been improved.

Please refer to the release notes of Aspose.Imaging for Java 3.7.0 for a full view of improvements along with sample code snippets for newly added features. If you are planning to upgrade the API to the latest revision, we strongly suggest you to check the Public API Changes section to know what has been changed in the public API since your current version.

Aspose.Imaging for Java Resources

The resources, you may need to accomplish your tasks:

As always we appreciate your feedback so if you ever have anything to tell us about this release or anything else, please head to the Aspose.Imaging forum for a chat.