-
Notifications
You must be signed in to change notification settings - Fork 691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arabic Support Problem #921
Comments
What happens when you don't use that gem? Are the glyphs showing up incorrectly? |
I have same result with or without using Arabic prawn. |
I don't have artro.ttf but I did a test with KacstOne.ttf from http://sourceforge.net/projects/arabeyes/files/kacst_fonts/. It rendered the text but I'm not sure if it is correct. Does that font work if you try it? It could still be related to Prawn but maybe that will help narrow things down. Also, what version of Ruby and Prawn are you using? Here's the code I used: Prawn::Document.generate('arabic.pdf') do
font "KacstOne.ttf"
font_size 16
self.text_direction = :rtl
long_text = "مرحبا يا العالم"
text long_text
end Here's the output: |
This is great, thank you so much. But how can I display in both languages: Arabic and English? Because when I used KacstOne font, it caused a problem in the English Text. I used this code:
and this is the output;
I get the same if I try this instead: long_text = "مرحبا يا العالم" |
You may want to change the font depending if you're using Arabic or English. You can change it back and forth as many times as you want. There are good examples of loading fonts in the manual. |
I noticed this, but the problem is that the values I need to display are unknowns, and they could be entered by the user in English or Arabic, that's why I need something that works for both. |
What glyphs can be shown will be controlled by what the font supports. Short term your best solution might be to inspect the string code points and use that information to determine what font to use => [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33]
irb(main):002:0> "مرحبا يا العالم".codepoints
=> [1605, 1585, 1581, 1576, 1575, 32, 1610, 1575, 32, 1575, 1604, 1593, 1575, 1604, 1605]
irb(main):003:0> Also know that you may need to use another library to build up the string and insert it into prawn, we ran into that with Persian support in #871, I apologize if that's not related I don't know much (if anything) about Arabic (or Persian) so the issues related to it may be totally unrelated, but it was another user who was running into problems with rtl text. |
There are some examples out there on how to detect Arabic text: http://stackoverflow.com/questions/7066137/how-to-determine-if-string-contains-arabic-symbols |
Thank you for your solution. Before trying it, I found something called fallback fonts: http://cookieshq.co.uk/posts/fallback-fonts-in-prawn/ As this link mentions, a fallback font is called when a string contains unsupported characters like Arabic. So I will try it maybe it'll work. |
I'm closing this in favour of #1295. |
I'm running my project on Ruby on Rails, and I want to use Prawn to generate pdf reports, for all its advantages. However, I have one main issue: it doesn't support Arabic Language.
I searched for a solution and I found this:
https://rubygems.org/gems/Arabic-Prawn/versions/0.0.1
I installed arabic-prawn 0.0.1 and used this :
Prawn::Document.generate('hello.pdf') do
font "#{Prawn::BASEDIR}/data/fonts/artro.ttf"
font_size 16
self.text_direction = :rtl
long_text = "مرحبا يا العالم"
text long_text.fix_arabic_glyphs
end
This is the result: ِarabic words are not appearing
I use rails 2.3.5 and prawn 0.6.3.
I couldn't find a solution for this, please help.
The text was updated successfully, but these errors were encountered: