Repository navigation
feat(layout): give a paragraph holding only a picture its line cache - #552
Merged
Merged
Conversation
write_line_caches now writes the one line Hancom writes for a paragraph holding nothing but a plain picture set as a character: as tall as the picture and its outer margins, or as the paragraph's characters when they are taller, its baseline at 85 % of that, spaced as the paragraph's characters are unless the picture affects the line spacing. A picture with a caption, a shadow or effects, or in a paragraph not spaced by a percentage, is left for Hancom. Saved as .hwp, the cache becomes the paragraph's PARA_LINE_SEG, which viewers other than Hancom Office use to place the picture (#550). Saving without calling write_line_caches is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
airmang
force-pushed
the
feat/hwp-save-line-caches
branch
from
October 23, 2026 13:15
5c6d850 to
57cbb07
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #550 as an opt-in.
Background
A
.hwpparagraph'sPARA_LINE_SEGis the same line layout cache ashp:linesegarrayin HWPX. python-hwpx writes new paragraphs without one and leaves the layout to Hancom Office, which lays out a paragraph without a cache when it opens the file. Hancom does take a cache that is present as written, so a cache can only be written when it is exactly the one Hancom would write — a wrong one moves or squeezes text.Some other HWP viewers place a picture from its paragraph's
PARA_LINE_SEGand skip it when there is none, which is what #550 reports.Change
hwpx.layout.line_cache.write_line_caches(doc)(experimental, opt-in) now also writes the one line Hancom writes for a paragraph holding nothing but a plain picture set as a character:A picture with a caption, a shadow or effects, or in a paragraph not spaced by a percentage, is left for Hancom.
Calling it before saving to
.hwpcarries the caches intoPARA_LINE_SEG:Saving without calling it is unchanged.
Tests
line_cache_pictures_alone.hwpx: a Hancom-saved document of 120 picture paragraphs (character sizes, picture heights, outer margins, affectLSpacing) between text paragraphs; every cache written matches Hancom's.PARA_LINE_SEGin an.hwpsave; a picture with a caption, a shadow or a fixed spacing gets none.🤖 Generated with Claude Code