Skip to content

Instantly share code, notes, and snippets.

@lokedhs
Created December 24, 2020 06:17
Show Gist options
  • Save lokedhs/50b92d6f9d77fc565a0601dc4ca2ee0a to your computer and use it in GitHub Desktop.
Save lokedhs/50b92d6f9d77fc565a0601dc4ca2ee0a to your computer and use it in GitHub Desktop.
(define-g-boxed-cstruct pango-rectangle "PangoRectangle"
(x :int :initform 0)
(y :int :initform 0)
(width :int :initform 0)
(height :int :initform 0))
(defcfun ("pango_layout_get_pixel_extents" %pango-layout-get-pixel-extents) :void
(layout (g-object pango-layout))
(ink-rect (:pointer (:struct pango-rectangle-cstruct)))
(logical-rect (:pointer (:struct pango-rectangle-cstruct))))
(defun pango-layout-get-pixel-extents (layout)
(with-foreign-objects ((ink-rect '(:struct pango-rectangle-cstruct))
(logical-rect '(:struct pango-rectangle-cstruct)))
(%pango-layout-get-pixel-extents layout ink-rect logical-rect)
(let ((a (make-pango-rectangle :x (cffi:foreign-slot-value ink-rect '(:struct pango-rectangle-cstruct) 'x)
:y (cffi:foreign-slot-value ink-rect '(:struct pango-rectangle-cstruct) 'y)
:width (cffi:foreign-slot-value ink-rect '(:struct pango-rectangle-cstruct) 'width)
:height (cffi:foreign-slot-value ink-rect '(:struct pango-rectangle-cstruct) 'height)))
(b (make-pango-rectangle :x (cffi:foreign-slot-value logical-rect '(:struct pango-rectangle-cstruct) 'x)
:y (cffi:foreign-slot-value logical-rect '(:struct pango-rectangle-cstruct) 'y)
:width (cffi:foreign-slot-value logical-rect '(:struct pango-rectangle-cstruct) 'width)
:height (cffi:foreign-slot-value logical-rect '(:struct pango-rectangle-cstruct) 'height))))
(values a b))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment