Recent

Author Topic: Text rendering  (Read 4807 times)

meanderix

  • Jr. Member
  • **
  • Posts: 50
Text rendering
« on: June 23, 2012, 10:02:41 pm »
Hi,

When I use Canvas.TextOut(), the text will not be properly blended onto the background (see attachment.)

I'm trying to figure out if this can be fixed or if it's possible to somehow set the background color that will be used for the antialiased edges.

I think the LCLDoDrawText() and ExtTextOut() are the main functions involved here.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Text rendering
« Reply #1 on: June 24, 2012, 09:12:06 am »
It is a known issue, although I don't know how to fix it. Look at lazcanvas.pas, there are many blending routines, 1 of them ignores the background and it is the one currently utilized to draw text.

The problem is that Android draws text with alpha and when trying to alpha-blend the result into our bitmap I was getting a redish result in the alpha pixels, so it looked horrible in white background some red pixels. I have no idea what caused it, and my work around was to always suppose a white background ... which obviously don't work great if the background is not a light color.

One easy way to solve this would be to invest into the non-native text rendering. Implement the font finding algorithm and add a define to set using lazfreetype under Android. Then it should work perfectly through lazfreetype which is our 100% text rendering and is utilized by LCL-CustomDrawn in all platforms except Android.

In Android I utilized the native font rendering system because the Android fonts are chaotic, so it is hard to choose the font properly in a way that works in all devices. A lot of testing would be needed. But to me it looks like that the non-native way is better in the long run. It is faster too.

meanderix

  • Jr. Member
  • **
  • Posts: 50
Re: Text rendering
« Reply #2 on: June 24, 2012, 11:32:07 am »
It is a known issue, although I don't know how to fix it. Look at lazcanvas.pas, there are many blending routines, 1 of them ignores the background and it is the one currently utilized to draw text.

The problem is that Android draws text with alpha and when trying to alpha-blend the result into our bitmap I was getting a redish result in the alpha pixels, so it looked horrible in white background some red pixels. I have no idea what caused it, and my work around was to always suppose a white background ... which obviously don't work great if the background is not a light color.

Ok, I wonder if this is a problem specific to certain Android versions. I changed to lDestCanvas.AlphaBlend() in ExtTextOut() and now everything is working fine. My Android version is 4.0.3.

Quote
One easy way to solve this would be to invest into the non-native text rendering. Implement the font finding algorithm and add a define to set using lazfreetype under Android. Then it should work perfectly through lazfreetype which is our 100% text rendering and is utilized by LCL-CustomDrawn in all platforms except Android.

In Android I utilized the native font rendering system because the Android fonts are chaotic, so it is hard to choose the font properly in a way that works in all devices. A lot of testing would be needed. But to me it looks like that the non-native way is better in the long run. It is faster too.

Yep, I was considering this option too and I had a look at the lazfreetype units yesterday. Since I'm also using Graphics32, I might want to add support to freetype text rendering in the backend classes. Recently I added an ITextToPathSupport interface that allows you to utilize the new path classes for drawing text (that also gives you some interesting options for drawing the outlines, with the new GR32_Brushes unit.)

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Text rendering
« Reply #3 on: June 24, 2012, 11:34:19 am »
Ok, I wonder if this is a problem specific to certain Android versions. I changed to lDestCanvas.AlphaBlend() in ExtTextOut() and now everything is working fine. My Android version is 4.0.3.

Yes, it might be specific to older Android versions. I had the issue in HTC Wildfire 2.2

But I haven't rechecked it in quite some time ... I will retest this monday. Maybe some of the other JNI fixes that I made fixed this issue.

 

TinyPortal © 2005-2018