| 139 | static const char* const kRoleAliases[5] = {"steelfishb", "tahomab", "couriernewb", "garamond", "audreyshand"}; |
| 140 | |
| 141 | void LoadTuningIfNeeded() |
| 142 | { |
| 143 | if (s_tuning.loaded) |
| 144 | return; |
| 145 | // Parse the dump to fill renderPx / widthScale for each role. |
| 146 | // Format per line: ' {"prefix", "ttfPath", maxH, renderPx, widthScalef, oblique},' |
| 147 | const char* dump = DumpFontTable(); |
| 148 | for (int r = 0; r < 5; r++) |
| 149 | { |
| 150 | s_tuning.roles[r].prefix = kRolePrefixes[r]; |
| 151 | s_tuning.roles[r].alias = kRoleAliases[r]; |
| 152 | s_tuning.roles[r].renderPx = 24; |
| 153 | s_tuning.roles[r].widthScale = 1.0f; |
| 154 | s_tuning.roles[r].baselineOffset = 0.0f; |
| 155 | s_tuning.roles[r].syntheticBold = 0.0f; |
| 156 | s_tuning.roles[r].letterSpacing = 0.0f; |
| 157 | char needle[64]; |
| 158 | snprintf(needle, sizeof(needle), "{\"%s\",", kRolePrefixes[r]); |
| 159 | const char* p = strstr(dump, needle); |
| 160 | if (!p) |
| 161 | continue; |
| 162 | // Skip past prefix + ttfPath + maxH by counting commas. DumpFontTable |
| 163 | // emits: prefix, ttfPath, maxH, renderPx, widthScalef, obliqueBool, |
| 164 | // baselineOffsetf, syntheticBoldf, letterSpacingf |
| 165 | int commas = 0; |
| 166 | const char* q = p; |
| 167 | while (*q && commas < 3) |
| 168 | { |
| 169 | if (*q == ',') |
| 170 | commas++; |
| 171 | q++; |
| 172 | } |
| 173 | // q now points just after the 3rd comma — next is space + renderPx |
| 174 | int rpx = 0; |
| 175 | float ws = 1.0f; |
| 176 | char oblique[16] = "false"; |
| 177 | float baseline = 0.0f, bold = 0.0f, spacing = 0.0f; |
| 178 | if (sscanf(q, " %d, %ff, %15[^,], %ff, %ff, %ff", &rpx, &ws, oblique, &baseline, &bold, &spacing) >= 2) |
| 179 | { |
| 180 | s_tuning.roles[r].renderPx = rpx; |
| 181 | s_tuning.roles[r].widthScale = ws; |
| 182 | s_tuning.roles[r].baselineOffset = baseline; |
| 183 | s_tuning.roles[r].syntheticBold = bold; |
| 184 | s_tuning.roles[r].letterSpacing = spacing; |
| 185 | } |
| 186 | } |
| 187 | s_tuning.loaded = true; |
| 188 | } |
| 189 | |
| 190 | void DrawFontTab() |
| 191 | { |
no test coverage detected