Page 1 of 1

Unicode and HTML for Fields

Posted: Sat Oct 20, 2012 8:29 am
by dave_probertGA6e24
Hi All,

I have various simple html files translated into asian languages (e.g. Thai) that contain html tags to provide bold, font colours, etc. I would like to be able to load these into a normal Field object on a card. I can get the utf8 text to display fine, but the html tags show (using unicodetext property), or I can show gobbledigook text with bold/colours/etc (using htmltext property).

Is there a way to have the best of both worlds like this? Or am I stuck with messing around with a browser view or something? Has anyone else done anything similar with success?

For further information the html files have extra tags in them that I pre-parse to let the program know things like pictures to use (and where they should appear) and also to tell the program to split the text. These are easy to get via basic text location functions, etc. So I'm not too interested in using RTF formatting (as I don't know how to split that or insert data into the text-stream)

Any ideas would be great.
Cheers,
Dave

Re: Unicode and HTML for Fields

Posted: Sat Oct 20, 2012 4:32 pm
by Simon
Hi Dave,
Not sure but when I use htmlText I get:
input 才出吃
output <p><font face="Heiti SC Light" size="11">&#25165;&#20986;&#21507;</font></p>
and the reverse works, no gobbelygook.

How does your html look?

Simon

Re: Unicode and HTML for Fields

Posted: Mon Oct 22, 2012 9:45 am
by dave_probertGA6e24
Hi.

Sorry for not replying earlier - had a Modem crash!

If I have something like:

<b>才出吃</b>

in my html/text file then I get the same appearing in the field for unicodetext (i.e. - characters are there along with the <b> tags), but I would get a proper bold text, but it is not readable for htmltext.

What I'm wondering is is there a way to convert the raw utf8 to the &#25165; style on the fly - so as to preserve the original (editable) text, but to then be able to display it in an htmltext field?

At this point in time the translators are simply writing the translations using a text editor - and dropping the basic tags in the appropriate places. They have no knowledge of the numerical codes for the characters they are typing as such.

Cheers,
Dave

Re: Unicode and HTML for Fields

Posted: Mon Oct 22, 2012 4:24 pm
by Simon
As you say they add simple tags I think one way of doing it is:
put the utf into fld1 you get:
<b>才出吃</b>
put the htmlText fld1 into fld2:
<p><b>&#25165;&#20986;&#21507;</b></p>
then
replace "<" with "<" in fld2
replace ">" with ">" in fld2
result <p><b>&#25165;&#20986;&#21507;</b></p>
and then set the htmlText of a fld2 to the output fld.

Simon

Re: Unicode and HTML for Fields

Posted: Mon Oct 22, 2012 7:02 pm
by dave_probertGA6e24
Simon - that was Perfect - exactly what I needed, and so simple too.

The only thing I added was a replace """ with quote - to handle some <font color="red"> bits.

Code: Select all

      // tdat contains html tags and raw utf8 data
      set the unicodetext of field "textField" to uniEncode(tdat,"utf8")
      put the htmltext of field "textField" into tagged
      replace "<" with "<" in tagged
      replace ">" with ">" in tagged
      replace """ with quote in tagged
      set the htmltext of field "textfield" to tagged
I really hope that this can help others too, who may be having difficulty with utf8/unicode/html.

Thanks again.

Cheers,
Dave

Re: Unicode and HTML for Fields

Posted: Tue Oct 23, 2012 2:05 am
by Simon
Great, I'm glad it worked for you.
A couple of weeks ago I went through double byte terror so it was all still fresh in my mind.

Simon