Copy link to clipboard
Copied
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
My questions are:
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...
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Good job Klaus. That is a nice piece of code.