r18830 by fschmid - ODG-Importer: better text import, esp on measurements.
scribus-commit
scribus-commit at lists.scribus.net
Fri Feb 21 20:52:55 UTC 2014
Author: fschmid
Date: Fri Feb 21 20:52:54 2014
New Revision: 18830
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=18830
Log:
ODG-Importer: better text import, esp on measurements.
Modified:
trunk/Scribus/scribus/plugins/import/odg/importodg.cpp
trunk/Scribus/scribus/plugins/import/odg/importodg.h
Modified: trunk/Scribus/scribus/plugins/import/odg/importodg.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18830&path=/trunk/Scribus/scribus/plugins/import/odg/importodg.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/odg/importodg.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/odg/importodg.cpp Fri Feb 21 20:52:54 2014
@@ -1240,12 +1240,15 @@
item->itemText.clear();
item->itemText.setDefaultStyle(newStyle);
item->setFirstLineOffset(FLOPFontAscent);
+ ObjStyle pStyle = tmpOStyle;
+ if (elem.hasAttribute("text:style-name"))
+ resovleStyle(pStyle, elem.attribute("text:style-name"));
for(QDomElement para = elem.firstChildElement(); !para.isNull(); para = para.nextSiblingElement())
{
- if (para.hasAttributes() && para.hasChildNodes())
- {
- ObjStyle pStyle;
- resovleStyle(pStyle, para.attribute("text:style-name"));
+ if (para.hasChildNodes())
+ {
+ if (para.hasAttribute("text:style-name"))
+ resovleStyle(pStyle, para.attribute("text:style-name"));
ParagraphStyle tmpStyle = newStyle;
tmpStyle.setAlignment(pStyle.textAlign);
tmpStyle.setLeftMargin(pStyle.margin_left);
@@ -1272,16 +1275,57 @@
}
else
{
- for(QDomElement sp = para.firstChildElement(); !sp.isNull(); sp = sp.nextSiblingElement())
+ for(QDomNode spn = para.firstChild(); !spn.isNull(); spn = spn.nextSibling())
{
- ObjStyle cStyle;
- resovleStyle(cStyle, sp.attribute("text:style-name"));
CharStyle tmpCStyle = tmpStyle.charStyle();
+ QDomElement sp = spn.toElement();
+ ObjStyle cStyle = pStyle;
+ if (spn.isElement() && (sp.tagName() == "text:span"))
+ {
+ if (sp.hasAttribute("text:style-name"))
+ resovleStyle(cStyle, sp.attribute("text:style-name"));
+ }
tmpCStyle.setFont((*m_Doc->AllFonts)[cStyle.fontName]);
tmpCStyle.setFontSize(cStyle.fontSize * 10);
tmpCStyle.setFillColor(cStyle.CurrColorText);
maxFsize = qMax(maxFsize, cStyle.fontSize);
- QString txt = sp.text().trimmed();
+ if ((cStyle.textPos.startsWith("super")) || (cStyle.textPos.startsWith("sub")))
+ {
+ StyleFlag styleEffects = tmpCStyle.effects();
+ if (cStyle.textPos.startsWith("super"))
+ styleEffects |= ScStyle_Superscript;
+ else
+ styleEffects |= ScStyle_Subscript;
+ tmpCStyle.setFeatures(styleEffects.featureList());
+ }
+ QString txt = "";
+ if (spn.isElement())
+ {
+ if (sp.tagName() == "text:span")
+ {
+ if (sp.tagName() == "text:s")
+ txt = " ";
+ else if (sp.tagName() == "text:tab")
+ txt = SpecialChars::TAB;
+ else if (sp.tagName() == "text:line-break")
+ txt = SpecialChars::LINEBREAK;
+ else
+ txt = sp.text().trimmed();
+ }
+ else if (sp.tagName() == "text:measure")
+ {
+ QString kind = sp.attribute("text:kind");
+ if (kind == "value")
+ txt += sp.text().trimmed();
+ else if (kind == "unit")
+ txt += " " + sp.text().trimmed();
+ }
+ }
+ else if (spn.isText())
+ {
+ QDomText t = spn.toText();
+ txt = t.data().trimmed();
+ }
if (txt.length() > 0)
{
item->itemText.insertChars(posC, txt);
@@ -1319,6 +1363,15 @@
tmpCStyle.setFont((*m_Doc->AllFonts)[tmpOStyle.fontName]);
tmpCStyle.setFontSize(tmpOStyle.fontSize * 10);
tmpCStyle.setFillColor(tmpOStyle.CurrColorText);
+ if ((tmpOStyle.textPos.startsWith("super")) || (tmpOStyle.textPos.startsWith("sub")))
+ {
+ StyleFlag styleEffects = tmpCStyle.effects();
+ if (tmpOStyle.textPos.startsWith("super"))
+ styleEffects |= ScStyle_Superscript;
+ else
+ styleEffects |= ScStyle_Subscript;
+ tmpCStyle.setFeatures(styleEffects.featureList());
+ }
if (tmpOStyle.lineHeight < 0.0)
tmpStyle.setLineSpacingMode(ParagraphStyle::AutomaticLineSpacing);
else
@@ -1615,6 +1668,7 @@
currStyle.fontName = AttributeValue(spe.attribute("fo:font-family", ""));
currStyle.fontSize = AttributeValue(spe.attribute("fo:font-size", ""));
currStyle.fontColor = AttributeValue(spe.attribute("fo:color", ""));
+ currStyle.textPos = AttributeValue(spe.attribute("style:text-position", ""));
}
}
currStyle.parentStyle = AttributeValue(spd.attribute("style:parent-style-name", ""));
@@ -1738,6 +1792,8 @@
actStyle.textIndent = AttributeValue(currStyle.textIndent.value);
if (currStyle.textAlign.valid)
actStyle.textAlign = AttributeValue(currStyle.textAlign.value);
+ if (currStyle.textPos.valid)
+ actStyle.textPos = AttributeValue(currStyle.textPos.value);
if (currStyle.lineHeight.valid)
actStyle.lineHeight = AttributeValue(currStyle.lineHeight.value);
if (currStyle.fontColor.valid)
@@ -1924,6 +1980,8 @@
else if (attValue == "justify")
tmpOStyle.textAlign = ParagraphStyle::Justified;
}
+ if (actStyle.textPos.valid)
+ tmpOStyle.textPos = actStyle.textPos.value;
if (actStyle.lineHeight.valid)
{
if (actStyle.lineHeight.value == "normal")
Modified: trunk/Scribus/scribus/plugins/import/odg/importodg.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=18830&path=/trunk/Scribus/scribus/plugins/import/odg/importodg.h
==============================================================================
--- trunk/Scribus/scribus/plugins/import/odg/importodg.h (original)
+++ trunk/Scribus/scribus/plugins/import/odg/importodg.h Fri Feb 21 20:52:54 2014
@@ -64,6 +64,7 @@
fontSize(10.0),
textIndent(0.0),
textAlign(ParagraphStyle::Leftaligned),
+ textPos(""),
lineHeight(1.0),
absLineHeight(false),
margin_top(0.0),
@@ -126,6 +127,7 @@
double fontSize;
double textIndent;
ParagraphStyle::AlignmentType textAlign; // 0 = left
+ QString textPos;
double lineHeight;
bool absLineHeight;
double margin_top;
@@ -225,6 +227,7 @@
AttributeValue fontSize;
AttributeValue textIndent;
AttributeValue textAlign;
+ AttributeValue textPos;
AttributeValue lineHeight;
AttributeValue margin_top;
AttributeValue margin_bottom;
More information about the scribus-commit
mailing list