I am trying to do a Pie charts in my ruby on rails app

230 Views Asked by At

I am using the gem gruff in window 7 with docker, but when I try to write the g.data I get this error:

unable to read font `\Users\Raul del Rio\Desktop\grupo-43\Vera.ttf' @ error/annotate.c/RenderFreetype/1362
Extracted source (around line #32):


puts "mira para que revises"
puts g
g.write("pie_keynote.png")




Rails.root: /example
Application Trace | Framework Trace | Full Trace

app/controllers/articles_controller.rb:32:in `index'

and this is my code of articles_controller line 32:

g = Gruff::Pie.new
g.title = "Visual Pie Graph Test"
g.font="\\Users\\Raul del Rio\\Desktop\\grupo-43\\Vera.ttf"
g.data 'Fries', 20
g.data 'Hamburgers', 50
puts "mira para que revises"
puts g
g.write("pie_keynote.png")

and I really don't understand why the error :( and here is a photo of the app folder:

enter image description here

i also try the following:

g = Gruff::Pie.new
g.font=ActionController::Base.helpers.asset_path("Vera.ttf")
g.title = "Visual Pie Graph Test"
@datasets.each do |data|
  g.data(data[0], data[1])
end

# Default theme
g.write("pie_keynote.png")

and give me a weird error :

unable to read font `/assets/Vera-c4c45690b345435b2cba52ecabe275f05e49b389b39fe68ad03afbb551288d3d.ttf' @ error/annotate.c/RenderFreetype/1362

enter image description here

in another try i write in the .env file the following:

MAGICK_FONT_PATH=/Users/Raul del Rio/Desktop/grupo-43/Vera.ttf

and give me the next error:

Magick::ImageMagickError in ArticlesController#index 
unable to open file `/Users/Raul del Rio/Desktop/grupo-43/Vera.ttf/type.xml': No such file or directory @ error/blob.c/FileToBlob/987

in another try i edit the .env again file with some modifications:

MAGICK_FONT_PATH=C:/Users/Raul del Rio/Desktop/grupo-43/font

and the screen error give me:

unable to open file `C:/Users/Raul del Rio/Desktop/grupo-43/font/type.xml': No such file or directory @ error/blob.c/FileToBlob/987

and now i did a folder with font:

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

Finally all the problems were solve using the following package in docker:

docker-compose run web install ghostscript

It seems that it establishes the routes between docker and windows. I really don't know how or why I need that, but work.

Here is where I found the information: https://github.com/docksal/docksal/issues/362

5
On

Looking at the source it says to set an ENV var pointing to a path with fonts:

Looks for Bitstream Vera as the default font. Expects an environment var
# of MAGICK_FONT_PATH to be set. (Uses RMagick's default font otherwise.)

There is more info here, but basically (on unix-like os) do something like:

export MAGICK_FONT_PATH=/path/to/fonts/dir

And on windows follow these instructions.