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

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 21st, 2009, 09:55 AM
pmorgan pmorgan is offline
IW IT Tech Specialist
 
Join Date: Nov 2008
Location: Chicago, IL
Posts: 9
Default Copyfit multiple frames with the same factor

Good Afternoon,

I'm posting a fresh thread that evolved out of my previous thread entitled,
"Copyfit with connected frames work, but vertical alignment is off"

I understand the logic of how copyfit could be customized to force multiple frames to copyfit using the same scaling factor, however, I'm at a loss as to how to code this.

The logic is entered below. Could anyone provide sample code to get me started?

In this scenario, my template has many frames, and 3 of them are labeled
Frame1, Frame2, and Frame3. Any combination of these may appear (via page usage settings).

These named frames, when present, need to have their copyfit based on copyfitting the frame with the largest text width.

Logic:

--------------------------------------
Factor = 0


If Frame1's text width exists

Factor = Frame1 text width;


If Frame2's text width exists
{

If Frame2's text wdith > Factor
Factor = Frame2's text width;
}

If Frame3's text width exists
{
If Frame3's text width > Factor
Factor = Frame3's text width;
}


If the current Frame is Frame1, Frame2, or Frame3
copyfit using Factor

Else
Copyfit using the regular method

------------------------------
Attached Files
File Type: zip Sample Project.zip (573.2 KB, 22 views)
__________________
Thank You,

Parrish Morgan / Technical Specialist / InnerWorkings

FusionPro Designer 6.0P1f / Adobe Acrobat 7.0 / Windows XP Version 2002 Service Pack 2

Last edited by pmorgan; July 22nd, 2009 at 07:19 AM.. Reason: adding sample project attachment.
Reply With Quote
  #2  
Old July 24th, 2009, 02:38 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,305
Default Re: Copyfit multiple frames with the same factor

Okay, I've decided to take up the challenge here on a Friday afternoon. Attached is a modified version of the template which Parrish uploaded in the original post. I think this solves the stated problem. Basically, as I suggested in the other thread, it uses the FusionProTextMeasure object to determine what magnification factor each frame needs, and then applies the smaller of those two factors to the text in both frames.

A few caveats about this solution:
  1. This takes advantage of some of the new features in FusionPro 6.0, so you'll need that version or later.
  2. Since this uses the FusionProTextMeasure object, it only works in simple rectangular single-frame text flows with no other frames to wrap text around. It doesn't have the ability that full-flow Copyfitting does to take into account things like multi-frame flows and text wrapping.
  3. The Text Measurement logic relies on the text returned by the rules specifying the initial font and point size, rather than that being set in the Text Editor. (Although theoretically a solution which takes the GUI settings into account should be possible by using the FusionProTextFrame.content property, but that's an exercise for another day.)
  4. I've removed all the <f> tags which reference variations of the "Berthold" font and just left everything in Arial, so that I (and anyone else who doesn't have those non-standard fonts installed) can see this working. (Parrish, you can feel free to put those calls to fonts you're using back in; I just couldn't test with fonts I don't have.)
  5. It's not exactly fast. Composition isn't too bad, but rule validation takes a while. The MagnifyFactorForFrame function just uses a simple linear algorithm to find the closest integral (whole number) magnification factor; as the comment in the function notes, this could be greatly optimized by using a binary search algorithm instead. But that's also an exercise for a different day.
If you try this, you can turn on Preview, and you should see that as you change records or resize either of the two frames, the text in both will be adjusted proportionately, and the vertical alignment will still be honored in both. This solution should be scalable to three or more frames as well.

You'll want to download the attached template (and the input file from Parrish's original post) to see this in action, but what makes it go is some JavaScript logic, both in the JavaScript Globals and in OnRecordStart, which I'll include here.

Here's what's in the JavaScript Globals:
Code:
function GetSettableTextHeight(frame)
{
  if ((!frame instanceof FusionProFrame) || (typeof frame.columns == "undefined"))
    ThrowError("GetSettableTextWidth", "The parameter is not a valid FusionProTextFrame.");

  return frame.height - (frame.borderThickness * 2) - (frame.textInsetY * 2);
}
FusionProFrame.GetSettableTextHeight = function()
{
  return GetSettableTextHeight(this);
}

function MagnifyText(text, factor, isTagged, type)
{
  if (!isTagged)
    text = TaggedTextFromRaw(text);
  return "<magnify type=" + (type || "text") +
         " factor=" + factor + ">" + text + "</magnify>";
}

function MagnifyFactorForFrame(name, text, isTagged, type)
{
  var frame = FindTextFrame(name);
  var width = frame.GetSettableTextWidth();
  var height = frame.GetSettableTextHeight(); //frame.height;

  var tm = new FusionProTextMeasure;
  tm.maxWidth = width;

  // TODO: optimize to binary sort instead of linear
  for (var factor = 100; factor > 0; factor--)
  {
    tm.CalculateTextExtent(MagnifyText(text, factor, isTagged, type));
    if (tm.messages)
      ThrowError("MagnifyFactorForFrame", tm.messages);

    if (tm.textHeight < height)
      return factor;
  }
  
  return 0;
}
The FusionProFrame.GetSettableTextHeight function is very similar to the FusionProFrame.GetSettableTextWidth function in Builtins.js (not surprising since I wrote both). It takes any border and text inset on the frame into account.

The logic in MagnifyFactorForFrame is similar to CopyfitLine, but instead of trying to make a single line of text fit within a particular amount of horizontal space, it tries to make the multiple lines fit within a specific amount of both horizontal and vertical space.

And here's what's in OnRecordStart:
Code:
var text1 = Rule("Location1RULE");
var text2 = Rule("Location2RULE")

var factor1 = MagnifyFactorForFrame("Location1", text1, true);
var factor2 = MagnifyFactorForFrame("Location2", text2, true);

var factor = Math.min(factor1, factor2);
var newtext1 = MagnifyText(text1, factor, true);
var newtext2 = MagnifyText(text2, factor, true);

FusionPro.Composition.AddVariable("Location1New", newtext1, true);
FusionPro.Composition.AddVariable("Location2New", newtext2, true);
This is basically the implementation of the algorithm in Parrish's pseudocode. I'm using FusionPro.Composition.AddVariable function to "inject" the results into new variables which can ultimately be accessed in the text frames.

As I said earlier, I've modified the rules "Location1RULE" and "Location2RULE" to specify the point size and font (specifically Arial, since it's a standard font). And, of course, I've disconnected the two frames, named them, turned off full-flow Copyfitting, and changed their contents to reference the new variables being set up in OnRecordStart. (Again, this could be reworked to directly modify the text contents in the frame, but this is what I've got for now.) Enjoy!
Attached Files
File Type: pdf NewSample-Dan.pdf (118.8 KB, 40 views)
__________________
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; July 28th, 2010 at 01:35 PM.. Reason: textInsetX should be textInsetY
Reply With Quote
  #3  
Old July 24th, 2009, 02:43 PM
pmorgan pmorgan is offline
IW IT Tech Specialist
 
Join Date: Nov 2008
Location: Chicago, IL
Posts: 9
Default Re: Copyfit multiple frames with the same factor

Dan,

Thank you for taking a look at this one. It looks like I've got some good reading to do for the weekend and I'll try this out with our templates.
__________________
Thank You,

Parrish Morgan / Technical Specialist / InnerWorkings

FusionPro Designer 6.0P1f / Adobe Acrobat 7.0 / Windows XP Version 2002 Service Pack 2
Reply With Quote
Reply

Tags
copyfit, frame, frames

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 02:40 AM.


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