Mercurial > hg > release > icedtea-web-1.7
changeset 1445:483cc3f4db73
Splash-screen text renderers adapted to different fonts on windows. It is miracle splash screen is working on windows...
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Mon, 22 May 2017 19:33:13 +0200 |
parents | 22933dfe94ac |
children | c72a8aea9450 |
files | AUTHORS ChangeLog netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRenderer.java netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevel.java tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/MovingTextTest.java tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRendererTest.java tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevelTest.java |
diffstat | 7 files changed, 69 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/AUTHORS Mon May 22 18:57:58 2017 +0200 +++ b/AUTHORS Mon May 22 19:33:13 2017 +0200 @@ -36,6 +36,7 @@ Joshua Sumali <jsumali@redhat.com> Michal Vala <mvala@redhat.com> Jiri Vanek <jvanek@redhat.com> +Tomáš Votava <tomcacolca@gmail.com> Mark Wielaard <mark@klomp.org> Jacob Wisor <gitne@excite.co.jp> Man Lung Wong <mwong@redhat.com>
--- a/ChangeLog Mon May 22 18:57:58 2017 +0200 +++ b/ChangeLog Mon May 22 19:33:13 2017 +0200 @@ -1,3 +1,16 @@ +2017-05-22 Jiri Vanek <jvanek@redhat.com> + Tomáš Votava <tomcacolca@gmail.com> + + Splash-screen text renderers adapted to different fonts on windows. It is miracle splash screen is working on windows... + * AUTHORS: added Tom + * netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRenderer.java: cutTo now returns rectangle in vain attempt to find center + * netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevel.java: same + * tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/MovingTextTest.java: + where possible, used relative measurements. hardcoded if values otherwise + * tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRendererTest.java: same + * tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevelTest.java: same + + 2017-05-22 Jiri Vanek <jvanek@redhat.com> Tomáš Votava <tomcacolca@gmail.com> @@ -83,7 +96,7 @@ Michal Vala <mvala@redhat.com> Added support for MSI generation - * AUTHORS: added MIchal and Alex + * AUTHORS: added Michal and Alex * Makefile.am: added win-installer target. For now missing clean * acinclude.m4: all search macros enhanced for cygpath on windows, java read from path (if available, windows only), added IT_CHECK_FOR_WIX macro
--- a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRenderer.java Mon May 22 18:57:58 2017 +0200 +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRenderer.java Mon May 22 19:33:13 2017 +0200 @@ -80,7 +80,7 @@ return img.getHeight(null); } - public void cutTo(Graphics2D g2, int x, int y) { + public Rectangle cutTo(Graphics2D g2, int x, int y) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -98,6 +98,7 @@ g2.draw(shape); g2.setClip(shape); g2.drawImage(getImg(), r.x, r.y, r.width, r.height, null); + return r; }
--- a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevel.java Mon May 22 18:57:58 2017 +0200 +++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevel.java Mon May 22 19:33:13 2017 +0200 @@ -42,6 +42,7 @@ import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Point; +import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.util.Random; @@ -117,12 +118,12 @@ } @Override - public void cutTo(Graphics2D g2, int x, int y) { + public Rectangle cutTo(Graphics2D g2, int x, int y) { if (this.getImg() == null) { this.setImg(getBackground()); } if (this.getImg() == null) { - return; + return null; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setFont(getFont()); @@ -132,7 +133,7 @@ g2.drawString(getText(), x - 2, y); g2.drawString(getText(), x + 2, y); //sorry, cuted text have disturbed borders - super.cutTo(g2, x, y); + return super.cutTo(g2, x, y); } /**
--- a/tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/MovingTextTest.java Mon May 22 18:57:58 2017 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/MovingTextTest.java Mon May 22 19:33:13 2017 +0200 @@ -36,13 +36,13 @@ exception statement from your version. */ package net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012; -import net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012.MovingText; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import org.junit.Assert; import org.junit.Test; +import net.sourceforge.jnlp.splashscreen.impls.defaultsplashscreen2012.TextWithWaterLevel; public class MovingTextTest { @@ -133,10 +133,10 @@ bic = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); ifc.cutTo(bic.createGraphics(), 0, h); Color cc = new Color(0, 0, 0); - assertNotEquals(cc, new Color(bic.getRGB(52, 142))); - assertNotEquals(cc, new Color(bic.getRGB(170, 110))); - assertNotEquals(cc, new Color(bic.getRGB(52, 62))); - assertNotEquals(cc, new Color(bic.getRGB(245, 85))); + assertNotEquals(cc, new Color(bic.getRGB((int) (w * TextWithWaterLevelTest.firstLetterMiddleWidth), (int) (h * TextWithWaterLevelTest.firstLetterLowerHeight)))); + assertNotEquals(cc, new Color(bic.getRGB((int) (w * TextWithWaterLevelTest.secondLetterLeftWidth), (int) (h * TextWithWaterLevelTest.secondLetterMiddleHeight)))); + assertNotEquals(cc, new Color(bic.getRGB((int) (w * TextWithWaterLevelTest.firstLetterMiddleWidth), (int) (h * TextWithWaterLevelTest.firstLetterUpperHeight)))); + assertNotEquals(cc, new Color(bic.getRGB((int) (w * TextWithWaterLevelTest.secondLetterRightWidth), (int) (h * TextWithWaterLevelTest.secondLetterUpperHeight)))); //well this should be acctually rgba 0,0,0,0 but somehow this was no passig //you can confirm with:
--- a/tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRendererTest.java Mon May 22 18:57:58 2017 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextOutlineRendererTest.java Mon May 22 19:33:13 2017 +0200 @@ -42,14 +42,19 @@ import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; +import net.sourceforge.jnlp.annotations.WindowsIssue; +import net.sourceforge.jnlp.runtime.JNLPRuntime; import org.junit.Assert; import org.junit.Test; public class TextOutlineRendererTest { + final int imageSize = 100; + final int zero = 0; + @Test public void getSetTest() { - BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); + BufferedImage bi = new BufferedImage(imageSize, imageSize, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bi.createGraphics(); Font f1 = g2d.getFont().deriveFont(Font.ITALIC); Font f2 = g2d.getFont().deriveFont(Font.BOLD); @@ -62,8 +67,8 @@ Assert.assertEquals(s, ifc.getText()); Assert.assertEquals(Color.BLACK, ifc.getTextOutline()); ifc.setImg(bi); - Assert.assertEquals(100, ifc.getHeight()); - Assert.assertEquals(100, ifc.getWidth()); + Assert.assertEquals(imageSize, ifc.getHeight()); + Assert.assertEquals(imageSize, ifc.getWidth()); Assert.assertEquals(f1, ifc.getFont()); Assert.assertEquals(bi, ifc.getImg()); Assert.assertEquals(s, ifc.getText()); @@ -73,8 +78,8 @@ xfc.setImg(bi); xfc.setFont(f2); String ss = "HelloHello"; - Assert.assertEquals(100, xfc.getHeight()); - Assert.assertEquals(100, xfc.getWidth()); + Assert.assertEquals(imageSize, xfc.getHeight()); + Assert.assertEquals(imageSize, xfc.getWidth()); Assert.assertEquals(f2, xfc.getFont()); Assert.assertEquals(bi, xfc.getImg()); Assert.assertEquals(s, xfc.getText()); @@ -85,32 +90,44 @@ } @Test + @WindowsIssue + //hardcoded values cannot be metrified, the solution to find the centre is unknown. public void cutToTest() { - BufferedImage bi1 = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); + BufferedImage bi1 = new BufferedImage(imageSize, imageSize, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d1 = bi1.createGraphics(); g2d1.setColor(Color.red); - g2d1.fillRect(0, 0, 100, 100); + g2d1.fillRect(zero, zero, imageSize, imageSize); - BufferedImage bi2 = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); + BufferedImage bi2 = new BufferedImage(imageSize, imageSize, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d2 = bi2.createGraphics(); g2d2.setColor(Color.blue); - g2d2.fillRect(0, 0, 100, 100); + g2d2.fillRect(zero, zero, imageSize, imageSize); TextOutlineRenderer ifc = new TextOutlineRenderer(g2d1.getFont().deriveFont(Font.BOLD, 130), "O"); ifc.setImg(bi1); - ifc.cutTo(g2d2, -5, 100); + ifc.cutTo(g2d2, -5, imageSize); + Color c2 = null; + Color c3 = null; + Color c5 = null; Color c1 = new Color(bi2.getRGB(1, 1)); + Color c4 = new Color(bi2.getRGB(70, 70)); + if (JNLPRuntime.isWindows()) { + c2 = new Color(bi2.getRGB(45, 54)); + c3 = new Color(bi2.getRGB(27, 27)); + c5 = new Color(bi2.getRGB(20, 52)); + } else { + c2 = new Color(bi2.getRGB(50, 50)); + c3 = new Color(bi2.getRGB(30, 30)); + c5 = new Color(bi2.getRGB(26, 52)); + } Assert.assertEquals(Color.blue, c1); - Color c2 = new Color(bi2.getRGB(50, 50)); Assert.assertEquals(Color.blue, c2); - Color c3 = new Color(bi2.getRGB(30, 30)); Assert.assertEquals(Color.red, c3); - Color c4 = new Color(bi2.getRGB(70, 70)); Assert.assertEquals(Color.red, c4); - Color c5 = new Color(bi2.getRGB(26, 52)); Assert.assertEquals(Color.black, c5); + } public static void save(BufferedImage bi1, String string) {
--- a/tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevelTest.java Mon May 22 18:57:58 2017 +0200 +++ b/tests/netx/unit/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/TextWithWaterLevelTest.java Mon May 22 19:33:13 2017 +0200 @@ -45,6 +45,14 @@ public class TextWithWaterLevelTest { + static final double firstLetterMiddleWidth = 0.1947565543; + static final double firstLetterLowerHeight = 0.934210526; + static final double secondLetterLeftWidth = 0.63670412; + static final double secondLetterMiddleHeight = 0.723684211; + static final double firstLetterUpperHeight = 0.43902439; + static final double secondLetterRightWidth = 0.917602996; + static final double secondLetterUpperHeight = 0.559210526; + @Test public void setGetTest() { BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); @@ -105,7 +113,6 @@ @Test public void cutToTest() { - double firstColumnSharedWidth = 0.1947565543; TextWithWaterLevel ifc = getInstance(); ifc.setPercentageOfWater(50); BufferedImage bic = ifc.getBackground(); @@ -113,10 +120,10 @@ int h = bic.getHeight(); bic = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); ifc.cutTo(bic.createGraphics(), 0, h); - Assert.assertEquals(Color.blue, new Color(bic.getRGB((int) (w * firstColumnSharedWidth), (int) (h * 0.93421052631)))); - Assert.assertEquals(Color.blue, new Color(bic.getRGB((int) (w * 0.63670411985), (int) (h * 0.72368421052)))); - Assert.assertEquals(Color.white, new Color(bic.getRGB((int) (w * firstColumnSharedWidth), (int) (h * 0.45)))); - Assert.assertEquals(Color.white, new Color(bic.getRGB((int) (w * 0.91760299625), (int) (h * 0.55921052631)))); + Assert.assertEquals(Color.blue, new Color(bic.getRGB((int) (w * firstLetterMiddleWidth), (int) (h * firstLetterLowerHeight)))); + Assert.assertEquals(Color.blue, new Color(bic.getRGB((int) (w * secondLetterLeftWidth), (int) (h * secondLetterMiddleHeight)))); + Assert.assertEquals(Color.white, new Color(bic.getRGB((int) (w * firstLetterMiddleWidth), (int) (h * firstLetterUpperHeight)))); + Assert.assertEquals(Color.white, new Color(bic.getRGB((int) (w * secondLetterRightWidth), (int) (h * secondLetterUpperHeight)))); //well this should be acctually rgba 0,0,0,0 but somehow this was no passig //you can confirm with: