Skip to content

Commit d6339dc

Browse files
committed
Fix handling of hyperlinks with missing characters
1 parent 4ad5bb0 commit d6339dc

6 files changed

Lines changed: 85 additions & 7 deletions

File tree

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Changed:
7171

7272
Fixed:
7373

74+
* Handling of hyperlinks with missing characters
7475
* Glyphs missing from a font (rendered by the fallback font) resulted in
7576
duplicated words when line wrapping
7677
* OpenType: handle optional subtables (e.g. Liberation Sans Narrow now loads)

src/rinoh/paragraph.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ def handle_missing_glyphs(span, container):
439439
if isinstance(span, InlineFlowable):
440440
yield span
441441
return
442+
443+
def annotate(styled_text):
444+
if isinstance(span, AnnotatedSpan):
445+
return AnnotatedSpan(styled_text, anchor=span.anchor_annotation,
446+
link=span.link_annotation)
447+
else:
448+
return styled_text
449+
442450
get_glyph, _ = create_lig_kern(span, container)
443451
string = []
444452
has_missing_glyphs = False
@@ -450,18 +458,21 @@ def handle_missing_glyphs(span, container):
450458
except MissingGlyphException:
451459
has_missing_glyphs = True
452460
if string:
453-
yield SingleStyledText(''.join(string), parent=span)
461+
text = SingleStyledText(''.join(string), parent=span)
462+
yield annotate(text)
454463
string.clear()
455-
if span.parent.style == FALLBACK_STYLE:
456-
yield SingleStyledText('?', parent=span)
464+
if span.parent.style is FALLBACK_STYLE:
465+
text = SingleStyledText('?', parent=span)
466+
yield annotate(text)
457467
else:
458468
fallback_span = SingleStyledText(char, style=FALLBACK_STYLE, parent=span)
459-
yield from handle_missing_glyphs(fallback_span, container)
469+
yield from handle_missing_glyphs(annotate(fallback_span), container)
460470
if not has_missing_glyphs:
461471
yield span
462472
return
463473
if string:
464-
yield SingleStyledText(''.join(string), parent=span)
474+
text = SingleStyledText(''.join(string), parent=span)
475+
yield annotate(text)
465476

466477

467478
class LinePart(object):
964 Bytes
Binary file not shown.

tests_regression/rst/missing_glyphs.pxml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,40 @@
359359
and
360360
361361
.
362+
<paragraph>
363+
Missing glyph in a linked reference:
364+
<reference refuri="http://www.python.org">
365+
366+
,
367+
<reference refuri="http://www.python.org">
368+
369+
after
370+
,
371+
<reference refuri="http://www.python.org">
372+
after
373+
374+
.
375+
<footnote auto="1" ids="f1" names="f1">
376+
<label>
377+
1
378+
<paragraph>
379+
Footnote one!
380+
<footnote auto="1" ids="f2" names="f2">
381+
<label>
382+
2
383+
<paragraph>
384+
Footnote two!
385+
<substitution_definition names="solo">
386+
387+
<target ids="solo" names="solo" refuri="http://www.python.org">
388+
<substitution_definition names="after">
389+
390+
after
391+
<target ids="after" names="after" refuri="http://www.python.org">
392+
<substitution_definition names="before">
393+
after
394+
395+
<target ids="before" names="before" refuri="http://www.python.org">
362396
<substitution_definition names=">">
363397
364398
<paragraph>

tests_regression/rst/missing_glyphs.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ Missing glyphs: |cylcty| and |nabla|.
1010

1111
Without surrounding whitespace:\ |cylcty|\ and\ |nabla|.
1212

13+
Missing glyph in a linked reference: |solo|_, |after|_, |before|_.
14+
15+
.. [#f1] Footnote one!
16+
.. [#f2] Footnote two!
17+
18+
.. |solo| replace:: |nabla|
19+
.. _solo: http://www.python.org
20+
21+
.. |after| replace:: |nabla| after
22+
.. _after: http://www.python.org
23+
24+
.. |before| replace:: after |nabla|
25+
.. _before: http://www.python.org
1326

1427
.. |>| unicode:: 0x2023
1528

tests_regression/rst/missing_glyphs.stylelog

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,26 @@
2626
SingleStyledText('and')
2727
SingleStyledText('∇')
2828
SingleStyledText('.')
29-
Paragraph('Test for word wrapping of a line...') missing_glyphs.rst:17 <paragraph>
29+
Paragraph('Missing glyph in a linked refere...') missing_glyphs.rst:13 <paragraph>
30+
> (0,0,0,0,2) body [Sphinx] > default
31+
MixedStyledText('Missing glyph in a linked refere...')
32+
MixedStyledText('Missing glyph in a linked refere...')
33+
SingleStyledText('Missing glyph in a linked refere...')
34+
MixedStyledText('∇', style='external link') <reference>
35+
> (0,0,1,0,1) external hyperlink [Sphinx] > DEFAULT
36+
SingleStyledText('∇')
37+
SingleStyledText(', ')
38+
MixedStyledText('∇ after', style='external link') <reference>
39+
> (0,0,1,0,1) external hyperlink [Sphinx] > DEFAULT
40+
SingleStyledText('∇')
41+
SingleStyledText(' after')
42+
SingleStyledText(', ')
43+
MixedStyledText('after ∇', style='external link') <reference>
44+
> (0,0,1,0,1) external hyperlink [Sphinx] > DEFAULT
45+
SingleStyledText('after ')
46+
SingleStyledText('∇')
47+
SingleStyledText('.')
48+
Paragraph('Test for word wrapping of a line...') missing_glyphs.rst:29 <paragraph>
3049
> (0,0,0,0,2) body [Sphinx] > default
3150
MixedStyledText('Test for word wrapping of a line...')
3251
MixedStyledText('Test for word wrapping of a line...')
@@ -38,7 +57,7 @@
3857
SingleStyledText('Test for word wrapping of a line...')
3958
SingleStyledText('‣')
4059
SingleStyledText(' Item')
41-
Paragraph('And Menu ‣ Item, Utility Functio...') missing_glyphs.rst:19 <paragraph>
60+
Paragraph('And Menu ‣ Item, Utility Functio...') missing_glyphs.rst:31 <paragraph>
4261
> (0,0,0,0,2) body [Sphinx] > default
4362
MixedStyledText('And Menu ‣ Item, Utility Functio...')
4463
MixedStyledText('And Menu ‣ Item, Utility Functio...')

0 commit comments

Comments
 (0)