diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/actions/FontAction.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/actions/FontAction.java index c8ca56398..48a8985a8 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/actions/FontAction.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/actions/FontAction.java @@ -75,7 +75,7 @@ public void run() { String rgbValue = null; rgbValue = model.getFontColor(); - String fontValue = model.getFont(); + String fontValue = FontFactory.getPlatformDependentFontString(model.getFont()); if(fontValue != null) { try { fontData = new FontData(fontValue); diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java index 4141aec78..d179a9b63 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/AbstractDiagramModelObjectFigure.java @@ -153,7 +153,7 @@ protected void setDisabledState(Graphics graphics) { * Set the font to that in the model, or failing that, as per user's default */ protected void setFont() { - String fontName = fDiagramModelObject.getFont(); + String fontName = FontFactory.getPlatformDependentFontString(fDiagramModelObject.getFont()); setFont(FontFactory.get(fontName)); // Need to do this after font change diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/connections/AbstractDiagramConnectionFigure.java b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/connections/AbstractDiagramConnectionFigure.java index 723321b4f..a760bca80 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/connections/AbstractDiagramConnectionFigure.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/diagram/figures/connections/AbstractDiagramConnectionFigure.java @@ -178,7 +178,7 @@ protected void setConnectionText() { * Set the font in the label to that in the model, or failing that, as per user's default */ protected void setLabelFont() { - String fontName = getModelConnection().getFont(); + String fontName = FontFactory.getPlatformDependentFontString(getModelConnection().getFont()); Font font = FontFactory.get(fontName); // Possible font scaling for non 96 DPI on Windows or if property set diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/FontFactory.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/FontFactory.java index 31a1f9b28..49ce566b9 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/FontFactory.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/FontFactory.java @@ -153,7 +153,7 @@ public static Font getScaledFont96DPI(Font font) { FontData[] fd = font.getFontData(); float factor = (float)96 / DPI; - int newHeight = (int)(fd[0].getHeight() * factor); + int newHeight = Math.round(fd[0].getHeight() * factor); fd[0].setHeight(newHeight); String fontName = fd[0].toString(); @@ -168,6 +168,40 @@ public static Font getScaledFont96DPI(Font font) { return font; } + /** + * Return a FontData string with adjusted font height if the FontData string is not for the current platform. + * @param fontDataString The FontData string + * @return The Font Data String for the current platform or the same string if there is no change. + */ + public static String getPlatformDependentFontString(String fontDataString) { + if(StringUtils.isSet(fontDataString)) { + float factor = 0; + + // On Mac but fontdata contains Windows or Linux + if(PlatformUtils.isMac() && (fontDataString.contains("|WINDOWS|") || fontDataString.contains("|GTK|"))) { + factor = (float)96 / 72; + } + // On Windows or Linux but font came from Mac + else if(!PlatformUtils.isMac() && fontDataString.contains("|COCOA|")) { + factor = (float)72 / 96; + } + + if(factor != 0) { + try { + FontData fd = new FontData(fontDataString); + int newHeight = Math.round(fd.getHeight() * factor); + fd.setHeight(newHeight); + fontDataString = fd.toString(); + } + catch(Exception ex) { + //ex.printStackTrace(); + } + } + } + + return fontDataString; + } + /** * @param font * @return The italic variant of the given font diff --git a/com.archimatetool.editor/src/com/archimatetool/editor/ui/components/FontChooser.java b/com.archimatetool.editor/src/com/archimatetool/editor/ui/components/FontChooser.java index 374fb5f9f..794b3e83c 100644 --- a/com.archimatetool.editor/src/com/archimatetool/editor/ui/components/FontChooser.java +++ b/com.archimatetool.editor/src/com/archimatetool/editor/ui/components/FontChooser.java @@ -240,7 +240,7 @@ public void chooseFont() { protected void updateFont() { fFontData = FontFactory.getDefaultUserViewFontData(); - String fontValue = fFontObject.getFont(); + String fontValue = FontFactory.getPlatformDependentFontString(fFontObject.getFont()); if(fontValue != null) { try { fFontData = new FontData(fontValue); diff --git a/org.opengroup.archimate.xmlexchange/src/org/opengroup/archimate/xmlexchange/XMLModelExporter.java b/org.opengroup.archimate.xmlexchange/src/org/opengroup/archimate/xmlexchange/XMLModelExporter.java index ef8f97e8b..d1407c19c 100644 --- a/org.opengroup.archimate.xmlexchange/src/org/opengroup/archimate/xmlexchange/XMLModelExporter.java +++ b/org.opengroup.archimate.xmlexchange/src/org/opengroup/archimate/xmlexchange/XMLModelExporter.java @@ -1033,7 +1033,7 @@ Element writeFont(IFontAttribute fontObject, Element styleElement) { try { FontData fontData = null; - String fontString = fontObject.getFont(); + String fontString = FontFactory.getPlatformDependentFontString(fontObject.getFont()); if(fontString != null) { fontData = new FontData(fontString); }