Jump to content

Variable length text box with fill attribute


LesSjo

Recommended Posts

I have a business card template setup that has a solid 6 pt solid line running horizontally across the business card. My customer wants to have a white fill behind the name that covers this line so that the text box has a 3 pt bleed to the left and right of the name, which is horizontally centered on the line.

 

Because most names are variable in length, is there a method of controlling the length of the text box so that it will contract/expand to produce the desired effect I am after?

 

A picture says a thousand words, so I have attached an image of what I am after.

 

Thanks is advance.

sample.pdf

Link to comment
Share on other sites

I'm not sure that you can adjust the width of the text box based on the length of a field but you can adjust the width of a cell in a table on the fly.

 

I created a table with 1 row and 3 columns. The outside columns are empty and are set at the width of 3pt to give you your 3pt white space on either side of the name. I used TextMeasure to variably adjust the width of the inside column based on the length of the "Name" field. This should be a good starting point for you:

 

// Use TextMeasure to measure the length of each name
var tm = new FusionProTextMeasure;
tm.pointSize = "10 pt"; // set the type size
tm.font = "Helvetica"; // set your typeface
tm.CalculateTextExtent(Field("Name")); // Replace with your field
tm.useTags = false;
var tmWidth = tm.textWidth;

// Create table 
var myTable = new FPTable;
myTable.AddColumns(300, tmWidth, 300); 
myTable.AddRows(1);

// Declare TableMargin object to adjust margins
myTable.Rows[0].Cells[0].Margins = new FPTableMargins;
myTable.Rows[0].Cells[0].Margins.Top = 60;
myTable.Rows[0].Cells[0].Margins.Bottom = 60;
myTable.Rows[0].Cells[0].Margins.Left = 0;
myTable.Rows[0].Cells[0].Margins.Right = 0;

myTable.Rows[0].Cells[0].VAlign = "Middle";
myTable.Rows[0].Cells[0].HAlign = "Center";
myTable.Rows[0].Cells[0].Font="Helvetica";
myTable.Rows[0].CopyCells(0, 1,2);

myTable.ShadingColor1 = "White";
myTable.ShadingPct1 = 100;
myTable.ShadingRepeat1 = 1;
myTable.ShadingType = "ByRow"; 

myTable.Rows[0].Cells[0].Content = "";
myTable.Rows[0].Cells[1].Content = Field("Name");
myTable.Rows[0].Cells[2].Content = "";

return myTable.MakeTags().replace(/^\<table/, "<table alignment=center"); // Center table in Text box

Link to comment
Share on other sites

  • 4 years later...

I am new to FusionPro and javascript. I think the code you provided will help with the issue I am having; however when I create the new rule with this code and apply it to the text box, it generates code. Is this what it's supposed to do or am I supposed to see a table within the text box?

 

Thanks in advance.

Link to comment
Share on other sites

I am new to FusionPro and javascript. I think the code you provided will help with the issue I am having; however when I create the new rule with this code and apply it to the text box, it generates code. Is this what it's supposed to do or am I supposed to see a table within the text box?

 

Open the Rule and check the box that reads "Treat returned strings as tagged text".

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