From kde-commits Sun Dec 31 21:46:00 2017 From: =?utf-8?q?Wolthera_van_H=C3=B6vell_tot_Westerflier?= Date: Sun, 31 Dec 2017 21:46:00 +0000 To: kde-commits Subject: [krita] libs/flake/text: Fix text-align to text-anchor conversion. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=151475677226455 Git commit 308a7e7997a02b353ce5b06e72a59c09ba40d29c by Wolthera van H=C3=B6= vell tot Westerflier. Committed on 31/12/2017 at 21:26. Pushed by woltherav into branch 'master'. Fix text-align to text-anchor conversion. The SVGToHTML conversion now assumes that the toplevel nodes under the root text are always paragraphs. This makes sense from a html standards perspective, but will do odd things to certain configurations. This has been considered acceptable to handle situations where the user creates text with rich text, saves it, and reopens the editor. M +50 -53 libs/flake/text/KoSvgTextChunkShape.cpp M +21 -13 libs/flake/text/KoSvgTextShapeMarkupConverter.cpp https://commits.kde.org/krita/308a7e7997a02b353ce5b06e72a59c09ba40d29c diff --git a/libs/flake/text/KoSvgTextChunkShape.cpp b/libs/flake/text/KoSv= gTextChunkShape.cpp index 821002bcdaf..42694385194 100644 --- a/libs/flake/text/KoSvgTextChunkShape.cpp +++ b/libs/flake/text/KoSvgTextChunkShape.cpp @@ -399,72 +399,69 @@ bool KoSvgTextChunkShape::saveHtml(HtmlSavingContext = &context) appendLazy(&dyPos, t.dyPos, i); } = + KoSvgTextChunkShape *parent =3D !isRootTextNode() ? dynamic_cast(this->parent()) : 0; + KoSvgTextProperties parentProperties =3D + parent ? parent->textProperties() : KoSvgTextProperties::defaultPr= operties(); + + // XXX: we don't save fill, stroke, text length, length adjust or spac= ing and glyphs. + KoSvgTextProperties ownProperties =3D textProperties().ownProperties(p= arentProperties); + if (isRootTextNode()) { context.shapeWriter().startElement("body", false); - context.shapeWriter().startElement("p", false); + if (layoutInterface()->isTextNode()) { + context.shapeWriter().startElement("p", false); + } // XXX: Save the style? = - } else if (!dyPos.isEmpty()) { + } else if (parent->isRootTextNode()) { context.shapeWriter().startElement("p", false); } else { context.shapeWriter().startElement("span", false); // XXX: Save the style? } = - if (layoutInterface()->isTextNode()) { - - KoSvgTextChunkShape *parent =3D !isRootTextNode() ? dynamic_cast(this->parent()) : 0; - - - qDebug() << "saveHTML" << this << d->text << xPos << yPos << dxPos= << dyPos; - KoSvgTextProperties parentProperties =3D - parent ? parent->textProperties() : KoSvgTextProperties::defau= ltProperties(); - - // XXX: we don't save fill, stroke, text length, length adjust or = spacing and glyphs. - KoSvgTextProperties ownProperties =3D textProperties().ownProperti= es(parentProperties); - QMap attributes =3D ownProperties.convertToSvgTe= xtAttributes(); - - if (attributes.count() > 0) { - QString styleString; - for (auto it =3D attributes.constBegin(); it !=3D attributes.c= onstEnd(); ++it) { - if (QString(it.key().toLatin1().data()).contains("text-anc= hor")) { - QString val =3D it.value(); - if (it.value()=3D=3D"middle") { - val =3D "center"; - } else if (it.value()=3D=3D"end") { - val =3D "right"; - } else { - val =3D "left"; - } - styleString.append("text-align") - .append(": ") - .append(val) - .append(";" ); - } else if (QString(it.key().toLatin1().data()).contains("f= ill")){ - styleString.append("color") - .append(": ") - .append(it.value()) - .append(";" ); - } else if (QString(it.key().toLatin1().data()).contains("f= ont-size")){ - QString val =3D it.value(); - if (QRegExp ("\\d*").exactMatch(val)) { - val.append("pt"); - } - styleString.append(it.key().toLatin1().data()) - .append(": ") - .append(val) - .append(";" ); + QMap attributes =3D ownProperties.convertToSvgTextAt= tributes(); + if (attributes.size() > 0) { + QString styleString; + for (auto it =3D attributes.constBegin(); it !=3D attributes.const= End(); ++it) { + if (QString(it.key().toLatin1().data()).contains("text-anchor"= )) { + QString val =3D it.value(); + if (it.value()=3D=3D"middle") { + val =3D "center"; + } else if (it.value()=3D=3D"end") { + val =3D "right"; } else { - styleString.append(it.key().toLatin1().data()) - .append(": ") - .append(it.value()) - .append(";" ); + val =3D "left"; + } + styleString.append("text-align") + .append(": ") + .append(val) + .append(";" ); + } else if (QString(it.key().toLatin1().data()).contains("fill"= )){ + styleString.append("color") + .append(": ") + .append(it.value()) + .append(";" ); + } else if (QString(it.key().toLatin1().data()).contains("font-= size")){ + QString val =3D it.value(); + if (QRegExp ("\\d*").exactMatch(val)) { + val.append("pt"); } + styleString.append(it.key().toLatin1().data()) + .append(": ") + .append(val) + .append(";" ); + } else { + styleString.append(it.key().toLatin1().data()) + .append(": ") + .append(it.value()) + .append(";" ); } - context.shapeWriter().addAttribute("style", styleString); } - - + context.shapeWriter().addAttribute("style", styleString); + } + if (layoutInterface()->isTextNode()) { + qDebug() << "saveHTML" << this << d->text << xPos << yPos << dxPos= << dyPos; // After adding all the styling to the

element, add the text context.shapeWriter().addTextNode(d->text); } @@ -476,7 +473,7 @@ bool KoSvgTextChunkShape::saveHtml(HtmlSavingContext &c= ontext) } } = - if (isRootTextNode()) { + if (isRootTextNode() && layoutInterface()->isTextNode()) { context.shapeWriter().endElement(); // body } context.shapeWriter().endElement(); // p or span diff --git a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp b/libs/flake= /text/KoSvgTextShapeMarkupConverter.cpp index c532714ef59..059079a1233 100644 --- a/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp +++ b/libs/flake/text/KoSvgTextShapeMarkupConverter.cpp @@ -257,21 +257,32 @@ bool KoSvgTextShapeMarkupConverter::convertFromHtml(c= onst QString &htmlText, QSt } = QXmlStreamAttributes attributes =3D htmlReader.attributes(); + + QString textAlign; + if (attributes.hasAttribute("align")) { + textAlign =3D attributes.value("align").toString(); + } + if (attributes.hasAttribute("style")) { QString filteredStyles; QStringList svgStyles =3D QString("font-family font-size f= ont-weight font-variant word-spacing text-decoration font-style font-size-a= djust font-stretch direction").split(" "); QStringList styles =3D attributes.value("style").toString(= ).split(";"); for(int i=3D0; i