Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

463
Visualizações
How to draw a text with unicode character on the main window using Gosu Ruby?

I'm trying to output text to the main window with unicode character like that

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       

but the window displays only the 'Сhess' string without unicode symbol '♘' as supposed.

What I have tried so far:

  • to change font name itself, 'Gosu.default_font_name' to 'Serif', 'Arial', 'Hack' - same result only 'Chess' string changes font but not displaying glyph
  • use symbol '♘' instead of unicode code
  • use .draw_markup, .draw_text, Gosu::Image.from_text.
  • use different unicode code, for example with cyrillic letter '\u0416' it worked as supposed.
  • use different encoding arguments.
  • use different colors.

I looked for similar problems on the Gosu forum, but I could not find anything.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need to use a font that includes those Unicode characters or Gosu's internal font rendering code will return a 0 width image for drawing that character.

A font like: 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
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda