Questions about fonts

Starting to make some tools for a newer device (Edge 1050) brings up many questions how to use fonts the best way.

1. Vector fonts

1a) Why no scalable fonts are allowed with the Edge 1050? Is it the hardware or just a "mistake" in the SDK implementation?

1b) Why Garmin's own datafields to show multiple font sizes which are NOT available for own programs - are these all custom fonts?

2. Optimizing (speed)

2a) When creating custom fonts, does xoffset and yoffset really has any impact? (For me it looks like these values are automatically calculated when compiling a program)

2b) Is dc.drawText(...) execution time identical when...
      ...using different alignments
      ...using a normal background color or transparent background
      ...a custom font or internal font (identical character sizes)

3. Internals

3a) Does anyone know how custom fonts are compressed in resources? Sometimes I just change one pixel in a character and the resulting "prg" changes by many bytes. I'd like to understand the internals here.

  • 1) Not all devices, even newer ones, have vector fonts. .Not sure if any edge devices have them

    2) custom fonts are less efficient than native fonts and also consume some space in your app or the graphics pool

    3) What did you change and how?

  • 3.at the end it's a zip file. You can change 1 bit in one of the original files and end up with a zip file 10 bytes bigger.

  • 1) Toybox.Graphics has :getVectorFont returns false, anyhow you can see around 30 different font sizes in Garmin's datafields - but only 11 different fonts are listed in the SDK.

    2) My feeling is that writting text using a transparent background could be a little bit faster because less pixels have to be changed usually. I tried ti investigate it but within the simulator the results vary. In my tests TEXT_JUSTIFY_CENTER would be statistically faster than left or right alignment but also here the results are inconsistent.

    3) Just setting a different color (black, dark or light gray, white) for a single pixel has an impact because of the compression - which is not documented anywhere. I'll do such things in a self written font editor which makes it much easier.

  • 1) The firmware on a device can have more fonts than are available in CIQ.  Long story, but the FONT_X and FONT_SYSTEM_X fonts you see are the same.

    3) with a custom font generated by BMFONT, the png is only black and white.  Sounds like your custom font editor is doing something odd.

  • Not sure what do you base on what you wrote in 2, but my instinct disagrees. IMHO if there's a difference, then transparent background would use more CPU, and left justify would be the fastest

  • 3) @jim_m_58 BmFont does use 2 bit of the 8 bits per pixel (font smoothing) - fonts which have only black and white pixels aren't looking nice. I don't think my editor is doing anything odd - anyhow it just creates png and fnt files which are linked together by the connect IQ compiler (that's where the resource data get squeezed in a way I am not able to understand completely).

    2) @flocsy I wrote all my programs using left alignment when possible and - when no overlapping is given - used full background color. But meanwhile I'm unsure if this is the best strategy.

    At least the simulator (Edge 1050) shows surprising results when calling a routine like the following: 

        function text(dc,font,alignment,background)
        {
            var time=Sys.getTimer();
            dc.setColor(Gfx.COLOR_WHITE, background);
            
            for (var i = 0; i < _iterations; ++i)
            {
                dc.drawText(240,0,font,"Speedtest",alignment);
            }
            return Sys.getTimer()-time;

        }

    A full background color was slower than transparent background in all tests. Left alignment was not faster than any other alignment, sometimes centering was the most fastest mode. I know that this kind of test does not deliver reliable numbers and I also wasn't able to get clear answers by using the internal profiler - that's why I started with this thread... ;-)

  • If you are looking at timing, you want to sideload to a real device.  In some cases. the timing in the sim can be inaccurate.

  • Yes, the simulator is definitely not an emulator - meanwhile I did a lot of real time testing on an edge 1050 (so these results are no indicators for other devices)...

    Self made fonts are around 50% slower than internal fonts - so please, Garmin, allow access to all internal fonts on all devices (saves memory, CPU time, CO2, etc.)

    Alignment seems to be not a big point for speed optimization - anyhow left may be a tick faster than right alignment and centering a text can take around 10 percent more time.

    Interesting points:
    1. drawing text while having set a full background color is around 10% slower than using transparent background.
    2. drawing a rectangle and adding a text with transparent background is not slower than drawing the text (with background color) alone

    Funny thing: using FillRectangle with a transparent background color is faster than with a normal background color.