I'm trying to figure out the width a character would have before I draw it. For example, if I want to draw "Hello", I would like to know the width of the letters "H", "e", "l" and "o" and finally put that information in an array for usage further along
I'm new at JS/ECMA and find it a bit hard to use. What I have so far, after having looked at TextAlong and other scripts, is:
Code: Select all
include("scripts/library.js");
include("scripts/Draw/Draw.js");
include("scripts/WidgetFactory.js");
include("scripts/Draw/Text/TextDialog/TextDialog.js");
function FunnyText(inText, centreX, centreY){
    var doc = getTransactionDocument();
    if (isNull(doc)) {
        return undefined;
    }
    var height = 1.0;
    var angle = 0.0;
    var font = "Standard";
    var vAlign = RS.VAlignTop;
    var hAlign = RS.HAlignLeft;
    var bold = false;
    var italic = false;
    this.textData = new RTextData();
    textData.text = inText;
    this.textEntity = new RTextEntity(doc, textData);
//Get text width 
    var num = textData.text.length;
    var charWidths = [];
    var totalCharWidth = 0.0;
    for (var i = 0; i < num; i++) {
        var char = textData.text[i];
        // A space character is returned as zero width
        if (char === " ") {
            char = "-";
        }
        var td = getTextData(char);
        var wid = td.getTextWidth()
        charWidths.push(wid);
        totalCharWidth += wid;
    }
    writeTextFile('/home/jsroy/OUTPUT', num + " | " + this.textData.getTextWidth());
}
FunnyText.prototype = new Draw();
getTextData = function(txt) {
    var td = new RTextData();
    if (this.pos !== undefined) {
        td.setAlignmentPoint(this.pos);
    }
    td.setText(txt);
    td.setTextHeight(10);
    td.setTextWidth(this.textData.getTextWidth());
    return td;
}
FunnyText("Janvier", 0, 0);Any help would be appreciated.
Thank you,
Jean
