From 2c163ae2c27d9e678bee19254b1616f5de103ebc Mon Sep 17 00:00:00 2001 From: "hhclaw.eb@gmail.com" Date: Fri, 6 Sep 2013 20:00:08 +0800 Subject: [PATCH] Amend width calculation for wide characters --- js/id/svg/labels.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/id/svg/labels.js b/js/id/svg/labels.js index 7256e223a..f7d6a5283 100644 --- a/js/id/svg/labels.js +++ b/js/id/svg/labels.js @@ -70,6 +70,7 @@ iD.svg.Labels = function(projection, context) { function textWidth(text, size, elem) { var c = textWidthCache[size]; + var str; if (!c) c = textWidthCache[size] = {}; if (c[text]) { @@ -80,7 +81,12 @@ iD.svg.Labels = function(projection, context) { return c[text]; } else { - return size / 3 * 2 * text.length; + str = encodeURIComponent(text).match(/%[CDEFcdef]/g); + if (str == null) { + return size / 3 * 2 * text.length; + } else { + return size / 3 * ( 2 * text.length + str.length); + } } }