How can I set a custom size for the RichTextArea.Formatter.setFontSize() in GWT?
Using the RichTextArea in GWT, It looks like I can on开发者_StackOverflow社区ly change the font size to one of the values: LARGE
, MEDIUM
, SMALL
, etc (RichTextArea.FontSize), but I want to be able to setFontSize
of the RichTextArea.Formatter
to a specific size in pt
or in px
.
How can I achieve that?
I've been digging a bit on this, and it would seem that it is unfortunately not possible, because browsers are limited in their handling of font sizes in the rich text editors. In particular, Firefox generates the (deprecated) <font size="x"></font>
element when the font size is changed, and the value of x can be only in the 1-7 range.
If you have a look at the setFontSize method in RichTextAreaImplStandard (GWT source code), you'll see that it ends up calling the execCommand javascript function, which in the case of FontSize only accepts values in 1-7:
http://msdn.microsoft.com/en-us/library/ms536991%28VS.85%29.aspx
You can actually achieve that using string manipulation of the HTML code. So if you are not using the background color property of the RichTextArea then what you have to do is to replace the "background-color=RED" to "font-size=12px". And then set it back to the RichTextArea object as setHTML().
This works fine as I've implemented this functionality in one of our production application..
Thanks, Pratik.
精彩评论