Graphics Object Tips?

Hey everyone, I’ve been working with the graphics object to create a print layout, and could really use some tips since I am entirely new to graphics. I was mainly wondering if people enter the xy coordinates explicitly for each line of text, or if they tend to use some sort of counter to keep track of that.

Like I said, I am entirely new to this graphics stuffs, and could use any tips you have in general
Thanks!

Avoid hardcoding X,Y values when ever possible…

here is a crude example… assuming writing on a canvas

dim X as integer
dim y as integer
//
x=5
y=g.textascent
g.drawtext "Line 1",x,y
y=y+g.textheight
g.drawtext "Line 2",x,y

this way if you change the font, or font size etc, you don’t have to start over again

Hey Sean,

Look this I Wish I Knew How To …Program the Canvas Control with Xojo Desktop ( http://www.scispec.com), it’s very good to start working with Graphics.

Greetings :slight_smile:

Thank you Dave and Martin.
Dave, even though it is crude, your example really points me in the right direction.
Martin, thanks for the suggestion, I’ll have to look into that book a little bit

If you’re going to draw circles and curves, it’s almost impossible to get sharp/smooth edges.
A very easy trick I use is; Instead of drawing straight on the Canvas, I create a larger picture and then draw the final resized picture on the canvas.

I used that here: https://forum.xojo.com/28256-progress-circle-gauge-thingy
And here’s some example code: https://forum.xojo.com/27661-graphics-drawsvg-method/p3#p233178

I maintain a line number and then calculate the baseline for text from the printer resolution, line number, and the desired lines per inch.

@Tim Hare
Not sure if this is the same thing but I’m currently struggling with properly Top -Aligning text in a canvas. Whatever I try, I always have some blank space above the characters.
How do you calculate the baseline? And is that the real baseline or the descent?

TextAscent is the baseline… but most fonts have some space above even the tallest characters…
One thing I have found, is that OSX measures everything in POINTS (regardless of what you set TEXTUNIT to) and Windows uses Points or Pixels (but Integer values only), AND the sizes are NOT consistent between the two

Test Text=[W] designated TextSize =100.0

Platform =Desktop:OSX
   FontName = Arial
      Unit=Point Width=94.38 Height=115.00 Ascent=91.00 Aspect=82.07%
      Unit=Pixel Width=94.38 Height=115.00 Ascent=91.00 Aspect=82.07%
   FontName = Times New Roman
      Unit=Point Width=94.38 Height=115.00 Ascent=89.00 Aspect=82.07%
      Unit=Pixel Width=94.38 Height=115.00 Ascent=89.00 Aspect=82.07%
   FontName = Courier
      Unit=Point Width=60.01 Height=100.00 Ascent=75.00 Aspect=60.01%
      Unit=Pixel Width=60.01 Height=100.00 Ascent=75.00 Aspect=60.01%
   FontName = Courier New
      Unit=Point Width=60.01 Height=113.00 Ascent=83.00 Aspect=53.11%
      Unit=Pixel Width=60.01 Height=113.00 Ascent=83.00 Aspect=53.11%


Platform =Desktop:Win
   FontName = Arial
      Unit=Point Width=126.00 Height=149.00 Ascent=119.00 Aspect=84.56%
      Unit=Pixel Width=99.00 Height=112.00 Ascent=90.00 Aspect=88.39%
   FontName = Times New Roman
      Unit=Point Width=125.00 Height=151.00 Ascent=119.00 Aspect=82.78%
      Unit=Pixel Width=95.00 Height=114.00 Ascent=90.00 Aspect=83.33%
   FontName = Courier
      Unit=Point Width=80.00 Height=143.00 Ascent=107.00 Aspect=55.94%
      Unit=Pixel Width=60.00 Height=107.00 Ascent=80.00 Aspect=56.07%
   FontName = Courier New
      Unit=Point Width=80.00 Height=143.00 Ascent=107.00 Aspect=55.94%
      Unit=Pixel Width=60.00 Height=107.00 Ascent=80.00 Aspect=56.07%

Hmm… I can’t argue because you’re the expert in this but I thought ‘textascent’ is the distance between the baseline (somewhere close to the bottom) and the textheight/top.

So I figured that the filler space at the top is the same space between baseline and bottom. That’s why I jumped when Tim said he was able to calculate baseline.

And about the difference between windows and OSX, that’s not cool.
We need some better framework tools to work with this because it’s a real pita now. :confused:

That space above your text is room for diacritical marks above a capital letter. TextAscent gives you a true baseline. The text sits on that line, with descenders going below it. I’ve never had any trouble aligning text given the tools Xojo provides, but then, my needs are probably different than yours.

From what I can see, TextAscent reflects correctly the instructions in the fonts. As Tim said, it does not reflect the top of uppercase characters, but the top of accents above them.

On Canvas, the results are identical as far as I can tell with identical fonts.

Where issues start presenting is with controls, singularly labels, where text does not appear at the same position to the top.

I do not believe it is the fault of Xojo, since they use the native controls, but simply the result of differences betweens platforms.

One solution I found was to use a ContainerControl subclass on Windows, where not only the label is transparent as default, but also where the label is positioned so it renders the same way as on Mac.

I’d say it depends on the target platform. On iOS and OS X, InterpolationQuality, Flatness and FontSmoothing (if you declare them) should allow good quality without oversampling, and I’m almost certain the other platforms have similar features too. But without declares or plug-ins: Yes, tricky at least.