guile-fontconfig/fontconfig/bindings.scm

115 lines
3.1 KiB
Scheme
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

;;; guile-fontconfig --- FFI bindings for FontConfig
;;; Copyright © 2021 Nicolò Balzarotti <nicolo@nixo.xyz>
;;;
;;; This file is part of guile-fontconfig.
;;;
;;; Guile-fontconfig is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public License
;;; as published by the Free Software Foundation; either version 3 of
;;; the License, or (at your option) any later version.
;;;
;;; Guile-fontconfig is distributed in the hope that it will be
;;; useful, but WITHOUT ANY WARRANTY; without even the implied
;;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
;;; See the GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with guile-fontconfig. If not, see
;;; <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Low-level FFI bindings.
;;
;;; Code:
(define-module (fontconfig bindings)
#:use-module (fontconfig config)
#:use-module (system foreign)
#:export (fontconfig-func
define-foreign
fontconfig-pattern-create fontconfig-pattern-destroy
fontconfig-object-set-destroy))
(define fontconfig-func
(let ((lib (dynamic-link %libfontconfig)))
(lambda (return-type function-name arg-types)
"Return a procedure for the foreign function FUNCTION-NAME in
the FontConfig shared library. That function must return a value of
RETURN-TYPE and accept arguments of ARG-TYPES."
(pointer->procedure return-type
(dynamic-func function-name lib)
arg-types))))
(define-syntax-rule (define-foreign name return-type func-name arg-types)
(define-public name
(fontconfig-func return-type func-name arg-types)))
;;;
;;; Initialization
;;;
(define-foreign fontconfig-init-load-config-and-fonts
'* "FcInitLoadConfigAndFonts" '())
(define-foreign fontconfig-finalize
void "FcFini" '())
;;;
;;; Version
;;;
(define-foreign fontconfig-get-version
int "FcGetVersion" '())
;;;
;;; Pattern
;;;
(define-foreign fontconfig-pattern-create
'* "FcPatternCreate" '())
(define fontconfig-pattern-destroy
(dynamic-func "FcPatternDestroy" (dynamic-link %libfontconfig)))
(define-foreign fontconfig-pattern-add-string
int "FcPatternAddString" '(* * *))
(define-foreign fontconfig-pattern-add-double
int "FcPatternAddDouble" `(* * ,double))
(define-foreign fontconfig-pattern-add-integer
int "FcPatternAddInteger" `(* * ,int))
(define-foreign fontconfig-pattern-add-bool
int "FcPatternAddBool" `(* * ,int))
(define-foreign fontconfig-name-unparse
'* "FcNameUnparse" '(*))
(define-foreign fontconfig-pattern-format
'* "FcPatternFormat" '(* *))
;; FcResult (FcPattern *p, const char *object, int id, FcValue *v);
(define-foreign fontconfig-pattern-get
int "FcPatternGet" `(* * ,int *))
;;;
;;; Object Set
;;;
(define-foreign fontconfig-object-set-create
'* "FcObjectSetCreate" '())
(define-foreign fontconfig-object-set-add
int "FcObjectSetAdd" '(* *))
(define-foreign fontconfig-font-list
'* "FcFontList" '(* * *))
(define fontconfig-object-set-destroy
(dynamic-func "FcObjectSetDestroy" (dynamic-link %libfontconfig)))