Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 2210 → Rev 2211

/trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.h
56,12 → 56,11
bool importTextOnly;
bool append;
bool inList;
bool isOrdered;
bool inSpan;
int listLevel;
int listIndex;
ListStyle *currentListStyle;
std::vector<int> listIndex2;
std::vector<bool> isOrdered2;
bool inT;
std::vector<QString> styleNames;
QString tName;
/trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.cpp
41,8 → 41,9
importTextOnly = textOnly;
usePrefix = prefix;
packStyles = combineStyles;
currentStyle = NULL;
parentStyle = NULL;
currentStyle = 0;
currentListStyle = 0;
parentStyle = 0;
inList = false;
currentList = "";
defaultStyleCreated = false;
73,6 → 74,7
for (int i = 0; i < attrs.count(); ++i)
if (attrs.localName(i) == "style:name")
currentList = attrs.value(i);
currentListStyle = new ListStyle(currentList);
inList = true;
}
else if (((name == "text:list-level-style-bullet") ||
79,11 → 81,19
(name == "text:list-level-style-number") ||
(name == "text:list-level-style-image")) && (inList))
{
BulletType bstyle = Bullet;
QString prefix = "";
QString suffix = "";
QString bullet = "-";
uint ulevel = 0;
uint displayLevels = 1;
uint startAt = 0;
QString level = "";
for (int i = 0; i < attrs.count(); ++i)
{
if (attrs.localName(i) == "text:level")
{
ulevel = QString(attrs.value(i)).toUInt();
gtStyle *plist;
if (attrs.value(i) == "1")
{
112,7 → 122,42
}
currentStyle->setName(currentList + "_" + attrs.value(i));
}
else if (attrs.localName(i) == "style:num-prefix")
prefix = attrs.value(i);
else if (attrs.localName(i) == "style:num-suffix")
suffix = attrs.value(i);
/*else if (attrs.localName(i) == "text:bullet-char")
bullet = attrs.value(i);*/
else if (attrs.localName(i) == "style:num-format") {
QString tmp = attrs.value(i);
if (tmp == "i")
bstyle = LowerRoman;
else if (tmp == "I")
bstyle = UpperRoman;
else if (tmp == "a")
bstyle = LowerAlpha;
else if (tmp == "A")
bstyle = UpperAlpha;
else if (tmp == "1")
bstyle = Number;
}
else if (attrs.localName(i) == "text:start-value") {
startAt = QString(attrs.value(i)).toUInt();
if (startAt > 0)
--startAt;
}
else if (attrs.localName(i) == "text:display-levels") {
displayLevels = QString(attrs.value(i)).toUInt();
if (displayLevels == 0)
displayLevels = 1;
}
}
if (bstyle == Bullet) {
prefix = "";
suffix = "";
}
ListLevel *llevel = new ListLevel(ulevel, bstyle, prefix, suffix, bullet, displayLevels, startAt);
currentListStyle->addLevel(ulevel, llevel);
readProperties = true;
}
else if ((name == "style:drop-cap") && (readProperties))
266,9 → 311,9
}
else if ((attrs.localName(i) == "text:space-before") && (pstyle != NULL))
{
if (inList)
/*if (inList)
pstyle->setIndent(pstyle->getIndent() + getSize(attrs.value(i)));
else
else*/
pstyle->setIndent(getSize(attrs.value(i)));
}
else if ((attrs.localName(i) == "fo:text-indent") && (pstyle != NULL))
426,6 → 471,10
}
else if (name == "text:list-style")
{
if (currentListStyle) {
lists[currentListStyle->name()] = currentListStyle;
currentListStyle = 0;
}
inList = false;
}
 
532,6 → 581,14
delete fstyle;
}
ListStyle* StyleReader::getList(const QString &name)
{
ListStyle *tmp = 0;
if (lists.contains(name))
tmp = lists[name];
return tmp;
}
 
bool StyleReader::updateStyle(gtStyle* style, gtStyle* parent2Style, const QString& key, const QString& value)
{
gtParagraphStyle* pstyle = NULL;
763,5 → 820,219
nname = new QString(nname->lower());
sreader->endElement(NULL, NULL, *nname);
}
#endif
 
/*** ListLevel *****************************************************************************************/
 
