Skip to content
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

Characters cannot be displayed when use SimSun ttf font #843

Closed
J-F-Liu opened this issue Apr 29, 2015 · 6 comments
Closed

Characters cannot be displayed when use SimSun ttf font #843

J-F-Liu opened this issue Apr 29, 2015 · 6 comments

Comments

@J-F-Liu
Copy link

J-F-Liu commented Apr 29, 2015

Used simsunb.ttf, 宋体, 新宋体, both fonts display square boxes.

@packetmonkey
Copy link
Contributor

Can you please provide links to both fonts you are having a problem with and a script to reproduce the issue?

@J-F-Liu
Copy link
Author

J-F-Liu commented Apr 29, 2015

The font file in the Windows\Fonts folder, created a script as below:

require 'prawn'

Prawn::Document.generate("test.pdf") do
  font("c:/Windows/Fonts/simsunb.ttf") do
    text "宋体,是为适应印刷术而出现的一种汉字字体。常用于书籍、杂志、报纸印刷的正文排版。
    中国书法和雕版印刷的结合产生了宋体字,因此,宋体字不但有中国书法的魅力,还具有雕版印刷及木版刀刻的韵味。"
    text "Windows系统的中易宋体(宋体、新宋体,非简体环境下显示为SimSun、NSimSun)
    是由北京中易中标电子信息技术有限公司制作的简体字字体;
    繁体的宋体字体则是华康科技制作的细明体(细明体、新细明体,非繁体环境下显示为MingLiU、PMingLiU)。
    Mac中的衬线字体有俪宋 Pro (LiSongPro)及苹果俪细宋(LiSungLight)。
    Linux发行版中使用较多的有AR PL 上海宋(AR PL Uming)和完全民间开发的文泉驿点阵宋体。
    此外网络上还有民间开发的“华秀月明”字体。"
  end
end

@packetmonkey
Copy link
Contributor

I don't have access to a windows machine to get a copy of the fonts so I can try to reproduce the problem.

I suspect we will find the problem is rooted in ttfunk which is the library prawn uses to deal with ttf fonts. Can you either help me find where I can get a copy of the fonts or confirm that ttfunk is able/unable to work with these specific fonts?

@J-F-Liu
Copy link
Author

J-F-Liu commented Apr 30, 2015

The file size of simsunb.ttf is 16.1MB, I confirmed the issue is in ttfunk when comparing the result of simhei.ttf and simsunb.ttf by running ttfunk/examples/metrics.rb

postscript: SimHei
-- FONT METRICS ----------------------------
units/em  : 256
ascent    : 220
descent   : -36
line gap  : 36
bbox      : (-3,-40)-(255,220)
-- SIMPLE CHARACTER -> GLYPH LOOKUP --------
character     : 我
character code: 25105
glyph id      : 6215
glyph type    : simple
glyph size    : 272b
glyph bbox    : (14,-28)-(247,206)
-- COMPOUND CHARACTER -> GLYPH LOOKUP ------
character     : 们
character code: 20204
glyph id      : 1314
glyph type    : simple
glyph size    : 168b
glyph bbox    : (9,-27)-(232,210)
postscript: SimSun-ExtB
-- FONT METRICS ----------------------------
units/em  : 256
ascent    : 220
descent   : -36
line gap  : 36
bbox      : (0,-41)-(470,220)
-- SIMPLE CHARACTER -> GLYPH LOOKUP --------
character     : 我
character code: 25105
glyph id      : 0
glyph type    : simple
glyph size    : 34b
glyph bbox    : (28,-13)-(224,193)
-- COMPOUND CHARACTER -> GLYPH LOOKUP ------
character     : 们
character code: 20204
glyph id      : 0
glyph type    : simple
glyph size    : 34b
glyph bbox    : (28,-13)-(224,193)

With simsunb.ttf glyph id is 0 for all Chinese characters.

@J-F-Liu
Copy link
Author

J-F-Liu commented Apr 30, 2015

Well, this issue is not urgent now. I found a tool called AiFont and converted c:/Windows/Fonts/simsun.ttc to simsun.ttf, then this ttf file can be used to render PDF correctly.

@packetmonkey
Copy link
Contributor

Glad to hear you came up with a solution!

I'll close this issue as it wasn't a prawn bug but ttfunk related. I would be happy to look at a PR to implement that functionality on the ttfunk side so the original font worked out of the box. Without the actual font file and spending some time in the TrueType spec, I won't be able to patch ttfunk myself.

Thanks for the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants