Skip to content

Commit 53f8a72

Browse files
committed
Some provisional definitions
To cope with upcoming features of MuPDF we make a few provisional definitions for flags that will be introduced then. This will avoid complex version checks in our code. Also adjust a table markdown output test: We do no longer replace line breaks by simple spaces, but by HTML line breaks `<br>`.
1 parent 902e92c commit 53f8a72

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

src/__init__.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8314,7 +8314,7 @@ def _show_pdf_page(self, fz_srcpage, overlay=1, matrix=None, xref=0, oc=0, clip=
83148314
#-------------------------------------------------------------
83158315
resources = mupdf.pdf_dict_get_inheritable(tpageref, PDF_NAME('Resources'))
83168316
if not resources.m_internal:
8317-
resources = mupdf.pdf_dict_put_dict(tpageref,PDF_NAME('Resources'),5)
8317+
resources = mupdf.pdf_dict_put_dict(tpageref,PDF_NAME('Resources'),5)
83188318
subres = mupdf.pdf_dict_get(resources, PDF_NAME('XObject'))
83198319
if not subres.m_internal:
83208320
subres = mupdf.pdf_dict_put_dict(resources, PDF_NAME('XObject'), 5)
@@ -9199,7 +9199,7 @@ def remove_rotation(self):
91999199
pass
92009200

92019201
for xref, rect in widgets: # modify field rectangles
9202-
widget = page.load_widget(xref)
9202+
widget = self.load_widget(xref)
92039203
widget.rect = r
92049204
widget.update()
92059205
return rot # the inverse of the generated derotation matrix
@@ -13487,6 +13487,13 @@ def width(self):
1348713487
TEXT_OUTPUT_XML = 3
1348813488
TEXT_OUTPUT_XHTML = 4
1348913489

13490+
TEXT_STRIKEOUT = 1
13491+
TEXT_UNDERLINE = 2
13492+
TEXT_SYNTHETIC = 4
13493+
TEXT_BOLD = 8
13494+
TEXT_FILLED = 16
13495+
TEXT_STROKED = 32
13496+
1349013497
TEXT_PRESERVE_LIGATURES = mupdf.FZ_STEXT_PRESERVE_LIGATURES
1349113498
TEXT_PRESERVE_WHITESPACE = mupdf.FZ_STEXT_PRESERVE_WHITESPACE
1349213499
TEXT_PRESERVE_IMAGES = mupdf.FZ_STEXT_PRESERVE_IMAGES
@@ -13507,6 +13514,7 @@ def width(self):
1350713514
TEXT_COLLECT_VECTORS = 1024
1350813515
TEXT_IGNORE_ACTUALTEXT = 2048
1350913516
TEXT_STEXT_SEGMENT = 4096
13517+
TEXT_COLLECT_FLAGS = 32768 # mupdf.FZ_STEXT_COLLECT_FLAGS
1351013518

1351113519
TEXTFLAGS_WORDS = (0
1351213520
| TEXT_PRESERVE_LIGATURES
@@ -16509,6 +16517,7 @@ def __str__(self):
1650916517
font_flags = JM_char_font_flags(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)), line, ch)
1651016518
origin = mupdf.FzPoint(ch.m_internal.origin)
1651116519
style.size = ch.m_internal.size
16520+
style.font_flags = font_flags
1651216521
style.flags = ch.m_internal.flags
1651316522
style.font = JM_font_name(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)))
1651416523
if THIS_MUPDF >= MUPDF1250:
@@ -16519,7 +16528,8 @@ def __str__(self):
1651916528
style.asc = JM_font_ascender(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)))
1652016529
style.desc = JM_font_descender(mupdf.FzFont(mupdf.ll_fz_keep_font(ch.m_internal.font)))
1652116530

16522-
if (0
16531+
if (
16532+
0
1652316533
or style.size != old_style.size
1652416534
or style.bidi != old_style.bidi
1652516535
or style.font_flags != old_style.font_flags
@@ -16528,7 +16538,7 @@ def __str__(self):
1652816538
or style.color != old_style.color
1652916539
or style.opacity != old_style.opacity
1653016540
or style.font != old_style.font
16531-
):
16541+
):
1653216542
if old_style.size > 0:
1653316543
# not first one, output previous
1653416544
if raw:
@@ -16562,24 +16572,24 @@ def __str__(self):
1656216572
span["descender"] = desc
1656316573
span["opacity"] = style.opacity
1656416574
# add more keys depending on MuPDF version
16565-
if THIS_MUPDF >= MUPDF1250: #separate if because not flags-dependent
16575+
if THIS_MUPDF >= MUPDF1250: # separate if because not flags-dependent
1656616576
span["opacity"] = style.opacity
1656716577
# rest of keys only make sense for FZ_STEXT_COLLECT_FLAGS
16568-
if dev_flags & mupdf.FZ_STEXT_COLLECT_FLAGS:
16569-
span["underline"] = bool(style.flags & mupdf.FZ_STEXT_UNDERLINE)
16570-
span["strikeout"] = bool(style.flags & mupdf.FZ_STEXT_STRIKEOUT)
16578+
if dev_flags & TEXT_COLLECT_FLAGS:
16579+
span["underline"] = bool(style.flags & TEXT_UNDERLINE)
16580+
span["strikeout"] = bool(style.flags & TEXT_STRIKEOUT)
1657116581
else:
1657216582
span["underline"] = None
1657316583
span["strikeout"] = None
1657416584

