r21775 by jghali - #14614: Font subsets do not include 6-letter leading tag required by spec

scribus-commit scribus-commit at lists.scribus.net
Sun Feb 12 12:57:17 UTC 2017


Author: jghali
Date: Sun Feb 12 12:57:16 2017
New Revision: 21775

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21775
Log:
#14614: Font subsets do not include 6-letter leading tag required by spec

Modified:
    trunk/Scribus/scribus/pdflib_core.cpp
    trunk/Scribus/scribus/pdflib_core.h

Modified: trunk/Scribus/scribus/pdflib_core.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21775&path=/trunk/Scribus/scribus/pdflib_core.cpp
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.cpp	(original)
+++ trunk/Scribus/scribus/pdflib_core.cpp	Sun Feb 12 12:57:16 2017
@@ -1392,7 +1392,6 @@
 	return result;
 }
 
-
 void PDFLibCore::PDF_WriteStandardFonts()
 {
 	int a = 0;
@@ -1664,6 +1663,25 @@
 	return embeddedFontObject;
 }
 
+QByteArray PDFLibCore::PDF_GenerateSubsetTag(const QByteArray& fontName, QList<uint> usedGlyphs)
+{
+	uint hash, mod;
+	QVector<uint> glyphVec = usedGlyphs.toVector();
+
+	hash = qHashBits(fontName.constData(), fontName.size(), 0);
+	hash = qHashBits(glyphVec.constData(), glyphVec.size() * sizeof(uint), hash);
+
+	QByteArray subsetTag(6, (char) 0);
+	for (int i = 0; i < 6; ++i)
+	{
+		mod = hash % 26;
+		subsetTag[i] = 'A' + mod;
+		hash = (hash - mod) / 26;
+	}
+
+	return subsetTag;
+}
+
 PdfId PDFLibCore::PDF_WriteFontDescriptor(const QByteArray& fontName, ScFace& face, ScFace::FontFormat fformat, PdfId embeddedFontObject)
 {
 	PdfId fontDescriptor = writer.newObject();
@@ -2043,9 +2061,12 @@
 	glyphs.prepend(0);
 	QByteArray subset = sfnt::subsetFace(font, glyphs);
 	/*dumpFont(face.psName()+"subs.ttf", subset);*/
+	QByteArray baseFont   = sanitizeFontName(face.psName());
+	QByteArray subsetTag  = PDF_GenerateSubsetTag(baseFont, glyphs);
+	QByteArray subsetName = subsetTag + '+' + baseFont;
 	PdfId embeddedFontObj = PDF_EmbedFontObject(subset, QByteArray());
-	PdfId fontDes = PDF_WriteFontDescriptor(fontName, face, face.format(), embeddedFontObj);
-	QByteArray baseFont = sanitizeFontName(face.psName());
+	PdfId fontDes = PDF_WriteFontDescriptor(subsetName, face, face.format(), embeddedFontObj);
+	
 	ScFace::FaceEncoding fullEncoding, subEncoding;
 	QMap<uint,uint> glyphmap;
 	face.glyphNames(fullEncoding);
@@ -2055,7 +2076,7 @@
 		qDebug() << glyphs[i] << " --> " << i << QChar(fullEncoding[glyphs[i]].first);
 	}
 	
-	PdfFont result = PDF_EncodeCidFont(fontName, face, baseFont, fontDes, fullEncoding, glyphmap);
+	PdfFont result = PDF_EncodeCidFont(fontName, face, subsetName, fontDes, fullEncoding, glyphmap);
 	return result;
 }
 
@@ -2084,9 +2105,12 @@
 	glyphs.prepend(0);
 	QByteArray subset = cff::subsetFace(font, glyphs);
 	/*dumpFont(face.psName()+"subs.cff", subset);*/
+	QByteArray baseFont   = sanitizeFontName(face.psName());
+	QByteArray subsetTag  = PDF_GenerateSubsetTag(baseFont, glyphs);
+	QByteArray subsetName = subsetTag + '+' + baseFont;
 	PdfId embeddedFontObj = PDF_EmbedFontObject(subset, "/CIDFontType0C");
-	PdfId fontDes = PDF_WriteFontDescriptor(fontName, face, face.format(), embeddedFontObj);
-	QByteArray baseFont = sanitizeFontName(face.psName());
+	PdfId fontDes = PDF_WriteFontDescriptor(subsetName, face, face.format(), embeddedFontObj);
+
 	ScFace::FaceEncoding fullEncoding, subEncoding;
 	QMap<uint,uint> glyphmap;
 	face.glyphNames(fullEncoding);
@@ -2096,7 +2120,7 @@
 		qDebug() << glyphs[i] << " --> " << i << QChar(fullEncoding[glyphs[i]].first);
 	}
 	
-	PdfFont result = PDF_EncodeCidFont(fontName, face, baseFont, fontDes, fullEncoding, glyphmap);
+	PdfFont result = PDF_EncodeCidFont(fontName, face, subsetName, fontDes, fullEncoding, glyphmap);
 	return result;
 }
 

Modified: trunk/Scribus/scribus/pdflib_core.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21775&path=/trunk/Scribus/scribus/pdflib_core.h
==============================================================================
--- trunk/Scribus/scribus/pdflib_core.h	(original)
+++ trunk/Scribus/scribus/pdflib_core.h	Sun Feb 12 12:57:16 2017
@@ -102,6 +102,7 @@
 	PdfFont PDF_WriteType3Font(const QByteArray& name, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
 	PdfFont PDF_WriteGlyphsAsXForms(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
 	
+	QByteArray PDF_GenerateSubsetTag(const QByteArray& fontName, QList<uint> usedGlyphs);
 	PdfId PDF_WriteFontDescriptor(const QByteArray& fontName, ScFace& face, ScFace::FontFormat fformat, PdfId embeddedFontObject);
 	PdfFont PDF_WriteTtfSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
 	PdfFont PDF_WriteCffSubsetFont(const QByteArray& fontName, ScFace& face, const QMap<uint,FPointArray>& RealGlyphs);
@@ -112,6 +113,7 @@
 	PdfId PDF_EmbedFontObject(const QByteArray& ttf, const QByteArray& subtype);
 	PdfId PDF_EmbedType1AsciiFontObject(const QByteArray& fontData);
 	PdfId PDF_EmbedType1BinaryFontObject(const QByteArray& fontData);
+
 	void PDF_Begin_Colors();
 	void PDF_Begin_Layers();
 	




More information about the scribus-commit mailing list