Drop Cap Style - remove and preserve formatting, find and replace others using same

Explorer ,
Mar 20, 2021 Mar 20, 2021

Copy link to clipboard

Copied

Hiya,

I've written the below code to "flatten" (I'm more a Photoshop guy, so that makes more sense to me as a term) nested styles, and find and replace any other text using the same nested styles. 
I'd like to do the same for Drop Cap Styles but am a bit of a loss where to start. There are no corresponding textPreferences for Drop Caps so that's out, beyond that I'm lost. 

Any pointers would be greatly appreciated,
Tim

 

 

    function removeStyles(check, whitelist) {
        for (i = doc.allParagraphStyles.length - 1; i >= 0; i--) {
            var clientItem = whitelist[3].arr[i];
            var hostItem = doc.allParagraphStyles[i];
            try {
                if (clientItem.checked === check && clientItem.name === hostItem.name) {
                    applyNestedStyles(hostItem, hostItem.nestedStyles);
                    applyNestedStyles(hostItem, hostItem.nestedLineStyles);
                    hostItem.dropCapStyle.remove();
                    hostItem.remove();
                }
            }
            catch (e) {
            }
        }
    };

    function applyNestedStyles(hostItem, nestedStyles) {
        for (j = nestedStyles.length -1; j>=0; j--) {
            resetFindReplace();

            var charStyle = hostItem.nestedStyles[j].appliedCharacterStyle;

            app.findTextPreferences.appliedParagraphStyle = hostItem;
            app.findTextPreferences.appliedCharacterStyle = charStyle;
            app.changeTextPreferences.appliedCharacterStyle = charStyle;

            doc.changeText();
        }
    }
    
    function resetFindReplace() {
        app.findTextPreferences = null;
        app.changeTextPreferences = null;
        app.findChangeTextOptions.properties = {
            includeLockedStoriesForFind: true,
            includeLockedLayersForFind: true,
            includeHiddenLayers: true,
            includeMasterPages: true,
            includeFootnotes: true,
            wholeWord: false,
            caseSensitive: false
        }
    }
}

 

TOPICS
Scripting

Views

85

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Explorer , Mar 24, 2021 Mar 24, 2021
I've solved it I think that I possibly didn't articulate myself very well in my OP.The function is passed a paragraph style, and if it has a drop cap style it then applies that drop cap style as a normal character style to all text present in the document that has the same paragraph style and drop cap applied. This is part of a larger script that removes all styles from a document whilst preserving formatting.The solution was to change:var charStyle = hostItem.nestedStyles[j].appliedCharacterSt...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Mar 21, 2021 Mar 21, 2021

Copy link to clipboard

Copied

I'd like to do the same for Drop Cap Styles 

 

I don’t see how—don’t think it’s even possible to do it manually.

 

You can get the dropChapChracters and dropCapLines from the paragraph properties and from there you could calculate the point size for the dropcap character, but if you try to baseline shift the cap character, the text is not going to wrap. You would have to create a textframe for the cap and anchor that in the text.

 

Screen Shot 1.png

 

 

 

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

Hi Rob,

thanks for your reply.
I've actually managed to have some success with my existing code by passing the dropCapStyle object to applyNestedStyles() as an array:

applyNestedStyles(hostItem, new Array(hostItem.dropCapStyle));

 It's not quite behaving, and at the moment I've not managed to clearly pinpoint what's happening. I just wanted to reply so as not to be rude! I shall return once I've managed to do some more debugging...

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

Are you trying to imitate an initial cap without setting drop cap lines and characters? Can you do that manually in the UI using other character and paragraph formatting?

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

I've solved it 😄

I think that I possibly didn't articulate myself very well in my OP.

The function is passed a paragraph style, and if it has a drop cap style it then applies that drop cap style as a normal character style to all text present in the document that has the same paragraph style and drop cap applied. This is part of a larger script that removes all styles from a document whilst preserving formatting.
The solution was to change:

var charStyle = hostItem.nestedStyles[j].appliedCharacterStyle;

to

var charStyle = hostItem.nestedStyles[j];

because the drop cap style being passed as nestedStyles to the function already is a CharacterStyle.

Likes

translate

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines