logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
Inco  
#1 Posted : Sunday, June 10, 2018 3:03:16 PM(UTC)
Quote
Inco

Rank: Newbie

Groups: Registered
Joined: 6/9/2018(UTC)
Posts: 8

When comparing PDFium rendering (based on the WPF PdfViewer) with Chrome PDF rendering, or even Adobe, Foxit Reader, it appears these latters produce thiner text.

As demonstrated here with a random PDF document (Top = Chrome, Bottom = PDFium): https://imgur.com/Dg2VHAS


While it isn't shocking at first, long reading sessions generate more strain on the eyes than their thinner counterpart.
As far as I can tell, this behavior cannot be changed from outside the PDFium DLL.

What workaround would you suggest ?

I attached the PDF document in case it would be handy.

Thanks,
Alexis

test2.pdf (1,004kb) downloaded 38 time(s).

Edited by user Sunday, June 10, 2018 3:07:22 PM(UTC)  | Reason: Not specified

Inco  
#2 Posted : Tuesday, June 12, 2018 5:10:21 AM(UTC)
Quote
Inco

Rank: Newbie

Groups: Registered
Joined: 6/9/2018(UTC)
Posts: 8

You are correct, the blurry issue lies in the WPF rendering.

The LCD flag was already activated. I had tried running experiments with the flag on and off, without significant results.

There is in fact an issue with the Rendering procedure: Points/Pixels conversions compute larger Bitmaps sizes than what is really being displayed on screen. This results in Downsampling and Blurry text when it is scaled back to fit the screen.
It is especially prominent when rendering small Zoom factors, since Bitmap scaling is rather efficient and doesn't produce much artifact with larger fonts sizes.

Here is a quick hack which produces correct results (find image comparison at the end):

PdfViewer.cs
Code:
protected virtual bool DrawPage(DrawingContext drawingContext, PdfPage page, Rect actualRect)
{
	if (actualRect.Width <= 0 || actualRect.Height <= 0)
		return true;
	//int width = Helpers.PointsToPixels(actualRect.Width);
	//int height = Helpers.PointsToPixels(actualRect.Height);
	//if (width <= 0 || height <= 0)
	//	return true;

	//var pageRect = new Int32Rect(
	//	Helpers.PointsToPixels(actualRect.X), 
	//	Helpers.PointsToPixels(actualRect.Y), width, height);
  
  var pageRect = new Int32Rect(
	(int)actualRect.X, 
	(int)actualRect.Y,
	(int)actualRect.Width,
	(int)actualRect.Height);

  return _prPages.RenderPage(page,
		                     pageRect,
		                     PageRotation(page),
		                     RenderFlags,
		                     UseProgressiveRender);
}


Helper.cs
Code:
public static void DrawImageUnscaled(DrawingContext  drawingContext,
                                     WriteableBitmap wpfBmp,
                                     double          x,
                                     double          y)
{
  drawingContext.DrawImage(wpfBmp,
                           new Rect(x,
                                    y,
                                    /*PixelsToPoints*/(wpfBmp.PixelWidth),
                                    /*PixelsToPoints*/(wpfBmp.PixelHeight)));
}


I put together an image comparison (click) of Chrome Rendering, Original WPF Rendering (blurry), Bitmap Rendering (Page > Bitmap > PNG file) (non-blurry), and fixed WPF Rendering (equivalent to Bitmap).

In addition to the blurry issue now identified, if you zoom on the Image comparison above, you will note that Chrome uses colors for its font rendering. Because of their intensity, as opposed to Greyscale only, it produces a thinner and more pleasant rendering. How could we activate this feature ?

Kind regards,
Alexis
Paul Rayman  
#3 Posted : Tuesday, June 12, 2018 7:37:49 AM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
We will release a hotfix for these issues on this week I hope.
Thank you for the bugreport.

By the way
The code should be as following
Code:
public static void DrawImageUnscaled(DrawingContext  drawingContext,
                                     WriteableBitmap wpfBmp,
                                     double          x,
                                     double          y)
{
  drawingContext.DrawImage(wpfBmp,
                           new Rect(x,
                                    y,
                                    wpfBmp.PixelWidth*96/Dpi),
                                    wpfBmp.PixelHeight*96/Dpi)));
}

Edited by user Tuesday, June 12, 2018 7:41:19 AM(UTC)  | Reason: Not specified

Inco  
#4 Posted : Tuesday, June 12, 2018 8:17:59 AM(UTC)
Quote
Inco

Rank: Newbie

Groups: Registered
Joined: 6/9/2018(UTC)
Posts: 8

So it is, rendering now produces expected result, thanks.

What ought to be done to upgrade the greyscale text to color shaded text, as seen in Chrome's rendering ?
Paul Rayman  
#5 Posted : Wednesday, June 13, 2018 11:43:00 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
We will release a fix on this week. Please use this one instead of the code above. The fixes much more complex. You will find the differences on github.
Inco  
#6 Posted : Thursday, June 14, 2018 3:17:55 AM(UTC)
Quote
Inco

Rank: Newbie

Groups: Registered
Joined: 6/9/2018(UTC)
Posts: 8

I will. I noted the fix above wasn't sufficient shortly after my last reply. I appreciate the heads up.

Do I understand the colored text rendering is impossible as of now ? With the fix bringing back rendering to an acceptable level, this is fine with me. I'd just like to have an understanding about that.

Also I have offered to send a Pull Request on GitHub, is this part of your policy ?

Edited by user Thursday, June 14, 2018 3:18:49 AM(UTC)  | Reason: Not specified

Paul Rayman  
#7 Posted : Thursday, June 14, 2018 5:13:22 AM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
We have already fixed both issues. At the moment, testing is in progress.
The first issue is the blurring of text in the WPF Viewer
The second issue is actually a ClearType problem.

UserPostedImage

So the viewer display text in anti-aliasing mode instead of ClearType mode as should be if LCD_TEXT flag is used.

Edited by user Thursday, September 5, 2019 9:23:53 PM(UTC)  | Reason: Not specified

Inco  
#8 Posted : Thursday, June 14, 2018 5:15:46 AM(UTC)
Quote
Inco

Rank: Newbie

Groups: Registered
Joined: 6/9/2018(UTC)
Posts: 8

I'm impressed. Thanks.
Paul Rayman  
#9 Posted : Sunday, June 17, 2018 6:00:32 AM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Fixed!
https://forum.patagames....on-Jun-17--2018#post1330

Edited by user Sunday, June 17, 2018 6:01:13 AM(UTC)  | Reason: Not specified

Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.