Merge pull request #319 from MIvanchev/sdl2-ttf

sdl-ttf: loop optimization and eq/eql fix.
This commit is contained in:
David 2026-05-29 21:49:28 -04:00 committed by GitHub
commit f9bda5dd7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View file

@ -3,7 +3,7 @@
(asdf:defsystem #:sdl-fonts
:serial t
:description "SDL-based TTF font rendering for StumpWM."
:version "1.0.0"
:version "1.0.1"
:author "Mihail Ivanchev <contact@ivanchev.net>"
:license "MIT"
:depends-on (#:stumpwm #:cffi #:cffi-libffi)

View file

@ -197,8 +197,8 @@
(defun update-dpi (font drawable)
(multiple-value-bind (hdpi vdpi) (screen-default-dpi (drawable-screen drawable))
(when (or (not (eq (font-hdpi font) hdpi))
(not (eq (font-vdpi font) vdpi)))
(when (or (not (eql (font-hdpi font) hdpi))
(not (eql (font-vdpi font) vdpi)))
(ttf-setfontsizedpi (sdl2-ptr font) (font-size font) hdpi vdpi)
(setf (font-hdpi font) hdpi)
(setf (font-vdpi font) vdpi))))
@ -220,6 +220,7 @@
text &rest keys
&key (start 0) end translate width size)
(declare (ignorable keys start end translate width size))
(declare (optimize (safety 0) (speed 3)))
(when (string= text "")
(return-from draw-image-glyphs))
; Update the DPI in case it has changed (i.e. rendering to another screen).
@ -239,9 +240,11 @@
(sdl-locksurface surf)
(let ((pixels (foreign-slot-value surf '(:struct sdl-surface) 'pixels)))
(dotimes (jj height)
(dotimes (ii width)
(let ((alpha (mem-ref pixels :uint8 (+ (* jj pitch) (* ii 4) 3))))
(setf (aref data jj ii) alpha)))))
; Calculate an offset to the first element of the current row.
(let ((offset (+ 3 (* jj pitch))))
(dotimes (ii width)
(let ((alpha (mem-ref pixels :uint8 (+ offset (* ii 4)))))
(setf (aref data jj ii) alpha))))))
(sdl-unlocksurface surf)
(sdl-freesurface surf)
(let* ((display (xlib:drawable-display drawable))