Jump to content

Dynamic Background, Table or Frame Width


David Miller

Recommended Posts

Not sure how to tackle this one...

 

We have a series of business cards where the name and job title are on the same line. The background color behind the name is black and behind the job title it is green. The gap between the name and job title is constant, but the width of the background color behind the name must change based on the length of the name. Obviously, affecting the background color width behind the title.

 

Attached is a PDF with examples. Anyone have any suggestions?

 

Thought about creating a series of backgrounds and change them based on the length of the name field. Maybe tables? New FP features I'm not familiar with? (The template files will probably be used in MarcomCentral.)

 

Thanks.

Link to comment
Share on other sites

After looking at the example, it looks to me like some of the longer names (specifically Rachelle Kivanoski) are sized a bit smaller than the others.

 

Will TextMeasure take into account whether or not the text needs to be CopyFit in the table's column?

Link to comment
Share on other sites

After looking at the example, it looks to me like some of the longer names (specifically Rachelle Kivanoski) are sized a bit smaller than the others.

 

Will TextMeasure take into account whether or not the text needs to be CopyFit in the table's column?

No, it just measures the text you give it. You can always call the CopyfitLine function first to make sure it fits, though. (CopyfitLine itself utilizes FusionProTextMeasure to know if the text fits on the line.)

Link to comment
Share on other sites

Haven't worked with tables in FusionPro before. So, I read through Dan's JavaScript Table API – The Basics and Step's post here.

 

Was able to get a very basic version of this working, but am unable to get any copy-fitting to work. Specifically, CopyFitLine with no breaks.

 

// 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;

var tableWidth = 27000
var column0Width = tmWidth + 2700
var column1Width = 150
var column2Width = tableWidth - column0Width - column1Width

// Create table 
var myTable = new FPTable;
myTable.AddColumns(column0Width, column1Width, column2Width); 
myTable.AddRows(1);

// Declare cell formatting
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 = 900;
myTable.Rows[0].Cells[0].Margins.Right = 1800;

myTable.Rows[0].Cells[2].Margins = new FPTableMargins;
myTable.Rows[0].Cells[2].Margins.Top = 60;
myTable.Rows[0].Cells[2].Margins.Bottom = 60;
myTable.Rows[0].Cells[2].Margins.Left = 900;
myTable.Rows[0].Cells[2].Margins.Right = 900;

myTable.Rows[0].Cells[0].ShadeColor="Black";
myTable.Rows[0].Cells[0].ShadePct=80;
myTable.Rows[0].Cells[0].VAlign = "Middle";
myTable.Rows[0].Cells[0].HAlign = "Left";
myTable.Rows[0].Cells[0].Font="Helvetica";
myTable.Rows[0].Cells[0].TextColor="White";
myTable.Rows[0].Cells[0].PointSize=10;

myTable.Rows[0].Cells[1].ShadeColor="Yellow";
myTable.Rows[0].Cells[1].ShadePct=80;

myTable.Rows[0].Cells[2].ShadeColor="Green";
myTable.Rows[0].Cells[2].ShadePct=80;
myTable.Rows[0].Cells[2].VAlign = "Middle";
myTable.Rows[0].Cells[2].HAlign = "Left";
myTable.Rows[0].Cells[2].Font="Helvetica";
myTable.Rows[0].Cells[2].TextColor="White";
myTable.Rows[0].Cells[2].PointSize=10;

myTable.Rows[0].Cells[0].Content = CopyfitLine("", Field("Name"), "Helvetica", 10, column0Width, 2, true);
myTable.Rows[0].Cells[1].Content = "";
myTable.Rows[0].Cells[2].Content = CopyfitLine("", Field("Title"), "Helvetica", 10, column2Width, 2, true);

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

 

I figured that the width needs to be 3.75" wide, the width of column 0 is set by the text width of the name field plus margins, column 1 is a fixed width, and column 3 fills the rest of the space.

 

Probably will need to set a minimum and maximum width of column 0 and limit the amount of character in the title field. (Unless there is a better way?)

 

Either way, any hints as to how I can get CopyFitLine with no breaks working with this?

 

Thanks!

Link to comment
Share on other sites

I copied and pasted your rule verbatim into the Frodo Travel Tutorial job, and changed Field("Title") to Field("Destination") on the next-to-last line, and it seems to be working fine. (Note that it works the same way if you simply set the field value in the first column, without the first call to CopyfitLine, since you're already measured that text and sized the column to hold it.)

 

So exactly what data is causing the line to break for you, and in which column? A screenshot may be worth a thousand words here.

Link to comment
Share on other sites

Ah, never mind, I downloaded the job you attached, and I see what the problem is. Actually, there are two problems. First, you need to subtract the left and right margin amounts in the cell from the column width to get the total amount of space available to set the text. Second, you need to divide the result by 100, since the table API uses units in hundredths of points, while the CopyfitLine function uses points.

 

So the last few lines of the rule should be this:

myTable.Rows[0].Cells[0].Content = Field("Name");
var Column2EffectiveWidth = column2Width - myTable.Rows[0].Cells[2].Margins.Left - myTable.Rows[0].Cells[2].Margins.Right;
myTable.Rows[0].Cells[2].Content = CopyfitLine("", Field("Title"), "Helvetica", 10, Column2EffectiveWidth / 100, 2, true);
return myTable.MakeTags();

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