Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Parse FontBBox in type1font.#30088

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 1 commit intomatplotlib:mainfromanntzer:t1bb
May 30, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Parse FontBBox in type1font.
... instead of having to go through ft2font in createType1Descriptorjust to extract the font bbox, ascender and descender.FontBBox is gauranteed to exist in the type1 font definition by thestandard; its parsing as a size-4 array matches freetype's behavior (seeps_parser_load_field); and using bbox entries as ascender and descenderalso matches freetype's behavior (T1_Face_Init directly assigns`root->ascender = (FT_Short)(root->bbox.yMax)` and likewise for thedescender; see also the docs for ascender and descender in FT_FaceRec).
  • Loading branch information
@anntzer
anntzer committedMay 20, 2025
commitc4e54cfc303c203e4acac728c17cedbea22fd2ef
4 changes: 4 additions & 0 deletionsdoc/api/next_api_changes/deprecations/30088-AL.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
*fontfile* parameter of ``PdfFile.createType1Descriptor``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This parameter is deprecated; all relevant pieces of information are now
directly extracted from the *t1font* argument.
10 changes: 10 additions & 0 deletionslib/matplotlib/_type1font.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -579,6 +579,16 @@
extras = ('(?i)([ -](regular|plain|italic|oblique|(semi)?bold|'
'(ultra)?light|extra|condensed))+$')
prop['FamilyName'] = re.sub(extras, '', prop['FullName'])

# Parse FontBBox
toks = [*_tokenize(prop['FontBBox'].encode('ascii'), True)]
if ([tok.kind for tok in toks]
!= ['delimiter', 'number', 'number', 'number', 'number', 'delimiter']
or toks[-1].raw != toks[0].opposite()):
raise RuntimeError(

Check warning on line 588 in lib/matplotlib/_type1font.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/_type1font.py#L588

Added line #L588 was not covered by tests
f"FontBBox should be a size-4 array, was {prop['FontBBox']}")
prop['FontBBox'] = [tok.value() for tok in toks[1:-1]]

# Decrypt the encrypted parts
ndiscard = prop.get('lenIV', 4)
cs = prop['CharStrings']
Expand Down
15 changes: 7 additions & 8 deletionslib/matplotlib/backends/backend_pdf.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1034,14 +1034,15 @@ def _embedTeXFont(self, fontinfo):
fontinfo.effects.get('extend', 1.0))
fontdesc = self._type1Descriptors.get((fontinfo.fontfile, effects))
if fontdesc is None:
fontdesc = self.createType1Descriptor(t1font, fontinfo.fontfile)
fontdesc = self.createType1Descriptor(t1font)
self._type1Descriptors[(fontinfo.fontfile, effects)] = fontdesc
fontdict['FontDescriptor'] = fontdesc

self.writeObject(fontdictObject, fontdict)
return fontdictObject

def createType1Descriptor(self, t1font, fontfile):
@_api.delete_parameter("3.11", "fontfile")
def createType1Descriptor(self, t1font, fontfile=None):
# Create and write the font descriptor and the font file
# of a Type-1 font
fontdescObject = self.reserveObject('font descriptor')
Expand DownExpand Up@@ -1076,24 +1077,22 @@ def createType1Descriptor(self, t1font, fontfile):
if 0:
flags |= 1 << 18

ft2font = get_font(fontfile)

descriptor = {
'Type': Name('FontDescriptor'),
'FontName': Name(t1font.prop['FontName']),
'Flags': flags,
'FontBBox':ft2font.bbox,
'FontBBox':t1font.prop['FontBBox'],
'ItalicAngle': italic_angle,
'Ascent':ft2font.ascender,
'Descent':ft2font.descender,
'Ascent':t1font.prop['FontBBox'][3],
'Descent':t1font.prop['FontBBox'][1],
'CapHeight': 1000, # TODO: find this out
'XHeight': 500, # TODO: this one too
'FontFile': fontfileObject,
'FontFamily': t1font.prop['FamilyName'],
'StemV': 50, # TODO
# (see also revision 3874; but not all TeX distros have AFM files!)
# 'FontWeight': a number where 400 = Regular, 700 = Bold
}
}

self.writeObject(fontdescObject, descriptor)

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp