0

平台:Windows 10 Pro 20H2 64 位 / SBCL 2.2.0

库:mingw64/mingw-w64-x86_64-pango 1.50.3-1

通过 MSYS2 安装:pacman -S mingw-w64-x86_64-pango

重现的示例代码:

(ql:quickload 'cl-pango)

;; the code below is for `cl-pango:g_object_unref`
(cffi:define-foreign-library :libgobject
  (cffi-features:windows "libgobject-2.0-0.dll"))
(cffi:load-foreign-library :libgobject)

(let* ((cairo-surface (cairo:create-image-surface :argb32 240 80))
       (cairo-context (cairo:create-context cairo-surface))
       (pango-layout (cl-pango:pango_cairo_create_layout
                      (slot-value cairo-context 'cairo:pointer))))

  ;; `pango_layout_set_text` works well
  ;; (cl-pango:pango_layout_set_text pango-layout "Hello, Pango" -1)

  ;; `pango_layout_set_marup` fails
  (cl-pango:pango_layout_set_markup pango-layout "Hello, Pango Markup" -1)
  
  (cairo:set-source-rgb 0 1 1 cairo-context)
  (cairo:move-to 10 50 cairo-context)
  (cl-pango:pango_cairo_show_layout (slot-value cairo-context 'cairo:pointer) pango-layout)

  (cl-pango:g_object_unref pango-layout)

  (cairo:destroy cairo-context)
  (cairo:surface-write-to-png cairo-surface "hello-pango.png")
  (cairo:destroy cairo-surface))


(quit)

上面的代码将在最近的 macOS 和 Linux 下成功运行,但在 Windows 10 上,它将生成以下输出:

$ sbcl --load hello-pango.lisp
This is SBCL 2.2.0, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
To load "cl-pango":
  Load 1 ASDF system:
    cl-pango
; Loading "cl-pango"
........

(process:2720): GLib-GObject-WARNING **: 09:15:43.571: cannot register existing type 'PangoLayout'

(process:2720): GLib-CRITICAL **: 09:15:43.571: g_once_init_leave: assertion 'result != 0' failed

(process:2720): Pango-CRITICAL **: 09:15:43.571: pango_layout_set_markup_with_accel: assertion 'PANGO_IS_LAYOUT (layout)' failed

这是生成的图像(似乎是空白的):

生成的空白图像

但与此同时,C 等效代码可以正常工作:

/*
 * compile:
 * gcc -o hello-pango-markup hello-pango-markup.c $(pkg-config --cflags --libs pangocairo)
 */

#include <pango/pangocairo.h>
PangoLayout *layout;
PangoFontDescription *font_description;

int main (int argc, char *argv[])
{
  cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
  cairo_t *cr = cairo_create (surface);

  layout = pango_cairo_create_layout (cr);
  pango_layout_set_markup (layout, "Hello, world", -1);

  cairo_set_source_rgb (cr, 0.0, 1.0, 1.0);
  cairo_move_to (cr, 10.0, 50.0);
  pango_cairo_show_layout (cr, layout);

  g_object_unref (layout);

  cairo_destroy (cr);
  cairo_surface_write_to_png (surface, "hello-pango.png");
  cairo_surface_destroy (surface);
  return 0;
}

所以我想 Lisp 和 Pango C 接口之间可能有一些奇怪的东西,也许它与 GObject 相关。

卡在这里很久了,大家有什么建议或建议,谢谢~

4

0 回答 0