|
|
|
|
@ -119,70 +119,93 @@ void SaveHandler::writeTimestamp(Stroke* s, XmlPointNode* stroke) |
|
|
|
|
stroke->setAttrib("fn",s->getAudioFilename()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SaveHandler::visitLayer(XmlNode* page, Layer* l) |
|
|
|
|
void SaveHandler::visitStroke(XmlPointNode* stroke, Stroke* s) |
|
|
|
|
{ |
|
|
|
|
XOJ_CHECK_TYPE(SaveHandler); |
|
|
|
|
|
|
|
|
|
XmlNode* layer = new XmlNode("layer"); |
|
|
|
|
page->addChild(layer); |
|
|
|
|
for(Element* e : *l->getElements()) |
|
|
|
|
StrokeTool t = s->getToolType(); |
|
|
|
|
|
|
|
|
|
unsigned char alpha = 0xff; |
|
|
|
|
|
|
|
|
|
if (t == STROKE_TOOL_PEN) |
|
|
|
|
{ |
|
|
|
|
if (e->getType() == ELEMENT_STROKE) |
|
|
|
|
{ |
|
|
|
|
Stroke* s = (Stroke*) e; |
|
|
|
|
XmlPointNode* stroke = new XmlPointNode("stroke"); |
|
|
|
|
layer->addChild(stroke); |
|
|
|
|
stroke->setAttrib("tool", "pen"); |
|
|
|
|
writeTimestamp(s, stroke); |
|
|
|
|
} |
|
|
|
|
else if (t == STROKE_TOOL_ERASER) |
|
|
|
|
{ |
|
|
|
|
stroke->setAttrib("tool", "eraser"); |
|
|
|
|
} |
|
|
|
|
else if (t == STROKE_TOOL_HIGHLIGHTER) |
|
|
|
|
{ |
|
|
|
|
stroke->setAttrib("tool", "highlighter"); |
|
|
|
|
alpha = 0x7f; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
g_warning("Unknown stroke tool type: %i", t); |
|
|
|
|
stroke->setAttrib("tool", "pen"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
StrokeTool t = s->getToolType(); |
|
|
|
|
stroke->setAttrib("color", getColorStr(s->getColor(), alpha).c_str()); |
|
|
|
|
|
|
|
|
|
unsigned char alpha = 0xff; |
|
|
|
|
int pointCount = s->getPointCount(); |
|
|
|
|
|
|
|
|
|
if (t == STROKE_TOOL_PEN) |
|
|
|
|
{ |
|
|
|
|
stroke->setAttrib("tool", "pen"); |
|
|
|
|
writeTimestamp(s,stroke); |
|
|
|
|
} |
|
|
|
|
else if (t == STROKE_TOOL_ERASER) |
|
|
|
|
{ |
|
|
|
|
stroke->setAttrib("tool", "eraser"); |
|
|
|
|
} |
|
|
|
|
else if (t == STROKE_TOOL_HIGHLIGHTER) |
|
|
|
|
{ |
|
|
|
|
stroke->setAttrib("tool", "highlighter"); |
|
|
|
|
alpha = 0x7f; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
g_warning("Unknown stroke tool type: %i", t); |
|
|
|
|
stroke->setAttrib("tool", "pen"); |
|
|
|
|
} |
|
|
|
|
for (int i = 0; i < pointCount; i++) |
|
|
|
|
{ |
|
|
|
|
Point p = s->getPoint(i); |
|
|
|
|
stroke->addPoint(&p); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stroke->setAttrib("color", getColorStr(s->getColor(), alpha).c_str()); |
|
|
|
|
if (s->hasPressure()) |
|
|
|
|
{ |
|
|
|
|
double* values = new double[pointCount + 1]; |
|
|
|
|
values[0] = s->getWidth(); |
|
|
|
|
for (int i = 0; i < pointCount; i++) |
|
|
|
|
{ |
|
|
|
|
values[i + 1] = s->getPoint(i).z; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int pointCount = s->getPointCount(); |
|
|
|
|
stroke->setAttrib("width", values, pointCount); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
stroke->setAttrib("width", s->getWidth()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < pointCount; i++) |
|
|
|
|
{ |
|
|
|
|
Point p = s->getPoint(i); |
|
|
|
|
stroke->addPoint(&p); |
|
|
|
|
} |
|
|
|
|
visitStrokeExtended(stroke, s); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (s->hasPressure()) |
|
|
|
|
{ |
|
|
|
|
double* values = new double[pointCount + 1]; |
|
|
|
|
values[0] = s->getWidth(); |
|
|
|
|
for (int i = 0; i < pointCount; i++) |
|
|
|
|
{ |
|
|
|
|
values[i + 1] = s->getPoint(i).z; |
|
|
|
|
} |
|
|
|
|
/**
|
|
|
|
|
* Export the fill attributes |
|
|
|
|
*/ |
|
|
|
|
void SaveHandler::visitStrokeExtended(XmlPointNode* stroke, Stroke* s) |
|
|
|
|
{ |
|
|
|
|
XOJ_CHECK_TYPE(SaveHandler); |
|
|
|
|
|
|
|
|
|
stroke->setAttrib("width", values, pointCount); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
stroke->setAttrib("width", s->getWidth()); |
|
|
|
|
} |
|
|
|
|
if (s->getFill() == -1) |
|
|
|
|
{ |
|
|
|
|
// no fill to save
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
stroke->setAttrib("fill", s->getFill()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SaveHandler::visitLayer(XmlNode* page, Layer* l) |
|
|
|
|
{ |
|
|
|
|
XOJ_CHECK_TYPE(SaveHandler); |
|
|
|
|
|
|
|
|
|
XmlNode* layer = new XmlNode("layer"); |
|
|
|
|
page->addChild(layer); |
|
|
|
|
for(Element* e : *l->getElements()) |
|
|
|
|
{ |
|
|
|
|
if (e->getType() == ELEMENT_STROKE) |
|
|
|
|
{ |
|
|
|
|
Stroke* s = (Stroke*) e; |
|
|
|
|
XmlPointNode* stroke = new XmlPointNode("stroke"); |
|
|
|
|
layer->addChild(stroke); |
|
|
|
|
visitStroke(stroke, s); |
|
|
|
|
} |
|
|
|
|
else if (e->getType() == ELEMENT_TEXT) |
|
|
|
|
{ |
|
|
|
|
|