RightAlign Text in Graphics

Are you sure is the lack of fonts?

Weird that @Javier_Menendez is saying that the underlying Graphic class for Console (Web) reports different width values than those reported for Desktop. I guess he knows how to install fonts.

On Xojo Web, for instance, a user can install fonts himself (copy to a folder).

I guess it is probably possible in a VPS machine, but by default, no fonts are installed.

Have you tried the applications posted in this thread?

The code in both is:

dim pdf as new PDFDocument
dim g as Graphics=pdf.Graphics

dim s() as string=Array("Hello World","We come in peace","Can you give me directions to Omicron Persei 8?")
g.FontName="Helvetica"
g.FontSize=14
g.Bold=True

dim margin as integer=30
g.DrawingColor=color.RGB(255,255,255)
g.FillRectangle 0,0,g.Width,g.Height

g.DrawingColor=color.RGB(0,0,0)

g.DrawLine g.Width-margin,0,g.Width-margin,200

for index as integer=0 to s.LastIndex
  g.DrawText s(index),g.Width-margin-g.TextWidth(s(index)),margin+g.TextHeight+index*g.TextHeight
  
next


dim f as FolderItem=SpecialFolder.Desktop.Child("Test.PDF")
pdf.Save f

Are you saying that the Web version running on my Mac can’t find the Helvetica font and do I need to install it in a special place? I’m not running the code on a server without fonts, I’m running Desktop and Web version on the same Mac getting different results.

I guess that’s why Javier says is a Graphics class for Console issue and not font related.

This is a bug in PDF, which manifests even if Helvetica is present.

I’ve tried with all fonts, web app running locally and it fails. As @Michel_Bujardet says, it is a bug.

I know it is a bug and already pointed to a case (#68914)

In this thread Michel mentioned several times that it was a fonts issue, just the last post he says “is a bug in PDF”.

I just want to make it clear that it is not a fonts issue and is not just a Right Align in Web, it happens also with center align and even if Bold is used.

Sorry, I misread what you posted

To make it clear, some pure graphic features (NOT PDF), such as StringWidth depend on installed fonts. Hence calculated rightalign, say, in the Paint event of a Canvas will work fine on a Mac or Windows, but not on most VPS if fonts are not installed.

As reported by @Chris_O_Brien above,

When I installed on my CentOS server, it turned out to be worse. All StringWidths returned Zero.

That is exactly what I was trying to explain. Without the necessary fonts, StringWidth does not return a valid value.

Once again, this applies to pure graphics like Canvas or pictures, not PDF.

In Xojo WEB 2023r4 have they solved the right alignment of the DrawText in the PDF?
Having advanced so much and incorporated other tools, I cannot find a simple solution to that problem as it should.

En Xojo WEB 2023r4 han solucionado en el PDF la alineación a la derecha del DrawText ?
Habiendo avanzado tanto e incorporado otras herramientas no encuentro una solución simple como debería a ese problema. @Javier_Menendez ?

As this Issue still open, I don’t think that something have changed for Console/Web apps:
68914 - PDFDocument size different between Desktop and Web

You can give a thumb up if you want.

1 Like

I’m just kicking myself I didn’t include it in my bug bust list back along :frowning: PDFDocument is such a terrific tool which I can’t be use because you can’t centre or right align text in Windows!!