Discussion:
[ft] FT_New_Face
Hartwig Wiesmann
2006-09-16 21:08:21 UTC
Permalink
Hi,

the file path parameter is a pointer to a constant char type. A lot
of OS are not using ASCII characters but Unicode to describe the file
name and its path. Is there any workaround to have also access to
font files that have non-ASCII characters in their file names?

Hartwig
Brian Weed
2006-09-17 00:52:57 UTC
Permalink
Hi,
the file path parameter is a pointer to a constant char type. A lot of
OS are not using ASCII characters but Unicode to describe the file
name and its path. Is there any workaround to have also access to font
files that have non-ASCII characters in their file names?
Hartwig
AFAIK, FT_New_Face eventually just calls fopen()...

On Win32 if you compile FreeType with _MBCS (a win32 define), then you
can pass Multi-Byte-Character-Strings (which can be represented with a
CHAR *).
On MacOS, I think the default is UTF-8 (which can also be represented by
a CHAR *).

I store all strings as UTF-8 (regardless of platform), and convert to
MBCS on Win32 as needed.

Brian
Wenlin Institute
2006-09-17 16:48:06 UTC
Permalink
Post by Brian Weed
Post by Hartwig Wiesmann
Hi,
the file path parameter is a pointer to a constant char type. A
lot of OS are not using ASCII characters but Unicode to describe
the file name and its path. Is there any workaround to have also
access to font files that have non-ASCII characters in their file
names?
Hartwig
AFAIK, FT_New_Face eventually just calls fopen()...
On Win32 if you compile FreeType with _MBCS (a win32 define), then
you can pass Multi-Byte-Character-Strings (which can be represented
with a CHAR *).
On MacOS, I think the default is UTF-8 (which can also be
represented by a CHAR *).
Yes, on OS X you can use UTF-8 for the font filename (which can
include Chinese characters, for example) and FT_New_Face() will open
the font.
Post by Brian Weed
I store all strings as UTF-8 (regardless of platform), and convert
to MBCS on Win32 as needed.
Same here. On Win32, I don't know if FT_New_Face works with UTF-8 or
whether fopen() can be made to work reliably with UTF-8. (My Windows
XP computer is currently broken so I can't test it.) Otherwise, on
Win32, when the filename is known to be UTF-8, it can be converted to
UTF-16, and _wfopen() can be called instead of fopen(). That works.
(I've tested it on XP with text files, but not with fonts.) It might
be good for FT_New_Face to support that method on Win32, if it
doesn't already.

Tom
Post by Brian Weed
Brian
_______________________________________________
Freetype mailing list
http://lists.nongnu.org/mailman/listinfo/freetype
文林 Wenlin Institute, Inc. Software for Learning Chinese
E-mail: ***@wenlin.com Web: http://www.wenlin.com
Telephone: 1-877-4-WENLIN (1-877-493-6546)

Werner LEMBERG
2006-09-17 17:38:58 UTC
Permalink
[...] on Win32, when the filename is known to be UTF-8, it can be
converted to UTF-16, and _wfopen() can be called instead of
fopen(). That works. (I've tested it on XP with text files, but not
with fonts.) It might be good for FT_New_Face to support that method
on Win32, if it doesn't already.
We don't have special code for Win32 as far as I can remember. In
case you think there is something we can improve please send a patch.


Werner
Wenlin Institute
2006-09-17 21:15:15 UTC
Permalink
You already provide a way for platform specific file loading -
FT_Open_Face. It is good enough for Windows platform.
That's good news. Could anyone point to sample code for using
FT_Open_Face on MS-Windows?

Tom
Sergey
-----Original Message-----
Behalf Of Werner LEMBERG
Sent: Sunday, September 17, 2006 10:39 AM
Subject: Re: [ft] FT_New_Face
[...] on Win32, when the filename is known to be UTF-8, it can be
converted to UTF-16, and _wfopen() can be called instead of
fopen().
That works. (I've tested it on XP with text files, but not with
fonts.) It might be good for FT_New_Face to support that method on
Win32, if it doesn't already.
We don't have special code for Win32 as far as I can
remember. In case you think there is something we can
improve please send a patch.
Werner
_______________________________________________
Freetype mailing list
http://lists.nongnu.org/mailman/listinfo/freetype
文林 Wenlin Institute, Inc. Software for Learning Chinese
E-mail: ***@wenlin.com Web: http://www.wenlin.com
Telephone: 1-877-4-WENLIN (1-877-493-6546)

Leonard Rosenthol
2006-09-17 23:45:11 UTC
Permalink
Post by Wenlin Institute
You already provide a way for platform specific file loading -
FT_Open_Face. It is good enough for Windows platform.
That's good news. Could anyone point to sample code for using
FT_Open_Face on MS-Windows?
I tend to use FT_New_Memory_Face() on Windows, having first
found the font data using native OS API calls and then loading the
font data into memory from there...


Leonard
--
---------------------------------------------------------------------------
Leonard Rosenthol <mailto:***@pdfsages.com>
Chief Technical Officer <http://www.pdfsages.com>
PDF Sages, Inc. 215-938-7080 (voice)
215-689-3863 (fax)
Michael Day
2006-09-17 23:57:19 UTC
Permalink
Hi Leonard,
I tend to use FT_New_Memory_Face() on Windows, having first found
the font data using native OS API calls and then loading the font data
into memory from there...
We do that too in Prince, however this method is difficult to use for
TrueType Collection (TTC) fonts such as the Chinese mingliu.ttc font, as
the table offsets are relative to the entire font file, but
GetFontData() only gives you the single font that you asked for, which
appears to be broken when handed to FreeType. Can you handle this
situation by rewriting the offsets, or do you only handle non-TTC fonts?

Best regards,

Michael
--
Print XML with Prince!
http://www.princexml.com
Leonard Rosenthol
2006-09-18 01:33:17 UTC
Permalink
Post by Michael Day
We do that too in Prince, however this method is difficult to use
for TrueType Collection (TTC) fonts such as the Chinese mingliu.ttc
font, as the table offsets are relative to the entire font file, but
GetFontData() only gives you the single font that you asked for,
which appears to be broken when handed to FreeType. Can you handle
this situation by rewriting the offsets, or do you only handle
non-TTC fonts?
I don't support TTC fonts using that methodology, since it
doesn't work as well for TTC (and also certain T1 fonts). For
those, we don't use FT at all and load the font & respective data
ourselves.


Leonard
--
---------------------------------------------------------------------------
Leonard Rosenthol <mailto:***@pdfsages.com>
Chief Technical Officer <http://www.pdfsages.com>
PDF Sages, Inc. 215-938-7080 (voice)
215-689-3863 (fax)
Wenlin Institute
2006-09-19 02:36:15 UTC
Permalink
I tend to use FT_New_Memory_Face() on Windows, having first found
the font data using native OS API calls and then loading the font
data into memory from there...
Thanks for that tip! That is one solution. Still, it seems preferable
not to have to load the whole font into RAM. Some fonts are huge and
memory may be limited; plus there's the problem with TTC fonts. Also,
some Freetype users are likely to go on using FT_New_Face on Win32,
and not realize that it may fail on non-ASCII filenames.

How about making FT_New_Face more usable on Win32, always supporting
UTF-8 as well as the default encoding. This could go in ftstdlib.h:

#if defined(WIN32) && defined(UNICODE)
FILE * ft_fopen_win32(char *fname, char *mode);
#define ft_fopen ft_fopen_win32
#else
#define ft_fopen fopen
#endif

(Currently ftstdlib.h just has "#define ft_fopen fopen".)

The following could go wherever it belongs (maybe ftsystem.c?):

#if defined(WIN32) && defined(UNICODE)
FILE * ft_fopen_win32(char *fname, char *mode)
{
// First try fopen, assuming nothing about character encodings.
FILE *file = fopen(fname, mode);
if (file == NULL) {
/* fopen failed. Assume the filename is UTF-8, convert to UTF-16,
and try _wfopen.
These max sizes are somewhat arbitrary; could use dynamic
allocation instead,
and call MultiByteToWideChar(..., 0) to get size needed... */
#define MAX_WIN32_FNAME 2048
#define MAX_FOPEN_MODE 100
TCHAR fnameW[MAX_WIN32_FNAME], modeW[MAX_FOPEN_MODE];
if (MultiByteToWideChar(CP_UTF8, 0, fname, strlen(fname),
fnameW, MAX_WIN32_FNAME) == 0) {
return NULL;
}
if (MultiByteToWideChar(CP_UTF8, 0, mode, strlen(mode),
modeW, MAX_FOPEN_MODE) == 0) {
return NULL;
}
file = _wfopen(fnameW, modeW);
}
return file;
} /* ft_fopen_win32 */
#endif

I haven't been able to test this yet. Maybe someone will want to.

Tom

文林 Wenlin Institute, Inc. Software for Learning Chinese
E-mail: ***@wenlin.com Web: http://www.wenlin.com
Telephone: 1-877-4-WENLIN (1-877-493-6546)

Werner LEMBERG
2006-09-19 05:34:07 UTC
Permalink
Post by Wenlin Institute
How about making FT_New_Face more usable on Win32, always supporting
[...]
This looks nice, but...
Post by Wenlin Institute
I haven't been able to test this yet. Maybe someone will want to.
I need tests since I don't use Windows.


Werner
Wenlin Institute
2006-09-19 20:09:13 UTC
Permalink
Post by Werner LEMBERG
Post by Wenlin Institute
How about making FT_New_Face more usable on Win32, always supporting
[...]
This looks nice, but...
Post by Wenlin Institute
I haven't been able to test this yet. Maybe someone will want to.
I need tests since I don't use Windows.
Understood. I'll do the testing eventually if no one else does. My
Windows XP machine died a while ago. (I'll have to get one soon since
most of my customers use Windows.) I normally cross-compile for Win32
on my Macintosh, but haven't tried to cross-compile Freetype. It's
not clear how soon I can work on this, so I made the code available
in case anyone else has the time and interest to try it sooner. For
my own purposes I can work around the problem by using
FT_New_Memory_Face on Win32, until FT_New_Face is fixed.

All the best,

Tom

文林 Wenlin Institute, Inc. Software for Learning Chinese
E-mail: ***@wenlin.com Web: http://www.wenlin.com
Telephone: 1-877-4-WENLIN (1-877-493-6546)


Loading...