r18348 by fschmid - Fixed Bug #11599: IDML importer doesn't detect fonts in the source directory of an IDML file

scribus-commit scribus-commit at lists.scribus.net
Sun Jun 30 08:51:51 UTC 2013


Author: fschmid
Date: Sun Jun 30 08:51:51 2013
New Revision: 18348

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18348
Log:
Fixed Bug #11599: IDML importer doesn't detect fonts in the source directory of an IDML file

Modified:
    trunk/Scribus/scribus/plugins/import/idml/importidml.cpp
    trunk/Scribus/scribus/plugins/import/idml/importidml.h

Modified: trunk/Scribus/scribus/plugins/import/idml/importidml.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18348&path=/trunk/Scribus/scribus/plugins/import/idml/importidml.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/idml/importidml.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/idml/importidml.cpp Sun Jun 30 08:51:51 2013
@@ -553,6 +553,7 @@
 						firstLayer = false;
 					}
 				}
+				parseFontsXMLNode(docElem);
 				parseGraphicsXMLNode(docElem);
 				parseStylesXMLNode(docElem);
 				parsePreferencesXMLNode(docElem);
@@ -583,6 +584,14 @@
 						layerTranslate.insert(layerSelf, layerName);
 						firstLayer = false;
 					}
+					if (dpg.tagName() == "idPkg:Fonts")
+					{
+						if (!parseFontsXML(dpg))
+						{
+							retVal = false;
+							break;
+						}
+					}
 					if (dpg.tagName() == "idPkg:Graphic")
 					{
 						if (!parseGraphicsXML(dpg))
@@ -672,7 +681,7 @@
 	return retVal;
 }
 
-bool IdmlPlug::parseGraphicsXML(const QDomElement& grElem)
+bool IdmlPlug::parseFontsXML(const QDomElement& grElem)
 {
 	QDomElement grNode;
 	QDomDocument grMapDom;
@@ -692,12 +701,60 @@
 		else
 			return false;
 	}
+	parseFontsXMLNode(grNode);
+	return true;
+}
+
+void IdmlPlug::parseFontsXMLNode(const QDomElement& grNode)
+{
+	for (QDomNode n = grNode.firstChild(); !n.isNull(); n = n.nextSibling() )
+	{
+		QDomElement e = n.toElement();
+		if (e.tagName() == "FontFamily")
+		{
+			QString family = e.attribute("Name");
+			QMap<QString, QString> styleMap;
+			for(QDomNode gr = e.firstChild(); !gr.isNull(); gr = gr.nextSibling() )
+			{
+				QDomElement grs = gr.toElement();
+				if (grs.tagName() == "Font")
+				{
+					QString styleName = grs.attribute("FontStyleName").remove("$ID/");
+					QString postName = grs.attribute("PostScriptName").remove("$ID/");
+					styleMap.insert(styleName, postName);
+				}
+			}
+			fontTranslateMap.insert(family, styleMap);
+		}
+	}
+}
+
+bool IdmlPlug::parseGraphicsXML(const QDomElement& grElem)
+{
+	QDomElement grNode;
+	QDomDocument grMapDom;
+	if (grElem.hasAttribute("src"))
+	{
+		QByteArray f2;
+		loadRawText(fun->getFile(grElem.attribute("src")), f2);
+		if(grMapDom.setContent(f2))
+			grNode = grMapDom.documentElement();
+		else
+			return false;
+	}
+	else
+	{
+		if (grElem.hasChildNodes())
+			grNode = grElem;
+		else
+			return false;
+	}
 	parseGraphicsXMLNode(grNode);
 	return true;
 }
 
 void IdmlPlug::parseGraphicsXMLNode(const QDomElement& grNode)
