Author: jghali
Date: Fri Jul 21 11:14:21 2017
New Revision: 22118

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22118
Log:
#14916: fix several issues causing text imported from ODT document to use wrong 
font

Modified:
    trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp
    trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.h

Modified: trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22118&path=/trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp  (original)
+++ trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.cpp  Fri Jul 21 
11:14:21 2017
@@ -645,10 +645,17 @@
 
 void ODTIm::parseTextSpan(QDomElement &elem, PageItem* item, ParagraphStyle 
&tmpStyle, CharStyle &tmpCStyle, ObjStyleODT &tmpOStyle, int &posC)
 {
-       ObjStyleODT cStyle = tmpOStyle;
-       if (elem.hasAttribute("text:style-name"))
-               resolveStyle(cStyle, elem.attribute("text:style-name"));
-       applyCharacterStyle(tmpCStyle, cStyle);
+       ObjStyleODT odtStyle = tmpOStyle;
+       CharStyle cStyle = tmpCStyle;
+
+       QString textStyleName = elem.attribute("text:style-name");
+       if (textStyleName.length() > 0)
+       {
+               resolveStyle(odtStyle, textStyleName);
+               m_textStylesStack.push(textStyleName);
+       }
+       
+       applyCharacterStyle(cStyle, odtStyle);
        if (!elem.hasChildNodes())
                return;
 
@@ -659,7 +666,7 @@
                if (spn.nodeName() == "#text")
                        txt = spn.nodeValue();
                else if (spn.nodeName() == "text:span")
-                       parseTextSpan(spEl, item, tmpStyle, tmpCStyle, cStyle, 
posC);
+                       parseTextSpan(spEl, item, tmpStyle, cStyle, odtStyle, 
posC);
                else if (spn.nodeName() == "text:s")
                {
                        if (spEl.hasAttribute("text:c"))
@@ -682,9 +689,12 @@
                        txt.replace(QChar(0xAD), SpecialChars::SHYPHEN);
                        txt.replace(QChar(0x2011), SpecialChars::NBHYPHEN);
                        txt.replace(QChar(0xA0), SpecialChars::NBSPACE);
-                       insertChars(item, txt, tmpStyle, tmpCStyle, posC);
-               }
-       }
+                       insertChars(item, txt, tmpStyle, cStyle, posC);
+               }
+       }
+
+       if (textStyleName.length() > 0)
+               m_textStylesStack.pop();
 }
 
 void ODTIm::parseTextParagraph(QDomNode &elem, PageItem* item, ParagraphStyle 
&newStyle, ObjStyleODT &tmpOStyle, int &posC)
@@ -693,9 +703,10 @@
        CharStyle tmpCStyle = tmpStyle.charStyle();
        ObjStyleODT pStyle = tmpOStyle;
        QString parStyleName = "";
-       if (elem.toElement().hasAttribute("text:style-name"))
-       {
-               QString pStyleName = 
elem.toElement().attribute("text:style-name");
+
+       QString pStyleName = elem.toElement().attribute("text:style-name");
+       if (pStyleName.length() > 0)
+       {
                resolveStyle(pStyle, pStyleName);
                if (m_Styles.contains(pStyleName))
                {
@@ -716,6 +727,7 @@
                                }
                        }
                }
+               m_textStylesStack.push(pStyleName);
        }
        if ((pStyle.breakBefore == "column") && (item->itemText.length() > 0))
        {
@@ -802,6 +814,9 @@
        item->itemText.insertChars(posC, SpecialChars::PARSEP);
        item->itemText.applyStyle(posC, tmpStyle);
        posC = item->itemText.length();
+
+       if (pStyleName.length() > 0)
+               m_textStylesStack.pop();
 }
 
 void ODTIm::parseText(QDomElement &elem, PageItem* item, ObjStyleODT 
&tmpOStyle)
@@ -1067,15 +1082,57 @@
                                m_fontMap[actStyle.fontName.value] = 
tmpOStyle.fontName;
                        }
                }
