pyfpdf icon indicating copy to clipboard operation
pyfpdf copied to clipboard

UserWarning: cmap value too big/small: -33395

Open edonyzpc opened this issue 10 years ago • 9 comments

I try to test pyfpdf with outputting Chinese pdf on my Fedora21. Here are the codes:

pdf = FPDF()
pdf.add_page()
pdf.add_font('fireflysung', '', '/usr/share/fonts/fireflysung/fireflysung.ttf', uni=True)
pdf.set_font('fireflysung', '', 16)
pdf.write(10, u'edony\n糯米517吃货节\n')
pdf.ln(10)
pdf.output('test.pdf', 'F')

But the warning comes and the test.pdf seems perfect.

pyfpdf/fpdf/ttfonts.py:671: UserWarning: cmap value too big/small: -33395
  warnings.warn("cmap value too big/small: %s" % cm)
pyfpdf/fpdf/ttfonts.py:671: UserWarning: cmap value too big/small: -36119
  warnings.warn("cmap value too big/small: %s" % cm)

Personally, this is fireflysung font's problem. I don't know why! What should I do to solve it? I download the font from http://www.study-area.org/apt/firefly-font/fireflysung-1.3.0.tar.gz.

edonyzpc avatar May 15 '15 12:05 edonyzpc

Edony, this is our untilled field. This sometimes happens to Droid font set. Be carefull with displayed charters. And stay tuned with this issue.

RomanKharin avatar May 15 '15 12:05 RomanKharin

Thank you very much. I will try my way to solve this and ,if it works, I will pull request.

edonyzpc avatar May 15 '15 13:05 edonyzpc

Someone has found a solution for this issue? I've the same problem with pdf.write of japanese characters (values less then zero are similar): the final print is fine, but I see in my log warnings about this. Precisely, I use this font: http://www.freejapanesefont.com/kokutetsu-ppoi-font-%E5%9B%BD%E9%89%84%E3%81%A3%E3%81%BD%E3%81%84%E3%83%95%E3%82%A9%E3%83%B3%E3%83%88/ (JNRFont_s.ttf)

Thanks, mauro

mauroesposito avatar Aug 24 '15 15:08 mauroesposito

I suppose this caused by misreading ttf documentation or some changes in format that are not properly handled. Sonn i'll push few commits in this area.

RomanKharin avatar Aug 24 '15 20:08 RomanKharin

Thank you RomanKharin.

m

mauroesposito avatar Aug 24 '15 20:08 mauroesposito

I got the same problem. I try to display Chinese string. The warning occur on some Chinese characters. I found that when the cmap is less than zero, this problem will happen. I don't know what it caused. Sorry. I do a dirty and quick way to remark a few lines from ttfonts.py. Then it works. All my Chinese words can be showed. for cm in cmap: if cm >= 0: cmapstr += pack(">H", cm) '# else: '# try: '# cmapstr += pack(">h", cm) '# except: '# warnings.warn("cmap value too big/small: %s" % cm) '# cmapstr += pack(">H", -cm)

cometl avatar Jun 01 '18 08:06 cometl

@cometl I've tried your method, but some words still can't be showed, instead [].

luckydog5 avatar Jun 05 '19 10:06 luckydog5

Had the same problem with ARIALUNI.TTF. It seems that the length of a range was computed as a negative value in ttfonts.py. Here is a patch. Apply with: >patch -i [name] ttfonts.py ----snip---- 649c649 < idDelta = -(start-subrange[0]) --- > idDelta = start-subrange[0] 668,672c668 < try: < cmapstr += pack(">h", cm) < except: < warnings.warn("cmap value too big/small: %s" % cm) < cmapstr += pack(">H", -cm) --- > warnings.warn("negative cmap value ignored: %s" % cm)`` ----snap----

asl5757 avatar Jan 28 '20 13:01 asl5757

Does anyone have an idea as to what this number means or where it is in the TTF definition? For example, if it is used in an official font library, it makes total sense to use something like fontTools instead of the port of the php ttf parser (which is clearly causing lots of problems).

alexanderankin avatar Jan 29 '20 23:01 alexanderankin