[Impromptu] Using non-English characters
Andrew Sorensen
andrew at moso.com.au
Mon Mar 9 00:44:33 GMT 2009
I'm afraid at the moment Impromptu only fully supports 7-bit ASCII
within the editor/interpreter.
However ...
The best way to handle non-english characters in impromptu is to use
NSString - which gives you UTF. Additionally as of v1.4 (soon to be
released) you can draw nsstrings and create paths from nsstrings
(exactly as you do now but passing an nsstring). I have been using
this recently to print multi-lingual graphics (across 20 languages).
Unfortunately this doesn't help you with string literals which are
restricted to 7-bit ASCII. I have been thinking about adding UTF
support to Impromptu but not sure about when this might happen. In
the mean time nsstring should do everything you need.
Cheers,
Andrew.
;;
;; utf-8 example from impromptu v1.4
;; original utf8 Hankaku:
アイウエオカキクケコサシスセソタチツテ
;;
(define canvas (gfx:make-canvas 350 100))
(gfx:clear-canvas (now) canvas '(0 0 0 1))
(define my-string (objc:call "NSString"
"stringWithContentsOfFile:encoding:error:" "/tmp/japanese.txt" 4 0))
(gfx:draw-text (now) canvas my-string (gfx:make-text-style "Arial" 32
'(1 1 1 1)) '(20 20 350 50))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: japanese.png
Type: image/png
Size: 7994 bytes
Desc: not available
Url : http://lists.moso.com.au/pipermail/impromptu/attachments/20090309/27633aff/attachment-0002.png
-------------- next part --------------
;; or more interestingly as a path
;; original utf8 Kanji てすと
(define text-path (gfx:make-text 100 100 "Hiragino Mincho Pro" 18 my-
string))
(dotimes (i 10)
(gfx:draw-path (now) canvas text-path (list 1 0 0 1) (list (* .1
i) .1 (* i .1) .8) 2)
(gfx:scale-path (now) text-path 1.1 1.1 *gfx:centre-scale*)
(gfx:rotate-path (now) text-path 36 100 100 *degrees*))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: out.png
Type: image/png
Size: 65670 bytes
Desc: not available
Url : http://lists.moso.com.au/pipermail/impromptu/attachments/20090309/27633aff/attachment-0003.png
-------------- next part --------------
On 09/03/2009, at 4:37 AM, Glen F wrote:
> Hi there, I was wondering if there is any way to use non-English
> characters in Impromptu. It seems to convert accented characters to
> non-accented ones in string quoting...
>
> (define text "Pués, ¡bueno!")
> (print text)
>
> This prints "Pues, !bueno!", having converted the 'é' and the '¡' to
> 'e' and '!' respectively...
>
> I've managed to get a non-English string in several ways...for
> example, loading in a text file that contains these characters. Or,
> doing something like this:
>
> (define *e-acute* (integer->char 142))
> (define *!-invert* (integer->char 193))
>
> (define text (string-append "Pu" (string *e-acute*) "s, " (string *!-
> invert*) "bueno!"))
> (print text)
>
> This prints the correct string. However, sadly, if I try to use
> gfx:draw-text with such a string, I get nothing... Using gfx:add-
> text to a path, I get the string with the special characters skipped.
>
> (gfx:make-canvas))
> (gfx:clear-canvas (now) *canvas* '(0 0 0 1))
> (define *text-style* (gfx:make-text-style "Arial" 24.0 (list 1 1 1
> 1)))
> (gfx:draw-text (now) *canvas* text *text-style* '(50 50))
>
> Is there any way to be able to display non-English characters in
> Impromptu? I'm not asking for full multi-byte/Unicode character
> support or anything, just a workaround (the ones I'm interested in
> are still 8-bit ASCII characters)...
>
> Thanks,
> Glen.
>
> _______________________________________________
> Impromptu mailing list
> Impromptu at lists.moso.com.au
> http://lists.moso.com.au/mailman/listinfo/impromptu
More information about the Impromptu
mailing list