Skip to main content
K.Daube
Community Expert
Community Expert
February 2, 2016
Answered

Re-apply format to paragraph

  • February 2, 2016
  • 1 reply
  • 1436 views

Dear all,

Once again it seams that I "put the cart before the horse" to do the following:

- In the current document i have a text selection and want to re-apply the pgf format from the catalogue to the current pgf.

- Taking the properties from the catalogue and applying to the current pgf does nothing.

function ReApplyPgfFormat (oDoc, tRange) {
// oDoc        current document
// tRange      current text range
  var currPgf = tRange.beg.obj;
  var pgfFormat = currPgf.Name;                   // most likely Footnote, but not guaranteed
  var pgfFmt = oDoc.GetNamedPgfFmt(pgfFormat);   
  var pgfProps = pgfFmt.GetProps();               // from catalogue
  currPgf.SetProps(pgfProps);                     // re-apply
alert ("Reformatting done?");                     // re-apply did not happen
}

I was searching in the documentation (fdk reference, object reference) back and forth - but did not get a clue.

This topic has been closed for replies.
Correct answer K.Daube

Wow, Klaus, again capitalisation hit me!

«try currPgf.Name instead of currPgf.name»

This works as intended.

I have not yet found a clear list of syntax rules - and there are differences between JS and ES object and methods ...


This is the final solution to my problem which is not just re-apply the current ¶-format:

  • Although the paste operation inserts something with different format, the information field bottom left does not indicate a modified ¶-format. There is no * after the format-name.
  • After inserting (replacing) the temp. citation by a biblographic record the ¶ shows mixed fonts and sizes. Only part of the ¶ is selected (that part where the found temp. citation was).

What I ned to do in my case is this:

  • Get only font-family and font-size from the catalogue
  • Apply only these properties to the completely selected ¶

function ReApplyFontAndSize (oDoc, tRange) {
  oDoc.TextSelection = tRange;                    // current selection is only part of ¶
  var currPgf = oDoc.TextSelection.beg.obj;
  var pgfFmt = 0, propsPgf;
  pgfFmt = oDoc.GetNamedPgfFmt(currPgf.Name);    // get properties from catalogue 

  if (!pgfFmt.ObjectValid()) {                   // pgf fmt is not in catalogue
    return;
  }
  propsPgf = AllocatePropVals(2);                // for font-family and -size
  propsCatlg = pgfFmt.GetProps();                // get properties from catalogue
  j =  GetPropIndex(propsCatlg, Constants.FP_FontFamily);
  propsPgf[0] = propsCatlg ;
  j =  GetPropIndex(propsCatlg, Constants.FP_FontSize);
  propsPgf[1] = propsCatlg ;

  tRange.beg.obj = currPgf;                      // select the whole paragraph
  tRange.beg.offset = 0;
  tRange.end.obj = currPgf;
  tRange.end.offset = Constants.FV_OBJ_END_OFFSET;
  oDoc.TextSelection = tRange;
  oDoc.SetTextProps (tRange, propsPgf);          // apply font family and size
} // --- end ReApplyFontAndSize

This may be streamlined - but it does what it should.

1 reply

frameexpert
Community Expert
Community Expert
February 2, 2016

Here is a function I use to apply a paragraph format to a paragraph.

function applyPgfFmt (pgf, name, doc) {

  

    var pgfFmt = 0;

  

    pgfFmt = doc.GetNamedPgfFmt(name);

    if (pgfFmt.ObjectValid()) {

        var props = pgfFmt.GetProps();

        pgf.SetProps(props);

    }

    else {

        pgf.Name = name;

    }

}

In your case, you could call it like this:

var doc = app.ActiveDoc;

var pgf = doc.TextSelection.beg.obj;

applyPgfFmt (pgf, pgf.Name, doc);

-Rick

www.frameexpert.com
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
February 3, 2016

Thank You Rick,

However, I had to insert line 4. Without this the format is not really applied (in this case). Maybe the Textselection is in a special state from the find/replace process. Probably my initial idea (not communicated) would also have worked with this.

function ReApplyPgfFormat (oDoc, tRange) {
// oDoc        current document
// tRange      current text range
  oDoc.TextSelection = tRange;                    // without this the re-apply don't work
  var currPgf = tRange.beg.obj;
  applyPgfFmt (currPgf, currPgf.Name, oDoc);      // re-apply
}

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
March 17, 2016

Dear all,

I was to fast in accepting the solution... Further tests with other fm-documents revealed my misconception: The ¶-format is not re-applied - it just looks so:

  • What's copied during the find/replace has a font size of 12pt (coming from the RTF file).
  • The reciving ¶-format has various font-sizes (due to various formats).
  • I had tested initially with files using 12pt everywhere...
  • Olthough the paste operation inserts something with different format, the information filed bottom left does not indicate a modified ¶-format. There is not * after the format-name.
  • In the script line 04 reports Undefined and hence lines 8 and 9 are not executed.

function ReApplyPgfFormat (oDoc, tRange) {
  oDoc.TextSelection = tRange;
  var currPgf = oDoc.TextSelection.beg.obj;
Alert ("currPgf.name = " + currPgf.name);        // => undefined
  var pgfFmt = 0; 
  pgfFmt = oDoc.GetNamedPgfFmt(currPgf.name);    // take properties from catalogue 
  if (pgfFmt.ObjectValid()) {
    var props = pgfFmt.GetProps(); 
    currPgf.SetProps(props); 
  }                                              // do nothing, if not in catalogue
  giLvlTrace -= 1;
} // --- end ReApplyPgfFormat

What can I do to get the current ¶ from the text range?