Skip to content
This repository
Browse code

While cache is generating add two the same chars at once, and then di…

…vide per 2 to get better kerning accuracy.
  • Loading branch information...
commit 1a451f8fe0a1c5c1e9940ad65b8970fe6eeabd67 1 parent fc5ea0f
Adam Lukaszczyk authored January 20, 2012

Showing 1 changed file with 6 additions and 5 deletions. Show diff stats Hide diff stats

  1. 11  js/jquery.FastEllipsis.js
11  js/jquery.FastEllipsis.js
@@ -51,19 +51,19 @@ function FastEllipsis(cssStyle) {
51 51
     testDrive.before(" ");
52 52
     oldTotalWidth = totalWidth;
53 53
     totalWidth = charWrapper.width();
54  
-    charWidth = totalWidth - oldTotalWidth;
  54
+    charWidth = (totalWidth - oldTotalWidth)+0.4; // hack: add 0.4px to every space 
55 55
     _charWidthArray["_ "] = charWidth;
56 56
             
57 57
     // Other ASCII chars
58 58
     for( var i = 33; i <= 126; i++ ) {
59 59
       character = String.fromCharCode( i );
60  
-      testDrive.before(character);
  60
+      testDrive.before(""+character+character);
61 61
       
62 62
       oldTotalWidth = totalWidth;
63 63
       totalWidth = charWrapper.width();
64  
-      charWidth = totalWidth - oldTotalWidth;
65  
-        _charWidthArray["_"+character] = charWidth;
66  
-          
  64
+      charWidth = (totalWidth - oldTotalWidth)/2; // While cache is generating add two the same chars at once, and then divide per 2 to get better kerning accuracy.
  65
+      _charWidthArray["_"+character] = charWidth;
  66
+        
67 67
       // Finds max width for char - it will be given for every undefined char like: Ą or Ć
68 68
       if (_maxWidth < _charWidthArray["_"+character]) {
69 69
         _maxWidth = _charWidthArray["_"+character];
@@ -106,6 +106,7 @@ function FastEllipsis(cssStyle) {
106 106
       for (var i = 0, len = myWord.length; i < len; i++) {
107 107
         sum = sum + getCharWidth(myWord[i]);
108 108
       }
  109
+	  sum = Math.floor(sum);
109 110
       _charWidthArray["_"+myWord] = sum;
110 111
       return sum;
111 112
     }

0 notes on commit 1a451f8

Please sign in to comment.
Something went wrong with that request. Please try again.