-	{
+{
 	for (QDomNode n = grNode.firstChild(); !n.isNull(); n = n.nextSibling() )
 	{
 		QDomElement e = n.toElement();
@@ -3000,38 +3057,44 @@
 
 QString IdmlPlug::constructFontName(QString fontBaseName, QString fontStyle)
 {
-	QString fontName;
-	if ((!fontBaseName.isEmpty()) && (!fontStyle.isEmpty()))
-	{
-		fontName = fontBaseName + " " + fontStyle;
-		bool found = false;
-		QString family = fontName;
-		SCFontsIterator it(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts);
-		for ( ; it.hasNext(); it.next())
-		{
-			if ((fontBaseName == it.current().family()) && (fontStyle == it.current().style()))
-				found = true;
-		}
-		if (found)
-			fontName = family;
-		else
-		{
-			if (importerFlags & LoadSavePlugin::lfCreateThumbnail)
-				fontName = PrefsManager::instance()->appPrefs.itemToolPrefs.textFont;
-			else
-			{
-				if (!PrefsManager::instance()->appPrefs.fontPrefs.GFontSub.contains(family))
-				{
-					qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
-					MissingFont *dia = new MissingFont(0, family, m_Doc);
-					dia->exec();
-					fontName = dia->getReplacementFont();
-					delete dia;
-					qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
-					PrefsManager::instance()->appPrefs.fontPrefs.GFontSub[family] = fontName;
-				}
+	QString fontName = PrefsManager::instance()->appPrefs.itemToolPrefs.textFont;
+	if (fontTranslateMap.contains(fontBaseName))
+	{
+		QMap<QString, QString> styleMap = fontTranslateMap[fontBaseName];
+		if (styleMap.contains(fontStyle))
+		{
+			QString postName = styleMap[fontStyle];
+			bool found = false;
+			SCFontsIterator it(PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts);
+			for ( ; it.hasNext(); it.next())
+			{
+				if (it.current().psName() == postName)
+				{
+					fontName = it.current().scName();
+					found = true;
+					break;
+				}
+			}
+			if (!found)
+			{
+				if (importerFlags & LoadSavePlugin::lfCreateThumbnail)
+					fontName = PrefsManager::instance()->appPrefs.itemToolPrefs.textFont;
 				else
-					fontName = PrefsManager::instance()->appPrefs.fontPrefs.GFontSub[family];
+				{
+					QString family = fontBaseName + " " + fontStyle;
+					if (!PrefsManager::instance()->appPrefs.fontPrefs.GFontSub.contains(family))
+					{
+						qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+						MissingFont *dia = new MissingFont(0, family, m_Doc);
+						dia->exec();
+						fontName = dia->getReplacementFont();
+						delete dia;
+						qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
+						PrefsManager::instance()->appPrefs.fontPrefs.GFontSub[family] = fontName;
+					}
+					else
+						fontName = PrefsManager::instance()->appPrefs.fontPrefs.GFontSub[family];
+				}
 			}
 		}
 	}

Modified: trunk/Scribus/scribus/plugins/import/idml/importidml.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18348&path=/trunk/Scribus/scribus/plugins/import/idml/importidml.h
==============================================================================
--- trunk/Scribus/scribus/plugins/import/idml/importidml.h (original)
+++ trunk/Scribus/scribus/plugins/import/idml/importidml.h Sun Jun 30 08:51:51 2013
@@ -94,6 +94,8 @@
 	};
 	QString getNodeValue(QDomNode &baseNode, QString path);
 	bool convert(QString fn);
+	bool parseFontsXML(const QDomElement& grElem);
+	void parseFontsXMLNode(const QDomElement& grNode);
 	bool parseGraphicsXML(const QDomElement& grElem);
 	void parseGraphicsXMLNode(const QDomElement& grNode);
 	bool parseStylesXML(const QDomElement& sElem);
@@ -145,6 +147,7 @@
 	QMap<QString, QString> styleTranslate;
 	QMap<QString, QStringList> styleParents;
 	QMap<QString, QString> charStyleTranslate;
+	QMap<QString, QMap<QString, QString> > fontTranslateMap;
 	QString def_fillColor;
 	QString def_fillGradient;
 	QString def_strokeColor;




More information about the scribus-commit mailing list