(gx, gy, info, word, weight,
distance, theta, rotateDeg, attributes)
| 842 | |
| 843 | /* Actually draw the text on the grid */ |
| 844 | var drawText = function drawText(gx, gy, info, word, weight, |
| 845 | distance, theta, rotateDeg, attributes) { |
| 846 | |
| 847 | var fontSize = info.fontSize; |
| 848 | var color; |
| 849 | if (getTextColor) { |
| 850 | color = getTextColor(word, weight, fontSize, distance, theta); |
| 851 | } else { |
| 852 | color = settings.color; |
| 853 | } |
| 854 | |
| 855 | var classes; |
| 856 | if (getTextClasses) { |
| 857 | classes = getTextClasses(word, weight, fontSize, distance, theta); |
| 858 | } else { |
| 859 | classes = settings.classes; |
| 860 | } |
| 861 | |
| 862 | var dimension; |
| 863 | var bounds = info.bounds; |
| 864 | dimension = { |
| 865 | x: (gx + bounds[3]) * g, |
| 866 | y: (gy + bounds[0]) * g, |
| 867 | w: (bounds[1] - bounds[3] + 1) * g, |
| 868 | h: (bounds[2] - bounds[0] + 1) * g |
| 869 | }; |
| 870 | |
| 871 | elements.forEach(function(el) { |
| 872 | if (el.getContext) { |
| 873 | var ctx = el.getContext('2d'); |
| 874 | var mu = info.mu; |
| 875 | |
| 876 | // Save the current state before messing it |
| 877 | ctx.save(); |
| 878 | ctx.scale(1 / mu, 1 / mu); |
| 879 | |
| 880 | ctx.font = settings.fontWeight + ' ' + |
| 881 | (fontSize * mu).toString(10) + 'px ' + settings.fontFamily; |
| 882 | ctx.fillStyle = color; |
| 883 | |
| 884 | // Translate the canvas position to the origin coordinate of where |
| 885 | // the text should be put. |
| 886 | ctx.translate((gx + info.gw / 2) * g * mu, |
| 887 | (gy + info.gh / 2) * g * mu); |
| 888 | |
| 889 | if (rotateDeg !== 0) { |
| 890 | ctx.rotate(- rotateDeg); |
| 891 | } |
| 892 | |
| 893 | // Finally, fill the text. |
| 894 | |
| 895 | // XXX: We cannot because textBaseline = 'top' here because |
| 896 | // Firefox and Chrome uses different default line-height for canvas. |
| 897 | // Please read https://bugzil.la/737852#c6. |
| 898 | // Here, we use textBaseline = 'middle' and draw the text at exactly |
| 899 | // 0.5 * fontSize lower. |
| 900 | ctx.textBaseline = 'middle'; |
| 901 | ctx.fillText(word, info.fillTextOffsetX * mu, |
no outgoing calls
no test coverage detected