Page 1 of 1

Get/Set character properties of TextPortion

Posted: Wed Mar 29, 2017 2:45 am
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

Re: Get/Set character properties of TextPortion

Posted: Wed Mar 29, 2017 3:13 am
by pnm_asst_ed
I'm using:

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

Re: Get/Set character properties of TextPortion

Posted: Sun May 30, 2021 8:55 am
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?

Re: Get/Set character properties of TextPortion

Posted: Sun May 30, 2021 11:35 am
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.