CalcTextSize returning incorrect values for Bold Font

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

CalcTextSize returning incorrect values for Bold Font

Post by whoit »

Hi -

I'm implementing some code which requires that I calculate the width of a string of text.
I'm using the CreateNewFont and CalcTextSize methods, but the results for Bold strings
appear to be wrong - too small.
When I place some strings end-to-end based on the CalcTextSize returned width,
they overlap when Bold is used.

I can supply a functioning VB project as an example - but I'll need to email the zip file.

Here's my basic code for the calculations (VB6):

Code: Select all

Private Function getTextSize(ByVal sFName As String, ByVal dSize As Double, ByVal sText As String, ByVal getWidth As Boolean) As Single
    Dim dFinal      As Double
    Dim xWid        As Double
    Dim xHit        As Double
    Dim myCreator   As IPXC_ContentCreator
    Dim xfnt        As IPXC_Font

    Set myCreator = pDoc.CreateContentCreator
    myCreator.SetFontSize dSize

    'this requires a "Postscript name" which is difficult to get so it's not used
    'Set xfnt = pDoc.CreateNewFont2("ArialMT")

    'Font name could be "Arial" or "Arial Bold" for example
    Set xfnt = pDoc.CreateNewFont(sFName)
    myCreator.SetFont xfnt
    
    myCreator.CalcTextSize dSize, sText, xWid, xHit
    If getWidth Then
        dFinal = xWid
    Else
        dFinal = xHit
    End If
    
    'echo out
    Debug.Print "String>>" & sText & "<<"
    Debug.Print "Size>> " & dFinal
    
    getTextSize = dFinal
End Function
Am I not setting the Font properly?
Or are the values wrong?

Thanks.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: CalcTextSize returning incorrect values for Bold Font

Post by Sasha - Tracker Dev Team »

Hello whoit,

1) Create the font ONCE and use it for both the calculation and output.
2) You have not specified a bold flag in the font weight - should be FW_BOLD (700).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: CalcTextSize returning incorrect values for Bold Font

Post by whoit »

Hi Alex -

I did some more digging and I see where I can add the flag for Italic and Weight - thanks.

But what are you referring to when you say to create the font ONCE?
I'm not sure where you are seeing it done more than once....
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: CalcTextSize returning incorrect values for Bold Font

Post by Sasha - Tracker Dev Team »

Hello whoit,

I meant that you should create the IPXC_Font with the CreateNewFont method (use one call of the method) and then use it for all of the methods that calculate and output text not create it several times in two separate methods.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: CalcTextSize returning incorrect values for Bold Font

Post by whoit »

Ah, ok - no problem.
Thanks again.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: CalcTextSize returning incorrect values for Bold Font

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: CalcTextSize returning incorrect values for Bold Font

Post by whoit »

Wait - one more question -

is it possible to create a font using CreateNewfont, and then use that font with IPXC_WatermarkParams
(instead of only FontName and FontSize) ?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: CalcTextSize returning incorrect values for Bold Font

Post by Sasha - Tracker Dev Team »

Hello whoit,

Nope, sadly that is not possible through the available parameters.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: CalcTextSize returning incorrect values for Bold Font

Post by whoit »

OK - because I'm having an issue where only a subset of installed fonts work for me.

For example - "Arial Bold", "Arial Italic", "Arial Bold Italic" - work fine
However - "Myriad Pro Black Italic" does not work. I end up with what appears to be either Myriad Pro Regular or Arial regular (they're very similar)

So, how do I determine the restrictions on which fonts will work?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: CalcTextSize returning incorrect values for Bold Font

Post by Sasha - Tracker Dev Team »

Hello whoit,

Are you sure that you can find you font here?
https://www.pdf-xchange.com/forum3 ... ms#p111157

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: CalcTextSize returning incorrect values for Bold Font

Post by Sasha - Tracker Dev Team »

Hello whoit,

I've added the IPXC_Font as a property for the Watermark and HeadersFooters/BatesNumbering. You can create a new font via the CreateNewFont method and use it as a parameter in place of the FontName. This will be available from the 323 build.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: CalcTextSize returning incorrect values for Bold Font

Post by whoit »

Wow - That will be a nice improvement for our app.

Thanks Alex!
-Wayne
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: CalcTextSize returning incorrect values for Bold Font

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: CalcTextSize returning incorrect values for Bold Font

Post by whoit »

Of course the next question is: build 323 will be available when?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17822
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: CalcTextSize returning incorrect values for Bold Font

Post by Tracker Supp-Stefan »

Hello Whoit,

The current plans are for mid October - but at this moment no specific date has been chosen. As soon as we get to the final testing stage of the build - we should be able to give an exact date as well.

Regards,
Stefan
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: CalcTextSize returning incorrect values for Bold Font

Post by whoit »

Great - thanks again.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: CalcTextSize returning incorrect values for Bold Font

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply