LesSjo Posted December 13, 2011 Share Posted December 13, 2011 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 Quote Link to comment Share on other sites More sharing options...
step Posted December 13, 2011 Share Posted December 13, 2011 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 Quote Link to comment Share on other sites More sharing options...
alisha Posted June 23, 2016 Share Posted June 23, 2016 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. Quote Link to comment Share on other sites More sharing options...
Leosmith Posted June 23, 2016 Share Posted June 23, 2016 Check box in rules editor "Treat returned strings as tagged text" Step - thanks for this and the many other well commented posts. Leo Quote Link to comment Share on other sites More sharing options...
David Miller Posted June 23, 2016 Share Posted June 23, 2016 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". Quote Link to comment Share on other sites More sharing options...
tou Posted June 24, 2016 Share Posted June 24, 2016 Very nice.....hopefully there's other text box beautifying tricks on later versions of FP.highlight name trick-output.pdf Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.