1265
1265
context.styleStack().restore();
1268
struct ParagraphBorderData {
1269
enum Values {Style = 1, Color = 2, Width = 4};
1271
ParagraphBorderData()
1274
ParagraphBorderData(const ParagraphBorderData &other)
1275
: values(other.values), style(other.style), color(other.color), width(other.width) {}
1277
// flag defining which data is set
1280
KoBorder::BorderStyle style;
1282
qreal width; ///< in pt
1286
/// Parses the @p dataString as value defined by CSS2 §7.29.3 "border"
1287
/// Adds parsed data to the data as set for @p defaultParagraphBorderData.
1288
/// Returns the enriched border data on success, the original @p defaultParagraphBorderData on a parsing error
1289
static ParagraphBorderData parseParagraphBorderData(const QString &dataString, const ParagraphBorderData &defaultParagraphBorderData)
1291
const QStringList bv = dataString.split(QLatin1Char(' '), QString::SkipEmptyParts);
1292
// too many items? ignore complete value
1293
if (bv.count() > 3) {
1294
return defaultParagraphBorderData;
1297
ParagraphBorderData borderData = defaultParagraphBorderData;
1298
int parsedValues = 0; ///< used to track what is read from the given string
1300
foreach(const QString &v, bv) {
1302
if (! (parsedValues & ParagraphBorderData::Style)) {
1303
bool success = false;
1304
KoBorder::BorderStyle style = KoBorder::odfBorderStyle(v, &success);
1305
// workaround for not yet supported "hidden"
1306
if (! success && (v == QLatin1String("hidden"))) {
1307
// map to "none" for now TODO: KoBorder needs to support "hidden"
1308
style = KoBorder::BorderNone;
1312
borderData.style = style;
1313
borderData.values |= ParagraphBorderData::Style;
1314
parsedValues |= ParagraphBorderData::Style;
1319
if (! (parsedValues & ParagraphBorderData::Color)) {
1320
const QColor color(v);
1321
if (color.isValid()) {
1322
borderData.color = color;
1323
borderData.values |= ParagraphBorderData::Color;
1324
parsedValues |= ParagraphBorderData::Color;
1329
if (! (parsedValues & ParagraphBorderData::Width)) {
1330
const qreal width = KoUnit::parseValue(v);
1332
borderData.width = width;
1333
borderData.values |= ParagraphBorderData::Width;
1334
parsedValues |= ParagraphBorderData::Width;
1338
// still here? found a value which cannot be parsed
1339
return defaultParagraphBorderData;
1268
1344
void KoParagraphStyle::loadOdfProperties(KoShapeLoadingContext &scontext)
1270
1346
KoStyleStack &styleStack = scontext.odfLoadingContext().styleStack();
1544
const QString borderLeft(styleStack.property(KoXmlNS::fo, "border", "left"));
1545
if (!borderLeft.isEmpty() && borderLeft != "none" && borderLeft != "hidden") {
1546
QStringList bv = borderLeft.split(' ', QString::SkipEmptyParts);
1547
setLeftBorderWidth(KoUnit::parseValue(bv.value(0), 1.0));
1548
setLeftBorderStyle(KoBorder::odfBorderStyle(bv.value(1)));
1549
setLeftBorderColor(QColor(bv.value(2)));
1550
//setLeftInnerBorderWidth(qreal width);
1551
//setLeftBorderSpacing(qreal width);
1553
const QString borderTop(styleStack.property(KoXmlNS::fo, "border", "top"));
1554
if (!borderTop.isEmpty() && borderTop != "none" && borderTop != "hidden") {
1555
QStringList bv = borderTop.split(' ', QString::SkipEmptyParts);
1556
setTopBorderWidth(KoUnit::parseValue(bv.value(0), 1.0));
1557
setTopBorderStyle(KoBorder::odfBorderStyle(bv.value(1)));
1558
setTopBorderColor(QColor(bv.value(2)));
1560
const QString borderRight(styleStack.property(KoXmlNS::fo, "border", "right"));
1561
if (!borderRight.isEmpty() && borderRight != "none" && borderRight != "hidden") {
1562
QStringList bv = borderRight.split(' ', QString::SkipEmptyParts);
1563
setRightBorderWidth(KoUnit::parseValue(bv.value(0), 1.0));
1564
setRightBorderStyle(KoBorder::odfBorderStyle(bv.value(1)));
1565
setRightBorderColor(QColor(bv.value(2)));
1567
const QString borderBottom(styleStack.property(KoXmlNS::fo, "border", "bottom"));
1568
if (!borderBottom.isEmpty() && borderBottom != "none" && borderBottom != "hidden") {
1569
QStringList bv = borderBottom.split(' ', QString::SkipEmptyParts);
1570
setBottomBorderWidth(KoUnit::parseValue(bv.value(0), 1.0));
1571
setBottomBorderStyle(KoBorder::odfBorderStyle(bv.value(1)));
1572
setBottomBorderColor(QColor(bv.value(2)));
1620
// The border attribute is actually three attributes in one string, all optional
1621
// and with no given order. Also there is a hierachy, first the common for all
1622
// sides and then overwrites per side, while in the code only the sides are stored.
1623
// So first the common data border is fetched, then this is overwritten per
1624
// side and the result stored.
1625
const QString border(styleStack.property(KoXmlNS::fo, "border"));
1626
const ParagraphBorderData borderData = parseParagraphBorderData(border, ParagraphBorderData());
1628
const QString borderLeft(styleStack.property(KoXmlNS::fo, "border-left"));
1629
const ParagraphBorderData leftParagraphBorderData = parseParagraphBorderData(borderLeft, borderData);
1630
if (leftParagraphBorderData.values & ParagraphBorderData::Width) {
1631
setLeftBorderWidth(leftParagraphBorderData.width);
1633
if (leftParagraphBorderData.values & ParagraphBorderData::Style) {
1634
setLeftBorderStyle(leftParagraphBorderData.style);
1636
if (leftParagraphBorderData.values & ParagraphBorderData::Color) {
1637
setLeftBorderColor(leftParagraphBorderData.color);
1640
const QString borderTop(styleStack.property(KoXmlNS::fo, "border-top"));
1641
const ParagraphBorderData topParagraphBorderData = parseParagraphBorderData(borderTop, borderData);
1642
if (topParagraphBorderData.values & ParagraphBorderData::Width) {
1643
setTopBorderWidth(topParagraphBorderData.width);
1645
if (topParagraphBorderData.values & ParagraphBorderData::Style) {
1646
setTopBorderStyle(topParagraphBorderData.style);
1648
if (topParagraphBorderData.values & ParagraphBorderData::Color) {
1649
setTopBorderColor(topParagraphBorderData.color);
1652
const QString borderRight(styleStack.property(KoXmlNS::fo, "border-right"));
1653
const ParagraphBorderData rightParagraphBorderData = parseParagraphBorderData(borderRight, borderData);
1654
if (rightParagraphBorderData.values & ParagraphBorderData::Width) {
1655
setRightBorderWidth(rightParagraphBorderData.width);
1657
if (rightParagraphBorderData.values & ParagraphBorderData::Style) {
1658
setRightBorderStyle(rightParagraphBorderData.style);
1660
if (rightParagraphBorderData.values & ParagraphBorderData::Color) {
1661
setRightBorderColor(rightParagraphBorderData.color);
1664
const QString borderBottom(styleStack.property(KoXmlNS::fo, "border-bottom"));
1665
const ParagraphBorderData bottomParagraphBorderData = parseParagraphBorderData(borderBottom, borderData);
1666
if (bottomParagraphBorderData.values & ParagraphBorderData::Width) {
1667
setBottomBorderWidth(bottomParagraphBorderData.width);
1669
if (bottomParagraphBorderData.values & ParagraphBorderData::Style) {
1670
setBottomBorderStyle(bottomParagraphBorderData.style);
1672
if (bottomParagraphBorderData.values & ParagraphBorderData::Color) {
1673
setBottomBorderColor(bottomParagraphBorderData.color);
1574
1676
const QString borderLineWidthLeft(styleStack.property(KoXmlNS::style, "border-line-width", "left"));
1575
if (!borderLineWidthLeft.isEmpty() && borderLineWidthLeft != "none" && borderLineWidthLeft != "hidden") {
1677
if (!borderLineWidthLeft.isEmpty()) {
1576
1678
QStringList blw = borderLineWidthLeft.split(' ', QString::SkipEmptyParts);
1577
1679
setLeftInnerBorderWidth(KoUnit::parseValue(blw.value(0), 0.1));
1578
1680
setLeftBorderSpacing(KoUnit::parseValue(blw.value(1), 1.0));
1579
1681
setLeftBorderWidth(KoUnit::parseValue(blw.value(2), 0.1));
1581
1683
const QString borderLineWidthTop(styleStack.property(KoXmlNS::style, "border-line-width", "top"));
1582
if (!borderLineWidthTop.isEmpty() && borderLineWidthTop != "none" && borderLineWidthTop != "hidden") {
1684
if (!borderLineWidthTop.isEmpty()) {
1583
1685
QStringList blw = borderLineWidthTop.split(' ', QString::SkipEmptyParts);
1584
1686
setTopInnerBorderWidth(KoUnit::parseValue(blw.value(0), 0.1));
1585
1687
setTopBorderSpacing(KoUnit::parseValue(blw.value(1), 1.0));
1586
1688
setTopBorderWidth(KoUnit::parseValue(blw.value(2), 0.1));
1588
1690
const QString borderLineWidthRight(styleStack.property(KoXmlNS::style, "border-line-width", "right"));
1589
if (!borderLineWidthRight.isEmpty() && borderLineWidthRight != "none" && borderLineWidthRight != "hidden") {
1691
if (!borderLineWidthRight.isEmpty()) {
1590
1692
QStringList blw = borderLineWidthRight.split(' ', QString::SkipEmptyParts);
1591
1693
setRightInnerBorderWidth(KoUnit::parseValue(blw.value(0), 0.1));
1592
1694
setRightBorderSpacing(KoUnit::parseValue(blw.value(1), 1.0));
1593
1695
setRightBorderWidth(KoUnit::parseValue(blw.value(2), 0.1));
1595
1697
const QString borderLineWidthBottom(styleStack.property(KoXmlNS::style, "border-line-width", "bottom"));
1596
if (!borderLineWidthBottom.isEmpty() && borderLineWidthBottom != "none" && borderLineWidthBottom != "hidden") {
1698
if (!borderLineWidthBottom.isEmpty()) {
1597
1699
QStringList blw = borderLineWidthBottom.split(' ', QString::SkipEmptyParts);
1598
1700
setBottomInnerBorderWidth(KoUnit::parseValue(blw.value(0), 0.1));
1599
1701
setBottomBorderSpacing(KoUnit::parseValue(blw.value(1), 1.0));