Metafile issue

General TRichView support forum. Please post your questions here
Post Reply
shapoval
Posts: 9
Joined: Tue Mar 01, 2011 5:41 pm

Metafile issue

Post by shapoval »

Hello Sergey,

I have an issue when adding metafiles to an RVF document and then saving them to RTF. When adding metafiles, I scale them to the size of the page by adjusting TMetafile.MMHeight and MMWidth. I use TRichView.DocParameters.PageWidth and PageHeight to get the available width and height of the document. The resulting code looks more or less like the following:

Code: Select all

    mw:=FRVHelper.RichView.DocParameters.PageWidth*100;
    mh:=FRVHelper.RichView.DocParameters.PageHeight*100;
    if (Metafile.MMHeight < mh) or (Metafile.MMWidth < mw) then
    begin
      r:=Round(mh/Metafile.MMHeight*100);
      If Metafile.MMWidth*(r/100)>mw Then
        r:=Round(mw/Metafile.MMWidth*100);
    end
    else
      r:=100;

    Metafile.MMWidth:=Trunc(Metafile.MMWidth * r / 100);
    Metafile.MMHeight:=Trunc(Metafile.MMHeight * r / 100);
So the resulting MMWidth or MMHeight of the metafile should be equal to width or height of the document (actually margins are taken into account as well, but I've removed that code for simplicity). However, when I export it to RTF, the picture doesn't have the desired size. On my PC it looks much smaller than the page width. After some experiments I've found that it looks as I want when I set MMWidth to the value of about 35000, while the page width is 297 mm (A4 landscape). The biggest problem, however, is the fact that on the customer's PC the resulting picture is bigger than the page (not smaller as in my case), so I can't simply use that empirical value. It makes me think that there is some additional scaling somewhere. Do you, may be, know what's going on?

BTW, I don't see the RVF document itself, I only use it as an intermediate storage when exporting to RTF.

Thanks in advance.
JimVern
Posts: 21
Joined: Wed Jul 25, 2012 10:41 pm

Re: Metafile issue

Post by JimVern »

shapoval wrote:... When adding metafiles, I scale them to the size of the page by adjusting TMetafile.MMHeight and MMWidth. I use TRichView.DocParameters.PageWidth and PageHeight to get the available width and height of the document.

...

However, when I export it to RTF, the picture doesn't have the desired size. On my PC it looks much smaller than the page width. After some experiments I've found that it looks as I want when I set MMWidth to the value of about 35000, while the page width is 297 mm (A4 landscape). The biggest problem, however, is the fact that on the customer's PC the resulting picture is bigger than the page (not smaller as in my case), so I can't simply use that empirical value. It makes me think that there is some additional scaling somewhere. Do you, may be, know what's going on?
Before I started using TRichView, I had to do the opposite of what you are trying to do -- manually extract the WMF data out of RTF files. The WMF data includes the image width and height, but not in "pixel" values. There are two sets of RTF values:

\picw, \pich
\picwgoal, \pichgoal

The 1st params are values measured in 100th of a milimeter. The 2nd params are values measured in twips. To calculate the pixels for the first, I use "picw * DPI / 2540". The pixels for the second are "picwgoal * DPI / 1440".

The static values 2540 and 1440 are useful as empirical values. The DPI however can be different on each user's computer, which is likely why you are seeing the image smaller on your computer and larger on a customer's computer. The DPI is typically 96, 120 or 150, depending on whether the user has elected to use 'Large Fonts' in Windows. You can access the user's DPI setting using "Screen.PixelsPerInch" in Delphi.

While this isn't the exact formula you need to use, hopefully it will point you in the right direction and you will be able to use something like "width / DPI * 2540" or "width / DPI * 1440"...
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The difference may be because of different screen resolutions. By default, a screen resolution is used to convert sizes from pixels to twips (twips are used in RTF). So the results will be different on different computers.

To make TRichView independent of the screen resolution, assign
RichViewPixelsPerInch := 96;
RVStyle1.TextStyles.PixelsPerInch := 96.

More info: http://www.trichview.com/help/idh_const ... rinch.html

PS: make sure that you use the latest version of TRichView, metafile sizing in RTF were changed in new versions.
Post Reply