Jump to content

Formatting Headache


esmith

Recommended Posts

I have been struggling with setting up contact info on a business card all week. The client wants to put contact info on the right side of card (email, phone, fax, mobile) with the contents of the longest field right-aligned to a 1/4" margin and all other fields left-aligned with the start position of the longest field. They also have a custom graphic for each field that appears to the left of each line. If a particular field is empty, the balance of the fields collapse downward with the bottom line resting 1/4" from bottom trim.

 

I can't figure out how to left-align lines of data to each other while determining which of the four fields is longest in width (per record) and making that line right-align to margin. I thought I could use a table to place the icon graphics in a one cell, and then the data in a 2nd. I had thought that all the data would be left-aligned in a single column and that the column width would expand or collapse per the longest line of copy. That doesn't seem to be the case since you must define the width of the column first.

 

Additionally, I would expect to have to right-align the table in the frame, but when I do this, the text runs off the right edge of the frame. The graphic resource does not display either, but that's a different story.

 

Here's the code I was trying to use to generate my table:

var tableData = "<table columns=\"2\"><column width=\"1480\"><column width=\"11520\">";

if (Field("e-mail") != "") {
   tableData += "<row><cell>" + Resource("email").content + "<cell>" + Field("e-mail");
   } 
if (Field("Work phone") != "") {
   tableData += "<row><cell>" + Resource("tele").content + "<cell>" + Field("Work phone");
   }
if (Field("Extension") != "") {
   tableData += "<row><cell>" + Resource("blank").content + "<cell>ext. " + Field("Extension");
   }
if (Field("Fax (optional)") != "") {
   tableData += "<row><cell>" + Resource("fax").content + "<cell>" + Field("Fax (optional)");
   }
if (Field("Cell phone (optional)") != "") {
   tableData += "<row><cell>" + Resource("cell").content + "<cell>" + Field("Cell phone (optional)");
   }
tableData += "</table>";

return tableData;

Does anyone have a way to modify this code or come up with a different solution to solve my problem? I am attaching a PDF of a sample card showing the alignment I am trying to achieve.

sample card.pdf

Link to comment
Share on other sites

I was informed my question is too open ended. Not sure that it's any more open ended than half the posts I try to assist with, but let me make it a bit more (con)dense(d):

 

Is there a way to left-align a stack/column of fields in a text frame so that the longest of those fields is right-aligned to a specific point on the static template?

 

If the answer is NO, that's fine (although I don't think the forum will allow a 2 character response). :p

Link to comment
Share on other sites

Is there a way to left-align a stack/column of fields in a text frame so that the longest of those fields is right-aligned to a specific point on the static template?

Yes. Here was a post I wrote to the old email forum (archived at

http://www.mail-archive.com/fusionpro@lists.printable.com/msg00760.html ) a couple years ago in response to this same question:

 

You can accomplish things like this with Text Measurement. Here's an

example using the Frodo Travel tutorial:

    // CHANGE THIS TO THE WIDTH OF YOUR FRAME
   var FrameWidth = 3 * 7200;

   // CHANGE THIS TO WHATEVER LINES YOU HAVE
   var Lines = [ Field("Name"), "Welcome to", Field("Destination") ];

   var tm = new FusionProTextMeasure;

   // CHANGE THESE TO MATCH YOUR TEXT ATTRIBUTES
   tm.pointSize = "12 pt";
   tm.font = "Arial";
   tm.bold = true;
   tm.useTags = false;

   var LargestWidth = 0;

   for (var i = 0; i < Lines.length; i++)
   {
     if (tm.CalculateTextExtent(Lines[i]))
       return "***ERROR***: " + tm.messages;
     var LineWidth = tm.textWidth;
     if (LineWidth > LargestWidth)
       LargestWidth = LineWidth;
   }

   var LineIndent = FrameWidth - LargestWidth;

   var result = "";

   for (var i = 0; i < Lines.length; i++)
   {
     result += "<p findent=" + LineIndent + ">";
     result += NormalizeEntities(Lines[i]) + "\n";
   }

   return result;

Actually, with FusionPro 6.0, instead of hard-coding the width of the frame in the first line, you can use the new Frame Properties JavaScript access, like so:

var FrameWidth = FindTextFrame("YourFrameName").GetSettableTextWidth();

Link to comment
Share on other sites

Thank you Dan. With a few minor adjustments to include inline graphic resources, that worked perfectly.

 

Although I am using FP 6.0p1f, when I tried to use the GetSettableWidth() function, I received the following error:

***Error*** (/Library/Application Support/Printable/FusionPro/Builtins.js, line 2936: TypeError: invalid 'instanceof' operand FusionProFrame)

I looked at the Builtins.js file in a text editor, but didn't see any glaring mistakes with the referenced function. Regardless, hard coding the FrameWidth worked fine for my needs.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...