Page 1 of 1

Paste text and picture from office word,pictures changed crude

Posted: Wed Mar 02, 2022 8:11 pm
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

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

Posted: Thu Mar 03, 2022 4:09 am
by Sergey Tkachenko
Please send me a document where I can reproduce this problem.

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

Posted: Thu Mar 03, 2022 4:46 am
by wolf1860
The test docx sent to richview@gmail.com.Thank u!

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

Posted: Thu Mar 03, 2022 6:30 pm
by Sergey Tkachenko
I confirm the problem in scaling some pictures that have alpha channel.
I am trying to understand why it happens.

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

Posted: Thu Mar 03, 2022 6:43 pm
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)

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

Posted: Fri Mar 04, 2022 8:34 am
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;

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

Posted: Fri Mar 04, 2022 9:23 am
by Sergey Tkachenko
May be the unit was not recompiled?
Try running "Install TRichView In Delphi IDE" in Windows start menu to recompile packages.

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

Posted: Fri Mar 04, 2022 10:22 am
by wolf1860
I did "insall in delphi IDE", the fix did not work.

Image in office word:
Image

Paste to RVEditDemo.exe

Image

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

Posted: Fri Mar 04, 2022 11:16 am
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.

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

Posted: Fri Mar 04, 2022 12:29 pm
by wolf1860
I have sent a test docx file to richview@gmail.com

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

Posted: Sat Mar 05, 2022 9:02 am
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.

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

Posted: Sat Mar 05, 2022 10:53 am
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.

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

Posted: Sat Mar 05, 2022 12:04 pm
by wolf1860
Everything is ok,thanks u:)

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

Posted: Sat Mar 05, 2022 3:38 pm
by Sergey Tkachenko
Well, I found the problem that caused this regression.
I'll include a fix in the next update.

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

Posted: Tue Mar 15, 2022 4:23 pm
by Sergey Tkachenko
The fixes are included in TRichView 20.1 (uploaded today)