[cl-gd-devel] New release 0.5.4

Jong-won Choi jc at itsec.co.kr
Tue Apr 10 00:57:06 UTC 2007


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)))))))



More information about the Cl-gd-devel mailing list