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

Matt Miller matt.miller at fastmail.com
Mon Mar 22 13:55:49 UTC 2021



On Mon, Mar 22, 2021, at 06:06, Gregory Pittman wrote:
> 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.

Thanks for the ideas.

Regarding the canvas vs Scripter, yeah, using Scribus interactively I am able to pretty easily get exactly what I want here, which is good.  My longer-term goal, though, is to be able to change things like page size, margins, type size, and font family, and then automatically rebuild my document of several hundred pages without manual intervention.  So far I've had good success, and I'm confident I'll find a way around this issue of drop caps on a glyph that's within a few characters of the first paragraph character.

> Greg
> 
> ___
> Scribus Mailing List: scribus at lists.scribus.net
> Edit your options or unsubscribe:
> http://lists.scribus.net/mailman/listinfo/scribus
> See also:
> http://wiki.scribus.net
> http://forums.scribus.net
>

-- 

  Matt Miller
  mailto:matt.miller at fastmail.com



More information about the scribus mailing list