void make_trait_page (qse_wcint_t start, qse_wcint_t end) { qse_wcint_t code; size_t i; short traits[TRAIT_PAGE_SIZE]; trait_page_t* page; memset (traits, 0, sizeof(traits)); for (code = start; code <= end; code++) { traits[code - start] = get_trait(code); } for (page = trait_pages; page != NULL; page = page->next) { if (memcmp (traits, page->traits, sizeof(traits)) == 0) { trait_maps[trait_map_count++] = page; return; } } page = (trait_page_t*)malloc (sizeof(trait_page_t)); page->no = trait_page_count++; memcpy (page->traits, traits, sizeof(traits)); page->next = trait_pages; trait_pages = page; trait_maps[trait_map_count++] = page; }
static int get_variable(SEXP variable, struct design *s, struct design *r, struct design2 *d, struct variable *v) { int err = 0; if (isMatrix(variable) || inherits(variable, "matrix")) { err = get_trait(variable, s, r, v); } else if (inherits(variable, "special")) { err = get_special(variable, s, r, d, v); } else { DOMAIN_ERROR("unknown variable type"); } return err; }
static void get_font_traits(CTFontDescriptorRef fontd, ASS_FontProviderMetaData *meta) { float weight, slant, width; CFDictionaryRef traits = CTFontDescriptorCopyAttribute(fontd, kCTFontTraitsAttribute); get_trait(traits, kCTFontWeightTrait, &weight); get_trait(traits, kCTFontSlantTrait, &slant); get_trait(traits, kCTFontWidthTrait, &width); SAFE_CFRelease(traits); // Printed all of my system fonts (see if'deffed code below). Here is how // CoreText 'normalized' weights maps to CSS/libass: // opentype: 0 100 200 300 400 500 600 700 800 900 // css: LIGHT REG MED SBOLD BOLD BLACK EXTRABL // libass: LIGHT MEDIUM BOLD // coretext: -0.4 0.0 0.23 0.3 0.4 0.62 if (weight >= 0.62) meta->weight = 800; else if (weight >= 0.4) meta->weight = 700; else if (weight >= 0.3) meta->weight = 600; else if (weight >= 0.23) meta->weight = 500; else if (weight >= -0.4) meta->weight = 400; else meta->weight = 200; if (slant > 0.03) meta->slant = FONT_SLANT_ITALIC; else meta->slant = FONT_SLANT_NONE; if (width <= -0.2) meta->width = FONT_WIDTH_CONDENSED; else if (width >= 0.2) meta->width = FONT_WIDTH_EXPANDED; else meta->width = FONT_WIDTH_NORMAL; #if 0 char *name[1]; int idx = 0; get_name(fontd, kCTFontDisplayNameAttribute, name, &idx); char *file = get_font_file(fontd); printf( "Font traits for: %-40s [%-50s] " "<slant: %f, %03d>, <weight: (%f, %03d)>, <width: %f, %03d>\n", name[0], file, slant, meta->slant, weight, meta->weight, width, meta->width); free(name[0]); free(file); #endif }