File: utilT1Entries.c

package info (click to toggle)
ted 2.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,944 kB
  • ctags: 20,273
  • sloc: ansic: 167,980; makefile: 12,518; sh: 263
file content (138 lines) | stat: -rw-r--r-- 2,884 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#   include	"appUtilConfig.h"

#   include	<stdio.h>
#   include	<stdlib.h>
#   include	<string.h>
#   include	<ctype.h>

#   include	"psFont.h"
#   include	"appSystem.h"
#   include	"utilX11FontNames.h"
#   include	"utilT1Entries.h"
#   include	"utilFontmap.h"

#   include	<appDebugon.h>

/************************************************************************/
/*									*/
/*  Get a line of input. (Essentially fgets())				*/
/*									*/
/************************************************************************/

static char *	utilT1GetInputLine(	char *		s,
					int *		pLen,
					int		size,
					FILE *		stream )
    {
    s= fgets( s, size, stream );

    if  ( s )
	{
	int		lineLength= strlen( s );

	if  ( lineLength > 0		&&
	      s[lineLength-1] == '\n'	)
	    { s[--lineLength]= '\0'; 	}

#	if 0
	No! are unix specific files

	if  ( lineLength > 0		&&
	      s[lineLength-1] == '\r'	)
	    { s[--lineLength]= '\0';	}

	/*  3  */
	if  ( lineLength > 0		&&
	      s[lineLength-1] == '\r'	)
	    { s[--lineLength]= '\0';	}
#	endif

	*pLen= lineLength;
	}

    return s;
    }


int utilSetT1EntriesForFonts(	const char *			t1MapFile,
				int				mapNames,
				const PostScriptFontList *	psfl )
    {
    FILE *	xfontDir= fopen( t1MapFile, "r" );
    char	scratch[256+1];
    int		lineLength;

    int		line= 0;

    if  ( ! xfontDir )
	{ SXDEB(t1MapFile,xfontDir); return -1;	}

    while( utilT1GetInputLine( scratch, &lineLength,
					    sizeof(scratch)- 1, xfontDir ) )
	{
	int			x11Start;
	int			x11Length;
	int			res;

	const AppFontFamily *	aff;
	AppFontTypeface *	aft;
	int			fam;
	int			face;

	res= utilX11SplitFontsDirLine( scratch,
					&x11Start, &x11Length, line++ );
	if  ( res < 0 )
	    { SDEB(scratch); continue;	}
	if  ( res > 0 )
	    { continue;	}

	aff= psfl->psflFamilies; aft= (AppFontTypeface *)0;
	for ( fam= 0; fam < psfl->psflFamilyCount; aff++, fam++ )
	    {
	    aft= aff->affFaces;
	    for ( face= 0; face < aff->affFaceCount; aft++, face++ )
		{
		const AfmFontInfo *	afi;
		const char *		fontName;
		const char *		alias;

		afi= (const AfmFontInfo *)aft->aftPrintingData;
		fontName= alias= afi->afiFontName;

		if  ( mapNames )
		    {
		    alias= utilFontmapGetEntry( fontName );
		    if  ( ! alias )
			{ alias= fontName;	}
		    }

		if  ( ! strcmp( alias, scratch ) )
		    { break;	}
		}

	    if  ( face < aff->affFaceCount )
		{ break;	}
	    }

	if  ( fam < psfl->psflFamilyCount )
	    {
	    const char *	x11Name= scratch+ x11Start;
	    int			enc= utilEncodingFromX11FontName( x11Name );

	    if  ( enc >= 0				&&
		  ! aft->aftXQueryFormats[enc]		)
		{
		aft->aftXQueryFormats[enc]= (char *)malloc( x11Length+ 1 );
		if  ( ! aft->aftXQueryFormats[enc] )
		    { XDEB(aft->aftXQueryFormats[enc]); return -1;	}

		strcpy( aft->aftXQueryFormats[enc], x11Name );
		}
	    }
	}

    fclose( xfontDir );

    return 0;
    }