View Issue Details

IDProjectCategoryView StatusLast Update
0000853FreeCADFeaturepublic2015-04-27 14:09
ReportermrlukeparryAssigned Toyorik 
PriorityhighSeveritymajorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version 
Target VersionFixed in Version0.16 
Summary0000853: Unicode Strings in Coin3D
DescriptionImplementing UTF support inside FreeCAD and updating all text nodes to utlise this.
Tagsencoding, unicode

Relationships

parent of 0001404 closedyorik Draft Draft Dimension Override string: Non ascii-Characters are not shown in Drawings 
related to 0001745 closedwmayer FreeCAD App::Annotation should store LabelText as unicode 

Activities

yorik

2013-08-21 14:10

administrator   ~0003501

Actually coin3D can already display non-ascii strings, they must be encoded as latin1:

from pivy import coin
t = coin.SoText2()
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(t)
s = "Alçapão"
t.string = s.decode("utf8").encode("latin1")

I just adapted the Draft objects that use coin text to do the conversion, maybe it's just a matter of adapting the remaining places where coin text is used.

The Document::Annotation object must be adapted to convert text to latin1 when it is given as utf8, I think I can do that, I'll have a look.

shoogen

2013-08-22 04:08

developer   ~0003503

As latin-1 can not represent any unicode char. i would recommend to change the error mode from 'strict' to 'replace', 'igonore' or another strategy.
t.string = s.decode("utf8").encode("latin1","replace")
http://docs.python.org/2/library/codecs.html#codec-base-classes

You would not recomment to catch the UnicodeError

yorik

2013-08-22 11:27

administrator   ~0003504

Ah good point! Thanks!
If anyone know how to do that conversion in c++, I'm all ears!

mrlukeparry

2013-10-25 09:39

developer   ~0003805

the problem is that it latin1 encoding will not support non-latin characters. This would be a short term fix for the problem but would be helpful.

yorik

2014-03-29 17:40

administrator   ~0004516

Starting from coin 4.0 (libcoin80), utf is apparently totally supported now... This now works:

from pivy import coin
t = coin.SoText2()
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(t)
s = "Alçapão"
t.string = s

yorik

2014-05-11 17:46

administrator   ~0004651

I believe this can be closed now... Reopen if needed!

shoogen

2014-05-11 18:07

developer   ~0004652

Last edited: 2014-05-11 18:08

View 2 revisions

i think you forgot the "replace" strategy in the if branch for coin version <4
https://github.com/FreeCAD/FreeCAD_sf_master/commit/32d7839da4413f2be7f34e0d204ab4dfb3d6b034#diff-24e5bcc9ea97d5685e3d0c894b51b1ffR885

yorik

2014-05-11 18:22

administrator   ~0004653

Oops indeed... Seems like I made a little mix of "encode" and "decode"... :) Thanks for checking

yorik

2014-05-11 20:00

administrator   ~0004655

Hm but it seems to work fine the way it is... Anybody with coin3 can please test? Thanks...

wmayer

2014-05-12 13:48

administrator   ~0004660

Last edited: 2014-05-12 13:49

View 2 revisions

Coin3:

from pivy import coin
t = coin.SoText2()
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(t)
s = "Alçapão"
t.string = s.decode("utf8").encode("latin1")

=> works

from pivy import coin
t = coin.SoText2()
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(t)
s = "Alçapão"
t.string = s

=> doesn't work


from pivy import coin
t = coin.SoText2()
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(t)
s = "??? / ???"
t.string = s

=> doesn't work




Coin4:

from pivy import coin
t = coin.SoText2()
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(t)
s = "Alçapão"
t.string = s.decode("utf8").encode("latin1")

=> doesn't work

from pivy import coin
t = coin.SoText2()
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(t)
s = "Alçapão"
t.string = s

=> works

from pivy import coin
t = coin.SoText2()
sg = Gui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(t)
s = "??? / ???"
t.string = s

=> doesn't work

Everything tested on Windows. The Chinese characters are taken from here: http://de.wikipedia.org/wiki/Chinesische_Zeichenkodierung

EDIT: The Chinese characters are replaced with "?".

shoogen

2014-05-12 15:53

developer   ~0004663

i meant to use only "encode('latin1','replace')" to prevent exceptions like with
u'\u2300'.encode('latin1')

yorik

2014-05-12 18:06

administrator   ~0004665

Ok, thanks a lot for testing Werner!

At least the utf8 / latin1 between coin3 and 4 works OK. I think the chinese texts that don't work are because those characters are not in the default font...

@shoogen, ah, thanks!! I didn't remember that "replace" option existed...

yorik

2015-01-20 23:31

administrator   ~0005684

I think if we release 0.15 with coin4 on all targets, we could consider this solved.

yorik

2015-04-27 14:09

administrator   ~0006090

IMHO we can consider this solved, as all platforms now use coin4... Please reopen if needed

Issue History

Date Modified Username Field Change
2012-10-07 13:13 mrlukeparry New Issue
2012-10-07 13:13 mrlukeparry Status new => assigned
2012-10-07 13:13 mrlukeparry Assigned To => mrlukeparry
2013-08-21 14:10 yorik Note Added: 0003501
2013-08-22 04:08 shoogen Note Added: 0003503
2013-08-22 11:27 yorik Note Added: 0003504
2013-10-25 09:39 mrlukeparry Note Added: 0003805
2014-01-08 20:08 mrlukeparry Status assigned => acknowledged
2014-01-08 20:09 mrlukeparry Target Version 0.14 =>
2014-02-12 12:25 shoogen Relationship added child of 0001404
2014-03-29 17:40 yorik Note Added: 0004516
2014-05-11 17:45 yorik Relationship deleted child of 0001404
2014-05-11 17:45 yorik Relationship added parent of 0001404
2014-05-11 17:46 yorik Note Added: 0004651
2014-05-11 17:46 yorik Status acknowledged => closed
2014-05-11 17:46 yorik Resolution open => fixed
2014-05-11 17:46 yorik Fixed in Version => 0.14
2014-05-11 18:07 shoogen Assigned To mrlukeparry => yorik
2014-05-11 18:07 shoogen Note Added: 0004652
2014-05-11 18:07 shoogen Status closed => feedback
2014-05-11 18:07 shoogen Resolution fixed => reopened
2014-05-11 18:08 shoogen Note Edited: 0004652 View Revisions
2014-05-11 18:22 yorik Note Added: 0004653
2014-05-11 19:41 yorik Status feedback => assigned
2014-05-11 20:00 yorik Note Added: 0004655
2014-05-12 13:48 wmayer Note Added: 0004660
2014-05-12 13:49 wmayer Note Edited: 0004660 View Revisions
2014-05-12 15:53 shoogen Note Added: 0004663
2014-05-12 18:06 yorik Note Added: 0004665
2014-05-17 15:58 yorik Changeset attached => FreeCAD Master master da4f1bda
2014-07-06 15:27 yorik Target Version => 0.15
2014-09-18 09:56 shoogen Relationship added related to 0001745
2014-12-08 14:24 shoogen Tag Attached: encoding
2014-12-08 14:25 shoogen Tag Attached: unicode
2015-01-20 23:31 yorik Note Added: 0005684
2015-01-20 23:32 yorik Fixed in Version 0.14 =>
2015-01-20 23:32 yorik Target Version 0.15 =>
2015-04-27 14:09 yorik Note Added: 0006090
2015-04-27 14:09 yorik Status assigned => closed
2015-04-27 14:09 yorik Resolution reopened => fixed
2015-04-27 14:09 yorik Fixed in Version => 0.16