33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
import sys
|
|
sys.path.insert(0, 'gateway')
|
|
import pdfengine
|
|
|
|
doc = pdfengine.PdfDocument.load_from_file('corpus/fonts/utf-8.pdf')
|
|
fonts = doc.get_fonts(0, -1)
|
|
print(f'utf-8.pdf fonts: {len(fonts)}')
|
|
for f in fonts:
|
|
print(f' font_name={f.font_name!r} type={f.type} is_embedded={f.is_embedded}')
|
|
print(f' ascent={f.ascent} descent={f.descent} cap_height={f.cap_height}')
|
|
print(f' encoding={f.encoding} cmap_name={f.cmap_name} has_to_unicode={f.has_to_unicode}')
|
|
print(f' is_subset={f.is_subset} subset_tag={f.subset_tag!r}')
|
|
print(f' source_type={f.source_type} normalized_family={f.normalized_family!r}')
|
|
print(f' internal_font_id={f.internal_font_id!r}')
|
|
print()
|
|
|
|
page = doc.get_page(0)
|
|
glyphs = page.extract_text_with_bounds()
|
|
print(f'Glyphs: {len(glyphs)}')
|
|
sizes = set(g['fontSize'] for g in glyphs)
|
|
print(f'Unique sizes: {sorted(sizes)}')
|
|
|
|
errors = []
|
|
for i, g in enumerate(glyphs):
|
|
if g['fontSize'] <= 0:
|
|
errors.append(f'Glyph {i} fontSize <= 0: {g["fontSize"]}')
|
|
if g['text'].strip() and (g['w'] <= 0 or g['h'] <= 0):
|
|
errors.append(f'Glyph {i} {repr(g["text"])} has zero bounds w={g["w"]} h={g["h"]}')
|
|
if g['fontSize'] > 200:
|
|
errors.append(f'Glyph {i} unrealistic fontSize={g["fontSize"]}')
|
|
|
|
print(f'Glyph errors: {errors or "None"}')
|