Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QFontSubset Class Reference

#include <qfontsubset_p.h>

Public Functions

int addGlyph (int index)
 
QByteArray createToUnicodeMap () const
 
QVector< int > getReverseMap () const
 
QByteArray glyphName (unsigned int glyph, const QVector< int > reverseMap) const
 
int nGlyphs () const
 
 QFontSubset (QFontEngine *fe, int obj_id=0)
 
QByteArray toTruetype () const
 
QByteArray toType1 () const
 
QByteArray type1AddedGlyphs () const
 
QByteArray widthArray () const
 
 ~QFontSubset ()
 

Static Public Functions

static QByteArray glyphName (unsigned short unicode, bool symbol)
 

Public Variables

int downloaded_glyphs
 
QFixed emSquare
 
QFontEnginefontEngine
 
QList< int > glyph_indices
 
bool noEmbed
 
const int object_id
 
bool standard_font
 
QVector< QFixedwidths
 

Detailed Description

Definition at line 62 of file qfontsubset_p.h.

Constructors and Destructors

◆ QFontSubset()

QFontSubset::QFontSubset ( QFontEngine fe,
int  obj_id = 0 
)
inline

Definition at line 65 of file qfontsubset_p.h.

66  : object_id(obj_id), noEmbed(false), fontEngine(fe), downloaded_glyphs(0), standard_font(false)
67  { fontEngine->ref.ref(); addGlyph(0); }
QAtomicInt ref
int addGlyph(int index)
bool ref()
Atomically increments the value of this QAtomicInt.
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
int downloaded_glyphs
Definition: qfontsubset_p.h:88
bool standard_font
Definition: qfontsubset_p.h:89
const int object_id
Definition: qfontsubset_p.h:84

◆ ~QFontSubset()

QFontSubset::~QFontSubset ( )
inline

Definition at line 68 of file qfontsubset_p.h.

68  {
69  if (!fontEngine->ref.deref())
70  delete fontEngine;
71  }
QAtomicInt ref
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
bool deref()
Atomically decrements the value of this QAtomicInt.

Functions

◆ addGlyph()

int QFontSubset::addGlyph ( int  index)

Definition at line 531 of file qfontsubset.cpp.

Referenced by QPdfBaseEnginePrivate::drawTextItem(), QFontSubset(), and ~QFontSubset().

532 {
533  int idx = glyph_indices.indexOf(index);
534  if (idx < 0) {
535  idx = glyph_indices.size();
537  }
538  return idx;
539 }
QList< int > glyph_indices
Definition: qfontsubset_p.h:87
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
quint16 index

◆ createToUnicodeMap()

QByteArray QFontSubset::createToUnicodeMap ( ) const

Definition at line 439 of file qfontsubset.cpp.

Referenced by QPdfEnginePrivate::embedFont(), and ~QFontSubset().

