From 258b0e25327f3d4feb7c671d7eef25a0a8b28ac6 Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Sat, 25 Feb 2017 18:23:33 -0700 Subject: [PATCH] pango: Use bytevectors instead of strings. --- src/pango/pango.scm | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/pango/pango.scm b/src/pango/pango.scm index 4c559cb2e..89c060c70 100644 --- a/src/pango/pango.scm +++ b/src/pango/pango.scm @@ -33,15 +33,15 @@ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. (cond ((color? spec) spec) ((eq? spec 'WHITE) white) ((eq? spec 'BLACK) black) - ((symbol? spec) (pango-color-parse (symbol-name spec))) + ((symbol? spec) (pango-color-parse (symbol->string spec))) ((string? spec) (pango-color-parse spec)) (else (error:wrong-type-argument spec "a color spec" operator)))) (define (pango-color-parse spec) - (guarantee-string spec 'pango-color-parse) + (guarantee string? spec 'pango-color-parse) (let ((rgb (malloc (C-sizeof "PangoColor") '|PangoColor|))) - (if (zero? (C-call "pango_color_parse" rgb spec)) + (if (zero? (C-call "pango_color_parse" rgb (string->utf8 spec))) (error:wrong-type-argument spec "a color spec" 'pango-color-parse) (let ((color (make-color))) @@ -89,15 +89,17 @@ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. (define (pango-layout-set-text layout text) (guarantee-pango-layout layout 'pango-layout-set-text) - (guarantee-string text 'pango-layout-set-text) - (C-call "pango_layout_set_text" (gobject-alien layout) - text (string-length text))) + (guarantee string? text 'pango-layout-set-text) + (let ((text-bv (string->utf8 text))) + (C-call "pango_layout_set_text" (gobject-alien layout) + text-bv (bytevector-length text-bv)))) (define (pango-layout-set-markup layout markup) (guarantee-pango-layout layout 'pango-layout-set-markup) - (guarantee-string markup 'pango-layout-set-markup) - (C-call "pango_layout_set_markup" (gobject-alien layout) - markup (string-length markup))) + (guarantee string? markup 'pango-layout-set-markup) + (let ((markup-bv (string->utf8 markup))) + (C-call "pango_layout_set_markup" (gobject-alien layout) + markup-bv (bytevector-length markup-bv)))) (define (pango-layout-get-pixel-extents layout receiver) (guarantee-pango-layout layout 'pango-layout-set-text) @@ -175,11 +177,12 @@ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. (define (pango-font-description-from-string string) ;; The returned PangoFontDescription is owned by Scheme. - (guarantee-string string 'pango-font-description-from-string) + (guarantee string? string 'pango-font-description-from-string) (let ((font (make-alien '|PangoFontDescription|)) - (copy (make-alien '|PangoFontDescription|))) + (copy (make-alien '|PangoFontDescription|)) + (string-bv (string->utf8 string))) (add-glib-cleanup font (make-pango-font-description-cleanup copy)) - (C-call "pango_font_description_from_string" copy string) + (C-call "pango_font_description_from_string" copy string-bv) (copy-alien-address! font copy) (error-if-null font "Could not create:" font) font)) @@ -209,11 +212,12 @@ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. (lambda () (let ((cstr (make-alien '|char|))) (C-call "pango_font_description_to_string" cstr font) - (let ((str (c-peek-cstring cstr))) + (let ((str-bv (c-peek-cstring cstr))) (C-call "g_free" cstr) - str)))))) + (utf8->string str-bv))))))) (define (pango-font-description-copy font) + (guarantee-pango-font-description font 'pango-font-description-copy) (let ((new (make-alien '|PangoFontDescription|)) (copy (make-alien '|PangoFontDescription|))) (add-glib-cleanup new (make-pango-font-description-cleanup copy)) @@ -356,7 +360,7 @@ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. (define (pango-font-family-get-name PangoFontFamily) (let ((name (make-alien '(const char)))) (C-call "pango_font_family_get_name" name PangoFontFamily) - (c-peek-cstring name))) + (utf8->string (c-peek-cstring name)))) (define (pango-font-family-is-monospace? PangoFontFamily) (not (fix:zero? (C-call "pango_font_family_is_monospace" PangoFontFamily)))) @@ -387,4 +391,4 @@ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. (define (pango-font-face-get-name PangoFontFace) (let ((name (make-alien '(const char)))) (C-call "pango_font_face_get_face_name" name PangoFontFace) - (c-peek-cstring name))) \ No newline at end of file + (utf8->string (c-peek-cstring name)))) \ No newline at end of file -- 2.25.1