如何使用 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论坛上找过类似的问题,但是没有找到。

您需要使用包含这些 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