Jump to content

Copyfit Question


ReminderVDP

Recommended Posts

I'm trying to see if there is a way to write a Javascript rule for this issue. We have variable letters for every customer that come in all different lengths. We'd like the people who only have one paragraph to expand in point size from 9.5 to 12 in the letter. In the User Guide it says that you have to check Expand to Fill in the text Overflow control to make this happen. However, that expands every letter to fill the space. Is there a way to expand the letters only with one paragraph?
Link to comment
Share on other sites

One thing I thought of is if a rule could be created based on the character limit in the letter. We currently allow 1800 characters. So, I'd say if there was a way to tell the letter to increase in point size for any letters under 1000 characters, that would be ideal and cover any short letters.
Link to comment
Share on other sites

What exactly do you mean by "one paragraph?" In other words, what does the data look like? How are paragraphs delimited? Are there <p> tags embedded in the data, or <br> tags, or simply newline characters? I need to know exactly what's in the data in order to suggest something. Can you post a sample?

 

If you want to do something based on the number of characters, that's pretty simple. Something like this:

if (Len(Field("YourFieldName")) < 1000)
    return '<z newsize=12>' + Field("YourFieldName");
//else
 return Field("YourFieldName");

Link to comment
Share on other sites

I've never had reliable results when dealing with rules based on character limits, but to answer your 2nd post, you could create tagged text in a rule like this:

var letter = Field("LETTER-TEXT");
var result = (letter.length > 1000) ? '<z newsize="12">'  : '<z newsize="9.5">';
result += letter;
return result;

 

Alternatively (and depending on how your data indicates paragraphs), you could test your letter value to see if the paragraph break is present. If it isn't, then you add in similar logic to increase the point size. As an example, if your data returns a double return between two paragraphs, you could do something like:

var letter = Field("LETTER-TEXT");
var result = (letter.search(/\r\r/ == -1) ? '<z newsize="12">'  : '<z newsize="9.5">';
result += letter;
return result;

Link to comment
Share on other sites

The current rule is a lookup for a .txt file with the rule below. How would the character length check fit into this rule?

 

// Return tagged text file with embeded resource

 

 

var Var1 = "LetterFileName";

var Var2 = ".txt";

var Var3 = "";

var Var4 = "NoLetterAvailable.txt";

 

 

 

temp = '';

var_extension = '';

has_extension = '';

 

if (Var3 == "")

Var3 = Var3;

else

{

if (FusionPro.isMac)

Var3 = Var3 + ":";

else

Var3 = Var3 + "\\";

}

 

for (i=0; i<Field(Var1).length; i++)

{

temp = Mid(Field(Var1), Field(Var1).length-i,1);

var_extension = temp + var_extension;

 

if(var_extension == ".txt")

{

has_extension = "true";

i=Field(Var1).length;

}

else

has_extension = "false";

}

 

if(has_extension == "true")

LetterText = CreateResource(Var3 + Field(Var1), "Plain text file", true);

 

else

{

if(Var2 == ".txt")

{

Pic = CreateResource(Var3 + Field(Var1) + ".jpeg", "graphic", true);

if (Pic.exists)

Pic = Pic;

else

Pic = CreateResource(Var3 + Field(Var1) + ".jpg", "graphic", true);

}

 

 

if(Var2 == ".tif")

{

Pic = CreateResource(Var3 + Field(Var1) + ".tif", "graphic", true);

if (Pic.exists)

Pic = Pic;

else

Pic = CreateResource(Var3 + Field(Var1) + ".tiff", "graphic", true);

}

 

 

if(Var2 == ".png" || Var2 == ".pdf" || Var2 == ".eps" || Var2 == ".gif")

{

Pic = CreateResource(Var3 + Field(Var1) + Var2, "graphic", true);

}

 

}

 

if (LetterText.exists)

{

return LetterText;

}

 

else

{

return CreateResource(Var3 + Var4, "graphic", true);

}

Link to comment
Share on other sites

  • 2 weeks later...

Well, like I said, it's hard to analyze your rule in a vacuum, without the rest of the job. At a minimum, I'd have to see what the data file looks like.

 

Also, there's a lot of completely unnecessary code in that rule. For instance, all the code in blocks gated with if(Var2 == ".tif") and the like is never going to be hit, since you've hard-coded Var2 = ".txt"; right at the top. So I would clean up the code first before trying to add more logic to it. But I don't know for sure what all can be cleaned up without having some data, so that I can try running the rule myself.

 

And, if I could see the whole job and the data, I (or someone else) might be able to figure out a better approach, which doesn't rely on some fuzzy logic to guess how much space something might take up based purely on the number of characters, which, as Eric rightly points out, isn't very reliable.

 

Now, having said all of that, I'm not sure that you need to try to fit the logic to change the point size into the existing rule at all. You can just take the result of the first rule and use that in a new rule. For instance, if the name of the existing rule that you posted is "Letter Rule", then you can create a second rule to call that, like so:

var MyLetterText = Rule("Letter Rule");
if (Len(MyLetterText) < 1000)
   return '<z newsize=12>' + MyLetterText;
//else
return MyLetterText;

Then you can call out the name of this rule in your text frame instead of the name of the first rule.

Edited by Dan Korn
simpler function
Link to comment
Share on other sites

That works a lot better Dan than trying to fit it in the rule. It does make the text larger but instead of calling in the actual letter text from the rule "Letter Rule," it place the name of the letter at 12 points. Any insight to why "Letter Rule" looks up the text file and displays it in the layout and this rule just enlarges the name of the text file instead of actually bringing in the text? I've attached screen shots of the two. I'm using your code but changed the names to match my rules.

LetterRule.jpg.5a74355ef069a74c79f62cb31fda7f55.jpg

MyLetterText.jpg.6e0c7b0b9737947655b9a1f0fa4b913f.jpg

Link to comment
Share on other sites

That works a lot better Dan than trying to fit it in the rule. It does make the text larger but instead of calling in the actual letter text from the rule "Letter Rule," it place the name of the letter at 12 points. Any insight to why "Letter Rule" looks up the text file and displays it in the layout and this rule just enlarges the name of the text file instead of actually bringing in the text? I've attached screen shots of the two. I'm using your code but changed the names to match my rules.

Either change the line near the end of the first rule to call the "content" property of the resource, like so:

return LetterText.content;

Or change the first line of the second rule to access the property, like so:

var MyLetterText = Rule("Letter Rule").content;

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