Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 19396 → Rev 19395

/trunk/Scribus/scribus/fonts/ftface.h
85,10 → 85,7
// GlyphMetrics glyphBBox (uint gl, qreal sz) const;
 
void RawData (QByteArray & bb) const;
 
static QString adobeGlyphName(FT_ULong charcode);
virtual bool glyphNames(QMap<uint, std::pair<QChar, QString> >& GList) const;
 
bool glyphNames(QMap<uint, std::pair<QChar, QString> >& GList) const;
void load () const;
void unload () const;
void loadGlyph (uint ch) const;
/trunk/Scribus/scribus/fonts/scface.cpp
24,7 → 24,7
subset(false),
isStroked(false),
isFixedPitch(false),
hasGlyphNames(false),
hasNames(false),
maxGlyph(0),
cachedStatus(ScFace::UNKNOWN)
{
/trunk/Scribus/scribus/fonts/scface.h
121,7 → 121,7
 
bool isStroked;
bool isFixedPitch;
bool hasGlyphNames;
bool hasNames;
uint maxGlyph;
 
ScFaceData();
179,8 → 179,6
virtual GlyphMetrics glyphBBox(uint gl, qreal sz) const;
virtual bool EmbedFont(QString &/*str*/) const { return false; }
virtual void RawData(QByteArray & /*bb*/) const {}
 
virtual bool hasNames() const { return hasGlyphNames; }
virtual bool glyphNames(QMap<uint, std::pair<QChar, QString> >& gList) const;
 
// these use the cache:
289,7 → 287,7
void subset(bool flag) { m->subset = flag; }
 
/// deprecated? tells if the face has PS names
bool hasNames() const { return m->hasNames(); }
bool hasNames() const { return m->hasNames; }
 
/// tells if this font is an outline font
bool isStroked() const { return m->isStroked; }
/trunk/Scribus/scribus/fonts/scface_ttf.cpp
530,52 → 530,6
return FtFace::glyphKerning ( gl1, gl2, sz );
}
 
bool ScFace_ttf::hasNames() const
{
FT_Face face = ftFace();
if (!face)
return false;
 
// The glyph name table embedded in Truetype fonts is not reliable.
// For those fonts we consequently use Adobe Glyph names whenever possible.
const bool avoidFntNames = (formatCode != ScFace::TYPE42 && typeCode == ScFace::TTF) &&
(face->charmap && face->charmap->encoding == FT_ENCODING_UNICODE);
if (avoidFntNames)
return true; // We use Adobe 'uniXXXX' names in such case
 
return FtFace::hasNames();
}
 
bool ScFace_ttf::glyphNames(QMap<uint, std::pair<QChar, QString> >& GList) const
{
char buf[50];
FT_ULong charcode;
FT_UInt gindex = 0;
 
FT_Face face = ftFace();
if (!face)
return false;
// The glyph name table embedded in Truetype fonts is not reliable.
// For those fonts we consequently use Adobe Glyph names whenever possible.
const bool avoidFntNames = (formatCode != ScFace::TYPE42 && typeCode == ScFace::TTF) &&
(face->charmap && face->charmap->encoding == FT_ENCODING_UNICODE);
if (!avoidFntNames)
return FtFace::glyphNames(GList);
 
const bool hasPSNames = FT_HAS_GLYPH_NAMES(face);
// qDebug() << "reading metrics for" << face->family_name << face->style_name;
charcode = FT_Get_First_Char(face, &gindex);
while (gindex != 0)
{
GList.insert(gindex, std::make_pair(QChar(static_cast<uint>(charcode)), adobeGlyphName(charcode)));
charcode = FT_Get_Next_Char(face, charcode, &gindex );
}
 
return true;
}
 
