(text, size, lines)
| 17 | * @return {Phaser.Types.GameObjects.Text.GetTextSizeObject} An object containing dimensions of the Text object. |
| 18 | */ |
| 19 | var GetTextSize = function (text, size, lines) |
| 20 | { |
| 21 | var canvas = text.canvas; |
| 22 | var context = text.context; |
| 23 | var style = text.style; |
| 24 | |
| 25 | var lineWidths = []; |
| 26 | var maxLineWidth = 0; |
| 27 | var drawnLines = lines.length; |
| 28 | |
| 29 | if (style.maxLines > 0 && style.maxLines < lines.length) |
| 30 | { |
| 31 | drawnLines = style.maxLines; |
| 32 | } |
| 33 | |
| 34 | style.syncFont(canvas, context); |
| 35 | |
| 36 | // Text Width |
| 37 | var letterSpacing = text.letterSpacing; |
| 38 | |
| 39 | for (var i = 0; i < drawnLines; i++) |
| 40 | { |
| 41 | var lineWidth = style.strokeThickness; |
| 42 | |
| 43 | if (letterSpacing === 0) |
| 44 | { |
| 45 | lineWidth += context.measureText(lines[i]).width; |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | var line = lines[i]; |
| 50 | |
| 51 | for (var j = 0; j < line.length; j++) |
| 52 | { |
| 53 | lineWidth += context.measureText(line[j]).width; |
| 54 | } |
| 55 | |
| 56 | if (line.length > 1) |
| 57 | { |
| 58 | lineWidth += letterSpacing * (line.length - 1); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Adjust for wrapped text |
| 63 | if (style.wordWrap) |
| 64 | { |
| 65 | lineWidth -= context.measureText(' ').width; |
| 66 | } |
| 67 | |
| 68 | lineWidths[i] = Math.ceil(lineWidth); |
| 69 | maxLineWidth = Math.max(maxLineWidth, lineWidths[i]); |
| 70 | } |
| 71 | |
| 72 | // Text Height |
| 73 | |
| 74 | var lineHeight = size.fontSize + style.strokeThickness; |
| 75 | var height = lineHeight * drawnLines; |
| 76 | var lineSpacing = text.lineSpacing; |
no outgoing calls
no test coverage detected
searching dependent graphs…