red-data-tools/GR.rb

gtk example libfreetype error

kojix2 opened this issue · 2 comments

libfreetype error on Ubuntu.
Could it be a cairo problem?
It seems to work fine on some platforms other than Ubuntu.

gtk.rb:31:in `show_text': error occurred in libfreetype
         from gtk.rb:31:in `expose'
         from gtk.rb:20:in `block in plot_drawable'
         from /home/kojix2/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/gobject-introspection-3.4.4/lib/gobject-introspection/loader.rb:600:in `invoke'
         from /home/kojix2/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/gobject-introspection-3.4.4/lib/gobject-introspection/loader.rb:600:in `invoke'
         from /home/kojix2/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/gobject-introspection-3.4.4/lib/gobject-introspection/loader.rb:514:in `block in define_method'
         from gtk.rb:60:in `<main>'
# frozen_string_literal: true

require 'gr'
require 'gtk3'
require 'numo/narray'

DFloat = Numo::DFloat

class GRAppWindow < Gtk::ApplicationWindow
  def initialize(application)
    super(application)
    set_title('GTK example')
    set_default_size(500, 500)
    plot_drawable
  end

  def plot_drawable
    drawable = Gtk::DrawingArea.new
    drawable.signal_connect('draw') do |widget, context|
      expose(widget, context)
    end
    add(drawable)
  end

  def expose(_widget, cr)
    ENV['GKS_WSTYPE'] = '142'
    ENV['GKSconid'] = cr.raw_address.to_s

    cr.move_to(15, 45)
    cr.set_font_size(30)
    cr.show_text('Contour Plot using Gtk ...')

    xd = -2 + DFloat.new(100).rand * 4
    yd = -2 + DFloat.new(100).rand * 4
    zd = xd * Numo::NMath.exp(-xd * xd - yd * yd)

    GR.setviewport(0.1, 0.95, 0.1, 0.85)
    GR.setwindow(-2, 2, -2, 2)
    GR.setmarkersize(1)
    GR.setmarkertype(GR::MARKERTYPE_SOLID_CIRCLE)
    GR.setcharheight(0.024)
    GR.settextalign(2, 0)
    GR.settextfontprec(3, 0)

    x, y, z = GR.gridit(xd, yd, zd, 200, 200)
    h = -0.6.step(0.6, 0.05).to_a
    GR.contourf(x, y, h, z, 2)
    GR.polymarker(xd, yd)
    GR.axes(0.25, 0.25, -2, -2, 2, 2, 0.01)

    GR.updatews
  end
end

app = Gtk::Application.new('org.gtk.example', :flags_none)
app.signal_connect 'activate' do |application|
  GRAppWindow.new(application).show_all
end

app.run
kou commented

I couldn't reproduce this with bento/ubuntu-20.04 Vagrant (VirtualBox) image.

I installed only the following packages by APT:

  • gnome
  • ruby-dev
  • gcc
  • make
  • libgrm-dev (from packages.red-data-tools.org)

See packages.txt for the dpkg -l output on the environment.

It seems that some packages (font packages?) on your Ubuntu environment cause this problem.

Windows (RubyInstaller Ruby 2.6.5)

image

Ubuntu + Ruby 2.7.1 + GR official release

(not completed)