Jump to content

I'm have trouble with formatting color and text flow / copyfit


Recommended Posts

Hi,

I have a business card with one two or three possible phone numbers. (direct, cell, and main) The first number needs to be color red. The numbers are suppressed if they are empty fields. Is there a way to format the paragraph so that the first line is "color" regardless of the field.

 

The other issue I have is that on the business card the title may be to long to fit and should flow to another line or better flow to anther text box.

 

Any help would be appreciated. I know this has probably been answered in other posts and I may have read them but still lacking comprehension.

thanks

Leo

Link to comment
Share on other sites

Regarding your color question, you can definitely do that. Just add this rule:

var color = "Delkor Red"; // First Line Color
var numbers = [ // Array of numbers and identifiers
   ["Direct",Field("direct phone")],
   ["Cell",Field("cell")],
   ["Main",Field("main")]];

numbers = numbers.filter(function(s){return Trim(s[1]);}).map(function(s,p){var r = s.join(": ");return (!p)?'<span color="'+color+'">'+r+'</span>':r;}).join('<br>');

return numbers;

For the above code, I'm using a multi-dimensional array. Arrays are great for this type of scenario because of the methods available for them. Here's a quick break down of how I'm using it:

As I said, the array "numbers" is a 2D array. Meaning, each position in the array is another array. The inner array contains the phone number description (Cell, Main, etc) and the second position contains the field value that corresponds to that description.

 

Using the filter method, we can remove empty elements from the "numbers" array. This is essentially doing the same thing as "suppress if empty."

 

Using the map method we're able to apply a function to each element in the array. The function I used basically joins the two positions in the inner array (description & number) with a colon and a space. It then checks to see if it's the first element in the array (the first number) and if it is, it applies a span tag which is making the number red.

 

Finally, I used the join method to join all of the formatted elements with a break tag ("<br>");

 

If you wanted to, you could apply this logic to the entire card so that you only have one text box and one rule in your template.

Link to comment
Share on other sites

First Ste

Thanks for the response-solution and detailed explanation and links to sources. When I first saw your response I thought are you kidding me. I spent a full day trying various rabbit holes.

It is such elegant solution and I appreciate the notes you made.

I did see in another post on a similar topic that an array was used but it was way over my head.

 

I will challenge myself to apply the logic to the whole card so I can get a grasp on the programming elements you used. Again thanks much.

 

Leo

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

Some of the parameters changed on the project.

The client wants equal white space above and below the printing.

There was a static line in the original file. Now the line needs to float with the variable data.

My goal is to create a .5 point line 2 inches long underneath the Name. (example is the goal pdf)

The line needs to float with text because the number of lines are variable and the client wants equal white space above and below the print.

 

The other issue is that my line is one character to the left of all other type.

I put a space in front of text which worked (however wrong for coding) for most lines except on the rule which can have multiple lines of text.

The first phone number is ok but then the next one/two right align.

 

 

Any help would be appreciated.

thanks

Leo

DelKor_BizCard_FP.zip

Delkor_BizCard_goal.pdf

Link to comment
Share on other sites

That's a pretty tricky one. The way I would probably do this would be using a table. That will give you more control over the spacing of the three sections, allow you to put the "stroke" underneath the title, and adjust the left margins so that all of your sections line up neatly if they flow to another line.

 

I've attached a sample of how I would set up the template and I'll go ahead and apologize because it's a little sloppy because I just threw it together. Here's the code and what it's doing:

/*==================================================
// Edit your variables (All units in points)
//=================================================*/
   var color = "Delkor Red";   //Red color
   var leading = 6;            // Leading
   var pointsize = 6;          // Font size
   var spacing = 7;            // Spacing between sections 
   var lineOffset = 15;        // 0 == baseline
   var frameName = "contact"   // Name of the frame to display the table in
   var leftIndent = 3;         

/*==================================================
// Generate the 3 sections:
// Titles, Address, Numbers/Email/URL
//=================================================*/
   function phoneNumbers(){
       var numbers = [ // Array of numbers and identifiers
           ["Direct",Field("Direct Phone")],
           ["Main",Field("Main")],
           ["Cell",Field("Cell")]];

       numbers = numbers.filter(function(s){return Trim(s[1]);}).map(function(s,p){var r = s.join(" : ");return (!p)?'<span color="'+color+'">'+r+'</span>':r;}).join('<br>');
       return numbers;
   }

   // Titles
   var title = [Field("Title"),Field("title 2")].filter(String).join('<br>');
   title = (title) ? '<i>' + title + '</i>' : '';

   // Address
   var address = [Field("Address"),
                 [Field("City"),Field("St"),Field("Zip")].filter(String).join(', ').replace(/,( \d*)$/,'$1')].join('<br>');

   // Numbers/Email/URL
   var numbers = [phoneNumbers(),Field("email 1"),"www.delkorsystems.com"].filter(String).join('<br>');

/*==================================================
// Create table to display the content
//=================================================*/
   // Add leading to the sections
   var fields = [Field("Name"),title,address,numbers].filter(String).map(function(s,p){return (p) ? '<p br=false leading=' + (leading * 10) + '>' + s : s;});

   // Initiate table
   var myTable = new FPTable;
   myTable.AddColumns(GetSettableTextWidth(FindTextFrame(frameName)));

   for (var i=0; i<fields.length; i++){
       var row = myTable.AddRow();
       var cell = row.Cells[0];
       var content = fields[i];
       var isNameLine = (!i && Field("Name")); // flag name line for color and stroke
       if (isNameLine){
           cell.VAlign = "Bottom";
           cell.SetBorders("Thin",color,"Bottom");
           content = '<span color="' + color + '"><p br=false subratio="100" suboffset="'+lineOffset+'"><subscript>' + content + '</subscript></span>'
       }
       var topMargin = (isNameLine) ? 1 : (i == 1) ? (pointsize*1.5)+leading : (spacing*10);
       cell.Margins = {Top:topMargin, Bottom:1, Right:(leftIndent*100), Left:0}
       row.SetContents(content);
   }
   var table = '<z newsize="' + pointsize + '">' + myTable.MakeTags();

return table;

 

It's creating a table that has 1 column that is as wide as the text frame that it's in, and 4 rows.

 

The first row, contains the "Name" field. If the Name is not empty, that row will have a red border on the bottom. In order to offset the stroke, I'm actually subscripting the text so that it appears below the cell that it's in. That offset amount can be adjusted with the "lineOffset" variable to fit your font.

 

The next three rows will be the three sections of your card if they are populated. The second row will have unique leading to compensate for the subscripted name. It's calculated in this line:

var topMargin = (isNameLine) ? 1 : [color="Red"](i == 1) ? (pointsize*1.5)+leading[/color] : (spacing*10);

The balance of the rows will have a top margins equal to the "spacing" variable to ensure they are all equally spaced. Again, you can adjust these variables to fit your needs.

 

Once the table is generated, place it in a frame that's vertically aligned to the middle.

bizcard.zip

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...