const QString ListLevel::lowerUnits[10] = {"", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix"};
const QString ListLevel::lowerTens[10] = {"", "x", "xx", "xxx", "xl", "l", "lx", "lxx", "lxxx", "xc"};
const QString ListLevel::lowerHundreds[10] = {"", "c", "cc", "ccc", "cd", "d", "dc", "dcc", "dccc", "cm"};
const QString ListLevel::lowerThousands[4] = {"", "m", "mm", "mmm"};
const QString ListLevel::upperUnits[10] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
const QString ListLevel::upperTens[10] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
const QString ListLevel::upperHundreds[10] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCC", "CM"};
const QString ListLevel::upperThousands[4] = {"", "M", "MM", "MMM"};
const QString ListLevel::lowerAlphabets[27] = {"", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
const QString ListLevel::upperAlphabets[27] = {"", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
 
ListLevel::ListLevel(uint level,
BulletType btype,
const QString &prefix,
const QString &suffix,
const QString &bullet,
uint displayLevels,
uint startValue) :
m_level(level),
m_btype(btype),
m_prefix(prefix),
m_suffix(suffix),
m_bullet(bullet),
m_displayLevels(displayLevels),
m_next(startValue)
{
 
}
 
QString ListLevel::bulletString()
{
QString tmp;
switch (m_btype) {
case Bullet:
tmp = m_bullet;
break;
case Number:
tmp = QString("%1").arg(m_next);
break;
case LowerRoman:
tmp = lowerRoman(m_next);
break;
case UpperRoman:
tmp = upperRoman(m_next);
break;
case LowerAlpha:
tmp = lowerAlpha(m_next);
break;
case UpperAlpha:
tmp = upperAlpha(m_next);
break;
case Graphic:
tmp = "*";
break;
default:
tmp = "";
};
return tmp;
}
 
QString ListLevel::bullet()
{
return QString(m_prefix + bulletString() + m_suffix);
}
 
QString ListLevel::prefix()
{
return m_prefix;
}
 
QString ListLevel::suffix()
{
return m_suffix;
}
 
void ListLevel::advance()
{
++m_next;
}
 
uint ListLevel::level()
{
return m_level;
}
 
uint ListLevel::displayLevels()
{
return m_displayLevels;
}
 
void ListLevel::reset()
{
m_next = 0;
}
 
QString ListLevel::lowerRoman(uint n)
{
return QString(lowerThousands[(n / 1000)] +
lowerHundreds[(n / 100) % 10] +
lowerTens[(n / 10) % 10] +
lowerUnits[(n) % 10]);
}
 
QString ListLevel::upperRoman(uint n)
{
return QString(upperThousands[(n / 1000)] +
upperHundreds[(n / 100) % 10] +
upperTens[(n / 10) % 10] +
upperUnits[(n) % 10]);
}
 
QString ListLevel::lowerAlpha(uint n)
{
QString tmp;
uint rounds = static_cast<uint>(n / 26);
if (rounds > 26)
rounds = 0;
uint leftover = n % 26;
return QString(lowerAlphabets[rounds] + lowerAlphabets[leftover]);
}
 
QString ListLevel::upperAlpha(uint n)
{
QString tmp;
uint rounds = static_cast<uint>(n / 26);
if (rounds > 26)
rounds = 0;
uint leftover = n % 26;
return QString(upperAlphabets[rounds] + upperAlphabets[leftover]);
}
 
ListLevel::~ListLevel()
{
 
}
 
/*** ListStyle **********************************************************************************/
 
ListStyle::ListStyle(const QString &name, bool consecutiveNumbering, uint currentLevel) :
m_name(name),
m_consecutiveNumbering(consecutiveNumbering),
m_currentLevel(currentLevel),
m_count(0)
{
for (uint i = 0; i < 11; ++i)
levels[i] = 0;
}
 
void ListStyle::addLevel(uint level, ListLevel *llevel)
{
if (level > 0 && level < 11)
levels[level] = llevel;
}
 
QString ListStyle::bullet()
{
uint displayLevels = levels[m_currentLevel]->displayLevels();
if (displayLevels == 1)
return QString(levels[m_currentLevel]->bullet() + " ");
 
QString prefix = levels[m_currentLevel]->prefix();
QString suffix = levels[m_currentLevel]->suffix();
QString bullet = "";
int start = m_currentLevel - displayLevels + 1;
if (start < 1)
return QString(levels[m_currentLevel]->bullet() + " ");
while (static_cast<uint>(start) <= m_currentLevel)
{
if (static_cast<uint>(start) == m_currentLevel)
bullet += levels[start]->bulletString();
else
bullet += levels[start]->bulletString() + ".";
++start;
}
return QString(prefix + bullet + suffix + " ");
}
 
void ListStyle::advance()
{
++m_count;
if (levels[m_currentLevel])
levels[m_currentLevel]->advance();
}
 
void ListStyle::setLevel(uint level)
{
if (level > 0 && level < 11)
m_currentLevel = level;
}
 
void ListStyle::resetLevel()
{
levels[m_currentLevel]->reset();
}
 
QString& ListStyle::name()
{
return m_name;
}
 
ListStyle::~ListStyle()
{
for (uint i = 0; i < 11; ++i)
{
delete levels[i];
levels[i] = 0;
}
}
 
#endif
/trunk/Scribus/scribus/plugins/gettext/odtim/stylereader.h
35,9 → 35,83
#include <gtstyle.h>
#include <gtwriter.h>
 
 
enum BulletType {
Bullet,
Number,
LowerRoman,
UpperRoman,
LowerAlpha,
UpperAlpha,
Graphic
};
 
class ListLevel
{
public:
ListLevel(uint level,
BulletType btype,
const QString &prefix,
const QString &suffix,
const QString &bullet,
uint displayLevels = 1,
uint startValue = 0);
~ListLevel();
QString bulletString();
QString bullet();
QString prefix();
QString suffix();
void advance();
uint level();
uint displayLevels();
void reset();
private:
uint m_level;
BulletType m_btype;
QString m_prefix;
QString m_suffix;
QString m_bullet;
uint m_displayLevels;
uint m_next;
static const QString lowerUnits[10];
static const QString lowerTens[10];
static const QString lowerHundreds[10];
static const QString lowerThousands[4];
static const QString upperUnits[10];
static const QString upperTens[10];
static const QString upperHundreds[10];
static const QString upperThousands[4];
static const QString lowerAlphabets[27];
static const QString upperAlphabets[27];
QString lowerRoman(uint n);
QString upperRoman(uint n);
QString lowerAlpha(uint n);
QString upperAlpha(uint n);
};
 
class ListStyle
{
public:
ListStyle(const QString &name, bool consecutiveNumbering = false, uint currentLevel = 1);
~ListStyle();
void addLevel(uint level, ListLevel *llevel);
QString bullet();
void advance();
void setLevel(uint level);
void resetLevel();
QString& name();
private:
QString m_name;
bool m_consecutiveNumbering;
uint m_currentLevel;
uint m_count;
ListLevel* levels[11];
};
 
typedef QMap<QString, gtStyle*> StyleMap;
typedef QMap<QString, QString> FontMap;
typedef QMap<QString, int> CounterMap;
typedef QMap<QString, ListStyle*> ListMap;
 
class StyleReader
{
54,10 → 128,12
StyleMap attrsStyles;
CounterMap pstyleCounts;
FontMap fonts;
ListMap lists;
gtStyle* currentStyle;
gtStyle* parentStyle;
bool inList;
QString currentList;
ListStyle *currentListStyle;
bool defaultStyleCreated;
double getSize(QString s, double parentSize = -1);
void styleProperties(const QXmlAttributes& attrs);
77,6 → 153,7
gtStyle* getStyle(const QString& name);
void setStyle(const QString& name, gtStyle* style);
QString getFont(const QString& key);
ListStyle *getList(const QString &name);
};
 
#endif // HAVE_XML
/trunk/Scribus/scribus/plugins/gettext/odtim/contentreader.cpp
37,11 → 37,11
currentStyle = NULL;
append = false;
inList = false;
isOrdered = false;
inSpan = false;
listIndex = 0;
listLevel = 0;
currentList = "";
currentListStyle = 0;
inT = false;
tName = "";
}
93,9 → 93,7
else
currentStyle = tmp;
}
else if ((name == "text:unordered-list") ||
(name == "text:ordered-list") ||
(name == "text:list"))
else if (name == "text:list")
{
inList = true;
++listLevel;
107,35 → 105,15
currentList = attrs.value(i);
}
currentStyle = sreader->getStyle(QString(currentList + "_%1").arg(listLevel));
currentListStyle = sreader->getList(currentList);
currentListStyle->setLevel(listLevel);
styleNames.clear();
styleNames.push_back(QString(currentList + "_%1").arg(listLevel));
if (name == "text:ordered-list")
{
isOrdered = true;
isOrdered2.push_back(true);
qDebug("isOrdered2.push_back(true);");
}
else
{
isOrdered = false;
isOrdered2.push_back(false);
qDebug("isOrdered2.push_back(false);");
}
}
else if (name == "text:list-item")
{
qDebug(QString("isOrdered2.size() == %1").arg(isOrdered2.size()));
if (isOrdered2[listLevel - 1])
{
++listIndex;
++listIndex2[listLevel - 1];
if (listLevel == 1)
write(QString("%1. ").arg(listIndex2[listLevel - 1]));
else
write(QString("%1. ").arg(listIndex2[listLevel - 1]));
}
else
write("- ");
currentListStyle->advance();
write(currentListStyle->bullet());
}
else if (name == "style:style")
{
219,9 → 197,7
write(QChar(28));
else if (name == "text:tab")
write("\t");
else if ((name == "text:unordered-list") ||
(name == "text:ordered-list") ||
(name == "text:list"))
else if (name == "text:list")
{
--listLevel;
styleNames.clear();
229,11 → 205,15
{
inList = false;
listIndex2.clear();
currentListStyle = 0;
}
else
{
currentStyle = sreader->getStyle(QString(currentList + "_%1").arg(listLevel));
styleNames.push_back(QString(currentList + "_%1").arg(listLevel));
currentListStyle->resetLevel();
currentListStyle = sreader->getList(currentList);
currentListStyle->setLevel(listLevel);
}
}
else if ((name == "style:style") && (inT))
246,6 → 226,7
 
void ContentReader::write(const QString& text)
{
qDebug(text);
if (importTextOnly)
writer->append(text);
else if (inSpan)