Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/FigureUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class FigureUtilities {

private static final float RGB_VALUE_MULTIPLIER = 0.6f;
private static GC gc;
private static Shell shell;
private static Font appliedFont;
private static FontMetrics metrics;
private static Color ghostFillColor = new Color(null, 31, 31, 31);
Expand Down Expand Up @@ -59,7 +60,7 @@ public static Color darker(Color color) {
public static FontMetrics getFontMetrics(Font f) {
setFont(f);
if (metrics == null) {
metrics = getGC().getFontMetrics();
metrics = gc.getFontMetrics();
}
return metrics;
}
Expand All @@ -74,14 +75,20 @@ public static FontMetrics getFontMetrics(Font f) {
@Deprecated
protected static GC getGC() {
if (gc == null) {
Shell shell = new Shell();
gc = new GC(getShell());
appliedFont = gc.getFont();
}
return gc;
}

private static Shell getShell() {
if (shell == null) {
shell = new Shell();
InternalDraw2dUtils.configureForAutoscalingMode(shell, event -> {
// ignored
});
gc = new GC(shell);
appliedFont = gc.getFont();
}
return gc;
return shell;
}

/**
Expand All @@ -95,7 +102,7 @@ protected static GC getGC() {
*/
protected static org.eclipse.swt.graphics.Point getTextDimension(String s, Font f) {
setFont(f);
return getGC().textExtent(s);
return gc.textExtent(s);
}

/**
Expand Down Expand Up @@ -123,7 +130,7 @@ public static IFigure getRoot(IFigure figure) {
*/
protected static org.eclipse.swt.graphics.Point getStringDimension(String s, Font f) {
setFont(f);
return getGC().stringExtent(s);
return gc.stringExtent(s);
}

/**
Expand Down Expand Up @@ -341,10 +348,14 @@ public static void paintEtchedBorder(Graphics g, Rectangle r) {
* @since 2.0
*/
protected static void setFont(Font f) {
if (appliedFont == f || (f != null && f.equals(appliedFont))) {
if ((appliedFont == null && f == null && gc != null) || (f != null && f.equals(appliedFont))) {
return;
}
getGC().setFont(f);
if (gc != null && !gc.isDisposed()) {
gc.dispose();
}
gc = new GC(getShell());
gc.setFont(f);
appliedFont = f;
metrics = null;
}
Expand Down
Loading