TextHeight is not supported on Web PDF?

I was testing something and came across this issue.

Sample Code:

If g.TextHeight( tempText , maxTextWidth ) > 200 Then
  // We should get here
End If

Screen Shot 2023-04-14 at 09.14.01

See that ErrorNumber is 0 (zero) which means no error. This is something I have been seen a few times: Message and Reason are not empty when there is no error !

I don’t know the reason, but now I check ErrorNumber and if it is 0 I don’t mind Message and Reason. I have been flabergasted a few time with that non sense.

@Paul_Lefebvre Do you know the teason ? Thanks

Not so fun fact:

g.TextWidth compiles but returns Zero when running on the server

Var someText As String
someText = "This is some really long text, when I say long I mean at least a line's worth long " + _
" perhaps even a little longer than a line. Let's see how this works"
Var textLength As Double = g.TextWidth( someText)
Self.TextWidthTestLabel.Text = "Text L: " + textLength.ToString

Something just struct my mind: TextHeight returns a Double, but 200 is not specifically set to be a Double it’s in fact an Integer. For the comparison 200 should be promoted to Double but it may not be, and then the comparison result can be wrong. If you search on the forum you will find a thread about comparison results are wrong because of values promotion not correctly done. If you type

CDbl("200")

then you are makin sure to get 200 expressed as a Double.

Are you sure the server has installed (and available) the fonts used in the PDF? Returning 0 from that property is a good guess they aren’t :thinking:

Hi @Hector_Marroquin

It looks like a bug. I filed an issue for it: https://tracker.xojo.com/xojoinc/xojo/-/issues/72491

4 Likes

Hello Javier

I’m positive the fonts are installed

Thank you for your input!

Thing is that doing something like this:

Var theWidth as double = g.TextHeight( tempText , maxTextWidth )

Also returns zero.

Still looks like a server side fonts issue… maybe you can send over (privately) an example project reproducing the problem?

Regarding this… an error number of zero does not mean “no error”, but simply that there’s no reference-able error number to be had. The fact that the exception itself occurred means that there was an error.

The main reason for setting a number is for the ability to differentiate between several different exceptions of the same type in code so the developer doesn’t need to rely on parsing error text. Think of the places where an IOException can occur, those are usually directly translated from an underlying system error or exception which can be looked up in a .h header file somewhere. In those cases, the error number will be set to something other than zero.

The moral of the story is, don’t confuse error codes with exit codes. They’re not the same thing.

2 Likes