Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 21st, 2015, 09:37 AM
JeremyT JeremyT is offline
Regular Contributor
 
Join Date: Apr 2013
Location: Middleton, WI
Posts: 86
Default Centering text in variable width text frame

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
Attached Files
File Type: pdf Jeremys Copy Shop.pdf (14.7 KB, 18 views)
__________________
Jeremy
Acrobat Pro DC 2017
FusionPro VDP Creator 10.0.16
Mac OS X 10.11.6
Reply With Quote
  #2  
Old December 21st, 2015, 10:15 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 957
Default Re: Centering text in variable width text frame

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.
Code:
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."
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old December 23rd, 2015, 10:28 AM
JeremyT JeremyT is offline
Regular Contributor
 
Join Date: Apr 2013
Location: Middleton, WI
Posts: 86
Default Re: Centering text in variable width text frame

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
__________________
Jeremy
Acrobat Pro DC 2017
FusionPro VDP Creator 10.0.16
Mac OS X 10.11.6
Reply With Quote
  #4  
Old December 23rd, 2015, 11:09 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,694
Default Re: Centering text in variable width text frame

Quote:
Originally Posted by JeremyT View Post
I copied the font name from fonts.ini but that doesn't help either.
And that name was what exactly?
Quote:
Originally Posted by JeremyT View Post
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:
Code:
    tm.font = 'Myriad Pro'; // Your font FAMILY
    tm.italic = true; // Italic style/face
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; December 23rd, 2015 at 11:18 AM..
Reply With Quote
  #5  
Old December 23rd, 2015, 03:18 PM
JeremyT JeremyT is offline
Regular Contributor
 
Join Date: Apr 2013
Location: Middleton, WI
Posts: 86
Default Re: Centering text in variable width text frame

Quote:
Originally Posted by Dan Korn View Post
And that name was what exactly?
Myriad Pro-It

Quote:
Originally Posted by Dan Korn View Post
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:
Code:
    tm.font = 'Myriad Pro'; // Your font FAMILY
    tm.italic = true; // Italic style/face
This is exactly what I needed!

Thanks!
__________________
Jeremy
Acrobat Pro DC 2017
FusionPro VDP Creator 10.0.16
Mac OS X 10.11.6
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:53 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.