]> git.wh0rd.org Git - fontconfig.git/commitdiff
Implemented foundry generation for Type 1 and TrueType
authorJuliusz Chroboczek <Juliusz.Chroboczek@pps.jussieu.fr>
Fri, 11 Apr 2003 23:45:59 +0000 (23:45 +0000)
committerJuliusz Chroboczek <Juliusz.Chroboczek@pps.jussieu.fr>
Fri, 11 Apr 2003 23:45:59 +0000 (23:45 +0000)
src/data.h [new file with mode: 0644]
src/fcfreetype.c

diff --git a/src/data.h b/src/data.h
new file mode 100644 (file)
index 0000000..5b71113
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+  Copyright (c) 2002-2003 by Juliusz Chroboczek
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+/* Order is significant.  For example, some B&H fonts are hinted by
+   URW++, and both strings appear in the notice. */
+
+char *notice_foundries[][2] = 
+    {{"Bigelow", "b&h"},
+     {"Adobe", "adobe"},
+     {"Bitstream", "bitsteam"},
+     {"Monotype", "monotype"},
+     {"Linotype", "linotype"},
+     {"LINOTYPE-HELL", "linotype"},
+     {"IBM", "ibm"},
+     {"URW", "urw"},
+     {"International Typeface Corporation", "itc"},
+     {"Tiro Typeworks", "tiro"},
+     {"XFree86", "xfree86"},
+     {"Microsoft", "microsoft"},
+     {"Omega", "omega"},
+     {"Font21", "hwan"},
+     {"HanYang System", "hanyang"}};
+
+/* This table is partly taken from ttmkfdir by Joerg Pommnitz. */
+
+/* It should not contain useless entries (such as UNKN) nor duplicate
+   entries for padding both with spaces and NULs. */
+
+char *vendor_foundries[][2] =
+    {{"ADBE", "adobe"},
+     {"AGFA", "agfa"},
+     {"ALTS", "altsys"},
+     {"APPL", "apple"},
+     {"ARPH", "arphic"},
+     {"ATEC", "alltype"},
+     {"B&H", "b&h"},
+     {"BITS", "bitstream"},
+     {"CANO", "cannon"},
+     {"DYNA", "dynalab"},
+     {"EPSN", "epson"},
+     {"FJ",  "fujitsu"},
+     {"IBM", "ibm"},
+     {"ITC", "itc"},
+     {"IMPR", "impress"},
+     {"LARA", "larabiefonts"},
+     {"LEAF", "interleaf"},
+     {"LETR", "letraset"},
+     {"LINO", "linotype"},
+     {"MACR", "macromedia"},
+     {"MONO", "monotype"},
+     {"MS", "microsoft"},
+     {"MT", "monotype"},
+     {"NEC", "nec"},
+     {"PARA", "paratype"},
+     {"QMSI", "qms"},
+     {"RICO", "ricoh"},
+     {"URW", "urw"},
+     {"Y&Y", "y&y"}};
index dcbcc56f2cc432902091fb185b54d514bb36e021..1c950950af4b2650897d1dab67dd74d36615ab82 100644 (file)
@@ -33,6 +33,8 @@
 #include <freetype/ttnameid.h>
 #include <freetype/t1tables.h>
 
+#include "data.h"
+
 /*
  * Keep Han languages separated by eliminating languages
  * that the codePageRange bits says aren't supported
@@ -112,6 +114,41 @@ FcUtf8IsLatin (FcChar8 *str, int len)
     return FcTrue;
 }
 
+static char*
+notice_foundry(char *notice)
+{
+    int i;
+    for(i = 0; i < sizeof(notice_foundries) / sizeof(notice_foundries[0]); i++)
+        if(notice && strstr(notice, notice_foundries[i][0]))
+            return notice_foundries[i][1];
+    return NULL;
+}
+
+static int
+vendor_match(signed char *vendor, char *vendor_string)
+{
+    /* vendor is not necessarily NUL-terminated. */
+    int i, len;
+    len = strlen(vendor_string);
+    if(memcmp(vendor, vendor_string, len) != 0)
+        return 0;
+    for(i = len; i < 4; i++)
+        if(vendor[i] != ' ' && vendor[i] != '\0')
+            return 0;
+    return 1;
+}
+
+static char*
+vendor_foundry(signed char *vendor)
+{
+    int i;
+    for(i = 0; i < sizeof(vendor_foundries) / sizeof(vendor_foundries[0]); i++)
+        if(vendor_match(vendor, vendor_foundries[i][0]))
+            return vendor_foundries[i][1];
+    return NULL;
+}
+
+
 FcPattern *
 FcFreeTypeQuery (const FcChar8 *file,
                 int            id,
@@ -129,6 +166,7 @@ FcFreeTypeQuery (const FcChar8      *file,
     FT_Library     ftLibrary;
     FcChar8        *family;
     FcChar8        *style;
+    FcChar8         *foundry;
     int                    spacing;
     TT_OS2         *os2;
     PS_FontInfoRec  psfontinfo;
@@ -171,6 +209,16 @@ FcFreeTypeQuery (const FcChar8     *file,
     if (face->style_flags & FT_STYLE_FLAG_BOLD)
        weight = FC_WEIGHT_BOLD;
 
+    /*
+     * Get the OS/2 table
+     */
+    os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
+
+    if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
+        foundry = vendor_foundry(os2->achVendID);
+    else
+        foundry = NULL;
+
     /*
      * Grub through the name table looking for family
      * and style names.  FreeType makes quite a hash
@@ -178,6 +226,7 @@ FcFreeTypeQuery (const FcChar8      *file,
      */
     family = 0;
     style = 0;
+    foundry = 0;
     snamec = FT_Get_Sfnt_Name_Count (face);
     for (snamei = 0; snamei < snamec; snamei++)
     {
@@ -287,7 +336,9 @@ FcFreeTypeQuery (const FcChar8      *file,
            prio |= FC_NAME_PRIO_NAME_PS;
            break;
        case TT_NAME_ID_FONT_SUBFAMILY:
-           break;
+        case TT_NAME_ID_TRADEMARK:
+        case TT_NAME_ID_MANUFACTURER:
+            break;
        default:
            continue;
        }
@@ -400,6 +451,11 @@ FcFreeTypeQuery (const FcChar8     *file,
                style_prio = prio;
            }
            break;
+        case TT_NAME_ID_TRADEMARK:
+        case TT_NAME_ID_MANUFACTURER:
+            if(!foundry)
+                foundry = notice_foundry(utf8);
+            break;
        }
        if (utf8)
            free (utf8);
@@ -457,6 +513,11 @@ FcFreeTypeQuery (const FcChar8     *file,
            free (style);
     }
 
+    if(foundry) {
+        if(!FcPatternAddString (pat, FC_FOUNDRY, foundry))
+            goto bail;
+    }
+
     if (!FcPatternAddString (pat, FC_FILE, file))
        goto bail1;
 
@@ -492,10 +553,6 @@ FcFreeTypeQuery (const FcChar8     *file,
            goto bail1;
     }
 
-    /*
-     * Get the OS/2 table and poke about
-     */
-    os2 = (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2);
     if (os2 && os2->version >= 0x0001 && os2->version != 0xffff)
     {
        for (i = 0; i < NUM_CODE_PAGE_RANGE; i++)
@@ -527,6 +584,9 @@ FcFreeTypeQuery (const FcChar8      *file,
                exclusiveLang = FcCodePageRange[i].lang;
            }
        }
+
+        foundry = vendor_foundry(os2->achVendID);
+
     }
 
     if (os2 && os2->version != 0xffff)
@@ -607,6 +667,9 @@ FcFreeTypeQuery (const FcChar8      *file,
             slant = FC_SLANT_ITALIC; 
         else if (psfontinfo.italic_angle >= 0) 
             slant = FC_SLANT_ROMAN; 
+
+        if(!foundry)
+            foundry = notice_foundry(psfontinfo.notice);
     }
     
     if (!FcPatternAddInteger (pat, FC_SLANT, slant))