[cl-gd-devel] :convert-chars of draw-freetype-string
I don't know much about gd and cl-gd and currently I don't understand what :convert-chars does so I'm trying to understand it. When I tried utf-8 Korean string with test-020, it did not render characters correctly. But if I set ':convert-chars nil' all the characters rendered correctly. I guess maybe gd itself handles non-ascii characters correctly(if this is true, maybe the :convert-chars can be removed from the function) Please use Korean string "커먼리습" (utf-8 encoded) for "Common Lisp", install ttf-unfonts package(Ubuntu and Debian), and use "/usr/share/fonts/truetype/unfonts/UnBatang.ttf" to exercise it with test-020. Thanks Jong-won Choi
On Fri, 30 Mar 2007 07:15:02 +0900, Jong-won Choi <jc@itsec.co.kr> wrote:
I don't know much about gd and cl-gd and currently I don't understand what :convert-chars does so I'm trying to understand it.
When I tried utf-8 Korean string with test-020, it did not render characters correctly. But if I set ':convert-chars nil' all the characters rendered correctly.
I guess maybe gd itself handles non-ascii characters correctly(if this is true, maybe the :convert-chars can be removed from the function)
Please use Korean string "커먼리습" (utf-8 encoded) for "Common Lisp", install ttf-unfonts package(Ubuntu and Debian), and use "/usr/share/fonts/truetype/unfonts/UnBatang.ttf" to exercise it with test-020.
That's the result I get: http://miles.agharta.de/strings.png Is that wrong? Are you sure you're using the latest version of CL-GD?
Edi Weitz wrote:
http://miles.agharta.de/strings.png
Is that wrong? Are you sure you're using the latest version of CL-GD?
No, you got correct result. Yes I downloaded latest cl-gd couple of days ago. Are you sure you got the png image without ':convert-chars nil'? I'm using Ubuntu LTS with Korean locale. With ':convert-chars t', the default, I got incorrect result and with ':convert-chars nil' I got correct result.
On Fri, 30 Mar 2007 17:49:08 +0900, Jong-won Choi <jc@itsec.co.kr> wrote:
Are you sure you got the png image without ':convert-chars nil'?
Yes.
I'm using Ubuntu LTS with Korean locale. With ':convert-chars t', the default, I got incorrect result and with ':convert-chars nil' I got correct result.
I now remember that we had something similar on the mailing list a few weeks ago - check the archive. It might be due to different versions of libgd. Or your locale is the culprit. You could try with (map 'string #'code-char '(52964 47676 47532 49845)) instead of a literal string just to be sure. That's what I did.
Edi Weitz wrote:
I've released 0.5.4 which hopefully fixes this.
The bug in draw-freetype-string is still there. Now when _image_ is *default-image* and _do-not-draw_ is T, gd-image-string-ft* function will be called with an image instead of *null-image* Following code - put the code for _do-not-draw_ into inside of with-transformed-alternative - seems working (on my local machine): (defun draw-freetype-string (x y string &key (anti-aliased t) (point-size 12.0d0) (angle 0.0d0) (convert-chars t) line-spacing (font-name *default-font*) do-not-draw (color *default-color*) (image *default-image*)) "Draws the string STRING in color COLOR at position \(X,Y) using the FreeType library. FONT-NAME is the full path \(a pathname or a string) to a TrueType font file, or a font face name if the GDFONTPATH environment variable or FreeType's DEFAULT_FONTPATH variable have been set intelligently. The string may be arbitrarily scaled \(POINT-SIZE) and rotated \(ANGLE in radians). The direction of rotation is counter-clockwise, with 0 radians \(0 degrees) at 3 o'clock and PI/2 radians \(90 degrees) at 12 o'clock. Note that the ANGLE argument is purposefully _not_ affected by WITH-TRANSFORMATION. If ANTI-ALIASED if false, anti-aliasing is disabled. It is enabled by default. To output multiline text with a specific line spacing, provide a value for LINE-SPACING, expressed as a multiple of the font height. The default is to use 1.05. The string may contain XML character entity references like \"À\". If CONVERT-CHARS is true \(which is the default) characters of STRING with CHAR-CODE greater than 127 are converted accordingly. This of course pre-supposes that your Lisp's CHAR-CODE function returns ISO/IEC 10646 (Unicode) character codes. The return value is an array containing 8 elements representing the 4 corner coordinates \(lower left, lower right, upper right, upper left) of the bounding rectangle around the string that was drawn. The points are relative to the text regardless of the angle, so \"upper left\" means in the top left-hand corner seeing the text horizontally. Set DO-NOT-DRAW to true to get the bounding rectangle without rendering. This is a relatively cheap operation if followed by a rendering of the same string, because of the caching of the partial rendering during bounding rectangle calculation." (check-type string string) (check-type font-name (or pathname string)) (with-transformed-alternative ((x x-transformer) (y y-transformer) ((deref-array c-bounding-rectangle '(:array :int) i) x-inv-transformer) ((deref-array c-bounding-rectangle '(:array :int) (1+ i)) y-inv-transformer)) (cond (do-not-draw (setq color 0 image *null-image*)) (t (check-type color integer) (check-type image image))) (when (pathnamep font-name) (setq font-name (namestring font-name))) (when convert-chars (setq string (convert-to-char-references string))) (with-cstring (c-font-name font-name) (with-cstring (c-string string) (with-safe-alloc (c-bounding-rectangle (allocate-foreign-object :int 8) (free-foreign-object c-bounding-rectangle)) (let ((msg (convert-from-cstring (cond (line-spacing (with-foreign-object (strex 'gd-ft-string-extra) (setf (get-slot-value strex 'gd-ft-string-extra 'flags) +gd-ftex-linespace+ (get-slot-value strex 'gd-ft-string-extra 'line-spacing) (coerce line-spacing 'double-float)) (gd-image-string-ft-ex (img image) c-bounding-rectangle (if anti-aliased color (- color)) c-font-name (coerce point-size 'double-float) (coerce angle 'double-float) x y c-string strex))) (t (gd-image-string-ft (img image) c-bounding-rectangle (if anti-aliased color (- color)) c-font-name (coerce point-size 'double-float) (coerce angle 'double-float) x y c-string)))))) (when msg (error "Error in FreeType library: ~A" msg)) (let ((bounding-rectangle (make-array 8))) ;; strange iteration due to WITH-TRANSFORMED-ALTERNATIVE (loop for i below 8 by 2 do (setf (aref bounding-rectangle i) (deref-array c-bounding-rectangle '(:array :int) i)) (setf (aref bounding-rectangle (1+ i)) (deref-array c-bounding-rectangle '(:array :int) (1+ i)))) bounding-rectangle)))))))
On Tue, 10 Apr 2007 09:57:06 +0900, Jong-won Choi <jc@itsec.co.kr> wrote:
The bug in draw-freetype-string is still there.
Sorry for the delay and thanks for your fix. I've made a new release and I hope I didn't botch it again. Unfortunately, I'm pretty busy at the moment and I don't have enough time to play with CL-GD myself. Cheers, Edi.
participants (2)
-
Edi Weitz -
Jong-won Choi