Skip to content

feat(layout): write line caches for more picture paragraphs, columns and pages clear of wrapped objects - #554

Merged
airmang merged 1 commit into
mainfrom
feat/line-cache-wider-pictures
Oct 23, 2026
Merged

airmang merged 1 commit into
mainfrom
feat/line-cache-wider-pictures

Conversation

@airmang

@airmang airmang commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Follow-up to #552 (#550).

Background

write_line_caches(doc) (experimental, opt-in) writes a paragraph's line layout cache only where it is exactly the one Hancom Office writes: Hancom takes a cache that is present as written, so a wrong one moves or squeezes text. Saved as .hwp, the cache is the paragraph's PARA_LINE_SEG, which some other HWP viewers need to place a picture on a paragraph of its own. #552 covered a plain picture alone in a paragraph spaced by a percentage, in a one-column section with no object text runs beside.

Change

write_line_caches now also writes the lines Hancom writes for:

  • a picture alone in its paragraph (set as a character, no text)
    • with a caption: above or below it, the caption's lines and its gap join the line; beside it, the line stays as tall as the picture
    • with a soft edge or an inner shadow (they take no room)
    • in a paragraph spaced fixed, at least or between lines (spaced from the line's height, so a fixed spacing may be smaller than the picture), or setting its characters at the top, centre or bottom of the line
  • several pictures and nothing else in a paragraph spaced by a percentage, none of them affecting the line spacing: as many on a line as fit the column, each picture eight characters along the line's text, each line as tall as its tallest picture
  • newspaper columns of equal width: text and picture paragraphs laid out as wide as their column; where the columns change inside a section, as wide as the columns the paragraph is in (they were measured at the section's first columns' width)
  • a section with an object text runs beside (square, tight or through wrapping): the pages other than the one holding that object's paragraph and the next one (the whole section was skipped). An object in a header or footer still leaves the section alone.

Left for Hancom: a picture whose glow, outer shadow or reflection takes room around it, a picture with a shadow written as a drawing's (hp:shadow), a caption whose lines are less sure, several pictures affecting the line spacing, balanced or parallel columns, and a picture paragraph holding spaces (viewers draw those without a cache). Tables set as a character and table cells keep getting caches in one column only.

Saving without calling write_line_caches is unchanged.

Tests

  • Three Hancom-saved documents laid out from python-hwpx paragraphs without a cache, added to the comparison of every cache written with Hancom's:
    • line_cache_pictures_kinds.hwpx: captions on four sides, fixed / at least / between-lines spacing, top / centre / bottom alignment, a soft edge, an inner shadow, two rows of pictures; it ends with four pictures left for Hancom (long caption, glow, outer shadow, pictures affecting the spacing), which get no cache
    • line_cache_pictures_columns.hwpx: one column, then two columns from a paragraph inside the section
    • line_cache_pictures_beside.hwpx: a square-wrapped picture, picture and text paragraphs on its page and on later pages
  • Unit tests for captions, spacings, several pictures, columns, balanced and parallel columns, the pages beside a wrapped object, and the effects left for Hancom.

🤖 Generated with Claude Code

…and pages clear of wrapped objects

write_line_caches now also gives these paragraphs the lines Hancom writes:

- a paragraph holding nothing but a picture set as a character with a caption
  (above or below it the caption's lines and its gap join the line, beside it
  the line stays as tall as the picture), with a soft edge or an inner shadow,
  in a paragraph spaced fixed, at least or between lines (spaced from the
  line's height), or setting its characters at the top, centre or bottom;
- a paragraph holding several such pictures and nothing else, none of them
  affecting the line spacing, in a paragraph spaced by a percentage: as many
  pictures on a line as fit the column, each line as tall as its tallest;
- the text and picture paragraphs of newspaper columns of equal width, laid
  out as wide as their column, where the columns change inside a section as
  wide as those they are in (they were measured at the section's first
  columns' width);
- the paragraphs of a section with an object text runs beside, on the pages
  other than the one holding that object's paragraph and the next (the whole
  section was skipped).

A picture whose glow, outer shadow or reflection takes room around it, one
with a shadow written as a drawing's, a caption whose lines are less sure,
and balanced or parallel columns are left for Hancom, as is a picture
paragraph holding spaces. Saved as .hwp, the caches become the paragraphs'
PARA_LINE_SEG records, which viewers other than Hancom Office use to place
the pictures. Saving without calling write_line_caches is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@airmang
airmang merged commit b44f884 into main Oct 23, 2026
13 checks passed
airmang added a commit that referenced this pull request Oct 24, 2026
… default stops (#559)

A paragraph under a picture bullet (hh:bullet@useImage) loses the room
Hancom gives the picture: an em whatever the picture's shape, then the
gap (textOffset) and the width adjustment, off the first line and, with
자동 내어 쓰기, off every line. FormFit took it as no label at all, so
such paragraphs broke later than in Hancom, and write_line_caches gave
them lines Hancom does not lay out. A picture bullet sized by its picture
(useInstWidth) still takes no room in FormFit; write_line_caches leaves
its paragraphs to Hancom.

A tab reaches the default stops of the section it is in, as far apart
as hp:secPr@tabStopVal says; the page estimate and write_line_caches
counted 4,000 in every section. A section giving its stops in another
unit than HWPUNIT gets no caches.

Both came up once write_line_caches wrote the sections around objects
text runs beside (#554). Two Hancom-saved fixtures show the layouts.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant