Skip to content

Commit

Permalink
Fix handling of oblique fonts
Browse files Browse the repository at this point in the history
Take font weight into account when measuring text width.

Note that there will still be some issues with certain fonts due to
overlapping transparent billboards. That will be fixed with #2130.

Fixes #3782
  • Loading branch information
mramato committed Aug 26, 2016
1 parent c96a539 commit 17f64bf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Source/ThirdParty/measureText.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ define(function() {
var metrics = context2D.measureText(textstring),
fontFamily = getCSSValue(context2D.canvas,"font-family"),
fontSize = getCSSValue(context2D.canvas,"font-size").replace("px",""),
fontStyle = getCSSValue(context2D.canvas,"font-style"),
fontWeight = getCSSValue(context2D.canvas,"font-weight"),
isSpace = !(/\S/.test(textstring));
metrics.fontsize = fontSize;

// for text lead values, we meaure a multiline text container.
var leadDiv = document.createElement("div");
leadDiv.style.position = "absolute";
leadDiv.style.opacity = 0;
leadDiv.style.font = fontSize + "px " + fontFamily;
leadDiv.style.font = fontStyle + " " + fontWeight + " " + fontSize + "px " + fontFamily;
leadDiv.innerHTML = textstring + "<br/>" + textstring;
document.body.appendChild(leadDiv);

Expand All @@ -125,8 +127,10 @@ define(function() {
canvas.style.opacity = 1;
canvas.style.fontFamily = fontFamily;
canvas.style.fontSize = fontSize;
canvas.style.fontStyle = fontStyle;
canvas.style.fontWeight = fontWeight;
var ctx = canvas.getContext("2d");
ctx.font = fontSize + "px " + fontFamily;
ctx.font = fontStyle + " " + fontWeight + " " + fontSize + "px " + fontFamily;

var w = canvas.width,
h = canvas.height,
Expand Down

0 comments on commit 17f64bf

Please sign in to comment.