]> git.wh0rd.org - fontconfig.git/blobdiff - src/fcfreetype.c
Fix small memory error (tried to free argv); use basename and dirname
[fontconfig.git] / src / fcfreetype.c
index f3eeb8aa1d13dc1acce4a29477447fda63fe758b..98728363837a34fffeed5f8c02c8f2f71fc981fd 100644 (file)
@@ -47,6 +47,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <libgen.h>
 #include "fcint.h"
 #include <ft2build.h>
 #include FT_FREETYPE_H
@@ -111,9 +112,9 @@ FcFreeTypeIsExclusiveLang (const FcChar8  *lang)
 }
 
 typedef struct {
-    FT_UShort  platform_id;
-    FT_UShort  encoding_id;
-    char       *fromcode;
+    const FT_UShort    platform_id;
+    const FT_UShort    encoding_id;
+    const char fromcode[12];
 } FcFtEncoding;
 
 #define TT_ENCODING_DONT_CARE  0xffff
@@ -138,8 +139,8 @@ static const FcFtEncoding   fcFtEncoding[] = {
 #define NUM_FC_FT_ENCODING  (int) (sizeof (fcFtEncoding) / sizeof (fcFtEncoding[0]))
 
 typedef struct {
-    FT_UShort  platform_id;
-    FT_UShort  language_id;
+    const FT_UShort    platform_id;
+    const FT_UShort    language_id;
     const char lang[8];
 } FcFtLanguage;
 
@@ -549,7 +550,7 @@ static const FcFtLanguage   fcFtLanguage[] = {
 
 typedef struct {
     FT_UShort  language_id;
-    char       *fromcode;
+    char       fromcode[12];
 } FcMacRomanFake;
 
 static const FcMacRomanFake fcMacRomanFake[] = {
@@ -570,8 +571,8 @@ FcFontCapabilities(FT_Face face);
 static FcChar8 *
 FcSfntNameTranscode (FT_SfntName *sname)
 {
-    int            i;
-    char    *fromcode;
+    int               i;
+    const char *fromcode;
 #if USE_ICONV
     iconv_t cd;
 #endif
@@ -596,7 +597,7 @@ FcSfntNameTranscode (FT_SfntName *sname)
     {
        int     f;
 
-       fromcode = 0;
+       fromcode = NULL;
        for (f = 0; f < NUM_FC_MAC_ROMAN_FAKE; f++)
            if (fcMacRomanFake[f].language_id == sname->language_id)
            {
@@ -741,7 +742,7 @@ done:
     return utf8;
 }
 
-static FcChar8 *
+static const FcChar8 *
 FcSfntNameLanguage (FT_SfntName *sname)
 {
     int i;
@@ -1079,7 +1080,7 @@ FcFreeTypeQuery (const FcChar8    *file,
     for (snamei = 0; snamei < snamec; snamei++)
     {
        FcChar8         *utf8;
-       FcChar8         *lang;
+       const FcChar8   *lang;
        const char      *elt = 0, *eltlang = 0;
        int             *np = 0, *nlangp = 0;
 
@@ -1287,9 +1288,11 @@ FcFreeTypeQuery (const FcChar8   *file,
                printf ("Saving unique fullname %s\n", full);
     }
 
-    if (!FcPatternAddString (pat, FC_FILE, file))
+    if (!FcPatternAddString (pat, FC_FILE, (FcChar8 *)basename((char *)FcStrCopy(file))))
        goto bail1;
 
+    FcPatternAddFullFname (pat, (const char *)file);
+
     if (!FcPatternAddInteger (pat, FC_INDEX, id))
        goto bail1;
 
@@ -2217,12 +2220,12 @@ FcFreeTypeUseNames (FT_Face face)
     return FcFalse;
 }
 
-static FcChar8 *
+static const FcChar8 *
 FcUcs4ToGlyphName (FcChar32 ucs4)
 {
     int                i = (int) (ucs4 % FC_GLYPHNAME_HASH);
     int                r = 0;
-    FcGlyphName        *gn;
+    const FcGlyphName  *gn;
 
     while ((gn = ucs_to_name[i]))
     {
@@ -2247,7 +2250,7 @@ FcGlyphNameToUcs4 (FcChar8 *name)
     FcChar32   h = FcHashGlyphName (name);
     int                i = (int) (h % FC_GLYPHNAME_HASH);
     int                r = 0;
-    FcGlyphName        *gn;
+    const FcGlyphName  *gn;
 
     while ((gn = name_to_ucs[i]))
     {
@@ -2272,7 +2275,7 @@ FcGlyphNameToUcs4 (FcChar8 *name)
  * any defined order within the font
  */
 static FT_UInt
-FcFreeTypeGlyphNameIndex (FT_Face face, FcChar8 *name)
+FcFreeTypeGlyphNameIndex (FT_Face face, const FcChar8 *name)
 {
     FT_UInt gindex;
     FcChar8 name_buf[FC_GLYPHNAME_MAXLEN + 2];
@@ -2346,7 +2349,7 @@ FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4)
      */
     if (FcFreeTypeUseNames (face))
     {
-       FcChar8 *name = FcUcs4ToGlyphName (ucs4);
+       const FcChar8   *name = FcUcs4ToGlyphName (ucs4);
        if (name)
        {
            glyphindex = FcFreeTypeGlyphNameIndex (face, name);