void ScFace_ttf::RawData(QByteArray & bb) const {
if (formatCode == ScFace::TTCF) {
QByteArray coll;
/trunk/Scribus/scribus/fonts/scface_ttf.h
97,9 → 97,7
void RawData(QByteArray & bb) const;
 
qreal glyphKerning ( uint gl1, uint gl2, qreal sz ) const;
virtual bool glyphNames(QMap<uint, std::pair<QChar, QString> >& GList) const;
virtual bool hasNames() const;
 
virtual bool isSymbolic() const;
 
private:
/trunk/Scribus/scribus/fonts/scfontmetrics.cpp
368,6 → 368,8
if (FT_Get_Glyph_Name(face, gindex, &buf, 50))
continue;
QString glyphname(reinterpret_cast<char*>(buf));
if (avoidFntNames && buf[0] != '.' && buf[0] != '\0')
glyphname = adobeGlyphName(charcode);
 
charcode = 0;
QMap<uint,std::pair<QChar,QString> >::Iterator gli;
380,8 → 382,6
}
}
// qDebug() << "\tmore: " << gindex << " '" << charcode << "' --> '" << buf << "'";
if (avoidFntNames && buf[0] != '.' && buf[0] != '\0')
glyphname = adobeGlyphName(charcode);
GList.insert(gindex, std::make_pair(QChar(static_cast<uint>(charcode)), glyphname));
}
 
/trunk/Scribus/scribus/fonts/ftface.cpp
305,85 → 305,10
return error;
}
 
QString FtFace::adobeGlyphName(FT_ULong charcode)
{
static const char HEX[] = "0123456789ABCDEF";
QString result;
if (charcode < 0x10000) {
result = QString("uni") + HEX[charcode>>12 & 0xF]
+ HEX[charcode>> 8 & 0xF]
+ HEX[charcode>> 4 & 0xF]
+ HEX[charcode & 0xF];
}
else {
result = QString("u");
for (int i= 28; i >= 0; i-=4) {
if (charcode & (0xF << i))
result += HEX[charcode >> i & 0xF];
}
}
return result;
}
 
bool FtFace::glyphNames(QMap<uint, std::pair<QChar, QString> >& GList) const
{
char buf[50];
FT_ULong charcode;
FT_UInt gindex = 0;
 
FT_Face face = ftFace();
if (!face)
return false;
const bool hasPSNames = FT_HAS_GLYPH_NAMES(face);
// qDebug() << "reading metrics for" << face->family_name << face->style_name;
charcode = FT_Get_First_Char(face, &gindex );
while (gindex != 0)
{
bool notfound = true;
if (hasPSNames)
notfound = FT_Get_Glyph_Name(face, gindex, &buf, 50);
 
// just in case FT gives empty string or ".notdef"
// no valid glyphname except ".notdef" starts with '.'
// qDebug() << "\t" << gindex << " '" << charcode << "' --> '" << (notfound? "notfound" : buf) << "'";
if (notfound || buf[0] == '\0' || buf[0] == '.')
GList.insert(gindex, std::make_pair(QChar(static_cast<uint>(charcode)), adobeGlyphName(charcode)));
else
GList.insert(gindex, std::make_pair(QChar(static_cast<uint>(charcode)), QString(reinterpret_cast<char*>(buf))));
 
charcode = FT_Get_Next_Char(face, charcode, &gindex );
}
 
if (!hasPSNames)
return true;
 
// Let's see if we can find some more...
int maxSlot1 = face->num_glyphs;
for (int gindex = 1; gindex < maxSlot1; ++gindex)
{
if (GList.contains(gindex))
continue;
if (FT_Get_Glyph_Name(face, gindex, &buf, 50))
continue;
QString glyphname(reinterpret_cast<char*>(buf));
 
charcode = 0;
QMap<uint,std::pair<QChar,QString> >::Iterator gli;
for (gli = GList.begin(); gli != GList.end(); ++gli)
{
if (glyphname == gli.value().second)
{
charcode = gli.value().first.unicode();
break;
}
}
// qDebug() << "\tmore: " << gindex << " '" << charcode << "' --> '" << buf << "'";
GList.insert(gindex, std::make_pair(QChar(static_cast<uint>(charcode)), glyphname));
}
 
return true;
return GlyphNames(*this, GList);
}
 
 
/trunk/Scribus/scribus/scfonts.cpp
432,7 → 432,7
/* catching any types not handled above to silence compiler */
break;
}
t.m->hasGlyphNames = HasNames;
t.m->hasNames = HasNames;
t.embedPs(true);
t.usable(true);
t.m->status = ScFace::UNKNOWN;
661,7 → 661,7
break;
}
insert(ts,t);
t.m->hasGlyphNames = HasNames;
t.m->hasNames = HasNames;
t.embedPs(true);
t.usable(true);
t.m->status = ScFace::UNKNOWN;