1

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

mrpepo877
  • 490
  • 6
  • 23
  • You have to explicitly tell `ImageMagick` what font to use. – Aleksei Matiushkin Jul 04 '18 at 06:54
  • like \app\assets\images or like C:\Users\juan\Desktop\grupo-43\app\assets\images or another thing? – mrpepo877 Jul 04 '18 at 06:57
  • The **font** is a set of glyphs used to represent symbols. Like this: https://github.com/topfunky/gruff/blob/0625ec81f37908d519e6a725a3140a42fb9aa2ee/test/gruff_test_case.rb#L143 – Aleksei Matiushkin Jul 04 '18 at 07:01
  • so i have to add something like: `g.font = ' \app\assets\images\pie_keynote.png'` `g.write()'` – mrpepo877 Jul 04 '18 at 07:05
  • Rather than specifying a font by name, try using the full path to the actual font file with suffix. – fmw42 Jul 04 '18 at 17:10
  • can you give me an example :D pls? – mrpepo877 Jul 04 '18 at 17:14
  • you are getting close, the path you set up as ENV var is wrong. on windows paths start with something like "C:\". so in your case (example): MAGICK_FONT_PATH=C:\Users\juan\Desktop\grupo-43. and make sure to not point to a single font, but a folder with fonts. – manitu Jul 05 '18 at 14:03
  • i do that i appear another error, i going to edit my question so you can see it – mrpepo877 Jul 05 '18 at 14:38

2 Answers2

1

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.

manitu
  • 1,189
  • 10
  • 16
  • aaaa ok but what code i will have to puts to solve the problem? because i am so confused with what font puts and then what arg put in the write command? :/ – mrpepo877 Jul 04 '18 at 07:16
  • the problem is outside of your code. The IM library is not finding fonts, probably because the ENV variable called MAGICK_FONT_PATH is not pointing to the right folder. Makes sense? – manitu Jul 04 '18 at 07:18
  • aaaa now make more sense, so i going to test the instruction for window to see if i understand how fix it – mrpepo877 Jul 04 '18 at 07:20
  • [here there is a photo of my folder](http://prntscr.com/k2c0l2) there is a file that have name .env that file can be making some trouble? – mrpepo877 Jul 04 '18 at 07:35
  • it might, if you are using dotenv https://github.com/bkeepers/dotenv, you could add MAGICK_FONT_PATH in there as well. locate your font folder... – manitu Jul 04 '18 at 09:38
0

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

fmw42
  • 46,825
  • 10
  • 62
  • 80
mrpepo877
  • 490
  • 6
  • 23