1 //========================================================================
3 // SplashFTFontEngine.cc
5 //========================================================================
9 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
22 #include "FoFiTrueType.h"
23 #include "FoFiType1C.h"
24 #include "SplashFTFontFile.h"
25 #include "SplashFTFontEngine.h"
26 #include <aros/debug.h>
28 #if (__VMS_VER < 70000000)
29 extern "C" int unlink(char *filename
);
33 //------------------------------------------------------------------------
35 static void fileWrite(void *stream
, char *data
, int len
) {
36 fwrite(data
, 1, len
, (FILE *)stream
);
39 //------------------------------------------------------------------------
41 //------------------------------------------------------------------------
43 SplashFTFontEngine::SplashFTFontEngine(GBool aaA
, FT_Library libA
) {
44 FT_Int major
, minor
, patch
;
49 // as of FT 2.1.8, CID fonts are indexed by CID instead of GID
50 FT_Library_Version(lib
, &major
, &minor
, &patch
);
51 useCIDs
= major
> 2 ||
52 (major
== 2 && (minor
> 1 || (minor
== 1 && patch
> 7)));
55 SplashFTFontEngine
*SplashFTFontEngine::init(GBool aaA
) {
58 if (FT_Init_FreeType(&libA
)) {
61 return new SplashFTFontEngine(aaA
, libA
);
64 SplashFTFontEngine::~SplashFTFontEngine() {
65 FT_Done_FreeType(lib
);
68 SplashFontFile
*SplashFTFontEngine::loadType1Font(SplashFontFileID
*idA
,
72 return SplashFTFontFile::loadType1Font(this, idA
, fileName
, deleteFile
, enc
);
75 SplashFontFile
*SplashFTFontEngine::loadType1CFont(SplashFontFileID
*idA
,
79 return SplashFTFontFile::loadType1Font(this, idA
, fileName
, deleteFile
, enc
);
82 SplashFontFile
*SplashFTFontEngine::loadOpenTypeT1CFont(SplashFontFileID
*idA
,
86 return SplashFTFontFile::loadType1Font(this, idA
, fileName
, deleteFile
, enc
);
89 SplashFontFile
*SplashFTFontEngine::loadCIDFont(SplashFontFileID
*idA
,
97 // check for a CFF font
101 } else if ((ff
= FoFiType1C::load(fileName
))) {
102 cidToGIDMap
= ff
->getCIDToGIDMap(&nCIDs
);
108 ret
= SplashFTFontFile::loadCIDFont(this, idA
, fileName
, deleteFile
,
116 SplashFontFile
*SplashFTFontEngine::loadOpenTypeCFFFont(SplashFontFileID
*idA
,
121 Gushort
*cidToGIDMap
;
129 if ((ff
= FoFiTrueType::load(fileName
))) {
130 if (ff
->isOpenTypeCFF()) {
131 cidToGIDMap
= ff
->getCIDToGIDMap(&nCIDs
);
136 ret
= SplashFTFontFile::loadCIDFont(this, idA
, fileName
, deleteFile
,
144 SplashFontFile
*SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID
*idA
,
150 GString
*tmpFileName
;
154 if (!(ff
= FoFiTrueType::load(fileName
))) {
158 if (!openTempFile(&tmpFileName
, &tmpFile
, "wb", NULL
)) {
162 ff
->writeTTF(&fileWrite
, tmpFile
);
165 ret
= SplashFTFontFile::loadTrueTypeFont(this, idA
,
166 tmpFileName
->getCString(),
167 gTrue
, codeToGID
, codeToGIDLen
);
173 unlink(tmpFileName
->getCString());
179 #endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H