(item)
| 1017 | calculate it's size and determine it's position, and actually |
| 1018 | put it on the canvas. */ |
| 1019 | var putWord = function putWord(item) { |
| 1020 | var word, weight, attributes; |
| 1021 | if (Array.isArray(item)) { |
| 1022 | word = item[0]; |
| 1023 | weight = item[1]; |
| 1024 | } else { |
| 1025 | word = item.word; |
| 1026 | weight = item.weight; |
| 1027 | attributes = item.attributes; |
| 1028 | } |
| 1029 | var rotateDeg = getRotateDeg(); |
| 1030 | |
| 1031 | // get info needed to put the text onto the canvas |
| 1032 | var info = getTextInfo(word, weight, rotateDeg); |
| 1033 | |
| 1034 | // not getting the info means we shouldn't be drawing this one. |
| 1035 | if (!info) { |
| 1036 | return false; |
| 1037 | } |
| 1038 | |
| 1039 | if (exceedTime()) { |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | // If drawOutOfBound is set to false, |
| 1044 | // skip the loop if we have already know the bounding box of |
| 1045 | // word is larger than the canvas. |
| 1046 | if (!settings.drawOutOfBound) { |
| 1047 | var bounds = info.bounds; |
| 1048 | if ((bounds[1] - bounds[3] + 1) > ngx || |
| 1049 | (bounds[2] - bounds[0] + 1) > ngy) { |
| 1050 | return false; |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | // Determine the position to put the text by |
| 1055 | // start looking for the nearest points |
| 1056 | var r = maxRadius + 1; |
| 1057 | |
| 1058 | var tryToPutWordAtPoint = function(gxy) { |
| 1059 | var gx = Math.floor(gxy[0] - info.gw / 2); |
| 1060 | var gy = Math.floor(gxy[1] - info.gh / 2); |
| 1061 | var gw = info.gw; |
| 1062 | var gh = info.gh; |
| 1063 | |
| 1064 | // If we cannot fit the text at this position, return false |
| 1065 | // and go to the next position. |
| 1066 | if (!canFitText(gx, gy, gw, gh, info.occupied)) { |
| 1067 | return false; |
| 1068 | } |
| 1069 | |
| 1070 | // Actually put the text on the canvas |
| 1071 | drawText(gx, gy, info, word, weight, |
| 1072 | (maxRadius - r), gxy[2], rotateDeg, attributes); |
| 1073 | |
| 1074 | // Mark the spaces on the grid as filled |
| 1075 | updateGrid(gx, gy, gw, gh, info, item); |
| 1076 |
no test coverage detected