static fz_error*
pdf_createfontlistMS()
{
	char szFontDir[MAX_PATH*2];
	char szSearch[MAX_PATH*2];
	char szFile[MAX_PATH*2];
	BOOL fFinished;
	HANDLE hList;
	WIN32_FIND_DATA FileData;
	fz_error *err;

	if (fontlistMS.len != 0)
		return nil;

	GetWindowsDirectory(szFontDir, sizeof(szFontDir));

	// Get the proper directory path
	strcat(szFontDir,"\\Fonts\\");
	sprintf(szSearch,"%s*.tt?",szFontDir);
	// Get the first file
	hList = FindFirstFile(szSearch, &FileData);
	if (hList == INVALID_HANDLE_VALUE)
	{
		/* Don't complain about missing directories */
		if (errno == ENOENT)
			return fz_throw("fonterror : can't find system fonts dir");
		return fz_throw("ioerror");
	}
	// Traverse through the directory structure
	fFinished = FALSE;
	while (!fFinished)
	{
		if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
		{
			// Get the full path for sub directory
			sprintf(szFile,"%s%s",szFontDir,FileData.cFileName);
			if (szFile[strlen(szFile)-1] == 'c'|| szFile[strlen(szFile)-1] == 'C' )
			{
				err = parseTTCs(szFile);
                // ignore error parsing a given font file
			}
			else if (szFile[strlen(szFile)-1] == 'f' || szFile[strlen(szFile)-1] == 'F' )
			{
				err = parseTTFs(szFile);
                // ignore error parsing a given font file
			}
		}

		if (!FindNextFile(hList, &FileData))
		{
			if (GetLastError() == ERROR_NO_MORE_FILES)
			{
				fFinished = TRUE;
			}
		}
	}

	removeredundancy(&fontlistMS);
	return nil;
}
Пример #2
0
static fz_error
pdf_extend_system_font_list(const TCHAR *path, pdf_xref *xref)
{
	TCHAR szPath[MAX_PATH], *lpFileName;
	WIN32_FIND_DATA FileData;
	HANDLE hList;

	GetFullPathName(path, _countof(szPath), szPath, &lpFileName);

	hList = FindFirstFile(szPath, &FileData);
	if (hList == INVALID_HANDLE_VALUE)
	{
		// Don't complain about missing directories
		if (GetLastError() == ERROR_FILE_NOT_FOUND)
			return fz_okay;
		return fz_error_make(xref->ctx, "extend_system_font_list: unknown error %d", GetLastError());
	}
	do
	{
		if (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
		{
			char szPathAnsi[MAX_PATH], *fileExt;
			BOOL isNonAnsiPath = FALSE;
			lstrcpyn(lpFileName, FileData.cFileName, szPath + MAX_PATH - lpFileName);
#ifdef _UNICODE
			// FreeType uses fopen and thus requires the path to be in the ANSI code page
			WideCharToMultiByte(CP_ACP, 0, szPath, -1, szPathAnsi, sizeof(szPathAnsi), NULL, &isNonAnsiPath);
#else
			strcpy(szPathAnsi, szPath);
			isNonAnsiPath = strchr(szPathAnsi, '?') != NULL;
#endif
			fileExt = szPathAnsi + strlen(szPathAnsi) - 4;
			if (isNonAnsiPath)
				fz_warn(xref->ctx, "ignoring font with non-ANSI filename: %s", szPathAnsi);
			else if (!_stricmp(fileExt, ".ttc"))
				parseTTCs(szPathAnsi, xref);
			else if (!_stricmp(fileExt, ".ttf") || !_stricmp(fileExt, ".otf"))
				parseTTFs(szPathAnsi, xref);
			// ignore errors occurring while parsing a given font file
		}
	} while (FindNextFile(hList, &FileData));
	FindClose(hList);

	return fz_okay;
}