Commits

Akira TAGOH committed 27fce62

Support sFamilyClass to classify fonts

Comments (0)

Files changed (1)

libeasyfc/ezfc-font.c

 	ezfc_font_variant_t retval = EZFC_FONT_UNKNOWN;
 	TT_OS2 *os2;
 	FT_Face face = NULL;
+	FT_Byte cls_id, subcls_id;
 
 	FcPatternGetInteger(pattern, FC_SPACING, 0, &spacing);
 	if (spacing == FC_MONO ||
 	os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2);
 	if (!os2)
 		goto bail;
+	/* See http://www.microsoft.com/typography/otspec/os2.htm#fc
+	 * and http://www.microsoft.com/typography/otspec/ibmfc.htm
+	 * for the reference of sFamilyClass.
+	 */
+	cls_id = (os2->sFamilyClass >> 8) & 0xff;
+	subcls_id = os2->sFamilyClass & 0xff;
+	switch (cls_id) {
+	    case 0: /* No Classification */
+	    case 6: /* reserved for future use */
+	    case 11: /* reserved for future use */
+	    case 13: /* Reserved */
+	    case 14: /* Reserved */
+		    break;
+	    case 1: /* Oldstyle Serifs */
+		    retval |= EZFC_FONT_SERIF;
+		    if (subcls_id == 8) /* Calligraphic */
+			    retval |= EZFC_FONT_CURSIVE;
+		    break;
+	    case 2: /* Transitional Serifs */
+	    case 3: /* Modern Serifs */
+		    retval |= EZFC_FONT_SERIF;
+		    if (subcls_id == 2) /* Script */
+			    retval |= EZFC_FONT_CURSIVE;
+		    break;
+	    case 4: /* Clarendon Serifs */
+	    case 5: /* Slab Serifs */
+	    case 7: /* Freeform Serifs */
+		    retval |= EZFC_FONT_SERIF;
+		    break;
+	    case 8: /* Sans Serif */
+		    retval |= EZFC_FONT_SANS;
+		    break;
+	    case 9: /* Ornamentals */
+	    case 12: /* Symbolic */
+		    retval |= EZFC_FONT_FANTASY;
+		    break;
+	    case 10: /* Scripts */
+		    retval |= EZFC_FONT_CURSIVE;
+		    break;
+	    default:
+		    g_warning("Unknown sFamilyClass class ID: %d", cls_id);
+		    break;
+	}
 	/* See http://www.monotypeimaging.com/ProductsServices/pan1.aspx
 	 * for the reference of Panose
 	 */