From 17f64bf4fa91640ce9da24f161a377c9586fb3f9 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Fri, 26 Aug 2016 12:11:54 -0400 Subject: [PATCH] Fix handling of oblique fonts 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 --- Source/ThirdParty/measureText.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/ThirdParty/measureText.js b/Source/ThirdParty/measureText.js index ee658e24e3ea..782de3958358 100644 --- a/Source/ThirdParty/measureText.js +++ b/Source/ThirdParty/measureText.js @@ -95,6 +95,8 @@ 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; @@ -102,7 +104,7 @@ define(function() { 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 + "
" + textstring; document.body.appendChild(leadDiv); @@ -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,