Exemplo n.º 1
0
/*******************************************************************************
 *  BuildAFM
 *
 *  Builds the AFM for a PostScript font and adds it to the driver font list.
 *  Returns FALSE only on an unexpected error (memory allocation or I/O error).
 *
 */
static BOOL BuildAFM(FILE *file)
{
    CHAR    	buffer[258];    	/* allow for <cr>, <lf>, and <nul> */
    AFM     	*afm;
    AFMMETRICS	*metrics;
    LPSTR   	font_name, full_name, family_name, encoding_scheme;
    BOOL    	retval, added;

    retval = ReadFontMetrics(file, buffer, sizeof(buffer), &afm);
    if (retval == FALSE || afm == NULL)
    	return retval;

    retval = ReadString(file, buffer, sizeof(buffer), "FontName", &font_name);
    if (retval == FALSE || font_name == NULL)
    	goto cleanup_afm;

    retval = ReadString(file, buffer, sizeof(buffer), "FullName", &full_name);
    if (retval == FALSE || full_name == NULL)
    	goto cleanup_font_name;

    retval = ReadString(file, buffer, sizeof(buffer), "FamilyName",
    	    &family_name);
    if (retval == FALSE || family_name == NULL)
    	goto cleanup_full_name;

    retval = ReadString(file, buffer, sizeof(buffer), "EncodingScheme",
    	    &encoding_scheme);
    if (retval == FALSE || encoding_scheme == NULL)
    	goto cleanup_family_name;

    afm->FontName = font_name;
    afm->FullName = full_name;
    afm->FamilyName = family_name;
    afm->EncodingScheme = encoding_scheme;

    retval = ReadCharMetrics(file, buffer, sizeof(buffer), afm, &metrics);
    if (retval == FALSE || metrics == FALSE)
    	goto cleanup_encoding_scheme;

    retval = PSDRV_AddAFMtoList(&PSDRV_AFMFontList, afm, &added);
    if (retval == FALSE || added == FALSE)
    	goto cleanup_encoding_scheme;

    return TRUE;

    /* clean up after fatal or non-fatal errors */

    cleanup_encoding_scheme:
    	HeapFree(PSDRV_Heap, 0, encoding_scheme);
    cleanup_family_name:
    	HeapFree(PSDRV_Heap, 0, family_name);
    cleanup_full_name:
    	HeapFree(PSDRV_Heap, 0, full_name);
    cleanup_font_name:
    	HeapFree(PSDRV_Heap, 0, font_name);
    cleanup_afm:
    	HeapFree(PSDRV_Heap, 0, afm);

    return retval;
}
Exemplo n.º 2
0
/*******************************************************************************
 *  BuildTrueTypeAFM
 *
 *  Builds the AFM for a TrueType font and adds it to the driver font list.
 *  Returns FALSE only on an unexpected error (memory allocation failure or
 *  FreeType error).
 *
 */
static BOOL BuildTrueTypeAFM(FT_Face face)
{
    AFM     	*afm;
    AFMMETRICS	*metrics;
    LPSTR   	font_name, full_name, family_name, encoding_scheme = NULL;
    FT_CharMap	charmap;
    BOOL    	retval, added;

    retval = StartAFM(face, &afm);
    if (retval == FALSE || afm == NULL)
    	return retval;

    retval = FindCharMap(face, &charmap, &encoding_scheme);
    if (retval == FALSE || charmap == NULL)
    	goto cleanup_afm;

    retval = FindMSTTString(face, charmap, TT_NAME_ID_PS_NAME, &font_name);
    if (retval == FALSE || font_name == NULL)
    	goto cleanup_encoding_scheme;

    retval = FindMSTTString(face, charmap, TT_NAME_ID_FULL_NAME, &full_name);
    if (retval == FALSE || full_name == NULL)
    	goto cleanup_font_name;

    retval = FindMSTTString(face, charmap, TT_NAME_ID_FONT_FAMILY,
    	    &family_name);
    if (retval == FALSE || family_name == NULL)
    	goto cleanup_full_name;

    retval = ReadCharMetrics(face, afm, &metrics);
    if (retval == FALSE || metrics == NULL)
    	goto cleanup_family_name;

    afm->EncodingScheme = encoding_scheme; afm->FontName = font_name;
    afm->FullName = full_name; afm->FamilyName = family_name;
    afm->Metrics = metrics;

    retval = PSDRV_AddAFMtoList(&PSDRV_AFMFontList, afm, &added);
    if (retval == FALSE || added == FALSE)
    	goto cleanup_family_name;

    return TRUE;

    /* clean up after fatal or non-fatal errors */

    cleanup_family_name:
    	HeapFree(PSDRV_Heap, 0, family_name);
    cleanup_full_name:
    	HeapFree(PSDRV_Heap, 0, full_name);
    cleanup_font_name:
    	HeapFree(PSDRV_Heap, 0, font_name);
    cleanup_encoding_scheme:
    	HeapFree(PSDRV_Heap, 0, encoding_scheme);
    cleanup_afm:
    	HeapFree(PSDRV_Heap, 0, afm);

    return retval;
}