Results 1 to 10 of 10

Thread: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

  1. #1
    Join Date
    Nov 2012
    Posts
    7
    Qt products
    Platforms
    MacOS X

    Default Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    Hi,

    I'm using: PyQt4, OS X 10.7.5

    In an editor generated by QWebView I am unable to display five-digit hex unicode code points properly.

    For example, in the editor, the character "ð’€€" (U+12000, a Cuneiform sign, using the Neo-Assyrian font at: http://www.hethport.uni-wuerzburg.de/cuneifont/) displays both a "ð’€€" and a square box which is shaded on the left side and has the right side of an "A" on its right side.

    When I put a space (" ") in front of the Cuneiform sign the box disappears, but an empty space (which can't be deleted) appears after the Cuneiform sign.

    Other five-digit hex symbols (e.g. "ð“€€", U+13000, using the Aegyptus font from: http://users.teilar.gr/~g1951d/) also have the same problem.

    Four-digit hex symbols (e.g. "ሀ", U+1200) seem to work fine, without any of these issues.
    Mac's TextEdit has no troubles displaying the five-digit hex unicode symbols.

    Could the issue be QWebView's handling of Unicode symbols outside the four-digit hex range?

    Thanks,

    Nick Webb

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    This code snippet:
    Qt Code:
    1. QString cuneiform = QString::fromUtf8("\xF0\x92\x80\x80");
    2. // OR
    3. // uint character = 0x00012000;
    4. // QString cuneiform = QString::fromUcs4(&character, 1);
    5. // OR
    6. // ushort character[] = {0xD808,0xDC00};
    7. // QString cuneiform = QString::fromUtf16(character, 2);
    8. qDebug() << cuneiform;
    9.  
    10. QWebView w;
    11. w.setHtml(QString("<html><body>++%1++</body></html>").arg(cuneiform));
    12. w.show();
    To copy to clipboard, switch view to plain text mode 
    results in the correct glyph in my Linux console and QWebView.

    What is the encoding of the HTML file and how are you loading it?

  3. #3
    Join Date
    Nov 2012
    Posts
    7
    Qt products
    Platforms
    MacOS X

    Default Re: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    The following displays ++<two empty boxes>++ in a small window for me:

    Qt Code:
    1. import sys
    2.  
    3. from PyQt4.QtCore import QString
    4. from PyQt4.QtGui import QApplication, QWidget
    5. from PyQt4.QtWebKit import QWebView
    6.  
    7. # Constants
    8. CUNE_STR = u"\U00012000"
    9. HTML = r"<html><body>++%1++</body></html>"
    10.  
    11. # Main
    12.  
    13. qStr = QString(HTML).arg(CUNE_STR)
    14.  
    15. app = QApplication(sys.argv)
    16.  
    17. widget = QWidget()
    18.  
    19. widget.resize(320, 240)
    20. widget.setWindowTitle("Hello, World!")
    21. widget.show()
    22.  
    23. webView = QWebView(widget);
    24. webView.setHtml(qStr);
    25. webView.show()
    26.  
    27. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    Works fine here. What happens if you add:
    Qt Code:
    1. print type(CUNE_STR), CUNE_STR.encode('utf-8')
    To copy to clipboard, switch view to plain text mode 
    Assuming you have a console that handles UTF-8 and has access to the font you should see "<type 'unicode'>" and the correct glyph.

    As experiments you could try:
    Qt Code:
    1. HTML = u"<html><body>++%1++</body></html>"
    To copy to clipboard, switch view to plain text mode 
    to force Unicode encoding of the HTML. Also try putting the cuneiform glyph directly into the unicode HTML avoiding the possible mangling that QString::arg() might inflict.

    There are some rather unclear rules that apply to Python unicode to QString transforms:
    http://www.riverbankcomputing.com/st...l/gotchas.html

  5. #5
    Join Date
    Nov 2012
    Posts
    7
    Qt products
    Platforms
    MacOS X

    Default Re: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    Firstly, thanks for your help.

    The following produces "<type 'unicode'>" and the correct glyph:

    Qt Code:
    1. print type(CUNE_STR), CUNE_STR.encode('utf-8')
    To copy to clipboard, switch view to plain text mode 

    This does not fix my problem:

    Qt Code:
    1. HTML = u"<html><body>++%1++</body></html>"
    To copy to clipboard, switch view to plain text mode 

    Finally, putting the cuneiform glyph directly into the unicode HTML does not fix my problem either.

    I'm using Python 2.7.2 and I can't find anything on http://www.riverbankcomputing.com/st...l/gotchas.html that helps solve my problem.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    OK. We know the Python string is OK. If you:
    Qt Code:
    1. print qStr.toUtf8()
    To copy to clipboard, switch view to plain text mode 
    I will guess that the result is not good.

    Perhaps this has a different effect:
    Qt Code:
    1. qStr = QString(HTML).arg(QString(CUNE_STR))
    To copy to clipboard, switch view to plain text mode 
    by forcing the CUNE_STR explicitly through the QString constructor

  7. #7
    Join Date
    Nov 2012
    Posts
    7
    Qt products
    Platforms
    MacOS X

    Default Re: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    If I use:
    Qt Code:
    1. HTML = u"<html><body>++\U00012000++</body></html>"
    2. qStr = QString(HTML)
    3. print qStr.toUtf8()
    To copy to clipboard, switch view to plain text mode 
    then the HTML string with the correct glyph in it is printed.

    If I use:
    Qt Code:
    1. #!/usr/bin/env python
    2. # -*- coding: UTF-8 -*-
    3. '''
    4. Created on 7 November 2012
    5.  
    6. @author: nick
    7. '''
    8.  
    9. import sys
    10.  
    11. from PyQt4.QtCore import QString
    12. from PyQt4.QtGui import QApplication, QWidget
    13. from PyQt4.QtWebKit import QWebView
    14.  
    15. # Constants
    16. CUNE_STR = u"\U00012000"
    17. HTML = u"<html><body>++%1++</body></html>"
    18.  
    19. # Main
    20.  
    21. qStr = QString(HTML).arg(QString(CUNE_STR))
    22.  
    23. app = QApplication(sys.argv)
    24.  
    25. widget = QWidget()
    26.  
    27. widget.resize(320, 240)
    28. widget.setWindowTitle("Hello, World!")
    29. widget.show()
    30.  
    31. webView = QWebView(widget);
    32. webView.setHtml(qStr);
    33. webView.show()
    34.  
    35. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    then the same problem occurs: a window pops up with: ++<two empty boxes>++.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    Aarrgghh!! It looks like the Python-esque QString::arg() is mangling your character.

    Perhaps you could use Python methods to put the strings together then do a single conversion into QString.

  9. #9
    Join Date
    Nov 2012
    Posts
    7
    Qt products
    Platforms
    MacOS X

    Default Re: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    I don't think it's a string-combining problem, as even this:
    Qt Code:
    1. #!/usr/bin/env python
    2. # -*- coding: UTF-8 -*-
    3. '''
    4. Created on 7 November 2012
    5.  
    6. @author: nick
    7. '''
    8.  
    9. import sys
    10.  
    11. from PyQt4.QtCore import QString
    12. from PyQt4.QtGui import QApplication, QWidget
    13. from PyQt4.QtWebKit import QWebView
    14.  
    15. # Constants
    16. CUNE_STR = u"\U00012000"
    17. HTML = u"<html><body>++\U00012000++</body></html>"
    18.  
    19. # Main
    20.  
    21. #qStr = QString(HTML).arg(QString(CUNE_STR))
    22.  
    23. app = QApplication(sys.argv)
    24.  
    25. widget = QWidget()
    26.  
    27. widget.resize(320, 240)
    28. widget.setWindowTitle("Hello, World!")
    29. widget.show()
    30.  
    31. webView = QWebView(widget);
    32. webView.setHtml(HTML);
    33. webView.show()
    34.  
    35. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    where I make no use of QString, still only produces a box with: "++<two empty boxes>++"

    Considering unicode characters < 0xFFFF, I'm getting some strange behaviour. For example:
    Qt Code:
    1. #!/usr/bin/env python
    2. # -*- coding: UTF-8 -*-
    3. '''
    4. Created on 7 November 2012
    5.  
    6. @author: nick
    7. '''
    8.  
    9. import sys
    10.  
    11. #from PyQt4.QtCore import QString
    12. from PyQt4.QtGui import QApplication, QWidget
    13. from PyQt4.QtWebKit import QWebView
    14.  
    15. # Constants
    16. #CUNE_STR = u"\U00012000"
    17. HTML = u"<html><body>++؀؀\u1250++</body></html>"
    18.  
    19. # Main
    20.  
    21. #qStr = QString(HTML).arg(QString(CUNE_STR))
    22.  
    23. app = QApplication(sys.argv)
    24.  
    25. widget = QWidget()
    26.  
    27. widget.resize(320, 240)
    28. widget.setWindowTitle("Hello, World!")
    29. widget.show()
    30.  
    31. webView = QWebView(widget);
    32. webView.setHtml(HTML);
    33. webView.show()
    34.  
    35. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 
    displays the correct character in the window, but if I change the HTML string to:
    Qt Code:
    1. HTML = u"<html><body>++؀؀\u1200++</body></html>"
    To copy to clipboard, switch view to plain text mode 
    only "++<empty box>++" displays (EDIT: My system seems to have the font to display this glyph because it displays correctly in Mac's Character Viewer).
    Last edited by nickw2066; 8th November 2012 at 20:18.

  10. #10
    Join Date
    Nov 2012
    Posts
    7
    Qt products
    Platforms
    MacOS X

    Default Re: Does QWebView support Unicode characters > 0xFFFF (for Cuneiform fonts)

    **bump**

    Anyone have any idea about the \u1250 vs. \u1200 problem described immediately above?

Similar Threads

  1. Help needed to convert unicode characters
    By hybrid_snyper in forum Newbie
    Replies: 4
    Last Post: 24th August 2012, 15:20
  2. Replies: 6
    Last Post: 30th March 2012, 08:01
  3. QString to unicode characters
    By jsmax in forum Newbie
    Replies: 1
    Last Post: 19th September 2011, 10:41
  4. Unicode/ASCII characters in QTextStream
    By yren in forum Qt Programming
    Replies: 3
    Last Post: 23rd November 2009, 18:25
  5. Insertion of unicode characters into database oracle through pro c
    By hemananda choudhuri in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2007, 10:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.