
This function returns the default axis values for all named font instances in a font (assuming that named font instances are stored in the font file).
| Parameter | Description |
|---|---|
|
engine |
Handle of the previously created Standard Engine instance. |
|
font_index |
Font index of an existing multiple-master font or multiple-master font instance in the Font Catalog. |
|
inst_data |
An array that will store the default axis values. This array must be large enough to hold inst_count * font_axes elements, where inst_count is the number of multiple-master design instances in the font referenced by font_index and font_axes is the number of multiple-master design axes in the font referenced by font_index. Both of these values can be obtained by calling the dtFontGetMMAxisInfo function. |
|
reserved |
Reserved for future use. Must be 0. |
This example shows how to get named font instance names in a font and, for each instance, get its default axis values. The default axis values are shown as factors in the [0..1] range.
/*
Globals used in this example:
* DTEngineInst - A valid D-Type Font Engine Instance Handle
* FontIndex - A valid D-Type index of the MM or variable font in question
Note that in a real program these would not be globals.
*/
// Two helper functions (GetStringId and GetFontString)
inline DT_ID_SWORD GetStringId(DT_SWORD start_mm_id, DT_SLONG mm_axis) const
{
return static_cast<DT_ID_SWORD>(start_mm_id + mm_axis);
}
void GetFontString(DT_SWORD font_index, DT_ID_SWORD string_id_asc, DT_ID_SWORD string_id_uni, DT_UBYTE* buffer, DT_SLONG max_string_len) const
{
if (buffer == DV_NULL) return;
buffer[0] = 0;
if (font_index < 0 || max_string_len < 4) return;
max_string_len--; /* because we need one extra element at the end for 0 */
DT_SLONG i, j, len;
/* First try to get ASCII string */
if (string_id_asc != 0)
{
len = dtFontGetStringValue(DTEngineInst, font_index, string_id_asc, buffer, max_string_len);
if (len > max_string_len) len = max_string_len;
if (len > 0) { buffer[len] = 0; return; }
}
/* If not found, try Unicode */
if (string_id_uni != 0)
{
len = dtFontGetStringValue(DTEngineInst, font_index, string_id_uni, buffer, max_string_len);
if (len > max_string_len) len = max_string_len;
/* Convert Unicode to ASCII */
for (i = j = 0; i < len; i += 2, j++)
{
DT_UBYTE b = buffer[i]; buffer[i] = buffer[i + 1]; buffer[i + 1] = b; /* BE -> LE swap */
DT_UWORD char_code = DF_READ_UWORD_LE(buffer + i); if (char_code > 255) char_code = '?';
buffer[j] = static_cast<DT_UBYTE>(char_code);
}
buffer[j] = 0;
}
}
// Get named font instance names and for each instance get its default axis values
const DT_FLOAT one_over_65536 = 0.0000152587890625;
DT_SLONG i, j, k = 0;
DT_SLONG inst_count = 0;
DT_SLONG* inst_data = DV_NULL;
DT_SWORD font_dim /*unused*/, font_axes = dtFontGetMMAxisInfo(DTEngineInst, FontIndex, &font_dim, &inst_count);
DT_CHAR font_buffer[1024];
if (inst_count > 0 && font_axes > 0)
{
inst_data = static_cast<DT_SLONG*>(malloc(sizeof(DT_SLONG) * inst_count * font_axes));
if (inst_data == DV_NULL) { printf("malloc failed\r"); exit(0); }
dtFontGetMMInstData(DTEngineInst, FontIndex, inst_data, 0); /* get all default axis values in one shot */
}
for (i = 0; i < inst_count; i++)
{
/* copy font instance names to font_buffer */
GetFontString(FontIndex, GetStringId(DV_SVAL_ASC_MMINSTANCE_NAME_000, i), GetStringId(DV_SVAL_UNI_MMINSTANCE_NAME_000, i), (DT_UBYTE*)font_buffer, 1024);
if (font_buffer[0] == 0) break; /* unexpected (bad font?) */
printf("Instance #%ld: Name = %s\r", i, font_buffer);
/* get names and default values for each axis */
for (j = 0; j < font_axes; j++, k++)
{
GetFontString(FontIndex, GetStringId(DV_SVAL_ASC_MMAXIS_NAME_000, j), GetStringId(DV_SVAL_UNI_MMAXIS_NAME_000, j), (DT_UBYTE*)(font_buffer), 1024);
printf(" Axis Name = %s : Default Value = %.2f\r", font_buffer, inst_data[k] * one_over_65536);
}
printf("\r\r");
}
