Support for marked content section IDs (#961)

This commit is contained in:
David Huggins-Daines
2023-08-19 09:29:21 -06:00
committed by GitHub
parent d8b9c1581a
commit 142fc90cc5
5 changed files with 122 additions and 5 deletions
Binary file not shown.
+4 -3
View File
@@ -70,7 +70,7 @@ class Test(unittest.TestCase):
assert c.split("\r\n")[9] == (
"char,1,45.83,58.826,656.82,674.82,117.18,117.18,135.18,12.996,"
'18.0,12.996,,,,,,TimesNewRomanPSMT,,,"(1, 0, 0, 1, 45.83, 660.69)"'
',DeviceRGB,"(0, 0, 0)",,,18.0,,,,,,Y,,1,'
',,DeviceRGB,"(0, 0, 0)",,,18.0,,,,,,,Y,,1,'
)
io = StringIO()
@@ -125,7 +125,7 @@ class Test(unittest.TestCase):
assert res.decode("utf-8").split("\r\n")[9] == (
"char,1,45.83,58.826,656.82,674.82,117.18,117.18,135.18,12.996,"
'18.0,12.996,,,,,,TimesNewRomanPSMT,,,"(1, 0, 0, 1, 45.83, 660.69)"'
',DeviceRGB,"(0, 0, 0)",,,18.0,,,,,,Y,,1,'
',,DeviceRGB,"(0, 0, 0)",,,18.0,,,,,,,Y,,1,'
)
def test_cli_csv_exclude(self):
@@ -141,6 +141,7 @@ class Test(unittest.TestCase):
"3",
"--exclude-attrs",
"matrix",
"mcid",
"ncs",
"non_stroking_pattern",
"stroking_pattern",
@@ -150,7 +151,7 @@ class Test(unittest.TestCase):
assert res.decode("utf-8").split("\r\n")[9] == (
"char,1,45.83,58.826,656.82,674.82,117.18,117.18,135.18,12.996,"
"18.0,12.996,,,,,,TimesNewRomanPSMT,"
',,"(0, 0, 0)",,18.0,,,,,Y,,1,'
',,"(0, 0, 0)",,18.0,,,,,,Y,,1,'
)
def test_cli_csv_include(self):
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env python3
import os
import unittest
import pdfplumber
HERE = os.path.abspath(os.path.dirname(__file__))
class TestMCIDs(unittest.TestCase):
"""Test MCID extraction."""
def test_mcids(self):
path = os.path.join(HERE, "pdfs/mcid_example.pdf")
pdf = pdfplumber.open(path)
page = pdf.pages[0]
# Check text of MCIDS
mcids = []
for c in page.chars:
if "mcid" in c:
while len(mcids) <= c["mcid"]:
mcids.append("")
if not mcids[c["mcid"]]:
mcids[c["mcid"]] = c["tag"] + ": "
mcids[c["mcid"]] += c["text"]
assert mcids == [
"Standard: Test of figures",
"",
"P: 1 ligne",
"P: 2 ligne",
"P: 3 ligne",
"P: 4 ligne",
"P: 0",
"P: 2",
"P: 4",
"P: 6",
"P: 8",
"P: 10",
"P: 12",
"P: Figure 1: Chart",
"",
"P: 1 colonne",
"P: 2 colonne",
"P: 3 colonne",
]
# Check line and curve MCIDs
line_mcids = set(x["mcid"] for x in page.lines)
curve_mcids = set(x["mcid"] for x in page.curves)
assert all(x["tag"] == "Figure" for x in page.lines)
assert all(x["tag"] == "Figure" for x in page.curves)
assert line_mcids & {1, 14}
assert curve_mcids & {1, 14}
# No rects to test unfortunately!