I am desigining a script to find any instances where ctrl+b and ctrl+i are applied to body text and then replace those character format overrides with Italic or Bold chartag. Here's what the script is supposed to do:
- put the find method in a while loop that searches for character format overrides.
- If a character format override is found, pass the text range returned by the find method and the CharPropsChange flag to the GetTextForRange method.
- Use a boolean compare between the idata of the text item to the character angle and character weight constants.
- Whichever boolean evaluates to true, then use the SetTextProp method to set properties of the text range to the properties of the italic or bold character tag.
This script does work on the first character format override found however it ignores any other overrides in the same paragraph. The cause of this is that the while loop updates the text loc that the find method uses to the next paragraph in flow. I suspect that i need to add an inner loop that goes through all the text in a single paragraph, where at teach iteration the text loc used by the find method is based on the same paragraph but the offset is modified. I am just not sure how to do that.
function removeOverrides (pDoc)
{
var vDocStart = pDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
var vBoldFmt=getCharFmt (pDoc, 'Bold')
var vItalicFmt=getCharFmt (pDoc, 'Italic')
initFA_errno ();
while (FA_errno==Constants.FE_Success)
{
var vTextLoc = new TextLoc(vDocStart,0);
var vFindParams=findOverrideParams (pDoc);
var vTextRange=pDoc.Find(vTextLoc,vFindParams);
if (vTextRange.beg.obj.ObjectValid())
{
var vTextItems=pDoc.GetTextForRange (vTextRange, Constants.FTI_CharPropsChange)
if (vTextItems.length==!0 )
{
if (vTextItems[0].idata==Constants.FTF_WEIGHT)
{
pDoc.SetTextProps (vTextRange, vBoldFmt.GetProps())
}
if (vTextItems[0].idata==Constants.FTF_ANGLE)
{
pDoc.SetTextProps (vTextRange, vItalicFmt.GetProps())
}
} else (Log (vLogFileName, '\nERROR: No items were found in the text format array but format override was found: '+pDoc.Name))
}
vDocStart=vDocStart.NextPgfInFlow;
}
}
function findOverrideParams (pDoc)
{
var vFindParams = AllocatePropVals(1);
vFindParams[0].propIdent.num = Constants.FS_FindObject;
vFindParams[0].propVal.valType = Constants.FT_Integer;
vFindParams[0].propVal.ival = Constants.FV_FindCharacterFormatOverride;
return vFindParams;
}