|
6 | 6 |
|
7 | 7 | import org.eclipse.core.runtime.Platform;
|
8 | 8 | import org.eclipse.jface.resource.ColorRegistry;
|
| 9 | +import org.eclipse.jface.resource.FontRegistry; |
| 10 | +import org.eclipse.jface.resource.JFaceResources; |
9 | 11 | import org.eclipse.swt.graphics.Color;
|
10 | 12 | import org.eclipse.swt.graphics.RGB;
|
11 | 13 | import org.eclipse.ui.PlatformUI;
|
@@ -102,6 +104,7 @@ public String replaceCssVariables(String html) {
|
102 | 104 | htmlStyled = htmlStyled.replace("<style nonce=\"ideNonce\" data-ide-style></style>", css);
|
103 | 105 | htmlStyled = htmlStyled.replace("var(--default-font)",
|
104 | 106 | " ui-sans-serif, \"SF Pro Text\", \"Segoe UI\", \"Ubuntu\", Tahoma, Geneva, Verdana, sans-serif;");
|
| 107 | + htmlStyled = htmlStyled.replace("var(--main-font-size)", getScaledFontSize()); |
105 | 108 |
|
106 | 109 | // Replace CSS variables with actual color values
|
107 | 110 | htmlStyled = htmlStyled.replace("var(--text-color)",
|
@@ -132,6 +135,19 @@ public String replaceCssVariables(String html) {
|
132 | 135 | return htmlStyled;
|
133 | 136 | }
|
134 | 137 |
|
| 138 | + private String getScaledFontSize() { |
| 139 | + int defaultHeight; |
| 140 | + try { |
| 141 | + defaultHeight = getCurrentTheme().getFontRegistry().getFontData(JFaceResources.TEXT_FONT)[0].getHeight(); |
| 142 | + } catch (IllegalStateException e) { |
| 143 | + defaultHeight = 13; |
| 144 | + } |
| 145 | + // Language server HTML assumes a base font size of 10px. The default Eclipse font size is 17px (13pt), so we |
| 146 | + // apply a scaling factor here. This ensures that HTML fonts scale correctly if the user changes the text size. |
| 147 | + int scaledHeight = (int) (defaultHeight / 1.7); |
| 148 | + return scaledHeight + "pt"; |
| 149 | + } |
| 150 | + |
135 | 151 | public String getColorAsHex(String colorKey, String defaultColor) {
|
136 | 152 | if (Preferences.getInstance().isTest()) {
|
137 | 153 | return "";
|
|
0 commit comments