-
Notifications
You must be signed in to change notification settings - Fork 692
Description
Description of the bug
For text span type 1 (stroked) or 2 ("artificial" bold), the linewidth attribute of the corresponding elements returned by Page.get_texttrace() is always fixed to 0.05 * size (font size), regardless of the width of the stroke specified.
Here is an example PDF:
test.pdf
In the example PDF, the first text span is of type 2, which has two elements of type 0 and 1 in the list returned by Page.get_texttrace(). However, even though the width of stoke is defined by 2 Tr .4 w, the linewidth is fixed to 0.6 instead, which is 0.05 * size. I have verified that PDF viewers respect changes in the stoke width, but PyMuPDF always reports the same linewidth.
How to reproduce the bug
Open the PDF in PyMuPDF, call get_texttrace() on the first page. Below are the first two elements of the trace list:
trace[0]:
{'dir': (1.0, 0.0),
'font': 'Fsnfu0',
'wmode': 0,
'flags': 4,
'bidi_lvl': 0,
'bidi_dir': 2,
'ascender': 0.9390000104904175,
'descender': -0.28200000524520874,
'colorspace': 3,
'color': (0.09997711330652237, 0.09997711330652237, 0.09997711330652237),
'size': 12.0,
'opacity': 1.0,
'linewidth': 0.6000000000000001,
'spacewidth': 2.4375,
'type': 0,
'bbox': (72.0250015258789,
74.05152893066406,
211.11915588378906,
86.05152893066406),
'layer': '',
'seqno': 0,
'chars': ((48,
847,
(72.0250015258789, 83.280029296875),
(72.0250015258789,
74.05152893066406,
78.4351577758789,
86.05152893066406)),
(49,
848,
(78.51699829101562, 83.280029296875),
(78.51699829101562,
74.05152893066406,
84.92715454101562,
86.05152893066406)),
(50,
849,
(85.00899505615234, 83.280029296875),
(85.00899505615234,
74.05152893066406,
91.41915130615234,
86.05152893066406)),
(51,
850,
(91.50099182128906, 83.280029296875),
(91.50099182128906,
74.05152893066406,
97.91114807128906,
86.05152893066406)),
(65,
1,
(97.99298858642578, 83.280029296875),
(97.99298858642578,
74.05152893066406,
105.06525421142578,
86.05152893066406)),
(66,
26,
(104.9889907836914, 83.280029296875),
(104.9889907836914,
74.05152893066406,
112.2370376586914,
86.05152893066406)),
(67,
28,
(112.23699188232422, 83.280029296875),
(112.23699188232422,
74.05152893066406,
120.54558563232422,
86.05152893066406)),
(68,
34,
(120.49299621582031, 83.280029296875),
(120.49299621582031,
74.05152893066406,
128.7254180908203,
86.05152893066406)),
(97,
205,
(128.72499084472656, 83.280029296875),
(128.72499084472656,
74.05152893066406,
135.09999084472656,
86.05152893066406)),
(98,
230,
(134.98898315429688, 83.280029296875),
(134.98898315429688,
74.05152893066406,
141.72140502929688,
86.05152893066406)),
(99,
232,
(141.72097778320312, 83.280029296875),
(141.72097778320312,
74.05152893066406,
148.01980590820312,
86.05152893066406)),
(100,
238,
(148.02098083496094, 83.280029296875),
(148.02098083496094,
74.05152893066406,
154.74754333496094,
86.05152893066406)),
(96,
1244,
(154.7529754638672, 83.280029296875),
(154.7529754638672,
74.05152893066406,
161.3740692138672,
86.05152893066406)),
(126,
1145,
(161.4729766845703, 83.280029296875),
(161.4729766845703,
74.05152893066406,
167.8831329345703,
86.05152893066406)),
(33,
996,
(167.96498107910156, 83.280029296875),
(167.96498107910156,
74.05152893066406,
171.48060607910156,
86.05152893066406)),
(64,
1068,
(171.48098754882812, 83.280029296875),
(171.48098754882812,
74.05152893066406,
182.21536254882812,
86.05152893066406)),
(35,
1005,
(181.968994140625, 83.280029296875),
(181.968994140625,
74.05152893066406,
188.414306640625,
86.05152893066406)),
(36,
1097,
(188.46099853515625, 83.280029296875),
(188.46099853515625,
74.05152893066406,
194.87115478515625,
86.05152893066406)),
(37,
1159,
(194.9530029296875, 83.280029296875),
(194.9530029296875,
74.05152893066406,
204.8670654296875,
86.05152893066406)),
(94,
1147,
(204.70899963378906, 83.280029296875),
(204.70899963378906,
74.05152893066406,
211.11915588378906,
86.05152893066406)))}
trace[1]:
{'dir': (1.0, 0.0),
'font': 'Fsnfu0',
'wmode': 0,
'flags': 4,
'bidi_lvl': 0,
'bidi_dir': 2,
'ascender': 0.9390000104904175,
'descender': -0.28200000524520874,
'colorspace': 3,
'color': (0.5999389886856079, 0.6000305414199829, 0.5999237298965454),
'size': 12.0,
'opacity': 1.0,
'linewidth': 0.6000000000000001,
'spacewidth': 2.4375,
'type': 1,
'bbox': (72.0250015258789,
74.05152893066406,
211.11915588378906,
86.05152893066406),
'layer': '',
'seqno': 1,
'chars': ((48,
847,
(72.0250015258789, 83.280029296875),
(72.0250015258789,
74.05152893066406,
78.4351577758789,
86.05152893066406)),
(49,
848,
(78.51699829101562, 83.280029296875),
(78.51699829101562,
74.05152893066406,
84.92715454101562,
86.05152893066406)),
(50,
849,
(85.00899505615234, 83.280029296875),
(85.00899505615234,
74.05152893066406,
91.41915130615234,
86.05152893066406)),
(51,
850,
(91.50099182128906, 83.280029296875),
(91.50099182128906,
74.05152893066406,
97.91114807128906,
86.05152893066406)),
(65,
1,
(97.99298858642578, 83.280029296875),
(97.99298858642578,
74.05152893066406,
105.06525421142578,
86.05152893066406)),
(66,
26,
(104.9889907836914, 83.280029296875),
(104.9889907836914,
74.05152893066406,
112.2370376586914,
86.05152893066406)),
(67,
28,
(112.23699188232422, 83.280029296875),
(112.23699188232422,
74.05152893066406,
120.54558563232422,
86.05152893066406)),
(68,
34,
(120.49299621582031, 83.280029296875),
(120.49299621582031,
74.05152893066406,
128.7254180908203,
86.05152893066406)),
(97,
205,
(128.72499084472656, 83.280029296875),
(128.72499084472656,
74.05152893066406,
135.09999084472656,
86.05152893066406)),
(98,
230,
(134.98898315429688, 83.280029296875),
(134.98898315429688,
74.05152893066406,
141.72140502929688,
86.05152893066406)),
(99,
232,
(141.72097778320312, 83.280029296875),
(141.72097778320312,
74.05152893066406,
148.01980590820312,
86.05152893066406)),
(100,
238,
(148.02098083496094, 83.280029296875),
(148.02098083496094,
74.05152893066406,
154.74754333496094,
86.05152893066406)),
(96,
1244,
(154.7529754638672, 83.280029296875),
(154.7529754638672,
74.05152893066406,
161.3740692138672,
86.05152893066406)),
(126,
1145,
(161.4729766845703, 83.280029296875),
(161.4729766845703,
74.05152893066406,
167.8831329345703,
86.05152893066406)),
(33,
996,
(167.96498107910156, 83.280029296875),
(167.96498107910156,
74.05152893066406,
171.48060607910156,
86.05152893066406)),
(64,
1068,
(171.48098754882812, 83.280029296875),
(171.48098754882812,
74.05152893066406,
182.21536254882812,
86.05152893066406)),
(35,
1005,
(181.968994140625, 83.280029296875),
(181.968994140625,
74.05152893066406,
188.414306640625,
86.05152893066406)),
(36,
1097,
(188.46099853515625, 83.280029296875),
(188.46099853515625,
74.05152893066406,
194.87115478515625,
86.05152893066406)),
(37,
1159,
(194.9530029296875, 83.280029296875),
(194.9530029296875,
74.05152893066406,
204.8670654296875,
86.05152893066406)),
(94,
1147,
(204.70899963378906, 83.280029296875),
(204.70899963378906,
74.05152893066406,
211.11915588378906,
86.05152893066406)))}
Both of them report the linewidth as 0.6, but at least the type 1 span should report linewidth 0.4.
PyMuPDF version
1.27.1
Operating system
Windows
Python version
3.13