A nudge in the right direction regarding Vector Graphics - SOLVED

I have an invoicing system that I have created and it uses Vector Graphics to produce the invoice (I found Reports too hard). The part I can’t work out is where it is critical that I know the length of a StringShape in pixels. It seems that this can only be done in the Picture Class. Is it possible to find the StringWidth in a StringShape?

I would try to compare StringShape with StringWidth in a picture graphics wth identical font and size. chances are results are the same. Use a screen shot to get the picture from vector graphics and measure in a blown up, such as what Photoshop provides, to count pixels.

Thanks Michel

I will give that a try. Had a small crisis on my hands, hence the lack of a reply.

Thank you Michel, that technique worked a charm.

You’re welcome.

Hi Cliff,

If this is something you are going to be using often (getting the StringWidth of a StringShape object), I would recommend that you wrap it in an extends helper method. Just copy the method below to a global module:

Function StringWidth(extends s  As StringShape) As Integer
  Dim pic As new Picture(1, 1, 24)
  Dim g As Graphics
  Dim result As Integer
  g = pic.Graphics()
  g.TextFont = s.TextFont
  g.TextSize = s.TextSize
  g.TextUnit = s.TextUnit
  g.Bold = s.Bold
  g.Italic = s.Italic
  g.Underline = s.Underline
  result = g.StringWidth(s.Text)
  return result
End Function

You can then instantly get the StringWidth of any StringShape object, anywhere in your code with a single call:

  Dim s as new StringShape
  Dim w As Integer
  s.TextFont = "Arial"
  s.TextSize = 40
  s.Text = "Test 1... 2... 3... "
  w = s.StringWidth

It should be said that these methods work fine as long the app and machine are not HiDPI.

Otherwise the result will be points and not pixels.

I have not yet finished working on that but I would recommend checking HiDPISupport.pdf in the documentation folder of the Xojo app.

Thanks Alwyn and Michel. I have copied The above function.

This business of pixels and points really got me going when I first started using computers for typesetting (my trade for 40+ years).

To me a point was 1/72.27 inch. Then along came Adobe with their Desktop Publishing and Points were suddenly 1/72 inch.

So Michel, are you saying that in HiDPI, points have gone back to their proper measurement of 1/72.27 inch?

Remember bitmap Fonts and… PostScript Fonts, then Vector Fonts ?
(25 years ago or more ?)

The one who takes times to go to PostScript, then Vector Fonts had hard time to understand.

Same apply to standard screen resolution (72 dpi or 96 dpi) / 1 point = 1 pixel / n points = 1 pixel.

And this is the beginning of the end for the dynosaurs that used a rule (a physical rule) to measure the object size in the monitor.

At last, it is far away the time where 40 x 40 @ 72 dpi is equal to 40 x 40 @ 144 dpi. Simply in the Finder’s image in a Folder function: try to drop a 300 dpi image vs a 72 dpi image (to be set as the Finder’s Folder background image)…

Still in OS X, take time to play with the preferences (the images tab preference) in the Preview application. Same apply to PhotoShop and probably all Paint software (for years).

Hi Emile
I do agree with everything that you say about how easy things are today. But I sure am glad that I did an apprenticeship when type was something you could hold in your hand. Then you really did know that each letter had a width and a height. Also, If you wanted, for instance, to put type in a circle, you really needed a good reason to do so - it was a hard thing to do.

But then progress can’t be stopped, and so at one point I stopped being a Typesetter/Typographer and became a Desktop Publisher/Graphic Artist.

[quote=258332:@Cliff Strange]

To me a point was 1/72.27 inch. Then along came Adobe with their Desktop Publishing and Points were suddenly 1/72 inch.

So Michel, are you saying that in HiDPI, points have gone back to their proper measurement of 1/72.27 inch?[/quote]

I see where you are coming from. I am coming too from the ancient times and when I talked to the printers at the newspaper I started to work for back in the seventies, there was the point Pica, and the Point Didot, both printing measurement.

Then along the Apple II and what followed came the screen. And on the screen, a pixel uses to be 1/72th inch, sometimes 1/75th ON END USERS SCREENS. There has been higher resolution screens in use in industry for quite a while, but for some reason, never mentioned.

When Apple decided (blessed be) to increase the resolution of his end user machines screen, they used a double resolution screen. To ensure legacy compatibility, the API returned false 1/72th inch “pixels”, which were in fact made of four 1/144th inch pixels. In Apple terminology, a point is still 1/72th inch, made, depending on the resolution, with 4 or more pixels.

Xojo insured the same kind of compatibility. An app not Retina aware will be presented with 1/72th inch points, which means it will work as ever. But a Retina aware app will have much crisper font rendition on the appropriate hardware, as well as possibly much finer details in pictures.

So the typographical point is still what it has always been, but the pixel is no longer always about the same size.