r13769 by jghali - #8229 : invalid ps file created when two fonts have conflicting postscript names

scribus-commit scribus-commit at lists.scribus.net
Sun Jul 12 12:15:17 CEST 2009


Revision: 13769
Author: jghali
Date: 2009-07-12T10:13:19.769078Z
Commit message: #8229 : invalid ps file created when two fonts have conflicting postscript names

Changeset: 
M  /trunk/Scribus/scribus/pslib.cpp
M  /trunk/Scribus/scribus/pslib.h

Diffs:
Index: scribus/pslib.h
===================================================================
--- scribus/pslib.h	(revision 13768)
+++ scribus/pslib.h	(revision 13769)
@@ -171,14 +171,13 @@
 		int Seiten;
 		QString FillColor;
 		QString StrokeColor;
-		QString GrColor1;
-		QString GrColor2;
 		double LineW;
 		QString Fonts;
 		QString FontDesc;
 		QMap<QString, QString> UsedFonts;
-		typedef QMap<uint, std::pair<QChar, QString> > GListe;
-		QMap<QString, GListe> GlyphsOfFont;
+		QMap<QString, QString> FontSubsetMap;
+		typedef QMap<uint, std::pair<QChar, QString> > GlyphList;
+		QMap<QString, GlyphList> GlyphsOfFont;
 		bool isPDF;
 		QFile Spool;
 		QDataStream spoolStream;
Index: scribus/pslib.cpp
===================================================================
--- scribus/pslib.cpp	(revision 13768)
+++ scribus/pslib.cpp	(revision 13769)
@@ -133,19 +133,30 @@
 			erst = false;
 		}
 	}
+	QMap<QString, QString> psNameMap;
 	QMap<QString, QMap<uint, FPointArray> >::Iterator it;
 	int a = 0;
 	for (it = DocFonts.begin(); it != DocFonts.end(); ++it)
 	{
-/* Subset all TTF Fonts until the bug in the TTF-Embedding Code is fixed */
-		ScFace::FontType type = AllFonts[it.key()].type();
+		// Subset all TTF Fonts until the bug in the TTF-Embedding Code is fixed
+		// Subset also font whose postscript name conflicts with an already used font
+		ScFace &face (AllFonts[it.key()]);
+		ScFace::FontType type = face.type();
+		QString encodedName = face.psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" );
 
-		if ((type == ScFace::TTF) || (AllFonts[it.key()].isOTF()) || (AllFonts[it.key()].subset()))
+		if ((type == ScFace::TTF) || (face.isOTF()) || (face.subset()) || psNameMap.contains(encodedName))
 		{
 			QMap<uint, FPointArray>& RealGlyphs(it.value());
-			FontDesc += "/"+AllFonts[it.key()].psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+
-					" "+IToStr(RealGlyphs.count()+1)+" dict def\n";
-			FontDesc += AllFonts[it.key()].psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+" begin\n";
+			// Handle possible PostScript name conflict in oft/ttf fonts
+			int psNameIndex = 1;
+			QString initialName = encodedName;
+			while (psNameMap.contains(encodedName))
+			{
+				encodedName = QString("%1-%2").arg(initialName).arg(psNameIndex);
+				++psNameIndex;
+			}
+			FontDesc += "/" + encodedName + " " + IToStr(RealGlyphs.count()+1) + " dict def\n";
+			FontDesc += encodedName + " begin\n";
 			QMap<uint,FPointArray>::Iterator ig;
 			for (ig = RealGlyphs.begin(); ig != RealGlyphs.end(); ++ig)
 			{
@@ -179,25 +190,27 @@
 				FontDesc += "cl\n} bind def\n";
 			}
 			FontDesc += "end\n";
+			FontSubsetMap.insert(face.scName(), encodedName);
 		}
 		else
 		{
 			UsedFonts.insert(it.key(), "/Fo"+IToStr(a));
-			Fonts += "/Fo"+IToStr(a)+" /"+AllFonts[it.key()].psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" )+" findfont definefont pop\n";
+			Fonts += "/Fo" + IToStr(a) + " /" + encodedName + " findfont definefont pop\n";
 			if (AllFonts[it.key()].embedPs())
 			{
 				QString tmp;
-				if(AllFonts[it.key()].EmbedFont(tmp))
+				if(face.EmbedFont(tmp))
 				{
-					FontDesc += "%%BeginFont: " + AllFonts[it.key()].psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ) + "\n";
+					FontDesc += "%%BeginFont: " + encodedName + "\n";
 					FontDesc += tmp + "\n%%EndFont\n";
 				}
 			}
-			GListe gl;
-			AllFonts[it.key()].glyphNames(gl);
+			GlyphList gl;
+			face.glyphNames(gl);
 			GlyphsOfFont.insert(it.key(), gl);
 			a++;
 		}
+		psNameMap.insert(encodedName, face.scName());
 	}
 	Prolog = "%%BeginProlog\n";
 	Prolog += "/Scribusdict 100 dict def\n";
@@ -2766,8 +2779,7 @@
 					continue;
 				}
 				/* Subset all TTF Fonts until the bug in the TTF-Embedding Code is fixed */
-				ScFace::FontType type = style.font().type();
-				if ((type == ScFace::TTF) ||  (style.font().isOTF()) || (style.font().subset()))
+				if (FontSubsetMap.contains(style.font().scName()))
 				{
 //					uint chr = chstr.unicode();
 					uint chr = style.font().char2CMap(chstr);
@@ -2868,7 +2880,7 @@
 										PutStream(ToStr(style.strokeShade() / 100.0)+" "+spotMap[style.strokeColor()]);
 									else
 										PutStream(FillColor + " cmyk");
-									PS_showSub(chr, style.font().psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ), tsz / 10.0, false);
+									PS_showSub(chr, FontSubsetMap[style.font().scName()], tsz / 10.0, false);
 									PS_restore();
 								}
 								SetColor(style.fillColor(), style.fillShade(), &h, &s, &v, &k, gcr);
@@ -2877,7 +2889,7 @@
 									PutStream(ToStr(style.fillShade() / 100.0)+" "+spotMap[style.fillColor()]);
 								else
 									PutStream(FillColor + " cmyk");
-								PS_showSub(chr, style.font().psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ), tsz / 10.0, false);
+								PS_showSub(chr, FontSubsetMap[style.font().scName()], tsz / 10.0, false);
 								if ((style.effects() & ScStyle_Outline))
 								{
 									if ((style.strokeColor() != CommonStrings::None) && ((tsz * style.outlineWidth() / 10000.0) != 0))
@@ -2890,7 +2902,7 @@
 											PutStream(ToStr(style.strokeShade() / 100.0)+" "+spotMap[style.strokeColor()]);
 										else
 											PutStream(StrokeColor + " cmyk");
-										PS_showSub(chr, style.font().psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ), tsz / 10.0, true);
+										PS_showSub(chr, FontSubsetMap[style.font().scName()], tsz / 10.0, true);
 										PS_restore();
 									}
 								}
@@ -3787,7 +3799,7 @@
 					PutStream(ToStr(hl->fillShade() / 100.0)+" "+spotMap[hl->fillColor()]);
 				else
 					PutStream(FillColor + " cmyk");
-						PS_showSub(chr, hl->font().psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ), tsz / 10.0, false);
+						PS_showSub(chr, FontSubsetMap[hl->font().scName()], tsz / 10.0, false);
 			}
 			PS_restore();
 		}
@@ -4181,8 +4193,7 @@
 			putColor(cstyle.fillColor(), cstyle.fillShade(), false);
 		}
 		/* Subset all TTF Fonts until the bug in the TTF-Embedding Code is fixed */
-		ScFace::FontType ftype = cstyle.font().type();
-		if ((ftype == ScFace::TTF) || (cstyle.font().isOTF()) || (cstyle.font().subset()))
+		if (FontSubsetMap.contains(cstyle.font().scName()))
 		{
 			if (glyph != 0 && glyph != cstyle.font().char2CMap(QChar(' ')) && (!SpecialChars::isBreak(chstr)))
 			{
@@ -4212,7 +4223,7 @@
 						PutStream(ToStr(cstyle.fillShade() / 100.0)+" "+spotMap[cstyle.fillColor()]);
 					else
 						PutStream(FillColor + " cmyk");
-					PS_showSub(glyph, cstyle.font().psName().simplified().replace( QRegExp("[\\s\\/\\{\\[\\]\\}\\<\\>\\(\\)\\%]"), "_" ), tsz / 10.0, false);
+					PS_showSub(glyph, FontSubsetMap[cstyle.font().scName()], tsz / 10.0, false);
 				}
 				PS_restore();
 			}




More information about the scribus-commit mailing list