-               else if (parDefaultStyle.fontName.valid)
-               {
-                       tmpOStyle.fontName = 
constructFontName(parDefaultStyle.fontName.value, "");
-                       m_fontMap[parDefaultStyle.fontName.value] = 
tmpOStyle.fontName;
-               }
-               else if (txtDefaultStyle.fontName.valid)
-               {
-                       tmpOStyle.fontName = 
constructFontName(txtDefaultStyle.fontName.value, "");
-                       m_fontMap[txtDefaultStyle.fontName.value] = 
tmpOStyle.fontName;
+               else
+               {
+                       QString fontName;
+                       QStack<QString> textStyleStack = m_textStylesStack;
+                       while (!textStyleStack.isEmpty())
+                       {
+                               QString styleName = textStyleStack.pop();
+                               if (!m_Styles.contains(styleName))
+                                       continue;
+                               const DrawStyle& odtStyle = m_Styles[styleName];
+                               if (odtStyle.fontName.valid)
+                               {
+                                       if 
(m_fontMap.contains(odtStyle.fontName.value))
+                                               tmpOStyle.fontName = 
m_fontMap[odtStyle.fontName.value];
+                                       else
+                                               tmpOStyle.fontName = 
constructFontName(odtStyle.fontName.value, "");
+                                       if 
(!PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts.contains(tmpOStyle.fontName))
+                                       {
+                                               tmpOStyle.fontName = 
constructFontName(tmpOStyle.fontName, "");
+                                               
m_fontMap[odtStyle.fontName.value] = tmpOStyle.fontName;
+                                       }
+                                       fontName = tmpOStyle.fontName;
+                                       break;
+                               }
+                               if (odtStyle.parentStyle.valid)
+                               {
+                                       QVector<QString> parentStyles;
+                                       DrawStyle drawStyle = odtStyle;
+                                       while (drawStyle.parentStyle.valid)
+                                       {
+                                               if 
(!m_Styles.contains(drawStyle.parentStyle.value))
+                                                       break;
+                                               
parentStyles.prepend(drawStyle.parentStyle.value);
+                                               drawStyle = 
m_Styles[drawStyle.parentStyle.value];
+                                       }
+                                       if (parentStyles.count() > 0)
+                                               textStyleStack += parentStyles;
+                               }
+                       }
+                       if (txtDefaultStyle.fontName.valid && 
fontName.isEmpty())
+                       {
+                               tmpOStyle.fontName = 
constructFontName(txtDefaultStyle.fontName.value, "");
+                               m_fontMap[txtDefaultStyle.fontName.value] = 
tmpOStyle.fontName;
+                               fontName = tmpOStyle.fontName;
+                       }
+                       if (parDefaultStyle.fontName.valid && 
fontName.isEmpty())
+                       {
+                               tmpOStyle.fontName = 
constructFontName(parDefaultStyle.fontName.value, "");
+                               m_fontMap[parDefaultStyle.fontName.value] = 
tmpOStyle.fontName;
+                               fontName = tmpOStyle.fontName;
+                       }
                }
                if (actStyle.fontStyle.valid)
                        tmpOStyle.fontStyle = actStyle.fontStyle.value;

Modified: trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=22118&path=/trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.h
==============================================================================
--- trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.h    (original)
+++ trunk/Scribus/scribus/plugins/gettext/odt2im/importodt.h    Fri Jul 21 
11:14:21 2017
@@ -19,8 +19,10 @@
 
 #include <QDomDocument>
 #include <QDomElement>
+#include <QHash>
+#include <QStack>
 #include <QString>
-#include <QHash>
+
 class ScZipHandler;
 
 extern "C" PLUGIN_API void GetText2(QString filename, QString encoding, bool 
textOnly, bool prefix, bool append, PageItem *textItem);
@@ -159,6 +161,7 @@
                QHash<QString, QString> map_ID_to_Name;
                QHash<QString, QString> m_fontMap;
                QHash<QString, DrawStyle> m_Styles;
+               QStack<QString> m_textStylesStack;
                DrawStyle parDefaultStyle;
                DrawStyle txtDefaultStyle;
 };


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to