Highlighted

Re-apply format to paragraph

Advocate ,
Feb 02, 2016

Copy link to clipboard

Copied

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 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.

TOPICS
Scripting

Views

784

Likes

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

Re-apply format to paragraph

Advocate ,
Feb 02, 2016

Copy link to clipboard

Copied

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 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.

TOPICS
Scripting

Views

785

Likes

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
Feb 02, 2016 0
Adobe Community Professional ,
Feb 02, 2016

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Feb 02, 2016 0
Advocate ,
Feb 03, 2016

Copy link to clipboard

Copied

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
}

Likes

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
Reply
Loading...
Feb 03, 2016 0
Advocate ,
Mar 17, 2016

Copy link to clipboard

Copied

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?

Likes

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
Reply
Loading...
Mar 17, 2016 0
Enthusiast ,
Mar 17, 2016

Copy link to clipboard

Copied

Hi Klaus,

the problem is definitely the undefined Pgf (line 4);

There are some points to look at:

- try currPgf.Name instead of currPgf.name

- how do you define your selection?


The variable oDoc looks like a global one. But you use it as an argument in your function. I don't know, if this can cause a problem (same with tRange).


Likes

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
Reply
Loading...
Mar 17, 2016 0
Advocate ,
Mar 18, 2016

Copy link to clipboard

Copied

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 ...

Likes

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
Reply
Loading...
Mar 18, 2016 0
Advocate ,
Mar 22, 2016

Copy link to clipboard

Copied

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.

Likes

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
Reply
Loading...
Mar 22, 2016 0