Fix crash when Text object font is set to 0

This commit is contained in:
Florian Rival
2019-08-19 00:28:10 -07:00
parent 7d7bde12d0
commit e5aac3d75d
3 changed files with 4 additions and 4 deletions

View File

@@ -274,7 +274,7 @@ bool RuntimeTextObject::ChangeProperty(std::size_t propertyNb,
} else if (propertyNb == 1) {
ChangeFont(newValue);
} else if (propertyNb == 2) {
SetCharacterSize(newValue.To<int>());
SetCharacterSize(std::max(1, newValue.To<int>()));
} else if (propertyNb == 3) {
gd::String r, gb, g, b;
{
@@ -297,7 +297,7 @@ bool RuntimeTextObject::ChangeProperty(std::size_t propertyNb,
SetColor(r.To<int>(), g.To<int>(), b.To<int>());
} else if (propertyNb == 4) {
SetOpacity(newValue.To<float>());
SetOpacity(std::min(std::max(0.0f, newValue.To<float>()), 255.0f));
} else if (propertyNb == 5) {
SetSmooth(!(newValue == _("No")));
}

View File

@@ -14,7 +14,7 @@ gdjs.TextRuntimeObject = function(runtimeScene, objectData)
{
gdjs.RuntimeObject.call(this, runtimeScene, objectData);
this._characterSize = objectData.characterSize;
this._characterSize = Math.max(1, objectData.characterSize);
this._fontName = objectData.font;
this._bold = objectData.bold;
this._italic = objectData.italic;

View File

@@ -87,7 +87,7 @@ RenderedTextInstance.prototype.update = function() {
if (this._styleFontDirty) {
this._pixiObject.style.fontFamily = this._fontFamily || 'Arial';
this._pixiObject.style.fontSize = this._characterSize + 'px';
this._pixiObject.style.fontSize = Math.max(1, this._characterSize) + 'px';
this._pixiObject.style.fontStyle = this._isItalic ? 'italic' : 'normal';
this._pixiObject.style.fontWeight = this._isBold ? 'bold' : 'normal';
this._pixiObject.style.wordWrap = this._wrapping;