如何在 VS Code 中同时使用 Victor Mono 的倾斜和斜体样式?
How can I use both the oblique and italic styles of Victor Mono in VS Code?
Victor Mono 字体系列提供截然不同的斜体和斜体字体。我想对 comment.block.documentation 范围使用斜体,对其他注释范围使用斜体。但是,明显的 settings.json 部分:
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"name": "Documentation",
"scope": "comment.block.documentation",
"settings": { "fontStyle": "italic" }
},
{
"name": "Comment",
"scope": "comment",
"settings": { "fontStyle": "oblique" }
},
]
}
不起作用,因为渲染引擎似乎将 "oblique" 和 "italics" 解释为“在要加载的最后一个字体文件中提供斜体或斜体中的任何一个。
我采用了 previously published 方法来支持 VS Code 中的多种字体,然后将问题陈述转换为该形式。该解决方案使用两个 "font families":一个名为 "Victor Mono Medium" 并且是 "real" 字体系列,提供正常和斜体样式以及难以访问的倾斜样式;还有一个叫"Victor Mono Medium Oblique",只提供normal和oblique样式,并且只用于oblique样式。
作为简化,我选择牺牲使用带下划线的字体样式的能力。这对于我的用例来说是可以接受的,并且显着简化了解决方案。那么做法是:
- 使用标准的 tokenColorCustomizations 机制,在需要斜体的地方使用
fontStyle: "italic"
,在需要斜体的地方使用 fontStyle: "underline"
。
- 使用 "Enable Custom CSS and JS" 扩展,提供自定义 CSS 文件。
- 在自定义 CSS 文件中,创建一个
@font-face
具有斜体但不是斜体的样式。
- 在自定义 CSS 文件中,更改
fontStyle: "underline"
的样式以使用倾斜字体,倾斜,而不是下划线。
安装 "Enable Custom CSS and JS" 并按照其说明启用自定义 CSS 文件并将 VictorMono-MediumOblique.otf 字体文件复制到选定位置后,这里是相关内容我的 settings.json:
...
"editor.fontLigatures": true,
"editor.fontFamily": "'Victor Mono Medium'",
"vscode_custom_css.imports": ["file:///MYPATH/.vscode/style.css"],
"vscode_custom_css.policy": true,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"name": "Documentation",
"scope": "comment.block.documentation",
"settings": { "fontStyle": "italic" }
},
{
"name": "Comment",
"scope": "comment",
"settings": { "fontStyle": "underline" }
},
]
},
...
和我的 style.css:
/* Replace underline with oblique */
@font-face {
font-family: 'Victor Mono Medium Oblique';
src: url('file:///MYPATH/VictorMono-MediumOblique.otf');
}
.mtku {
font-family: 'Victor Mono Medium Oblique';
font-style: oblique;
text-decoration: none;
}
Victor Mono 字体系列提供截然不同的斜体和斜体字体。我想对 comment.block.documentation 范围使用斜体,对其他注释范围使用斜体。但是,明显的 settings.json 部分:
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"name": "Documentation",
"scope": "comment.block.documentation",
"settings": { "fontStyle": "italic" }
},
{
"name": "Comment",
"scope": "comment",
"settings": { "fontStyle": "oblique" }
},
]
}
不起作用,因为渲染引擎似乎将 "oblique" 和 "italics" 解释为“在要加载的最后一个字体文件中提供斜体或斜体中的任何一个。
我采用了 previously published 方法来支持 VS Code 中的多种字体,然后将问题陈述转换为该形式。该解决方案使用两个 "font families":一个名为 "Victor Mono Medium" 并且是 "real" 字体系列,提供正常和斜体样式以及难以访问的倾斜样式;还有一个叫"Victor Mono Medium Oblique",只提供normal和oblique样式,并且只用于oblique样式。
作为简化,我选择牺牲使用带下划线的字体样式的能力。这对于我的用例来说是可以接受的,并且显着简化了解决方案。那么做法是:
- 使用标准的 tokenColorCustomizations 机制,在需要斜体的地方使用
fontStyle: "italic"
,在需要斜体的地方使用fontStyle: "underline"
。 - 使用 "Enable Custom CSS and JS" 扩展,提供自定义 CSS 文件。
- 在自定义 CSS 文件中,创建一个
@font-face
具有斜体但不是斜体的样式。 - 在自定义 CSS 文件中,更改
fontStyle: "underline"
的样式以使用倾斜字体,倾斜,而不是下划线。
安装 "Enable Custom CSS and JS" 并按照其说明启用自定义 CSS 文件并将 VictorMono-MediumOblique.otf 字体文件复制到选定位置后,这里是相关内容我的 settings.json:
...
"editor.fontLigatures": true,
"editor.fontFamily": "'Victor Mono Medium'",
"vscode_custom_css.imports": ["file:///MYPATH/.vscode/style.css"],
"vscode_custom_css.policy": true,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"name": "Documentation",
"scope": "comment.block.documentation",
"settings": { "fontStyle": "italic" }
},
{
"name": "Comment",
"scope": "comment",
"settings": { "fontStyle": "underline" }
},
]
},
...
和我的 style.css:
/* Replace underline with oblique */
@font-face {
font-family: 'Victor Mono Medium Oblique';
src: url('file:///MYPATH/VictorMono-MediumOblique.otf');
}
.mtku {
font-family: 'Victor Mono Medium Oblique';
font-style: oblique;
text-decoration: none;
}