4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import * as platform from 'vs/base/common/platform' ;
7
- import { EditorOptions , EditorOption , FindComputedEditorOptionValueById , EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions' ;
7
+ import { EditorFontVariations , EditorOptions , EditorOption , FindComputedEditorOptionValueById , EDITOR_FONT_DEFAULTS } from 'vs/editor/common/config/editorOptions' ;
8
8
import { EditorZoom } from 'vs/editor/common/config/editorZoom' ;
9
9
10
10
/**
@@ -36,28 +36,30 @@ export class BareFontInfo {
36
36
const fontWeight = options . get ( EditorOption . fontWeight ) ;
37
37
const fontSize = options . get ( EditorOption . fontSize ) ;
38
38
const fontFeatureSettings = options . get ( EditorOption . fontLigatures ) ;
39
+ const fontVariationSettings = options . get ( EditorOption . fontVariations ) ;
39
40
const lineHeight = options . get ( EditorOption . lineHeight ) ;
40
41
const letterSpacing = options . get ( EditorOption . letterSpacing ) ;
41
- return BareFontInfo . _create ( fontFamily , fontWeight , fontSize , fontFeatureSettings , lineHeight , letterSpacing , pixelRatio , ignoreEditorZoom ) ;
42
+ return BareFontInfo . _create ( fontFamily , fontWeight , fontSize , fontFeatureSettings , fontVariationSettings , lineHeight , letterSpacing , pixelRatio , ignoreEditorZoom ) ;
42
43
}
43
44
44
45
/**
45
46
* @internal
46
47
*/
47
- public static createFromRawSettings ( opts : { fontFamily ?: string | string [ ] ; fontWeight ?: string ; fontSize ?: number ; fontLigatures ?: boolean | string ; lineHeight ?: number ; letterSpacing ?: number } , pixelRatio : number , ignoreEditorZoom : boolean = false ) : BareFontInfo {
48
+ public static createFromRawSettings ( opts : { fontFamily ?: string | string [ ] ; fontWeight ?: string ; fontSize ?: number ; fontLigatures ?: boolean | string ; fontVariations ?: boolean | string ; lineHeight ?: number ; letterSpacing ?: number } , pixelRatio : number , ignoreEditorZoom : boolean = false ) : BareFontInfo {
48
49
const fontFamily = EditorOptions . fontFamily . validate ( opts . fontFamily ) ;
49
50
const fontWeight = EditorOptions . fontWeight . validate ( opts . fontWeight ) ;
50
51
const fontSize = EditorOptions . fontSize . validate ( opts . fontSize ) ;
51
52
const fontFeatureSettings = EditorOptions . fontLigatures2 . validate ( opts . fontLigatures ) ;
53
+ const fontVariationSettings = EditorOptions . fontVariations . validate ( opts . fontVariations ) ;
52
54
const lineHeight = EditorOptions . lineHeight . validate ( opts . lineHeight ) ;
53
55
const letterSpacing = EditorOptions . letterSpacing . validate ( opts . letterSpacing ) ;
54
- return BareFontInfo . _create ( fontFamily , fontWeight , fontSize , fontFeatureSettings , lineHeight , letterSpacing , pixelRatio , ignoreEditorZoom ) ;
56
+ return BareFontInfo . _create ( fontFamily , fontWeight , fontSize , fontFeatureSettings , fontVariationSettings , lineHeight , letterSpacing , pixelRatio , ignoreEditorZoom ) ;
55
57
}
56
58
57
59
/**
58
60
* @internal
59
61
*/
60
- private static _create ( fontFamily : string , fontWeight : string , fontSize : number , fontFeatureSettings : string , lineHeight : number , letterSpacing : number , pixelRatio : number , ignoreEditorZoom : boolean ) : BareFontInfo {
62
+ private static _create ( fontFamily : string , fontWeight : string , fontSize : number , fontFeatureSettings : string , fontVariationSettings : string , lineHeight : number , letterSpacing : number , pixelRatio : number , ignoreEditorZoom : boolean ) : BareFontInfo {
61
63
if ( lineHeight === 0 ) {
62
64
lineHeight = GOLDEN_LINE_HEIGHT_RATIO * fontSize ;
63
65
} else if ( lineHeight < MINIMUM_LINE_HEIGHT ) {
@@ -75,12 +77,23 @@ export class BareFontInfo {
75
77
fontSize *= editorZoomLevelMultiplier ;
76
78
lineHeight *= editorZoomLevelMultiplier ;
77
79
80
+ if ( fontVariationSettings === EditorFontVariations . TRANSLATE ) {
81
+ if ( fontWeight === 'normal' || fontWeight === 'bold' ) {
82
+ fontVariationSettings = EditorFontVariations . OFF ;
83
+ } else {
84
+ const fontWeightAsNumber = parseInt ( fontWeight , 10 ) ;
85
+ fontVariationSettings = `'wght' ${ fontWeightAsNumber } ` ;
86
+ fontWeight = 'normal' ;
87
+ }
88
+ }
89
+
78
90
return new BareFontInfo ( {
79
91
pixelRatio : pixelRatio ,
80
92
fontFamily : fontFamily ,
81
93
fontWeight : fontWeight ,
82
94
fontSize : fontSize ,
83
95
fontFeatureSettings : fontFeatureSettings ,
96
+ fontVariationSettings,
84
97
lineHeight : lineHeight ,
85
98
letterSpacing : letterSpacing
86
99
} ) ;
@@ -91,6 +104,7 @@ export class BareFontInfo {
91
104
readonly fontWeight : string ;
92
105
readonly fontSize : number ;
93
106
readonly fontFeatureSettings : string ;
107
+ readonly fontVariationSettings : string ;
94
108
readonly lineHeight : number ;
95
109
readonly letterSpacing : number ;
96
110
@@ -103,6 +117,7 @@ export class BareFontInfo {
103
117
fontWeight : string ;
104
118
fontSize : number ;
105
119
fontFeatureSettings : string ;
120
+ fontVariationSettings : string ;
106
121
lineHeight : number ;
107
122
letterSpacing : number ;
108
123
} ) {
@@ -111,6 +126,7 @@ export class BareFontInfo {
111
126
this . fontWeight = String ( opts . fontWeight ) ;
112
127
this . fontSize = opts . fontSize ;
113
128
this . fontFeatureSettings = opts . fontFeatureSettings ;
129
+ this . fontVariationSettings = opts . fontVariationSettings ;
114
130
this . lineHeight = opts . lineHeight | 0 ;
115
131
this . letterSpacing = opts . letterSpacing ;
116
132
}
@@ -119,7 +135,7 @@ export class BareFontInfo {
119
135
* @internal
120
136
*/
121
137
public getId ( ) : string {
122
- return `${ this . pixelRatio } -${ this . fontFamily } -${ this . fontWeight } -${ this . fontSize } -${ this . fontFeatureSettings } -${ this . lineHeight } -${ this . letterSpacing } ` ;
138
+ return `${ this . pixelRatio } -${ this . fontFamily } -${ this . fontWeight } -${ this . fontSize } -${ this . fontFeatureSettings } -${ this . fontVariationSettings } - ${ this . lineHeight } -${ this . letterSpacing } ` ;
123
139
}
124
140
125
141
/**
@@ -148,7 +164,7 @@ export class BareFontInfo {
148
164
}
149
165
150
166
// change this whenever `FontInfo` members are changed
151
- export const SERIALIZED_FONT_INFO_VERSION = 1 ;
167
+ export const SERIALIZED_FONT_INFO_VERSION = 2 ;
152
168
153
169
export class FontInfo extends BareFontInfo {
154
170
readonly _editorStylingBrand : void = undefined ;
@@ -173,6 +189,7 @@ export class FontInfo extends BareFontInfo {
173
189
fontWeight : string ;
174
190
fontSize : number ;
175
191
fontFeatureSettings : string ;
192
+ fontVariationSettings : string ;
176
193
lineHeight : number ;
177
194
letterSpacing : number ;
178
195
isMonospace : boolean ;
@@ -205,6 +222,7 @@ export class FontInfo extends BareFontInfo {
205
222
&& this . fontWeight === other . fontWeight
206
223
&& this . fontSize === other . fontSize
207
224
&& this . fontFeatureSettings === other . fontFeatureSettings
225
+ && this . fontVariationSettings === other . fontVariationSettings
208
226
&& this . lineHeight === other . lineHeight
209
227
&& this . letterSpacing === other . letterSpacing
210
228
&& this . typicalHalfwidthCharacterWidth === other . typicalHalfwidthCharacterWidth
0 commit comments