shairontoledo / rghost

RGhost is a document creation and conversion API. It uses the Ghostscript framework for the format conversion, utilizes EPS templates and is optimized to work with larger documents. Support(PDF,PS,GIF,TIF,PNG,JPG,etc)
http://rghost.rubyforge.org
MIT License
187 stars 46 forks source link

Added special unicode encoding #52

Closed ollym closed 10 years ago

ollym commented 10 years ago

Fixes a number of unicode encoding issues. Table found here: http://www.w3.org/2001/06/utf-8-test/postscript-utf-8.html

shairontoledo commented 10 years ago

Wow long time anyone fixed anything in postscript level, thank you for doing that. Can you please test with external encoding option for this change? Just put

RGhost::Config::GS[:external_encoding]= 'ascii-8bit'

Before your document creation. If it work correctly I will create a new gem version.

ollym commented 10 years ago

sure I'll give it a go. I'm a bit worried about how this will turn out on Ruby < 1.8 (if you still support that?) but I'll give it a go.

I obviously need to write some tests too, so this is very much still a WIP

shairontoledo commented 10 years ago

We won't support Ruby 1.8 anymore. The coming releases are based on > 1.9.3.

ollym commented 10 years ago

@shairontoledo I can confirm this works with RGhost::Config::GS[:external_encoding]= 'ascii-8bit'

shairontoledo commented 10 years ago

@ollym I had to update ruby_to_ps with encoding utf-8 header. I created a method to print the current UTF-8 mapping:

RGhost::Config.utf8_encodings.render :pdf, :filename => "/tmp/encoding_map.pdf"

It generates http://d.pr/i/TKkh

New version has been created 0.9.4 https://rubygems.org/gems/rghost/versions/0.9.4

Thank you for the collaboration.

ollym commented 10 years ago

Looks good. You'll also need to use something like:

RGhost::Config::GS[:font_encoding] = 'UTF-8'
RGhost::Config::GS[:charset_convert] = -> (text) {
  text.encode(RGhost::Config::GS[:font_encoding], invalid: :replace, undef: :replace, replace: '?')
}