Tufty 2350 large/vector font alignment

I’m wanting to place some centred and right-aliigned text in sizes larger than any of the pixel fonts. Ideally, this would be done using vector fonts, but from some posts in the Tufty 2040 > code > Tufty 2350 thread, I’m guessing that this is essentially a non-starter. Is there any way of getting the height and width of a unit of vector font text? Or do I need to work out either how to scale a pixel font and deal with the jaggedness, or else create a new pixel font at the appropriate size?

Thanks.

Vector fonts should be doable. I just haven’t sat down and figured it all out.
I got some to display, I just haven’t sat down and did the sizing and positioning. It is on my list of things to do in that thread. Right now I have working code minus the vector fonts. And my chronic neck and back pain have me taking a break from being hunkered over my keyboard doing code. If and when I have another go I’ll post back here.

Many thanks. This is a great bit of kit and could be even more amazing. I’ve only used vector fonts in trivial ways so far, but they seem to work beautifully as long as you don’t need specific alignment.

Hope you get well soon. When you do get back to it, the ability to use measure_text() or something roughly equivalent with vector fonts would be my biggest hope for the device software. Next would be the ability to rotate text - preferably arbitrarily, but at least through 90deg steps to be able to put labels more easily against the up and down buttons hard up against the right of the screen.

Incidentally, moving away from the font question, is there a location documenting the details of the MicroPython version? I’ve been caught by what libraries are and are not supported - so far I’ve been able to work it all out from the generic material at docs.micropython.org but it would be good to have implementation-specific details.

Mike

Interesting question? I had a look see and didn’t see it listed?
@BillyTPilgrim likely knows. Or @gadgetoid will know.

The Pimoroni fork of MicroPython is MicroPython at it’s core, so the generic docs are fine. Not part of MicroPython are drivers and libraries. And no, these are not well documented. You have to look into the sources. Sometimes, you will find a readme with infos necessary to get started, but the whole story is in the source files.

Many thanks. That the generic docs are pretty much accurate for the included Python libraries is all I really need to know. At the moment, I don’t have time to get into the details of drivers so if it’s not nicely wrapped out of the box, I’m likely to move off and work on something easier. Though I am getting enthusiastic and might make more time if it continues!

Hi there, apologies for the delay, I’ve been off on my hols for the past week.

Provided you have up to date firmware, vector fonts should work just the same way as pixel fonts when it comes to measure_text(). You have to specify a font height in pixels as mentioned in this docs article. Once you’ve got your dimensions, you can use the usual ways of aligning it to centre it on the screen and so forth. Pixel fonts can’t be scaled at this time, but you could always create an image object, write the pixel text into that and then use screen.blit() to blow it up onto the screen. I’d advise always scaling by a whole number if you’re doing that and don’t want the text to look distorted.

One thing that is probably worth mentioning is that the heights you measure or specify are the height of the entire font - that is, the height of the tallest individual glyph in the font. That’s usually something not often used in regular text, at least in English, such as a capital with a diacritic on top. That means that most of the time there’ll be a bit of empty space at the top of the bounding box of the glyphs and the letters will appear to be placed a little below the point you specify. This is the case with both pixel and vector fonts.

It’s often easiest to just play about with text sizes and alignments and see what works best for your use case, or in a project which displays a lot of text in different contexts it might be useful to create a method which allows you specify where the bottom of the text sits rather than the top.

Horizontal alignment is accurate to the width of the specific characters you’ve typed, however.

Scaling vector fonts is covered in an example in this tutorial: Meet Badger, Tufty, and Blinky - the Digital Badge Crew

In this case, I’m creating preset text heights based on a variable called du which was set up earlier in the tutorial, but you don’t have to - a straight numeric value will do.

I don’t really get it. The RP2350 is so powerful and has so much space (flash and ram), so you should be able to maintain individual glyph heights and doing exact measuring of the text in two dimensions. Your solution seems very hacky and it is certainly not portable once you start to display texts you don’t control.

Thank you so much and my apologies. PEBKAC.

I thought I had tried that and it hadn’t worked, but I didn’t see it in the documentation so I must have assumed that it wasn’t implemented as I would have expected when it was really that I did something weird. But I didn’t push whatever the weirdness was to the repository so I’ll never know what stupid thing I actually did.

Excellent job on your part - it does indeed work exactly as expected.

Mike