SplashFTFontFile.cc 4.02 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6
//========================================================================
//
// SplashFTFontFile.cc
//
//========================================================================

7 8 9 10
//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
11 12 13
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
14
// Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
15
// Copyright (C) 2014, 2017 Adrian Johnson <ajohnson@redneon.com>
Albert Astals Cid's avatar
Albert Astals Cid committed
16
// Copyright (C) 2017, 2018 Oliver Sander <oliver.sander@tu-dresden.de>
17
// Copyright (C) 2018 Albert Astals Cid <aacid@kde.org>
18 19 20 21 22 23
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================

Kristian Høgsberg's avatar
Kristian Høgsberg committed
24 25 26
#include <config.h>

#include "goo/gmem.h"
27
#include "goo/GooString.h"
28
#include "poppler/GfxFont.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
29 30 31 32 33 34 35 36 37 38
#include "SplashFTFontEngine.h"
#include "SplashFTFont.h"
#include "SplashFTFontFile.h"

//------------------------------------------------------------------------
// SplashFTFontFile
//------------------------------------------------------------------------

SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA,
						SplashFontFileID *idA,
39
						SplashFontSrc *src,
40
						const char **encA) {
Kristian Høgsberg's avatar
Kristian Høgsberg committed
41
  FT_Face faceA;
42
  int *codeToGIDA;
43
  const char *name;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
44 45
  int i;

46
  if (src->isFile) {
47
    if (FT_New_Face(engineA->lib, src->fileName->c_str(), 0, &faceA))
48
      return nullptr;
49 50
  } else {
    if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
51
      return nullptr;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
52
  }
53
  codeToGIDA = (int *)gmallocn(256, sizeof(int));
Kristian Høgsberg's avatar
Kristian Høgsberg committed
54 55 56
  for (i = 0; i < 256; ++i) {
    codeToGIDA[i] = 0;
    if ((name = encA[i])) {
57
      codeToGIDA[i] = (int)FT_Get_Name_Index(faceA, (char *)name);
58 59 60 61 62 63
      if (codeToGIDA[i] == 0) {
	name = GfxFont::getAlternateName(name);
	if (name) {
	  codeToGIDA[i] = FT_Get_Name_Index(faceA, (char *)name);
	}
      }
Kristian Høgsberg's avatar
Kristian Høgsberg committed
64 65 66
    }
  }

67
  return new SplashFTFontFile(engineA, idA, src,
68
			      faceA, codeToGIDA, 256, false, true);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
69 70 71 72
}

SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA,
					      SplashFontFileID *idA,
73
					      SplashFontSrc *src,
74
					      int *codeToGIDA,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
75 76 77
					      int codeToGIDLenA) {
  FT_Face faceA;

78
  if (src->isFile) {
79
    if (FT_New_Face(engineA->lib, src->fileName->c_str(), 0, &faceA))
80
      return nullptr;
81 82
  } else {
    if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
83
      return nullptr;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
84 85
  }

86
  return new SplashFTFontFile(engineA, idA, src,
87
			      faceA, codeToGIDA, codeToGIDLenA, false, false);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
88 89 90 91
}

SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA,
						   SplashFontFileID *idA,
92
						   SplashFontSrc *src,
93
						   int *codeToGIDA,
94 95
						   int codeToGIDLenA,
						   int faceIndexA) {
Kristian Høgsberg's avatar
Kristian Høgsberg committed
96 97
  FT_Face faceA;

98
  if (src->isFile) {
99
    if (FT_New_Face(engineA->lib, src->fileName->c_str(), faceIndexA, &faceA))
100
      return nullptr;
101 102
  } else {
    if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, faceIndexA, &faceA))
103
      return nullptr;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
104 105
  }

106
  return new SplashFTFontFile(engineA, idA, src,
107
			      faceA, codeToGIDA, codeToGIDLenA, true, false);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
108 109 110 111
}

SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA,
				   SplashFontFileID *idA,
112
				   SplashFontSrc *srcA,
Kristian Høgsberg's avatar
Kristian Høgsberg committed
113
				   FT_Face faceA,
114
				   int *codeToGIDA, int codeToGIDLenA,
115
				   bool trueTypeA, bool type1A):
116
  SplashFontFile(idA, srcA)
Kristian Høgsberg's avatar
Kristian Høgsberg committed
117 118 119 120 121
{
  engine = engineA;
  face = faceA;
  codeToGID = codeToGIDA;
  codeToGIDLen = codeToGIDLenA;
122
  trueType = trueTypeA;
123
  type1 = type1A;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
124 125 126 127 128 129 130 131 132 133 134
}

SplashFTFontFile::~SplashFTFontFile() {
  if (face) {
    FT_Done_Face(face);
  }
  if (codeToGID) {
    gfree(codeToGID);
  }
}

135
SplashFont *SplashFTFontFile::makeFont(SplashCoord *mat,
136
				       const SplashCoord *textMat) {
Kristian Høgsberg's avatar
Kristian Høgsberg committed
137 138
  SplashFont *font;

139
  font = new SplashFTFont(this, mat, textMat);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
140 141 142
  font->initCache();
  return font;
}