package jira; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.paint.Color; import javafx.scene.paint.CycleMethod; import javafx.scene.paint.LinearGradient; import javafx.scene.paint.Stop; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; public class RT37327 extends Application { public static final int W = 300; public static final int H = 300; @Override public void start(Stage stage) { Canvas c = new Canvas(W*2, H); LinearGradient lg = new LinearGradient(0, 0, W/4.0, 0, false, CycleMethod.REFLECT, new Stop(0, Color.YELLOW), new Stop(1, Color.BLUE)); GraphicsContext gc = c.getGraphicsContext2D(); String string = "MMMMMMMMMMMMMMMMMMMMM"; gc.setFill(lg); gc.setFont(Font.font(35)); gc.fillText(string, 4, 100); Text text = new Text(string); text.setFont(gc.getFont()); double width = text.getLayoutBounds().getWidth(); double scale = 4; gc.setFont(Font.font(35*scale)); gc.save(); gc.scale(1, 1/scale); //not altering scale X gc.fillText(string, 4, 150*scale, width); //getting a free x scale from width gc.restore(); // scale = 1; gc.scale(1/scale, 1/scale); gc.fillText(string, 4*scale, 200*scale); //no max width Scene scene = new Scene(new Group(c), W*2, H); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }