r24307 by jghali - #11420: improvements related to text styles management during page import
scribus-commit
scribus-commit at lists.scribus.net
Sun Dec 6 00:41:14 UTC 2020
Author: jghali
Date: Sun Dec 6 00:41:14 2020
New Revision: 24307
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24307
Log:
#11420: improvements related to text styles management during page import
Modified:
trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
trunk/Scribus/scribus/scribusdoc.cpp
trunk/Scribus/scribus/scribusdoc.h
trunk/Scribus/scribus/style.h
trunk/Scribus/scribus/styles/style.cpp
trunk/Scribus/scribus/styles/styleset.h
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp Sun Dec 6 00:41:14 2020
@@ -191,13 +191,13 @@
Q_ASSERT(m_Doc==nullptr || m_AvailableFonts==nullptr);
return false;
}
- ParagraphStyle vg;
+
struct ScribusDoc::BookMa bok;
QMap<int, ScribusDoc::BookMa> bookmarks;
- QMap<int,PageItem*> TableID;
- QMap<int,PageItem*> TableIDM;
- QMap<int,PageItem*> TableIDF;
+ QMap<int, PageItem*> TableID;
+ QMap<int, PageItem*> TableIDM;
+ QMap<int, PageItem*> TableIDF;
QList<PageItem*> TableItems;
QList<PageItem*> TableItemsM;
QList<PageItem*> TableItemsF;
@@ -230,6 +230,8 @@
if (m_Doc->autoSaveTimer->isActive())
m_Doc->autoSaveTimer->stop();
+ parStyleMap.clear();
+ charStyleMap.clear();
groupRemap.clear();
itemRemap.clear();
itemNext.clear();
@@ -323,9 +325,10 @@
}
if (tagName == "STYLE")
{
- readParagraphStyle(m_Doc, reader, vg);
+ ParagraphStyle pstyle;
+ readParagraphStyle(m_Doc, reader, pstyle);
StyleSet<ParagraphStyle>tmp;
- tmp.create(vg);
+ tmp.create(pstyle);
m_Doc->redefineStyles(tmp, false);
}
if (tagName == "CHARSTYLE")
@@ -1216,7 +1219,12 @@
{
static const QString CPARENT("CPARENT");
if (attrs.hasAttribute(CPARENT))
- newStyle.setParent(attrs.valueAsString(CPARENT));
+ {
+ QString parentStyle = attrs.valueAsString(CPARENT);
+ if (!parentStyle.isEmpty())
+ parentStyle = charStyleMap.value(parentStyle, parentStyle);
+ newStyle.setParent(parentStyle);
+ }
static const QString FONT("FONT");
if (attrs.hasAttribute(FONT))
@@ -1364,13 +1372,12 @@
else
newStyle.setDefaultStyle(false);
- QString parentStyle = attrs.valueAsString("PARENT", "");
+ QString parentStyle = attrs.valueAsString("PARENT", QString());
if (!parentStyle.isEmpty() && (parentStyle != newStyle.name()))
{
+ parentStyle = parStyleMap.value(parentStyle, parentStyle);
if (m_Doc->styleExists(parentStyle))
newStyle.setParent(parentStyle);
- else if (parStyleMap.contains(parentStyle))
- newStyle.setParent(parStyleMap.value(parentStyle));
else
newStyle.setParent(CommonStrings::DefaultParagraphStyle);
}
@@ -1447,7 +1454,7 @@
if (attrs.hasAttribute(MaxGlyphExtend))
newStyle.setMaxGlyphExtension(attrs.valueAsDouble(MaxGlyphExtend));
- readCharacterStyleAttrs( doc, attrs, newStyle.charStyle());
+ readCharacterStyleAttrs(doc, attrs, newStyle.charStyle());
// newStyle.tabValues().clear();
int numTabs = attrs.valueAsInt("NUMTAB", 0);
@@ -2172,7 +2179,7 @@
QStack< QList<PageItem*> > groupStack;
QStack< QList<PageItem*> > groupStackP;
QStack<int> groupStack2;
- QMap<int,PageItem*> TableID2;
+ QMap<int, PageItem*> TableID2;
QList<PageItem*> TableItems2;
pat.setDoc(doc);
@@ -3178,14 +3185,14 @@
Q_ASSERT(m_Doc==nullptr || m_AvailableFonts==nullptr);
return false;
}
- ParagraphStyle vg;
+
struct ScribusDoc::BookMa bok;
QMap<int, ScribusDoc::BookMa> bookmarks;
ScPage* newPage = nullptr;
QString tmp;
- QMap<int,PageItem*> TableID;
+ QMap<int, PageItem*> TableID;
QList<PageItem*> TableItems;
QStack< QList<PageItem*> > groupStackFI;
QStack< QList<PageItem*> > groupStackMI;
@@ -3218,6 +3225,7 @@
itemCountM = 0;
parStyleMap.clear();
+ charStyleMap.clear();
legacyStyleMap.clear();
legacyStyleMap[0] = "0";
legacyStyleMap[1] = "1";
@@ -3299,7 +3307,7 @@
readMultiline(ml, reader);
QHash<QString,multiLine>::ConstIterator mlit = m_Doc->docLineStyles.constFind(mlName2);
if (mlit != m_Doc->docLineStyles.constEnd() && ml != mlit.value())
- mlName2 = getUniqueName(mlName2, m_Doc->docLineStyles);
+ mlName2 = getUniqueName(mlName2, m_Doc->docLineStyles);
m_Doc->docLineStyles.insert(mlName2, ml);
}
if (tagName == "Pattern")
@@ -3317,7 +3325,13 @@
}
if (tagName == "STYLE")
{
- getStyle(vg, reader, nullptr, m_Doc, true);
+ ParagraphStyle pStyle;
+ getStyle(pStyle, reader, nullptr, m_Doc, true);
+ }
+ if (tagName == "CHARSTYLE")
+ {
+ CharStyle cstyle;
+ getStyle(cstyle, reader, nullptr, m_Doc, true);
}
if (((tagName == "PAGE") || (tagName == "MASTERPAGE")) && (attrs.valueAsInt("NUM") == pageNumber))
{
@@ -3677,64 +3691,106 @@
return true;
}
-void Scribus134Format::getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *tempStyles, ScribusDoc* doc, bool fl)
+void Scribus134Format::getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *tempStyles, ScribusDoc* doc, bool equiv)
{
bool found(false);
const StyleSet<ParagraphStyle> &docParagraphStyles = tempStyles ? *tempStyles : doc->paragraphStyles();
+
+ style.erase();
readParagraphStyle(doc, reader, style);
- for (int i = 0; i < docParagraphStyles.count(); ++i)
- {
- const ParagraphStyle& paraStyle = docParagraphStyles[i];
- if (style.name() == paraStyle.name())
- {
- if (style.equiv(paraStyle))
- {
- if (fl)
- {
- legacyStyleMap[legacyStyleCount] = style.name();
- legacyStyleCount++;
- }
- found = true;
- }
- else
- {
- style.setName(docParagraphStyles.getUniqueCopyName(paraStyle.name()));
- found = false;
- }
- break;
- }
- }
- if (!found && fl)
- {
- for (int i = 0; i < docParagraphStyles.count(); ++i)
- {
- const ParagraphStyle& paraStyle = docParagraphStyles[i];
- if (style.equiv(paraStyle))
- {
- parStyleMap[style.name()] = paraStyle.name();
- style.setName(paraStyle.name());
+
+ // Do not duplicate default style
+ if (style.isDefaultStyle())
+ style.setDefaultStyle(false);
+
+ const ParagraphStyle* foundStyle = docParagraphStyles.getPointer(style.name());
+ if (foundStyle)
+ {
+ found = style.equiv(*foundStyle);
+ if (found)
+ {
+ if (equiv)
+ {
legacyStyleMap[legacyStyleCount] = style.name();
legacyStyleCount++;
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- if (tempStyles)
- tempStyles->create(style);
- else
- {
- StyleSet<ParagraphStyle> tmp;
- tmp.create(style);
- doc->redefineStyles(tmp, false);
- }
- if (fl)
- {
+ }
+ return;
+ }
+ QString newName = docParagraphStyles.getUniqueCopyName(style.name());
+ parStyleMap[style.name()] = newName;
+ style.setName(newName);
+ }
+
+ if (equiv)
+ {
+ const ParagraphStyle* equivStyle = docParagraphStyles.findEquivalent(style);
+ if (equivStyle)
+ {
+ parStyleMap[style.name()] = equivStyle->name();
+ style.setName(equivStyle->name());
legacyStyleMap[legacyStyleCount] = style.name();
legacyStyleCount++;
- }
+ return;
+ }
+ }
+
+ if (tempStyles)
+ tempStyles->create(style);
+ else
+ {
+ StyleSet<ParagraphStyle> tmp;
+ tmp.create(style);
+ doc->redefineStyles(tmp, false);
+ }
+ if (equiv)
+ {
+ legacyStyleMap[legacyStyleCount] = style.name();
+ legacyStyleCount++;
+ }
+}
+
+void Scribus134Format::getStyle(CharStyle& style, ScXmlStreamReader& reader, StyleSet<CharStyle> *tempStyles, ScribusDoc* doc, bool equiv)
+{
+ bool found(false);
+ const StyleSet<CharStyle> &docCharStyles = tempStyles ? *tempStyles : doc->charStyles();
+
+ style.erase();
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ readNamedCharacterStyleAttrs(m_Doc, attrs, style);
+
+ // Do not duplicate default style
+ if (style.isDefaultStyle())
+ style.setDefaultStyle(false);
+
+ const CharStyle* foundStyle = docCharStyles.getPointer(style.name());
+ if (foundStyle)
+ {
+ found = style.equiv(*foundStyle);
+ if (found)
+ return;
+ QString newName = docCharStyles.getUniqueCopyName(style.name());
+ parStyleMap[style.name()] = newName;
+ style.setName(newName);
+ }
+
+ if (equiv)
+ {
+ const CharStyle* equivStyle = docCharStyles.findEquivalent(style);
+ if (equivStyle)
+ {
+ charStyleMap[style.name()] = equivStyle->name();
+ style.setName(equivStyle->name());
+ return;
+ }
+ }
+
+ if (tempStyles)
+ tempStyles->create(style);
+ else
+ {
+ StyleSet<CharStyle> tmp;
+ tmp.create(style);
+ doc->redefineCharStyles(tmp, false);
}
}
@@ -3747,6 +3803,9 @@
QScopedPointer<QIODevice> ioDevice(slaReader(fileName));
if (ioDevice.isNull())
return false;
+
+ parStyleMap.clear();
+ charStyleMap.clear();
ScXmlStreamReader reader(ioDevice.data());
ScXmlStreamAttributes attrs;
@@ -3784,6 +3843,9 @@
QScopedPointer<QIODevice> ioDevice(slaReader(fileName));
if (ioDevice.isNull())
return false;
+
+ parStyleMap.clear();
+ charStyleMap.clear();
ScXmlStreamReader reader(ioDevice.data());
ScXmlStreamAttributes attrs;
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.h Sun Dec 6 00:41:14 2020
@@ -38,6 +38,7 @@
// Standard plugin implementation
Scribus134Format();
virtual ~Scribus134Format();
+
QString fullTrName() const override;
const AboutData* getAboutData() const override;
void deleteAboutData(const AboutData* about) const override;
@@ -83,7 +84,8 @@
QIODevice* slaReader(const QString & fileName);
- void getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *docParagraphStyles, ScribusDoc* doc, bool fl);
+ void getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *docParagraphStyles, ScribusDoc* doc, bool equiv);
+ void getStyle(CharStyle& style, ScXmlStreamReader& reader, StyleSet<CharStyle> *docCharStyles, ScribusDoc* doc, bool equiv);
void readDocAttributes(ScribusDoc* doc, ScXmlStreamAttributes& attrs);
void readCMSSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs);
@@ -116,7 +118,8 @@
bool readTableOfContents(ScribusDoc* doc, ScXmlStreamReader& reader);
PageItem* pasteItem(ScribusDoc *doc, ScXmlStreamAttributes& attrs, const QString& baseDir, PageItem::ItemKind itemKind, int pagenr = -2 /* currentPage*/);
-
+
+ QMap<QString, QString> charStyleMap;
QMap<QString, QString> parStyleMap;
QMap<uint, QString> legacyStyleMap;
uint legacyStyleCount;
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp Sun Dec 6 00:41:14 2020
@@ -202,7 +202,6 @@
bool Scribus150Format::loadElements(const QString& data, const QString& fileDir, int toLayer, double Xp_in, double Yp_in, bool loc)
{
- ParagraphStyle vg;
isNewFormat = false;
LayerToPaste = toLayer;
Xp = Xp_in;
@@ -214,10 +213,10 @@
QList<PageItem*> TableItemsF;
QList<PageItem*> TableItemsM;
QList<PageItem*> WeldItems;
- QMap<int,PageItem*> TableID;
- QMap<int,PageItem*> TableIDF;
- QMap<int,PageItem*> TableIDM;
- QMap<int,PageItem*> WeldID;
+ QMap<int, PageItem*> TableID;
+ QMap<int, PageItem*> TableIDF;
+ QMap<int, PageItem*> TableIDM;
+ QMap<int, PageItem*> WeldID;
QStack< QList<PageItem*> > groupStackFI;
QStack< QList<PageItem*> > groupStackMI;
QStack< QList<PageItem*> > groupStackPI;
@@ -228,6 +227,8 @@
QStack<int> groupStackMI2;
QStack<int> groupStackPI2;
+ parStyleMap.clear();
+ charStyleMap.clear();
itemRemap.clear();
itemNext.clear();
itemCount = 0;
@@ -283,7 +284,12 @@
}
// 10/25/2004 pv - None is "reserved" color. cannot be defined in any file...
if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
+ {
+ QString colorName = attrs.valueAsString("NAME");
+ if (m_Doc->PageColors.contains(colorName))
+ continue;
readColor(m_Doc->PageColors, attrs);
+ }
if (tagName == "Gradient")
{
VGradient gra;
@@ -292,31 +298,27 @@
if (!success)
break;
gra.setRepeatMethod((VGradient::VGradientRepeatMethod)(attrs.valueAsInt("Ext", VGradient::pad)));
- if (!grName.isEmpty())
- {
+ if (!grName.isEmpty() && !m_Doc->docGradients.contains(grName))
m_Doc->docGradients.insert(grName, gra);
- }
}
if (tagName == "STYLE")
{
- readParagraphStyle(m_Doc, reader, vg);
- StyleSet<ParagraphStyle>tmp;
- tmp.create(vg);
- m_Doc->redefineStyles(tmp, false);
+ ParagraphStyle pstyle;
+ getStyle(pstyle, reader, nullptr, m_Doc, true);
}
if (tagName == "CHARSTYLE")
{
CharStyle cstyle;
- StyleSet<CharStyle> temp;
- ScXmlStreamAttributes attrs = reader.scAttributes();
- readNamedCharacterStyleAttrs(m_Doc, attrs, cstyle);
- temp.create(cstyle);
- m_Doc->redefineCharStyles(temp, false);
+ getStyle(cstyle, reader, nullptr, m_Doc, true);
}
if (tagName == "TableStyle")
{
TableStyle tstyle;
readTableStyle(m_Doc, reader, tstyle);
+ // FIXME: import style under new name if existing
+ // Do not break current doc for now
+ if (m_Doc->tableStyles().contains(tstyle.name()))
+ continue;
StyleSet<TableStyle> temp;
temp.create(tstyle);
m_Doc->redefineTableStyles(temp, false);
@@ -325,6 +327,10 @@
{
CellStyle tstyle;
readCellStyle(m_Doc, reader, tstyle);
+ // FIXME: import style under new name if existing
+ // Do not break current doc for now
+ if (m_Doc->cellStyles().contains(tstyle.name()))
+ continue;
StyleSet<CellStyle> temp;
temp.create(tstyle);
m_Doc->redefineCellStyles(temp, false);
@@ -339,11 +345,10 @@
multiLine ml;
QString mlName = attrs.valueAsString("Name");
success = readMultiline(ml, reader);
- if (!success) break;
- if (!mlName.isEmpty())
- {
+ if (!success)
+ break;
+ if (!mlName.isEmpty() && !m_Doc->docLineStyles.contains(mlName))
m_Doc->docLineStyles.insert(mlName, ml);
- }
}
if ((tagName == "ITEM") || (tagName == "PAGEOBJECT") || (tagName == "FRAMEOBJECT"))
{
@@ -746,9 +751,10 @@
bool Scribus150Format::loadStory(const QByteArray& data, StoryText& story, PageItem* item)
{
- ParagraphStyle vg;
isNewFormat = false;
+ parStyleMap.clear();
+ charStyleMap.clear();
itemRemap.clear();
itemNext.clear();
itemCount = 0;
@@ -816,13 +822,14 @@
}
if (tagName == "STYLE")
{
- readParagraphStyle(m_Doc, reader, vg);
+ ParagraphStyle pstyle;
+ readParagraphStyle(m_Doc, reader, pstyle);
// FIXME: import style under new name if existing
// Do not break current doc for now
- if (m_Doc->paragraphStyles().contains(vg.name()))
+ if (m_Doc->paragraphStyles().contains(pstyle.name()))
continue;
StyleSet<ParagraphStyle> tmp;
- tmp.create(vg);
+ tmp.create(pstyle);
m_Doc->redefineStyles(tmp, false);
}
if (tagName == "CHARSTYLE")
@@ -930,20 +937,20 @@
Q_ASSERT(m_Doc == nullptr || m_AvailableFonts == nullptr);
return false;
}
- ParagraphStyle vg;
+
Xp = 0.0;
Yp = 0.0;
GrX = 0.0;
GrY = 0.0;
isNewFormat = false;
- QMap<int,PageItem*> TableID;
- QMap<int,PageItem*> TableIDM;
- QMap<int,PageItem*> TableIDF;
+ QMap<int, PageItem*> TableID;
+ QMap<int, PageItem*> TableIDM;
+ QMap<int, PageItem*> TableIDF;
QList<PageItem*> TableItems;
QList<PageItem*> TableItemsM;
QList<PageItem*> TableItemsF;
- QMap<int,PageItem*> WeldID;
+ QMap<int, PageItem*> WeldID;
QList<PageItem*> WeldItems;
QStack< QList<PageItem*> > groupStackFI;
QStack< QList<PageItem*> > groupStackMI;
@@ -1501,7 +1508,7 @@
Q_ASSERT(m_Doc==nullptr || m_AvailableFonts==nullptr);
return false;
}
- ParagraphStyle vg;
+
Xp = 0.0;
Yp = 0.0;
GrX = 0.0;
@@ -1511,13 +1518,13 @@
isNewFormat = false;
- QMap<int,PageItem*> TableID;
- QMap<int,PageItem*> TableIDM;
- QMap<int,PageItem*> TableIDF;
+ QMap<int, PageItem*> TableID;
+ QMap<int, PageItem*> TableIDM;
+ QMap<int, PageItem*> TableIDF;
QList<PageItem*> TableItems;
QList<PageItem*> TableItemsM;
QList<PageItem*> TableItemsF;
- QMap<int,PageItem*> WeldID;
+ QMap<int, PageItem*> WeldID;
QList<PageItem*> WeldItems;
QStack< QList<PageItem*> > groupStackFI;
QStack< QList<PageItem*> > groupStackMI;
@@ -1555,6 +1562,8 @@
if (m_Doc->autoSaveTimer->isActive())
m_Doc->autoSaveTimer->stop();
+ parStyleMap.clear();
+ charStyleMap.clear();
itemRemap.clear();
itemNext.clear();
itemCount = 0;
@@ -1665,9 +1674,10 @@
}
if (tagName == "STYLE")
{
- readParagraphStyle(m_Doc, reader, vg);
+ ParagraphStyle pstyle;
+ readParagraphStyle(m_Doc, reader, pstyle);
StyleSet<ParagraphStyle>tmp;
- tmp.create(vg);
+ tmp.create(pstyle);
m_Doc->redefineStyles(tmp, false);
}
if (tagName == "CHARSTYLE")
@@ -2789,7 +2799,12 @@
{
static const QString CPARENT("CPARENT");
if (attrs.hasAttribute(CPARENT))
- newStyle.setParent(attrs.valueAsString(CPARENT));
+ {
+ QString parentStyle = attrs.valueAsString(CPARENT);
+ if (!parentStyle.isEmpty())
+ parentStyle = charStyleMap.value(parentStyle, parentStyle);
+ newStyle.setParent(parentStyle);
+ }
static const QString FONT("FONT");
if (attrs.hasAttribute(FONT))
@@ -2956,13 +2971,12 @@
else
newStyle.setDefaultStyle(false);
- QString parentStyle = attrs.valueAsString("PARENT", "");
+ QString parentStyle = attrs.valueAsString("PARENT", QString());
if (!parentStyle.isEmpty() && (parentStyle != newStyle.name()))
{
+ parentStyle = parStyleMap.value(parentStyle, parentStyle);
if (m_Doc->styleExists(parentStyle))
newStyle.setParent(parentStyle);
- else if (parStyleMap.contains(parentStyle))
- newStyle.setParent(parStyleMap.value(parentStyle));
else
newStyle.setParent(CommonStrings::DefaultParagraphStyle);
}
@@ -3133,7 +3147,7 @@
if (attrs.hasAttribute(BSHADE))
newStyle.setBackgroundShade(attrs.valueAsInt(BSHADE, 100));
- readCharacterStyleAttrs( doc, attrs, newStyle.charStyle());
+ readCharacterStyleAttrs(doc, attrs, newStyle.charStyle());
// newStyle.tabValues().clear();
QList<ParagraphStyle::TabRecord> tbs;
@@ -6361,7 +6375,7 @@
Q_ASSERT(m_Doc==nullptr || m_AvailableFonts==nullptr);
return false;
}
- ParagraphStyle vg;
+
Xp = 0.0;
Yp = 0.0;
GrX = 0.0;
@@ -6397,6 +6411,7 @@
}
parStyleMap.clear();
+ charStyleMap.clear();
itemRemap.clear();
itemNext.clear();
itemCount = 0;
@@ -6458,7 +6473,12 @@
}
if (tagName == "COLOR" && attrs.valueAsString("NAME") != CommonStrings::None)
+ {
+ QString colorName = attrs.valueAsString("NAME");
+ if (m_Doc->PageColors.contains(colorName))
+ continue;
readColor(m_Doc->PageColors, attrs);
+ }
if (tagName == "Gradient" && attrs.valueAsString("Name") != CommonStrings::None)
{
VGradient gra;
@@ -6467,10 +6487,8 @@
if (!success)
break;
gra.setRepeatMethod((VGradient::VGradientRepeatMethod)(attrs.valueAsInt("Ext", VGradient::pad)));
- if (!grName.isEmpty())
- {
+ if (!grName.isEmpty() && !m_Doc->docGradients.contains(grName))
m_Doc->docGradients.insert(grName, gra);
- }
}
if (tagName == "JAVA")
{
@@ -6506,9 +6524,9 @@
QString mlName = attrs.valueAsString("Name");
QString mlName2 = mlName;
readMultiline(ml, reader);
- QHash<QString,multiLine>::ConstIterator mlit = m_Doc->docLineStyles.find(mlName2);
+ QHash<QString, multiLine>::ConstIterator mlit = m_Doc->docLineStyles.constFind(mlName2);
if (mlit != m_Doc->docLineStyles.constEnd() && ml != mlit.value())
- mlName2 = getUniqueName(mlName2, m_Doc->docLineStyles);
+ mlName2 = getUniqueName(mlName2, m_Doc->docLineStyles);
m_Doc->docLineStyles.insert(mlName2, ml);
}
if (tagName == "Pattern")
@@ -6526,7 +6544,37 @@
}
if (tagName == "STYLE")
{
- getStyle(vg, reader, nullptr, m_Doc, true);
+ ParagraphStyle pstyle;
+ getStyle(pstyle, reader, nullptr, m_Doc, true);
+ }
+ if (tagName == "CHARSTYLE")
+ {
+ CharStyle cstyle;
+ getStyle(cstyle, reader, nullptr, m_Doc, true);
+ }
+ if (tagName == "TableStyle")
+ {
+ TableStyle tstyle;
+ readTableStyle(m_Doc, reader, tstyle);
+ // FIXME: import style under new name if existing
+ // Do not break current doc for now
+ if (m_Doc->tableStyles().contains(tstyle.name()))
+ continue;
+ StyleSet<TableStyle> temp;
+ temp.create(tstyle);
+ m_Doc->redefineTableStyles(temp, false);
+ }
+ if (tagName == "CellStyle")
+ {
+ CellStyle tstyle;
+ readCellStyle(m_Doc, reader, tstyle);
+ // FIXME: import style under new name if existing
+ // Do not break current doc for now
+ if (m_Doc->cellStyles().contains(tstyle.name()))
+ continue;
+ StyleSet<CellStyle> temp;
+ temp.create(tstyle);
+ m_Doc->redefineCellStyles(temp, false);
}
if (((tagName == "PAGE") || (tagName == "MASTERPAGE")) && (attrs.valueAsInt("NUM") == pageNumber))
{
@@ -7026,52 +7074,92 @@
return true;
}
-void Scribus150Format::getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *tempStyles, ScribusDoc* doc, bool fl)
+void Scribus150Format::getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *tempStyles, ScribusDoc* doc, bool equiv)
{
bool found(false);
const StyleSet<ParagraphStyle> &docParagraphStyles = tempStyles ? *tempStyles : doc->paragraphStyles();
+
+ style.erase();
readParagraphStyle(doc, reader, style);
- for (int xx = 0; xx < docParagraphStyles.count(); ++xx)
- {
- const ParagraphStyle& paraStyle = docParagraphStyles[xx];
- if (style.name() == paraStyle.name())
- {
- if (style.equiv(paraStyle))
- {
- found = true;
- }
- else
- {
- style.setName(docParagraphStyles.getUniqueCopyName(paraStyle.name()));
- found = false;
- }
- break;
- }
- }
- if (!found && fl)
- {
- for (int xx = 0; xx < docParagraphStyles.count(); ++xx)
- {
- const ParagraphStyle& paraStyle = docParagraphStyles[xx];
- if (style.equiv(paraStyle))
- {
- parStyleMap[style.name()] = paraStyle.name();
- style.setName(paraStyle.name());
- found = true;
- break;
- }
- }
- }
- if (!found)
- {
- if (tempStyles)
- tempStyles->create(style);
- else
- {
- StyleSet<ParagraphStyle> tmp;
- tmp.create(style);
- doc->redefineStyles(tmp, false);
- }
+
+ // Do not duplicate default style
+ if (style.isDefaultStyle())
+ style.setDefaultStyle(false);
+
+ const ParagraphStyle* foundStyle = docParagraphStyles.getPointer(style.name());
+ if (foundStyle)
+ {
+ found = style.equiv(*foundStyle);
+ if (found)
+ return;
+ QString newName = docParagraphStyles.getUniqueCopyName(style.name());
+ parStyleMap[style.name()] = newName;
+ style.setName(newName);
+ }
+
+ if (equiv)
+ {
+ const ParagraphStyle* equivStyle = docParagraphStyles.findEquivalent(style);
+ if (equivStyle)
+ {
+ parStyleMap[style.name()] = equivStyle->name();
+ style.setName(equivStyle->name());
+ return;
+ }
+ }
+
+ if (tempStyles)
+ tempStyles->create(style);
+ else
+ {
+ StyleSet<ParagraphStyle> tmp;
+ tmp.create(style);
+ doc->redefineStyles(tmp, false);
+ }
+}
+
+void Scribus150Format::getStyle(CharStyle& style, ScXmlStreamReader& reader, StyleSet<CharStyle> *tempStyles, ScribusDoc* doc, bool equiv)
+{
+ bool found(false);
+ const StyleSet<CharStyle> &docCharStyles = tempStyles ? *tempStyles : doc->charStyles();
+
+ style.erase();
+ ScXmlStreamAttributes attrs = reader.scAttributes();
+ readNamedCharacterStyleAttrs(m_Doc, attrs, style);
+
+ // Do not duplicate default style
+ if (style.isDefaultStyle())
+ style.setDefaultStyle(false);
+
+ const CharStyle* foundStyle = docCharStyles.getPointer(style.name());
+ if (foundStyle)
+ {
+ found = style.equiv(*foundStyle);
+ if (found)
+ return;
+ QString newName = docCharStyles.getUniqueCopyName(style.name());
+ parStyleMap[style.name()] = newName;
+ style.setName(newName);
+ }
+
+ if (equiv)
+ {
+ const CharStyle* equivStyle = docCharStyles.findEquivalent(style);
+ if (equivStyle)
+ {
+ charStyleMap[style.name()] = equivStyle->name();
+ style.setName(equivStyle->name());
+ return;
+ }
+ }
+
+ if (tempStyles)
+ tempStyles->create(style);
+ else
+ {
+ StyleSet<CharStyle> tmp;
+ tmp.create(style);
+ doc->redefineCharStyles(tmp, false);
}
}
@@ -7085,6 +7173,9 @@
if (ioDevice.isNull())
return false;
+ parStyleMap.clear();
+ charStyleMap.clear();
+
ScXmlStreamReader reader(ioDevice.data());
ScXmlStreamAttributes attrs;
while (!reader.atEnd() && !reader.hasError())
@@ -7121,6 +7212,9 @@
QScopedPointer<QIODevice> ioDevice(slaReader(fileName));
if (ioDevice.isNull())
return false;
+
+ parStyleMap.clear();
+ charStyleMap.clear();
ScXmlStreamReader reader(ioDevice.data());
ScXmlStreamAttributes attrs;
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.h Sun Dec 6 00:41:14 2020
@@ -117,7 +117,8 @@
QIODevice* slaReader(const QString & fileName);
- void getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *docParagraphStyles, ScribusDoc* doc, bool fl);
+ void getStyle(ParagraphStyle& style, ScXmlStreamReader& reader, StyleSet<ParagraphStyle> *docParagraphStyles, ScribusDoc* doc, bool equiv);
+ void getStyle(CharStyle& style, ScXmlStreamReader& reader, StyleSet<CharStyle> *docCharStyles, ScribusDoc* doc, bool equiv);
void readDocAttributes(ScribusDoc* doc, ScXmlStreamAttributes& attrs);
void readCMSSettings(ScribusDoc* doc, ScXmlStreamAttributes& attrs);
@@ -190,8 +191,8 @@
void writeGradients(ScXmlStreamWriter & docu, bool part = false);
void writeGradients(ScXmlStreamWriter & docu, const QStringList& gradientNames);
void writeHyphenatorLists(ScXmlStreamWriter& docu);
- void writePStyles(ScXmlStreamWriter& docu);
- void writeCStyles(ScXmlStreamWriter& docu);
+ void writeParagraphStyles(ScXmlStreamWriter& docu);
+ void writeCharStyles(ScXmlStreamWriter& docu);
void writeTableStyles(ScXmlStreamWriter& docu);
void writeCellStyles(ScXmlStreamWriter& docu);
void putPStyle(ScXmlStreamWriter& docu, const ParagraphStyle & style, const QString &nodeName);
@@ -221,7 +222,8 @@
void WritePages(ScribusDoc *doc, ScXmlStreamWriter& docu, QProgressBar *dia2, uint maxC, bool master);
void WriteObjects(ScribusDoc *doc, ScXmlStreamWriter& docu, const QString& baseDir, QProgressBar *dia2, uint maxC, ItemSelection master, QList<PageItem*> *items = 0);
void SetItemProps(ScXmlStreamWriter& docu, PageItem* item, const QString& baseDir);
-
+
+ QMap<QString, QString> charStyleMap;
QMap<QString, QString> parStyleMap;
QMap<int, int> itemRemap;
Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp Sun Dec 6 00:41:14 2020
@@ -92,20 +92,9 @@
}
}
- // Write paragraph styles
- QList<QString>::Iterator it;
- QList<QString> names = lists.styleNames();
- QList<int> styleList = m_Doc->getSortedStyleList();
- for (int i = 0; i < styleList.count(); ++i)
- {
- const ParagraphStyle& paragraphStyle = m_Doc->paragraphStyles()[styleList[i]];
- if (names.contains(paragraphStyle.name()))
- putPStyle(writer, paragraphStyle, "STYLE");
- }
-
// Write character styles
- names = lists.charStyleNames();
- styleList = m_Doc->getSortedCharStyleList();
+ QList<QString> names = lists.charStyleNames();
+ QList<int> styleList = m_Doc->getSortedCharStyleList();
for (int i = 0; i < styleList.count(); ++i)
{
const CharStyle& charStyle = m_Doc->charStyles()[styleList[i]];
@@ -114,6 +103,16 @@
writer.writeStartElement("CHARSTYLE");
putNamedCStyle(writer, charStyle);
writer.writeEndElement();
+ }
+
+ // Write paragraph styles
+ names = lists.styleNames();
+ styleList = m_Doc->getSortedStyleList();
+ for (int i = 0; i < styleList.count(); ++i)
+ {
+ const ParagraphStyle& paragraphStyle = m_Doc->paragraphStyles()[styleList[i]];
+ if (names.contains(paragraphStyle.name()))
+ putPStyle(writer, paragraphStyle, "STYLE");
}
writeLineStyles(writer, lists.lineStyleNames());
@@ -189,21 +188,10 @@
if (pi && !embeddedFrames.contains(pi))
embeddedFrames.append(pi);
}
-
- // Write paragraph styles
- QList<QString>::Iterator it;
- QList<QString> names = lists.styleNames();
- QList<int> styleList = m_Doc->getSortedStyleList();
- for (int i = 0; i < styleList.count(); ++i)
- {
- const ParagraphStyle& paragraphStyle = m_Doc->paragraphStyles()[styleList[i]];
- if (names.contains(paragraphStyle.name()))
- putPStyle(writer, paragraphStyle, "STYLE");
- }
-
+
// Write character styles
- names = lists.charStyleNames();
- styleList = m_Doc->getSortedCharStyleList();
+ QList<QString> names = lists.charStyleNames();
+ QList<int> styleList = m_Doc->getSortedCharStyleList();
for (int i = 0; i < styleList.count(); ++i)
{
const CharStyle& charStyle = m_Doc->charStyles()[styleList[i]];
@@ -212,6 +200,16 @@
writer.writeStartElement("CHARSTYLE");
putNamedCStyle(writer, charStyle);
writer.writeEndElement();
+ }
+
+ // Write paragraph styles
+ names = lists.styleNames();
+ styleList = m_Doc->getSortedStyleList();
+ for (int i = 0; i < styleList.count(); ++i)
+ {
+ const ParagraphStyle& paragraphStyle = m_Doc->paragraphStyles()[styleList[i]];
+ if (names.contains(paragraphStyle.name()))
+ putPStyle(writer, paragraphStyle, "STYLE");
}
writeLineStyles(writer, lists.lineStyleNames());
@@ -525,8 +523,8 @@
writeColors(docu);
writeGradients(docu);
writeHyphenatorLists(docu);
- writePStyles(docu);
- writeCStyles(docu);
+ writeCharStyles(docu);
+ writeParagraphStyles(docu);
writeTableStyles(docu);
writeCellStyles(docu);
writeLineStyles(docu);
@@ -801,7 +799,7 @@
docu.writeEndElement();
}
-void Scribus150Format::writePStyles(ScXmlStreamWriter & docu)
+void Scribus150Format::writeParagraphStyles(ScXmlStreamWriter & docu)
{
QList<int> styleList = m_Doc->getSortedStyleList();
for (int a = 0; a < styleList.count(); ++a)
@@ -927,7 +925,7 @@
}
-void Scribus150Format::writeCStyles(ScXmlStreamWriter & docu)
+void Scribus150Format::writeCharStyles(ScXmlStreamWriter & docu)
{
QList<int> styleList = m_Doc->getSortedCharStyleList();
for (int a = 0; a < styleList.count(); ++a)
Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Sun Dec 6 00:41:14 2020
@@ -1048,14 +1048,14 @@
}
}
-bool ScribusDoc::styleExists(const QString& styleName)
-{
- for (int i = 0; i < paragraphStyles().count(); ++i)
- {
- if (paragraphStyles()[i].name() == styleName)
- return true;
- }
- return false;
+bool ScribusDoc::styleExists(const QString& styleName) const
+{
+ return m_docParagraphStyles.contains(styleName);
+}
+
+bool ScribusDoc::charStyleExists(const QString& styleName) const
+{
+ return m_docCharStyles.contains(styleName);
}
QList<int> ScribusDoc::getSortedStyleList()
Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Sun Dec 6 00:41:14 2020
@@ -613,7 +613,9 @@
ResourceCollection m_newNames;
};
void replaceNamedResources(ResourceCollection& newNames);
- bool styleExists(const QString& styleName);
+
+ bool styleExists(const QString& styleName) const;
+ bool charStyleExists(const QString& styleName) const;
QList<int> getSortedStyleList();
QList<int> getSortedCharStyleList();
Modified: trunk/Scribus/scribus/style.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/style.h
==============================================================================
--- trunk/Scribus/scribus/style.h (original)
+++ trunk/Scribus/scribus/style.h Sun Dec 6 00:41:14 2020
@@ -24,7 +24,6 @@
#include "styles/stylecontext.h"
#include "desaxe/saxio.h"
-
/**
* This is the base class for all style-like objects: CharStyles,
* ParagraphStyles, LineStyles, FrameStyles, CellStyles,
@@ -34,7 +33,8 @@
* the stored m_contextversion against the StyleContext's version and updates all
* attributes if they are different.
*/
-class SCRIBUS_API BaseStyle : public SaxIO {
+class SCRIBUS_API BaseStyle : public SaxIO
+{
protected:
bool m_isDefaultStyle;
QString m_name;
@@ -42,6 +42,7 @@
int m_contextversion;
QString m_parent;
QString m_shortcut;
+
public:
// static const short NOVALUE = -16000;
@@ -81,6 +82,8 @@
QString name() const { return m_name; }
void setName(const QString& n) { m_name = n.isEmpty() ? "" : n; }
bool hasName() const { return ! m_name.isEmpty(); }
+
+ QString baseName() const;
virtual QString displayName() const = 0;/*{
if ( hasName() || !hasParent() || !m_context)
Modified: trunk/Scribus/scribus/styles/style.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/styles/style.cpp
==============================================================================
--- trunk/Scribus/scribus/styles/style.cpp (original)
+++ trunk/Scribus/scribus/styles/style.cpp Sun Dec 6 00:41:14 2020
@@ -59,6 +59,21 @@
m_contextversion = m_context->version();
}
+QString BaseStyle::baseName() const
+{
+ if (m_name.isEmpty())
+ return QString();
+
+ static QRegExp rx("^(.*)\\s+\\((\\d+)\\)$");
+ if (rx.indexIn(m_name) != -1)
+ {
+ QStringList matches = rx.capturedTexts();
+ if (matches.count() >= 3)
+ return matches[1];
+ }
+ return m_name;
+}
+
const BaseStyle* BaseStyle::parentStyle() const
{
//qDebug() << QString("follow %1").arg(reinterpret_cast<uint>(m_context),16);
Modified: trunk/Scribus/scribus/styles/styleset.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24307&path=/trunk/Scribus/scribus/styles/styleset.h
==============================================================================
--- trunk/Scribus/scribus/styles/styleset.h (original)
+++ trunk/Scribus/scribus/styles/styleset.h Sun Dec 6 00:41:14 2020
@@ -21,6 +21,11 @@
{
return * dynamic_cast<const STYLE*>(resolve(name));
}
+
+ const STYLE* getPointer(const QString& name) const
+ {
+ return dynamic_cast<const STYLE*>(resolve(name));
+ }
STYLE& operator[] (int index)
{
@@ -37,6 +42,8 @@
inline bool contains(const QString& name) const;
inline int find(const QString& name) const;
+
+ const STYLE* findEquivalent(const STYLE& style) const;
inline const BaseStyle* resolve(const QString& name) const;
@@ -149,6 +156,17 @@
if (styles[i]->name() == name)
return i;
return -1;
+}
+
+template<class STYLE>
+const STYLE* StyleSet<STYLE>::findEquivalent(const STYLE& style) const
+{
+ for (int i = 0; i < styles.count(); ++i)
+ {
+ if (style.equiv(*styles[i]))
+ return styles[i];
+ }
+ return nullptr;
}
template<class STYLE>
More information about the scribus-commit
mailing list