Get/Set character properties of TextPortion

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
pnm_asst_ed
Posts: 14
Joined: Sun Jul 17, 2011 9:09 pm

Get/Set character properties of TextPortion

Post by pnm_asst_ed »

I'm trying to write code to search out every space in a Writer document and set it's character properties to be the same as those of the following character.

To this end, I've written code in OpenOffice BASIC that cycles through each TextPortion, checks if the last character is a space, and if so, removes it and then appends a space to the beginning of the next TextPortion. However, any default (i.e., unset) character properties in the "next TextPortion" get changed to those of the preceding text portion.

For example, if I have "a b" where "a " is small caps and "b" is italic, I wind up with "a" being small caps (fine) and " b" being small caps and italic (not fine). What I want is for " b" to be just italic and not pick up the small caps attribute.

To work around this, I would have to change every space in the document by hand, which isn't a reasonable solution for me. How can I do this in code?

Many thanks,
Aaron
AOO413m1(Build:9783) - Rev. 1761381
MacOS 10.12.3 (16D32)

Assistant Editor
Perspectives of New Music
pnm_asst_ed
Posts: 14
Joined: Sun Jul 17, 2011 9:09 pm

Re: Get/Set character properties of TextPortion

Post by pnm_asst_ed »

I'm using:

AOO413m1(Build:9783) - Rev. 1761381
MacOS 10.12.3 (16D32)
AOO413m1(Build:9783) - Rev. 1761381
MacOS 10.12.3 (16D32)

Assistant Editor
Perspectives of New Music
pnm_asst_ed
Posts: 14
Joined: Sun Jul 17, 2011 9:09 pm

Re: Get/Set character properties of TextPortion

Post by pnm_asst_ed »

I found a workaround for my purposes. The core problem is that I get weird character spacing when I have, say, a word in Roman type, a word in italics, and another word in Roman. If the space before the italics is not itself italic, and if the space after is not Roman, then the character spacing goes awry.

So now I search all italics and replace it with @@@$1___. I then search for [:space:]([@@@|___]) and replace it with $1[:space:]. I can then search for @@@<stuff>___ and replace it with <stuff in italics>.

Still, is there any way to add a leading space to a TextPortion such that the space inherits the character properties of the TextPortion rather than the preceding one?
AOO413m1(Build:9783) - Rev. 1761381
MacOS 10.12.3 (16D32)

Assistant Editor
Perspectives of New Music
JeJe
Volunteer
Posts: 2755
Joined: Wed Mar 09, 2016 2:40 pm

Re: Get/Set character properties of TextPortion

Post by JeJe »

Do a search for all the spaces and then go through the results setting the format of each result to the format of the next character using a text cursor.

Edit: search as in not enumerating the paragraphs and text portions - use a searchdescriptor.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply