如何使用 Gosu Ruby 在主 window 上绘制带有 unicode 字符的文本?
How to draw a text with unicode character on the main window using Gosu Ruby?
我正在尝试将文本输出到主 window 并使用类似的 unicode 字符
def initialize
super 800, 800
self.caption = 'Chess'
@font = Gosu::Font.new(self, Gosu.default_font_name, 100)
end
def draw
text = "Chess \u2658".encode('utf-8')
@font.draw(text, 100, 100, 10, 1, 1, Gosu::Color::BLACK)
end
但是 window 只显示 'Сhess' 字符串,没有预期的 unicode 符号 '♘'。
到目前为止我尝试过的:
- 更改字体名称本身,'Gosu.default_font_name' 到 'Serif'、'Arial'、'Hack' - 只有相同的结果 'Chess' 字符串更改字体但不显示字形
- 使用符号 '♘' 代替 unicode 代码
- 使用.draw_markup,.draw_text,Gosu::Image.from_text.
- 使用不同的 unicode 代码,例如使用西里尔字母 '\u0416' 它可以正常工作。
- 使用不同的编码参数。
- 使用不同的颜色。
我在Gosu论坛上找过类似的问题,但是没有找到。
您需要使用包含这些 Unicode 字符的字体,否则 Gosu 的内部字体渲染代码将 return 一个 0 宽度的图像来绘制该字符。
字体如:https://fontlibrary.org/en/font/chess
require "gosu"
class Window < Gosu::Window
def initialize(*args)
super
@font = Gosu::Font.new(28, name: "Chess.odf")
end
def draw
@font.draw_text("♘\u2658", 10, 10, 10)
end
end
Window.new(100, 100, false).show
我正在尝试将文本输出到主 window 并使用类似的 unicode 字符
def initialize
super 800, 800
self.caption = 'Chess'
@font = Gosu::Font.new(self, Gosu.default_font_name, 100)
end
def draw
text = "Chess \u2658".encode('utf-8')
@font.draw(text, 100, 100, 10, 1, 1, Gosu::Color::BLACK)
end
但是 window 只显示 'Сhess' 字符串,没有预期的 unicode 符号 '♘'。
到目前为止我尝试过的:
- 更改字体名称本身,'Gosu.default_font_name' 到 'Serif'、'Arial'、'Hack' - 只有相同的结果 'Chess' 字符串更改字体但不显示字形
- 使用符号 '♘' 代替 unicode 代码
- 使用.draw_markup,.draw_text,Gosu::Image.from_text.
- 使用不同的 unicode 代码,例如使用西里尔字母 '\u0416' 它可以正常工作。
- 使用不同的编码参数。
- 使用不同的颜色。
我在Gosu论坛上找过类似的问题,但是没有找到。
您需要使用包含这些 Unicode 字符的字体,否则 Gosu 的内部字体渲染代码将 return 一个 0 宽度的图像来绘制该字符。
字体如:https://fontlibrary.org/en/font/chess
require "gosu"
class Window < Gosu::Window
def initialize(*args)
super
@font = Gosu::Font.new(28, name: "Chess.odf")
end
def draw
@font.draw_text("♘\u2658", 10, 10, 10)
end
end
Window.new(100, 100, false).show