[Approved] Font Rendering Issues (1 Viewer)

offbyone

Development Group
  • Team MediaPortal
  • April 26, 2008
    3,989
    3,712
    Stuttgart
    Home Country
    Germany Germany
    After doing the News plugin I noticed that some pixels at the bottom of a Label are always clipped away when it is just a single line and has no margin. This shouldn't happen, so I dug into the code and think I found where the problem is coming from. The calculation of a text's height is not taking the full possible height into account. I did a small change and the result can be on the screenshots below. I simply added a very large label and set the background to black so we can see what the bounding box is .
    First pic shows current status, second after the fix. It also fixes the problem that single line labels are not exactly centered.
    I am not sure if the fix is correct, I haven't fully understood the font rendering yet, so someone with more knowledge in this are should check this (/me looks at @Albert).

    On a sidenote: a newer freetype binary is available (2.4.2 for win) and works fine with MP2.
     

    Attachments

    • CurrentFontRendering.jpg
      CurrentFontRendering.jpg
      61.8 KB
    • FixedHeightCalculation.jpg
      FixedHeightCalculation.jpg
      60 KB
    • FontAssetCore.diff
      1.6 KB
    • freetype_2.4.2-1_win32.zip
      272.1 KB

    morpheus_xx

    Lead Dev MP2
  • Team MediaPortal
  • March 24, 2007
    11,990
    7,376
    Home Country
    Germany Germany
    The results on screenshoots look good.

    I did not check the current code yet and don't understand the changes in your patch, can you explain this more detailed, please?
    _charSet.MaxHeight = (int)Math.Ceiling(_charSet.RenderedSize * (face.bbox.yMax + Math.Abs(face.bbox.yMin)) / (double)face.height);
    • Why you calc with Math.Abs()?
    • Does this mean, that single line labels can be of different height, depending on the contained characters?
     

    offbyone

    Development Group
  • Team MediaPortal
  • April 26, 2008
    3,989
    3,712
    Stuttgart
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #3
    face is a struct from the freetype lib.
    face.bbox.yMin is negative and in order to get the correct max height I need to add yMax and yMin.
    From the freetype docs, it said that the bbox is the maximum enclosing of all characters in the font.
    The old code did not ever look at the bbox, only at height and ascender which seems was not the total a character can be when ascender and descender are taken into account.

    I had some fun with this: http://en.wikipedia.org/wiki/Typeface_anatomy
    and this: http://www.freetype.org/freetype2/documentation.html
     

    morpheus_xx

    Lead Dev MP2
  • Team MediaPortal
  • March 24, 2007
    11,990
    7,376
    Home Country
    Germany Germany
    We recently changed the text size calculation method that fixes the issues shown in images above. But now we have another problem when other fonts are used (here: MayaTypeUI): the new textsizes are calculated way too small :(

    For example see both screenshots, before and after font fix

    01_original_MayaTypeUI.png02_AfterFontFix_MayaTypeUI.png

    I've added an extended patch, it works for both fonts.
     

    Attachments

    • 0001-Changed-font-height-calculation-to-use-maximum-of-pr.patch
      1.3 KB

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    44
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    The last fix from october 27th was nonsense. Font calculation is a difficult subject. I am no expert in this, but I tried a better fix for the problem shown above. See branch FIX_FontHeightCalculation. offbyone and morpheus, can you please test if my fix fixes your problems? Thanks!
     

    offbyone

    Development Group
  • Team MediaPortal
  • April 26, 2008
    3,989
    3,712
    Stuttgart
    Home Country
    Germany Germany
    • Thread starter
    • Moderator
    • #7
    Tested your branch and couldn't find problematic rendering in the News plugin or anywhere I looked (Default and Reflexion skin).
    Didn't check the code, but as I said in the beginning - my fix was only a hack :)
     

    Albert

    MP2 Developer
  • Premium Supporter
  • February 18, 2008
    1,297
    1,130
    44
    Freiburg im Breisgau, Germany
    Home Country
    Germany Germany
    After some reading of font theory, I just reworked the branch again. In fact, the original code was correct, it only subtracted a fixed pixel from all text heights which produced the problem of the cut y's and g's.
    I removed this fixed value and added a fixed pixel to ensure there's enough place around the text to be completely rendered. I also changed some method names which were not correct and I improved some comments.
    Please check the Fix_FontHeightCalculation branch again!
     

    morpheus_xx

    Lead Dev MP2
  • Team MediaPortal
  • March 24, 2007
    11,990
    7,376
    Home Country
    Germany Germany
    Will check later today! I'm so happy that (if?) I don't need to tweak "hundreds" of skin styles :D
     

    Users who are viewing this thread

    Top Bottom