0

I try to add a non-breaking space when using CreateJS (or EaselJS). But it does not work. For example: I don't want a linebreak between a "text" and a "!" Example:

this.copy_01 = new cjs.Text("This is a text\u00A0!", "bold 60px 'Times New Roman'", "#FFFFFF");

\u00A0 usually works in JavaScript. But now it only adds a space, but not a non-breaking space.

Does someone know if it is possible to add a non-breaking space in CreateJS?

2 Answers 2

1

The line-wrapping in EaselJS is manually implemented in the Canvas, so it doesn't follow the JavaScript ruleset. You would have to manually add support for it. Sorry!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for letting me know :)
0

I am currently trying a workaround. Seems to work for me, but I am not really happy with this.

function nonBreak(textObj) {
    var origString = textObj.text; 
    var compStr = origString.replace(/(.|[\r\n])*?<nbr>.*?($|\s)/, "");
    compStr = origString.replace(compStr, ""); 
    compStr1 = compStr.replace(/<nbr>/, " "); 
    compStr2 = compStr.replace(/<nbr>/, "\n"); 
    textObj.text = compStr1;
    var sizeStr1 = textObj.getMetrics().height;
    textObj.text = compStr2;
    sizeStr2 = textObj.getMetrics().height;
    textObj.text = origString;

    if (sizeStr1 == sizeStr2) {
        newString1 = origString.replace(/\s?[^ ]*<nbr>.*/, "");
        newString2 = origString.replace(newString1 + " ", "");
        newString1 = newString1 + "\n";
        newString2 = newString2.replace(/<nbr>/, " ");
        newString = newString1 + newString2;
        textObj.text = newString;
    } else {
        newString = origString.replace(/<nbr>/, " ");
        textObj.text = newString;
    }

}




var origString = this.copy_01.text;
var textCopy = this.copy_01;
var countBR = origString.match(/<nbr>/g);
if (countBR !== null) {
    for (i = 0; i < countBR.length; i++) {

        if (countBR[i] == "<nbr>") {
            nonBreak(textCopy);
        }

    }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.