Skip to main content
Community Expert
June 14, 2017
Beantwortet

Apply Paragraph Style while preserving paragraph and character overrides

  • June 14, 2017
  • 2 Antworten
  • 1973 Ansichten

Hello All,

I have a paragraph with two kinds of overrides applied over it. First one is a paragraph level override like left indent, and other a character level override like changing fonts of some characters in the paragraph. Now i want to change the paragraph style applied on this paragraph but preserve both kinds of overrides. Using applyParagraphStyle does not preserve the paragraph level override

For ex: app.selection[0].paragraphs[0].applyParagraphStyle(pStyle, false) // This removes the left indent override, but maintains the character level override

app.selection[0].paragraphs[0].applyParagraphStyle(pStyle, true) //This removes both the left indent as well as the character level override

Am i missing something, as according to documentation of applyParagraphStyle, false as the second option should preserve the local formatting.

Thanks,

-Manan

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von Laubender

https://forums.adobe.com/people/Manan+Joshi  wrote

… In order to identify the overrides do we need to traverse through all the properties of the paragraph and match it with those of the paragraphstyle and the properties whose value don't match would be identified as overridden. Won't this be a time taking process, is there a faster way to achieve this.

Hi Manan,

yes this is a time consuming process and requires a lot of coding work.

Especially if it comes to enumerators and nested styles, nested GREP styles, tabLists, bullet characters, numbering restart policies or applied conditions.

You have to do a exemption lists for properties as well. Just to name some in no particular order you would not like to compare: length, contents, allPageItems, parentStory, parentTextFrames, endBaseline, endHorizontalOffset, horizontalOffset, baseline, numberingResultNumber, appliedParagraphStyle, styleOverridden etc.pp.

Regards,
Uwe

2 Antworten

Trevor:
Legend
June 14, 2017

What the document means by local formatting is the character overrides and not the paragraph ones.

Community Expert
June 14, 2017

AFAIK the only way of doing that is to detect quacks overrides first then apply duck and then apply the overrides to the newly ducked paragraph.

Hi Trevor,

I agree.

This could be tricky for all possible overrides one cannot find properties for in character styles.
Especially for GREP Styles, I think. Doable, but you have to write a lot of code. With a plain leftIndent override this should be easy.

FWIW:

Let's see into the styleOverridden property of the Text class.
That will also return true, if the only override is a typical one that we usually associate with paragraph formatting.
Like a different value for leftIndent that is not defined in the applied paragraph style.

I am inclined to define "local formatting" like that:

If styleOverride returns true for any insertion point in a paragraph, the paragraph is "local formatted".

And you are right, DOM documentation sometimes is a bit vague.

( the understatement of the century )

Regards,
Uwe

Trevor:
Legend
June 14, 2017

Ok so you have 2 paragraph styles 1 called quack and the other called duck.

quack has a 10mm indent to it but on your paragraph you've giving it a 20mm indent.

You want to apply duck to it which has an indent of 30mm but keep the 20m indent override.

AFAIK the only way of doing that is to detect quacks overrides first then apply duck and then apply the overrides to the newly ducked paragraph.

This is not a bug or fault in the documentation.

HTH

Trevor

Community Expert
June 14, 2017

Thanks for the reply Trevor, i also had finally arrived at the same conclusion which you confirmed.

Now my other query would be, how to detect overrides on a paragraph style. I know there is a method/property on the paragraph that can tell us if it has overrides over it.

In order to identify the overrides do we need to traverse through all the properties of the paragraph and match it with those of the paragraphstyle and the properties whose value don't match would be identified as overridden. Won't this be a time taking process, is there a faster way to achieve this.

Thanks,

-Manan

-Manan
Community Expert
June 14, 2017

https://forums.adobe.com/people/Manan+Joshi  wrote

… In order to identify the overrides do we need to traverse through all the properties of the paragraph and match it with those of the paragraphstyle and the properties whose value don't match would be identified as overridden. Won't this be a time taking process, is there a faster way to achieve this.

Hi Manan,

yes this is a time consuming process and requires a lot of coding work.

Especially if it comes to enumerators and nested styles, nested GREP styles, tabLists, bullet characters, numbering restart policies or applied conditions.

You have to do a exemption lists for properties as well. Just to name some in no particular order you would not like to compare: length, contents, allPageItems, parentStory, parentTextFrames, endBaseline, endHorizontalOffset, horizontalOffset, baseline, numberingResultNumber, appliedParagraphStyle, styleOverridden etc.pp.

Regards,
Uwe


Thanks Uwe, i had implemented this code and did find it really eating up the time in cases i had to do it for lots of paragraphs, and yeah i did stumble upon the fact that i need to be mindful of not using some properties. But the list i had made so far was not as extensive as you gave, so you did help me save some time of investigation

Thanks for all the help Uwe and Trevor much appreciated

-Manan