Jump to content

Centering text in variable width text frame


JeremyT

Recommended Posts

I am trying to adjust where the address is centered under a logo.

 

The problem is that if either line of text is wider than the logo then I'd like to have the widest line start at the same x coordinate as the logo (left justified under logo). Then the shortest line would be centered under the widest line.

 

I've attached a pdf of 3 examples. The top example shows what address block looks like centered under logo-all the text is narrower than logo.

 

Middle example shows what I'd like to happen if the street address line is the longest.

 

Bottom example shows what I'd like to happen if the city, state zip line is the longest.

 

 

Is the best route to adjust this add a center tab and then adjust tab position based on text line width?

 

Or, can I adjust the width of the text frame based on longest line of text?

 

Thanks,

Jeremy

Jeremys Copy Shop.pdf

Link to comment
Share on other sites

If you're composing this job using FPServer, you can adjust the text frame width based on the largest line. However, you'd be able to mimic that functionality by using a 1 column, 2 row table. In the example below, you set the 'width' variable to the width of your logo. If neither line exceeds that width then the table will be the same width as the logo and the text will be centered inside it. If either line is longer, the table's width will be set to match that of the longest line and the text will be centered inside. Since the table itself is left aligned, a line of text that is centered within a table of the same width will also appear to be left-aligned while the shorter lines appear centered.

var address = '223 Blue Green Yellow Red Pkwy';
var csz = 'Anytown, USA 12345';
var width = 7200; // Width of logo. 7200 = 1"

function getTextWidth(input){
   var tm = new FusionProTextMeasure;
   tm.font = 'Helvetica'; // Your font
   tm.pointSize = '12 pt'; // Your font size
   tm.CalculateTextExtent(input);
   return tm.textWidth;
}

address = [address, csz];
for (var i in address)
   if ((w = getTextWidth(address[i])) > width)
       width = w;

var table = new FPTable();
table.AddColumn(width*1.001);
for (var i in address) {
   var row = table.AddRow();
   var cell = row.Cells[0];
   cell.Margins = {Top:10, Bottom:10, Right:0, Left:0};
   cell.HAlign = 'Center';
   row.SetContents(address[i]);
}

return table.MakeTags();

 

Make sure to define your font and font size within the 'getTextWidth' function and check "Treat returned strings as tagged text."

Link to comment
Share on other sites

Step,

 

Thanks again for your help.

 

I used the code you suggested and all works as needed on the Mac.

 

I switch to a Windows 8 machine to compose so that the Helvetica font will embed.

 

When I switch to Windows 8, I am having problems with Myriad Pro Italic font. I enter "MyriadPro-It" instead of "Helvetica" in the font measure function.

 

It's not working correctly-column width is wider than longest line of text. In my very brief experience with measuring text width that means that I don't have the correct name in the code.

 

I copied the font name from fonts.ini but that doesn't help either.

 

How do I find the correct name for Myriad Pro Italic so that it composes correctly?

 

Thanks,

Jeremy

 

Thanks,

Jeremy

Link to comment
Share on other sites

I copied the font name from fonts.ini but that doesn't help either.

And that name was what exactly?

How do I find the correct name for Myriad Pro Italic so that it composes correctly?

The way to figure out what name FusionPro uses for a font is to create a Formatted Text Resource, set some text in that font, then use the View Source button to see the tags that are generated.

 

Usually, the font name for the <f name="***"> tag is the same font name displayed in the fonts drop-down list in the Text Editor.

 

But remember that fonts work a bit differently on Windows and Mac. On Windows, the names in that font drop-down are really font family names, and the way to get different styles (faces) of a font family is to use the B and I buttons in the Text Editor (or <b> and <i> markup tags) for bold and italic. The FusionProTextMeasure object also has bold and italic properties to specify the styles of the specified font family.

 

So, on Windows, you probably need to specify "Myriad Pro" as the font family name, and then set the italic property to true, like so:

   tm.font = 'Myriad Pro'; // Your font FAMILY
   tm.italic = true; // Italic style/face

Edited by Dan Korn
Link to comment
Share on other sites

And that name was what exactly?

Myriad Pro-It

 

So, on Windows, you probably need to specify "Myriad Pro" as the font family name, and then set the italic property to true, like so:

   tm.font = 'Myriad Pro'; // Your font FAMILY
   tm.italic = true; // Italic style/face

 

This is exactly what I needed!

 

Thanks!

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