How can I get the correct ttf font size based on simulator.json?

I'm trying to match the datafield label font in my DF (based on DataField class) For older devices (i.e fenix6) it used to work, because in simulator.json there are things like:

{
  "layouts": [
    {
      "datafields": {
        "datafields": [
          {
            "label": {
              "font": "xtiny"
            }
          }
        ]
      }
    }
  ]
}

So I use FONT_XTINY.

(For the sake of this post I'm looking at the "ww" variants)

But on newer devices (i.e fr965) no it uses ttf:

{
  "fonts": [
    {
      "fonts": [
        {
          "filename": "Roboto-Regular",
          "name": "simExtNumber2",
          "size": 5.4424,
          "type": "ttf"
        }
      ]
    }
  ]
  "layouts": [
    {
      "datafields": {
        "datafields": [
          {
            "label": {
              "font": "simExtNumber2"
            }
          }
        ]
      }
    }
  ]
}

However when I use RobotoRegular (BTW: IMHO there's a bug in simulator.json, and the filename probably should not contain the '-', but that's another issue) with size: 5.4424 then it is way to small:

var labelFont = Graphics.getVectorFont({:face => "RobotoRegular", :size => 5.4424});

(Note the datafield label is above "searching .")

Interestingly when I look here: https://developer.garmin.com/connect-iq/device-reference/fr965/ then there are different numbers from what is in simulator.json. i.e:

xtiny: simulator.json: 6.9542, device-reference: 37

Does anyone know how to "translate" the size in simulator.json to a number that when used in getVectorFont, will look like the real label?

  • I've been wondering the same, as I'm making some build tooling that I plan to open-source. In my observation, ratios are inconsistent between device families (e.g. Edge devices seem to render the sizes quite differently).

    From other forum discussions I've wondered if it's worth seeking an answer, given that the simulator.json files's sizes might not actually match the real device's sizes.

    I've concluded that one should use vector fonts and Dc.drawScaledBitmap where available, and if necessary fall back to providing pre-scaled bitmaps to match the CFT fonts (which are also potentially not matching, but Fingers crossed).

  • TTF fonts are vector fonts. For my use case I do want to use the built in ttf fonts because I am trying to create a DataField with similar label as the built-in fields (but with dynamic text in the label, before someone pints to SimpleDataField)

  • I've been through a similar struggle recently; I hit a snag after realising (partly through the forum) that certain layouts present ambiguous decisions on whether to position the label above or below, but also that the positions in the simulator.json files aren't altogether consistent. I've now decided that for what I'm building, I won't actually use a label at all Sweat smile

    I see what you mean now actually; I can only assume there's some magic knowledge in the simulator binaries that scale these size parameters, whether to the screen dimensions or some other constant. At first I thought I had discovered that the scale factor is something like 6.2 or so (it's hard to tell because there's rounding), but then I tried on the Edge simulator and it was way off.