Print Page | Close Window

Different text ascent size in v10 from v9?

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2856
Printed Date: 04 Apr 26 at 11:06PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Different text ascent size in v10 from v9?
Posted By: eric_moraware
Subject: Different text ascent size in v10 from v9?
Date Posted: 02 Apr 14 at 6:14PM
Hi, we just updated from version 9.14 to 10.13 and we're seeing changed results when printing PDFs. Specifically, the whitespace between lines has increased in 10.13 in a way that is making our users (who have spent a lot of time making forms fit exactly one page) very unhappy.

After some investigation (code below), it appears that the Text Ascent (and to a smaller extent, Descent) values have changed for a number of fonts. Is this an intentional change? Is there some other way we could/should be calculating line height, or some simple way we can account for the change so that v10 PDFs look the same as v9 PDFs?

While the changes appear to be constant for each font (i.e. Arial is always increased by 1.2431), I'd rather not put in some kind of hack to adjust the sizes as that will be a maintenance problem going forward.

Here's how we're calculating our line heights:

    Public Shared Function GetBaselineOffsetToUse(quickPDF_ As PDFLibrary) As Decimal
        Dim tmpAscent As Decimal = CDec(quickPDF_.GetTextAscent())
        Dim tmpDescent As Decimal = CDec(quickPDF_.GetTextDescent())

        Return tmpAscent + Math.Abs(tmpDescent)
    End Function


    '***************************************************************************
    '***************************************************************************
    Public Shared Function GetTextHeightToUse(quickPDF_ As PDFLibrary) As Decimal
        Dim tmpDistToBaseline As Decimal = GetBaselineOffsetToUse(quickPDF_)

        Dim tmpHeight As Decimal = CDec(quickPDF_.GetTextHeight())
        Dim tmpDescent As Decimal = Math.Abs(CDec(quickPDF_.GetTextDescent()))
        Dim tmpSize As Decimal = CDec(quickPDF_.GetTextSize())

        Return tmpDistToBaseline + tmpDescent  'tmpAscentAndDescent ' tmpHeight
    End Function

And here's my sample code demonstrating that the font ascent/descent changed:

        Dim quickPDF914 As New DebenuPDFLibraryAX0914.PDFLibrary
        Dim quickPDF1013 As New DebenuPDFLibraryAX1013.PDFLibrary

        quickPDF914.SetMeasurementUnits(2)  ''Inches
        quickPDF914.SetOrigin(1)  '' Top left
        quickPDF914.SetPageDimensions(8.5D, 11D)

        quickPDF1013.SetMeasurementUnits(2)  ''Inches
        quickPDF1013.SetOrigin(1)  '' Top left
        quickPDF1013.SetPageDimensions(8.5D, 11D)

        TestFont(quickPDF914, quickPDF1013, "Arial", 12)
        TestFont(quickPDF914, quickPDF1013, "Arial", 18)
        TestFont(quickPDF914, quickPDF1013, "Arial", 24)
        TestFont(quickPDF914, quickPDF1013, "Arial", 36)
        
        

    Private Sub TestFont(quickPDF914 As DebenuPDFLibraryAX0914.PDFLibrary, quickPDF1013 As DebenuPDFLibraryAX1013.PDFLibrary, fontName As String, fontSize As Decimal)
        Console.WriteLine("Font: {0} {1}pt", fontName, fontSize)

        quickPDF914.SelectFont(quickPDF914.AddTrueTypeFont(fontName, 0))
        quickPDF914.SetTextSize(fontSize)

        Dim tmpHeight As Decimal = CDec(quickPDF914.GetTextHeight())
        Dim tmpAscent As Decimal = Math.Abs(CDec(quickPDF914.GetTextAscent()))
        Dim tmpOldAscent As Decimal = tmpAscent
        Dim tmpDescent As Decimal = Math.Abs(CDec(quickPDF914.GetTextDescent()))
        Dim tmpSize As Decimal = CDec(quickPDF914.GetTextSize())
        Dim tmpTextBound As Decimal = CDec(quickPDF914.GetTextBound(2)) ' 2 = top

        Console.WriteLine("Old font height: {0:#0.000}, ascent: {1:#0.000}, descent: {2:#0.000}, size: {3:#0.000}, top: {4:#0.000}", tmpHeight, tmpAscent, tmpDescent, tmpSize, tmpTextBound)

        quickPDF1013.SelectFont(quickPDF1013.AddTrueTypeFont(fontName, 0))
        quickPDF1013.SetTextSize(fontSize)

        tmpHeight = CDec(quickPDF1013.GetTextHeight())
        tmpAscent = Math.Abs(CDec(quickPDF1013.GetTextAscent()))
        tmpDescent = Math.Abs(CDec(quickPDF1013.GetTextDescent()))
        tmpSize = CDec(quickPDF1013.GetTextSize())
        tmpTextBound = CDec(quickPDF1013.GetTextBound(2)) ' 2 = top

        Console.WriteLine("New font height: {0:#0.000}, ascent: {1:#0.000}, descent: {2:#0.000}, size: {3:#0.000}, top: {4:#0.000}", tmpHeight, tmpAscent, tmpDescent, tmpSize, tmpTextBound)


        Console.WriteLine("New font ascent / Old font ascent: {0:#0.0000}", tmpAscent / tmpOldAscent)
    End Sub




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk