To right align in graphics requires measuring the text, and then set the drawstring left as g.width-g.Stringwidth(text)
Problem is if your host does not have the font that you want to use, stringwidth won’t work. In Xojo Cloud, one can add fonts to the host. In a VPS, it is probably more difficult. Unless Lifeboat takes care of that, I don’t know.
Lifeboat doesn’t take care ot if yet. I have added the fonts using copyfonts and attempted to add the fonts manually to a VPS server but not luck getting this to work correctly yet. I’ll give it a try in a couple of days and report back
g.TextWidth(“ABC”) return 0, it is a bug or have at least a not supported error for web.
Xojo 2021r3.1
and TextShape is not supported too because drawobject is not supported^^
chaos framework …
I never had to add the fonts manually, so I did not know if lifeboat would help.
I suppose the usual way to install Linux fonts would work, but it may depend on the distro. It is also quite possible one has to install the desktop as well.
Before we go blaming the server and font, try running the web project on your desktop. This is what I get running the web project in debug mode on macOS, with, confirmed, Helvetica installed.
You did not read what I posted. The issue comes indeed from hosts not having the necessary fonts. On a desktop, such as Mac or Windows, all the fonts are there.
In Xojo web, it is possible to add fonts by simple copy. years ago, Phillip Zedalis added fonts for me on 1701.
I am not familiar enough with Linux in host version to know where the fonts can be installed. But it must be possible.
You did not read what I posted. My screenshot comes from running the web app on Desktop, where indeed I have the fonts installed.
You’re jumping to blame the server when it doesn’t even work on Mac Desktop with the fonts installed. Chris O’s post shows that it fails on Windows Desktop too.
Yeah, the problem is in the underlying Graphic class for Console (Web) reporting different width values than those reported for Desktop… so the PDF draws the text at it expected size, but the width doesn’t gets the proper value.
I’ve just spent the last couple of hours researching installing these fonts on Linux. The answers suggest the font metrics files which are provided by Adobe. Installing the fonts themselves makes you responsible for following the license for each of them.
As I understand it, installing the core-14 shouldn’t be a problem we have to face as the PDF generating software (Xojo) should be aware of the font metrics of the core-14.
When I installed on my CentOS server, it turned out to be worse. All StringWidths returned Zero. So I decided just to try to figure the width out myself. It’s a bit clunky, but if anyone really needs to right or centre justify at the moment, it might help.
On the Mac, I created a Json table of HelveticaNeue 12 Point Char Widths for Bold and Plain text using the following code
dim chars() as string
dim widths() as Double
dim bWidths() as Double
dim p as new Picture(300,100)
dim g as Graphics=p.Graphics
g.FontName="HelveticaNeue"
g.FontSize=12
g.FontUnit=FontUnits.Point
dim s as string=TextArea1.Text
dim jWidths as new JSONItem
for index as integer=0 to s.Length-1
jWidths.Value(s.Middle(index,1))=g.TextWidth(s.Middle(index,1))
next
g.Bold=True
for index as integer=0 to s.Length-1
jWidths.Value("b"+s.Middle(index,1))=g.TextWidth(s.Middle(index,1))
next
TextArea1.Text=jWidths.ToString
(I prefix the Char with ‘b’ for the BOLD chars)
The contents of TextArea1 allowed me to create a constant HELVETICANEUE12
Then I used the following function to return the estimated width of a string:
Public Function CharWidth(S as String, PointSize as Double = 12, Bold as Boolean = False) As Double
if s="" then Return 0
if Widths=nil then
try
Widths=new JSONItem(HELVETICANEUE12)
catch err
dim xx as integer
end try
end if
dim ws as Double
for index as integer=0 to S.Length-1
dim found as Boolean
//I understand these are the average widths of bold and non-bold characters
//When the character width isn't found
dim w as Double=583.44/514
if bold then
w=613.25/684
end if
if Widths<>nil then
dim key as string=S.Middle(index,1)
if Bold then
key="b"+key
end if
w=Widths.Lookup(key,w)
end if
w=w*PointSize/12
ws=ws+w
next
Return ws
End Function
It seems to work well on all platforms. I’m sure it’s needless to say, If you need to use a different font you need to add it and make the json keys more complex.