Author Topic: Problems rendering bitmaps in Linux  (Read 2954 times)

Grahame Grieve

  • Full Member
  • ***
  • Posts: 228
Problems rendering bitmaps in Linux
« on: November 01, 2021, 03:07:08 am »
I'm porting PDFium to Lazarus (again). There's an older port, but it's windows only, and doesn't do some things I wanted. And it's not in Git. So:

It compiles for Windows, Linux and OSX, and the example works fine on Windows. But on linux, I get an exception rendering the PDF. The source of the exception is in, line 4285:

  if SrcDevContext.Drawable = nil then RaiseSrcDrawableNil;

SrcDevContext is indeed nil. I don't know why - should it be? or what should I do to make it not nil? The code that sets up the error is in PDFiumCtrl (line 750):

    PageDC := CreateCompatibleDC(DC);
    OldPageBmp := SelectObject(PageDC, FPageBitmap);
      if FRenderedPageIndex <> PageIndex then
        FRenderedPageIndex := PageIndex;
        Draw(PageDC, 0, 0, Page);
      BitBlt(DC, FDrawX, FDrawY, FDrawWidth, FDrawHeight, PageDC, 0, 0, SRCCOPY);     

There's a whole set of things going on here that I'm not familar with around DCs and bitmaps, and it all works on windows, but not linux. is it me doing something wrong?

Lazarus Version: 2.3.0, trunk 25th Oct, revision = main-2_3-520-gcff7d7fdb8. To reproduce, tag c854f3e80a81e0999b68596d40c6b1f99a34ee1a , compile the example and open any PDF (I think)


  • Hero Member
  • *****
  • Posts: 1097
  • Former Turbo Pascal 3 user
Re: Problems rendering bitmaps in Linux
« Reply #1 on: January 17, 2022, 11:17:17 pm »
May be a bug. Perhaps you might consider a more cross-platform solution? See felipemdc's comments:

I have had great success using BGRABitmap on several flavors of Windows, maxOS, and Linux.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 10.13.6: Lazarus 2.2.0 (64 bit Cocoa)
macOS 12.0.1: Lazarus 2.2.0 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.0 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.0 (64 bit on VBox)


TinyPortal © 2005-2018