Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Repairs the construction of CMap objects so that the mapping order … #47

Open
wants to merge 1 commit into
base: wk_4.8.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 52 additions & 13 deletions src/gui/painting/qpdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1985,40 +1985,79 @@ void QPdfBaseEnginePrivate::drawTextItem(const QPointF &p, const QTextItemInt &t
#else
qreal last_x = 0.;
qreal last_y = 0.;
QList<qreal> coordinates_x;
QList<qreal> coordinates_y;
QList<int> markerSynthesizedBold;
QList<int> glyph_indices_mirror;
int last_glyph = font->nGlyphs();
for (int i = 0; i < glyphs.size(); ++i) {
qreal x = positions[i].x.toReal();
qreal y = positions[i].y.toReal();
if (synthesized & QFontEngine::SynthesizedItalic)
x += .3*y;
x /= stretch;
char buf[5];
int g = font->addGlyph(glyphs[i]);
*currentPage << x - last_x << last_y - y << "Td <"
<< QPdf::toHex((ushort)g, buf) << "> Tj\n";
int new_index = 0;
int g = font->addGlyph(glyphs[i], new_index, last_glyph);
coordinates_x.append(x-last_x);
coordinates_y.append(last_y-y);
markerSynthesizedBold.append(0);
if (g==new_index) {
glyph_indices_mirror.append(g);
}
else {
for (int i = 0; i < glyph_indices_mirror.size(); i++) {
if (glyph_indices_mirror.at(i) >= new_index) {
glyph_indices_mirror[i]++;
}
}
glyph_indices_mirror.append(new_index);
}
last_x = x;
last_y = y;
}
if (synthesized & QFontEngine::SynthesizedBold) {
*currentPage << stretch << (synthesized & QFontEngine::SynthesizedItalic
? "0 .3 -1 0 0 Tm\n"
: "0 0 -1 0 0 Tm\n");
*currentPage << "/Span << /ActualText <> >> BDC\n";
last_x = 0.5*fe->lineThickness().toReal();
last_y = 0.;
markerSynthesizedBold.append(1);
for (int i = 0; i < glyphs.size(); ++i) {
qreal x = positions[i].x.toReal();
qreal y = positions[i].y.toReal();
if (synthesized & QFontEngine::SynthesizedItalic)
x += .3*y;
x /= stretch;
char buf[5];
int g = font->addGlyph(glyphs[i]);
*currentPage << x - last_x << last_y - y << "Td <"
<< QPdf::toHex((ushort)g, buf) << "> Tj\n";
int new_index = 0;
int g = font->addGlyph(glyphs[i], new_index, last_glyph);
coordinates_x.append(x-last_x);
coordinates_y.append(last_y-y);
markerSynthesizedBold.append(2);
if (g==new_index) {
glyph_indices_mirror.append(g);
}
else {
for (int i = 0; i < glyph_indices_mirror.size(); i++) {
if (glyph_indices_mirror.at(i) >= new_index) {
glyph_indices_mirror[i]++;
}
}
glyph_indices_mirror.append(new_index);
}
last_x = x;
last_y = y;
}
*currentPage << "EMC\n";
}
for (int i = 0; i < glyph_indices_mirror.size(); i++) {
char buf[5];
if (markerSynthesizedBold.at(i) == 1) {
*currentPage << stretch << (synthesized & QFontEngine::SynthesizedItalic
? "0 .3 -1 0 0 Tm\n"
: "0 0 -1 0 0 Tm\n");
*currentPage << "/Span << /ActualText <> >> BDC\n";
}
*currentPage << coordinates_x.at(i) << coordinates_y.at(i) << "Td <"
<< QPdf::toHex((ushort)glyph_indices_mirror.at(i), buf) << "> Tj\n";
if (markerSynthesizedBold.size() == (i+2)) {
*currentPage << "EMC\n";
}
}
#endif

Expand Down
26 changes: 26 additions & 0 deletions src/gui/text/qfontsubset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,32 @@ int QFontSubset::addGlyph(int index)
return idx;
}

int QFontSubset::addGlyph(int index, int& new_index, int begin)
{
int idx = glyph_indices.indexOf(index);
new_index = glyph_indices.indexOf(index);
if (idx < 0) {
idx = glyph_indices.size();
glyph_indices.append(index);
if (begin==1) {
qSort(glyph_indices.begin(), glyph_indices.end());
}
else {
if (begin<(glyph_indices.size()-1)) {
QList<int> aid;
for (int i=begin;i<glyph_indices.size();i++) {
aid.append(glyph_indices.at(i));
}
qSort(aid.begin(), aid.end());
for (int i=0;i<aid.size();i++) {
glyph_indices[begin+i] = aid.at(i);
}
}
}
new_index = glyph_indices.indexOf(index);
}
return idx;
}

// ------------------------------ Truetype generation ----------------------------------------------

Expand Down
6 changes: 4 additions & 2 deletions src/gui/text/qfontsubset_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class QFontSubset
{
public:
QFontSubset(QFontEngine *fe, int obj_id = 0)
: object_id(obj_id), noEmbed(false), fontEngine(fe), downloaded_glyphs(0), standard_font(false)
{ fontEngine->ref.ref(); addGlyph(0); }
: new_index(0), object_id(obj_id), noEmbed(false), fontEngine(fe), downloaded_glyphs(0), standard_font(false)
{ fontEngine->ref.ref(); addGlyph(0); addGlyph(0,new_index,1);}
~QFontSubset() {
if (!fontEngine->ref.deref() && fontEngine->cache_count == 0)
delete fontEngine;
Expand All @@ -80,7 +80,9 @@ class QFontSubset

static QByteArray glyphName(unsigned short unicode, bool symbol);

int new_index;
int addGlyph(int index);
int addGlyph(int index, int& new_index, int begin);
const int object_id;
bool noEmbed;
QFontEngine *fontEngine;
Expand Down