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

Ingo Bormuth ibormuth at efil.de
Sun Jan 20 14:09:43 UTC 2008


Hi Peter,

thank you for your cumulative patch. I'm really looking forward to 
playing with cells-trie-view, cairo and the threading code.

> 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

In my hands utf-8-to-lisp didn't work for multi byte characters 
like #\REGISTERED_SIGN. I changed it to

   (defun utf-8-to-lisp (str)
      (when str
       #+sbcl (sb-ext:octets-to-string 
                 (sb-ext:string-to-octets str :external-format :latin1) 
                 :external-format :utf-8)
       #-(or sbcl) str))

and now everything works like a charm.


Btw, find the patch in my git repository at
http://public.efil.de/gitweb/?p=cells-gtk/.git;a=commitdiff;h=48c5592f984460269bb09415b472a8495db73251


Btw', what do you think about putting all utf8 trancoding directly 
into gtk-ffi's macro def-gtk-function?

The current usage

   (def-gtk-lib-functions :gtk
     (gtk-entry-set-text :void ((entry :pointer) (text :gtk-string)))
     (gtk-entry-get-text :pointer ((entry :pointer)))
     ...

would become


   (def-gtk-lib-functions :gtk
     (gtk-entry-set-text :void ((entry :pointer) (text :string)))
     (gtk-entry-get-text :string ((entry :pointer)))
     ...

In def-gtk-function we would have something along the line of

   (mapcar (lambda (arg)
              (if (equal (cdr arg) :string)
                  (cons (lisp-to-gtk-string (car arg))
                        (:gtk-pointer))
                  arg))
           arguments)

and

   (if (equal return-type :string)
       (gtk-string-to-lisp result)
       result)

to have all conversions handled transparently.

Lisp-to-gtk-string should be similar to to-gtk-string.
Note, to-gtk-string uses g-locale-to-utf8 which is itself 
defined using def-gtk-lib-functions.

I'd just be interested in what you think of the approach
and whether I missed something here.

>
> ... (BTW, it is "whether" ;-) )
>

Danke, die beide bekomme ich immer durcheinander.
Mal sehn' Wetter ich das in Zukunft hinbekomme :)

Ingo


-- 
Ingo Bormuth, voicebox & fax: +49-(0)-12125-10226517
public key 86326EC9, http://ibormuth.efil.de/contact




More information about the cells-gtk-devel mailing list