You should open an Issues case.
Create a sample project and add the font.
It is strange that g.textwidth(string) results in 0 for that font.
Javier may have an idea.
This is getting weirder by the minute. Uploaded to server.
I’m positive that I have not installed Zapfino font. But it not only gets rendered correctly but the width is also calculated correctly
There seems to be a problen with how Xojo is calculating the Text Width for Bold text. This is running locally on a Mac where I know for a fact that the Helvetica Font is installed.
This code ( Note Bold = False )
g.FontSize = 14
g.Bold = False
g.DrawText( PrescriptionBody , kMargin , 280 , g.Width - (kMargin * 2) )
Produces this correct output
Setting Bold to True makes the text wrap incorrectly:
g.FontSize = 14
g.Bold = True
g.DrawText( PrescriptionBody , kMargin , 280 , g.Width - (kMargin * 2) )
Result: (Note how it extends outside the width of the graphics object )
What OS are you using?
I tried to duplicate your problem but I get good results on my Mac with Catalina:
The only difference between the first text and the second is bold = False/True. I think that is how it should work.
Can you share a sample project just to run on my computer and I will let you know if it behaves differently than yours?
Edit: another test on the same PDF
Thanks for taking the time to investigate this.
I’m running BigSur 11.6.4
I’ll prepare a test project for you to test. Much appreciated.
Are you setting the .FontName explicitly?
Here is a test project:
https://www.dropbox.com/s/aooh6ua79ibob76/PdfTestProject.xojo_binary_project?dl=0
I’m opening an Issues case with some information, feel free to add if I missed something.
It looks like PDFDocument for Xojo Web has some sizing problems.
I copied the Xojo Example for PDFAnnotations Demo (see image above) and just pasted it into a Xojo Web project and here is the PDF that I get:
See the difference between the bold text and the line under PDFAnnotations Demo with the image in the previous post.
Edit: Case #68914
That seems to be the case.
Thanks for you help @AlbertoD
I may be wrong, but why don’t you pass the correct font using the correct Postscript name ?
(I meant “Helvetica-Bold” instead of g.Bold = True
).
I recall reading the styles does not works anymore/people have to use the installed Font Name (the Postscript Name).
For macOS, check the Apple documentation abput fonts, there are Declare for that.
Good idea but I don’t have experience with PDFDocument, I changed my code to this:
g.FontSize = 14
g.Bold = False
g.FontName = "Helvetica"
g.DrawText(tBD, 30, 80, g.Width - 60)
'g.Bold = True
g.FontName = "Helvetica Bold"
g.DrawText(tBD, 30, 180, g.Width - 60)
so I expected the first paragraph to be “Helvetica” and the second to be “Helvetica Bold”
This is what I get on Desktop:
This is what I get on Web:
Looks like a different bug. I will add the notes to the case and let @Javier_Menendez decide if one fix will fix the other too.
Is not the Postscript name of the Font; more likely, this may be “Helvetica-Bold”. (that was its name 30-40 years ago, but today ?)
In Monterey, Helvetica is installed (and I notices some occurences of the word “Zapf”).
Beware: user centered applications will show you the word Bold using the current language (Gras for French). It never shows you the development name (of course).
So, you can fill a PopupMenu with
Helvetica
Helvetica-Bold
Helvetica-BoldOblique
etc.
and try these as FontName (instead of multiple runs in the IDE).
Loading a Font file (like Helvetica.ttc) as text will allow you to get informations about that Font (Names and © are included in the file).
In the Xojo documentation, you will found a list of embeded fonts included some with the Bold style.
https://documentation.xojo.com/api/pdf/pdfdocument.html
Search for StandardFontNames…
The Apple relevant documentation is here:
You will get the Declare to ask for a Font Name, ID, Load a Font, etc…
Emile, thank you for your ideas, but look at the tests I made. You can download the test code from the Issues case if you want to test.
I expect Xojo Desktop and Xojo Web to produce the same PDFDocument with the same code and this is not the case.
Is up to @Javier_Menendez now to see my bug report and make Xojo Web behave the same as Xojo Desktop in both cases (Bold = True and FontName = “Helvetica Bold”)
Edit: I don’t work with Mobile, can’t test this with other targets. If someone can/wants to test for other targets that support PDFDocument you can add your comments here or on Issues. Thank you.
Edit2: I know that Bold/FontName problem with Web has nothing to do with the title of this thread and that may confuse someone. Just go to case #68914 to see the notes/examples/screenshots for these problems.
Hi Alberto,
Wrong Reference Name.
In the mean time, I searched for an example and found one with Xojo… and this crashed when I clicked in the Bold CheckBox.
Example: macOSSystemFonts.xojo_binary_project
The exposed FontNames are user names… and mixed languages… look below:
Thank you Emile, I changed the test code posted on that case to use
- Helvetica
- Helvetica-Bold
Xojo Desktop creates this PDF:
Xojo Web creates this PDF:
PDFDocument should create the same PDF on both (all) Xojo targets.
Anything else that you want me to test?
Testing
- HelveticaNeue
- HelveticaNeue-Bold
Xojo Desktop creates this PDF:
Xojo Web creates this PDF:
Note: this is running locally on my Mac with Catalina
Different fonts have different results with Xojo Web.
Same results here
Further testing.
Trying to make sense of this I re-read the documentation and decided to name the fonts using the enumerations as follows:
g.FontName = PDFDocument.StandardFontNames.LiberationSansBold
g.FontSize = 10
g.Bold = False
currentFont = "Curent Font: " + g.FontName + " | Font Size: " + g.FontSize.ToString
g.DrawText( currentFont , 30 , 700 , g.Width - 60 )
Var LineZero As String = "Testing what gets rendered with this Font"
LineZero = Str(g.textwidth(LineZero)) + "Px - " + LineZero
g.DrawText( LineZero , (g.Width / 2) - (g.TextWidth(LineZero) / 2) , 710 ) // This line is not centering correctly
g.FontName = PDFDocument.StandardFontNames.LiberationSans
g.FontSize = 8
g.Bold = False
currentFont = "Curent Font: " + g.FontName + " | Font Size: " + g.FontSize.ToString
g.DrawText( currentFont , 30 , 720 , g.Width - 60 )
Var lineOne As String = "This is the text for line 1. Some filler content for testing purposes"
lineone = Str(g.textwidth(lineone)) + "Px - " + lineOne
g.DrawText( lineOne , (g.Width / 2) - (g.TextWidth(lineOne) / 2) , 730 ) // This line is not centering correctly
g.FontName = PDFDocument.StandardFontNames.LiberationSansBold
g.FontSize = 8
g.Bold = True
currentFont = "Curent Font: " + g.FontName + " | Font Size: " + g.FontSize.ToString
g.DrawText( currentFont , 30 , 740 , g.Width - 60 )
Var lineTwo As String = "This is the text for line 2 "
lineTwo = Str(g.TextWidth(lineTwo)) + "Px - " + lineTwo
g.DrawText( lineTwo , (g.Width / 2) - (g.TextWidth(lineTwo) / 2) , 750 )
g.FontName = PDFDocument.StandardFontNames.LiberationMono
g.FontSize = 10
g.Bold = False
currentFont = "Curent Font: " + g.FontName + " | Font Size: " + g.FontSize.ToString
g.DrawText( currentFont , 30 , 760 , g.Width - 60 )
Var lineThree As String = "This is line Three"
lineThree = Str(g.TextWidth(lineThree)) + "Px - " + lineThree
g.DrawText( lineThree , (g.Width / 2) - (g.TextWidth(lineThree) / 2) , 770 )
Liberation Font IS installed in the system and is part of the enumerations, however the when the PDF gets created/rendered it ignores the font name and uses a different one
Same code running on the server:
At least the font name is being honored (kinda)