hterm-dev-0.7.4.4: Detect font bold/normal size mismatch.
* Add ability to detect fonts with mismatched bold/normal sizes, and disable
bold characters when that happens.
BUG=None
TEST=From js console, `term_.setFontFamily("sans-serif");`, then echo bold text in the terminal and verify that it is bright, but not bold.
You may need to choose a different font if your default sans-serif has a bold X that is the same size as the normal X.
Change-Id: I7ad57ec305a623d0bf67417c3eadd8e669f0cc6d
Reviewed-on: https://gerrit.chromium.org/gerrit/17031
Commit-Ready: Marius Schilder <mschilder@google.com>
Reviewed-by: Marius Schilder <mschilder@google.com>
Reviewed-by: Robert Ginda <rginda@chromium.org>
Tested-by: Robert Ginda <rginda@chromium.org>
Commit-Ready: Robert Ginda <rginda@chromium.org>
diff --git a/hterm/js/terminal.js b/hterm/js/terminal.js
index 67bbfa8..3347ed1 100644
--- a/hterm/js/terminal.js
+++ b/hterm/js/terminal.js
@@ -200,6 +200,15 @@
*/
hterm.Terminal.prototype.setFontFamily = function(str) {
this.scrollPort_.setFontFamily(str);
+ var normalSize = this.scrollPort_.measureCharacterSize();
+ var boldSize = this.scrollPort_.measureCharacterSize('bold');
+
+ var isBoldSafe = normalSize.equals(boldSize);
+ this.screen_.textAttributes.enableBold = isBoldSafe;
+ if (!isBoldSafe) {
+ console.warn('Bold characters disabled: Size of bold weight differs ' +
+ 'from normal. Font family is: ' + str);
+ }
};
/**
@@ -597,8 +606,9 @@
this.div_ = div;
this.scrollPort_.decorate(div);
- this.scrollPort_.setFontFamily(this.defaultFontFamily);
- this.scrollPort_.setFontSize(this.defaultFontSize);
+
+ this.setFontSize(this.defaultFontSize);
+ this.setFontFamily(this.defaultFontFamily);
this.document_ = this.scrollPort_.getDocument();