Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1338)

Unified Diff: src/xml/SkXMLWriter.cpp

Issue 899683002: [SkSVGDevice] Initial text support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: drop addText() length param Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/animator/SkXMLAnimatorWriter.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/xml/SkXMLWriter.cpp
diff --git a/src/xml/SkXMLWriter.cpp b/src/xml/SkXMLWriter.cpp
index ec351b728b84b5cc69a05627f3ef07e09d8318fa..56e08893883c67c8a508d583a90691ce9eeb9875 100644
--- a/src/xml/SkXMLWriter.cpp
+++ b/src/xml/SkXMLWriter.cpp
@@ -51,6 +51,17 @@ void SkXMLWriter::addScalarAttribute(const char name[], SkScalar value)
this->addAttribute(name, tmp.c_str());
}
+void SkXMLWriter::addText(const char text[])
+{
+ if (fElems.isEmpty()) {
+ return;
+ }
+
+ this->onAddText(text);
+
+ fElems.top()->fHasText = true;
+}
+
void SkXMLWriter::doEnd(Elem* elem)
{
delete elem;
@@ -63,9 +74,7 @@ bool SkXMLWriter::doStart(const char name[], size_t length)
if (firstChild)
fElems[level-1]->fHasChildren = true;
Elem** elem = fElems.push();
- *elem = new Elem;
- (*elem)->fName.set(name, length);
- (*elem)->fHasChildren = 0;
+ *elem = new Elem(name, length);
return firstChild;
}
@@ -212,7 +221,7 @@ SkXMLStreamWriter::~SkXMLStreamWriter()
void SkXMLStreamWriter::onAddAttributeLen(const char name[], const char value[], size_t length)
{
- SkASSERT(!fElems.top()->fHasChildren);
+ SkASSERT(!fElems.top()->fHasChildren && !fElems.top()->fHasText);
fStream.writeText(" ");
fStream.writeText(name);
fStream.writeText("=\"");
@@ -220,18 +229,32 @@ void SkXMLStreamWriter::onAddAttributeLen(const char name[], const char value[],
fStream.writeText("\"");
}
+void SkXMLStreamWriter::onAddText(const char text[])
+{
+ Elem* elem = fElems.top();
+
+ if (!elem->fHasChildren && !elem->fHasText) {
+ fStream.writeText(">");
+ fStream.newline();
+ }
+
+ tab(fStream, fElems.count() + 1);
+ fStream.writeText(text);
+ fStream.newline();
+}
+
void SkXMLStreamWriter::onEndElement()
{
Elem* elem = getEnd();
- if (elem->fHasChildren)
+ if (elem->fHasChildren || elem->fHasText)
{
tab(fStream, fElems.count());
fStream.writeText("</");
fStream.writeText(elem->fName.c_str());
fStream.writeText(">");
- }
- else
+ } else {
fStream.writeText("/>");
+ }
fStream.newline();
doEnd(elem);
}
@@ -274,11 +297,16 @@ SkXMLParserWriter::~SkXMLParserWriter()
void SkXMLParserWriter::onAddAttributeLen(const char name[], const char value[], size_t length)
{
- SkASSERT(fElems.count() == 0 || !fElems.top()->fHasChildren);
+ SkASSERT(fElems.count() == 0 || (!fElems.top()->fHasChildren && !fElems.top()->fHasText));
SkString str(value, length);
fParser.addAttribute(name, str.c_str());
}
+void SkXMLParserWriter::onAddText(const char text[])
+{
+ fParser.text(text, SkToInt(strlen(text)));
+}
+
void SkXMLParserWriter::onEndElement()
{
Elem* elem = this->getEnd();
« no previous file with comments | « src/animator/SkXMLAnimatorWriter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698