Add FcFreeTypeQueryFace external API. Bug #7311.

Expose ability to build an FcPattern directly from an FT_Face
object.
This commit is contained in:
Keith Packard 2006-12-02 13:22:27 -08:00
parent 5e234d9e76
commit 72ffe6536a
4 changed files with 52 additions and 25 deletions

View File

@ -41,11 +41,11 @@ dnl libtool versioning
dnl bump revision when fixing bugs dnl bump revision when fixing bugs
dnl bump current and age, reset revision to zero when adding APIs dnl bump current and age, reset revision to zero when adding APIs
dnl bump current, leave age, reset revision to zero when changing/removing APIS dnl bump current, leave age, reset revision to zero when changing/removing APIS
LT_CURRENT=2 LT_CURRENT=3
LT_REVISION=0 LT_REVISION=0
AC_SUBST(LT_CURRENT) AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION) AC_SUBST(LT_REVISION)
LT_AGE=1 LT_AGE=2
LT_VERSION_INFO="$LT_CURRENT:$LT_REVISION:$LT_AGE" LT_VERSION_INFO="$LT_CURRENT:$LT_REVISION:$LT_AGE"
AC_SUBST(LT_VERSION_INFO) AC_SUBST(LT_VERSION_INFO)

View File

@ -62,8 +62,23 @@ not in 'blanks' are not placed in the returned FcCharSet.
@TYPE2@ int @ARG2@ id @TYPE2@ int @ARG2@ id
@TYPE3@ FcBlanks * @ARG3@ blanks @TYPE3@ FcBlanks * @ARG3@ blanks
@TYPE4@ int * @ARG4@ count @TYPE4@ int * @ARG4@ count
@PURPOSE@ compute font file pattern @PURPOSE@ compute pattern from font file (and index)
@DESC@ @DESC@
Constructs a pattern representing the 'id'th font in 'file'. The number Constructs a pattern representing the 'id'th font in 'file'. The number
of fonts in 'file' is returned in 'count'. of fonts in 'file' is returned in 'count'.
@@ @@
@SYNOPSIS@
#include <fontconfig.h>
#include <fcfreetype.h>
@RET@ FcPattern *
@FUNC@ FcFreeTypeQueryFace
@TYPE1@ const FT_Face @ARG1@ face
@TYPE2@ const char * @ARG2@ file
@TYPE3@ int @ARG3@ id
@TYPE4@ FcBlanks * @ARG4@ blanks
@PURPOSE@ compute pattern from FT_Face
@DESC@
Constructs a pattern representing 'face'. 'file' and 'id' are used solely as
data for pattern elements (FC_FILE, FC_INDEX and sometimes FC_FAMILY).
@@

View File

@ -48,6 +48,12 @@ FcPatternGetFTFace (const FcPattern *p, const char *object, int n, FT_Face *f);
FcPublic FcBool FcPublic FcBool
FcPatternAddFTFace (FcPattern *p, const char *object, const FT_Face f); FcPatternAddFTFace (FcPattern *p, const char *object, const FT_Face f);
FcPublic FcPattern *
FcFreeTypeQueryFace (const FT_Face face,
const FcChar8 *file,
int id,
FcBlanks *blanks);
_FCFUNCPROTOEND _FCFUNCPROTOEND
#endif #endif

View File

@ -1063,12 +1063,11 @@ static const FT_UShort nameid_order[] = {
#define NUM_NAMEID_ORDER (sizeof (nameid_order) / sizeof (nameid_order[0])) #define NUM_NAMEID_ORDER (sizeof (nameid_order) / sizeof (nameid_order[0]))
FcPattern * FcPattern *
FcFreeTypeQuery (const FcChar8 *file, FcFreeTypeQueryFace (const FT_Face face,
const FcChar8 *file,
int id, int id,
FcBlanks *blanks, FcBlanks *blanks)
int *count)
{ {
FT_Face face;
FcPattern *pat; FcPattern *pat;
int slant = -1; int slant = -1;
int weight = -1; int weight = -1;
@ -1077,7 +1076,6 @@ FcFreeTypeQuery (const FcChar8 *file,
int i; int i;
FcCharSet *cs; FcCharSet *cs;
FcLangSet *ls; FcLangSet *ls;
FT_Library ftLibrary;
#if 0 #if 0
FcChar8 *family = 0; FcChar8 *family = 0;
#endif #endif
@ -1108,14 +1106,6 @@ FcFreeTypeQuery (const FcChar8 *file,
FcChar8 *style = 0; FcChar8 *style = 0;
int st; int st;
if (FT_Init_FreeType (&ftLibrary))
return 0;
if (FT_New_Face (ftLibrary, (char *) file, id, &face))
goto bail;
*count = face->num_faces;
pat = FcPatternCreate (); pat = FcPatternCreate ();
if (!pat) if (!pat)
goto bail0; goto bail0;
@ -1785,12 +1775,6 @@ FcFreeTypeQuery (const FcChar8 *file,
*/ */
FcCharSetDestroy (cs); FcCharSetDestroy (cs);
/*
* Deallocate family/style values
*/
FT_Done_Face (face);
FT_Done_FreeType (ftLibrary);
return pat; return pat;
bail2: bail2:
@ -1798,13 +1782,35 @@ bail2:
bail1: bail1:
FcPatternDestroy (pat); FcPatternDestroy (pat);
bail0: bail0:
return NULL;
}
FcPattern *
FcFreeTypeQuery(const FcChar8 *file,
int id,
FcBlanks *blanks,
int *count)
{
FT_Face face;
FT_Library ftLibrary;
FcPattern *pat = NULL;
if (FT_Init_FreeType (&ftLibrary))
return NULL;
if (FT_New_Face (ftLibrary, (char *) file, id, &face))
goto bail;
*count = face->num_faces;
pat = FcFreeTypeQueryFace (face, file, id, blanks);
FT_Done_Face (face); FT_Done_Face (face);
bail: bail:
FT_Done_FreeType (ftLibrary); FT_Done_FreeType (ftLibrary);
return 0; return pat;
} }
/* /*
* For our purposes, this approximation is sufficient * For our purposes, this approximation is sufficient
*/ */