View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0015911||Scribus||Scripter||public||2019-11-04 17:25||2019-12-08 21:24|
|Target Version||Fixed in Version||1.5.6.svn|
|Summary||0015911: After calling insertText(), getText() does not show all characters|
|Description||I have a textframe with several templates. When the first template is expanded in situ, I can see the following text with getAllText, but most often not with getText. The functions getTextLength, getStyle work as expected and show the correct length and style, but getText normally returns an empty string. I was looking for a flush-function, and it appears that e.g. saveDoc has some effect, but it cannot be relied on. |
This bug prevents my program to expand more than one template. I would also appreciate a workaround.
|Steps To Reproduce||To see this, open a textframe, insert "abcde" into it, and start scribtest.py. This program inserts "12345" before "abcde". getAllText then shows "12345abcde", but getText only "12345".|
|Tags||No tags attached.|
scribtest.py (2,100 bytes)
There can be indeed a need to update text layout after specific calls such as insertText(). Scripter's getText() use the layout information to return only text shown in the frame and text layout is normally not updated while a script is running.
I have consequently added a new layoutText() function so as to be able to update layout when needed. That means you will need to call this new function after calling insertText() and before calling getText():
layoutText does indeed work for the small testscript. But I produce from the first template some 25000 characters in 8 new pages, in a loop "while textOverflows: createNewPage", where createNewPage calls getMasterPage, newPage, gotoPage, createText, linkTextFrames. The position of the second template thus changes from ca. 300 to 25000. layoutText() has apparently no effect, when I getText the second template. getText still returns only empty strings. There are more templates after the second, and astonishingly getText returns parts of some of them!?
But I have a workaround, where I use getAllText instead of getText, so this has now low priority for me.
As an aside:
I go through the templates one character at a time, collecting all characters with the same paragraph and character style in a "run". Parameters are then expanded and the expanded strings are inserted with insertText, setStyle and setCharacterStyle. This works nicely, but of course only, if the function getCharacterStyle is in scribus. Without getCharacterStyle, I would have to call getFont, getFontSize, getTextColor for each (!) character, and still miss something.
For linked text frames, you have to call layoutText() on all frames of the chain for updating text layout of the whole text chain. layoutText() updates text layout only for a specific box.
I have added a convenience layoutTextChain() function for updating text layout for the whole chain a specific text frame belongs:
Thank you. I just added a call to layoutText(newframe) right after linkTextFrames(textbox, newframe). No effect. I found no other script functions to follow frame links. Perhaps I have to go otherwise through all pages, all pageitems, all textframes and call layoutText on each of them.
But now it also occurred to me that a template might cross a page/textframe boundary after expansion of a previous template. Not sure what the ramifications are.
Have to do more thinking.
Anyway, I will try layoutTextChain soon, and I hope, I do not keep you from more important work.
||After some thinking: Spreading text across new textframes for overflown textframes while continuing to work on the text causes too many problems. Rather, I stay with one large textframe until all templates are expanded, then create the pages and textframes. As getText does not return text in overflown text, I just cannot use it then. Nevertheless, getStyle/getFont/getFontSize do work fortunately for overflown text. That the one works and the other not, is still a bit surprising for me.|
|2019-11-04 17:25||m.uhlenberg||New Issue|
|2019-11-04 17:25||m.uhlenberg||File Added: scribtest.py|
|2019-11-05 00:49||jghali||Summary||after insertText getText does not show all characters => After calling insertText(), getText() does not show all characters|
|2019-11-05 00:49||jghali||Description Updated||View Revisions|
|2019-11-05 00:49||jghali||Steps to Reproduce Updated||View Revisions|
|2019-11-05 00:56||jghali||Assigned To||=> jghali|
|2019-11-05 00:56||jghali||Status||new => resolved|
|2019-11-05 00:56||jghali||Resolution||open => fixed|
|2019-11-05 00:56||jghali||Fixed in Version||=> 1.5.6.svn|
|2019-11-05 00:56||jghali||Note Added: 0046962|
|2019-11-06 08:59||m.uhlenberg||Status||resolved => feedback|
|2019-11-06 08:59||m.uhlenberg||Resolution||fixed => reopened|
|2019-11-06 08:59||m.uhlenberg||Note Added: 0046990|
|2019-11-06 11:15||jghali||Status||feedback => resolved|
|2019-11-06 11:15||jghali||Resolution||reopened => fixed|
|2019-11-06 11:15||jghali||Note Added: 0046994|
|2019-11-06 11:43||jghali||Note Edited: 0046994||View Revisions|
|2019-11-06 11:52||jghali||Note Added: 0046995|
|2019-11-06 12:23||jghali||Note Edited: 0046995||View Revisions|
|2019-11-06 12:34||m.uhlenberg||Note Added: 0046997|
|2019-11-06 13:18||m.uhlenberg||Note Added: 0046998|
|2019-12-08 21:24||cbradney||Status||resolved => closed|