0

I have an HTML file which I want to load in a QWebView. The header looks something like:

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>

The body text is mixed Latin and Japanese characters.

The page displays perfectly in Chrome, but all of the Japanese characters are replaced with when the page is displayed in a QWebView.

QtWebKit seems to use the same system as used by QTextCodec to handle conversions between unicode and other charsets (please correct me if I'm wrong on this) and I'm therefore working on the assumption that QtWebKit can support Shift_JIS.

As a test, I've tried adding the specific unicode for a kanji character (e.g. &#x3041; to display ぁ) to my HTML file. I get the character properly rendered in Chrome, but it also displays as in a QWebView - I'm not sure whether this means I can trust the Shift_JIS to unicode conversion in Qt, but it certainly means I can't assume that it is the cause of the problem.

I'm not sure where to go from here; any suggestions as to solutions or other areas to investigate would be much appreciated.

sam-w
  • 7,478
  • 1
  • 47
  • 77

1 Answers1

1

Turns out I've been over-thinking this one, there is in fact a pretty simple solution:

When confronted with Kanji characters which the current font is unable to display, Chrome is clever enough to fall back to a font which does support those characters (on my Win 7 PC the default Kanji font is MS Gothic).

QtWebKit does not have this feature, and hence it is necessary to explicitly specify (in CSS) a Kanji-capable font for the areas which need it.

sam-w
  • 7,478
  • 1
  • 47
  • 77
  • Hey @sjwarner, how did you end up solving or working around this issue? I have exactly the same problem, and I want to show English characters in the correct font and non-English characters in the fallback font. See my own similar stackoverflow post here: http://stackoverflow.com/questions/12769169/how-to-fix-work-around-qtwebkits-incorrect-font-fallback-behavior – Yoni Rozenshein Oct 09 '12 at 12:28
  • Hi yoni, since the vast majority of the content on the page referred to here is in Kanji rather than Latin I just applied a Kanji and Latin capable font to the whole of the page. My Latin characters don't look exactly as I'd like them but the main issue for me here was Japanese readability. Sorry to not be of more help. – sam-w Oct 09 '12 at 13:26