Skip to content

Layout: an inline picture is as high as its whole twips, as in Word - #8341

Merged
2 commits merged into
storytold:mainfrom
dfgodvan:w1/picture-whole-twips
Dec 2, 2026
Merged

2 commits merged into
storytold:mainfrom
dfgodvan:w1/picture-whole-twips

Conversation

@dfgodvan

@dfgodvan dfgodvan commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

A picture's height in EMU rarely falls on a whole twip. WordCraft laid it out at its exact EMU height, so at the foot of a page a picture could move on where Word keeps it.

How Word does it. Word keeps a picture's height in whole twips and drops the rest of the EMUs: 2661310 EMU (209.552 pt) is drawn 209.55 pt high, and at the foot of a page only that has to fit above the bottom margin. Measured in Word for Mac with a synthetic document: a picture of 14170.998 twips stays on the page where one of 14171 twips moves on, at single and at 1.5 spacing.

What changes. The inline picture's height is cut to whole twips before the line is measured (crates/layout/src/para/paragraph.rs).

Tests. a_picture_is_as_high_as_its_whole_twips_and_fits_by_them_at_the_page_bottom fails on main without the change. cargo test -p wordcraft-layout --lib passes except the three hyphenation and hidden-text tests that fail on main here too without the dictionaries; cargo fmt --all -- --check and cargo clippy -p wordcraft-layout --all-targets -- -D warnings are clean. A row in docs/layout-parity.md.

Summary by CodeRabbit

  • Bug Fixes
    • Inline pictures now use whole-twip heights when fitting near the bottom of a page, improving pagination at page boundaries.

Word keeps a picture's height in whole twips and drops the rest of the EMUs: 2661310 EMU
(209.552pt) is drawn 209.55pt high, and at the foot of a page only that has to fit above the
bottom margin. Word for Mac: a picture of 14170.998 twips stays where one of 14171 twips moves
on, at single and 1.5 spacing.

Test: a_picture_is_as_high_as_its_whole_twips_and_fits_by_them_at_the_page_bottom (fails
before this change).
# Conflicts:
#	docs/layout-parity.md
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Inline drawing heights are rounded down to whole twips before clamping and layout. A pagination test checks picture placement near a page-bottom fit boundary. The revision history documents the rounding behavior.

Changes: Inline picture layout

Layer / File(s) Summary
Round inline picture height before layout
crates/layout/src/para/paragraph.rs, crates/layout/src/tests.rs, docs/layout-parity.md
Shaped::drawing rounds drawing height to whole twips before the existing clamp and layout. A pagination test checks that a picture 1 EMU below 400.05 pt fits when 400 pt of page space remains, while a 400.05 pt picture does not. The revision history records the rounding behavior.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related issues

  • storytold/wordcraft issue 7109: The issue describes inline-picture placement near a page bottom. This change also adjusts inline-picture height measurement at the page-bottom fit boundary.

Suggested reviewers: benandez, vangel76

Merge Risk: Minimal · up to b8362

Inline picture height is now truncated to whole twips before layout, so page-bottom fit matches Word. The change is small and tested. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: inline pictures are now sized to their whole-twip height, matching Word. The raw summary confirms that Shaped::drawing truncates the drawing height to whole twips befo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: inline pictures are now sized to their whole-twip height, matching Word. The raw summary confirms that Shaped::drawing truncates the drawing height to whole twips before clamping and fitting, and the objectives describe the same truncation. The title is specific and does not use vague terms.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f87e9cd and b8362fc.

Files selected for processing: 3

  • crates/layout/src/para/paragraph.rs
  • crates/layout/src/tests.rs
  • docs/layout-parity.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@autocraft-bot autocraft-bot Bot added the bugfix Fixes something that is broken: wrong result, crash, data loss label Dec 2, 2026
@autocraft-bot autocraft-bot Bot closed this pull request by merging all changes into storytold:main in e5bc372 Dec 2, 2026
cyfung1031 pushed a commit to cyfung1031/wordcraft that referenced this pull request Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes something that is broken: wrong result, crash, data loss

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants