From bd39b49201d771da5175da62b077045db9f70716 Mon Sep 17 00:00:00 2001 From: eknauel Date: Tue, 14 Oct 2003 15:27:33 +0000 Subject: [PATCH] + better handling of functions specific to Xft 2 + added interface definitions --- c/libs/xft.c | 48 +++++++++++++++------------------ c/libs/xft.h | 36 +++++++++++++++++-------- scheme/libs/libs-interfaces.scm | 36 +++++++++++++++++++++++++ scheme/libs/xft.scm | 46 +++++++++++++++++++++++-------- 4 files changed, 117 insertions(+), 49 deletions(-) diff --git a/c/libs/xft.c b/c/libs/xft.c index 3232149..005567e 100644 --- a/c/libs/xft.c +++ b/c/libs/xft.c @@ -1,42 +1,17 @@ #include "xft.h" -/* XftPattern */ XFT_REC_ACCESSOR_MAKER(scx_enter_xftpattern, XftPattern, scx_xftpattern_record_type); -#define scx_extract_xftpattern(x) \ - ((XftPattern *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftpattern_record_type))) - -/* XftFont */ XFT_REC_ACCESSOR_MAKER(scx_enter_xftfont, XftFont, scx_xftfont_record_type); -#define scx_extract_xftfont(x) \ - ((XftFont *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftfont_record_type))) - -/* XftDraw */ XFT_REC_ACCESSOR_MAKER(scx_enter_xftdraw, XftDraw, scx_xftdraw_record_type); -#define scx_extract_xftdraw(x) \ - ((XftDraw *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftdraw_record_type))) - -/* XftColor */ XFT_REC_ACCESSOR_MAKER(scx_enter_xftcolor, XftColor, scx_xftcolor_record_type); -#define scx_extract_xftcolor(x) \ - ((XftColor *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftcolor_record_type))) - -/* XftObjectSet */ XFT_REC_ACCESSOR_MAKER(scx_enter_xftobjectset, XftObjectSet, scx_xftobjectset_record_type); -#define scx_extract_xftobjectset(x) \ - ((XftObjectSet *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftobjectset_record_type))) - -/* XftFontSet */ XFT_REC_ACCESSOR_MAKER(scx_enter_xftfontset, XftFontSet, scx_xftfontset_record_type); -#define scx_extract_xftfontset(x) \ - ((XftFontSet *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftfontset_record_type))) - - s48_value scx_XftPatternCreate(void) { return scx_enter_xftpattern(XftPatternCreate()); @@ -231,25 +206,42 @@ s48_value scx_XftDrawChange(s48_value sxd, s48_value sdrawable) scx_extract_drawable(sdrawable)); return S48_UNSPECIFIC; } - + + s48_value scx_XftDrawDisplay(s48_value sxd) { +#if SCX_XFT_VERSION > 1 return scx_enter_display(XftDrawDisplay(scx_extract_xftdraw(sxd))); +#else + return S48_FALSE; +#endif } s48_value scx_XftDrawDrawable(s48_value sxd) { +#if SCX_XFT_VERSION > 1 return scx_enter_drawable(XftDrawDrawabale(scx_extract_xftdraw(sxd))); +#else + return S48_FALSE; +#endif } s48_value scx_XftDrawColormap(s48_value sxd) { +#if SCX_XFT_VERSION > 1 return scx_enter_colormap(XftDrawColormap(scx_extract_xftdraw(sxd))); +#else + return S48_FALSE; +#endif } s48_value scx_XftDrawVisual(s48_value sxd) { +#if SCX_XFT_VERSION > 1 return scx_enter_visual(XftDrawVisual(scx_extract_xftdraw(sxd))); +#else + return S48_FALSE; +#endif } s48_value scx_XftDrawDestroy(s48_value sxd) @@ -295,7 +287,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_xftdraw(sxd), SCX_EXTRACT_REGION(sreg)) + return (XftDrawSetClip(scx_extract_xftdraw(sxd), scx_extract_region(sreg)) ? S48_TRUE : S48_FALSE); } @@ -341,6 +333,8 @@ void scx_xft_init(void) GC_PROTECT_ENTER_INT(scx_XftResultNoMatch, XftResultNoMatch); GC_PROTECT_ENTER_INT(scx_XftResultTypeMismatch, XftResultTypeMismatch); GC_PROTECT_ENTER_INT(scx_XftResultNoId, XftResultNoId); + GC_PROTECT_ENTER_INT(scx_XftVersionMajor, SCX_XFT_VERSION_MAJOR); + GC_PROTECT_ENTER_INT(scx_XftVersionMinor, SCX_XFT_VERSION_MINOR); S48_EXPORT_FUNCTION(scx_XftPatternCreate); S48_EXPORT_FUNCTION(scx_XftPatternDestroy); diff --git a/c/libs/xft.h b/c/libs/xft.h index e9bd71e..ba6ee0f 100644 --- a/c/libs/xft.h +++ b/c/libs/xft.h @@ -3,8 +3,14 @@ #include #include -#ifndef XFT_VERSION -#define XFT_VERSION 1 +#ifdef XFT_VERSION +#define SCX_XFT_VERSION XFT_MAJOR +#define SCX_XFT_VERSION_MAJOR XFT_MAJOR +#define SCX_XFT_VERSION_MINOR XFT_MINOR +#else +#define SCX_XFT_VERSION 1 +#define SCX_XFT_VERSION_MAJOR 1 +#define SCX_XFT_VERSION_MINOR 0 #endif #define SCX_XFT_FAMILY 0 /* String */ @@ -54,14 +60,14 @@ static struct xft_pattern_property xft_pattern_property_tbl [] = { {SCX_XFT_WEIGHT, XFT_WEIGHT, SCX_XFT_INT}, {SCX_XFT_SIZE, XFT_SIZE, SCX_XFT_DOUBLE}, {SCX_XFT_PIXEL_SIZE, XFT_PIXEL_SIZE, SCX_XFT_DOUBLE}, -#if XFT_VERSION < 2 +#if SCX_XFT_VERSION < 2 {SCX_XFT_ENCODING, XFT_ENCODING, SCX_XFT_STRING}, #else {SCX_XFT_ENCODING, XFT_ENCODING, SCX_XFT_UNIMPLEMENTED}, #endif {SCX_XFT_SPACING, XFT_SPACING, SCX_XFT_INT}, {SCX_XFT_FOUNDRY, XFT_FOUNDRY, SCX_XFT_STRING}, -#if XFT_VERSION < 2 +#if SCX_XFT_VERSION < 2 {SCX_XFT_CORE, XFT_CORE, SCX_XFT_BOOL}, #else {SCX_XFT_CORE, XFT_CORE, SCX_XFT_UNIMPLEMENTED}, @@ -78,7 +84,7 @@ static struct xft_pattern_property xft_pattern_property_tbl [] = { {SCX_XFT_RENDER, XFT_RENDER, SCX_XFT_BOOL}, {SCX_XFT_MINSPACE, XFT_MINSPACE, SCX_XFT_BOOL}, {SCX_XFT_DPI, XFT_DPI, SCX_XFT_DOUBLE}, -#if XFT_VERSION < 2 +#if SCX_XFT_VERSION < 2 {SCX_XFT_CHAR_WIDTH, XFT_CHAR_WIDTH, SCX_XFT_INT}, {SCX_XFT_CHAR_HEIGHT, XFT_CHAR_HEIGHT, SCX_XFT_INT}, #else @@ -105,6 +111,8 @@ static s48_value scx_XftResultMatch = S48_UNSPECIFIC; static s48_value scx_XftResultNoMatch = S48_UNSPECIFIC; static s48_value scx_XftResultTypeMismatch = S48_UNSPECIFIC; static s48_value scx_XftResultNoId = S48_UNSPECIFIC; +static s48_value scx_XftVersionMajor = S48_UNSPECIFIC; +static s48_value scx_XftVersionMinor = S48_UNSPECIFIC; #define XFT_REC_ACCESSOR_MAKER(FN, TN, RN) \ s48_value FN(TN *p) \ @@ -125,22 +133,28 @@ static s48_value scx_XftResultNoId = S48_UNSPECIFIC; /* function prototypes */ s48_value scx_enter_xftpattern(XftPattern *p); -s48_value scx_extract_xftpattern(s48_value s); +#define scx_extract_xftpattern(x) \ + ((XftPattern *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftpattern_record_type))) s48_value scx_enter_xftfont(XftFont *f); -s48_value scx_extract_xftfont(s48_value s); +#define scx_extract_xftfont(x) \ + ((XftFont *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftfont_record_type))) s48_value scx_enter_xftdraw(XftDraw *d); -s48_value scx_extract_xftdraw(s48_value s); +#define scx_extract_xftdraw(x) \ + ((XftDraw *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftdraw_record_type))) s48_value scx_enter_xftcolor(XftColor *c); -s48_value scx_extract_xftcolor(s48_value s); +#define scx_extract_xftcolor(x) \ + ((XftColor *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftcolor_record_type))) s48_value scx_enter_xftobjectset(XftObjectSet *os); -s48_value scx_extract_xftobjectset(s48_value s); +#define scx_extract_xftobjectset(x) \ + ((XftObjectSet *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftobjectset_record_type))) s48_value scx_enter_xftfontset(XftFontSet *fs); -s48_value scx_extract_xftfontset(s48_value s); +#define scx_extract_xftfontset(x) \ + ((XftFontSet *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xftfontset_record_type))) struct xft_pattern_property* lookup_pattern_property_by_id(int id); diff --git a/scheme/libs/libs-interfaces.scm b/scheme/libs/libs-interfaces.scm index 5199c57..a0d21b8 100644 --- a/scheme/libs/libs-interfaces.scm +++ b/scheme/libs/libs-interfaces.scm @@ -2,3 +2,39 @@ (export create-pixmap-from-data read-file-to-pixmap ((xpm-attribute) :syntax))) + +(define-interface xft-interface + (export + xft-pattern? + xft-font? + xft-color? + xft-objectset? + xft-fontset? + make-xft-pattern + scx-xft-pattern-duplicate + scx-xft-font-match + scx-xft-font-open-pattern + scx-xft-font-open-name + scx-xft-font-open-xlfd + scx-xft-draw-create + scx-xft-draw-create-bitmap + make-xft-objectset + scx-xft-pattern-get + scx-xft-pattern-add + scx-xft-draw-create + scx-xft-draw-create-bitmap + scx-xft-draw-change + scx-xft-text-extents-8bit + scx-xft-draw-rect + scx-xft-draw-set-clip + scx-xft-objectset-add + scx-xft-list-fonts-pattern-objects + scx-xft-version-major + scx-xft-version-minor)) + +(define-interface xft-v2-additions-interface + (export + scx-xft-draw-display + scx-xft-draw-drawable + scx-xft-draw-colormap + scx-xft-draw-visual)) \ No newline at end of file diff --git a/scheme/libs/xft.scm b/scheme/libs/xft.scm index d5d48f4..00546f3 100644 --- a/scheme/libs/xft.scm +++ b/scheme/libs/xft.scm @@ -60,21 +60,21 @@ (add-finalizer! xft-pattern scx-xft-pattern-destroy) (values result xft-pattern)) (lambda () - (scx-xft-font-match display screen xft-pattern)))) + (scx-xft-font-match-internal 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) + (add-finalizer! xft-font scx-xft-font-close) 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) + (add-finalizer! xft-font scx-xft-font-close) 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) + (add-finalizer! xft-font scx-xft-font-close) xft-font)) (define (scx-xft-draw-create display drawable visual colormap) @@ -92,6 +92,30 @@ (add-finalizer! xft-objectset scx-xft-objectset-destroy) xft-objectset)) +(define (scx-xft-draw-display xft-draw) + (let ((display (scx-xft-draw-display-internal xft-draw))) + (if display + display + (error "XftDrawDisplay() unavailable in this version of Xft")))) + +(define (scx-xft-draw-drawable xft-draw) + (let ((drawable (scx-xft-draw-drawable-internal xft-draw))) + (if drawable + drawable + (error "XftDrawDrawable() unavailable in this version of Xft")))) + +(define (scx-xft-draw-colormap xft-draw) + (let ((colormap (scx-xft-draw-colormap-internal xft-draw))) + (if colormap + colormap + (error "XftDrawColormap() unavailable in this version of Xft")))) + +(define (scx-xft-draw-visual xft-draw) + (let ((visual (scx-xft-draw-visual-internal xft-draw))) + (if visual + visual + (error "XftDrawVisual() unavailable in this version of Xft")))) + ;;; import functions from C code (import-lambda-definition scx-xft-pattern-create @@ -110,7 +134,7 @@ (xft-pattern object value append?) "scx_XftPatternAdd") -(import-lambda-definition scx-xft-font-match +(import-lambda-definition scx-xft-font-match-internal (display screen xft-pattern) "scx_XftFontMatch") @@ -142,19 +166,19 @@ (xft-draw drawable) "scx_XftDrawChange") -(import-lambda-definition scx-xft-draw-display +(import-lambda-definition scx-xft-draw-display-internal (xft-draw) "scx_XftDrawDisplay") -(import-lambda-definition scx-xft-draw-drawable +(import-lambda-definition scx-xft-draw-drawable-internal (xft-draw) "scx_XftDrawDrawable") -(import-lambda-definition scx-xft-draw-colormap +(import-lambda-definition scx-xft-draw-colormap-internal (xft-draw) "scx_XftDrawColormap") -(import-lambda-definition scx-xft-draw-visual +(import-lambda-definition scx-xft-draw-visual-internal (xft-draw) "scx_XftDrawVisual") @@ -178,11 +202,11 @@ (xft-draw region) "scx_XftDrawSetClip") -(import-lambda-definition scx-xft-object-set-create +(import-lambda-definition scx-xft-objectset-create () "scx_XftObjectSetCreate") -(import-lambda-definition scx-xft-object-set-add +(import-lambda-definition scx-xft-objectset-add (xft-objectset object) "scx_XftObjectSetAdd")