mstanton Posted December 22, 2010 Posted December 22, 2010 Hello, I have a situation where a rule returning a text resource is placed in a variable text field and it is not copyfitting the text in the resource. I have "Do not break on copyfit" selected for both the resource and the variable text field, and "Adjust text to fit" selected in the Overflow Options for the text field. The text continues to wrap to the next line. I have tried editing the default OnCopyfit settings and no matter what I do nothing changes; the text still wraps to the next line. I have tried the CopyfitLine function and I get an error that says "Function does not return a result". The Variable Text Field looks like: Location «Clinic-Address» Floor «FLOOR» Parking «PARKING» Registration «REGISTRATION» The Clinic-Address rule is: return Resource("LocationResource")The Resource "LocationResource" is: «LOCATION» «ADDRESS» The rule for the field ADDRESS is: var numberFont = "Folio Light"; var numberWidth = "11"; var numberHeight = "10.5"; var text = NormalizeEntities(Rule("AddressCopyfit")); return text.replace(/(\d+\s*)/g, function(d){return '<span font="' + numberFont + '"><z newsize="' + numberHeight + '"><setwidth newsize="' + numberWidth + '">' + d + '</span>';});The rule AddressCopyfit is: CopyfitLine("", Field("ADDRESS"), "Alright Sans Regular", 6, 330, 6, false);In this scenario what shows up in the variable text field instead of the address is the word "undefined". What am I doing wrong and how do I get the Address line to copyfit, i.e. shrink when necessary?
Dan Korn Posted December 22, 2010 Posted December 22, 2010 I have tried the CopyfitLine function and I get an error that says "Function does not return a result". ... The rule AddressCopyfit is: CopyfitLine("", Field("ADDRESS"), "Alright Sans Regular", 6, 330, 6, false);In this scenario what shows up in the variable text field instead of the address is the word "undefined". The error message that you get when you validate the rule is exactly right; it's trying to tell you that you're not actually returning anything. Try adding "return " (without quotes) to the beginning of that rule, before the call to the CopyfitLine function.
mstanton Posted December 22, 2010 Author Posted December 22, 2010 Thanks for the quick reply! I added return to the beginning of the rule and now the result I get is: <f name="Alright Sans Regular"><z newsize=6><z newsize=6>4855 West Arrowhead Road | Hermantown MN 55811-3936 The address is there, but so is some code, and still none of it has shrunk to fit on one line. It is the same whether I have "Treat returned strings as tagged text" checked or not.
Dan Korn Posted December 23, 2010 Posted December 23, 2010 I added return to the beginning of the rule and now the result I get is: <f name="Alright Sans Regular"><z newsize=6><z newsize=6>4855 West Arrowhead Road | Hermantown MN 55811-3936 The address is there, but so is some code, and still none of it has shrunk to fit on one line. When calling CopyfitLine, you need to set the sixth parameter (the minimum point size) to something smaller than the fourth parameter (the starting point size), otherwise it won't do anything. Try something like this: return CopyfitLine("", Field("ADDRESS"), "Alright Sans Regular", 6, 330, 4, false); Although less than six points is getting pretty small.
mstanton Posted December 28, 2010 Author Posted December 28, 2010 Ok, I have changed the AddressCopyfit rule to: return CopyfitLine("", Field("ADDRESS"), "Alright Sans Regular", 7, 330, 6, false); but it hasn't solved the problem I am now having where extra information shows up before the address:<f name="Alright Sans Regular"><z newsize=7><z newsize=7>
Dan Korn Posted January 5, 2011 Posted January 5, 2011 Ok, I have changed the AddressCopyfit rule to: return CopyfitLine("", Field("ADDRESS"), "Alright Sans Regular", 7, 330, 6, false);but it hasn't solved the problem I am now having where extra information shows up before the address:<f name="Alright Sans Regular"><z newsize=7><z newsize=7> I don't understand what you mean. Those tags are not "extra information," they're formatting commands needed to make the text appear correctly. Did you forget to check the "Treat returned strings as tagged text" box?
mstanton Posted January 5, 2011 Author Posted January 5, 2011 "Treat Returned Strings..." is checked for all the rules and still, in the preview, it shows the <f name="Alright Sans Regular"><z newsize=7><z newsize=7> before the address; and nothing has been resized. I've attached a screen shot of what I'm seeing - at least I've tried to.
Dan Korn Posted January 5, 2011 Posted January 5, 2011 "Treat Returned Strings..." is checked for all the rules and still, in the preview, it shows the <f name="Alright Sans Regular"><z newsize=7><z newsize=7> before the address; and nothing has been resized. I've attached a screen shot of what I'm seeing - at least I've tried to. Can you collect up your job, or at least a minimal example which demonstrates the problem, and post it?
mstanton Posted January 5, 2011 Author Posted January 5, 2011 Here is the collected zip fileAC-Example.zip
Dan Korn Posted January 11, 2011 Posted January 11, 2011 The problem is in the rule named "ADDRESS", on this line: var text = NormalizeEntities(Rule("AddressCopyfit")); You need to remove the call to NormalizeEntities here; it's taking the markup tags generated by the "AddressCopyfit" rule and turning them into entities which cause the markup to appear literally in the output. (The "Treat returned strings as tagged text" box only affects rules used directly in text frames, not rules referenced in other rules like this.)
mstanton Posted January 13, 2011 Author Posted January 13, 2011 Ok, that worked to hide the code. Thanks! But still nothing shrinks to fit.
mstanton Posted January 13, 2011 Author Posted January 13, 2011 Ah-ha! I discovered the fatal flaw. I unchecked "Treat returned strings..." in the rule Clinic-Address and everything works fine now.
Dan Korn Posted January 13, 2011 Posted January 13, 2011 Ok, that worked to hide the code. Thanks! But still nothing shrinks to fit. There's another problem in that ADDRESS rule, on the very last line where you're doing a String.replace. It's erroneously adding tags to the existing tags returned by the CopyfitLine function, which is messing things up. (You can see that it's putting something like "77" in front of the street number in the address.) Try changing that last line to simply: return text;And you'll see the copyfitting working. Now, how do we fix this to work with that other replace code? It looks like you're trying to change the font and point size of the numbers in the address, but this isn't the right way to do it. You need to take that different sizing of the numbers into account during the copyfitting, which needs to be the very last thing that happens before the text is put down. So we can change the order that things are happening in in the ADDRESS rule like so:var numberFont = "Folio Light"; var numberWidth = "11"; var numberHeight = "10.5"; var text = Field("ADDRESS"); text = text.replace(/(\d+\s*)/g, function(d){return '<span font="' + numberFont + '"><z newsize="' + numberHeight + '"><setwidth newsize="' + numberWidth + '">' + d + '</span>';}); text = CopyfitLine("", text, "Alright Sans Regular", 7, 330, 6, false); return text;Now you should see numbers in that 10.5 point size and the rest of the address shrinking so that everything fits in the allotted space (330 points). I think this still isn't quite right, because you probably don't always want to set the number in 10.5 point text if the size of the rest of the text varies because of copyfitting; instead, you probably want the size of the numbers to always be relative to the other text, which suggests using a <magnify> tag. But I'll leave that as another exercise.
Dan Korn Posted January 13, 2011 Posted January 13, 2011 Ah-ha! I discovered the fatal flaw. I unchecked "Treat returned strings..." in the rule Clinic-Address and everything works fine now. Actually, I don't see how that would make any difference, because that rule is returning a resource, so FusionPro ignores the check box because it knows that the resource itself contains tagged markup. I think the problem is what I said in my previous post, which is that you need to do the copyfitting last after any other tagging is applied. But if it's working, that's good.
mstanton Posted January 14, 2011 Author Posted January 14, 2011 var numberFont = "Folio Light"; var numberWidth = "11"; var numberHeight = "10.5"; var text = Field("ADDRESS"); text = text.replace(/(\d+\s*)/g, function(d){return '<span font="' + numberFont + '"><z newsize="' + numberHeight + '"><setwidth newsize="' + numberWidth + '">' + d + '</span>';}); text = CopyfitLine("", text, "Alright Sans Regular", 7, 330, 6, false); return text;Now you should see numbers in that 10.5 point size and the rest of the address shrinking so that everything fits in the allotted space (330 points). Ok, well that gets rid of the mysterious sevens, but now everything but the numbers has shrunk to teeny tiny text even when it doesn't come close to filling the 330 point space. I don't want the text to be small all of the time and I most certainly do not want the numbers to stay large when the rest of the text is supposed to be smaller. How do I accomplish this?
Dan Korn Posted January 14, 2011 Posted January 14, 2011 Ok, well that gets rid of the mysterious sevens, but now everything but the numbers has shrunk to teeny tiny text even when it doesn't come close to filling the 330 point space. Well, I think the main problem is that you're starting out at 7 points as the maximum size for the text. You probably want to start bigger and let it shrink as needed. So that first number in the call to CopyfitLine should probably be something like 10, to match the size of the other text. Of course, you can start with a smaller number, but it's more likely that space will be left over. Also, the space you're trying to fill is a lot less than 330 points; I think it's more like 260 points, so that's what I would put for the second number. Try this: text = CopyfitLine("", text, "Alright Sans Regular", 10, 260, 5, false); When I do this (although I'm using Arial since I don't have your font), the text does size itself to fill up the entire space. But now the numbers are smaller than the other text, because that point size is hard-coded to 10.5 points. Which leads into your next question... I don't want the text to be small all of the time and I most certainly do not want the numbers to stay large when the rest of the text is supposed to be smaller. How do I accomplish this? Like I said, you probably don't want to have the size of the numbers fixed while everything else shrinks to fit. I would use a <magnify> tag to keep it always proportional to the rest of the text. Something like this: text = text.replace(/(\d+\s*)/g, function(d){return '<span font="' + numberFont + '"><magnify type=pointsize factor=120>' + d + '</magnify></span>';});Putting it all together: var numberFont = "Folio Light"; var startingPointSize = 10; var minPointSize = 5; var maxWidthPoints = 260; var numberMagnifyFactor = 120; var text = Field("ADDRESS"); text = text.replace(/(\d+\s*)/g, function(d){return '<span font="' + numberFont + '"><magnify type=pointsize factor=' + numberMagnifyFactor + '>' + d + '</magnify></span>';}); text = CopyfitLine("", text, "Alright Sans Regular", startingPointSize, maxWidthPoints, minPointSize, false); return text;
Recommended Posts
Archived
This topic is now archived and is closed to further replies.