gpt4 book ai didi

lua - lua 无法识别 cairo_text_extents_t

转载 作者:行者123 更新时间:2023-12-01 11:21:14 28 4
gpt4 key购买 nike

我正在 lua 中编写一些小部件以供 conky 使用显示一些东西。我达到了我想要居中文本的程度。正在关注this教程,我移植了C编码为 lua代码,所以它现在看起来像这样:

local extents
local utf8 = "cairo"
local x, y
cairo_select_font_face(cr, "Ubuntu", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_font_size(cr, 13)
cairo_text_extents(cr, utf8, extents)
x = 128.0 - (extents.width / 2 + extents.x_bearing)
y = 128.0 - (extents.height / 2 + extents.y_bearing)

cairo_move_to(cr, x, y)
cairo_show_text(cr, utf8)

我现在要处理的问题是 C数据类型 cairo_text_extents_t应该传递给 cairo_text_extents未被 lua 识别, 事实上 conky关闭没有任何输出。

有没有办法让lua认识那种数据类型?

最佳答案

我终于找到了答案。在 conky 中,存在一个函数可以满足我的需求,如指定的那样 here :

cairo_text_extents_t:create() function
Call this function to return a new cairo_text_extents_t structure. A creation function for this structure is not provided by the cairo API. After calling this, you should use tolua.takeownership() on the return value to ensure ownership is passed properly.

因此,执行以下操作就足够了:

local extents = cairo_text_extents_t:create()
tolua.takeownership(extents)
local utf8 = "cairo"
local x, y
cairo_select_font_face(cr, "Ubuntu", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_font_size(cr, 52)
cairo_text_extents(cr, utf8, extents)
x = 128.0 - (extents.width / 2 + extents.x_bearing)
y = 128.0 - (extents.height / 2 + extents.y_bearing)

cairo_move_to (cr, x, y)
cairo_show_text (cr, utf8)

关于lua - lua 无法识别 cairo_text_extents_t,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42671518/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com