phaser3-rex-plugins
Version:
35 lines (29 loc) • 1.35 kB
JavaScript
import {
TextType, TagTextType, BitmapTextType
} from './GetTextObjectType.js';
import GetTextObjectType from './GetTextObjectType.js';
var TextHeightToLineCount = function (textObject) {
var textObjectType = GetTextObjectType(textObject);
var height, lineSpacing, lineHeight;
switch (textObjectType) {
case TextType:
height = textObject.height - textObject.padding.top - textObject.padding.bottom;
lineSpacing = textObject.lineSpacing;
lineHeight = textObject.style.metrics.fontSize + textObject.style.strokeThickness;
break;
case TagTextType: // + fixedLineHeightMode: true
height = textObject.height - textObject.padding.top - textObject.padding.bottom;
lineSpacing = textObject.lineSpacing;
lineHeight = textObject.style.metrics.fontSize;
break;
case BitmapTextType:
height = textObject.height;
lineSpacing = 0;
var scale = (textObject.fontSize / textObject.fontData.size);
lineHeight = textObject.fontData.lineHeight * scale;
break;
}
// height = (lines * (lineHeight + lineSpacing)) - lineSpacing
return (height + lineSpacing) / (lineHeight + lineSpacing);
}
export default TextHeightToLineCount;