remcoboerma / pyfpdf

Automatically exported from code.google.com/p/pyfpdf
GNU Lesser General Public License v3.0
0 stars 0 forks source link

get_string_width report wrong value for missed glyphs #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Select unicode font eg. DejaVuCondesed.ttf, 14pt
2. Call get_string_width("안녕하세요") # from HelloWorld.txt
3. Get 0

What is the expected output? What do you see instead?

Should be 13 with these values

Original issue reported on code.google.com by romiq...@gmail.com on 26 Feb 2015 at 6:58

GoogleCodeExporter commented 9 years ago
fix for getHMTX in ttfonts.py
        def add_chars(char, defaultwidth):
            if char > 256*256:
                char = 256*256
            delta = char - len(self.charWidths) + 1
            if delta > 0:
                self.charWidths += [defaultwidth] * delta

...
                for char in glyphToChar[glyph]: 
                    if (char != 0 and char != 65535): 
                        w = int(round(scale*aw+0.001))   # ROUND_HALF_UP in PY3K (like php)
                        if (w == 0):  w = 65535 
                        if (char < 196608):
                            if len(self.charWidths) <= char:
                                add_chars(char, self.defaultWidth)
                            self.charWidths[char] = w 
                            nCharWidths += 1

Original comment by romiq...@gmail.com on 26 Feb 2015 at 6:59

GoogleCodeExporter commented 9 years ago
fixed in default branch

Original comment by romiq...@gmail.com on 27 Feb 2015 at 9:37