OLD | NEW |
1 var SubPixelLayout = (function() { | 1 var SubPixelLayout = (function() { |
2 var _subPixelLayout = null; | 2 var enabled = undefined; |
3 function initSubPixelLayout() { | 3 |
4 var elem = document.createElement('div'); | 4 function isEnabled() |
5 elem.style.setProperty('width', '4.5px'); | 5 { |
6 document.body.appendChild(elem); | 6 if (enabled === undefined) { |
7 var bounds = elem.getBoundingClientRect(); | 7 var elem = document.createElement('div'); |
8 _subPixelLayout = (bounds.width != Math.floor(bounds.width)); | 8 elem.style.setProperty('width', '4.5px'); |
9 document.body.removeChild(elem); | 9 document.body.appendChild(elem); |
| 10 var bounds = elem.getBoundingClientRect(); |
| 11 enabled = (bounds.width != Math.floor(bounds.width)); |
| 12 document.body.removeChild(elem); |
| 13 } |
| 14 return enabled; |
10 } | 15 } |
11 document.addEventListener('DOMContentLoaded', initSubPixelLayout); | 16 |
12 return { | 17 return { |
13 initSubPixelLayout: initSubPixelLayout, | 18 isEnabled: isEnabled, |
14 roundLineLeft: function(f) { | 19 snapToLayoutUnit: function(f) { |
15 if (!_subPixelLayout) | 20 return isEnabled() ? Math.floor(f * 64) / 64 : Math.floor(f); // as
in LayoutUnit(f).toFloat() |
16 return Math.floor(f); | |
17 return Math.floor((Math.floor(f * 64) + 32) / 64); // see FractionLa
youtUnit::round() | |
18 }, | 21 }, |
19 roundLineRight: function(f) { | 22 ceilToLayoutUnit: function(f) { |
20 if (!_subPixelLayout) | 23 return isEnabled() ? Math.ceil(f * 64) / 64 : Math.ceil(f); // see c
eiledLayoutUnit(), LayoutUnit.h |
21 return Math.floor(f); | |
22 return Math.floor(Math.floor(f * 64) / 64); // see FractionLayoutUni
t::floor() | |
23 }, | 24 }, |
24 isSubPixelLayoutEnabled: function() { | |
25 return _subPixelLayout; | |
26 } | |
27 } | 25 } |
28 }()); | 26 }()); |
OLD | NEW |