Standard Fonts Resizing

I want to make some calculations for dynamic text localion based on the screen size and other elements.

I use dc.getTextDimensions() and dc.getTextWidthInPixels(). It works fine for me with standard fonts like Graphics.FONT_XTINY, etc. Also, I want to use layout.xml like this

<label id="my_label" x="20%" y="60" font="#RobotoCondensedBold:25"/>
as much as possible to split code vs design.

My problem: On Fenix 8 with 454x454 resolution the standard fonts are too small or too large, and I want a custom font size, but I do not want to make custom fonts.

In layout.xml I can define fonts like this font="#RobotoCondensedBold:25" and it works fine. I can make any font size.

The problem comes when I want to use dc.getTextDimensions() and dc.getTextWidthInPixels() with font="#RobotoCondensedBold:25". Second argument for dc.getTextDimensions() and dc.getTextWidthInPixels() is Graphics.FontType. If I start reading documentation about that FontType, it says it is one of these 4:

FontType as WatchUi.FontResource or Graphics.FontDefinition or Graphics.FontReference or Graphics.VectorFont. and I cannot just pass "#RobotoCondensedBold:25". It has to be one of these objects. When I get a label like this

var myLabelView = View.findDrawableById("my_label") as Text;

then I can do myLabelView.width and height and it works ok, but only for static fixed labels. If I change the text, then I still get value for text from xml, not for the text which I set. This is why I would like to ask a few questions.

- If I define font like this font="#RobotoCondensedBold:25", how can I pass it to dc.getTextDimensions()?

- Is it good idea in general to use font="#RobotoCondensedBold:25" or there is a better way to scale standard fonts? I see that Graphics has getVectorFont(options as Graphics.VectorFontOptions) method and VectorFontOptions has scale parameter.

  • I think I found a solution for question 1 in the examples, which are coming with the SDK.

    if my font is this one RobotoCondensedBold:25
    var font = Graphics.getVectorFont({:face => "RobotoCondensedBold", :size => 25});
    var myTextDimentions = dc.getTextDimensions(myText, font);
    then it works fine.
    Also, what I found
    WatchUi.FontResource - custom fonts from .fnt file.
    Graphics.FontDefinition - standard fonts like this Graphics.FONT_LARGE.
    Graphics.FontReference - Still could not find any examples.
  • Graphics.FontReference - Still could not find any examples.

    FontReference (and BitmapReference) are what loadResource() returns instead of FontResource/BitmapResource for devices with CIQ 4.0 or higher, which have a shared graphics pool for all CIQ apps. This means that fonts and bitmaps are loaded into the shared graphics pool, and not app memory. 

    Instead of getting the resource itself, you get a reference to a resource. (Since classes are already passed by reference, it really means you get a standard reference to a special reference to the resource in the graphics pool, as opposed to a standard reference to the resource in app memory.)

    Advantages:

    - your app obviously has more memory to use which would otherwise be consumed by resources

    Disadvantages

    - the shared graphics pool can run out of memory even if your app still has available memory (because of this, some people have wished to avoid using the graphics pool on CIQ 4 devices, but it's not possible)

    For the most partFontReference can be used interchangeably with FontResource, and BitmapReference can be used interchangeably with BitmapResource.

    https://developer.garmin.com/connect-iq/core-topics/graphics/#graphics-pool