Przeglądaj źródła

calculate app title width with string-width

Yuki Takei 8 lat temu
rodzic
commit
9b94b4f7a4
1 zmienionych plików z 5 dodań i 3 usunięć
  1. 5 3
      lib/util/swigFunctions.js

+ 5 - 3
lib/util/swigFunctions.js

@@ -1,5 +1,6 @@
 module.exports = function(crowi, app, req, locals) {
   var debug = require('debug')('growi:lib:swigFunctions')
+    , stringWidth = require('string-width')
     , Page = crowi.model('Page')
     , Config = crowi.model('Config')
     , User = crowi.model('User')
@@ -28,10 +29,11 @@ module.exports = function(crowi, app, req, locals) {
   };
 
   locals.getAppTitleFontSize = function(appTitle) {
+    let appTitleWidth = stringWidth(appTitle);
     let fontSize = 22;
-    if (appTitle.length < 13) { /* do nothing */ }
-    else if (appTitle.length < 21) {
-      fontSize -= 3 * (Math.floor((appTitle.length - 13) / 3) + 1);
+    if (appTitleWidth < 13) { /* do nothing */ }
+    else if (appTitleWidth < 21) {
+      fontSize -= 3 * (Math.floor((appTitleWidth - 13) / 3) + 1);
     }
     else  {
       fontSize = 11;