[solved] Picture set to 80% but become very very large after exported to .docx or .rtf

General TRichView support forum. Please post your questions here
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

[solved] Picture set to 80% but become very very large after exported to .docx or .rtf

Post by edwinyzh »

The steps that caused the issue:

- Insert a picture.
- set its size to 80%
- export to .docx
- you'll find the the picture enlarged to something like 500% or 1000%. In short, very large.
Last edited by edwinyzh on Wed Jun 29, 2022 3:01 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by Sergey Tkachenko »

I cannot reproduce this problem.
Please send me an RVF file with a scaled picture for testing.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by edwinyzh »

Is XML OK? You know, I use XML.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by edwinyzh »

Additional info - the issue happens with content added with `TRichViewXml.AppendFromStream`.

Maybe this is cause?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by Sergey Tkachenko »

Please give me step-by-step instructions how to reproduce this problem.
I cannot reproduce it myself: I tried saving and loading to DocX and RichViewXML, scaled pictures were OK in the both of them.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by edwinyzh »

When I can construct a test program/code I'll provide it to you.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by edwinyzh »

New finding:
The wrong image size seems to be happening inside TRichViewEdit but not after exporting to Word.

If the png image is not resized, the savec xml is like:

Code: Select all

<image spacing="0" class="TPngImage" img="89504E470D0A1A0A0000000D4948....
But if I reduce its size with mouse drag-and-drop inside TRichViewEdit, after saving to xml, the related xml code is like:

Code: Select all

<image spacing="0" width="9127" height="3578" class="TPngImage" img="89504E470D0A1A0A0000000D4948...
As a result, after reloaded to TRichViewEdit, the image is very large!
Note, the original image size is 656x257
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by edwinyzh »

More findings - the image size is already wrong in `TRVGraphicItemInfo.SetExtraIntProperty`.

If you check the call stack produced by the IDE debugger, 9404 is the calculated new image width which is wrong - I reduced the size of a 656x257 image and the new width couldn't be 9404:

Code: Select all

RVItem.TRVGraphicItemInfo.SetExtraIntProperty(???,9404)
RVItem.TCustomRVItemInfo.SetExtraIntPropertyEx(14981552,???)
CRVData.TCustomRVData.SetItemExtraIntPropertyEx(4,3,9404)
RVERVData.TRVEditRVData.Do_ExtraIntProperty(4,3,9404,rvrfNormal)
RVEdit.TCustomRichViewEdit.SetItemExtraIntPropertyExEd(4,3,9404,False)
RVEdit.TCustomRichViewEdit.SetItemExtraIntPropertyEd(???,???,9404,False)
RVERVData.TRVEditRVData.ResizeItem(4,???,333)
RVERVData.TRVEditRVData.MouseUp(mbLeft,[],52,401)
RichView.TCustomRichView.MouseUp(mbLeft,[],13176640,401)
Vcl.Controls.TControl.DoMouseUp((514, (), 0, (), 52, 401, (), (52, 401), (), 0),(out of bound) 116)
Vcl.Controls.TControl.WMLButtonUp((514, (), 0, (), 52, 401, (), (52, 401), (), 0))
Vcl.Controls.TControl.WndProc((514, 0, 26279988, 0, 0, 0, (), 52, 401, (), 0, 0, ()))
Vcl.Controls.TWinControl.WndProc((514, 0, 26279988, 0, 0, 0, (), 52, 401, (), 0, 0, ()))
RichView.TCustomRichView.WndProc((514, 0, 26279988, 0, 0, 0, (), 52, 401, (), 0, 0, ()))
Vcl.Controls.TWinControl.MainWndProc(???)
System.Classes.StdWndProc(1970246,514,0,26279988)
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by edwinyzh »

More finding:

Maybe `TRVEditRVData.ResizeItem` or TRichViewXml mixed up pixels and twips?
You know, I set all units as twips for all TRichView components.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by Sergey Tkachenko »

It looks like I understand the problem.

Do you save XML without styles?

In this case, none of TRVStyle properties are saved in XML, including TRVStyle.Units.

Because of this, TRichViewXML does not know that values are saved in twips, loads them as pixels and they become too large.

I'll provide a fix today.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by Sergey Tkachenko »

See the updated RichViewXML files in https://www.trichview.com/forums/viewto ... 172#p41172

In this update, RVStyle.Units are saved even if other TRVStyle properties are not saved.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by edwinyzh »

Sergey Tkachenko wrote: Wed Jun 29, 2022 12:15 pm It looks like I understand the problem.
Do you save XML without styles?
No, TRichViewXml.SaveStyles is False in my case.

I'll try you rvxml fixes, I appreciate your quick fixes!
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by Sergey Tkachenko »

edwinyzh wrote: Wed Jun 29, 2022 2:46 pm No, TRichViewXml.SaveStyles is False in my case.
This is the reason of this problem: in the previous version, if SaveStyles = False, measure units were not saved in XML.
Unfortunately, since the problem was in saving. not in loading, this change does not help with files that were saved previously.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: Picture set to 80% but become very very large after exported to .docx or .rtf

Post by edwinyzh »

This issue's fixed with your latest updates, thank you!
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [solved] Picture set to 80% but become very very large after exported to .docx or .rtf

Post by Sergey Tkachenko »

I've made a small correction, and uploaded new files to https://www.trichview.com/support/files ... xmlpas.zip

There was a bug: if RvXML.StyleLoadingMode <> slmIgnore, and XML file was saved without styles but with measure units, RvXML might think that this XML contains 0 styles (instead of "this XML was saved without styles")
Post Reply