From ff15c7cd3acec9c9c46f9d53d5e2d9805d90791b Mon Sep 17 00:00:00 2001 From: eknauel Date: Mon, 13 Oct 2003 15:27:19 +0000 Subject: [PATCH] + added support for XGlyphInfo (part of the Xrender extension) + many bugfixes for xft.[ch] + added some interfacing scheme code --- c/libs/xft.c | 32 ++++--- c/libs/xft.h | 2 + c/libs/xrender.c | 61 +++++++++++++ c/libs/xrender.h | 11 +++ scheme/libs/xft.scm | 195 ++++++++++++++++++++++++++++++++++++++++ scheme/libs/xrender.scm | 55 ++++++++++++ 6 files changed, 342 insertions(+), 14 deletions(-) create mode 100644 c/libs/xrender.c create mode 100644 c/libs/xrender.h create mode 100644 scheme/libs/xft.scm create mode 100644 scheme/libs/xrender.scm diff --git a/c/libs/xft.c b/c/libs/xft.c index a588cfd..3232149 100644 --- a/c/libs/xft.c +++ b/c/libs/xft.c @@ -39,7 +39,7 @@ XFT_REC_ACCESSOR_MAKER(scx_enter_xftfontset, XftFontSet, scx_xftfontset_record_t s48_value scx_XftPatternCreate(void) { - return s48_enter_xftpattern(XftPatternCreate()); + return scx_enter_xftpattern(XftPatternCreate()); } @@ -160,7 +160,7 @@ s48_value scx_XftFontMatch(s48_value sdpy, s48_value sscreen, s48_value sxp) XftPattern *p; XftResult r; - p = XftFontMatch(scx_extract_display(sdpy), + p = XftFontMatch((Display *) scx_extract_display(sdpy), s48_extract_integer(sscreen), scx_extract_xftpattern(sxp), &r); @@ -179,16 +179,20 @@ s48_value scx_XftFontOpenPattern(s48_value sdpy, s48_value sxp) s48_value scx_XftFontOpenName(s48_value sdpy, s48_value sscreen, s48_value sname) { - return scx_enter_xftfont(scx_extract_display(sdpy), - scx_extract_integer(sscreen), - s48_extract_string(sname)); + XftFont *xf; + + xf = XftFontOpenName(scx_extract_display(sdpy), s48_extract_integer(sscreen), + s48_extract_string(sname)); + return scx_enter_xftfont(xf); } s48_value scx_XftFontOpenXlfd(s48_value sdpy, s48_value sscreen, s48_value sxlfd) { - return scx_enter_xftfont(scx_extract_display(sdpy), - s48_extract_integer(sscreen), - s48_extract_string(sxlfd)); + XftFont *xf; + + xf = XftFontOpenXlfd(scx_extract_display(sdpy), s48_extract_integer(sscreen), + s48_extract_string(sxlfd)); + return scx_enter_xftfont(xf); } s48_value scx_XftFontClose(s48_value sdpy, s48_value sxf) @@ -256,13 +260,13 @@ s48_value scx_XftDrawDestroy(s48_value sxd) s48_value scx_XftTextExtents8(s48_value sdpy, s48_value sxf, s48_value sstr) { - XGlyphInfo extents; + XGlyphInfo *extents; XftTextExtents8(scx_extract_display(sdpy), scx_extract_xftfont(sxf), (XftChar8 *) s48_extract_string(sstr), S48_STRING_LENGTH(sstr), - &extents); + extents); return scx_enter_glyphinfo(extents); } @@ -291,7 +295,7 @@ s48_value scx_XftDrawRect(s48_value sxd, s48_value sxc, s48_value scx_XftDrawSetClip(s48_value sxd, s48_value sreg) { - return (XftDrawSetClip(scx_extract_draw(sxd), S48_EXTRACT_REGION(sreg)) + return (XftDrawSetClip(scx_extract_xftdraw(sxd), SCX_EXTRACT_REGION(sreg)) ? S48_TRUE : S48_FALSE); } @@ -317,10 +321,10 @@ s48_value scx_XftListFontsPatternObjects(s48_value sdpy, s48_value sscreen, fs = XftListFontsPatternObjects(scx_extract_display(sdpy), s48_extract_integer(sscreen), - scx_extract_xftpatter(sxp), - scx_extract_objectset(sxo)); + scx_extract_xftpattern(sxp), + scx_extract_xftobjectset(sxo)); - return scx_enter_fontset(fs); + return scx_enter_xftfontset(fs); } diff --git a/c/libs/xft.h b/c/libs/xft.h index 14aa278..e9bd71e 100644 --- a/c/libs/xft.h +++ b/c/libs/xft.h @@ -1,5 +1,7 @@ #include #include +#include +#include #ifndef XFT_VERSION #define XFT_VERSION 1 diff --git a/c/libs/xrender.c b/c/libs/xrender.c new file mode 100644 index 0000000..7159591 --- /dev/null +++ b/c/libs/xrender.c @@ -0,0 +1,61 @@ +#include "xrender.h" + +s48_value scx_enter_glyphinfo(XGlyphInfo *i) +{ + s48_value girec = S48_UNSPECIFIC; + S48_DECLARE_GC_PROTECT(1); + + S48_GC_PROTECT_1(girec); + girec = s48_make_record(scx_xrender_glyphinfo_record_type); + S48_RECORD_SET(girec, 0, s48_enter_integer((long) i)); + S48_GC_UNPROTECT(); + return girec; +} + +#define scx_extract_glyphinfo(x) \ + ((XGlyphInfo *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xrender_glyphinfo_record_type))) + +#define XGLYPHINFO_GET(FUN, FN) \ + s48_value FUN(s48_value sv) { \ + return s48_enter_integer(scx_extract_glyphinfo(sv)->FN); \ + } + +#define XGLYPHINFO_SET(FUN, FN) \ + s48_value FUN(s48_value sv, s48_value nv) { \ + scx_extract_glyphinfo(sv)->FN = s48_enter_integer(nv); \ + return S48_UNSPECIFIC; \ + } + +XGLYPHINFO_GET(scx_xglyphinfo_width_get, width); +XGLYPHINFO_GET(scx_xglyphinfo_height_get, height); +XGLYPHINFO_GET(scx_xglyphinfo_x_get, x); +XGLYPHINFO_GET(scx_xglyphinfo_y_get, y); +XGLYPHINFO_GET(scx_xglyphinfo_xOff_get, xOff); +XGLYPHINFO_GET(scx_xglyphinfo_yOff_get, yOff); + +XGLYPHINFO_SET(scx_xglyphinfo_width_set, width); +XGLYPHINFO_SET(scx_xglyphinfo_height_set, height); +XGLYPHINFO_SET(scx_xglyphinfo_x_set, x); +XGLYPHINFO_SET(scx_xglyphinfo_y_set, y); +XGLYPHINFO_SET(scx_xglyphinfo_xOff_set, xOff); +XGLYPHINFO_SET(scx_xglyphinfo_yOff_set, yOff); + +void scx_xrender_init(void) +{ + S48_GC_PROTECT_GLOBAL(scx_xrender_glyphinfo_record_type); + scx_xrender_glyphinfo_record_type = s48_get_imported_binding("xglyphinfo"); + + S48_EXPORT_FUNCTION(scx_xglyphinfo_width_get); + S48_EXPORT_FUNCTION(scx_xglyphinfo_height_get); + S48_EXPORT_FUNCTION(scx_xglyphinfo_x_get); + S48_EXPORT_FUNCTION(scx_xglyphinfo_y_get); + S48_EXPORT_FUNCTION(scx_xglyphinfo_xOff_get); + S48_EXPORT_FUNCTION(scx_xglyphinfo_yOff_get); + + S48_EXPORT_FUNCTION(scx_xglyphinfo_width_set); + S48_EXPORT_FUNCTION(scx_xglyphinfo_height_set); + S48_EXPORT_FUNCTION(scx_xglyphinfo_x_set); + S48_EXPORT_FUNCTION(scx_xglyphinfo_y_set); + S48_EXPORT_FUNCTION(scx_xglyphinfo_xOff_set); + S48_EXPORT_FUNCTION(scx_xglyphinfo_yOff_set); +} diff --git a/c/libs/xrender.h b/c/libs/xrender.h new file mode 100644 index 0000000..567c8b2 --- /dev/null +++ b/c/libs/xrender.h @@ -0,0 +1,11 @@ +#include +#include +#include + +/* add more stuff later */ + +static s48_value scx_xrender_glyphinfo_record_type = S48_UNSPECIFIC; + +s48_value scx_enter_glyphinfo(XGlyphInfo *i); +s48_value scx_extract_glyphinfo(s48_value v); + diff --git a/scheme/libs/xft.scm b/scheme/libs/xft.scm new file mode 100644 index 0000000..d5d48f4 --- /dev/null +++ b/scheme/libs/xft.scm @@ -0,0 +1,195 @@ + +(define-record-type xft-pattern :xft-pattern + (really-make-xft-pattern c-pointer) + xft-pattern? + (c-pointer xft-pattern-c-pointer)) + +(define-exported-binding "xft-pattern" :xft-pattern) + +(define-record-type xft-font :xft-font + (make-xft-font x-pointer) + xft-font? + (x-pointer xft-font-x-pointer)) + +(define-exported-binding "xft-font" :xft-font) + +(define-record-type xft-draw :xft-draw + (make-xft-draw c-pointer) + xft-dra + w? + (c-pointer xft-draw-c-pointer)) + +(define-exported-binding "xft-draw" :xft-draw) + +(define-record-type xft-color :xft-color + (make-xft-color c-pointer) + xft-color? + (c-pointer xft-color-c-pointer)) + +(define-exported-binding "xft-color" :xft-color) + +(define-record-type xft-objectset :xft-objectset + (make-xft-objectset c-pointer) + xft-objectset? + (c-pointer xft-objectset-c-pointer)) + +(define-exported-binding "xft-objectset" :xft-objectset) + +(define-record-type xft-fontset :xft-fontset + (make-xft-fontset c-pointer) + xft-fontset? + (c-pointer xft-fontset-c-pointer)) + +(define-exported-binding "xft-fontset" :xft-fontset) + +;;; add finalizers + +(define (make-xft-pattern) + (let ((xft-pattern (scx-xft-pattern-create))) + (add-finalizer! xft-pattern scx-xft-pattern-destroy) + xft-pattern)) + +(define (scx-xft-pattern-duplicate xft-pattern) + (let ((copy (scx-xft-pattern-duplicate-internal xft-pattern))) + (add-finalizer! copy scx-xft-pattern-destroy) + copy)) + +(define (scx-xft-font-match display screen xft-pattern) + (call-with-values + (lambda (result xft-pattern) + (add-finalizer! xft-pattern scx-xft-pattern-destroy) + (values result xft-pattern)) + (lambda () + (scx-xft-font-match display screen xft-pattern)))) + +(define (scx-xft-font-open-pattern display xft-pattern) + (let ((xft-font (scx-xft-font-open-pattern-internal display xft-pattern))) + (add-finalizer! xft-font scx-xft-font-destroy) + xft-font)) + +(define (scx-xft-font-open-name display screen name) + (let ((xft-font (scx-xft-font-open-name-internal display screen name))) + (add-finalizer! xft-font scx-xft-font-destroy) + xft-font)) + +(define (scx-xft-font-open-xlfd display screen name) + (let ((xft-font (scx-xft-font-open-xlfd-internal display screen name))) + (add-finalizer! xft-font scx-xft-font-destroy) + xft-font)) + +(define (scx-xft-draw-create display drawable visual colormap) + (let ((xft-draw (scx-xft-draw-create-internal display drawable visual colormap))) + (add-finalizer! xft-draw scx-xft-draw-destroy) + xft-draw)) + +(define (scx-xft-draw-create-bitmap display drawable) + (let ((xft-draw (scx-xft-draw-create-bitmap-internal display drawable))) + (add-finalizer! xft-draw scx-xft-draw-destroy) + xft-draw)) + +(define (make-xft-objectset) + (let ((xft-objectset (scx-xft-objectset-create))) + (add-finalizer! xft-objectset scx-xft-objectset-destroy) + xft-objectset)) + +;;; import functions from C code + +(import-lambda-definition scx-xft-pattern-create + () + "scx_XftPatternCreate") + +(import-lambda-definition scx-xft-pattern-duplicate-internal + (xft-pattern) + "scx_XftPatternDuplicate") + +(import-lambda-definition scx-xft-pattern-get + (xft-pattern object id) + "scx_XftPatternGet") + +(import-lambda-definition scx-xft-pattern-add + (xft-pattern object value append?) + "scx_XftPatternAdd") + +(import-lambda-definition scx-xft-font-match + (display screen xft-pattern) + "scx_XftFontMatch") + +(import-lambda-definition scx-xft-font-open-pattern-internal + (display xft-pattern) + "scx_XftFontOpenPattern") + +(import-lambda-definition scx-xft-font-open-name-internal + (display screen name) + "scx_XftFontOpenName") + +(import-lambda-definition scx-xft-font-open-xlfd-internal + (display screen xlfd-name) + "scx_XftFontOpenXlfd") + +(import-lambda-definition scx-xft-font-close + (display xft-font) + "scx_XftFontClose") + +(import-lambda-definition scx-xft-draw-create-internal + (display drawable visual colormap) + "scx_XftDrawCreate") + +(import-lambda-definition scx-xft-draw-create-bitmap-internal + (display drawable) + "scx_XftDrawCreateBitmap") + +(import-lambda-definition scx-xft-draw-change + (xft-draw drawable) + "scx_XftDrawChange") + +(import-lambda-definition scx-xft-draw-display + (xft-draw) + "scx_XftDrawDisplay") + +(import-lambda-definition scx-xft-draw-drawable + (xft-draw) + "scx_XftDrawDrawable") + +(import-lambda-definition scx-xft-draw-colormap + (xft-draw) + "scx_XftDrawColormap") + +(import-lambda-definition scx-xft-draw-visual + (xft-draw) + "scx_XftDrawVisual") + +(import-lambda-definition scx-xft-draw-destroy + (xft-draw) + "scx_XftDrawDestroy") + +(import-lambda-definition scx-xft-text-extents-8bit + (display xft-font string) + "scx_XftTextExtents8") + +(import-lambda-definition scx-xft-draw-string-8bit + (xft-draw xft-color xft-font x y string) + "scx_XftDrawString8") + +(import-lambda-definition scx-xft-draw-rect + (xft-draw xft-color x y w h) + "scx_XftDrawRect") + +(import-lambda-definition scx-xft-draw-set-clip + (xft-draw region) + "scx_XftDrawSetClip") + +(import-lambda-definition scx-xft-object-set-create + () + "scx_XftObjectSetCreate") + +(import-lambda-definition scx-xft-object-set-add + (xft-objectset object) + "scx_XftObjectSetAdd") + +(import-lambda-definition scx-xft-list-fonts-pattern-objects + (diplay screen xft-pattern xft-objectset) + "scx_XftListFontsPatternObjects") + + + + \ No newline at end of file diff --git a/scheme/libs/xrender.scm b/scheme/libs/xrender.scm new file mode 100644 index 0000000..42ddc93 --- /dev/null +++ b/scheme/libs/xrender.scm @@ -0,0 +1,55 @@ + +(define-record-type xglyphinfo :xglyphinfo + (make-xglyphinfo c-pointer) + xglyphinfo? + (c-pointer xglyphinfo-c-pointer)) + +(define-exported-binding "xglyphinfo" :xglyphinfo) + +(import-lambda-definition scx-xglyphinfo-width + (xglyphinfo) + "scx_xglyphinfo_width_get") + +(import-lambda-definition scx-xglyphinfo-height + (xglyphinfo) + "scx_xglyphinfo_height_get") + +(import-lambda-definition scx-xglyphinfo-x + (xglyphinfo) + "scx_xglyphinfo_x_get") + +(import-lambda-definition scx-xglyphinfo-y + (xglyphinfo) + "scx_xglyphinfo_y_get") + +(import-lambda-definition scx-xglyphinfo-xOff + (xglyphinfo) + "scx_xglyphinfo_xOff_get") + +(import-lambda-definition scx-xglyphinfo-yOff + (xglyphinfo) + "scx_xglyphinfo_yOff_get") + +(import-lambda-definition set-scx-xglyphinfo-width! + (xglyphinfo new-value) + "scx_xglyphinfo_width_set") + +(import-lambda-definition set-scx-xglyphinfo-height! + (xglyphinfo new-value) + "scx_xglyphinfo_height_set") + +(import-lambda-definition set-scx-xglyphinfo-x! + (xglyphinfo new-value) + "scx_xglyphinfo_x_set") + +(import-lambda-definition set-scx-xglyphinfo-y! + (xglyphinfo new-value) + "scx_xglyphinfo_y_set") + +(import-lambda-definition set-scx-xglyphinfo-xOff! + (xglyphinfo new-value) + "scx_xglyphinfo_xOff_set") + +(import-lambda-definition set-scx-xglyphinfo-yOff! + (xglyphinfo new-value) + "scx_xglyphinfo_yOff_set")