Skip to main content
Participant
January 19, 2011
Question

TextConverter.importToFlow() - HTML with Superscript

  • January 19, 2011
  • 1 reply
  • 894 views

I need to create a TextFlow instance from generic HTML text with a reduced subset of possible tags, being <p>, <b>, <u>, <i>, <a>, <sup> and <sub>.

The problem is the conversion of sub and sup tags. Simply importing the HTML text with

TextConverter.importToFlow(htmlText, TextConverter.TEXT_FIELD_HTML_FORMAT);

results in sup and sub tags being ignored, as they are not supported by TEXT_FIELD_HTML_FORMAT.

Do you have any idea how to get the sup and sup content converted to spans with appropriate baselineshift?

Be aware that inside sup and sup elements may contains <b>, <i> and <u> tags as they are inline elements!

This topic has been closed for replies.

1 reply

Adobe Employee
January 20, 2011

Easiest way would use TLF 2.0, which has the <g> element for grouping spans. But, lacking that, you can create spans that are not nested, but have the appropriate baselineShift attributes. The main trick is getting the html conversion code to do what you want with <sub> and <super>.

So, if you are using TLF 1.0, start by looking at the HTMLImporter class. This is the code that is used for converting from HTML to a TextFlow. You could look at how it handles <b> and <i> (see parseBold and parseItalic) and add to it something similar for <sub> and <super>. You can make your changes directly in the HTMLImporter class and recompile TLF, or you can add a second class, MyHTMLImporter that inherits from HTMLImporter, and that you call directly.

TLF 2.0 is only a little different from this, in that it has support for the <g> element, and you will see this in the 2.0 version of the HTMLImporter class. TLF 2.0 also has a mechanism for adding a new importer class that goes side-by-side with the pre-defined ones, and you can call it through TextConverter. Other than those two differences, I think its the same problem.

Hope this helps,

- robin