diff --git a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCBufferedContext.java b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCBufferedContext.java index f496088f4d..5f823ebaf8 100644 --- a/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCBufferedContext.java +++ b/modules/javafx.web/src/main/java/com/sun/javafx/webkit/prism/WCBufferedContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -204,6 +204,11 @@ private boolean trIntersectsClip(RectBounds bounds, BaseTransform tx) { super.saveState(); } + @Override public void scale(float sx, float sy) { + init(); + super.scale(sx, sy); + } + @Override public void setTransform(WCTransform tm) { init(); super.setTransform(tm); diff --git a/tests/system/src/test/java/test/javafx/scene/web/SVGTest.java b/tests/system/src/test/java/test/javafx/scene/web/SVGTest.java new file mode 100644 index 0000000000..2127e86cf3 --- /dev/null +++ b/tests/system/src/test/java/test/javafx/scene/web/SVGTest.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package test.javafx.scene.web; + +import java.util.concurrent.CountDownLatch; +import javafx.application.Application; +import javafx.application.Platform; +import javafx.scene.Scene; +import javafx.scene.image.PixelReader; +import javafx.scene.image.WritableImage; +import javafx.scene.paint.Color; +import javafx.scene.web.WebView; +import javafx.stage.Stage; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import test.util.Util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class SVGTest { + private static final CountDownLatch launchLatch = new CountDownLatch(1); + + // Maintain one application instance + static SVGTestApp svgTestApp; + + private WebView webView; + + public static class SVGTestApp extends Application { + Stage primaryStage = null; + + @Override + public void init() { + SVGTest.svgTestApp = this; + } + + @Override + public void start(Stage primaryStage) throws Exception { + Platform.setImplicitExit(false); + this.primaryStage = primaryStage; + launchLatch.countDown(); + } + } + + @BeforeClass + public static void setupOnce() { + // Start the Test Application + new Thread(() -> Application.launch(SVGTestApp.class, (String[])null)).start(); + + assertTrue("Timeout waiting for FX runtime to start", Util.await(launchLatch)); + } + + @AfterClass + public static void tearDownOnce() { + Platform.exit(); + } + + @Before + public void setupTestObjects() { + Platform.runLater(() -> { + webView = new WebView(); + svgTestApp.primaryStage.setScene(new Scene(webView)); + svgTestApp.primaryStage.show(); + }); + } + + /** + * @test + * @bug 8223298 + * summary Checks if svg pattern is displayed properly + */ + @Test public void testSVGRenderingWithPattern() { + final CountDownLatch webViewStateLatch = new CountDownLatch(1); + final String htmlSVGContent = "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + ""; + + Util.runAndWait(() -> { + assertNotNull(webView); + webView.getEngine().loadContent(htmlSVGContent); + webViewStateLatch.countDown(); + }); + + assertTrue("Timeout when waiting for focus change ", Util.await(webViewStateLatch)); + + Util.runAndWait(() -> { + WritableImage snapshot = svgTestApp.primaryStage.getScene().snapshot(null); + PixelReader pr = snapshot.getPixelReader(); + + Color redColor = Color.color(1, 0, 0); + assertEquals("Color should be opaque red:", redColor, pr.getColor(0, 0)); + assertEquals("Color should be opaque red:", redColor, pr.getColor(30, 30)); + assertEquals("Color should be opaque red:", redColor, pr.getColor(49, 49)); + }); + } +}