Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 256453 Details for
Bug 422139
[Graphics] Move "org.eclipse.ui.images" to eclipse.platform.images git repo and rename to "org.eclipse.images"
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Changes from old repo
Bug-422139-Sync-eclipseimages-changes-with-eplatform.patch (text/plain), 113.72 KB, created by
Tony McCrary
on 2015-09-08 20:40:12 EDT
(
hide
)
Description:
Changes from old repo
Filename:
MIME Type:
Creator:
Tony McCrary
Created:
2015-09-08 20:40:12 EDT
Size:
113.72 KB
patch
obsolete
>diff --git a/org.eclipse.images.renderer/README.md b/org.eclipse.images.renderer/README.md >index 0c15d0f..ca1f778 100644 >--- a/org.eclipse.images.renderer/README.md >+++ b/org.eclipse.images.renderer/README.md >@@ -1,25 +1,25 @@ >-org.eclipse.ui.images.renderer >+org.eclipse.images.renderer > ============================== > >-org.eclipse.ui.images provides the a Maven generator of svg images located in the org.eclipse.ui.images plug-in. >+org.eclipse.images provides the a Maven generator of svg images located in the org.eclipse.images plug-in. > >-org.eclipse.ui.images.renderer plug-in usage >+org.eclipse.images.renderer plug-in usage > -------------------------------------------- > >-Install the org.eclipse.ui.images.renderer plug-in: >+Install the org.eclipse.images.renderer plug-in: > >-cd org.eclipse.ui.images.renderer >+cd org.eclipse.images.renderer > mvn clean install > > After the renderer plugin is installed, change into the root of the images project: > >-cd org.eclipse.ui.images >+cd org.eclipse.images > > Finally, execute the icon render mojo with: > >-mvn org.eclipse.ui:org.eclipse.ui.images.renderer:render-icons >+mvn org.eclipse.images:org.eclipse.images.renderer:render-icons > >-This renders all of the svg icons in "eclipse-svg" into the "eclipse-png" folder of the org.eclipse.ui.images project, maintaining the directory structure (i.e. eclipse-svg/icondir will be rendered into org.eclipse.ui.images/eclipse-png/icondir). >+This renders all of the svg icons in "eclipse-svg" into the "eclipse-png" folder of the org.eclipse.images project, maintaining the directory structure (i.e. eclipse-svg/icondir will be rendered into org.eclipse.images/eclipse-png/icondir). > > Supported runtime arguments (e.g mvn -Declipse.svg.scale=2 ...): > >@@ -30,7 +30,7 @@ > > Once the icon sets have been rendered, you can create galleries for evaluation and feedback with the gallery mojo: > >-mvn org.eclipse.ui:org.eclipse.ui.images.renderer:render-galleries >+mvn org.eclipse.images:org.eclipse.images.renderer:render-galleries > > This will create a set of galleries and gif comparisons comprised of the newly rendered icons, located in the target/ output directory. > >diff --git a/org.eclipse.images.renderer/pom.xml b/org.eclipse.images.renderer/pom.xml >index 2d95d0d..f61dd59 100644 >--- a/org.eclipse.images.renderer/pom.xml >+++ b/org.eclipse.images.renderer/pom.xml >@@ -1,134 +1,117 @@ > <?xml version="1.0" encoding="UTF-8"?> >-<!-- >- (c) Copyright 2013 l33t labs LLC and others. >- All rights reserved. This program and the accompanying materials >- are made available under the terms of the Eclipse Distribution License v1.0 >- which accompanies this distribution, and is available at >- http://www.eclipse.org/org/documents/edl-v10.php >+<!-- (c) Copyright 2013 l33t labs LLC and others. All rights reserved. This >+ program and the accompanying materials are made available under the terms >+ of the Eclipse Distribution License v1.0 which accompanies this distribution, >+ and is available at http://www.eclipse.org/org/documents/edl-v10.php Contributors: >+ Tony McCrary - initial implementation --> >+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> > >- Contributors: >- Tony McCrary - initial implementation >---> >-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> >+ <modelVersion>4.0.0</modelVersion> >+ <groupId>org.eclipse.images</groupId> >+ <artifactId>org.eclipse.images.renderer</artifactId> >+ <version>1.0.100-SNAPSHOT</version> >+ <name>Eclipse Images SVG Renderer Plugin</name> > >- <modelVersion>4.0.0</modelVersion> >- <groupId>org.eclipse.ui</groupId> >- <artifactId>org.eclipse.ui.images.renderer</artifactId> >- <version>1.0.100-SNAPSHOT</version> >- <name>Eclipse Platform SVG Renderer Plugin</name> >+ <packaging>maven-plugin</packaging> > >- <packaging>maven-plugin</packaging> >+ <dependencies> >+ <dependency> >+ <groupId>org.apache.maven</groupId> >+ <artifactId>maven-plugin-api</artifactId> >+ <version>3.0</version> >+ </dependency> >+ <dependency> >+ <groupId>org.apache.maven</groupId> >+ <artifactId>maven-project</artifactId> >+ <version>3.0-alpha-2</version> >+ </dependency> >+ <dependency> >+ <groupId>org.twdata.maven</groupId> >+ <artifactId>mojo-executor</artifactId> >+ <version>2.0</version> >+ </dependency> >+ <!-- Image Filtering Library License: Apache License, Version 2.0 http://www.jhlabs.com/ip/filters/ --> >+ <dependency> >+ <groupId>com.jhlabs</groupId> >+ <artifactId>filters</artifactId> >+ <version>2.0.235-1</version> >+ </dependency> >+ <!-- Advanced Image Scaling Library License: New BSD License https://code.google.com/p/java-image-scaling/ --> >+ <dependency> >+ <groupId>com.mortennobel</groupId> >+ <artifactId>java-image-scaling</artifactId> >+ <version>0.8.5</version> >+ </dependency> >+ <!-- Batik SVG Rendering Library License: Apache License, Version 2.0 http://xmlgraphics.apache.org/batik/ --> >+ <dependency> >+ <groupId>org.apache.xmlgraphics</groupId> >+ <artifactId>batik-rasterizer</artifactId> >+ <version>1.7</version> >+ </dependency> >+ <dependency> >+ <groupId>org.apache.xmlgraphics</groupId> >+ <artifactId>batik-codec</artifactId> >+ <version>1.7</version> >+ </dependency> >+ </dependencies> > >- <dependencies> >- <dependency> >- <groupId>org.apache.maven</groupId> >- <artifactId>maven-plugin-api</artifactId> >- <version>3.0</version> >- </dependency> >- <dependency> >- <groupId>org.apache.maven</groupId> >- <artifactId>maven-project</artifactId> >- <version>3.0-alpha-2</version> >- </dependency> >- <dependency> >- <groupId>org.twdata.maven</groupId> >- <artifactId>mojo-executor</artifactId> >- <version>2.0</version> >- </dependency> >- <!-- >- Image Filtering Library >- License: Apache License, Version 2.0 >- http://www.jhlabs.com/ip/filters/ >- --> >- <dependency> >- <groupId>com.jhlabs</groupId> >- <artifactId>filters</artifactId> >- <version>2.0.235-1</version> >- </dependency> >- <!-- >- Advanced Image Scaling Library >- License: New BSD License >- https://code.google.com/p/java-image-scaling/ >- --> >- <dependency> >- <groupId>com.mortennobel</groupId> >- <artifactId>java-image-scaling</artifactId> >- <version>0.8.5</version> >- </dependency> >- <!-- >- Batik SVG Rendering Library >- License: Apache License, Version 2.0 >- http://xmlgraphics.apache.org/batik/ >- --> >- <dependency> >- <groupId>org.apache.xmlgraphics</groupId> >- <artifactId>batik-rasterizer</artifactId> >- <version>1.7</version> >- </dependency> >- <dependency> >- <groupId>org.apache.xmlgraphics</groupId> >- <artifactId>batik-codec</artifactId> >- <version>1.7</version> >- </dependency> >- </dependencies> >- >- <build> >- <plugins> >- <!-- >- Setup Java 1.7 output >- --> >- <plugin> >- <groupId>org.apache.maven.plugins</groupId> >- <artifactId>maven-compiler-plugin</artifactId> >- <version>2.3.2</version> >- <configuration> >- <source>1.7</source> >- <target>1.7</target> >- </configuration> >- </plugin> >- <plugin> >- <artifactId>maven-plugin-plugin</artifactId> >- <version>2.3</version> >- <configuration> >- <goalPrefix>eclipse-images-renderer</goalPrefix> >- </configuration> >- </plugin> >- </plugins> >- <pluginManagement> >- <plugins> >- <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> >- <plugin> >- <groupId>org.eclipse.m2e</groupId> >- <artifactId>lifecycle-mapping</artifactId> >- <version>1.0.0</version> >- <configuration> >- <lifecycleMappingMetadata> >- <pluginExecutions> >- <pluginExecution> >- <pluginExecutionFilter> >- <groupId> >- org.apache.maven.plugins >- </groupId> >- <artifactId> >- maven-plugin-plugin >- </artifactId> >- <versionRange> >- [2.3,) >- </versionRange> >- <goals> >- <goal>descriptor</goal> >- </goals> >- </pluginExecutionFilter> >- <action> >- <ignore></ignore> >- </action> >- </pluginExecution> >- </pluginExecutions> >- </lifecycleMappingMetadata> >- </configuration> >- </plugin> >- </plugins> >- </pluginManagement> >- </build> >+ <build> >+ <plugins> >+ <!-- Setup Java 1.7 output --> >+ <plugin> >+ <groupId>org.apache.maven.plugins</groupId> >+ <artifactId>maven-compiler-plugin</artifactId> >+ <version>2.3.2</version> >+ <configuration> >+ <source>1.7</source> >+ <target>1.7</target> >+ </configuration> >+ </plugin> >+ <plugin> >+ <artifactId>maven-plugin-plugin</artifactId> >+ <version>2.3</version> >+ <configuration> >+ <goalPrefix>eclipse-images-renderer</goalPrefix> >+ </configuration> >+ </plugin> >+ </plugins> >+ <pluginManagement> >+ <plugins> >+ <!--This plugin's configuration is used to store Eclipse m2e settings >+ only. It has no influence on the Maven build itself. --> >+ <plugin> >+ <groupId>org.eclipse.m2e</groupId> >+ <artifactId>lifecycle-mapping</artifactId> >+ <version>1.0.0</version> >+ <configuration> >+ <lifecycleMappingMetadata> >+ <pluginExecutions> >+ <pluginExecution> >+ <pluginExecutionFilter> >+ <groupId> >+ org.apache.maven.plugins >+ </groupId> >+ <artifactId> >+ maven-plugin-plugin >+ </artifactId> >+ <versionRange> >+ [2.3,) >+ </versionRange> >+ <goals> >+ <goal>descriptor</goal> >+ </goals> >+ </pluginExecutionFilter> >+ <action> >+ <ignore></ignore> >+ </action> >+ </pluginExecution> >+ </pluginExecutions> >+ </lifecycleMappingMetadata> >+ </configuration> >+ </plugin> >+ </plugins> >+ </pluginManagement> >+ </build> > > </project> >diff --git a/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/GalleryMojo.java b/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/GalleryMojo.java >new file mode 100644 >index 0000000..d778e5e >--- /dev/null >+++ b/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/GalleryMojo.java >@@ -0,0 +1,412 @@ >+/******************************************************************************* >+ * (c) Copyright 2015 l33t labs LLC and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * l33t labs LLC and others - initial contribution >+ *******************************************************************************/ >+ >+package org.eclipse.images.renderer; >+ >+import java.awt.Color; >+import java.awt.Graphics2D; >+import java.awt.RenderingHints; >+import java.awt.image.BufferedImage; >+import java.io.File; >+import java.io.IOException; >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.Date; >+import java.util.HashMap; >+import java.util.List; >+import java.util.Map; >+import java.util.Map.Entry; >+ >+import javax.imageio.ImageIO; >+ >+import org.apache.maven.plugin.AbstractMojo; >+import org.apache.maven.plugin.MojoExecutionException; >+import org.apache.maven.plugin.MojoFailureException; >+import org.apache.maven.plugin.logging.Log; >+ >+import com.mortennobel.imagescaling.ResampleFilters; >+import com.mortennobel.imagescaling.ResampleOp; >+ >+/** >+ * <p>Mojo which renders galleries for comparing >+ * and evaluating icons..</p> >+ * >+ * @goal render-galleries >+ * @phase generate-resources >+ */ >+public class GalleryMojo extends AbstractMojo { >+ >+ /** Maven logger */ >+ Log log; >+ >+ /** Used for finding gif files by extension. */ >+ public static final String GIF_EXT = ".gif"; >+ >+ /** Used to specify the directory name where the SVGs are taken from. */ >+ public static final String PNG_DIR = "eclipse.svg.pngdirectory"; >+ >+ /** Used to specify the directory name where the SVGs are taken from. */ >+ public static final String GIF_DIR = "eclipse.svg.gifdirectory"; >+ >+ /** >+ * <p>Mojo takes rendered images and generates various galleries for >+ * testing and evaluation.</p> >+ */ >+ public void execute() throws MojoExecutionException, MojoFailureException { >+ log = getLog(); >+ >+ // Defaults to "eclipse-png" >+ String pngDir = "eclipse-png"; >+ String pngDirProp = System.getProperty(PNG_DIR); >+ if (pngDirProp != null) { >+ pngDir = pngDirProp; >+ } >+ >+ // Defaults to "eclipse-gif" >+ String gifDir = "eclipse-gif"; >+ String gifDirProp = System.getProperty(GIF_DIR); >+ if (gifDirProp != null) { >+ gifDir = gifDirProp; >+ } >+ >+ File iconDirectoryRoot = new File(pngDir + "/"); >+ if (!iconDirectoryRoot.exists()){ >+ log.error("PNG directory' "+pngDir+"' does not exist."); >+ return; >+ } >+ >+ Map<String, List<IconEntry>> galleryIconSets = new HashMap<>(); >+ >+ // Search each subdir in the root dir for svg icons >+ for (File file : iconDirectoryRoot.listFiles()) { >+ if(!file.isDirectory()) { >+ continue; >+ } >+ >+ List<IconEntry> icons = new ArrayList<>(); >+ IconGatherer.gatherIcons(icons, "png", file, file, iconDirectoryRoot, false); >+ >+ galleryIconSets.put(file.getName(), icons); >+ } >+ >+ File mavenTargetDir = new File("target/"); >+ File galleryDir = new File(mavenTargetDir, "gallery/"); >+ File gifCompare = new File(galleryDir, "gifcompare/"); >+ File master = new File(galleryDir, "master/"); >+ >+ if(galleryDir.exists()) { >+ galleryDir.delete(); >+ } >+ >+ galleryDir.mkdirs(); >+ gifCompare.mkdirs(); >+ master.mkdirs(); >+ >+ renderGalleries(galleryDir, gifCompare, master, galleryIconSets, 16, 800, pngDir, gifDir); >+ } >+ >+ /** >+ * <p>Renders each icon set into a gallery image for reviewing and showing off >+ * icons, and then composes them into a master gallery image.</p> >+ * >+ * @param rasterizer >+ * @param galleryDir >+ * @param gifCompare >+ * @param master >+ * @param iconSize >+ * @param width >+ * @param pngDir >+ * @param gifDir >+ */ >+ public void renderGalleries(File galleryDir, File gifCompare, File master, Map<String, List<IconEntry>> iconSets, int iconSize, int width, String pngDir, String gifDir) { >+ // Render each icon set and a master list >+ List<IconEntry> masterList = new ArrayList<>(); >+ >+ for (Entry<String, List<IconEntry>> entry : iconSets.entrySet()) { >+ String key = entry.getKey(); >+ List<IconEntry> value = entry.getValue(); >+ >+ masterList.addAll(value); >+ >+ log.info("Creating gallery for: " + key); >+ renderGallery(galleryDir, key, value, iconSize, width, 3); >+ renderGifCompareGallery(gifCompare, key, value, iconSize, width, 6, pngDir, gifDir); >+ } >+ >+ // Render the master image >+ log.info("Rendering master icon gallery..."); >+ renderMasterGallery(galleryDir, master, "-gallery.png", iconSize, iconSize + width, true); >+ renderMasterGallery(galleryDir, master, "-gallery.png", iconSize, iconSize + width, false); >+ >+ // Master gif compare >+ //renderMasterGallery(outputDir, "-gifcompare.png", iconSize, iconSize + width, false); >+ } >+ >+ /** >+ * <p>Renders comparison images, the new png/svg icons vs old gifs.</p> >+ * >+ * @param outputDir >+ * @param key >+ * @param icons >+ * @param iconSize >+ * @param width >+ * @param margin >+ * @param pngDir >+ * @param gifDir >+ */ >+ private void renderGifCompareGallery(File outputDir, String key, List<IconEntry> icons, int iconSize, int width, int margin, String pngDir, String gifDir) { >+ int leftColumnWidth = 300; >+ int textHeaderHeight = 31; >+ int outputSize = iconSize; >+ int widthTotal = (outputSize * 4) + (margin * 6) + leftColumnWidth; >+ >+ int rowHeight = iconSize + (margin * 2); >+ >+ // Compute the height and add some room for the text header (31 px) >+ int height = (icons.size() * rowHeight) + textHeaderHeight; >+ >+ BufferedImage bi = new BufferedImage(widthTotal + iconSize, height, >+ BufferedImage.TYPE_INT_ARGB); >+ Graphics2D g = bi.createGraphics(); >+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, >+ RenderingHints.VALUE_ANTIALIAS_ON); >+ >+ g.setColor(Color.GRAY); >+ g.drawString("SVG Icon Set: " + key + " - Count: " + icons.size(), 8, 20); >+ >+ int x = leftColumnWidth; >+ int y = textHeaderHeight; >+ >+ // Render >+ ResampleOp resampleOp = new ResampleOp(outputSize, outputSize); >+ resampleOp.setFilter(ResampleFilters.getLanczos3Filter()); >+ // resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Oversharpened); >+ resampleOp.setNumberOfThreads(Runtime.getRuntime() >+ .availableProcessors()); >+ >+ int second = leftColumnWidth + margin + iconSize; >+ >+ g.setColor(Color.WHITE); >+ g.fillRect(0, 0, widthTotal + 10, height); >+ >+ g.setColor(Color.DARK_GRAY); >+ g.fillRect(second + (margin / 2) + iconSize + 20, 0, (margin * 2) + (iconSize * 2) + 10, height); >+ >+ g.drawString(key + " (GIF / PNG)", 15, 20); >+ >+ Collections.sort(icons); >+ >+ // Render each icon into the gallery grid >+ for (IconEntry entry : icons) { >+ >+ if (entry.inputPath == null) { >+ continue; >+ } >+ >+ try { >+ BufferedImage pngImage = ImageIO.read(entry.inputPath); >+ >+ // Munge the gif path >+ File gifLocalPath = new File(entry.inputPath.getParentFile(), entry.nameBase + GIF_EXT); >+ String absoluteLocalPath = gifLocalPath.getAbsolutePath(); >+ String gifAbsPath = absoluteLocalPath.replaceFirst(pngDir, gifDir); >+ File gifPath = new File(gifAbsPath); >+ >+ log.debug("Search for GIF..."); >+ log.debug("Entry path: " + entry.inputPath.getAbsolutePath()); >+ log.debug("GIF path: " + gifPath.getAbsolutePath()); >+ >+ BufferedImage gifImage = null; >+ >+ if(gifPath.exists()) { >+ gifImage = ImageIO.read(gifPath); >+ } else { >+ log.debug("GIF not found: " + gifPath.getAbsolutePath()); >+ } >+ >+ g.drawString(entry.nameBase, 5, y + (margin * 3)); >+ >+ g.drawLine(0, y, widthTotal, y); >+ >+ if(gifImage != null) { >+ g.drawImage(gifImage, leftColumnWidth, y + margin, null); >+ } >+ >+ g.drawImage(pngImage, second, y + margin, null); >+ >+ if(gifImage != null) { >+ g.drawImage(gifImage, second + margin + iconSize + 30, y + margin, null); >+ } >+ >+ g.drawImage(pngImage, second + (margin * 2) + (iconSize * 2) + 30, y + margin, null); >+ >+ y += iconSize + margin * 2; >+ } catch (Exception e) { >+ e.printStackTrace(); >+ log.error("Error rendering icon for gallery: " + entry.inputPath.getAbsolutePath()); >+ continue; >+ } >+ } >+ >+ try { >+ // Write the gallery image to disk >+ String outputName = key + "-" + iconSize + "-gifcompare.png"; >+ ImageIO.write(bi, "PNG", new File(outputDir, outputName)); >+ } catch (IOException e) { >+ e.printStackTrace(); >+ log.error("Error writing gif comparison gallery: " + e.getMessage()); >+ } >+ } >+ >+ >+ /** >+ * <p>Renders an icon set into a grid within an image.</p> >+ * >+ * @param outputRoot >+ * @param key >+ * @param icons >+ */ >+ private void renderGallery(File outputRoot, String key, List<IconEntry> icons, >+ int iconSize, int width, int margin) { >+ int textHeaderHeight = 31; >+ int outputSize = iconSize; >+ int outputTotal = outputSize + (margin * 2); >+ int div = width / outputTotal; >+ int rowCount = icons.size() / div; >+ >+ if (width % outputTotal > 0) { >+ rowCount++; >+ } >+ >+ // Compute the height and add some room for the text header (31 px) >+ int height = Math.max(outputTotal, rowCount * outputTotal) >+ + textHeaderHeight; >+ >+ BufferedImage bi = new BufferedImage(width + iconSize, height, >+ BufferedImage.TYPE_INT_ARGB); >+ Graphics2D g = bi.createGraphics(); >+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, >+ RenderingHints.VALUE_ANTIALIAS_ON); >+ >+ g.setColor(Color.GRAY); >+ g.drawString("SVG Icon Set: " + key + " - Count: " + icons.size(), 8, 20); >+ >+ int x = 1; >+ int y = textHeaderHeight; >+ >+ // Render >+ ResampleOp resampleOp = new ResampleOp(outputSize, outputSize); >+ resampleOp.setFilter(ResampleFilters.getLanczos3Filter()); >+ // resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Oversharpened); >+ resampleOp.setNumberOfThreads(Runtime.getRuntime().availableProcessors()); >+ >+ // Render each icon into the gallery grid >+ for (IconEntry def : icons) { >+ try { >+ if (def.inputPath == null) { >+ log.error("Undefined gallery image for : " + def.nameBase); >+ continue; >+ } >+ >+ BufferedImage iconImage = ImageIO.read(def.inputPath); >+ BufferedImage sizedImage = resampleOp.filter(iconImage, null); >+ >+ g.drawImage(sizedImage, x + margin, y + margin, null); >+ >+ x += outputTotal; >+ >+ if (x >= width) { >+ x = 1; >+ y += outputTotal; >+ } >+ } catch (Exception e) { >+ log.error("Error rendering icon for gallery: " + def.inputPath.getAbsolutePath()); >+ e.printStackTrace(); >+ continue; >+ } >+ } >+ >+ try { >+ // Write the gallery image to disk >+ String outputName = key + "-" + iconSize + "-gallery.png"; >+ ImageIO.write(bi, "PNG", new File(outputRoot, outputName)); >+ } catch (IOException e) { >+ log.error("Error writing icon: " + e.getMessage()); >+ e.printStackTrace(); >+ } >+ } >+ >+ /** >+ * <p>Renders a master gallery image that contains every icon set at the >+ * current resolution.</p> >+ * >+ * @param root >+ * @param iconSize >+ * @param width >+ * @param dark >+ */ >+ private void renderMasterGallery(File root, File output, String fileEnding, int iconSize, int width, >+ boolean dark) { >+ int headerHeight = 30; >+ List<BufferedImage> images = new ArrayList<>(); >+ for (File file : root.listFiles()) { >+ if (file.getName().endsWith(iconSize + fileEnding)) { >+ BufferedImage set = null; >+ try { >+ set = ImageIO.read(file); >+ } catch (IOException e) { >+ log.error("Error reading icon: " + e.getMessage()); >+ e.printStackTrace(); >+ continue; >+ } >+ images.add(set); >+ headerHeight += set.getHeight(); >+ } >+ } >+ >+ BufferedImage bi = new BufferedImage(width, headerHeight, >+ BufferedImage.TYPE_INT_ARGB); >+ Graphics2D g = bi.createGraphics(); >+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, >+ RenderingHints.VALUE_ANTIALIAS_ON); >+ >+ if (dark) { >+ g.setColor(Color.DARK_GRAY); >+ } else { >+ g.setColor(Color.WHITE); >+ } >+ g.fillRect(0, 0, bi.getWidth(), bi.getHeight()); >+ >+ g.setColor(Color.BLACK); >+ g.drawString("SVG Icons for Eclipse - Count: " >+ + iconSize + "x" + iconSize >+ + " Rendered: " + new Date().toString(), 8, 20); >+ >+ int x = 0; >+ int y = 31; >+ >+ // Draw each icon set image into the uber gallery >+ for (BufferedImage image : images) { >+ g.drawImage(image, x, y, null); >+ y += image.getHeight(); >+ } >+ >+ try { >+ // Write the uber gallery to disk >+ String bgState = (dark) ? "dark" : "light"; >+ String outputName = "global-svg-" + iconSize + "-" + bgState + fileEnding + "-icons.png"; >+ ImageIO.write(bi, "PNG", new File(output, outputName)); >+ } catch (IOException e) { >+ log.error("Error writing gallery: " + e.getMessage()); >+ e.printStackTrace(); >+ } >+ } >+} >diff --git a/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/IconEntry.java b/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/IconEntry.java >new file mode 100644 >index 0000000..4674d79 >--- /dev/null >+++ b/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/IconEntry.java >@@ -0,0 +1,60 @@ >+/******************************************************************************* >+ * (c) Copyright 2015 l33t labs LLC and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * l33t labs LLC and others - initial contribution >+ *******************************************************************************/ >+ >+package org.eclipse.images.renderer; >+ >+import java.io.File; >+ >+/** >+ * <p>IconEntry is used to define an icon to rasterize, >+ * where to put it and the dimensions to render it at.</p> >+ */ >+class IconEntry implements Comparable<IconEntry> { >+ >+ /** The name of the icon minus extension */ >+ String nameBase; >+ >+ /** The input path of the source svg files. */ >+ File inputPath; >+ >+ /** The sizes this icon should be rendered at */ >+ int[] sizes; >+ >+ /** >+ * The path rasterized versions of this icon should be written into. >+ */ >+ File outputPath; >+ >+ /** The path to a disabled version of the icon (gets desaturated). */ >+ File disabledPath; >+ >+ /** >+ * >+ * @param nameBase >+ * @param inputPath >+ * @param outputPath >+ * @param disabledPath >+ * @param sizes >+ */ >+ public IconEntry(String nameBase, File inputPath, File outputPath, >+ File disabledPath, int[] sizes) { >+ this.nameBase = nameBase; >+ this.sizes = sizes; >+ this.inputPath = inputPath; >+ this.outputPath = outputPath; >+ this.disabledPath = disabledPath; >+ } >+ >+ @Override >+ public int compareTo(IconEntry o) { >+ return nameBase.compareTo(o.nameBase); >+ } >+} >\ No newline at end of file >diff --git a/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/IconGatherer.java b/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/IconGatherer.java >new file mode 100644 >index 0000000..13947ca >--- /dev/null >+++ b/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/IconGatherer.java >@@ -0,0 +1,119 @@ >+/******************************************************************************* >+ * (c) Copyright 2015 l33t labs LLC and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * l33t labs LLC and others - initial contribution >+ *******************************************************************************/ >+ >+package org.eclipse.images.renderer; >+ >+import java.io.File; >+import java.net.URI; >+import java.util.List; >+ >+/** >+ * <p>Utility to find and organize icons for rendering.</p> >+ * >+ * @author tmccrary@l33tlabs.com >+ * >+ */ >+public class IconGatherer { >+ >+ /** >+ * <p>Searches the root resources directory for svg icons and adds them to a >+ * collection for later rasterization.</p> >+ * >+ * @param outputName >+ * @param iconDir >+ * @param outputBase >+ * @param outputDir2 >+ */ >+ public static void gatherIcons(List<IconEntry> icons, String extension, File rootDir, File iconDir, File outputBase, boolean generateDisabledDirs) { >+ File[] listFiles = iconDir.listFiles(); >+ >+ for (File child : listFiles) { >+ if (child.isDirectory()) { >+ if(child.getName().startsWith("d")) { >+ continue; >+ } >+ >+ gatherIcons(icons, extension, rootDir, child, outputBase, generateDisabledDirs); >+ continue; >+ } >+ >+ if (!child.getName().endsWith(extension)) { >+ continue; >+ } >+ >+ // Compute a relative path for the output dir >+ URI rootUri = rootDir.toURI(); >+ URI iconUri = iconDir.toURI(); >+ >+ String relativePath = rootUri.relativize(iconUri).getPath(); >+ File outputDir = new File(outputBase, relativePath); >+ File disabledOutputDir = null; >+ >+ File parentFile = child.getParentFile(); >+ >+ /* Determine if/where to put a disabled version of the icon >+ Eclipse traditionally uses a prefix of d for disabled, e for >+ enabled in the folder name */ >+ if (generateDisabledDirs && parentFile != null) { >+ String parentDirName = parentFile.getName(); >+ if (parentDirName.startsWith("e")) { >+ StringBuilder builder = new StringBuilder(); >+ builder.append("d"); >+ builder.append(parentDirName.substring(1, parentDirName.length())); >+ >+ // Disabled variant folder name >+ String disabledVariant = builder.toString(); >+ >+ // The parent's parent, to create the disabled directory in >+ File setParent = parentFile.getParentFile(); >+ >+ // The source directory's disabled folder >+ File disabledSource = new File(setParent, disabledVariant); >+ >+ // Compute a relative path, so we can create the output folder >+ String path = rootUri.relativize( >+ disabledSource.toURI()).getPath(); >+ >+ // Create the output folder, so a disabled icon is generated >+ disabledOutputDir = new File(outputBase, path); >+ if(!disabledOutputDir.exists()) { >+ disabledOutputDir.mkdirs(); >+ } >+ } >+ } >+ >+ IconEntry icon = createIcon(child, outputDir, disabledOutputDir); >+ >+ icons.add(icon); >+ } >+ } >+ >+ /** >+ * <p>Creates an IconEntry, which contains information about rendering an icon such >+ * as the source file, where to render, what alternative types of output to >+ * generate, etc.</p> >+ * >+ * @param input the source of the icon file (SVG document) >+ * @param outputPath the path of the rasterized version to generate >+ * @param disabledPath the path of the disabled (desaturated) icon, if one is required >+ * >+ * @return an IconEntry describing the rendering operation >+ */ >+ public static IconEntry createIcon(File input, File outputPath, File disabledPath) { >+ String name = input.getName(); >+ String[] split = name.split("\\.(?=[^\\.]+$)"); >+ >+ IconEntry def = new IconEntry(split[0], input, outputPath, disabledPath, new int[0]); >+ >+ return def; >+ } >+ >+} >diff --git a/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/RenderMojo.java b/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/RenderMojo.java >new file mode 100644 >index 0000000..1044f96 >--- /dev/null >+++ b/org.eclipse.images.renderer/src/main/java/org/eclipse/images/renderer/RenderMojo.java >@@ -0,0 +1,647 @@ >+/******************************************************************************* >+ * (c) Copyright 2015 l33t labs LLC and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * l33t labs LLC and others - initial contribution >+ *******************************************************************************/ >+ >+package org.eclipse.images.renderer; >+ >+import java.awt.RenderingHints; >+import java.awt.image.BufferedImage; >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.FileWriter; >+import java.io.IOException; >+import java.io.OutputStream; >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+import java.util.concurrent.Callable; >+import java.util.concurrent.ExecutorService; >+import java.util.concurrent.Executors; >+import java.util.concurrent.atomic.AtomicInteger; >+ >+import javax.imageio.ImageIO; >+ >+import org.apache.batik.dom.svg.SAXSVGDocumentFactory; >+import org.apache.batik.gvt.renderer.ImageRenderer; >+import org.apache.batik.transcoder.ErrorHandler; >+import org.apache.batik.transcoder.TranscoderException; >+import org.apache.batik.transcoder.TranscoderInput; >+import org.apache.batik.transcoder.TranscoderOutput; >+import org.apache.batik.transcoder.image.PNGTranscoder; >+import org.apache.batik.util.XMLResourceDescriptor; >+import org.apache.maven.plugin.AbstractMojo; >+import org.apache.maven.plugin.MojoExecutionException; >+import org.apache.maven.plugin.MojoFailureException; >+import org.apache.maven.plugin.logging.Log; >+import org.w3c.dom.Element; >+import org.w3c.dom.svg.SVGDocument; >+ >+import com.jhlabs.image.ContrastFilter; >+import com.jhlabs.image.GrayscaleFilter; >+import com.jhlabs.image.HSBAdjustFilter; >+ >+/** >+ * <p>Mojo which renders SVG icons into PNG format.</p> >+ * >+ * @goal render-icons >+ * @phase generate-resources >+ */ >+public class RenderMojo extends AbstractMojo { >+ >+ /** Maven logger */ >+ Log log; >+ >+ /** Used for high res rendering support. */ >+ public static final String ECLIPSE_SVG_SCALE = "eclipse.svg.scale"; >+ >+ /** Used to specify the number of render threads when rasterizing icons. */ >+ public static final String RENDERTHREADS = "eclipse.svg.renderthreads"; >+ >+ /** Used to specify the directory name where the SVGs are taken from. */ >+ public static final String SOURCE_DIR = "eclipse.svg.sourcedirectory"; >+ >+ /** Used to specify the directory name where the PNGs are saved to. */ >+ public static final String TARGET_DIR = "eclipse.svg.targetdirectory"; >+ >+ /** A list of directories with svg sources to rasterize. */ >+ private List<IconEntry> icons; >+ >+ /** The pool used to render multiple icons concurrently. */ >+ private ExecutorService execPool; >+ >+ /** The number of threads to use when rendering icons. */ >+ private int threads; >+ >+ /** >+ * A counter used to keep track of the number of rendered icons. Atomic is >+ * used to make it easy to access between threads concurrently. >+ */ >+ private AtomicInteger counter; >+ >+ /** List of icons that failed to render, made safe for parallel access */ >+ List<IconEntry> failedIcons = Collections >+ .synchronizedList(new ArrayList<IconEntry>(5)); >+ >+ /** The amount of scaling to apply to rasterized images. */ >+ private double outputScale; >+ >+ /** >+ * @return the number of icons rendered at the time of the call >+ */ >+ public int getIconsRendered() { >+ return counter.get(); >+ } >+ >+ /** >+ * @return the number of icons that failed during the rendering process >+ */ >+ public int getFailedIcons() { >+ return failedIcons.size(); >+ } >+ >+ /** >+ * <p>Generates raster images from the input SVG vector image.</p> >+ * >+ * @param icon >+ * the icon to render >+ */ >+ public void rasterize(IconEntry icon, GrayscaleFilter grayFilter, HSBAdjustFilter desaturator, ContrastFilter decontrast) { >+ if (icon == null) { >+ log.error("Null icon definition, skipping."); >+ failedIcons.add(icon); >+ return; >+ } >+ >+ if (icon.inputPath == null) { >+ log.error("Null icon input path, skipping: " >+ + icon.nameBase); >+ failedIcons.add(icon); >+ return; >+ } >+ >+ if (!icon.inputPath.exists()) { >+ log.error("Input path specified does not exist, skipping: " >+ + icon.nameBase); >+ failedIcons.add(icon); >+ return; >+ } >+ >+ if (icon.outputPath != null && !icon.outputPath.exists()) { >+ icon.outputPath.mkdirs(); >+ } >+ >+ if (icon.disabledPath != null && !icon.disabledPath.exists()) { >+ icon.disabledPath.mkdirs(); >+ } >+ >+ // Create the document to rasterize >+ SVGDocument svgDocument = generateSVGDocument(icon); >+ >+ if(svgDocument == null) { >+ return; >+ } >+ >+ // Determine the output sizes (native, double, quad) >+ // We render at quad size and resample down for output >+ Element svgDocumentNode = svgDocument.getDocumentElement(); >+ String nativeWidthStr = svgDocumentNode.getAttribute("width"); >+ String nativeHeightStr = svgDocumentNode.getAttribute("height"); >+ int nativeWidth = -1; >+ int nativeHeight = -1; >+ >+ try{ >+ if (nativeWidthStr != "" && nativeHeightStr != ""){ >+ nativeWidth = Integer.parseInt(nativeWidthStr); >+ nativeHeight = Integer.parseInt(nativeHeightStr); >+ } else { >+ // Vector graphics editing programs don't always output height and width attributes on SVG. >+ // As fall back: parse the viewBox attribute (which is almost always set). >+ String viewBoxStr = svgDocumentNode.getAttribute("viewBox"); >+ if (viewBoxStr == ""){ >+ log.error("Icon defines neither width/height nor a viewBox, skipping: " + icon.nameBase); >+ failedIcons.add(icon); >+ return; >+ } >+ String[] splitted = viewBoxStr.split(" "); >+ String xStr = splitted[0]; >+ String yStr = splitted[1]; >+ String widthStr = splitted[2]; >+ String heightStr = splitted[3]; >+ nativeWidth = Integer.parseInt(widthStr) - Integer.parseInt(xStr); >+ nativeHeight = Integer.parseInt(heightStr) - Integer.parseInt(yStr); >+ } >+ }catch (NumberFormatException e){ >+ log.error("Dimension could not be parsed ( "+e.getMessage()+ "), skipping: " + icon.nameBase); >+ failedIcons.add(icon); >+ return; >+ } >+ >+ int outputWidth = (int) (nativeWidth * outputScale); >+ int outputHeight = (int) (nativeHeight * outputScale); >+ >+ // Guesstimate the PNG size in memory, BAOS will enlarge if necessary. >+ int outputInitSize = nativeWidth * nativeHeight * 4 + 1024; >+ ByteArrayOutputStream iconOutput = new ByteArrayOutputStream( >+ outputInitSize); >+ >+ // Render to SVG >+ try { >+ log.info(Thread.currentThread().getName() + " " >+ + " Rasterizing: " + icon.nameBase + ".png at " + outputWidth >+ + "x" + outputHeight); >+ >+ TranscoderInput svgInput = new TranscoderInput(svgDocument); >+ >+ boolean success = renderIcon(icon.nameBase, outputWidth, outputHeight, svgInput, iconOutput); >+ >+ if (!success) { >+ log.error("Failed to render icon: " + icon.nameBase + ".png, skipping."); >+ failedIcons.add(icon); >+ return; >+ } >+ } catch (Exception e) { >+ log.error("Failed to render icon: " + e.getMessage()); >+ failedIcons.add(icon); >+ return; >+ } >+ >+ // Generate a buffered image from Batik's png output >+ byte[] imageBytes = iconOutput.toByteArray(); >+ ByteArrayInputStream imageInputStream = new ByteArrayInputStream(imageBytes); >+ >+ BufferedImage inputImage = null; >+ try { >+ inputImage = ImageIO.read(imageInputStream); >+ >+ if(inputImage == null) { >+ log.error("Failed to generate BufferedImage from rendered icon, ImageIO returned null: " + icon.nameBase); >+ failedIcons.add(icon); >+ return; >+ } >+ } catch (IOException e2) { >+ log.error("Failed to generate BufferedImage from rendered icon: " + icon.nameBase + " - " + e2.getMessage()); >+ failedIcons.add(icon); >+ return; >+ } >+ >+ writeIcon(icon, outputWidth, outputHeight, inputImage); >+ >+ try { >+ if (icon.disabledPath != null) { >+ BufferedImage desaturated16 = desaturator.filter( >+ grayFilter.filter(inputImage, null), null); >+ >+ BufferedImage deconstrast = decontrast.filter(desaturated16, null); >+ >+ ImageIO.write(deconstrast, "PNG", new File(icon.disabledPath, icon.nameBase + ".png")); >+ } >+ } catch (Exception e1) { >+ log.error("Failed to render disabled icon: " + >+ icon.nameBase, e1); >+ failedIcons.add(icon); >+ } >+ } >+ >+ /** >+ * <p>Generates a Batik SVGDocument for the supplied IconEntry's input >+ * file.</p> >+ * >+ * @param icon the icon entry to generate an SVG document for >+ * >+ * @return a batik SVGDocument instance or null if one could not be generated >+ */ >+ private SVGDocument generateSVGDocument(IconEntry icon) { >+ // Load the document and find out the native height/width >+ // We reuse the document later for rasterization >+ SVGDocument svgDocument = null; >+ try { >+ FileInputStream iconDocumentStream = new FileInputStream(icon.inputPath); >+ >+ String parser = XMLResourceDescriptor.getXMLParserClassName(); >+ SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); >+ >+ // What kind of URI is batik expecting here??? the docs don't say >+ svgDocument = f.createSVGDocument("file://" + icon.nameBase + ".svg", iconDocumentStream); >+ } catch (Exception e3) { >+ log.error("Error parsing SVG icon document: " + e3.getMessage()); >+ failedIcons.add(icon); >+ return null; >+ } >+ return svgDocument; >+ } >+ >+ /** >+ * <p>Resizes the supplied inputImage to the specified width and height, using >+ * lanczos resampling techniques.</p> >+ * >+ * @param icon the icon that's being resized >+ * @param width the desired output width after rescaling operations >+ * @param height the desired output height after rescaling operations >+ * @param sourceImage the source image to resource >+ */ >+ private void writeIcon(IconEntry icon, int width, int height, BufferedImage sourceImage) { >+ try { >+ String outputName = icon.nameBase; >+ if (outputScale != 1) { >+ String scaleId = outputScale == (double) (int) outputScale ? Integer.toString((int) outputScale): Double.toString(outputScale); >+ outputName += "@" + scaleId + "x"; >+ } >+ outputName += ".png"; >+ ImageIO.write(sourceImage, "PNG", new File(icon.outputPath, outputName)); >+ } catch (Exception e1) { >+ log.error("Failed to resize rendered icon to output size: " + >+ icon.nameBase, e1); >+ failedIcons.add(icon); >+ } >+ } >+ >+ /** >+ * <p>Handles concurrently rasterizing the icons to >+ * reduce the duration on multicore systems.</p> >+ */ >+ public void rasterizeAll() { >+ // The number of icons that haven't been distributed to >+ // callables >+ int remainingIcons = icons.size(); >+ >+ // The number of icons to distribute to a rendering callable >+ final int threadExecSize = Math.max(1, icons.size() / this.threads); >+ >+ // The current offset to start a batch, as they're distributed >+ // between rendering callables >+ int batchOffset = 0; >+ >+ // A list of callables used to render icons on multiple threads >+ // Each callable gets a set of icons to render >+ List<Callable<Object>> tasks = new ArrayList<>( >+ this.threads); >+ >+ // Distribute the rasterization operations between multiple threads >+ while (remainingIcons > 0) { >+ // The current start index for the current batch >+ final int batchStart = batchOffset; >+ >+ // Increment the offset to reflect this batch (used for the next batch) >+ batchOffset += threadExecSize; >+ >+ // Determine this batch size, used for batches that have less than >+ // threadExecSize at the end of the distribution operation >+ int batchSize = 0; >+ >+ // Determine if we can fit a full batch in this callable >+ // or if we are at the end of gathered icons >+ if (remainingIcons > threadExecSize) { >+ batchSize = threadExecSize; >+ } else { >+ // We have less than a full batch worth of remaining icons >+ // just add them all >+ batchSize = remainingIcons; >+ } >+ >+ // Deincrement the remaining Icons >+ remainingIcons -= threadExecSize; >+ >+ // Used for access in the callable's scope >+ final int execCount = batchSize; >+ >+ // Create the callable and add it to the task pool >+ Callable<Object> runnable = new Callable<Object>() { >+ @Override >+ public Object call() throws Exception { >+ // The jhlabs filters are not thread safe, so provide one set per thread >+ GrayscaleFilter grayFilter = new GrayscaleFilter(); >+ >+ HSBAdjustFilter desaturator = new HSBAdjustFilter(); >+ desaturator.setSFactor(0.0f); >+ >+ ContrastFilter decontrast = new ContrastFilter(); >+ decontrast.setBrightness(2.9f); >+ decontrast.setContrast(0.2f); >+ >+ // Rasterize this batch >+ for (int count = 0; count < execCount; count++) { >+ rasterize(icons.get(batchStart + count), grayFilter, desaturator, decontrast); >+ } >+ >+ // Update the render counter >+ counter.getAndAdd(execCount); >+ log.info("Finished rendering batch, index: " + batchStart); >+ >+ return null; >+ } >+ }; >+ >+ tasks.add(runnable); >+ } >+ >+ // Execute the rasterization operations that >+ // have been added to the pool >+ try { >+ execPool.invokeAll(tasks); >+ } catch (InterruptedException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ >+ // Print info about failed render operations, so they can be fixed >+ log.info("Failed Icon Count: " + failedIcons.size()); >+ for (IconEntry icon : failedIcons) { >+ log.info("Failed Icon: " + icon.nameBase); >+ } >+ >+ } >+ >+ /** >+ * Use batik to rasterize the input SVG into a raster image at the specified >+ * image dimensions. >+ * >+ * @param width the width to render the icons at >+ * @param height the height to render the icon at >+ * @param input the SVG transcoder input >+ * @param stream the stream to write the PNG data to >+ */ >+ public boolean renderIcon(final String iconName, int width, int height, >+ TranscoderInput tinput, OutputStream stream) { >+ PNGTranscoder transcoder = new PNGTranscoder() { >+ protected ImageRenderer createRenderer() { >+ ImageRenderer renderer = super.createRenderer(); >+ >+ RenderingHints renderHints = renderer.getRenderingHints(); >+ >+ renderHints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, >+ RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)); >+ >+ renderHints.add(new RenderingHints(RenderingHints.KEY_RENDERING, >+ RenderingHints.VALUE_RENDER_QUALITY)); >+ >+ renderHints.add(new RenderingHints(RenderingHints.KEY_DITHERING, >+ RenderingHints.VALUE_DITHER_DISABLE)); >+ >+ renderHints.add(new RenderingHints(RenderingHints.KEY_INTERPOLATION, >+ RenderingHints.VALUE_INTERPOLATION_BICUBIC)); >+ >+ renderHints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION, >+ RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)); >+ >+ renderHints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, >+ RenderingHints.VALUE_ANTIALIAS_ON)); >+ >+ renderHints.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, >+ RenderingHints.VALUE_COLOR_RENDER_QUALITY)); >+ >+ renderHints.add(new RenderingHints(RenderingHints.KEY_STROKE_CONTROL, >+ RenderingHints.VALUE_STROKE_PURE)); >+ >+ renderHints.add(new RenderingHints(RenderingHints.KEY_FRACTIONALMETRICS, >+ RenderingHints.VALUE_FRACTIONALMETRICS_ON)); >+ >+ renderer.setRenderingHints(renderHints); >+ >+ return renderer; >+ } >+ }; >+ >+ transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width)); >+ transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(height)); >+ >+ transcoder.setErrorHandler(new ErrorHandler() { >+ public void warning(TranscoderException arg0) >+ throws TranscoderException { >+ log.error("Icon: " + iconName + " - WARN: " + arg0.getMessage()); >+ } >+ >+ public void fatalError(TranscoderException arg0) >+ throws TranscoderException { >+ log.error("Icon: " + iconName + " - FATAL: " + arg0.getMessage()); >+ } >+ >+ public void error(TranscoderException arg0) >+ throws TranscoderException { >+ log.error("Icon: " + iconName + " - ERROR: " + arg0.getMessage()); >+ } >+ }); >+ >+ // Transcode the SVG document input to a PNG via the output stream >+ TranscoderOutput output = new TranscoderOutput(stream); >+ >+ try { >+ transcoder.transcode(tinput, output); >+ return true; >+ } catch (Exception e) { >+ e.printStackTrace(); >+ return false; >+ } finally { >+ try { >+ stream.close(); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ } >+ >+ /** >+ * <p>Initializes rasterizer defaults</p> >+ * >+ * @param threads the number of threads to render with >+ * @param scale multiplier to use with icon output dimensions >+ */ >+ private void init(int threads, double scale) { >+ this.threads = threads; >+ this.outputScale = Math.max(1, scale); >+ icons = new ArrayList<>(); >+ execPool = Executors.newFixedThreadPool(threads); >+ counter = new AtomicInteger(); >+ } >+ >+ /** >+ * @see AbstractMojo#execute() >+ */ >+ public void execute() throws MojoExecutionException, MojoFailureException { >+ log = getLog(); >+ >+ // Default to 2x the number of processor cores but allow override via jvm arg >+ int threads = Math.max(1, Runtime.getRuntime().availableProcessors() * 2); >+ String threadStr = System.getProperty(RENDERTHREADS); >+ if (threadStr != null) { >+ try { >+ threads = Integer.parseInt(threadStr); >+ } catch (Exception e) { >+ e.printStackTrace(); >+ System.out >+ .println("Could not parse thread count, using default thread count"); >+ } >+ } >+ >+ // if high res is enabled, the icons output size will be scaled by iconScale >+ // Defaults to 1, meaning native size >+ double iconScale = 1; >+ String iconScaleStr = System.getProperty(ECLIPSE_SVG_SCALE); >+ if (iconScaleStr != null) { >+ iconScale = Double.parseDouble(iconScaleStr); >+ if (iconScale != 1 && iconScale != 1.5 && iconScale != 2) { >+ log.warn("Unusual scale factor: " + iconScaleStr + " (@" + iconScale + "x)"); >+ } >+ } >+ >+ // Defaults to "eclipse-svg" >+ String sourceDir = "eclipse-svg"; >+ String sourceDirProp = System.getProperty(SOURCE_DIR); >+ if (sourceDirProp != null) { >+ sourceDir = sourceDirProp; >+ } >+ >+ // Defaults to "eclipse-png" >+ String targetDir = "eclipse-png"; >+ String targetDirProp = System.getProperty(TARGET_DIR); >+ if (targetDirProp != null) { >+ targetDir = targetDirProp; >+ } >+ >+ // Track the time it takes to render the entire set >+ long totalStartTime = System.currentTimeMillis(); >+ >+ // initialize defaults (the old renderer was instantiated via constructor) >+ init(threads, iconScale); >+ >+ String workingDirectory = System.getProperty("user.dir"); >+ >+ File outputDir = new File(workingDirectory + (iconScale == 1 ? "/" + targetDir + "/" : "/" + targetDir + "-highdpi/")); >+ File iconDirectoryRoot = new File(sourceDir + "/"); >+ >+ if (!iconDirectoryRoot.exists()){ >+ log.error("Source directory' "+sourceDir+"' does not exist."); >+ return; >+ } >+ >+ // Search each subdir in the root dir for svg icons >+ for (File file : iconDirectoryRoot.listFiles()) { >+ if(!file.isDirectory()) { >+ continue; >+ } >+ >+ String dirName = file.getName(); >+ >+ // Where to place the rendered icon >+ File outputBase = new File(outputDir, (iconScale == 1 ? dirName : dirName + ".highdpi")); >+ if (iconScale != 1) { >+ createFragmentFiles(outputBase, dirName); >+ } >+ >+ IconGatherer.gatherIcons(icons, "svg", file, file, outputBase, true); >+ } >+ >+ log.info("Working directory: " + outputDir.getAbsolutePath()); >+ log.info("SVG Icon Directory: " + iconDirectoryRoot.getAbsolutePath()); >+ log.info("Rendering icons with " + threads + " threads, scaling output to " + iconScale + "x"); >+ long startTime = System.currentTimeMillis(); >+ >+ // Render the icons >+ rasterizeAll(); >+ >+ // Print summary of operations >+ int iconRendered = getIconsRendered(); >+ int failedIcons = getFailedIcons(); >+ int fullIconCount = iconRendered - failedIcons; >+ >+ log.info(fullIconCount + " Icons Rendered"); >+ log.info(failedIcons + " Icons Failed"); >+ log.info("Took: " + (System.currentTimeMillis() - startTime) + " ms."); >+ >+ log.info("Rasterization operations completed, Took: " >+ + (System.currentTimeMillis() - totalStartTime) + " ms."); >+ } >+ >+ private void createFragmentFiles(File outputBase, String dirName) { >+ createFile(new File(outputBase, "build.properties"), "bin.includes = META-INF/,icons/,.\n"); >+ createFile(new File(outputBase, ".project"), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + >+ "<projectDescription>\n" + >+ " <name>" + dirName + ".highdpi</name>\n" + >+ " <comment></comment>\n" + >+ " <projects>\n" + >+ " </projects>\n" + >+ " <buildSpec>\n" + >+ " <buildCommand>\n" + >+ " <name>org.eclipse.pde.ManifestBuilder</name>\n" + >+ " <arguments>\n" + >+ " </arguments>\n" + >+ " </buildCommand>\n" + >+ " <buildCommand>\n" + >+ " <name>org.eclipse.pde.SchemaBuilder</name>\n" + >+ " <arguments>\n" + >+ " </arguments>\n" + >+ " </buildCommand>\n" + >+ " </buildSpec>\n" + >+ " <natures>\n" + >+ " <nature>org.eclipse.pde.PluginNature</nature>\n" + >+ " </natures>\n" + >+ "</projectDescription>\n"); >+ createFile(new File(outputBase, "META-INF/MANIFEST.MF"), "Manifest-Version: 1.0\n" + >+ "Bundle-ManifestVersion: 2\n" + >+ "Bundle-Name: " + dirName + ".highdpi\n" + >+ "Bundle-SymbolicName: " + dirName + ".highdpi\n" + >+ "Bundle-Version: 0.1.0.qualifier\n" + >+ "Fragment-Host: " + dirName + "\n"); >+ } >+ >+ private void createFile(File file, String contents) { >+ try { >+ file.getParentFile().mkdirs(); >+ FileWriter writer = new FileWriter(file); >+ writer.write(contents); >+ writer.close(); >+ } catch (IOException e) { >+ log.error(e); >+ } >+ } >+ >+} >diff --git a/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/GalleryMojo.java b/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/GalleryMojo.java >deleted file mode 100644 >index cd0e0ec..0000000 >--- a/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/GalleryMojo.java >+++ /dev/null >@@ -1,408 +0,0 @@ >-/******************************************************************************* >- * (c) Copyright 2015 l33t labs LLC and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * l33t labs LLC and others - initial contribution >- *******************************************************************************/ >- >-package org.eclipse.ui.images.renderer; >- >-import java.awt.Color; >-import java.awt.Graphics2D; >-import java.awt.RenderingHints; >-import java.awt.image.BufferedImage; >-import java.io.File; >-import java.io.IOException; >-import java.util.ArrayList; >-import java.util.Collections; >-import java.util.Date; >-import java.util.HashMap; >-import java.util.List; >-import java.util.Map; >-import java.util.Map.Entry; >- >-import javax.imageio.ImageIO; >- >-import org.apache.maven.plugin.AbstractMojo; >-import org.apache.maven.plugin.MojoExecutionException; >-import org.apache.maven.plugin.MojoFailureException; >-import org.apache.maven.plugin.logging.Log; >- >-import com.mortennobel.imagescaling.ResampleFilters; >-import com.mortennobel.imagescaling.ResampleOp; >- >-/** >- * <p>Mojo which renders galleries for comparing >- * and evaluating icons..</p> >- * >- * @goal render-galleries >- * @phase generate-resources >- */ >-public class GalleryMojo extends AbstractMojo { >- >- /** Maven logger */ >- Log log; >- >- /** Used for finding gif files by extension. */ >- public static final String GIF_EXT = ".gif"; >- >- /** Used to specify the directory name where the SVGs are taken from. */ >- public static final String PNG_DIR = "eclipse.svg.pngdirectory"; >- >- /** Used to specify the directory name where the SVGs are taken from. */ >- public static final String GIF_DIR = "eclipse.svg.gifdirectory"; >- >- /** >- * <p>Mojo takes rendered images and generates various galleries for >- * testing and evaluation.</p> >- */ >- public void execute() throws MojoExecutionException, MojoFailureException { >- log = getLog(); >- >- // Defaults to "eclipse-png" >- String pngDir = "eclipse-png"; >- String pngDirProp = System.getProperty(PNG_DIR); >- if (pngDirProp != null) { >- pngDir = pngDirProp; >- } >- >- // Defaults to "eclipse-gif" >- String gifDir = "eclipse-gif"; >- String gifDirProp = System.getProperty(GIF_DIR); >- if (gifDirProp != null) { >- gifDir = gifDirProp; >- } >- >- File iconDirectoryRoot = new File(pngDir + "/"); >- >- Map<String, List<IconEntry>> galleryIconSets = new HashMap<>(); >- >- // Search each subdir in the root dir for svg icons >- for (File file : iconDirectoryRoot.listFiles()) { >- if(!file.isDirectory()) { >- continue; >- } >- >- List<IconEntry> icons = new ArrayList<>(); >- IconGatherer.gatherIcons(icons, "png", file, file, iconDirectoryRoot, false); >- >- galleryIconSets.put(file.getName(), icons); >- } >- >- File mavenTargetDir = new File("target/"); >- File galleryDir = new File(mavenTargetDir, "gallery/"); >- File gifCompare = new File(galleryDir, "gifcompare/"); >- File master = new File(galleryDir, "master/"); >- >- if(galleryDir.exists()) { >- galleryDir.delete(); >- } >- >- galleryDir.mkdirs(); >- gifCompare.mkdirs(); >- master.mkdirs(); >- >- renderGalleries(galleryDir, gifCompare, master, galleryIconSets, 16, 800, pngDir, gifDir); >- } >- >- /** >- * <p>Renders each icon set into a gallery image for reviewing and showing off >- * icons, and then composes them into a master gallery image.</p> >- * >- * @param rasterizer >- * @param galleryDir >- * @param gifCompare >- * @param master >- * @param iconSize >- * @param width >- * @param pngDir >- * @param gifDir >- */ >- public void renderGalleries(File galleryDir, File gifCompare, File master, Map<String, List<IconEntry>> iconSets, int iconSize, int width, String pngDir, String gifDir) { >- // Render each icon set and a master list >- List<IconEntry> masterList = new ArrayList<>(); >- >- for (Entry<String, List<IconEntry>> entry : iconSets.entrySet()) { >- String key = entry.getKey(); >- List<IconEntry> value = entry.getValue(); >- >- masterList.addAll(value); >- >- log.info("Creating gallery for: " + key); >- renderGallery(galleryDir, key, value, iconSize, width, 3); >- renderGifCompareGallery(gifCompare, key, value, iconSize, width, 6, pngDir, gifDir); >- } >- >- // Render the master image >- log.info("Rendering master icon gallery..."); >- renderMasterGallery(galleryDir, master, "-gallery.png", iconSize, iconSize + width, true); >- renderMasterGallery(galleryDir, master, "-gallery.png", iconSize, iconSize + width, false); >- >- // Master gif compare >- //renderMasterGallery(outputDir, "-gifcompare.png", iconSize, iconSize + width, false); >- } >- >- /** >- * <p>Renders comparison images, the new png/svg icons vs old gifs.</p> >- * >- * @param outputDir >- * @param key >- * @param icons >- * @param iconSize >- * @param width >- * @param margin >- * @param pngDir >- * @param gifDir >- */ >- private void renderGifCompareGallery(File outputDir, String key, List<IconEntry> icons, int iconSize, int width, int margin, String pngDir, String gifDir) { >- int leftColumnWidth = 300; >- int textHeaderHeight = 31; >- int outputSize = iconSize; >- int widthTotal = (outputSize * 4) + (margin * 6) + leftColumnWidth; >- >- int rowHeight = iconSize + (margin * 2); >- >- // Compute the height and add some room for the text header (31 px) >- int height = (icons.size() * rowHeight) + textHeaderHeight; >- >- BufferedImage bi = new BufferedImage(widthTotal + iconSize, height, >- BufferedImage.TYPE_INT_ARGB); >- Graphics2D g = bi.createGraphics(); >- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, >- RenderingHints.VALUE_ANTIALIAS_ON); >- >- g.setColor(Color.GRAY); >- g.drawString("SVG Icon Set: " + key + " - Count: " + icons.size(), 8, 20); >- >- int x = leftColumnWidth; >- int y = textHeaderHeight; >- >- // Render >- ResampleOp resampleOp = new ResampleOp(outputSize, outputSize); >- resampleOp.setFilter(ResampleFilters.getLanczos3Filter()); >- // resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Oversharpened); >- resampleOp.setNumberOfThreads(Runtime.getRuntime() >- .availableProcessors()); >- >- int second = leftColumnWidth + margin + iconSize; >- >- g.setColor(Color.WHITE); >- g.fillRect(0, 0, widthTotal + 10, height); >- >- g.setColor(Color.DARK_GRAY); >- g.fillRect(second + (margin / 2) + iconSize + 20, 0, (margin * 2) + (iconSize * 2) + 10, height); >- >- g.drawString(key + " (GIF / PNG)", 15, 20); >- >- Collections.sort(icons); >- >- // Render each icon into the gallery grid >- for (IconEntry entry : icons) { >- >- if (entry.inputPath == null) { >- continue; >- } >- >- try { >- BufferedImage pngImage = ImageIO.read(entry.inputPath); >- >- // Munge the gif path >- File gifLocalPath = new File(entry.inputPath.getParentFile(), entry.nameBase + GIF_EXT); >- String absoluteLocalPath = gifLocalPath.getAbsolutePath(); >- String gifAbsPath = absoluteLocalPath.replaceFirst(pngDir, gifDir); >- File gifPath = new File(gifAbsPath); >- >- log.debug("Search for GIF..."); >- log.debug("Entry path: " + entry.inputPath.getAbsolutePath()); >- log.debug("GIF path: " + gifPath.getAbsolutePath()); >- >- BufferedImage gifImage = null; >- >- if(gifPath.exists()) { >- gifImage = ImageIO.read(gifPath); >- } else { >- log.debug("GIF not found: " + gifPath.getAbsolutePath()); >- } >- >- g.drawString(entry.nameBase, 5, y + (margin * 3)); >- >- g.drawLine(0, y, widthTotal, y); >- >- if(gifImage != null) { >- g.drawImage(gifImage, leftColumnWidth, y + margin, null); >- } >- >- g.drawImage(pngImage, second, y + margin, null); >- >- if(gifImage != null) { >- g.drawImage(gifImage, second + margin + iconSize + 30, y + margin, null); >- } >- >- g.drawImage(pngImage, second + (margin * 2) + (iconSize * 2) + 30, y + margin, null); >- >- y += iconSize + margin * 2; >- } catch (Exception e) { >- e.printStackTrace(); >- log.error("Error rendering icon for gallery: " + entry.inputPath.getAbsolutePath()); >- continue; >- } >- } >- >- try { >- // Write the gallery image to disk >- String outputName = key + "-" + iconSize + "-gifcompare.png"; >- ImageIO.write(bi, "PNG", new File(outputDir, outputName)); >- } catch (IOException e) { >- e.printStackTrace(); >- log.error("Error writing gif comparison gallery: " + e.getMessage()); >- } >- } >- >- >- /** >- * <p>Renders an icon set into a grid within an image.</p> >- * >- * @param outputRoot >- * @param key >- * @param icons >- */ >- private void renderGallery(File outputRoot, String key, List<IconEntry> icons, >- int iconSize, int width, int margin) { >- int textHeaderHeight = 31; >- int outputSize = iconSize; >- int outputTotal = outputSize + (margin * 2); >- int div = width / outputTotal; >- int rowCount = icons.size() / div; >- >- if (width % outputTotal > 0) { >- rowCount++; >- } >- >- // Compute the height and add some room for the text header (31 px) >- int height = Math.max(outputTotal, rowCount * outputTotal) >- + textHeaderHeight; >- >- BufferedImage bi = new BufferedImage(width + iconSize, height, >- BufferedImage.TYPE_INT_ARGB); >- Graphics2D g = bi.createGraphics(); >- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, >- RenderingHints.VALUE_ANTIALIAS_ON); >- >- g.setColor(Color.GRAY); >- g.drawString("SVG Icon Set: " + key + " - Count: " + icons.size(), 8, 20); >- >- int x = 1; >- int y = textHeaderHeight; >- >- // Render >- ResampleOp resampleOp = new ResampleOp(outputSize, outputSize); >- resampleOp.setFilter(ResampleFilters.getLanczos3Filter()); >- // resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Oversharpened); >- resampleOp.setNumberOfThreads(Runtime.getRuntime().availableProcessors()); >- >- // Render each icon into the gallery grid >- for (IconEntry def : icons) { >- try { >- if (def.inputPath == null) { >- log.error("Undefined gallery image for : " + def.nameBase); >- continue; >- } >- >- BufferedImage iconImage = ImageIO.read(def.inputPath); >- BufferedImage sizedImage = resampleOp.filter(iconImage, null); >- >- g.drawImage(sizedImage, x + margin, y + margin, null); >- >- x += outputTotal; >- >- if (x >= width) { >- x = 1; >- y += outputTotal; >- } >- } catch (Exception e) { >- log.error("Error rendering icon for gallery: " + def.inputPath.getAbsolutePath()); >- e.printStackTrace(); >- continue; >- } >- } >- >- try { >- // Write the gallery image to disk >- String outputName = key + "-" + iconSize + "-gallery.png"; >- ImageIO.write(bi, "PNG", new File(outputRoot, outputName)); >- } catch (IOException e) { >- log.error("Error writing icon: " + e.getMessage()); >- e.printStackTrace(); >- } >- } >- >- /** >- * <p>Renders a master gallery image that contains every icon set at the >- * current resolution.</p> >- * >- * @param root >- * @param iconSize >- * @param width >- * @param dark >- */ >- private void renderMasterGallery(File root, File output, String fileEnding, int iconSize, int width, >- boolean dark) { >- int headerHeight = 30; >- List<BufferedImage> images = new ArrayList<>(); >- for (File file : root.listFiles()) { >- if (file.getName().endsWith(iconSize + fileEnding)) { >- BufferedImage set = null; >- try { >- set = ImageIO.read(file); >- } catch (IOException e) { >- log.error("Error reading icon: " + e.getMessage()); >- e.printStackTrace(); >- continue; >- } >- images.add(set); >- headerHeight += set.getHeight(); >- } >- } >- >- BufferedImage bi = new BufferedImage(width, headerHeight, >- BufferedImage.TYPE_INT_ARGB); >- Graphics2D g = bi.createGraphics(); >- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, >- RenderingHints.VALUE_ANTIALIAS_ON); >- >- if (dark) { >- g.setColor(Color.DARK_GRAY); >- } else { >- g.setColor(Color.WHITE); >- } >- g.fillRect(0, 0, bi.getWidth(), bi.getHeight()); >- >- g.setColor(Color.BLACK); >- g.drawString("SVG Icons for Eclipse - Count: " >- + iconSize + "x" + iconSize >- + " Rendered: " + new Date().toString(), 8, 20); >- >- int x = 0; >- int y = 31; >- >- // Draw each icon set image into the uber gallery >- for (BufferedImage image : images) { >- g.drawImage(image, x, y, null); >- y += image.getHeight(); >- } >- >- try { >- // Write the uber gallery to disk >- String bgState = (dark) ? "dark" : "light"; >- String outputName = "global-svg-" + iconSize + "-" + bgState + fileEnding + "-icons.png"; >- ImageIO.write(bi, "PNG", new File(output, outputName)); >- } catch (IOException e) { >- log.error("Error writing gallery: " + e.getMessage()); >- e.printStackTrace(); >- } >- } >-} >diff --git a/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/IconEntry.java b/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/IconEntry.java >deleted file mode 100644 >index 05d72d3..0000000 >--- a/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/IconEntry.java >+++ /dev/null >@@ -1,60 +0,0 @@ >-/******************************************************************************* >- * (c) Copyright 2015 l33t labs LLC and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * l33t labs LLC and others - initial contribution >- *******************************************************************************/ >- >-package org.eclipse.ui.images.renderer; >- >-import java.io.File; >- >-/** >- * <p>IconEntry is used to define an icon to rasterize, >- * where to put it and the dimensions to render it at.</p> >- */ >-class IconEntry implements Comparable<IconEntry> { >- >- /** The name of the icon minus extension */ >- String nameBase; >- >- /** The input path of the source svg files. */ >- File inputPath; >- >- /** The sizes this icon should be rendered at */ >- int[] sizes; >- >- /** >- * The path rasterized versions of this icon should be written into. >- */ >- File outputPath; >- >- /** The path to a disabled version of the icon (gets desaturated). */ >- File disabledPath; >- >- /** >- * >- * @param nameBase >- * @param inputPath >- * @param outputPath >- * @param disabledPath >- * @param sizes >- */ >- public IconEntry(String nameBase, File inputPath, File outputPath, >- File disabledPath, int[] sizes) { >- this.nameBase = nameBase; >- this.sizes = sizes; >- this.inputPath = inputPath; >- this.outputPath = outputPath; >- this.disabledPath = disabledPath; >- } >- >- @Override >- public int compareTo(IconEntry o) { >- return nameBase.compareTo(o.nameBase); >- } >-} >\ No newline at end of file >diff --git a/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/IconGatherer.java b/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/IconGatherer.java >deleted file mode 100644 >index 7f559a2..0000000 >--- a/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/IconGatherer.java >+++ /dev/null >@@ -1,119 +0,0 @@ >-/******************************************************************************* >- * (c) Copyright 2015 l33t labs LLC and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * l33t labs LLC and others - initial contribution >- *******************************************************************************/ >- >-package org.eclipse.ui.images.renderer; >- >-import java.io.File; >-import java.net.URI; >-import java.util.List; >- >-/** >- * <p>Utility to find and organize icons for rendering.</p> >- * >- * @author tmccrary@l33tlabs.com >- * >- */ >-public class IconGatherer { >- >- /** >- * <p>Searches the root resources directory for svg icons and adds them to a >- * collection for later rasterization.</p> >- * >- * @param outputName >- * @param iconDir >- * @param outputBase >- * @param outputDir2 >- */ >- public static void gatherIcons(List<IconEntry> icons, String extension, File rootDir, File iconDir, File outputBase, boolean generateDisabledDirs) { >- File[] listFiles = iconDir.listFiles(); >- >- for (File child : listFiles) { >- if (child.isDirectory()) { >- if(child.getName().startsWith("d")) { >- continue; >- } >- >- gatherIcons(icons, extension, rootDir, child, outputBase, generateDisabledDirs); >- continue; >- } >- >- if (!child.getName().endsWith(extension)) { >- continue; >- } >- >- // Compute a relative path for the output dir >- URI rootUri = rootDir.toURI(); >- URI iconUri = iconDir.toURI(); >- >- String relativePath = rootUri.relativize(iconUri).getPath(); >- File outputDir = new File(outputBase, relativePath); >- File disabledOutputDir = null; >- >- File parentFile = child.getParentFile(); >- >- /* Determine if/where to put a disabled version of the icon >- Eclipse traditionally uses a prefix of d for disabled, e for >- enabled in the folder name */ >- if (generateDisabledDirs && parentFile != null) { >- String parentDirName = parentFile.getName(); >- if (parentDirName.startsWith("e")) { >- StringBuilder builder = new StringBuilder(); >- builder.append("d"); >- builder.append(parentDirName.substring(1, parentDirName.length())); >- >- // Disabled variant folder name >- String disabledVariant = builder.toString(); >- >- // The parent's parent, to create the disabled directory in >- File setParent = parentFile.getParentFile(); >- >- // The source directory's disabled folder >- File disabledSource = new File(setParent, disabledVariant); >- >- // Compute a relative path, so we can create the output folder >- String path = rootUri.relativize( >- disabledSource.toURI()).getPath(); >- >- // Create the output folder, so a disabled icon is generated >- disabledOutputDir = new File(outputBase, path); >- if(!disabledOutputDir.exists()) { >- disabledOutputDir.mkdirs(); >- } >- } >- } >- >- IconEntry icon = createIcon(child, outputDir, disabledOutputDir); >- >- icons.add(icon); >- } >- } >- >- /** >- * <p>Creates an IconEntry, which contains information about rendering an icon such >- * as the source file, where to render, what alternative types of output to >- * generate, etc.</p> >- * >- * @param input the source of the icon file (SVG document) >- * @param outputPath the path of the rasterized version to generate >- * @param disabledPath the path of the disabled (desaturated) icon, if one is required >- * >- * @return an IconEntry describing the rendering operation >- */ >- public static IconEntry createIcon(File input, File outputPath, File disabledPath) { >- String name = input.getName(); >- String[] split = name.split("\\.(?=[^\\.]+$)"); >- >- IconEntry def = new IconEntry(split[0], input, outputPath, disabledPath, new int[0]); >- >- return def; >- } >- >-} >diff --git a/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java b/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java >deleted file mode 100644 >index 66b6d96..0000000 >--- a/org.eclipse.images.renderer/src/main/java/org/eclipse/ui/images/renderer/RenderMojo.java >+++ /dev/null >@@ -1,642 +0,0 @@ >-/******************************************************************************* >- * (c) Copyright 2015 l33t labs LLC and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * l33t labs LLC and others - initial contribution >- *******************************************************************************/ >- >-package org.eclipse.ui.images.renderer; >- >-import java.awt.RenderingHints; >-import java.awt.image.BufferedImage; >-import java.io.ByteArrayInputStream; >-import java.io.ByteArrayOutputStream; >-import java.io.File; >-import java.io.FileInputStream; >-import java.io.FileWriter; >-import java.io.IOException; >-import java.io.OutputStream; >-import java.util.ArrayList; >-import java.util.Collections; >-import java.util.List; >-import java.util.concurrent.Callable; >-import java.util.concurrent.ExecutorService; >-import java.util.concurrent.Executors; >-import java.util.concurrent.atomic.AtomicInteger; >- >-import javax.imageio.ImageIO; >- >-import org.apache.batik.dom.svg.SAXSVGDocumentFactory; >-import org.apache.batik.gvt.renderer.ImageRenderer; >-import org.apache.batik.transcoder.ErrorHandler; >-import org.apache.batik.transcoder.TranscoderException; >-import org.apache.batik.transcoder.TranscoderInput; >-import org.apache.batik.transcoder.TranscoderOutput; >-import org.apache.batik.transcoder.image.PNGTranscoder; >-import org.apache.batik.util.XMLResourceDescriptor; >-import org.apache.maven.plugin.AbstractMojo; >-import org.apache.maven.plugin.MojoExecutionException; >-import org.apache.maven.plugin.MojoFailureException; >-import org.apache.maven.plugin.logging.Log; >-import org.w3c.dom.Element; >-import org.w3c.dom.svg.SVGDocument; >- >-import com.jhlabs.image.ContrastFilter; >-import com.jhlabs.image.GrayscaleFilter; >-import com.jhlabs.image.HSBAdjustFilter; >- >-/** >- * <p>Mojo which renders SVG icons into PNG format.</p> >- * >- * @goal render-icons >- * @phase generate-resources >- */ >-public class RenderMojo extends AbstractMojo { >- >- /** Maven logger */ >- Log log; >- >- /** Used for high res rendering support. */ >- public static final String ECLIPSE_SVG_SCALE = "eclipse.svg.scale"; >- >- /** Used to specify the number of render threads when rasterizing icons. */ >- public static final String RENDERTHREADS = "eclipse.svg.renderthreads"; >- >- /** Used to specify the directory name where the SVGs are taken from. */ >- public static final String SOURCE_DIR = "eclipse.svg.sourcedirectory"; >- >- /** Used to specify the directory name where the PNGs are saved to. */ >- public static final String TARGET_DIR = "eclipse.svg.targetdirectory"; >- >- /** A list of directories with svg sources to rasterize. */ >- private List<IconEntry> icons; >- >- /** The pool used to render multiple icons concurrently. */ >- private ExecutorService execPool; >- >- /** The number of threads to use when rendering icons. */ >- private int threads; >- >- /** >- * A counter used to keep track of the number of rendered icons. Atomic is >- * used to make it easy to access between threads concurrently. >- */ >- private AtomicInteger counter; >- >- /** List of icons that failed to render, made safe for parallel access */ >- List<IconEntry> failedIcons = Collections >- .synchronizedList(new ArrayList<IconEntry>(5)); >- >- /** The amount of scaling to apply to rasterized images. */ >- private double outputScale; >- >- /** >- * @return the number of icons rendered at the time of the call >- */ >- public int getIconsRendered() { >- return counter.get(); >- } >- >- /** >- * @return the number of icons that failed during the rendering process >- */ >- public int getFailedIcons() { >- return failedIcons.size(); >- } >- >- /** >- * <p>Generates raster images from the input SVG vector image.</p> >- * >- * @param icon >- * the icon to render >- */ >- public void rasterize(IconEntry icon, GrayscaleFilter grayFilter, HSBAdjustFilter desaturator, ContrastFilter decontrast) { >- if (icon == null) { >- log.error("Null icon definition, skipping."); >- failedIcons.add(icon); >- return; >- } >- >- if (icon.inputPath == null) { >- log.error("Null icon input path, skipping: " >- + icon.nameBase); >- failedIcons.add(icon); >- return; >- } >- >- if (!icon.inputPath.exists()) { >- log.error("Input path specified does not exist, skipping: " >- + icon.nameBase); >- failedIcons.add(icon); >- return; >- } >- >- if (icon.outputPath != null && !icon.outputPath.exists()) { >- icon.outputPath.mkdirs(); >- } >- >- if (icon.disabledPath != null && !icon.disabledPath.exists()) { >- icon.disabledPath.mkdirs(); >- } >- >- // Create the document to rasterize >- SVGDocument svgDocument = generateSVGDocument(icon); >- >- if(svgDocument == null) { >- return; >- } >- >- // Determine the output sizes (native, double, quad) >- // We render at quad size and resample down for output >- Element svgDocumentNode = svgDocument.getDocumentElement(); >- String nativeWidthStr = svgDocumentNode.getAttribute("width"); >- String nativeHeightStr = svgDocumentNode.getAttribute("height"); >- int nativeWidth = -1; >- int nativeHeight = -1; >- >- try{ >- if (nativeWidthStr != "" && nativeHeightStr != ""){ >- nativeWidth = Integer.parseInt(nativeWidthStr); >- nativeHeight = Integer.parseInt(nativeHeightStr); >- } else { >- // Vector graphics editing programs don't always output height and width attributes on SVG. >- // As fall back: parse the viewBox attribute (which is almost always set). >- String viewBoxStr = svgDocumentNode.getAttribute("viewBox"); >- if (viewBoxStr == ""){ >- log.error("Icon defines neither width/height nor a viewBox, skipping: " + icon.nameBase); >- failedIcons.add(icon); >- return; >- } >- String[] splitted = viewBoxStr.split(" "); >- String xStr = splitted[0]; >- String yStr = splitted[1]; >- String widthStr = splitted[2]; >- String heightStr = splitted[3]; >- nativeWidth = Integer.parseInt(widthStr) - Integer.parseInt(xStr); >- nativeHeight = Integer.parseInt(heightStr) - Integer.parseInt(yStr); >- } >- }catch (NumberFormatException e){ >- log.error("Dimension could not be parsed ( "+e.getMessage()+ "), skipping: " + icon.nameBase); >- failedIcons.add(icon); >- return; >- } >- >- int outputWidth = (int) (nativeWidth * outputScale); >- int outputHeight = (int) (nativeHeight * outputScale); >- >- // Guesstimate the PNG size in memory, BAOS will enlarge if necessary. >- int outputInitSize = nativeWidth * nativeHeight * 4 + 1024; >- ByteArrayOutputStream iconOutput = new ByteArrayOutputStream( >- outputInitSize); >- >- // Render to SVG >- try { >- log.info(Thread.currentThread().getName() + " " >- + " Rasterizing: " + icon.nameBase + ".png at " + outputWidth >- + "x" + outputHeight); >- >- TranscoderInput svgInput = new TranscoderInput(svgDocument); >- >- boolean success = renderIcon(icon.nameBase, outputWidth, outputHeight, svgInput, iconOutput); >- >- if (!success) { >- log.error("Failed to render icon: " + icon.nameBase + ".png, skipping."); >- failedIcons.add(icon); >- return; >- } >- } catch (Exception e) { >- log.error("Failed to render icon: " + e.getMessage()); >- failedIcons.add(icon); >- return; >- } >- >- // Generate a buffered image from Batik's png output >- byte[] imageBytes = iconOutput.toByteArray(); >- ByteArrayInputStream imageInputStream = new ByteArrayInputStream(imageBytes); >- >- BufferedImage inputImage = null; >- try { >- inputImage = ImageIO.read(imageInputStream); >- >- if(inputImage == null) { >- log.error("Failed to generate BufferedImage from rendered icon, ImageIO returned null: " + icon.nameBase); >- failedIcons.add(icon); >- return; >- } >- } catch (IOException e2) { >- log.error("Failed to generate BufferedImage from rendered icon: " + icon.nameBase + " - " + e2.getMessage()); >- failedIcons.add(icon); >- return; >- } >- >- writeIcon(icon, outputWidth, outputHeight, inputImage); >- >- try { >- if (icon.disabledPath != null) { >- BufferedImage desaturated16 = desaturator.filter( >- grayFilter.filter(inputImage, null), null); >- >- BufferedImage deconstrast = decontrast.filter(desaturated16, null); >- >- ImageIO.write(deconstrast, "PNG", new File(icon.disabledPath, icon.nameBase + ".png")); >- } >- } catch (Exception e1) { >- log.error("Failed to render disabled icon: " + >- icon.nameBase, e1); >- failedIcons.add(icon); >- } >- } >- >- /** >- * <p>Generates a Batik SVGDocument for the supplied IconEntry's input >- * file.</p> >- * >- * @param icon the icon entry to generate an SVG document for >- * >- * @return a batik SVGDocument instance or null if one could not be generated >- */ >- private SVGDocument generateSVGDocument(IconEntry icon) { >- // Load the document and find out the native height/width >- // We reuse the document later for rasterization >- SVGDocument svgDocument = null; >- try { >- FileInputStream iconDocumentStream = new FileInputStream(icon.inputPath); >- >- String parser = XMLResourceDescriptor.getXMLParserClassName(); >- SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); >- >- // What kind of URI is batik expecting here??? the docs don't say >- svgDocument = f.createSVGDocument("file://" + icon.nameBase + ".svg", iconDocumentStream); >- } catch (Exception e3) { >- log.error("Error parsing SVG icon document: " + e3.getMessage()); >- failedIcons.add(icon); >- return null; >- } >- return svgDocument; >- } >- >- /** >- * <p>Resizes the supplied inputImage to the specified width and height, using >- * lanczos resampling techniques.</p> >- * >- * @param icon the icon that's being resized >- * @param width the desired output width after rescaling operations >- * @param height the desired output height after rescaling operations >- * @param sourceImage the source image to resource >- */ >- private void writeIcon(IconEntry icon, int width, int height, BufferedImage sourceImage) { >- try { >- String outputName = icon.nameBase; >- if (outputScale != 1) { >- String scaleId = outputScale == (double) (int) outputScale ? Integer.toString((int) outputScale): Double.toString(outputScale); >- outputName += "@" + scaleId + "x"; >- } >- outputName += ".png"; >- ImageIO.write(sourceImage, "PNG", new File(icon.outputPath, outputName)); >- } catch (Exception e1) { >- log.error("Failed to resize rendered icon to output size: " + >- icon.nameBase, e1); >- failedIcons.add(icon); >- } >- } >- >- /** >- * <p>Handles concurrently rasterizing the icons to >- * reduce the duration on multicore systems.</p> >- */ >- public void rasterizeAll() { >- // The number of icons that haven't been distributed to >- // callables >- int remainingIcons = icons.size(); >- >- // The number of icons to distribute to a rendering callable >- final int threadExecSize = Math.max(1, icons.size() / this.threads); >- >- // The current offset to start a batch, as they're distributed >- // between rendering callables >- int batchOffset = 0; >- >- // A list of callables used to render icons on multiple threads >- // Each callable gets a set of icons to render >- List<Callable<Object>> tasks = new ArrayList<>( >- this.threads); >- >- // Distribute the rasterization operations between multiple threads >- while (remainingIcons > 0) { >- // The current start index for the current batch >- final int batchStart = batchOffset; >- >- // Increment the offset to reflect this batch (used for the next batch) >- batchOffset += threadExecSize; >- >- // Determine this batch size, used for batches that have less than >- // threadExecSize at the end of the distribution operation >- int batchSize = 0; >- >- // Determine if we can fit a full batch in this callable >- // or if we are at the end of gathered icons >- if (remainingIcons > threadExecSize) { >- batchSize = threadExecSize; >- } else { >- // We have less than a full batch worth of remaining icons >- // just add them all >- batchSize = remainingIcons; >- } >- >- // Deincrement the remaining Icons >- remainingIcons -= threadExecSize; >- >- // Used for access in the callable's scope >- final int execCount = batchSize; >- >- // Create the callable and add it to the task pool >- Callable<Object> runnable = new Callable<Object>() { >- @Override >- public Object call() throws Exception { >- // The jhlabs filters are not thread safe, so provide one set per thread >- GrayscaleFilter grayFilter = new GrayscaleFilter(); >- >- HSBAdjustFilter desaturator = new HSBAdjustFilter(); >- desaturator.setSFactor(0.0f); >- >- ContrastFilter decontrast = new ContrastFilter(); >- decontrast.setBrightness(2.9f); >- decontrast.setContrast(0.2f); >- >- // Rasterize this batch >- for (int count = 0; count < execCount; count++) { >- rasterize(icons.get(batchStart + count), grayFilter, desaturator, decontrast); >- } >- >- // Update the render counter >- counter.getAndAdd(execCount); >- log.info("Finished rendering batch, index: " + batchStart); >- >- return null; >- } >- }; >- >- tasks.add(runnable); >- } >- >- // Execute the rasterization operations that >- // have been added to the pool >- try { >- execPool.invokeAll(tasks); >- } catch (InterruptedException e) { >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } >- >- // Print info about failed render operations, so they can be fixed >- log.info("Failed Icon Count: " + failedIcons.size()); >- for (IconEntry icon : failedIcons) { >- log.info("Failed Icon: " + icon.nameBase); >- } >- >- } >- >- /** >- * Use batik to rasterize the input SVG into a raster image at the specified >- * image dimensions. >- * >- * @param width the width to render the icons at >- * @param height the height to render the icon at >- * @param input the SVG transcoder input >- * @param stream the stream to write the PNG data to >- */ >- public boolean renderIcon(final String iconName, int width, int height, >- TranscoderInput tinput, OutputStream stream) { >- PNGTranscoder transcoder = new PNGTranscoder() { >- protected ImageRenderer createRenderer() { >- ImageRenderer renderer = super.createRenderer(); >- >- RenderingHints renderHints = renderer.getRenderingHints(); >- >- renderHints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, >- RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)); >- >- renderHints.add(new RenderingHints(RenderingHints.KEY_RENDERING, >- RenderingHints.VALUE_RENDER_QUALITY)); >- >- renderHints.add(new RenderingHints(RenderingHints.KEY_DITHERING, >- RenderingHints.VALUE_DITHER_DISABLE)); >- >- renderHints.add(new RenderingHints(RenderingHints.KEY_INTERPOLATION, >- RenderingHints.VALUE_INTERPOLATION_BICUBIC)); >- >- renderHints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION, >- RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)); >- >- renderHints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, >- RenderingHints.VALUE_ANTIALIAS_ON)); >- >- renderHints.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, >- RenderingHints.VALUE_COLOR_RENDER_QUALITY)); >- >- renderHints.add(new RenderingHints(RenderingHints.KEY_STROKE_CONTROL, >- RenderingHints.VALUE_STROKE_PURE)); >- >- renderHints.add(new RenderingHints(RenderingHints.KEY_FRACTIONALMETRICS, >- RenderingHints.VALUE_FRACTIONALMETRICS_ON)); >- >- renderer.setRenderingHints(renderHints); >- >- return renderer; >- } >- }; >- >- transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width)); >- transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(height)); >- >- transcoder.setErrorHandler(new ErrorHandler() { >- public void warning(TranscoderException arg0) >- throws TranscoderException { >- log.error("Icon: " + iconName + " - WARN: " + arg0.getMessage()); >- } >- >- public void fatalError(TranscoderException arg0) >- throws TranscoderException { >- log.error("Icon: " + iconName + " - FATAL: " + arg0.getMessage()); >- } >- >- public void error(TranscoderException arg0) >- throws TranscoderException { >- log.error("Icon: " + iconName + " - ERROR: " + arg0.getMessage()); >- } >- }); >- >- // Transcode the SVG document input to a PNG via the output stream >- TranscoderOutput output = new TranscoderOutput(stream); >- >- try { >- transcoder.transcode(tinput, output); >- return true; >- } catch (Exception e) { >- e.printStackTrace(); >- return false; >- } finally { >- try { >- stream.close(); >- } catch (IOException e) { >- // TODO Auto-generated catch block >- e.printStackTrace(); >- } >- } >- } >- >- /** >- * <p>Initializes rasterizer defaults</p> >- * >- * @param threads the number of threads to render with >- * @param scale multiplier to use with icon output dimensions >- */ >- private void init(int threads, double scale) { >- this.threads = threads; >- this.outputScale = Math.max(1, scale); >- icons = new ArrayList<>(); >- execPool = Executors.newFixedThreadPool(threads); >- counter = new AtomicInteger(); >- } >- >- /** >- * @see AbstractMojo#execute() >- */ >- public void execute() throws MojoExecutionException, MojoFailureException { >- log = getLog(); >- >- // Default to 2x the number of processor cores but allow override via jvm arg >- int threads = Math.max(1, Runtime.getRuntime().availableProcessors() * 2); >- String threadStr = System.getProperty(RENDERTHREADS); >- if (threadStr != null) { >- try { >- threads = Integer.parseInt(threadStr); >- } catch (Exception e) { >- e.printStackTrace(); >- System.out >- .println("Could not parse thread count, using default thread count"); >- } >- } >- >- // if high res is enabled, the icons output size will be scaled by iconScale >- // Defaults to 1, meaning native size >- double iconScale = 1; >- String iconScaleStr = System.getProperty(ECLIPSE_SVG_SCALE); >- if (iconScaleStr != null) { >- iconScale = Double.parseDouble(iconScaleStr); >- if (iconScale != 1 && iconScale != 1.5 && iconScale != 2) { >- log.warn("Unusual scale factor: " + iconScaleStr + " (@" + iconScale + "x)"); >- } >- } >- >- // Defaults to "eclipse-svg" >- String sourceDir = "eclipse-svg"; >- String sourceDirProp = System.getProperty(SOURCE_DIR); >- if (sourceDirProp != null) { >- sourceDir = sourceDirProp; >- } >- >- // Defaults to "eclipse-png" >- String targetDir = "eclipse-png"; >- String targetDirProp = System.getProperty(TARGET_DIR); >- if (targetDirProp != null) { >- targetDir = targetDirProp; >- } >- >- // Track the time it takes to render the entire set >- long totalStartTime = System.currentTimeMillis(); >- >- // initialize defaults (the old renderer was instantiated via constructor) >- init(threads, iconScale); >- >- String workingDirectory = System.getProperty("user.dir"); >- >- File outputDir = new File(workingDirectory + (iconScale == 1 ? "/" + targetDir + "/" : "/" + targetDir + "-highdpi/")); >- File iconDirectoryRoot = new File(sourceDir + "/"); >- >- // Search each subdir in the root dir for svg icons >- for (File file : iconDirectoryRoot.listFiles()) { >- if(!file.isDirectory()) { >- continue; >- } >- >- String dirName = file.getName(); >- >- // Where to place the rendered icon >- File outputBase = new File(outputDir, (iconScale == 1 ? dirName : dirName + ".highdpi")); >- if (iconScale != 1) { >- createFragmentFiles(outputBase, dirName); >- } >- >- IconGatherer.gatherIcons(icons, "svg", file, file, outputBase, true); >- } >- >- log.info("Working directory: " + outputDir.getAbsolutePath()); >- log.info("SVG Icon Directory: " + iconDirectoryRoot.getAbsolutePath()); >- log.info("Rendering icons with " + threads + " threads, scaling output to " + iconScale + "x"); >- long startTime = System.currentTimeMillis(); >- >- // Render the icons >- rasterizeAll(); >- >- // Print summary of operations >- int iconRendered = getIconsRendered(); >- int failedIcons = getFailedIcons(); >- int fullIconCount = iconRendered - failedIcons; >- >- log.info(fullIconCount + " Icons Rendered"); >- log.info(failedIcons + " Icons Failed"); >- log.info("Took: " + (System.currentTimeMillis() - startTime) + " ms."); >- >- log.info("Rasterization operations completed, Took: " >- + (System.currentTimeMillis() - totalStartTime) + " ms."); >- } >- >- private void createFragmentFiles(File outputBase, String dirName) { >- createFile(new File(outputBase, "build.properties"), "bin.includes = META-INF/,icons/,.\n"); >- createFile(new File(outputBase, ".project"), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + >- "<projectDescription>\n" + >- " <name>" + dirName + ".highdpi</name>\n" + >- " <comment></comment>\n" + >- " <projects>\n" + >- " </projects>\n" + >- " <buildSpec>\n" + >- " <buildCommand>\n" + >- " <name>org.eclipse.pde.ManifestBuilder</name>\n" + >- " <arguments>\n" + >- " </arguments>\n" + >- " </buildCommand>\n" + >- " <buildCommand>\n" + >- " <name>org.eclipse.pde.SchemaBuilder</name>\n" + >- " <arguments>\n" + >- " </arguments>\n" + >- " </buildCommand>\n" + >- " </buildSpec>\n" + >- " <natures>\n" + >- " <nature>org.eclipse.pde.PluginNature</nature>\n" + >- " </natures>\n" + >- "</projectDescription>\n"); >- createFile(new File(outputBase, "META-INF/MANIFEST.MF"), "Manifest-Version: 1.0\n" + >- "Bundle-ManifestVersion: 2\n" + >- "Bundle-Name: " + dirName + ".highdpi\n" + >- "Bundle-SymbolicName: " + dirName + ".highdpi\n" + >- "Bundle-Version: 0.1.0.qualifier\n" + >- "Fragment-Host: " + dirName + "\n"); >- } >- >- private void createFile(File file, String contents) { >- try { >- file.getParentFile().mkdirs(); >- FileWriter writer = new FileWriter(file); >- writer.write(contents); >- writer.close(); >- } catch (IOException e) { >- log.error(e); >- } >- } >- >-} >diff --git a/org.eclipse.images/.gitignore b/org.eclipse.images/.gitignore >new file mode 100644 >index 0000000..76f0ee2 >--- /dev/null >+++ b/org.eclipse.images/.gitignore >@@ -0,0 +1,2 @@ >+/bin/ >+target/ >\ No newline at end of file >diff --git a/org.eclipse.images/.project b/org.eclipse.images/.project >index 8c0cb77..187e87d 100644 >--- a/org.eclipse.images/.project >+++ b/org.eclipse.images/.project >@@ -6,12 +6,24 @@ > </projects> > <buildSpec> > <buildCommand> >+ <name>org.eclipse.jdt.core.javabuilder</name> >+ <arguments> >+ </arguments> >+ </buildCommand> >+ <buildCommand> > <name>org.eclipse.pde.ManifestBuilder</name> >+ <arguments> >+ </arguments> >+ </buildCommand> >+ <buildCommand> >+ <name>org.eclipse.m2e.core.maven2Builder</name> > <arguments> > </arguments> > </buildCommand> > </buildSpec> > <natures> >+ <nature>org.eclipse.jdt.core.javanature</nature> >+ <nature>org.eclipse.m2e.core.maven2Nature</nature> > <nature>org.eclipse.pde.PluginNature</nature> > </natures> > </projectDescription> >diff --git a/org.eclipse.images/META-INF/MANIFEST.MF b/org.eclipse.images/META-INF/MANIFEST.MF >index dc0ba9e..d4a2183 100644 >--- a/org.eclipse.images/META-INF/MANIFEST.MF >+++ b/org.eclipse.images/META-INF/MANIFEST.MF >@@ -1,7 +1,7 @@ > Manifest-Version: 1.0 > Bundle-ManifestVersion: 2 > Bundle-Name: %Plugin.name >-Bundle-SymbolicName: org.eclipse.ui.images >+Bundle-SymbolicName: org.eclipse.images > Bundle-Version: 1.0.0.qualifier > Bundle-RequiredExecutionEnvironment: JavaSE-1.8 > Bundle-Vendor: %Plugin.providerName >diff --git a/org.eclipse.images/README.md b/org.eclipse.images/README.md >index d69a637..f0167eb 100644 >--- a/org.eclipse.images/README.md >+++ b/org.eclipse.images/README.md >@@ -1,11 +1,11 @@ >-org.eclipse.ui.images >+org.eclipse.images > ===================== > >-org.eclipse.ui.images provides svg versions of the Eclipse SDK images. The "eclipse-svg" folder contains svg version of the icons, while the "eclipse-png" folder contain generated png files. These icons can be used in custom Eclipse plug-ins or in arbitrary rich client applications. >+org.eclipse.images provides svg versions of the Eclipse SDK images. The "eclipse-svg" folder contains svg version of the icons, while the "eclipse-png" folder contain generated png files. These icons can be used in custom Eclipse plug-ins or in arbitrary rich client applications. > Generate png files > ------------------ > >-To generate the png files based on the svg files, see the README.md file in the org.eclipse.ui.images.renderer plug-in. >+To generate the png files based on the svg files, see the README.md file in the org.eclipse.images.renderer plug-in. > > License > ------- >diff --git a/org.eclipse.images/plugin.properties b/org.eclipse.images/plugin.properties >index 4233f90..a6f8800 100644 >--- a/org.eclipse.images/plugin.properties >+++ b/org.eclipse.images/plugin.properties >@@ -8,6 +8,6 @@ > # Contributors: > # IBM Corporation - initial API and implementation > ############################################################################### >-Plugin.name = Eclipse UI Image Resources >+Plugin.name = Eclipse Image Resources > Plugin.providerName = Eclipse.org > >diff --git a/org.eclipse.images/pom.xml b/org.eclipse.images/pom.xml >index 635009b..e80f0e7 100644 >--- a/org.eclipse.images/pom.xml >+++ b/org.eclipse.images/pom.xml >@@ -1,24 +1,21 @@ > <?xml version="1.0" encoding="UTF-8"?> >-<!-- >- Copyright (c) 2013 - vogella GmbH >- All rights reserved. This program and the accompanying materials >- are made available under the terms of the Eclipse Distribution License v1.0 >- which accompanies this distribution, and is available at >- http://www.eclipse.org/org/documents/edl-v10.php >- >- Contributors: >- Lars Vogel - initial implementation >---> >-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> >- <modelVersion>4.0.0</modelVersion> >- <parent> >- <artifactId>eclipse.platform.ui</artifactId> >- <groupId>eclipse.platform.ui</groupId> >- <version>4.6.0-SNAPSHOT</version> >- <relativePath>../../</relativePath> >- </parent> >- <groupId>org.eclipse.ui</groupId> >- <artifactId>org.eclipse.ui.images</artifactId> >- <version>1.0.0-SNAPSHOT</version> >- <packaging>eclipse-plugin</packaging> >+<!-- Copyright (c) 2013 - vogella GmbH All rights reserved. This program >+ and the accompanying materials are made available under the terms of the >+ Eclipse Distribution License v1.0 which accompanies this distribution, and >+ is available at http://www.eclipse.org/org/documents/edl-v10.php Contributors: >+ Lars Vogel - initial implementation Tony McCrary - move to eclipse.images --> >+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> >+ <modelVersion>4.0.0</modelVersion> >+ <parent> >+ <artifactId>org.eclipse.images.parent</artifactId> >+ <groupId>eclipse.images</groupId> >+ <version>4.6.0-SNAPSHOT</version> >+ <relativePath>../</relativePath> >+ </parent> >+ <groupId>org.eclipse.images</groupId> >+ <artifactId>org.eclipse.images</artifactId> >+ <version>1.0.0-SNAPSHOT</version> >+ <packaging>jar</packaging> >+ <name>Eclipse Images SVG Repository</name> > </project> >diff --git a/pom.xml b/pom.xml >new file mode 100644 >index 0000000..6684193 >--- /dev/null >+++ b/pom.xml >@@ -0,0 +1,87 @@ >+<?xml version="1.0" encoding="UTF-8"?> >+<!-- >+ Copyright (c) 2015 l33t labs LLC. >+ All rights reserved. This program and the accompanying materials >+ are made available under the terms of the Eclipse Distribution License v1.0 >+ which accompanies this distribution, and is available at >+ http://www.eclipse.org/org/documents/edl-v10.php >+ >+ Contributors: >+ Tony McCrary - initial implementation >+--> >+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> >+ <modelVersion>4.0.0</modelVersion> >+ >+ <parent> >+ <groupId>org.eclipse</groupId> >+ <artifactId>eclipse-platform-parent</artifactId> >+ <version>4.6.0-SNAPSHOT</version> >+ <relativePath>../eclipse-platform-parent</relativePath> >+ </parent> >+ >+ <groupId>eclipse.images</groupId> >+ <artifactId>org.eclipse.images.parent</artifactId> >+ <packaging>pom</packaging> >+ <name>Eclipse Images</name> >+ >+ <properties> >+ <tycho.scmUrl>scm:git:git://git.eclipse.org/gitroot/platform/eclipse.platform.images.git</tycho.scmUrl> >+ </properties> >+ >+ <repositories> >+ <repository> >+ <releases> >+ <enabled>true</enabled> >+ </releases> >+ <snapshots> >+ <enabled>true</enabled> >+ </snapshots> >+ <id>eclipse-hosted</id> >+ <url>https://repo.eclipse.org/content/repositories/eclipse/</url> >+ </repository> >+ </repositories> >+ >+ <modules> >+ <module>org.eclipse.images</module> >+ <module>org.eclipse.images.renderer</module> >+ </modules> >+ <build> >+ <pluginManagement> >+ <plugins> >+ <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> >+ <plugin> >+ <groupId>org.eclipse.m2e</groupId> >+ <artifactId>lifecycle-mapping</artifactId> >+ <version>1.0.0</version> >+ <configuration> >+ <lifecycleMappingMetadata> >+ <pluginExecutions> >+ <pluginExecution> >+ <pluginExecutionFilter> >+ <groupId> >+ org.eclipse.cbi.maven.plugins >+ </groupId> >+ <artifactId> >+ eclipse-cbi-plugin >+ </artifactId> >+ <versionRange> >+ [1.0.5,) >+ </versionRange> >+ <goals> >+ <goal> >+ generate-api-build-xml >+ </goal> >+ </goals> >+ </pluginExecutionFilter> >+ <action> >+ <ignore></ignore> >+ </action> >+ </pluginExecution> >+ </pluginExecutions> >+ </lifecycleMappingMetadata> >+ </configuration> >+ </plugin> >+ </plugins> >+ </pluginManagement> >+ </build> >+</project>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 422139
: 256453