1657516585
if THIS_MUPDF > MUPDF1251:
16576-
if dev_flags & mupdf.FZ_STEXT_COLLECT_FLAGS:
16577-
span["bold"] = bool(style.flags & mupdf.FZ_STEXT_BOLD)
16586+
if dev_flags & TEXT_COLLECT_FLAGS:
16587+
span["bold"] = bool(style.flags & TEXT_BOLD)
1657816588
else:
1657916589
span["bold"] = None
16580-
span["filled"] = bool(style.flags & mupdf.FZ_STEXT_FILLED)
16581-
span["stroked"] = bool(style.flags & mupdf.FZ_STEXT_STROKED)
16582-
span["clipped"] = bool(style.flags & mupdf.FZ_STEXT_CLIPPED)
16590+
span["filled"] = bool(style.flags & TEXT_FILLED)
16591+
span["stroked"] = bool(style.flags & TEXT_STROKED)
16592+
span["clipped"] = bool(style.flags & TEXT_CLIPPED)
1658316593

1658416594
# Need to be careful here - doing 'old_style=style' does a shallow
1658516595
# copy, but we need to keep old_style as a distinct instance.
@@ -16594,7 +16604,7 @@ def __str__(self):
1659416604
char_dict[dictkey_origin] = JM_py_from_point( ch.m_internal.origin)
1659516605
char_dict[dictkey_bbox] = JM_py_from_rect(r)
1659616606
if THIS_MUPDF >= MUPDF1250:
16597-
char_dict["synthetic"] = bool(ch.m_internal.flags & mupdf.FZ_STEXT_SYNTHETIC)
16607+
char_dict["synthetic"] = bool(ch.m_internal.flags & TEXT_SYNTHETIC)
1659816608
char_dict[dictkey_c] = chr(ch.m_internal.c)
1659916609

1660016610
if char_list is None:

src/extra.i

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,7 +3125,7 @@ mupdf::FzRect JM_make_spanlist(
31253125
DICT_SETITEMSTR_DROP(span, "opacity", Py_BuildValue("f", style.opacity));
31263126
#endif
31273127

3128-
// rest of keys only make sense if FZ_STEXT_COLLECT_FLAGS was set
3128+
// rest of keys only make sense if FZ_STEXT_COLLECT_FLAGS (32768) was set
31293129
#if (THIS_MUPDF >= MUPDF1250)
31303130
if (dev_flags & 32768)
31313131
{
@@ -3139,9 +3139,9 @@ mupdf::FzRect JM_make_spanlist(
31393139
}
31403140
#endif
31413141
#if (THIS_MUPDF > MUPDF1251)
3142-
if (dev_flags & FZ_STEXT_COLLECT_FLAGS)
3142+
if (dev_flags & 32768) // FZ_STEXT_COLLECT_FLAGS = 32768
31433143
{
3144-
DICT_SETITEMSTR_DROP(span, "bold", JM_BOOL(style.flags & FZ_STEXT_BOLD));
3144+
DICT_SETITEMSTR_DROP(span, "bold", JM_BOOL(style.flags & 8)); // FZ_STEXT_BOLD = 8
31453145
}
31463146
else
31473147
{

tests/test_tables.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ def test_markdown():
288288
text = (
289289
"|Header1|Header2|Header3|\n"
290290
"|---|---|---|\n"
291-
"|Col11 Col12|Col21 Col22|Col31 Col32 Col33|\n"
292-
"|Col13|Col23|Col34 Col35|\n"
291+
"|Col11 Col12|Col21<br>Col22|Col31<br>Col32<br>Col33|\n"
292+
"|Col13|Col23|Col34<br>Col35|\n"
293293
"|Col14|Col24|Col36|\n"
294-
"|Col15|Col25 Col26||\n\n"
294+
"|Col15|Col25<br>Col26||\n\n"
295295
)
296296
assert tab.to_markdown() == text
297297

0 commit comments

Comments
 (0)