440 {
441  QVector<int> reverseMap = getReverseMap();
442 
443  QByteArray touc;
444  QPdf::ByteStream ts(&touc);
445  ts << "/CIDInit /ProcSet findresource begin\n"
446  "12 dict begin\n"
447  "begincmap\n"
448  "/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n"
449  "/CMapName /Adobe-Identity-UCS def\n"
450  "/CMapType 2 def\n"
451  "1 begincodespacerange\n"
452  "<0000> <FFFF>\n"
453  "endcodespacerange\n";
454 
455  int nranges = 1;
456  QByteArray ranges = "<0000> <0000> <0000>\n";
457  QPdf::ByteStream s(&ranges);
458 
459  char buf[5];
460  for (int g = 1; g < nGlyphs(); ) {
461  int uc0 = reverseMap.at(g);
462  if (!uc0) {
463  ++g;
464  continue;
465  }
466  int start = g;
467  int startLinear = 0;
468  ++g;
469  while (g < nGlyphs()) {
470  int uc = reverseMap[g];
471  // cmaps can't have the high byte changing within one range, so we need to break on that as well
472  if (!uc || (g>>8) != (start >> 8))
473  break;
474  if (uc == uc0 + 1) {
475  if (!startLinear)
476  startLinear = g - 1;
477  } else {
478  if (startLinear > 0 && g - startLinear >= 10)
479  break;
480  startLinear = 0;
481  }
482  uc0 = uc;
483  ++g;
484  }
485  // qDebug("start=%x startLinear=%x g-1=%x",start,startLinear,g-1);
486  if (g - startLinear < 10)
487  startLinear = 0;
488  int endnonlinear = startLinear ? startLinear : g;
489  // qDebug(" startLinear=%x endnonlinear=%x", startLinear,endnonlinear);
490  if (endnonlinear > start) {
491  s << '<' << QPdf::toHex((ushort)start, buf) << "> <";
492  s << QPdf::toHex((ushort)(endnonlinear - 1), buf) << "> ";
493  if (endnonlinear == start + 1) {
494  s << '<' << QPdf::toHex((ushort)reverseMap[start], buf) << ">\n";
495  } else {
496  s << '[';
497  for (int i = start; i < endnonlinear; ++i) {
498  s << '<' << QPdf::toHex((ushort)reverseMap[i], buf) << "> ";
499  }
500  s << "]\n";
501  }
502  checkRanges(ts, ranges, nranges);
503  }
504  if (startLinear) {
505  while (startLinear < g) {
506  int len = g - startLinear;
507  int uc_start = reverseMap[startLinear];
508  int uc_end = uc_start + len - 1;
509  if ((uc_end >> 8) != (uc_start >> 8))
510  len = 256 - (uc_start & 0xff);
511  s << '<' << QPdf::toHex((ushort)startLinear, buf) << "> <";
512  s << QPdf::toHex((ushort)(startLinear + len - 1), buf) << "> ";
513  s << '<' << QPdf::toHex((ushort)reverseMap[startLinear], buf) << ">\n";
514  checkRanges(ts, ranges, nranges);
515  startLinear += len;
516  }
517  }
518  }
519  if (nranges) {
520  ts << nranges << "beginbfrange\n"
521  << ranges << "endbfrange\n";
522  }
523  ts << "endcmap\n"
524  "CMapName currentdict /CMap defineresource pop\n"
525  "end\n"
526  "end\n";
527 
528  return touc;
529 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
const char * toHex(ushort u, char *buffer)
Definition: qpdf.cpp:862
unsigned short ushort
Definition: qglobal.h:995
int nGlyphs() const
Definition: qfontsubset_p.h:90
static void checkRanges(QPdf::ByteStream &ts, QByteArray &ranges, int &nranges)
QVector< int > getReverseMap() const

◆ getReverseMap()

QVector< int > QFontSubset::getReverseMap ( ) const

Definition at line 421 of file qfontsubset.cpp.

Referenced by createToUnicodeMap(), toType1(), type1AddedGlyphs(), and ~QFontSubset().

422 {
423  QVector<int> reverseMap;
424  reverseMap.resize(0x10000);
425  for (uint i = 0; i < 0x10000; ++i)
426  reverseMap[i] = 0;
427  QGlyphLayoutArray<10> glyphs;
428  for (uint uc = 0; uc < 0x10000; ++uc) {
429  QChar ch(uc);
430  int nglyphs = 10;
431  fontEngine->stringToCMap(&ch, 1, &glyphs, &nglyphs, QTextEngine::GlyphIndicesOnly);
432  int idx = glyph_indices.indexOf(glyphs.glyphs[0]);
433  if (idx >= 0 && !reverseMap.at(idx))
434  reverseMap[idx] = uc;
435  }
436  return reverseMap;
437 }
HB_Glyph * glyphs
QList< int > glyph_indices
Definition: qfontsubset_p.h:87
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
virtual bool stringToCMap(const QChar *str, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const =0
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
unsigned int uint
Definition: qglobal.h:996
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847

◆ glyphName() [1/2]

QByteArray QFontSubset::glyphName ( unsigned int  glyph,
const QVector< int >  reverseMap 
) const

Definition at line 312 of file qfontsubset.cpp.

Referenced by type1AddedGlyphs(), and ~QFontSubset().

313 {
314  uint glyphIndex = glyph_indices[glyph];
315 
316  if (glyphIndex == 0)
317  return "/.notdef";
318 
319  QByteArray ba;
320  QPdf::ByteStream s(&ba);
321 #ifndef QT_NO_FREETYPE
322  FT_Face face = ft_face(fontEngine);
323 
324  char name[32];
325  name[0] = 0;
326  if (face && FT_HAS_GLYPH_NAMES(face)) {
327 #if defined(Q_WS_X11)
329  glyphIndex = static_cast<QFontEngineXLFD *>(fontEngine)->glyphIndexToFreetypeGlyphIndex(glyphIndex);
330 #endif
331  FT_Get_Glyph_Name(face, glyphIndex, &name, 32);
332  if (name[0] == '.') // fix broken PS fonts returning .notdef for many glyphs
333  name[0] = 0;
334  }
335  if (name[0]) {
336  s << '/' << name;
337  } else
338 #endif
339 #if defined(Q_WS_X11)
340  if (fontEngine->type() == QFontEngine::XLFD) {
341  uint uc = static_cast<QFontEngineXLFD *>(fontEngine)->toUnicode(glyphIndex);
342  s << '/' << glyphName(uc, false /* ### */);
343  } else
344 #endif
345  if (reverseMap[glyphIndex] && reverseMap[glyphIndex] < 0x10000) {
346  s << '/' << glyphName(reverseMap[glyphIndex], false);
347  } else {
348  s << "/gl" << (int)glyphIndex;
349  }
350  return ba;
351 }
static FT_Face ft_face(const QFontEngine *engine)
QList< int > glyph_indices
Definition: qfontsubset_p.h:87
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
QByteArray glyphName(unsigned int glyph, const QVector< int > reverseMap) const
virtual Type type() const =0
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50
const char * name
unsigned int uint
Definition: qglobal.h:996
static QString toUnicode(QTextCodec *tc, const char *str)
Definition: qsql_mysql.cpp:95

◆ glyphName() [2/2]

QByteArray QFontSubset::glyphName ( unsigned short  unicode,
bool  symbol 
)
static

Definition at line 267 of file qfontsubset.cpp.

268 {
269  if (symbol && unicode < 0x100)
270  // map from latin1 to symbol
271  unicode = symbol_map[unicode];
272 
273  int l = 0;
274  while(unicode_to_aglindex[l].u < unicode)
275  l++;
276  if (unicode_to_aglindex[l].u == unicode)
277  return agl + unicode_to_aglindex[l].index;
278 
279  char buffer[8];
280  buffer[0] = 'u';
281  buffer[1] = 'n';
282  buffer[2] = 'i';
283  QPdf::toHex(unicode, buffer+3);
284  return buffer;
285 }
static const unsigned short symbol_map[0x100]
static const struct @277 unicode_to_aglindex[]
quint16 u
const char * toHex(ushort u, char *buffer)
Definition: qpdf.cpp:862
QFactoryLoader * l
static const char *const agl
Definition: qfontsubset.cpp:64

◆ nGlyphs()

int QFontSubset::nGlyphs ( ) const
inline

Definition at line 90 of file qfontsubset_p.h.

Referenced by createToUnicodeMap(), generateGlyphTables(), toTruetype(), type1AddedGlyphs(), and widthArray().

90 { return glyph_indices.size(); }
QList< int > glyph_indices
Definition: qfontsubset_p.h:87
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ toTruetype()

QByteArray QFontSubset::toTruetype ( ) const

Definition at line 1385 of file qfontsubset.cpp.

Referenced by QPdfEnginePrivate::embedFont(), and ~QFontSubset().

1386 {
1387  qttf_font_tables font;
1388  memset(&font, 0, sizeof(qttf_font_tables));
1389 
1391 #define TO_TTF(x) qRound(x * 2048. / ppem)
1392  QList<QTtfGlyph> glyphs;
1393 
1395  // initialize some stuff needed in createWidthArray
1396  emSquare = 2048;
1397  widths.resize(nGlyphs());
1398 
1399  // head table
1400  font.head.font_revision = 0x00010000;
1401  font.head.flags = (1 << 2) | (1 << 4);
1402  font.head.created = 0; // ###
1403  font.head.modified = 0; // ###
1404  font.head.xMin = SHRT_MAX;
1405  font.head.xMax = SHRT_MIN;
1406  font.head.yMin = SHRT_MAX;
1407  font.head.yMax = SHRT_MIN;
1408  font.head.macStyle = (fontEngine->fontDef.weight > QFont::Normal) ? 1 : 0;
1410 
1411  // hhea table
1412  font.hhea.ascender = qRound(properties.ascent);
1413  font.hhea.descender = -qRound(properties.descent);
1414  font.hhea.lineGap = qRound(properties.leading);
1418  font.hhea.xMaxExtent = SHRT_MIN;
1419 
1420  font.maxp.numGlyphs = 0;
1421  font.maxp.maxPoints = 0;
1422  font.maxp.maxContours = 0;
1423  font.maxp.maxCompositePoints = 0;
1424  font.maxp.maxCompositeContours = 0;
1425  font.maxp.maxComponentElements = 0;
1426  font.maxp.maxComponentDepth = 0;
1427  font.maxp.numGlyphs = nGlyphs();
1428 
1429 
1430 
1431  uint sumAdvances = 0;
1432  for (int i = 0; i < nGlyphs(); ++i) {
1433  glyph_t g = glyph_indices.at(i);
1434  QPainterPath path;
1435  glyph_metrics_t metric;
1436  fontEngine->getUnscaledGlyph(g, &path, &metric);
1437  if (noEmbed) {
1438  path = QPainterPath();
1439  if (g == 0)
1440  path.addRect(QRectF(0, 0, 1000, 1000));
1441  }
1442  QTtfGlyph glyph = generateGlyph(i, path, metric.xoff.toReal(), metric.x.toReal(), properties.emSquare.toReal());
1443 
1444  font.head.xMin = qMin(font.head.xMin, glyph.xMin);
1445  font.head.xMax = qMax(font.head.xMax, glyph.xMax);
1446  font.head.yMin = qMin(font.head.yMin, glyph.yMin);
1447  font.head.yMax = qMax(font.head.yMax, glyph.yMax);
1448 
1449  font.hhea.xMaxExtent = qMax(font.hhea.xMaxExtent, (qint16)(glyph.lsb + glyph.xMax - glyph.xMin));
1450 
1451  font.maxp.maxPoints = qMax(font.maxp.maxPoints, glyph.numPoints);
1452  font.maxp.maxContours = qMax(font.maxp.maxContours, glyph.numContours);
1453 
1454  if (glyph.xMax > glyph.xMin)
1455  sumAdvances += glyph.xMax - glyph.xMin;
1456 
1457 // qDebug("adding glyph %d size=%d", glyph.index, glyph.data.size());
1458  glyphs.append(glyph);
1459  widths[i] = glyph.advanceWidth;
1460  }
1461 
1462 
1463  QList<QTtfTable> tables = generateGlyphTables(font, glyphs);
1464  tables.append(generateHead(font.head));
1465  tables.append(generateHhea(font.hhea));
1466  tables.append(generateMaxp(font.maxp));
1467  // name
1468  QTtfTable name_table;
1469  name_table.tag = MAKE_TAG('n', 'a', 'm', 'e');
1470  if (!noEmbed)
1471  name_table.data = fontEngine->getSfntTable(name_table.tag);
1472  if (name_table.data.isEmpty()) {
1474  if (noEmbed)
1475  name.copyright = QLatin1String("Fake font");
1476  else
1477  name.copyright = QLatin1String(properties.copyright);
1478  name.family = fontEngine->fontDef.family;
1479  name.subfamily = QLatin1String("Regular"); // ######
1480  name.postscript_name = QLatin1String(properties.postscriptName);
1481  name_table = generateName(name);
1482  }
1483  tables.append(name_table);
1484 
1485  if (!noEmbed) {
1486  QTtfTable os2;
1487  os2.tag = MAKE_TAG('O', 'S', '/', '2');
1488  os2.data = fontEngine->getSfntTable(os2.tag);
1489  if (!os2.data.isEmpty())
1490  tables.append(os2);
1491  }
1492 
1493  return bindFont(tables);
1494 }
qint16 xMin
quint16 numPoints
qttf_head_table head
virtual qreal minRightBearing() const
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QVector< QFixed > widths
Definition: qfontsubset_p.h:92
QList< int > glyph_indices
Definition: qfontsubset_p.h:87
QString postscript_name
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
quint16 numContours
qttf_hhea_table hhea
qint16 yMax
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
static QTtfTable generateMaxp(const qttf_maxp_table &maxp)
quint16 maxComponentDepth
qint16 xMax
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
qint16 yMin
#define MAKE_TAG(ch1, ch2, ch3, ch4)
virtual qreal maxCharWidth() const =0
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QFixed emSquare
Definition: qfontsubset_p.h:91
QByteArray data
static QTtfTable generateName(const qttf_name_table &name)
static QTtfTable generateHhea(const qttf_hhea_table &hhea)
const char * name
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
short qint16
Definition: qglobal.h:935
static QTtfTable generateHead(const qttf_head_table &head)
unsigned int uint
Definition: qglobal.h:996
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
qint16 minRightSideBearing
uint weight
Definition: qfont_p.h:95
virtual qreal minLeftBearing() const
#define TO_TTF(x)
virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
quint16 maxAdvanceWidth
quint16 maxCompositePoints
qreal pixelSize
Definition: qfont_p.h:90
qint16 minLeftSideBearing
virtual Properties properties() const
static QByteArray bindFont(const QList< QTtfTable > &_tables)
int nGlyphs() const
Definition: qfontsubset_p.h:90
quint16 maxComponentElements
static QTtfGlyph generateGlyph(int index, const QPainterPath &path, qreal advance, qreal lsb, qreal ppem)
qreal toReal() const
Definition: qfixed_p.h:77
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
qttf_maxp_table maxp
qint16 lsb
QFontDef fontDef
QString family
Definition: qfont_p.h:82
quint16 maxCompositeContours
uint styleHint
Definition: qfont_p.h:93
quint16 advanceWidth
unsigned int glyph_t
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
static QList< QTtfTable > generateGlyphTables(qttf_font_tables &tables, const QList< QTtfGlyph > &_glyphs)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QByteArray getSfntTable(uint) const

◆ toType1()

QByteArray QFontSubset::toType1 ( ) const

Definition at line 1648 of file qfontsubset.cpp.

Referenced by ~QFontSubset().

1649 {
1651  QVector<int> reverseMap = getReverseMap();
1652 
1653  QByteArray font;
1654  QPdf::ByteStream s(&font);
1655 
1657  QByteArray psname = properties.postscriptName;
1658  psname.replace(' ', "");
1659 
1660  standard_font = false;
1661 
1662 #ifndef QT_NO_FREETYPE
1663  FT_Face face = ft_face(fontEngine);
1664  if (face && !FT_IS_SCALABLE(face)) {
1665  int style = 0;
1666  if (fontEngine->fontDef.style)
1667  style += 2;
1669  style++;
1670  if (fontEngine->fontDef.family.contains(QLatin1String("Helvetica"))) {
1671  psname = helvetica_styles[style];
1672  standard_font = true;
1673  } else if (fontEngine->fontDef.family.contains(QLatin1String("Times"))) {
1674  psname = times_styles[style];
1675  standard_font = true;
1676  } else if (fontEngine->fontDef.family.contains(QLatin1String("Courier"))) {
1677  psname = courier_styles[style];
1678  standard_font = true;
1679  }
1680  }
1681 #endif
1682  s << "/F" << id << "-Base\n";
1683  if (standard_font) {
1684  s << '/' << psname << " findfont\n"
1685  "0 dict copy dup /NumGlyphs 0 put dup /CMap 256 array put def\n";
1686  } else {
1687  s << "<<\n";
1688  if(!psname.isEmpty())
1689  s << "/FontName /" << psname << '\n';
1690  s << "/FontInfo <</FsType " << (int)fontEngine->fsType << ">>\n"
1691  "/FontType 1\n"
1692  "/PaintType 0\n"
1693  "/FontMatrix [.001 0 0 .001 0 0]\n"
1694  "/FontBBox { 0 0 0 0 }\n"
1695  "/Private <<\n"
1696  "/password 5839\n"
1697  "/MinFeature {16 16}\n"
1698  "/BlueValues []\n"
1699  "/lenIV -1\n"
1700  ">>\n"
1701  "/CharStrings << >>\n"
1702  "/NumGlyphs 0\n"
1703  "/CMap 256 array\n"
1704  ">> def\n";
1705  }
1706  s << type1AddedGlyphs();
1708 
1709  return font;
1710 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
static FT_Face ft_face(const QFontEngine *engine)
QList< int > glyph_indices
Definition: qfontsubset_p.h:87
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray type1AddedGlyphs() const
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
int downloaded_glyphs
Definition: qfontsubset_p.h:88
struct FT_FaceRec_ * FT_Face
Definition: qfont.h:50
static const char * courier_styles[4]
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
uint weight
Definition: qfont_p.h:95
bool standard_font
Definition: qfontsubset_p.h:89
static const char * helvetica_styles[4]
virtual Properties properties() const
uint style
Definition: qfont_p.h:97
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
QByteArray & replace(int index, int len, const char *s)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
QFontDef fontDef
QString family
Definition: qfont_p.h:82
QVector< int > getReverseMap() const
static const char * times_styles[4]
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
const int object_id
Definition: qfontsubset_p.h:84

◆ type1AddedGlyphs()

QByteArray QFontSubset::type1AddedGlyphs ( ) const

Definition at line 1712 of file qfontsubset.cpp.

Referenced by toType1(), and ~QFontSubset().

1713 {
1715  return QByteArray();
1716 
1718  QVector<int> reverseMap = getReverseMap();
1719  QByteArray glyphs;
1720  QPdf::ByteStream s(&glyphs);
1721 
1722  int nGlyphs = glyph_indices.size();
1724 
1725  s << 'F' << id << "-Base [\n";
1726  for (int i = downloaded_glyphs; i < nGlyphs; ++i) {
1727  glyph_t g = glyph_indices.at(i);
1728  QPainterPath path;
1729  glyph_metrics_t metric;
1730  fontEngine->getUnscaledGlyph(g, &path, &metric);
1731  QByteArray charstring = charString(path, metric.xoff.toReal(), metric.x.toReal(),
1732  properties.emSquare.toReal());
1733  s << glyphName(i, reverseMap);
1734  if (!standard_font)
1735  s << "\n<" << charstring << ">\n";
1736  }
1737  s << (standard_font ? "] T1AddMapping\n" : "] T1AddGlyphs\n");
1738  return glyphs;
1739 }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QList< int > glyph_indices
Definition: qfontsubset_p.h:87
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QByteArray charString(const QPainterPath &path, qreal advance, qreal lsb, qreal ppem)
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
QByteArray glyphName(unsigned int glyph, const QVector< int > reverseMap) const
int downloaded_glyphs
Definition: qfontsubset_p.h:88
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual void getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics)
bool standard_font
Definition: qfontsubset_p.h:89
virtual Properties properties() const
int nGlyphs() const
Definition: qfontsubset_p.h:90
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
qreal toReal() const
Definition: qfixed_p.h:77
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
QVector< int > getReverseMap() const
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
unsigned int glyph_t
const int object_id
Definition: qfontsubset_p.h:84

◆ widthArray()

QByteArray QFontSubset::widthArray ( ) const

Definition at line 354 of file qfontsubset.cpp.

Referenced by QPdfEnginePrivate::embedFont(), and ~QFontSubset().

355 {
356  Q_ASSERT(!widths.isEmpty());
357 
359 
360  QByteArray width;
361  QPdf::ByteStream s(&width);
362  QFixed scale = QFixed(1000)/emSquare;
363 
364  QFixed defWidth = widths[0];
365  //qDebug("defWidth=%d, scale=%f", defWidth.toInt(), scale.toReal());
366  for (int i = 0; i < nGlyphs(); ++i) {
367  if (defWidth != widths[i])
368  defWidth = 0;
369  }
370  if (defWidth > 0) {
371  s << "/DW " << (defWidth*scale).toInt();
372  } else {
373  s << "/W [";
374  for (int g = 0; g < nGlyphs();) {
375  QFixed w = widths[g];
376  int start = g;
377  int startLinear = 0;
378  ++g;
379  while (g < nGlyphs()) {
380  QFixed nw = widths[g];
381  if (nw == w) {
382  if (!startLinear)
383  startLinear = g - 1;
384  } else {
385  if (startLinear > 0 && g - startLinear >= 10)
386  break;
387  startLinear = 0;
388  }
389  w = nw;
390  ++g;
391  }
392  // qDebug("start=%x startLinear=%x g-1=%x",start,startLinear,g-1);
393  if (g - startLinear < 10)
394  startLinear = 0;
395  int endnonlinear = startLinear ? startLinear : g;
396  // qDebug(" startLinear=%x endnonlinear=%x", startLinear,endnonlinear);
397  if (endnonlinear > start) {
398  s << start << '[';
399  for (int i = start; i < endnonlinear; ++i)
400  s << (widths[i]*scale).toInt();
401  s << "]\n";
402  }
403  if (startLinear)
404  s << startLinear << g - 1 << (widths[startLinear]*scale).toInt() << '\n';
405  }
406  s << "]\n";
407  }
408  return width;
409 }
QVector< QFixed > widths
Definition: qfontsubset_p.h:92
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QFontEngine * fontEngine
Definition: qfontsubset_p.h:86
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QFixed emSquare
Definition: qfontsubset_p.h:91
static int toInt(const QByteArray &str)
Definition: generator.cpp:167
int toInt() const
Definition: qfixed_p.h:76
virtual Properties properties() const
int nGlyphs() const
Definition: qfontsubset_p.h:90
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139

Properties

◆ downloaded_glyphs

int QFontSubset::downloaded_glyphs
mutable

Definition at line 88 of file qfontsubset_p.h.

Referenced by toType1(), and type1AddedGlyphs().

◆ emSquare

QFixed QFontSubset::emSquare
mutable

Definition at line 91 of file qfontsubset_p.h.

Referenced by toTruetype(), and widthArray().

◆ fontEngine

QFontEngine* QFontSubset::fontEngine

◆ glyph_indices

QList<int> QFontSubset::glyph_indices

◆ noEmbed

bool QFontSubset::noEmbed

Definition at line 85 of file qfontsubset_p.h.

Referenced by QPdfBaseEnginePrivate::drawTextItem(), and toTruetype().

◆ object_id

const int QFontSubset::object_id

◆ standard_font

bool QFontSubset::standard_font
mutable

Definition at line 89 of file qfontsubset_p.h.

Referenced by toType1(), and type1AddedGlyphs().

◆ widths

QVector<QFixed> QFontSubset::widths
mutable

Definition at line 92 of file qfontsubset_p.h.

Referenced by toTruetype(), and widthArray().


The documentation for this class was generated from the following files: