提交 c09fd454 编写于 作者: A Alex Dima

Extract font info validation code to fontInfo

上级 17181f3b
......@@ -11,7 +11,7 @@ import * as objects from 'vs/base/common/objects';
import * as platform from 'vs/base/common/platform';
import { Extensions, IConfigurationRegistry, IConfigurationNode } from 'vs/platform/configuration/common/configurationRegistry';
import { Registry } from 'vs/platform/platform';
import { DefaultConfig, DEFAULT_INDENTATION, DEFAULT_TRIM_AUTO_WHITESPACE, GOLDEN_LINE_HEIGHT_RATIO } from 'vs/editor/common/config/defaultConfig';
import { DefaultConfig, DEFAULT_INDENTATION, DEFAULT_TRIM_AUTO_WHITESPACE } from 'vs/editor/common/config/defaultConfig';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { EditorLayoutProvider } from 'vs/editor/common/viewLayout/editorLayoutProvider';
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
......@@ -496,22 +496,6 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
let opts = this._configWithDefaults.getEditorOptions();
let editorClassName = this._getEditorClassName(opts.theme, toBoolean(opts.fontLigatures));
let fontFamily = String(opts.fontFamily) || DefaultConfig.editor.fontFamily;
let fontWeight = String(opts.fontWeight) || DefaultConfig.editor.fontWeight;
let fontSize = toFloat(opts.fontSize, DefaultConfig.editor.fontSize);
fontSize = Math.max(0, fontSize);
fontSize = Math.min(100, fontSize);
if (fontSize === 0) {
fontSize = DefaultConfig.editor.fontSize;
}
let lineHeight = toInteger(opts.lineHeight, 0, 150);
if (lineHeight === 0) {
lineHeight = Math.round(GOLDEN_LINE_HEIGHT_RATIO * fontSize);
}
let editorZoomLevelMultiplier = 1 + (EditorZoom.getZoomLevel() * 0.1);
fontSize *= editorZoomLevelMultiplier;
lineHeight *= editorZoomLevelMultiplier;
let disableTranslate3d = toBoolean(opts.disableTranslate3d);
let canUseTranslate3d = this._getCanUseTranslate3d();
......@@ -519,16 +503,13 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
canUseTranslate3d = false;
}
let bareFontInfo = BareFontInfo.createFromRawSettings(opts);
return InternalEditorOptionsHelper.createInternalEditorOptions(
this.getOuterWidth(),
this.getOuterHeight(),
opts,
this.readConfiguration(new BareFontInfo({
fontFamily: fontFamily,
fontWeight: fontWeight,
fontSize: fontSize,
lineHeight: lineHeight
})),
this.readConfiguration(bareFontInfo),
editorClassName,
this._isDominatedByLongLines,
this._maxLineNumber,
......
......@@ -4,21 +4,80 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { DefaultConfig, GOLDEN_LINE_HEIGHT_RATIO } from 'vs/editor/common/config/defaultConfig';
import { EditorZoom } from 'vs/editor/common/config/editorZoom';
function safeParseFloat(n: number | string, defaultValue: number): number {
if (typeof n === 'number') {
return n;
}
let r = parseFloat(n);
if (isNaN(r)) {
return defaultValue;
}
return r;
}
function safeParseInt(n: number | string, defaultValue: number): number {
if (typeof n === 'number') {
return Math.round(n);
}
let r = parseInt(n);
if (isNaN(r)) {
return defaultValue;
}
return r;
}
function clamp(n: number, min: number, max: number): number {
if (n < min) {
return min;
}
if (n > max) {
return max;
}
return n;
}
export class BareFontInfo {
readonly _bareFontInfoBrand: void;
// /**
// * @internal
// */
// public static createFromRawSettings(editor: {
// fontFamily: string;
// fontWeight: string;
// fontSize: number;
// lineHeight: number;
// }): BareFontInfo {
/**
* @internal
*/
public static createFromRawSettings(opts: {
fontFamily?: string;
fontWeight?: string;
fontSize?: number | string;
lineHeight?: number | string;
}): BareFontInfo {
let fontFamily = String(opts.fontFamily) || DefaultConfig.editor.fontFamily;
let fontWeight = String(opts.fontWeight) || DefaultConfig.editor.fontWeight;
// }
let fontSize = safeParseFloat(opts.fontSize, DefaultConfig.editor.fontSize);
fontSize = clamp(fontSize, 0, 100);
if (fontSize === 0) {
fontSize = DefaultConfig.editor.fontSize;
}
let lineHeight = safeParseInt(opts.lineHeight, 0);
lineHeight = clamp(lineHeight, 0, 150);
if (lineHeight === 0) {
lineHeight = Math.round(GOLDEN_LINE_HEIGHT_RATIO * fontSize);
}
let editorZoomLevelMultiplier = 1 + (EditorZoom.getZoomLevel() * 0.1);
fontSize *= editorZoomLevelMultiplier;
lineHeight *= editorZoomLevelMultiplier;
return new BareFontInfo({
fontFamily: fontFamily,
fontWeight: fontWeight,
fontSize: fontSize,
lineHeight: lineHeight
});
}
readonly fontFamily: string;
readonly fontWeight: string;
......@@ -28,7 +87,7 @@ export class BareFontInfo {
/**
* @internal
*/
constructor(opts: {
protected constructor(opts: {
fontFamily: string;
fontWeight: string;
fontSize: number;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册