Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: set image extent so that it fits on a page #16

Open
andalman opened this issue Sep 29, 2022 · 6 comments · Fixed by #34 · May be fixed by #35
Open

Suggestion: set image extent so that it fits on a page #16

andalman opened this issue Sep 29, 2022 · 6 comments · Fixed by #34 · May be fixed by #35
Assignees
Labels
enhancement New feature or request

Comments

@andalman
Copy link
Contributor

When I create a docx, I’d like for any images to fit on a single page. I realize I can resize the image on my end, but that isn’t ideal as I’d like the original image to remain untouched.

I’ve attached two docx files that illustrate the issue:
Under-the-Wave-Created-DocX.docx
Under-the-Wave-Created-Word.docx

The first docx file was created using DocX, and you can see that my image, since it is large, is pushed to the next page and also clipped. When I add the original image into Word, you can see that it is resized to fit the page. (Word also – annoyingly – resizes the original image. However, when I unzip the docx, replace the resized image with my original image, then re-created the docx file, Word still displays the image correctly.)

I’ve only looked quickly, but it seems to me that this is controlled by the wp:extent element. In the DocX package, it looks like the extent is determined by the size of the image. This seems like a great fallback. It would be nice, though, if the image was scaled to fit when the image’s width/height is greater than the page’s usable width/height (i.e. not including margins).

Bonus suggestion #1: It would also be nice if there were a way to set the image’s display width more directly. Perhaps NSTextAttachment could be extended to have a “docxExportWidthFraction” attribute. If that were set to “0.5”, then the display width would be set to 50% of the page’s usable width.

Bonus suggestion #2: When the “docxExportWidthFraction” is set, it might be nice to center the image horizontally. (Though I wouldn’t complain if images were just always centered, rather than left-aligned.)

@shinjukunian
Copy link
Owner

Hi,
#34 implements defining a page size manually. This would be the starting point for scaling images (shrink to fit page, etc). #35 Is a draft of an implementation if scaling images larger than the printable area to fit the page. There are unfortunately still a few issues with the implementation and I am not entirely happy how things end up in the generated .docx...

@andalman
Copy link
Contributor Author

andalman commented Jan 16, 2023 via email

@shinjukunian
Copy link
Owner

It would be awesome if you could have a look at #35 to check whether this gives the desired behavior. I made a few remarks in the PR (#35) about aspects that might be changed / improved.
I guess further (auto-)scaling of images could be implemented in a NSTextAttachement subclass if desired.

@andalman
Copy link
Contributor Author

andalman commented Jan 17, 2023 via email

@shinjukunian shinjukunian self-assigned this Feb 25, 2023
@shinjukunian shinjukunian added the enhancement New feature or request label Feb 25, 2023
This was linked to pull requests Feb 25, 2023
@andalman
Copy link
Contributor Author

andalman commented Feb 28, 2023 via email

@shinjukunian
Copy link
Owner

Hi,

I am glad to hear the Scale-to-Fit works well for you. I have realized that my original plan - allowing custom NSTextAttachement subclasses to override autosizing behavior, doesn't work since subclasses can't override functionality added via extensions. I will take a closer look again, but I guess that one could in principle merge the branch as-is - after all there is always the alternative of explicitly specifying an image size if auto-sizing is not desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants