Files
designcraft/crates
Hamza Naveedandskylar taylor-barrick 8fce28258d IDML export: a document's hyperlinks are written out (#1446) (#1659)
* IDML import: a page item's or a text run's hyperlink survives (#1446)

IDML carries a hyperlink as three elements: a source, a destination and a
`Hyperlink` joining them by `Self`. Only `CrossReferenceSource` was mapped, so
an image frame linked to a photo and a run of text linked to a page were
dropped on import, although both are native here and both export to PDF.

The names are collected as the package is read and the two ends put together
in `finish`, once the pages, page items and anchors they name exist. A link
whose source or destination is not in the file is dropped with a warning
saying which, rather than silently or as a link that goes nowhere.

Carries all three review fixes:

- a source recorded in a table cell's or a footnote's story is dropped. Those
  stories are built under the StoryId(0) placeholder, so the link named a
  story nothing can look up, with offsets into text that is not there. The
  warning says where the text was instead of claiming it was not text.
- the same for a HyperlinkTextDestination in such a story: its anchor id is
  (0 << 24) | k, so it collides with other cells' anchors and belongs to no
  story the cross-reference index holds; the link resolved to Anchor(1) and
  the PDF left the annotation out without a word.
- the index's topic cross-references go in at the start of the first story
  with text after the ranges are recorded, so the ranges for that story are
  shifted with the markers; a range left alone covered the wrong nine bytes.

Rebased onto the post-split main, hunk by hunk: the Importer struct, its
fields, the element scan, hyperlink_list and finish are in import.rs, while
StoryBuilder, walk_story and the anchor list are in import/story.rs. finish
answers (Document, Vec<String>) so the warnings reach the caller.

* An anchor a hyperlink cannot mean is refused, not ignored

This branch carries its own copy of `dest_param`'s anchor arm -- the IDML import
needed anchors as link destinations and added it here independently of #1555 --
and it has the same hole, so review is right that the fix has to be here as well
rather than only on that PR.

`dest_param` returns `Result<Option<_>>`. `None` still means no destination was
given, which `hyperlink.edit` needs for an edit that only renames; an `anchor`
that is given and names none is an error.

An unknown *id* was accepted outright, since `as_u64` answers for any number, so
a link was stored to an anchor nobody has and the export quietly left it out. On
`hyperlink.edit` the `None` read as "no destination given", so the command
reported success and kept the old destination, which is the case review
reported. An unknown *name* did already fail on `hyperlink.create`, but with
"give `url`, `email`, `page` or `anchor`" -- the wrong problem named.

The same change is on #1555, deliberately: each PR introduces this code on its
own line and each has to be right on its own. Whichever lands first, the other's
conflict is the same text on both sides.

* IDML export: a document's hyperlinks are written out (#1446)

Import reads hyperlinks now, but export dropped them, so a round trip lost
every link the document had. The three elements IDML wants are written: a
destination, a source, and a `Hyperlink` joining them.

A link on a run of text is a `HyperlinkTextSource` around the ranges it
covers, and the element nests inside a `ParagraphStyleRange`, so a link whose
text crosses a paragraph is written as one source per paragraph and each piece
stays clickable. Consecutive ranges of one link share a single source element.

Carries both review fixes:

- a link to an anchor whose text has been deleted is not written. The anchor
  is resolved first, as the page destination's page already was, so the file
  cannot hold a `Hyperlink` whose `Destination` names no element.
- every `Self` names one element. Three links on one frame wrote three
  `HyperlinkPageItemSource` elements all called i12, and each link to a page
  pushed another `HyperlinkPageDestination`; the item source carries the
  link's index now, and the page destination is written once per page as
  url_dest_el already did for URLs. The round-trip test collects every `Self`
  in the designmap and asserts none repeats, so an element added later is
  covered without anyone remembering to extend it.

Rebased onto the post-split main, on top of the rebased #1652: the `Ex` state
is in export.rs, the hyperlink elements are written in export/designmap.rs
with url_dest_el, fnv and has_self beside their only caller, and the run
cutting and wrapping is in export/story.rs.

* Split the hyperlink and index-marker steps out of Importer::run, under clippy's complexity limit

* Split the hyperlink and index-marker steps out of Importer::run, under clippy's complexity limit

* Split the hyperlink steps out of story_para, under clippy's complexity limit

* IDML import: say when a link's frame is anchored in text, which PDF export cannot place yet

---------

Co-authored-by: skylar taylor-barrick <hi@skylar.cc>
2026-11-06 10:01:02 +01:00
..
2026-10-31 12:25:44 +00:00
2026-11-04 03:50:09 +00:00