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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#ifndef SCFACE_PS_H
#define SCFACE_PS_H
#include <QString>
#include <QStringList>
#include <QFont>
#include <QMap>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#include FT_GLYPH_H
#include "scribusapi.h"
#include "fpointarray.h"
#include "scconfig.h"
/*
Class ScFace_postscript
Subclass of ScFace, for PostScript fonts that could possibly have a .afm file
associated with them for metrics information.
*/
class ScFace_postscript : public FtFace
{
public:
ScFace_postscript(QString fam, QString sty, QString alt, QString scname, QString psname, QString path, int face) :
FtFace(fam,sty,alt,scname,psname,path,face)
{
isFixedPitch = false;
typeCode = ScFace::TYPE1;
}
virtual QStringList findFontMetrics(const QString& fontPath) const;
virtual QStringList findFontMetrics(const QString& baseDir, const QString& baseName) const;
virtual bool loadFontMetrics(FT_Face face, const QString& fontPath) const;
virtual void load() const // routine by Franz Schmid - modified by Alastair M. Robinson
{
FtFace::load();
// bool error;
FT_Face face = ftFace();
if (!face)
{
const_cast<ScFace_postscript*>(this)->usable = false;
qDebug("%s", QObject::tr("Font %1 is broken (no Face), discarding it").arg(fontFile).toLocal8Bit().constData());
return;
}
if (loadFontMetrics(face, fontFile))
{
// re-initialize: ScFaceData::load() just clears caches,
// FtFace::load() skips FT_New_Face if m_face is already defined.
// dont mind checking glyphs again for now (PS files have only 255 glyphs max, anyway)
FtFace::load();
}
// Ascent = tmp.setNum(face->ascender);
// Descender = tmp.setNum(face->descender);
// CapHeight = Ascent;
// ItalicAngle = "0";
// StdVW = "1";
// FontBBox = tmp.setNum(face->bbox.xMin)+" "+tmp2.setNum(face->bbox.yMin)+" "+tmp3.setNum(face->bbox.xMax)+" "+tmp4.setNum(face->bbox.yMax);
/*
setBestEncoding(face);
gindex = 0;
charcode = FT_Get_First_Char( face, &gindex );
int goodGlyph = 0;
int invalidGlyph = 0;
while ( gindex != 0 )
{
error = FT_Load_Glyph( face, gindex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP );
if (error)
{
++invalidGlyph;
sDebug(QObject::tr("Font %1 has broken glyph %2 (charcode %3)").arg(fontPath()).arg(gindex).arg(charcode));
charcode = FT_Get_Next_Char( face, charcode, &gindex );
continue;
}
++goodGlyph;
qreal ww = face->glyph->metrics.horiAdvance / uniEM;
if (face->glyph->format == FT_GLYPH_FORMAT_PLOTTER)
isStroked = true;
error = false;
outlines = traceChar(face, charcode, 10, &x, &y, &error);
if (!error)
{
CharWidth.insert(charcode, ww);
GRec.Outlines = outlines.copy();
GRec.x = x;
GRec.y = y;
GlyphArray.insert(charcode, GRec);
}
charcode = FT_Get_Next_Char( face, charcode, &gindex );
}
*/
}
};
/*
Class ScFace_pfb
Subclass of ScFace, specifically for Adobe type 1 .pfb fonts.
Implements: RealName() and EmbedFont().
*/
class ScFace_pfb : public ScFace_postscript
{
public:
ScFace_pfb(QString fam, QString sty, QString alt, QString scname, QString psname, QString path, int face) :
ScFace_postscript(fam,sty,alt,scname,psname,path,face)
{
formatCode = ScFace::PFB;
}
virtual bool EmbedFont(QString &str) const
{
QByteArray bb;
RawData(bb);
QString tmp2 = "";
if ((bb.size() > 2) && (bb[0] == char(0x80)) && (static_cast<int>(bb[1]) == 1))
{
QString tmp3="";
QString tmp4 = "";
int posi,cxxc=0;
for (posi = 6; posi < bb.size(); ++posi)
{
if ((bb[posi] == char(0x80)) && (posi+1 < bb.size()) && (static_cast<int>(bb[posi+1]) == 2))
break;
str += bb[posi];
}
int ulen;
if (posi+6 < bb.size())
{
ulen = bb[posi+2] & 0xff;
ulen |= (bb[posi+3] << 8) & 0xff00;
ulen |= (bb[posi+4] << 16) & 0xff0000;
ulen |= (bb[posi+5] << 24) & 0xff000000;
posi += 6;
if (posi + ulen > bb.size())
ulen = bb.size() - posi - 1;
char linebuf[80];
cxxc=0;
for (int j = 0; j < ulen; ++j)
{
unsigned char u=bb[posi];
linebuf[cxxc]=((u >> 4) & 15) + '0';
if(u>0x9f) linebuf[cxxc]+='a'-':';
++cxxc;
u&=15; linebuf[cxxc]=u + '0';
if(u>0x9) linebuf[cxxc]+='a'-':';
++posi;
++cxxc;
if (cxxc > 72)
{
linebuf[cxxc++]='\n';
linebuf[cxxc++]=0;
str += linebuf;
cxxc = 0;
}
}
linebuf[cxxc]=0;
str += linebuf;
str += "\n";
}
posi += 6;
for (int j = posi; j < bb.size(); ++j)
{
if ((bb[j] == static_cast<char>(0x80)) && (j+1 < bb.size()) && (static_cast<int>(bb[j+1]) == 3))
break;
if(bb[j]=='\r')
str+="\n";
else
str += bb[j];
}
str += "\n";
cxxc = 0;
return true;
}
else
{
qDebug("%s", QObject::tr("Font %1 cannot be read, no embedding").arg(fontFile).toLatin1().constData());
return false;
}
}
};
/*
Class ScFace_pfa
Subclass of ScFace, specifically for Adobe type 1 and type 3 .pfa fonts.
Implements: RealName() and EmbedFont().
*/
class ScFace_pfa : public ScFace_postscript
{
public:
ScFace_pfa(QString fam, QString sty, QString alt, QString scname, QString psname, QString path, int face) :
ScFace_postscript(fam,sty,alt,scname,psname,path,face)
{
formatCode = ScFace::PFA;
}
virtual bool EmbedFont(QString &str) const
{
QByteArray bb;
RawData(bb);
if (bb.size() > 2 && bb[0] == '%' && bb[1] == '!')
{
// this is ok since bb will not contain '\0'
str.append(bb);
return true;
}
qDebug("%s", QObject::tr("Font %1 cannot be read, no embedding").arg(fontFile).toLatin1().constData());
return false;
}
};
#endif
|