[scribus] Use API to Get Position of Selected Text (Or, Drop Caps not On First Character of Paragraph)

Gregory Pittman gpittman at iglou.com
Mon Mar 22 13:06:18 UTC 2021


On 3/21/21 7:39 PM, Matt Miller wrote:
> I want to use the API to get the position within the text frame of some text my program has scanned for and identified within a text frame chain, but I don't see how to do that.  I can get the position of the frame of the text, but not the position of a certain character of text within the frame.  I’m thinking of, for example, getFont(), which returns the font of the first character of the selected text, and I’m hoping to find something similar to give me the position of that character within its frame.
> 
> My actual goal with this is to use the Drop Caps attribute, but apply it to a character other than the first character of the paragraph.  There are a couple places in my API-generated documents where I need to leave a couple of the leading characters of a paragraph out to the left of the enlarged capital letter, and the only way I’ve seen to do that is to delete the leading characters from the paragraph, turn on drop caps for the paragraph, then create a new text frame right at the position where the deleted leading characters were, and finally put those deleted characters into that new frame.  I want to do all this from the API, and I don't know how to get the position for the new frame.

Hi Matt,

I think the problem with what you want to do is that Drop Caps is a feature of a Paragraph Style, so it is applied to a paragraph, more specifically to the first glyph of the paragraph.

You could probably create a Character Style that resembles a Drop Cap, though I'm not sure how the line spacing would work out.

Some time ago I wrote some scripts to transform typewriter quotes to typographic quotes:

https://wiki.scribus.net/canvas/Convert_Typewriter_Quotes_to_Typographic_Quotes

and also a script to convert '--' to an en dash and '---' to an em dash:

https://wiki.scribus.net/canvas/En%2Bemdash.py

What these do is to scan a text frame, character by character, and when they find what is being searched for, replace the character. In your case, you might apply your custom Character Style to the identified character instead of replacing it.

In many ways, I think what you're wanting to do is much more easily performed on the Scribus canvas than with Scripter.

Greg



More information about the scribus mailing list