OLD | NEW |
| (Empty) |
1 var SubPixelLayout = (function() { | |
2 var SUBPIXELS_PER_PIXEL = 64; | |
3 var enabled = undefined; | |
4 | |
5 function isEnabled() | |
6 { | |
7 if (enabled === undefined) { | |
8 var elem = document.createElement('div'); | |
9 elem.style.setProperty('width', '4.5px'); | |
10 document.body.appendChild(elem); | |
11 var bounds = elem.getBoundingClientRect(); | |
12 enabled = (bounds.width != Math.floor(bounds.width)); | |
13 document.body.removeChild(elem); | |
14 } | |
15 return enabled; | |
16 } | |
17 | |
18 return { | |
19 isEnabled: isEnabled, | |
20 snapToLayoutUnit: function(f) { | |
21 return isEnabled() ? Math.floor(f * SUBPIXELS_PER_PIXEL) / SUBPIXELS
_PER_PIXEL : Math.floor(f); // as in LayoutUnit(f).toFloat() | |
22 }, | |
23 ceilSnapToLayoutUnit: function(f) { | |
24 return isEnabled() ? Math.ceil(f * SUBPIXELS_PER_PIXEL) / SUBPIXELS_
PER_PIXEL : Math.ceil(f); // see ceiledLayoutUnit(), LayoutUnit.h | |
25 } | |
26 } | |
27 }()); | |
OLD | NEW |