summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-06-21 18:05:56 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-06-21 18:05:56 (GMT)
commit286a3d119ec95b235b09935296450ec36e640aeb (patch)
tree9146c0ebb21745bb985d24378829929ce92529e2 /Swiften/Serializer
parente0c79b3b885f126a2a2a34cb0d5df90796821130 (diff)
downloadswift-contrib-286a3d119ec95b235b09935296450ec36e640aeb.zip
swift-contrib-286a3d119ec95b235b09935296450ec36e640aeb.tar.bz2
Added parsing and serialization of freehand path element
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.cpp58
-rw-r--r--Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h4
2 files changed, 47 insertions, 15 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&) {
}
}
diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
index 50cf252..25642d0 100644
--- a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
+++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h
@@ -8,6 +8,7 @@
#include <Swiften/Elements/WhiteboardPayload.h>
#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h>
#include <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h>
#include <Swiften/Serializer/GenericPayloadSerializer.h>
#include <Swiften/Serializer/XML/XMLElement.h>
@@ -15,7 +16,8 @@
namespace Swift {
class WhiteboardElementSerializingVisitor : public WhiteboardElementVisitor {
public:
- void visit(const WhiteboardLineElement* line);
+ void visit(WhiteboardLineElement& line);
+ void visit(WhiteboardFreehandPathElement& path);
XMLElement::ref getResult() const;
private: