Jump to content

Word Wrap In Text Frame


ksulliv1

Recommended Posts

Hi, is there a way to set the maximum number of characters allowed to be entered in either a text frame per line, or in a single variable within a text frame?

 

So first if I have a text frame that is 1" wide and want to keep the text entered on each line from flowing past 1" to create a second line below it, or running out of view past the edge of the frame, is it possible?

 

And second is there a way to highlight one of the variables in the editor and set a maximum number of characters for just that variable? I see there is a "Text Wrap" setting on the text frame window, but that is just for wrapping text around a graphic or frame. And I don't see anything in the variable text editor window that will do this, nor do I see any setting for this in the Web DataCollect window for defining a HTML form. I'm sure there has to be a way to do something as simple as this, but I can't seem to find it.

 

Thanks,

Link to comment
Share on other sites

So first if I have a text frame that is 1" wide and want to keep the text entered on each line from flowing past 1" to create a second line below it, or running out of view past the edge of the frame, is it possible?

 

And second is there a way to highlight one of the variables in the editor and set a maximum number of characters for just that variable? I see there is a "Text Wrap" setting on the text frame window, but that is just for wrapping text around a graphic or frame. And I don't see anything in the variable text editor window that will do this, nor do I see any setting for this in the Web DataCollect window for defining a HTML form. I'm sure there has to be a way to do something as simple as this, but I can't seem to find it.,

In both cases, you would create a rule and return your variable or line via the rule rather than the field itself in the text editor.

 

For a line you might have a text rule that says:

var result = Field("One") + " " + Field("Two") + " " + Field("Three");
var maxChars = 64; //changes based on width of frame and point size of type
result = Left(Result,maxChars);
return result;

For the 2nd scenario, you would just change "result" to equal the specific field you want to truncate.

Link to comment
Share on other sites

Thanks esmith for the response, I guess I wasn't thinking it would take writing a custom JS rule to achieve this. So if my Variable Text Editor window looks like this:

 

«NameColorRule»

«Title1»

«Title2»

«ColorChangeRule1»«Change PhoneFormatRule1»

«ColorChangeRule2»«ChangePhoneFormatRule2»

«Email»

 

and I wanted all six lines to be truncated to 40 characters how should the code look?

Or if I just wanted lets say "Title2" to be 40 characters how should the code look?

Sorry but I just am not yet understanding what you mean by Fields ("One") ("Two") and ("Three"). Does each one represent the name of a variable placed together on a single line? Or does it mean everything on lines 1-3 vertically? And what part does the + " " + command have.

And also when you say for the 2nd scenario change "result" to equal a specific field wanted to change, is "field" the same as "variable" (anything in the VTE that has <<>> around it? And "result" appears three different times in the code, so I am not sure which one needs to change. I am assuming the last one.

And lastly once I have the rule created how do I use it, do I just "Insert" it over the top of what is already shown in the VTE window. And in the case where there are more than one variable on a line, would I highlight all of them at once and then insert the rule?

Sorry for this but I am very new to all of this yet and desperately wanting to learn. And would have thought something like setting maximum characters on a line would have been an easy setting within the application interface somewhere.

Thanks,

Link to comment
Share on other sites

«NameColorRule»

«Title1»

«Title2»

«ColorChangeRule1»«Change PhoneFormatRule1»

«ColorChangeRule2»«ChangePhoneFormatRule2»

«Email»

 

and I wanted (1) all six lines to be truncated to 40 characters how should the code look?

 

Or if I just wanted lets say (2) "Title2" to be 40 characters how should the code look?

Rule for option (1):

For lines with only one variable element, you would set a rule similar to option 2 below. If the variable element is a rule itself, just edit the return line of your custom rule to return just the leftmost 40 characters.

 

For a situation like lines 4 and 5 in the example, assuming the existing rules are using tagging, You would need to combine the two rules per line into a single rule and truncate the contents of your field(s) prior to adding tagging, then return the "combined, truncated, and tagged" copy. That may sound complicated on pixels, but it's almost as easy as ordering hashbrowns as Waffle House, "scattered, smothered and covered". :D

Rule for option (2):

return Left(Field("Title2"),40);

There are more efficient ways to yield the same results, but this is a fairly easy way of handling the problem without totally reworking what you've already done based on your example above.

Link to comment
Share on other sites

Ok thanks, so for the lines like "Title2" that are just a single variable, and that variable is not a rule, I would just create a new rule like "TruncateTitle2Rule" using the code as you wrote it

 

return Left(Field("Title2"),40);

 

and simply insert it over the current "Title2" variable.

 

But in the example of the first line "NameColorRule" which is still a single variable but it is a rule, and the rule says:

 

if (Field("Color").indexOf(String("Blue")) > -1)

{

return "<span>" + '<color name="PANTONE 2905 C">' + Field("Name") + "</span>";

}

if (Field("Color").indexOf(String("Brown")) > -1)

{

return "<span>" + '<color name="PANTONE 4625 C">' + Field("Name") + "</span>";

}

if (Field("Color").indexOf(String("Green")) > -1)

{

return "<span>" + '<color name="PANTONE 390 C">' + Field("Name") + "</span>";

}

return "";

 

 

then I would need to add: ,40) after each instance of: Field("Name")? so it would look like this:

 

return "<span>" + '<color name="PANTONE 390 C">' + Field("Name"),40) + "</span>";

 

 

And for the lines that are more than one variable and they are also rules, I am in way over my head on, so I think I am going to let them alone.

 

Thanks,

Link to comment
Share on other sites

Ok thanks, so for the lines like "Title2" that are just a single variable, and that variable is not a rule, I would just create a new rule like "TruncateTitle2Rule" using the code as you wrote it

 

return Left(Field("Title2"),40);

 

and simply insert it over the current "Title2" variable.

 

Ok, the answer to this is yes that works.

 

But in the example of the first line "NameColorRule" which is still a single variable but it is a rule, and the rule says:

 

if (Field("Color").indexOf(String("Blue")) > -1)

{

return "<span>" + '<color name="PANTONE 2905 C">' + Field("Name") + "</span>";

}

if (Field("Color").indexOf(String("Brown")) > -1)

{

return "<span>" + '<color name="PANTONE 4625 C">' + Field("Name") + "</span>";

}

if (Field("Color").indexOf(String("Green")) > -1)

{

return "<span>" + '<color name="PANTONE 390 C">' + Field("Name") + "</span>";

}

return "";

 

 

then I would need to add: ,40) after each instance of: Field("Name")? so it would look like this:

 

return "<span>" + '<color name="PANTONE 390 C">' + Field("Name"),40) + "</span>";

 

 

The answer to this I fugured out is no, my code was a little off, I missed the Left( in front of Field("Name"), and I removed the spans that the wizard adds. So this is how the strings in that code should look for each color:

 

return '<color name="PANTONE 390 C">' + Left(Field("Name"),40);

 

As for the multiple variables on one line, I still am not sure.

Link to comment
Share on other sites

for the multiple variables on one line, I still am not sure.

You would need to combine the two rules into one and truncate the results (minus any tagging). If you post your rules as they exist now for ColorChangeRule1 and Change PhoneFormatRule1, perhaps we can offer a working solution. :cool:

Link to comment
Share on other sites

You would need to combine the two rules into one and truncate the results (minus any tagging). If you post your rules as they exist now for ColorChangeRule1 and Change PhoneFormatRule1, perhaps we can offer a working solution. :cool:

 

Ok thanks I would like to see how this is done. I am sure for this template it isn't really necessary for these rules because they are for phone numbers, and I know they won't exceed the limit anyway. But again if you are willing to do it, I would really like to see how it is done for future templates. However the ChangePhoneFormatRule1 is one of the pre-written options taken right out of the first window of the rule wizard, and now that I have converted it to JS it is freeking huge, so let's not use it for this example. I will supply another rule being used in the template for that line along with the ColorChangeRule1.

 

The first rule is PhoneLabel1Rule and looks like this:

 

if (Left(Field("Type1"),Len(String("O"))) == String("O"))

{

return "<span>" + String("o. ") + "</span>";

}

if (Left(Field("Type1"),Len(String("C"))) == String("C"))

{

return "<span>" + String("c. ") + "</span>";

}

if (Left(Field("Type1"),Len(String("F"))) == String("F"))

{

return "<span>" + String("f. ") + "</span>";

}

if (Field("Type1") == String("N"))

{

return "<span>" + String("") + "</span>";

}

return "";

 

 

And the ColorChangeRule1 looks like this:

 

 

if (Field("Color").indexOf(String("Blue")) > -1)

{

return "<span>" + '<color name="PANTONE 2905 C">' + Rule("PhoneLabel1Rule") + "</span>";

}

if (Field("Color").indexOf(String("Brown")) > -1)

{

return "<span>" + '<color name="PANTONE 4625 C">' + Rule("PhoneLabel1Rule") + "</span>";

}

if (Field("Color").indexOf(String("Green")) > -1)

{

return "<span>" + '<color name="PANTONE 390 C">' + Rule("PhoneLabel1Rule") + "</span>";

}

return "";

 

 

So the first rule returns an initial before the phone number provided by the user according to a selection they make in a drop down list. And the second one changes the color of the initial according to a selection the user makes in another drop down list. Then I drop the one on top of the other in the variable text editor window. I'm sure this isn't the best way to accomplish this, but for now I am using the helps provided in the app as much as possible because I have no JS training.

Link to comment
Share on other sites

Well, reviewing your two rules, it would seem that all they do is return a letter followed by a period and space tagged in a specific color. As a result, it's kind of hard to incorporate these two rules into an example that also uses the "Left()" code. My fix was to add some static text as a separate variable in my rule, but it may not apply in your final solution depending on what you plan to have follow the tagged characters on each line.

 

I also condensed your code to make it a bit more clean and concise.

switch (Left(Field("Type1"), 1)) {
case "O": 
       var PhoneLabel = "o. ";
       break;
case "C": 
       var PhoneLabel = "c. ";
       break;
   case "F": 
       var PhoneLabel = "f. ";
       break;
default: var PhoneLabel = "";
}

if (Field("Color")) {
   var PrefixColor = "<color name=\"";
   switch (Field("Color")) {
       case "Blue": 
           PrefixColor += "PANTONE 2905 C";
           break;
       case "Brown": 
           PrefixColor += "PANTONE 4625 C";
           break;
       case "Green": 
           PrefixColor += "PANTONE 390 C";
           break;
       default: PrefixColor += "";
   }
   PrefixColor += "\">" + PhoneLabel + "</color>";
} else var PrefixColor = PhoneLabel;

// next two lines are for example only to add characters to result to apply truncating
var fillerText = "This is the text that follows the result of the combined switch statements to produce a prefix of a custom color.";
var myText = PrefixColor + Left(fillerText, 37);

return myText;

If you replace

// next two lines are for example only to add characters to result to apply truncating
var fillerText = "This is the text that follows the result of the combined switch statements to produce a prefix of a custom color.";
var myText = PrefixColor + Left(fillerText, 37);

return myText;

with

return PrefixColor;

this rule would return the same result as your two rules above. Of course you would then be bypassing the added option of truncating your results that we were talking about in the first place! :cool:

Link to comment
Share on other sites

It seems to me that you might want to use the CopyfitLine function to make the text fit into a specific amount of horizontal space, rather than using fuzzy logic and guesswork to approximate the number of characters that will fill the space. Some characters are going to take up a lot more space than others, so sometimes cutting it off to 40 characters is going to leave a lot of extra space, while other times it may still break the line. For instance, unless you're using a monospaced font, forty capital "M"s are going to take up a lot more space than forty capital "I"s.

 

So, if you already have a rule working right that's returning what you want on a given line, just use the result of that rule in another rule which calls CopyfitLine on it. For instance:

return CopyfitLine("", Rule("ChangePhoneFormatRule1"), "Arial", 10, 72, 0, 0);

Replacing the third and fourth parameters ("Arial", 10) with the desired font and point size. Note that you don't need to include the color-changing rule in here; the color has no effect on the amount of space that the text takes up.

Link to comment
Share on other sites

Another thing you can do, without writing any JavaScript at all, is to use the "Do not break on copyfit" setting. Follow these steps:

 

  • Open up the Text Editor for the text frame (double-click on the frame).
  • Select all the text (Ctrl-A on Windows, Cmd-A on Mac).
  • Click "Paragraph..."
  • Check the "Do not break on copyfit" box.
  • Click "OK" twice.
  • With the text frame still selected, on the Text Frame Properties palette, click "Overflow..."
  • Click the "Adjust text to fit" radio button and then "OK".

Now when you compose or preview, you will see that all of the text in the frame is shrunk down as necessary to fit the longest line. No JavaScript, no rules, just a few clicks!

 

I'll try to answer some of your other questions:

I see there is a "Text Wrap" setting on the text frame window, but that is just for wrapping text around a graphic or frame.

Right. That setting doesn't affect the text in the selected frame. Rather, it affects text in other text frames at a lower level which intersect the selected frame. You might think of this as "Runaround" ("Item" or "None") if you're used to QuarkXPress terminology.

And I don't see anything in the variable text editor window that will do this

No, but the aforementioned "Do not break on copyfit" setting in the Paragraph Formatting dialog will do something pretty close to what you want. There are only so many complex options that can be crammed into the Text Editor GUI before it becomes way too confusing on its own. Our general philosophy behind FusionPro Desktop is to make basic settings easy and WYSIWYG, and to leave more complex settings, especially where a GUI would be limiting, to scripting. That said, we are always open to new feature and usability suggestions, and posts to this forum are considered as such.

nor do I see any setting for this in the Web DataCollect window for defining a HTML form.

Well, this specific setting is not found on the Web DataCollect dialog, but you can certainly add some client-side JavaScript code to the XSL stylesheet used for the conversion of the generated XML to HTML to preform such range validation on the web form. (You can validate the number of characters by matching a regular expression such as "^.{0,40}$".) That's a bit beyond the scope of this forum, however. Besides, I'll reiterate that you want to limit the text not by the number of raw characters, but by the actual space it takes up when typeset in the FusionPro output, and that can't be predetermined by a web form.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...