44 *--------------------------------------------------------------------------------------------*/
55
66import * 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' ;
88import { EditorZoom } from 'vs/editor/common/config/editorZoom' ;
99
1010/**
@@ -36,28 +36,30 @@ export class BareFontInfo {
3636 const fontWeight = options . get ( EditorOption . fontWeight ) ;
3737 const fontSize = options . get ( EditorOption . fontSize ) ;
3838 const fontFeatureSettings = options . get ( EditorOption . fontLigatures ) ;
39+ const fontVariationSettings = options . get ( EditorOption . fontVariations ) ;
3940 const lineHeight = options . get ( EditorOption . lineHeight ) ;
4041 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 ) ;
4243 }
4344
4445 /**
4546 * @internal
4647 */
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 {
4849 const fontFamily = EditorOptions . fontFamily . validate ( opts . fontFamily ) ;
4950 const fontWeight = EditorOptions . fontWeight . validate ( opts . fontWeight ) ;
5051 const fontSize = EditorOptions . fontSize . validate ( opts . fontSize ) ;
5152 const fontFeatureSettings = EditorOptions . fontLigatures2 . validate ( opts . fontLigatures ) ;
53+ const fontVariationSettings = EditorOptions . fontVariations . validate ( opts . fontVariations ) ;
5254 const lineHeight = EditorOptions . lineHeight . validate ( opts . lineHeight ) ;
5355 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 ) ;
5557 }
5658
5759 /**
5860 * @internal
5961 */
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 {
6163 if ( lineHeight === 0 ) {
6264 lineHeight = GOLDEN_LINE_HEIGHT_RATIO * fontSize ;
6365 } else if ( lineHeight < MINIMUM_LINE_HEIGHT ) {
@@ -75,12 +77,23 @@ export class BareFontInfo {
7577 fontSize *= editorZoomLevelMultiplier ;
7678 lineHeight *= editorZoomLevelMultiplier ;
7779
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+
7890 return new BareFontInfo ( {
7991 pixelRatio : pixelRatio ,
8092 fontFamily : fontFamily ,
8193 fontWeight : fontWeight ,
8294 fontSize : fontSize ,
8395 fontFeatureSettings : fontFeatureSettings ,
96+ fontVariationSettings,
8497 lineHeight : lineHeight ,
8598 letterSpacing : letterSpacing
8699 } ) ;
@@ -91,6 +104,7 @@ export class BareFontInfo {
91104 readonly fontWeight : string ;
92105 readonly fontSize : number ;
93106 readonly fontFeatureSettings : string ;
107+ readonly fontVariationSettings : string ;
94108 readonly lineHeight : number ;
95109 readonly letterSpacing : number ;
96110
@@ -103,6 +117,7 @@ export class BareFontInfo {
103117 fontWeight : string ;
104118 fontSize : number ;
105119 fontFeatureSettings : string ;
120+ fontVariationSettings : string ;
106121 lineHeight : number ;
107122 letterSpacing : number ;
108123 } ) {
@@ -111,6 +126,7 @@ export class BareFontInfo {
111126 this . fontWeight = String ( opts . fontWeight ) ;
112127 this . fontSize = opts . fontSize ;
113128 this . fontFeatureSettings = opts . fontFeatureSettings ;
129+ this . fontVariationSettings = opts . fontVariationSettings ;
114130 this . lineHeight = opts . lineHeight | 0 ;
115131 this . letterSpacing = opts . letterSpacing ;
116132 }
@@ -119,7 +135,7 @@ export class BareFontInfo {
119135 * @internal
120136 */
121137 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 } ` ;
123139 }
124140
125141 /**
@@ -148,7 +164,7 @@ export class BareFontInfo {
148164}
149165
150166// change this whenever `FontInfo` members are changed
151- export const SERIALIZED_FONT_INFO_VERSION = 1 ;
167+ export const SERIALIZED_FONT_INFO_VERSION = 2 ;
152168
153169export class FontInfo extends BareFontInfo {
154170 readonly _editorStylingBrand : void = undefined ;
@@ -173,6 +189,7 @@ export class FontInfo extends BareFontInfo {
173189 fontWeight : string ;
174190 fontSize : number ;
175191 fontFeatureSettings : string ;
192+ fontVariationSettings : string ;
176193 lineHeight : number ;
177194 letterSpacing : number ;
178195 isMonospace : boolean ;
@@ -205,6 +222,7 @@ export class FontInfo extends BareFontInfo {
205222 && this . fontWeight === other . fontWeight
206223 && this . fontSize === other . fontSize
207224 && this . fontFeatureSettings === other . fontFeatureSettings
225+ && this . fontVariationSettings === other . fontVariationSettings
208226 && this . lineHeight === other . lineHeight
209227 && this . letterSpacing === other . letterSpacing
210228 && this . typicalHalfwidthCharacterWidth === other . typicalHalfwidthCharacterWidth
0 commit comments