[quote=131951:@Tim Turner]Unfortunately I dont have a graphics object.
I am using TurboReport to print the report and I dont have access to the graphics object it is using.[/quote]
But you can create a picture object in Xojo and use Stringwidth on its graphics property to find out the width of a particular string, then calculate your X value with that before handing the result to Turbo Report. Or is your question about how to program Turbo Report ?
Function MeasureString(s as string,fnt as string,fnt_size as double) as double
dim p as picture
dim g as graphics
you might want to also set g.bold, italic etc if those are important
I am trying to put the company name, address, email etc. on lower right of cover page… left aligned… but when I hard code how far from the right side to put it… I keep running into cases where the street address or the email is too wide and then wraps to next line…
I’m trying to measure theses strings… determine which one is the longest… and then move over from the right margin by that width and then left align everything at that location.
Now the notion of pixel is a bit thorny. On a regular screen, one pixel usually equates a point, which is 1/72th an inch.
But on a printer, there may be 300 or 600 dots per inch, so a point may not necessarily equate 1/72th an inch. In Xojo, it is the case with the Printer object, but since you print with something else, difficult to say.
I would simply get the stringwidth for a long enough string so it produces for instance 3 inches, then print it through Turbo Report and measure the printed output. Then divide the actual print width by the number of pixels. This will give you the measurement by pixel, so you can calculate the final width in millimeters. There are 25.4 millimeters to an inch.
[quote=132406:@Tim Turner]Do you mean print it out to paper and measure with a ruler?
if my printer is not the same resolution as the client’s then I’m not sure how this translates.
The string will vary in length as well.[/quote]
Macintosh and Windows printer drivers deal with the resolution issues to produce identical output. In practice, when you request a printing on Letter size paper, for instance, the printer driver does whatever is necessary to print at the proper dimension, whatever it’s resolution. So, yes, you use a ruler to know how many pixels there are in the output, so stringwidth gives you a good estimate of how many millimeters you should move the printing.
It would do nothing to the printer, as stringwidth reports pixels in a graphics object which is an abstraction until it is printed or displayed. Hence the need to measure with a good old ruler the printed output.
Assuming the printed output uses pixels 1/72th inch wide, each pixel is 0.3527777 millimeter. A 100 pixel wide string will be 35.27777 millimeters wide. Now the only way to know the exact width of a pixel on paper is to use a ruler…
[quote=132413:@Tim Hare]When you print to paper, a pixel in the graphics object is a dot on the printer, so it is essential to know the print resolution from the printer setup object. Do you have access to that information?
For example, if you use the default of 72 dpi and print 12 point text, and then change to 300 dpi on the printer, you would have to print 50 point text to get the same physical size text on the page.
I don’t think (based solely on what I’ve heard) that retina affects text.[/quote]
The problem of the OP is different. He does not print a graphic object, but a string with a given font.
Essentially, he needs to estimate the printed width in millimeters of a string. Normally, the printer driver should equate one pixel to 1/72th of an inch, whatever the printer resolution. That is what happens when printing with Xojo. I have an app that does that, so I am certain of it. But given the fact that printing takes place through Turbo Report, it is necessary to verify, I think.
OK, I know nothing of Turbo Report, so I will bow out. It sounds like Turbo Report is doing some “magic” behind the scenes, but doesn’t expose an api to do what the OP wants. Thus your guess and check approach.