(item, loopIndex)
| 983 | calculate it's size and determine it's position, and actually |
| 984 | put it on the canvas. */ |
| 985 | var putWord = function putWord(item, loopIndex) { |
| 986 | if (loopIndex > 20) { |
| 987 | return null; |
| 988 | } |
| 989 | |
| 990 | var word, weight, attributes; |
| 991 | if (Array.isArray(item)) { |
| 992 | word = item[0]; |
| 993 | weight = item[1]; |
| 994 | } else { |
| 995 | word = item.word; |
| 996 | weight = item.weight; |
| 997 | attributes = item.attributes; |
| 998 | } |
| 999 | var rotateDeg = getRotateDeg(); |
| 1000 | |
| 1001 | var extraDataArray = getItemExtraData(item); |
| 1002 | |
| 1003 | // get info needed to put the text onto the canvas |
| 1004 | var info = getTextInfo(word, weight, rotateDeg, extraDataArray); |
| 1005 | |
| 1006 | // not getting the info means we shouldn't be drawing this one. |
| 1007 | if (!info) { |
| 1008 | return false; |
| 1009 | } |
| 1010 | |
| 1011 | if (exceedTime()) { |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | // If drawOutOfBound is set to false, |
| 1016 | // skip the loop if we have already know the bounding box of |
| 1017 | // word is larger than the canvas. |
| 1018 | if (!settings.drawOutOfBound && !settings.shrinkToFit) { |
| 1019 | var bounds = info.bounds; |
| 1020 | if (bounds[1] - bounds[3] + 1 > ngx || bounds[2] - bounds[0] + 1 > ngy) { |
| 1021 | return false; |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | // Determine the position to put the text by |
| 1026 | // start looking for the nearest points |
| 1027 | var r = maxRadius + 1; |
| 1028 | |
| 1029 | var tryToPutWordAtPoint = function (gxy) { |
| 1030 | var gx = Math.floor(gxy[0] - info.gw / 2); |
| 1031 | var gy = Math.floor(gxy[1] - info.gh / 2); |
| 1032 | var gw = info.gw; |
| 1033 | var gh = info.gh; |
| 1034 | |
| 1035 | // If we cannot fit the text at this position, return false |
| 1036 | // and go to the next position. |
| 1037 | if (!canFitText(gx, gy, gw, gh, info.occupied)) { |
| 1038 | return false; |
| 1039 | } |
| 1040 | |
| 1041 | // Actually put the text on the canvas |
| 1042 | drawText( |
no test coverage detected