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

error: in __getitem__ return self.metrics[glyphName] KeyError: 'A' #1804

Closed
peterennis opened this issue Jan 21, 2020 · 6 comments
Closed

error: in __getitem__ return self.metrics[glyphName] KeyError: 'A' #1804

peterennis opened this issue Jan 21, 2020 · 6 comments

Comments

@peterennis
Copy link
Contributor

Using this as a reference: https://groups.google.com/forum/#!topic/fonttools/ll4G3dOrDBc

I have this py script:

from fontTools.ttLib import TTFont
from fontTools.pens.svgPathPen import SVGPathPen

font = TTFont("./Center-Point-2026.ttf")
glyphSet = font.getGlyphSet()
svgpen = SVGPathPen(glyphSet)
glyph = glyphSet["A"]
glyph.draw(svgpen)
path = svgpen.getCommands()
print(path)

It is run against the a ttf I am developing.

Result:

C:\ae\adaept.com\ae-pytools>python .\ae-outglyph.py
Traceback (most recent call last):
  File ".\ae-outglyph.py", line 7, in <module>
    glyph = glyphSet["A"]
  File "C:\Users\peter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\fontTools\ttLib\ttFont.py", line 717, in __getitem__
    horizontalMetrics = self._hmtx[glyphName]
  File "C:\Users\peter\AppData\Local\Programs\Python\Python38-32\lib\site-packages\fontTools\ttLib\tables\_h_m_t_x.py", line 136, in __getitem__
    return self.metrics[glyphName]
KeyError: 'A'

C:\ae\adaept.com\ae-pytools>

GitHub will not allow me to attach the file.

What is the next step in this process?

Windows 10 x64

C:\ae\adaept.com\ae-pytools>python --version
Python 3.8.0

Using fonttools 4.2.4

@justvanrossum
Copy link
Collaborator

You can attach the font as a zip file.

@peterennis
Copy link
Contributor Author

zipped font

Center-Point-2026.zip

@anthrotype
Copy link
Member

Does your font contain a glyph named "A"?

@justvanrossum
Copy link
Collaborator

Does your font contain a glyph named "A"?

It doesn't, the font doesn't contain a proper post table with glyph names it seems.

@peterennis
Copy link
Contributor Author

The font was created using glyphter.com

How do I make it have a "proper post table"?

@behdad
Copy link
Member

behdad commented Aug 14, 2022

See this for how to correctly get the glyph index for character "A":

g = cmap[ord(u)]
glyph = glyphset[g]

@behdad behdad closed this as completed Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants