jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject [jmeter] branch master updated: Ensure all used fonts support fallback fonts by using methods that preserve the underlying Font2D handle. (#618)
Date Wed, 07 Oct 2020 11:51:20 GMT
This is an automated email from the ASF dual-hosted git repository.

pmouawad pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new fc334b0  Ensure all used fonts support fallback fonts by using methods that preserve
the underlying Font2D handle. (#618)
fc334b0 is described below

commit fc334b0426b48a1ee86015a1fba52d274c479f54
Author: Jannis Weis <31143295+weisJ@users.noreply.github.com>
AuthorDate: Wed Oct 7 13:51:06 2020 +0200

    Ensure all used fonts support fallback fonts by using methods that preserve the underlying
Font2D handle. (#618)
    
    Ensure fallback enabled fonts are used
---
 .../org/apache/jmeter/visualizers/AxisGraph.java   |  3 +-
 .../jmeter/visualizers/MailerVisualizer.java       |  3 +-
 .../visualizers/RespTimeGraphVisualizer.java       |  8 +++--
 .../jmeter/visualizers/StatGraphVisualizer.java    | 12 +++++---
 .../apache/jmeter/gui/util/JSyntaxTextArea.java    |  2 +-
 .../org/apache/jorphan/gui/JMeterUIDefaults.java   | 34 ++++++++++++++++++++--
 .../protocol/http/config/gui/UrlConfigGui.java     |  6 ----
 7 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/AxisGraph.java b/src/components/src/main/java/org/apache/jmeter/visualizers/AxisGraph.java
index 14ffcbc..3de8a94 100644
--- a/src/components/src/main/java/org/apache/jmeter/visualizers/AxisGraph.java
+++ b/src/components/src/main/java/org/apache/jmeter/visualizers/AxisGraph.java
@@ -30,6 +30,7 @@ import javax.swing.JPanel;
 import javax.swing.UIManager;
 
 import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.gui.JMeterUIDefaults;
 import org.jCharts.axisChart.AxisChart;
 import org.jCharts.axisChart.customRenderers.axisValue.renderers.ValueLabelPosition;
 import org.jCharts.axisChart.customRenderers.axisValue.renderers.ValueLabelRenderer;
@@ -82,7 +83,7 @@ public class AxisGraph extends JPanel {
 
     private static final Font FONT_DEFAULT = UIManager.getDefaults().getFont("TextField.font");
 
-    protected Font valueFont = new Font("SansSerif", Font.PLAIN, (int) Math.round(FONT_DEFAULT.getSize()
* 0.6));
+    protected Font valueFont = JMeterUIDefaults.createFont("SansSerif", Font.PLAIN, (int)
Math.round(FONT_DEFAULT.getSize() * 0.6));
 
     protected Color[] color = { Color.YELLOW };
 
diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/MailerVisualizer.java
b/src/components/src/main/java/org/apache/jmeter/visualizers/MailerVisualizer.java
index b24ea2b..aaaa058 100644
--- a/src/components/src/main/java/org/apache/jmeter/visualizers/MailerVisualizer.java
+++ b/src/components/src/main/java/org/apache/jmeter/visualizers/MailerVisualizer.java
@@ -49,6 +49,7 @@ import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.testelement.TestElement;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
+import org.apache.jorphan.gui.JMeterUIDefaults;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -283,7 +284,7 @@ public class MailerVisualizer extends AbstractVisualizer implements ActionListen
                 MailerModel.MailAuthType.NONE.toString(),
                 MailerModel.MailAuthType.SSL.toString(),
                 MailerModel.MailAuthType.TLS.toString()});
-        authTypeCombo.setFont(new Font("SansSerif", Font.PLAIN, 10)); // $NON-NLS-1$
+        authTypeCombo.setFont(JMeterUIDefaults.createFont("SansSerif", Font.PLAIN, 10));
// $NON-NLS-1$
         authTypePane.add(authTypeCombo, BorderLayout.CENTER);
 
         JPanel credPane = new JPanel(new BorderLayout());
diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java
b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java
index 234c96f..59ad93f 100644
--- a/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java
+++ b/src/components/src/main/java/org/apache/jmeter/visualizers/RespTimeGraphVisualizer.java
@@ -21,7 +21,6 @@ import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
-import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.text.SimpleDateFormat;
@@ -66,6 +65,7 @@ import org.apache.jmeter.visualizers.utils.Colors;
 import org.apache.jorphan.gui.GuiUtils;
 import org.apache.jorphan.gui.JFactory;
 import org.apache.jorphan.gui.JLabeledTextField;
+import org.apache.jorphan.gui.JMeterUIDefaults;
 import org.apache.jorphan.math.StatCalculatorLong;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -373,10 +373,12 @@ public class RespTimeGraphVisualizer extends AbstractVisualizer implements
Actio
         graphPanel.setPointShape(StatGraphProperties.getPointShapeMap().get(pointShapeLine.getSelectedItem()));
         graphPanel.setStrokeWidth(Float.parseFloat((String) strokeWidthList.getSelectedItem()));
 
-        graphPanel.setTitleFont(new Font(StatGraphProperties.getFontNameMap().get(titleFontNameList.getSelectedItem()),
+        graphPanel.setTitleFont(JMeterUIDefaults.createFont(
+                StatGraphProperties.getFontNameMap().get(titleFontNameList.getSelectedItem()),
                 StatGraphProperties.getFontStyleMap().get(titleFontStyleList.getSelectedItem()),
                 Integer.parseInt((String) titleFontSizeList.getSelectedItem())));
-        graphPanel.setLegendFont(new Font(StatGraphProperties.getFontNameMap().get(fontNameList.getSelectedItem()),
+        graphPanel.setLegendFont(JMeterUIDefaults.createFont(
+                StatGraphProperties.getFontNameMap().get(fontNameList.getSelectedItem()),
                 StatGraphProperties.getFontStyleMap().get(fontStyleList.getSelectedItem()),
                 Integer.parseInt((String) fontSizeList.getSelectedItem())));
 
diff --git a/src/components/src/main/java/org/apache/jmeter/visualizers/StatGraphVisualizer.java
b/src/components/src/main/java/org/apache/jmeter/visualizers/StatGraphVisualizer.java
index 9ab55b2..7ce6d37 100644
--- a/src/components/src/main/java/org/apache/jmeter/visualizers/StatGraphVisualizer.java
+++ b/src/components/src/main/java/org/apache/jmeter/visualizers/StatGraphVisualizer.java
@@ -81,6 +81,7 @@ import org.apache.jmeter.visualizers.gui.AbstractVisualizer;
 import org.apache.jorphan.gui.GuiUtils;
 import org.apache.jorphan.gui.JFactory;
 import org.apache.jorphan.gui.JLabeledTextField;
+import org.apache.jorphan.gui.JMeterUIDefaults;
 import org.apache.jorphan.gui.NumberRenderer;
 import org.apache.jorphan.gui.ObjectTableModel;
 import org.apache.jorphan.gui.ObjectTableSorter;
@@ -622,13 +623,16 @@ public class StatGraphVisualizer extends AbstractVisualizer implements
Clearable
         graphPanel.setLegendPlacement(StatGraphProperties.getPlacementNameMap()
                 .get(legendPlacementList.getSelectedItem()));
 
-        graphPanel.setTitleFont(new Font(StatGraphProperties.getFontNameMap().get(titleFontNameList.getSelectedItem()),
+        graphPanel.setTitleFont(JMeterUIDefaults.createFont(
+                StatGraphProperties.getFontNameMap().get(titleFontNameList.getSelectedItem()),
                 StatGraphProperties.getFontStyleMap().get(titleFontStyleList.getSelectedItem()),
                 Integer.parseInt((String) titleFontSizeList.getSelectedItem())));
-        graphPanel.setLegendFont(new Font(StatGraphProperties.getFontNameMap().get(fontNameList.getSelectedItem()),
+        graphPanel.setLegendFont(JMeterUIDefaults.createFont(
+                StatGraphProperties.getFontNameMap().get(fontNameList.getSelectedItem()),
                 StatGraphProperties.getFontStyleMap().get(fontStyleList.getSelectedItem()),
                 Integer.parseInt((String) fontSizeList.getSelectedItem())));
-        graphPanel.setValueFont(new Font(StatGraphProperties.getFontNameMap().get(valueFontNameList.getSelectedItem()),
+        graphPanel.setValueFont(JMeterUIDefaults.createFont(
+                StatGraphProperties.getFontNameMap().get(valueFontNameList.getSelectedItem()),
                 StatGraphProperties.getFontStyleMap().get(valueFontStyleList.getSelectedItem()),
                 Integer.parseInt((String) valueFontSizeList.getSelectedItem())));
 
@@ -926,7 +930,7 @@ public class StatGraphVisualizer extends AbstractVisualizer implements
Clearable
 
     private JPanel createGraphTitlePane() {
         JPanel titleNamePane = new JPanel(new BorderLayout());
-        syncWithName.setFont(new Font("SansSerif", Font.PLAIN, 10));
+        syncWithName.setFont(JMeterUIDefaults.createFont("SansSerif", Font.PLAIN, 10));
         titleNamePane.add(graphTitle, BorderLayout.CENTER);
         titleNamePane.add(syncWithName, BorderLayout.EAST);
 
diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java
index d186477..61e01ad 100644
--- a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java
+++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java
@@ -233,7 +233,7 @@ public class JSyntaxTextArea extends RSyntaxTextArea {
         this.disableUndo = disableUndo;
         if (USER_FONT_FAMILY != null) {
             int fontSize = USER_FONT_SIZE > 0 ? USER_FONT_SIZE : getFont().getSize();
-            setFont(new Font(USER_FONT_FAMILY, Font.PLAIN, fontSize));
+            setFont(JMeterUIDefaults.createFont(USER_FONT_FAMILY, Font.PLAIN, fontSize));
             if (log.isDebugEnabled()) {
                 log.debug("Font is set to: {}", getFont());
             }
diff --git a/src/jorphan/src/main/java/org/apache/jorphan/gui/JMeterUIDefaults.java b/src/jorphan/src/main/java/org/apache/jorphan/gui/JMeterUIDefaults.java
index 94e51af..ab7d771 100644
--- a/src/jorphan/src/main/java/org/apache/jorphan/gui/JMeterUIDefaults.java
+++ b/src/jorphan/src/main/java/org/apache/jorphan/gui/JMeterUIDefaults.java
@@ -30,6 +30,7 @@ import javax.swing.UIDefaults;
 import javax.swing.UIManager;
 import javax.swing.plaf.FontUIResource;
 import javax.swing.plaf.UIResource;
+import javax.swing.text.StyleContext;
 
 import org.apache.jorphan.gui.ui.TextAreaUIWithUndo;
 import org.apache.jorphan.gui.ui.TextFieldUIWithUndo;
@@ -141,6 +142,10 @@ public class JMeterUIDefaults {
         });
     }
 
+    public static Font createFont(String family, int style, int size) {
+        return stripUiResource(StyleContext.getDefaultStyleContext().getFont(family, style,
size));
+    }
+
     private static void addScaledFont(UIDefaults defaults, String output, String input, float
scale) {
         addDerivedFont(defaults, output, input, f -> f.deriveFont(f.getSize2D() * scale));
     }
@@ -154,7 +159,7 @@ public class JMeterUIDefaults {
         // Note: we drop UIResource here so LaF treats the font as user-provided rather than
         // LaF-provided.
         if (input instanceof UIResource) {
-            output = new Font(output.getAttributes());
+            output = stripUiResource(output);
         }
         return output;
     }
@@ -238,8 +243,22 @@ public class JMeterUIDefaults {
     }
 
     /**
+     * Ensures the font isn't of type {@link UIResource}.
+     *
+     * @param font the font.
+     * @return font which does not implement {@link UIResource}.
+     */
+    private static Font stripUiResource(Font font) {
+        if (font instanceof UIResource) {
+            return new NonUIResourceFont(font);
+        }
+        return font;
+    }
+
+    /**
      * Ensures {@code oldFont} and {@code newFont} either both implement {@link UIResource},
      * or none of them implement.
+     *
      * @param oldFont old font
      * @param newFont new font
      * @return Font (when oldFont does not implement UIResource) or FontUIResource (when
oldFont implements UIResource)
@@ -249,8 +268,19 @@ public class JMeterUIDefaults {
         boolean O = newFont instanceof FontUIResource;
         // This is a beautiful smile, isn't it?
         if (o ^ O) {
-            return o ? new FontUIResource(newFont) : new Font(newFont.getAttributes());
+            return o ? new FontUIResource(newFont) : stripUiResource(newFont);
         }
         return newFont;
     }
+
+    /**
+     * Non UIResource wrapper for fonts which preserves the underlying {@link sun.font.Font2D}.
+     * This way the font behaves the same way with respect to fallback fonts
+     * (i.e. if the {@link sun.font.Font2D} base is of type {@link sun.font.CompositeFont}).
+     */
+    private static class NonUIResourceFont extends Font {
+        private NonUIResourceFont(Font font) {
+            super(font);
+        }
+    }
 }
diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
index 4f29b4b..5a670e0 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/config/gui/UrlConfigGui.java
@@ -20,14 +20,12 @@ package org.apache.jmeter.protocol.http.config.gui;
 import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.FlowLayout;
-import java.awt.Font;
 
 import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
 import javax.swing.JCheckBox;
 import javax.swing.JPanel;
 import javax.swing.JTabbedPane;
-import javax.swing.UIManager;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
@@ -74,10 +72,6 @@ public class UrlConfigGui extends JPanel implements ChangeListener {
 
     private int tabFileUploadIndex = 2;
 
-    private static final Font FONT_DEFAULT = UIManager.getDefaults().getFont("TextField.font");
-
-    private static final Font FONT_SMALL = new Font("SansSerif", Font.PLAIN, (int) Math.round(FONT_DEFAULT.getSize()
* 0.8));
-
     private HTTPArgumentsPanel argsPanel;
 
     private HTTPFileArgsPanel filesPanel;


Mime
View raw message