Paste text and picture from office word,pictures changed crude

General TRichView support forum. Please post your questions here
Post Reply
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

Paste text and picture from office word,pictures changed crude

Post by wolf1860 »

I select some text and pictures then ctrl+c ,when I pasted to the TRichViewEdit,some pictures changed crude.Sometimes the same action is right in TSRichViewEdit. Single picture,none text ,the result is right.
In TSRichViewEdit:
Image
In TRichViewEdit:
Image
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paste text and picture from office word,pictures changed crude

Post by Sergey Tkachenko »

Please send me a document where I can reproduce this problem.
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

Re: Paste text and picture from office word,pictures changed crude

Post by wolf1860 »

The test docx sent to richview@gmail.com.Thank u!
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paste text and picture from office word,pictures changed crude

Post by Sergey Tkachenko »

I confirm the problem in scaling some pictures that have alpha channel.
I am trying to understand why it happens.
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paste text and picture from office word,pictures changed crude

Post by Sergey Tkachenko »

Try the following fix.
Open RVThumbMaker.pas.

Find

Code: Select all

            rgba.a := rgba.a + SrcPixel^.rgbReserved * Weight;
Change to:

Code: Select all

            if Weight > 0 then
              rgba.a := rgba.a + SrcPixel^.rgbReserved * Weight;
(do it for the both 2 occurrences of this line)
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

Re: Paste text and picture from office word,pictures changed crude

Post by wolf1860 »

Only copy and paste both text and picture mixed ,the images will change crude, single picture copy and paste is right.
The fix does not work,if I did fix right.But I'm confused for the paste action in the compiled demo ActionTests both TSRichView and TRichViewEdit ,it looks right. But I opened the demo app in delphi and run it,the result is wrong! What did I missed?
The fix I did in RVThumbMaker.pas:

Code: Select all

procedure ApplyHorizontally32;
  var......
  begin
    .............
          if IgnoreAlpha or (TempPixel^.rgbReserved <> 0) then
          begin
            Weight := WPMatrix[x, i].Weight;
            rgba.r := rgba.r + SrcPixel^.rgbRed * Weight;
            rgba.g := rgba.g + SrcPixel^.rgbGreen * Weight;
            rgba.b := rgba.b + SrcPixel^.rgbBlue * Weight;
            // rgba.a := rgba.a + SrcPixel^.rgbReserved * Weight;
            if Weight > 0 then
              rgba.a := rgba.a + SrcPixel^.rgbReserved * Weight;
          end;
    .............
  end;

Code: Select all

procedure ApplyVertically32;
  var...........
  begin
   ..................
          if IgnoreAlpha or (TempPixel^.rgbReserved <> 0) then
          begin
            Weight := WPMatrix[y, i].Weight;
            rgba.r := rgba.r + TempPixel^.rgbRed * Weight;
            rgba.g := rgba.g + TempPixel^.rgbGreen * Weight;
            rgba.b := rgba.b + TempPixel^.rgbBlue * Weight;
            if Weight > 0 then
              rgba.a := rgba.a + TempPixel^.rgbReserved * Weight;
            // rgba.a := rgba.a + TempPixel^.rgbReserved * Weight;
          end;
   ....................   
  end;
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paste text and picture from office word,pictures changed crude

Post by Sergey Tkachenko »

May be the unit was not recompiled?
Try running "Install TRichView In Delphi IDE" in Windows start menu to recompile packages.
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

Re: Paste text and picture from office word,pictures changed crude

Post by wolf1860 »

I did "insall in delphi IDE", the fix did not work.

Image in office word:
Image

Paste to RVEditDemo.exe

Image
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paste text and picture from office word,pictures changed crude

Post by Sergey Tkachenko »

Please send me a document with these pictures. With this fix, I cannot reproduce the problem on your previous document with a chart picture.
It may be another problem.
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

Re: Paste text and picture from office word,pictures changed crude

Post by wolf1860 »

I have sent a test docx file to richview@gmail.com
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

Re: Paste text and picture from office word,pictures changed crude

Post by wolf1860 »

Now I am sure,this problem happens in new version.The old compiled application worked perfect,But I don't know the version.
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paste text and picture from office word,pictures changed crude

Post by Sergey Tkachenko »

Ok, I realized, there are two different problems here.

The first problem (that was fixed by the above provided code change) produced minor artifacts when scaling pictures that have an alpha channel (semitransparency). You can see the difference in this document before and after the fix if you load this document using LoadDocX method. In this case, images are imported as PNG. The images are correct, artifacts were produced by the TRichView's image scaling procedure.

The second problem is different. It happens when you copy this document from MS Word. In this case, document is inserted as RTF, and images are metafiles.
In this case, TRichView checks if these metafiles contain only raster images, and if yes, inserts them as bitmaps, instead of metafiles.
Obviously, older version of TRichView were not able to extract bitmaps from metafiles in this document, so they imported them as metafiles.
The new version can extract bitmaps, but these bitmaps are damaged for some reasons.

I'll try to find what's wrong. For now, you can simply disable extraction of bitmaps from metafiles by assigning RichViewEdit1.RTFReadProperies.ExtractMetafileBitmaps = False.
wolf1860
Posts: 118
Joined: Sat Nov 21, 2015 2:04 am

Re: Paste text and picture from office word,pictures changed crude

Post by wolf1860 »

Everything is ok,thanks u:)
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paste text and picture from office word,pictures changed crude

Post by Sergey Tkachenko »

Well, I found the problem that caused this regression.
I'll include a fix in the next update.
Sergey Tkachenko
Site Admin
Posts: 17554
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paste text and picture from office word,pictures changed crude

Post by Sergey Tkachenko »

The fixes are included in TRichView 20.1 (uploaded today)
Post Reply