Skip to main content
K.Daube
Community Expert
Community Expert
November 29, 2018
Answered

Creating a TextLine with character format

  • November 29, 2018
  • 1 reply
  • 685 views

Well friends, the story about TextLine needs a new chapter:

Things go really strange with this short script:

// Clone a selected TextLine to check the function

#target framemaker

main ();

function main () {

  var j, oDoc = app.ActiveDoc, oFrame, oSelected, oTextLine, sText, oTextLoc, oTR, CM = 1857713, DEGREE = 65536;

 

  oSelected = oDoc.FirstSelectedGraphicInDoc;

  oFrame = oSelected.FrameParent;

  oTextLine = oDoc.NewTextLine(oFrame);

  oTextLoc = new TextLoc (oTextLine, 0);

  oDoc.AddText (oTextLoc, "New text");

  oTextLine.BasePointX = oSelected.BasePointX;    // not changed

  oTextLine.BasePointY = oSelected.BasePointY + 1*CM;

  oTextLine.StyleTag = "fh2-fig-heading2";

  oTextLine.Angle = 5 * DEGREE;

  oTextLine.Fill = 0;   // not used !

  oTextLine.Color = oDoc.GetNamedColor("Magenta"); // does not work

} //--- end main

  1. Source TextLine selected, then script applied:
    Resultant 'clone' is an object TextLine, indicated in the status line as  O: fh2-fig-heading2*
    but using colour ddd-3 (used in table heading cells etc.)
    Selected as text it has no style, but size is 128 pt (as used by a specific ¶ format) and font family which can be from fh2-fig-heading2 but also from the specific ¶ format
  2. Now I select the cloned text (the green one) as text and apply the character format fh2-fig-heading2.
  3. Now i delete the clone TextLIne (the red one), select the source TextLine again and run the script:
    Resultant 'clone' text is an object TextLine as before indicated in status line and text has character format (obviously from the manual action before deletion).

My questions are:

  • Wherefrom gets the first created clone TextLine its strange properties?
  • How to correctly apply a character format to this type of thingy?

You may say that the cloned object did not get the properties from the source object (the one I select before invoking the script), but trying to replace lines 10 -18 by

oTextLine = CloneTextLine (oDoc, oFrame, oSelected);

oTextLine.BasePointY = oSelected.BasePointY + 1*CM;

and defining the required function as

function CloneTextLine (oDoc, oFrame, oSource) { // --- Clone TextLine object ----------

var oClone, attr

  oClone = oDoc.NewTextLine(oFrame);

  for (attr in oSource) {                         // attr = BasePointX, ...

    if (oSource.hasOwnProperty(attr)) {

      oClone[attr] = oSource[attr];

    }

  }

  return oClone;

} //--- end CloneObject

creates an empty TextLine with Witdh 0 and Height 128pt ...  and some additional TextLInes, which remain invisble when selected and centered to have them in the middle of the Anchored Frame - but they can be deleted...

This topic has been closed for replies.
Correct answer frameexpert

Remember that Doc objects have their own text properties. Try this code, then create a new text line and see what it looks like:

#target framemaker

var doc = app.ActiveDoc;

doc.FontSize = 65536 * 18; // 18 points

doc.Color = doc.GetNamedColor ("Red");

This may solve the mystery for you. -Rick

1 reply

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
November 29, 2018

Remember that Doc objects have their own text properties. Try this code, then create a new text line and see what it looks like:

#target framemaker

var doc = app.ActiveDoc;

doc.FontSize = 65536 * 18; // 18 points

doc.Color = doc.GetNamedColor ("Red");

This may solve the mystery for you. -Rick

www.frameexpert.com
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
November 30, 2018

Thanks Rick for this hot tip!

During shaving this morning it came to my mind that a TextLine is a double faced object: part of its properties are that of the TextLine object, part are that of the 'mother'-object document (the text itself).

oTextLine.StyleTag is not a character format, but a style defined with the Object Designer. And this sort of style can only contain Alignment (AsIs, Left, Right, Center) and Direction (AsIs, Inherit, LTR, RTL).

Since eventually I want to create textlines using various character formats (e.g. 17.5×10-3) - bold for the full text, superscript for part of it - that obviously must be done with text ranges.

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
November 30, 2018

Eventually I made it:

// Create a TextLine with overall and local character format

#target framemaker

main ();

function main () {

  var j, oDoc = app.ActiveDoc,

      oCharFmt, oCharProps, oHilight, oHiProps, oTRall, oTRhi,

      oFrame, oSelected, oTextLine, sText, oTextLoc, oTR,

      CM = 1857713, DEGREE = 65536;

  oFrame = oDoc.FirstSelectedGraphicInDoc;

  if (!oFrame.ObjectValid()) {

    alert ("An anchored frame must be selected.");

    return;

  }

//oTextLine = oDoc.NewGraphicObject(Constants.FO_TextLine, oFrame); // alternative

  oTextLine = oDoc.NewTextLine(oFrame);

// ---------------------------------------------- Properties of the TextLine object

  oTextLine.BasePointX = 0.5 * CM;

  oTextLine.BasePointY =  1  * CM;

//oTextLine.Width = oSelected.Width;              // set by text contents !

//oTextLine.Height= oSelected.Height

  oTextLine.Angle = 5 * DEGREE;

// ---------------------------------------------- Default text format in document - just in case

  oDoc.FontSize = 65536 * 18; // 18 points

  oDoc.Color = oDoc.GetNamedColor ("Mauve");

// ---------------------------------------------- Define and format the text

  oTextLoc = new TextLoc (oTextLine, 0);

  oDoc.AddText (oTextLoc, "New text with highlight"); // highlicht starts at offset 14

  oCharFmt = oDoc.GetNamedCharFmt("FT-fig-textline"); // general character format

  oCharProps = oCharFmt.GetProps();

  oTRall    = new TextRange();

  oTRall.end.obj = oTRall.beg.obj = oTextLine;

  oTRall.beg.offset = 0;

  oTRall.end.offset = Constants.FV_OBJ_END_OFFSET;

  oDoc.SetTextProps (oTRall, oCharProps);        // apply the general char format

  oHilight = oDoc.GetNamedCharFmt("super");      // local highlight

  oHiProps = oHilight.GetProps();

  oTRhi    = new TextRange();

  oTRhi.end.obj = oTRhi.beg.obj = oTextLine;

  oTRhi.beg.offset = 14;

  oTRhi.end.offset = Constants.FV_OBJ_END_OFFSET;

  oDoc.SetTextProps (oTRhi, oHiProps);            // apply the local char format

} //--- end main