/** * Load SVG from file. */ public static SvgImage loadSvgImage( InputStream in ) throws Exception { Document document = getSvgFactory().createDocument( null, in ); return new SvgImage( document ); }
/** * Converts SVG file name to PNG. */ public static String toPngName( String name ) { if ( isSvgName( name ) ) { name = name.substring( 0, name.length() - 4 ) + PNG_EXTENSION; } return name; }
/** * Converts PNG file name to SVG. */ public static String toSvgName( String name ) { if ( isPngName( name ) ) { name = name.substring( 0, name.length() - 4 ) + SVG_EXTENSION; } return name; } }
if ( SvgSupport.isSvgEnabled() && ( SvgSupport.isSvgName( resource ) || SvgSupport.isPngName( resource ) ) ) { InputStream in = null; try { SvgImage svg = SvgSupport.loadSvgImage( in ); SwtUniversalImage image = new SwtUniversalImageSvg( svg ); IOUtils.closeQuietly( in ); resource = SvgSupport.toPngName( resource );
/** * Load image from several sources. */ public static SwingUniversalImage getImageAsResource( String location ) { SwingUniversalImage result = null; if ( result == null && SvgSupport.isSvgEnabled() ) { result = getImageAsResourceInternal( SvgSupport.toSvgName( location ) ); } if ( result == null ) { result = getImageAsResourceInternal( SvgSupport.toPngName( location ) ); } if ( result == null && !location.equals( NO_IMAGE ) ) { result = getImageAsResource( NO_IMAGE ); } return result; }
/** * Load image from InputStream as bitmap image, or SVG image conversion to bitmap image. */ private static SwingUniversalImage loadImage( InputStream in, String filename ) { if ( !SvgSupport.isSvgName( filename ) ) { // bitmap image try { return new SwingUniversalImageBitmap( ImageIO.read( in ) ); } catch ( IOException e ) { throw new RuntimeException( e ); } } else { // svg image - need to convert to bitmap try { return new SwingUniversalImageSvg( SvgSupport.loadSvgImage( in ) ); } catch ( Exception ex ) { throw new RuntimeException( ex ); } } } }
public SwtUniversalImageSvg( SvgImage svg ) { // get GraphicsNode and size from svg document UserAgentAdapter userAgentAdapter = new UserAgentAdapter(); DocumentLoader documentLoader = new DocumentLoader( userAgentAdapter ); BridgeContext ctx = new BridgeContext( userAgentAdapter, documentLoader ); GVTBuilder builder = new GVTBuilder(); svgGraphicsNode = builder.build( ctx, svg.getDocument() ); svgGraphicsSize = ctx.getDocumentSize(); }
private static SAXSVGDocumentFactory getSvgFactory() { SAXSVGDocumentFactory factory = SVG_FACTORY_THREAD_LOCAL.get(); if ( factory == null ) { factory = createFactory(); SVG_FACTORY_THREAD_LOCAL.set( factory ); } return factory; }
resource = resource.substring( 0, resource.indexOf( ":" ) ) + resource.substring( resource.indexOf( "." ) ); if ( SvgSupport.isSvgEnabled() && ( SvgSupport.isSvgName( resource ) || SvgSupport.isPngName( resource ) ) ) { InputStream in = null; try { in = super.getResourceAsStream( SvgSupport.toSvgName( resource ) ); SvgImage svg = SvgSupport.loadSvgImage( in ); SwtUniversalImage image = new SwtUniversalImageSvg( svg ); IOUtils.closeQuietly( in ); resource = SvgSupport.toPngName( resource );
/** * Load image from several sources. */ public static SwingUniversalImage getUniversalImage( ClassLoader classLoader, String filename ) { if ( StringUtils.isBlank( filename ) ) { throw new RuntimeException( "Filename not provided" ); } SwingUniversalImage result = null; if ( SvgSupport.isSvgEnabled() ) { result = getUniversalImageInternal( classLoader, SvgSupport.toSvgName( filename ) ); } // if we haven't loaded SVG attempt to use PNG if ( result == null ) { result = getUniversalImageInternal( classLoader, SvgSupport.toPngName( filename ) ); } // if we can't load PNG, use default "no_image" graphic if ( result == null ) { result = getImageAsResource( NO_IMAGE ); } return result; }
/** * Load image from InputStream as bitmap image, or SVG image conversion to bitmap image. */ private static SwtUniversalImage loadImage( Display display, InputStream in, String filename ) { if ( !SvgSupport.isSvgName( filename ) ) { // bitmap image return new SwtUniversalImageBitmap( new Image( display, in ) ); } else { // svg image - need to convert to bitmap try { return new SwtUniversalImageSvg( SvgSupport.loadSvgImage( in ) ); } catch ( Exception ex ) { throw new RuntimeException( ex ); } } } }
public SwingUniversalImageSvg( SvgImage svg ) { // get GraphicsNode and size from svg document UserAgentAdapter userAgentAdapter = new UserAgentAdapter(); DocumentLoader documentLoader = new DocumentLoader( userAgentAdapter ); BridgeContext ctx = new BridgeContext( userAgentAdapter, documentLoader ); GVTBuilder builder = new GVTBuilder(); svgGraphicsNode = builder.build( ctx, svg.getDocument() ); svgGraphicsSize = ctx.getDocumentSize(); }
if ( SvgSupport.isSvgEnabled() && SvgSupport.isSvgName( fileName ) ) { try { inputStream = new FileInputStream( fileName ); SvgImage svg = SvgSupport.loadSvgImage( inputStream ); image = new SwingUniversalImageSvg( svg ); } catch ( Exception ex ) { fileName = SvgSupport.toPngName( fileName );
/** * Load image from several sources. */ public static SwtUniversalImage getImageAsResource( Display display, String location ) { SwtUniversalImage result = null; if ( result == null && SvgSupport.isSvgEnabled() ) { result = getImageAsResourceInternal( display, SvgSupport.toSvgName( location ) ); } if ( result == null ) { result = getImageAsResourceInternal( display, SvgSupport.toPngName( location ) ); } if ( result == null && !location.equals( NO_IMAGE ) ) { log.logError( "Unable to load image [" + location + "]" ); result = getImageAsResource( display, NO_IMAGE ); } if ( result == null ) { log.logError( "Unable to load image [" + location + "]" ); result = getMissingImage( display ); } return result; }
if ( SvgSupport.isSvgEnabled() && SvgSupport.isSvgName( fileName ) ) { try { inputStream = new FileInputStream( fileName ); SvgImage svg = SvgSupport.loadSvgImage( inputStream ); image = new SwingUniversalImageSvg( svg ); } catch ( Exception ex ) { fileName = SvgSupport.toPngName( fileName );
/** * Load image from several sources. */ public static SwtUniversalImage getUniversalImage( Display display, ClassLoader classLoader, String filename ) { if ( StringUtils.isBlank( filename ) ) { log.logError( "Unable to load image [" + filename + "]" ); return getImageAsResource( display, NO_IMAGE ); } SwtUniversalImage result = null; if ( SvgSupport.isSvgEnabled() ) { result = getUniversalImageInternal( display, classLoader, SvgSupport.toSvgName( filename ) ); } // if we haven't loaded SVG attempt to use PNG if ( result == null ) { result = getUniversalImageInternal( display, classLoader, SvgSupport.toPngName( filename ) ); } // if we can't load PNG, use default "no_image" graphic if ( result == null ) { log.logError( "Unable to load image [" + filename + "]" ); result = getImageAsResource( display, NO_IMAGE ); } return result; }
if ( SvgSupport.isSvgEnabled() && SvgSupport.isSvgName( filename ) ) { SvgImage svg = SvgSupport.loadSvgImage( inputStream ); image = new SwingUniversalImageSvg( svg ); } finally { filename = SvgSupport.toPngName( filename );