kenstraker Posted July 31, 2014 Share Posted July 31, 2014 Hi I am trying to create a business card in which I need to Provide a drop-down menu for selection of Rank/Title. It is preferred that each officer selects their rank from a list as opposed to manual entry. As a further requirement the Rank may be abbreviated if the Officer’s name is over a set length. I can create the drop down menu but I am having trouble abbreviating Title when the name is too long. Is this at all achievable? Regards. . Quote Link to comment Share on other sites More sharing options...
David Miller Posted July 31, 2014 Share Posted July 31, 2014 It is achievable. I suggest using the FusionProTextMeasure object to measure the length of the data field. If the officer's name is greater than your maximum width, return the abbreviated version of the rank. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 31, 2014 Share Posted July 31, 2014 I'm imagining a rule something like this: var abbrs = { "Captain": "Capt", "Lieutenant": "Lt", "Major": "Maj", // etc. }; var rank = Field("Rank"); if (Field("Name").length > 20) rank = abbrs[rank] || rank; return rank; Although, instead of simply examining the number of characters in the name, you might want to use Text Measurement instead. Quote Link to comment Share on other sites More sharing options...
David Miller Posted August 1, 2014 Share Posted August 1, 2014 (edited) Dan posted a most-excellent way of handling the abbreviations. Let's hope he keeps imaging these really cool things. Okay, so, try combining it with his other posts regarding FusionProTextMeasure. [color="red"]var maxWidth = [color="Magenta"].25[/color] * 7200; [color="SeaGreen"]// Set the maximum width of your field in hundredths of points; 7200 = one inch[/color] [color="SeaGreen"]// Use FusionProTextMeasure to measure the length of your field[/color] var tm = new FusionProTextMeasure; tm.pointSize = "10 pt"; [color="SeaGreen"]// Set the type size used for your field[/color] tm.font = "Helvetica"; [color="SeaGreen"]// Set typeface used for your field[/color] tm.CalculateTextExtent(Field("[color="Magenta"]MyFieldName[/color]")); [color="SeaGreen"]// Replace with your field name[/color] tm.useTags = false; var tmWidth = tm.textWidth;[/color] [color="red"][color="SeaGreen"]// Edit long names and abbreviations in the same format as below[/color][/color] var abbrs = { "Captain": "Capt", "Lieutenant": "Lt", "Major": "Maj", [color="SeaGreen"]// etc.[/color] }; var rank = Field("[color="Magenta"]Rank[/color]");[color="SeaGreen"]// The variable "rank" is being set to the field "rank" here. Edit accordingly.[/color] if [color="red"](tmWidth > maxWidth)[/color] rank = abbrs[rank] || rank; return rank; My additions and changes are in red, comments are in green and template specifics are in magenta. You will need to edit your JavaScript rule according to the comments in green. Edited August 1, 2014 by David Miller Quote Link to comment Share on other sites More sharing options...
kenstraker Posted August 1, 2014 Author Share Posted August 1, 2014 Thanks David for your help on this much appreciated. Ken:) Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 1, 2014 Share Posted August 1, 2014 Thanks David, that's good. Still, this can be improved upon a bit more. For one thing, you can have the rule automatically calculate the width of the current frame, so that you don't need to hard-code it. Also, you probably want to measure the whole line, with the rank and the name, and adjust only if that doesn't fit. And, you probably want to check if it fits after using the abbreviation, and apply some copyfitting to shrink the text as necessary. Try this, with both the "Re-evaluate this rule for every text box" and "Treat returned strings as tagged text" boxes checked, and a name applied to the text frame: // Edit long names and abbreviations in the same format as below var abbrs = { "Captain": "Capt", "Lieutenant": "Lt", "Major": "Maj", // etc. }; var rank = Field("Rank"); // The variable "rank" is being set to the field "rank" here. Edit accordingly. var name = Field("Name"); // Replace with your field name var pointsize = 10; // Set the type size used for your field var font = "Arial"; // Set typeface used for your field var tags = '<f name="' + font + '"><z newsize="' + pointsize + '">'; var maxWidth = 0.25 * 7200; // For validation in the Rule Editor, in hundredths of points; 7200 = one inch if (!FusionPro.inValidation) // At composition time, use the actual frame width maxWidth = FindTextFrame(FusionPro.Composition.CurrentFlow.name).GetSettableTextWidth(); var text = tags + rank + " " + name; // Use FusionProTextMeasure to measure the length of the text and see if it fits. var tm = new FusionProTextMeasure; tm.useTags = true; tm.CalculateTextExtent(text); if (tm.textWidth <= maxWidth) return text; // it fits without modification //else // Abbreviate the rank rank = abbrs[rank] || rank; text = tags + rank + " " + name; // See if it fits with the abbreviated rank. tm.CalculateTextExtent(text); if (tm.textWidth <= maxWidth) return text; // it fits with the abbreviated rank //else // Shrink (copyfit) the line to fit. var factor = Round(maxWidth / tm.textWidth * 100, 0) - 1; return "<magnify type=setwidth factor=" + factor + ">" + text + "</magnify>"; The bit at the end is borrowed from the CopyfitLineWithMagnifyTag function. Quote Link to comment Share on other sites More sharing options...
David Miller Posted August 4, 2014 Share Posted August 4, 2014 Thank you Dan. Good to know. Quote Link to comment Share on other sites More sharing options...
kenstraker Posted August 4, 2014 Author Share Posted August 4, 2014 Hi Dan/David I don't seem to get Dan code to work it keeps repeating the name and does not abbreviate the rank. Please see file. RegardsNonFrontline Contact card No.zip Quote Link to comment Share on other sites More sharing options...
David Miller Posted August 4, 2014 Share Posted August 4, 2014 I don't see your template repeating the name and the abbreviations are working. There is 1 sample record with a name that has 11 or less characters. That person's rank is "PC". The abbreviation for "PC" is "PC". So, it might appear that it is not working, but it is. Quote Link to comment Share on other sites More sharing options...
kenstraker Posted August 4, 2014 Author Share Posted August 4, 2014 Hi David There are two rules I was playing with the one in mention is RankRule10. Regards Quote Link to comment Share on other sites More sharing options...
David Miller Posted August 4, 2014 Share Posted August 4, 2014 Okay, can you upload the template with RankRule10? The template that was uploaded doesn't seem to have that one. Quote Link to comment Share on other sites More sharing options...
kenstraker Posted August 4, 2014 Author Share Posted August 4, 2014 Hi David Please see attaché file. CheersNonFrontline Contact card No.zip Quote Link to comment Share on other sites More sharing options...
David Miller Posted August 4, 2014 Share Posted August 4, 2014 (edited) Dan's rule works perfectly. But adjustments are needed to work with your template. // Edit long names and abbreviations in the same format as below var abbrs = { "PCSO": "PCSO", "PC": "PC", "Detective Constable": "Det Con", "Sergeant": "Sgt", "Inspector": "Insp", "Detective Inspector": "Det Insp", "Chief Inspector": "Ch Insp", "Detective Chief Inspector": "Det Ch Insp", "Superintendent": "Supt", "Detective Superintendent": "Det Supt", "Chief Superintendent": "Ch Supt", "Detective Chief Superintendent": "Det Ch Supt", "Assistant Chief Constable": "ACC", "Detective Chief Constable": "DCC", // etc. }; var rank = Field("Rank"); // The variable "rank" is being set to the field "rank" here. Edit accordingly. var name = Field("Name"); // Replace with your field name [color="Red"]var collar = Field("Collar Number");[/color] var pointsize = 12; // Set the type size used for your field var font = "[color="red"]Helvetica[/color]"; // Set typeface used for your field var tags = '<f name="' + font + '"><z newsize="' + pointsize + '">'; var maxWidth = [color="red"]3.19[/color] * 7200; // For validation in the Rule Editor, in hundredths of points; 7200 = one inch if (!FusionPro.inValidation) // At composition time, use the actual frame width maxWidth = FindTextFrame(FusionPro.Composition.CurrentFlow.name).GetSettableTextWidth(); [color="Red"]var text = tags + rank + " " + name + " " + collar;[/color] // Use FusionProTextMeasure to measure the length of the text and see if it fits. var tm = new FusionProTextMeasure; tm.useTags = true; tm.CalculateTextExtent(text); if (tm.textWidth <= maxWidth) return text; // it fits without modification //else // Abbreviate the rank rank = abbrs[rank] || rank; text = tags + rank + " " + name; // See if it fits with the abbreviated rank. tm.CalculateTextExtent(text); if (tm.textWidth <= maxWidth) return text; // it fits with the abbreviated rank //else // Shrink (copyfit) the line to fit. var factor = Round(maxWidth / tm.textWidth * 100, 0) - 1; return "<magnify type=setwidth factor=" + factor + ">" + text + "</magnify>"; The rule should evaluate the entire line of text and return the entire line of text accordingly. Changes are in red. Remove the fields "name" and "collar number" from the variable text frame using the variable text editor. (Because they are returned in the rule above.) Add var "collar", fix the font name, change the maxWidth of your frame and update the var "text" line. Edited August 5, 2014 by David Miller typos and technical stuff Quote Link to comment Share on other sites More sharing options...
kenstraker Posted August 4, 2014 Author Share Posted August 4, 2014 Thanks David once again for all your help. Regards Ken Quote Link to comment Share on other sites More sharing options...
David Miller Posted August 5, 2014 Share Posted August 5, 2014 (edited) Dan deserves the thanks here. I just happened to be looking for a similar solution. Learned a lot myself. Glad to chip in. Pass it on. Cheers. Edited August 5, 2014 by David Miller Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.