diff options
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp index f02791c..b5a4c49 100644 --- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp @@ -7,24 +7,54 @@ #include <Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h> #include <boost/smart_ptr/make_shared.hpp> +#include <boost/lexical_cast.hpp> #include <Swiften/Serializer/XML/XMLTextNode.h> namespace Swift { - void WhiteboardElementSerializingVisitor::visit(const WhiteboardLineElement* line) { + void WhiteboardElementSerializingVisitor::visit(WhiteboardLineElement& line) { element = boost::make_shared<XMLElement>("line"); - element->setAttribute("x1", intToStr(line->x1())); - element->setAttribute("y1", intToStr(line->y1())); - element->setAttribute("x2", intToStr(line->x2())); - element->setAttribute("y2", intToStr(line->y2())); - element->setAttribute("id", line->getID()); - element->setAttribute("stroke", line->getColor().toHex()); - element->setAttribute("stroke-width", intToStr(line->getPenWidth())); - int alpha = line->getColor().getAlpha(); - int opacity = 100*alpha/254; - if (opacity == 100) { - element->setAttribute("opacity", "1"); - } else { - element->setAttribute("opacity", "."+intToStr(opacity)); + try { + element->setAttribute("x1", boost::lexical_cast<std::string>(line.x1())); + element->setAttribute("y1", boost::lexical_cast<std::string>(line.y1())); + element->setAttribute("x2", boost::lexical_cast<std::string>(line.x2())); + element->setAttribute("y2", boost::lexical_cast<std::string>(line.y2())); + element->setAttribute("id", line.getID()); + element->setAttribute("stroke", line.getColor().toHex()); + element->setAttribute("stroke-width", boost::lexical_cast<std::string>(line.getPenWidth())); + int alpha = line.getColor().getAlpha(); + int opacity = 100*alpha/254; + if (opacity == 100) { + element->setAttribute("opacity", "1"); + } else { + element->setAttribute("opacity", "."+boost::lexical_cast<std::string>(opacity)); + } + } catch (boost::bad_lexical_cast&) { + } + } + + void WhiteboardElementSerializingVisitor::visit(WhiteboardFreehandPathElement& path) { + element = boost::make_shared<XMLElement>("path"); + element->setAttribute("id", path.getID()); + element->setAttribute("stroke", path.getColor().toHex()); + try { + element->setAttribute("stroke-width", boost::lexical_cast<std::string>(path.getPenWidth())); + int alpha = path.getColor().getAlpha(); + int opacity = 100*alpha/254; + if (opacity == 100) { + element->setAttribute("opacity", "1"); + } else { + element->setAttribute("opacity", "."+boost::lexical_cast<std::string>(opacity)); + } + std::string pathData; + if (path.getPoints().size() != 0) { + std::vector<std::pair<int, int> >::const_iterator it = path.getPoints().begin(); + pathData = "M"+boost::lexical_cast<std::string>(it->first)+" "+boost::lexical_cast<std::string>(it->second)+"L"; + for (; it != path.getPoints().end(); ++it) { + pathData += boost::lexical_cast<std::string>(it->first)+" "+boost::lexical_cast<std::string>(it->second)+" "; + } + } + element->setAttribute("d", pathData); + } catch (boost::bad_lexical_cast&) { } } |