[cells-gtk-devel] UTF-8 support -- Patch

Peter Hildebrandt peter.hildebrandt at gmail.com
Sat Jan 19 18:42:03 UTC 2008


> Most widgets work now. Just a list-view is still problematic.
> Entries containing special characters are still not displayed correctly:
> 
> (mk-listbox :columns (def-columns (:string (:title "foo äöüß bar")))
>             :items '( '("foo äöüß bar") '("foo äöüß bar")))

I fixed that one, too.  The problem was roughly that the string was 
converted to utf-8 *twice*.  cells-gtk read a utf-8 string back from 
gtk, forgot to decode it, then encoded it *again* and sent it back to gtk.

The fix is fairly straight forward.  However, I decided to move this 
stuff into a new file, thus factoring out the implementation dependent 
stuff.  Thus the patch got somewhat big, maybe it does more than you 
want.  I'll mail it in a second to the list and cc you.

If you just want to get this working, just add the following function to 
gtk-utilities.lisp

(defun utf-8-to-lisp (str)
   (when str
    #+sbcl (let ((s (sb-ext:string-to-octets str :external-format :utf-8)))
	    (sb-ext:octets-to-string
	     (coerce (loop for i from 0 below (length s)
			for b = (aref s i)
			collect b
			if (= b 195) do (incf i 2)) ; ph: gtk gives us 4 bytes per char -- no 
idea why.
		     '(vector (unsigned-byte 8)))
	     :external-format :utf-8))
    #-(or sbcl) str))

and change the function gtk-tree-model-get-typed-item-value in 
gtk-utilities.lisp:

....
	  (cond
	    (ret$ (utf-8-to-lisp (uffi:convert-from-cstring ret$))) ; ph 
01/2008: here we need to convert back from gtk utf-8 to lisp
	    ((eq col-type :boolean)
...

That did the trick for me.

Peter


> Should list-store check weather item-types is string and do 
> the conversation?
> 
> Best, Ingo
> 
> 



More information about the cells-gtk-devel mailing list