TerenceM Posted November 16, 2004 Posted November 16, 2004 Here is a pair of custom functions that others may find useful. I've been aggrevated by the inability to remove the font/size information from a block of text in FP7. I need to do this with text that has been pasted in from a different application (and thus has an associated font/size), and would like to appear in different fonts/sizes on different layouts. In earlier versions, you could reset the text font/size by using Set Field ( TextField ; TextField ), but this no longer works. You have the option of resetting the font/size to one of your choosing, but if you want the text to appear in the font/size as defined in the current layout, you're out of luck. Ender and a set of functions by The Shadow pointed me to the solution: GetAsCSS, which returns unformatted text. My implementation is attached. GetAsUnformattedText ( InputText ) will convert a piece of text to a CSS, remove the CSS information, and then use a second function (HTMLtoText) to convert any special characters (such as <,>,&, etc.) back to their original forms. It should work on Mac and Windows platforms, but I suspect the conversion matrix of special characters may require some editing on Windows to make sure all the characters are what they're supposed to be. You can use it as an Auto-Enter Calculation (with "Do not replace existing value" unchecked) to ensure that a user can't apply a font/size/color/style to a text field. -Terence Edit: attachment removed, and replaced by the one in the following post.
TerenceM Posted November 17, 2004 Author Posted November 17, 2004 I just discovered that TextStyleRemove ( text ; AllStyles ) has a bug, and doesn't always remove AllStyles. The workaround is to use the command: TextStyleRemove ( TextStyleAdd ( text ; AllStyles ) ; AllStyles ) I've incorporated this change into the attached version of the GetAsUnformattedText function (and reported the bug to Filemaker). -Terence Updated attachment: The prior version of the HTMLtoText converter was missing a conversion for ≠ (not equals), which I've now added. Also, for those without Developer, the text field "autoenter" now has a non-custom function version of GetAsUnformattedText, although it only handles basic special characters like <, >, ", etc, and no accented letters. But it will help get the job done. UnformatText.fp7.zip
CoZiMan Posted November 18, 2004 Posted November 18, 2004 That works very well. My workaround was to copy and paste with no style, twice, via script. Very painful to manage the position and un-automagic. I also appreciate the html extraction, and this is much more useful for me at the moment. All the nbsp - n(on)b(reak)sp(aces) were not stripped out when replacing and trimming for blank spaces. This meant that the character counts in a position statement couldn't see the actual beginning of a text string but COULD see the end of the previous. I ended up parsing from the END to the BEGINNING (Think of fifty cascading / reliant on subsequent value / variables). Phew. Calculation nightmare. So your html conversion replaces the unreadables with standard ascii and that can be substituted/removed. Hurrah ! All other text functions will now work as expected You rock !
TerenceM Posted November 18, 2004 Author Posted November 18, 2004 The thing that aggrevates me most about this problem is FileMaker's suggested solution (as mentioned in Help) export and reimport the text! As if the chore of scripting a copy and paste wasn't enough. By the way, I discovered that the copy and paste technique can be done in one pass: Copy Set Field ( text ; "" ) Paste (without style) The intervening Set Field step is needed to blank out the residual formatting saved before the first character in the field. And a Clear step doesn't work. But I didn't like having to do this, either, which resulted in my quest for a way to do the custom function. It sounds like your problem with non-breaking spaces could also be solved with just a substitute ( text ; nbsp ; " " ) function. I had never considered the problem of non-breaking spaces when using TrimAll, I'll have to consider that problem in a few places. Glad the functions help. -Terence
Lee Smith Posted November 18, 2004 Posted November 18, 2004 And so, the Replace (Menu or Script Step) is not available in v7?
TerenceM Posted November 18, 2004 Author Posted November 18, 2004 I assume that you mean "Replace Field Contents," which has the same effect as Set Field ( text ; text ) in both FP6 and FP7. That is, in FP6, it will strip out any text formatting, but in FP7, all text formatting is retained. To some extent its nice, like if you have greek letters in Symbol font and want to attach them to another field without losing that font information. But its rather shortsighted of FileMaker to not leave some way to get rid of the font/size/color information (there is a TextStyleRemove function, to get rid of bold/italics/etc.). You can _change_ the font/size/color to something else, but you can't reset it (via the functions) so that it will appear in the font/size/color defined by the layout. I've suggested to Filemaker that they should add a way do the function TextFont (text ; NoFont ), which I would think they could implement in an interim update since it wouldn't change the way existing functions work. I love FP7, but there are definitely a lot of quirks that I hope will be addressed before FP8. -Terence
TerenceM Posted December 15, 2004 Author Posted December 15, 2004 Perusing the custom functions on Brian Dunning's web site, I found a much simpler way to remove text formatting in FP7. Tim Cimbura posted the following solution: Evaluate ( Quote ( text ) ) Luckily for me, its trivial to change the Custom Function in my databases to use this much simpler calculation! -Terence
Recommended Posts