Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add number type to fontWeight & fontWeightBold options #3062

Merged
merged 4 commits into from
Sep 8, 2020

Conversation

IllusionMH
Copy link
Contributor

Fixes #3051

_sanitizeAndValidateOption now implements custom normalization for fontWeight & fontWeightBold options that matches normalization from VSCode PR.
This is needed because if invalid value (7000 or normal123) is passes to fontWeight when canvas or webgl rendenderer is used it will lead to really small characters.
image

In browsers that don't support numeric values for font-weight property when values that doesn't match existing enum would be reset to normal/400 - this is current browser behavior for font-weight and no special logic added to handle this case. I assume that users of these browsers shouldn't won't use numeric values e.g. 350 because they don't work anyway for everything else.

Copy link
Contributor Author

@IllusionMH IllusionMH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions

@IllusionMH IllusionMH force-pushed the numeric-fontWeight-3051 branch from ada7aa9 to 3e0f033 Compare September 4, 2020 21:48
@IllusionMH IllusionMH requested a review from Tyriar September 4, 2020 21:50
@IllusionMH
Copy link
Contributor Author

IllusionMH commented Sep 4, 2020

As per first feedback I've changed return type of getOption to FontWeight alias.
As for second comment about argument - I think there was no call to action so not changed.
Also added tests for this property behavior.

P.S. If function previously had return type string but now it also has number in return type - can this change be counted as minor/feature change or it's major/breaking change?
In fact previously it would return anything except falsy values, and now it's subset of actual previous return values, but superset of previously declared type.

P.P.S. Implementation of normalization here is different from one in VS Code.
VS Code - clamps numeric values to 1-1000 range, resets incorrect string values to default one.
Xterm.js - follows browser behavior and resets all incorrect values to default one. This behavior can be observed with DOM renderer before this PR*
* I guess fontWeightBold was reset to normal instead of bold as this PR does.

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If function previously had return type string but now it also has number in return type - can this change be counted as minor/feature change or it's major/breaking change?

Yes it is technically a breaking change but I'm fine with letting this one go into a minor patch as it's such a small thing that maybe no one would eve. I don't know when v5 will happen and we don't want to block the VS Code change until then. I checked a few apps that use xterm.js and saw Hyper uses getOption only once for bellSound.

@@ -56,6 +56,8 @@ export const DEFAULT_OPTIONS: ITerminalOptions = Object.freeze({
cancelEvents: false
});

const FONT_WEIGHT_OPTIONS: Extract<FontWeight, string>[] = ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

@Tyriar Tyriar merged commit d960793 into xtermjs:master Sep 8, 2020
@IllusionMH IllusionMH deleted the numeric-fontWeight-3051 branch September 8, 2020 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support number in fontWeight option
2 participants