modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGCanvas.java

Print this page
rev 7082 : RT-37148: [Graphics, Text, Canvas] Draw gradient text broken for Canvas.

@@ -1297,30 +1297,41 @@
                 }
                 if (gr != null) {
                     if (maxWidth > 0.0 && layoutWidth > maxWidth) {
                         float sx = maxWidth / layoutWidth;
                         if (rtl) {
-                            x += maxWidth;
-                            gr.translate(x - xAlign * sx, y - yAlign);
+                            gr.translate(x + maxWidth - xAlign * sx, y - yAlign);
                             gr.scale(-sx, 1);
                         } else {
                             gr.translate(x - xAlign * sx, y - yAlign);
                             gr.scale(sx, 1);
                         }
-                        ngtext.setLayoutLocation(0, 0);
                     } else {
                         if (rtl) {
-                            x = -(x + layoutWidth);
-                            xAlign = -xAlign;
+                            gr.translate(x + layoutWidth - xAlign, y - yAlign);
                             gr.scale(-1, 1);
+                        } else {
+                            gr.translate(x - xAlign, y - yAlign);
                         }
-                        ngtext.setLayoutLocation(xAlign - x, yAlign - y);
                     }
                     if (token == FILL_TEXT) {
                         ngtext.setMode(NGShape.Mode.FILL);
                         ngtext.setFillPaint(fillPaint);
+                        if (fillPaint.getType() == Paint.Type.LINEAR_GRADIENT && fillPaint.isProportional()) {
+                            ngtext.setContentBounds(new RectBounds(0, 0, layoutWidth, layoutHeight));
+                        }
                     } else {
+                        if (strokePaint.getType() == Paint.Type.LINEAR_GRADIENT && strokePaint.isProportional()) {
+                            int flag = PrismTextLayout.TYPE_TEXT;
+                            Shape textShape = textLayout.getShape(flag, null);
+                            RectBounds shapeBounds = new RectBounds();
+                            strokebounds(getStroke(), textShape, shapeBounds, BaseTransform.IDENTITY_TRANSFORM);
+                            RectBounds textBounds = new RectBounds();
+                            textLayout.getBounds(null, textBounds);
+                            textBounds.unionWith(shapeBounds);
+                            ngtext.setContentBounds(textBounds);
+                        }
                         ngtext.setMode(NGShape.Mode.STROKE);
                         ngtext.setDrawStroke(getStroke());
                         ngtext.setDrawPaint(strokePaint);
                     }
                     ngtext.setFont(pgfont);