setText Changes Alignment

Previous topic - Next topic

MattMiller

I create a text frame and set the alignment to "Align Text Right" using the Text Properties window, or to ALIGN_RIGHT using setTextAlignment.  If I then enter text into the frame manually the text aligns right as it should, but if I use setText() from the scripter to populate the frame the alignment suddenly changes to "Align Text Left."  If first use setText() to populate the frame, and then use setTextAlignment() to set ALIGN_RIGHT, then everything is fine.

So, I have a workaround, but I'm wondering if I'm missing something here.  Shouldn't I be able to use setTextAlignment() and then use setText() and have the alignment stay?

I'm on Windows, and I see this in 1.5.6.1 and 1.5.7.svn.

bastianilso

I experienced the same as MattMiller - i figured its because setText first removes all text and therefore all settings applied to the previous text before it inserts the new text - this behaviour can be simulated in scribus editor too. To work around the problem, I implemented my own "replaceText()" function, which inserts the new text, before it deletes the old text. Essentially it creates the same result as setText, except it "remembers" the settings from the previous text in the text frame.


def replaceText(text, item):
    txtwidth = getTextLength(item[0])
    insertText(text, txtwidth, item[0])
    selectText(0,txtwidth, item[0])
    deleteText(item[0])


I hope this can help someone who search for this issue in the future.

noobjuk

Noob struggling to get this working.

Do you have this as a working command line example?