Jump to content

Use TextMeasure to adjust font size


scotts

Recommended Posts

I could use some help on a project. I think I should be able to use TextMeasure to make this happen, but it will be the first time to use it, and I'm stuck. I'm sure I'm overthinking it.

 

And I'm just stuck, and don't know where/how to begin.

 

The field that this will be coming in as, will be a text field that will have different lengths of data, and I would like to be able to adjust the text font size, when it composes to match the attached graphic sample.

 

So it will have to make adjustments twice to the data. But I've been beating my head against the wall and looking on the forum and can't find anything that will at least get me started. I'm just looking for a nudge.

Text_Sample.png.4738c5d118dc0871d25b2c803e2c9dff.png

Link to comment
Share on other sites

There's not much to go on just from that picture, but I don't see why regular copyfitting won't work. Just check the Overflow button on the Text Frame palette, then click "Adjust text to fit." You can tweak the settings in the OnCopyfit rule as needed. Please refer to the User Guide and the Rules Guide for more information.
Link to comment
Share on other sites

Dan, sorry but that will not work for this, because each set of lines need to be a different font size, and that last bit of text is a different font. And this is all created from a single text field. I needed to break apart the text so that the first part would be a larger font, and the second couple of lines a bit smaller, and the rest a different font and size.

 

But what I finally did, since I was making for DigitalStorefront, was to make that one field into three, and then three different text frames.

 

Not as nice as I wanted, but does work. I will still have to play around with it, because now I want to figure it out.

 

I was thinking of still having one field, but with three text frames, and then a rule to select the first 18 characters of the field for the first frame, and then the next 55 characters starting at character 19 for the second frame, and then rest in the last frame. But when I was working on it, I just couldn't get it to work.

 

//First frame
return Field("Desc3").replace(/(.){18}(.){55}(.)*/, "$1")";

//Second frame
return Field("Desc3").replace(/(.){18}(.){55}(.)*/, "$2")";

//Third frame
return Field("Desc3").replace(/(.){18}(.){55}(.)*/, "$3")";

Link to comment
Share on other sites

Dan, sorry but that will not work for this, because each set of lines need to be a different font size, and that last bit of text is a different font. And this is all created from a single text field. I needed to break apart the text so that the first part would be a larger font, and the second couple of lines a bit smaller, and the rest a different font and size.

I think that it will work, and that you're misunderstanding what full-flow copyfitting does. It doesn't simply make all of the text in the flow the same size (unless it's all the same size to begin with). It applies a magnification factor to all of the text. So if you have, say, some text in 20 points and some other text in 10 points, and if you copyfit it, let's say it gets shrunk (magnified) by 70 percent, so you end up with some text at 14 points and the rest in 7 points. The upshot is that all the text should shrink (or grow) by the same factor, even if it's not all the same size.

 

See the attached sample that demonstrates this.

 

Now, there are some numbers in the MagnifyAttributes object in the OnCopyfit rule that control both the minimum and maximum percentage for scaling the text, and the absolute minimum and maximum point sizes, and depending on the original size of your text, and those numbers in the rule, you can end up with text scaling disproportionately. But those numbers can be tweaked to get what you want.

 

Also, there's a different kind of per-line copyfitting that sometimes gets used, with the CopyfitLine function, which usually does end up putting all the text on the line into the same point size. But that's not the kind of full-flow copyfitting I'm talking about.

 

If you could post the template, it shouldn't be too hard to get copyfitting working.

But what I finally did, since I was making for DigitalStorefront, was to make that one field into three, and then three different text frames.

 

Not as nice as I wanted, but does work. I will still have to play around with it, because now I want to figure it out.

Okay, but I still think regular copyfitting would work too.

 

I was thinking of still having one field, but with three text frames, and then a rule to select the first 18 characters of the field for the first frame, and then the next 55 characters starting at character 19 for the second frame, and then rest in the last frame. But when I was working on it, I just couldn't get it to work.

 

//First frame
return Field("Desc3").replace(/(.){18}(.){55}(.)*/, "$1")";

//Second frame
return Field("Desc3").replace(/(.){18}(.){55}(.)*/, "$2")";

//Third frame
return Field("Desc3").replace(/(.){18}(.){55}(.)*/, "$3")";

Okay. I don't know how to analyze that code without the context of the entire template and the data file. If you can post the collected template, then I, or someone else, might be able to offer more specific suggestions.

copyfitting-example.pdf

Edited by Dan Korn
Added sample template showing copyfitting with different point sizes.
Link to comment
Share on other sites

Here is a your sample file modified to try and show what I'm trying to accomplish. It includes the PDF and a TXT file.

 

I hope this helps to understand my cause.

Okay, I think I see what you're trying to do know.

 

This was very confusing initially, as all three rules were returning the same string. That's because you seem to have set the job to use comma-delimited data, so all that FusionPro read in from that Description field was "Nullam Feugiat nulla sit amet velit rutrum" before the first comma. I changed the data source to use tab as the delimiter instead, and now I get the full string as the field value. Although I just get a single character back from each rule. (There may be a subtle difference in how the JavaScript engine processes the regular expression in FusionPro 10.0 than in FusionPro 8.2.) But those rules need to be rewritten anyway. Also, I don't have all of your fonts; an example with just Arial would be better.

 

Anyway, I think what you're trying to do is figure out where the line breaks are in the text as its being typeset, and be able to change the point size at the start of a new line. A better title for this thread may have been something that explains that a bit more specifically, like "Change point size when line breaks," rather than just a general question about using TextMeasure to adjust the font size.

 

This is a very unusual requirement, which won't be easy to meet, but I don't think it's impossible either. The basic idea of figuring out where the line breaks are isn't too tough. You just need to keep adding on a word at a time from the text, measuring it, and then stopping when it gets to be more than one line, so that you know where the line break is. Then you can just break the text there, set the point size you want for the next line, and repeat, until you either get to the end of the text or you no longer need to change the size.

 

Where this gets tricky is in two places. One, if you need hyphenation, it's hard to discern exactly where FusionPro wants to break a word. Two, you need to do all that measuring in an outer loop than measures the entire result for the whole frame, so that everything fits.

 

Unfortunately, this is all a little more than I have the time to do for you basically for free here on the forum. Someone else is free to jump in, of course. But you may need to inquire about some paid template building work.

Link to comment
Share on other sites

Dan, thanks for the guidance. But this is what I wanted to do. I am not looking for line endings, but character counts of possible lines to make it work. And with some of your hints I found the answer I was looking for. My code was a bit off. I used BBEdit a lot and the Grep searching which is very close to Javascript, but in this case it wasn't. You will see what I did to make it work below.

 

Pretty sweet (showing my age).

 

Thanks again Mr. Korn

 

//Before return Field("Desc3").replace(/(.){18}(.){55}(.)*/, "$1")";

//Before return Field("Desc3").replace(/(.{18})(.{55})(.*)/, "$1");

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