ext/xlsxwriter/libxlsxwriter/src/drawing.c in xlsxwriter-0.0.5 vs ext/xlsxwriter/libxlsxwriter/src/drawing.c in xlsxwriter-0.0.6
- old
+ new
@@ -237,11 +237,11 @@
LXW_INIT_ATTRIBUTES();
LXW_PUSH_ATTRIBUTES_INT("id", index + 1);
LXW_PUSH_ATTRIBUTES_STR("name", name);
- if (drawing_object)
+ if (drawing_object && drawing_object->description)
LXW_PUSH_ATTRIBUTES_STR("descr", drawing_object->description);
lxw_xml_empty_tag(self->file, "xdr:cNvPr", &attributes);
LXW_FREE_ATTRIBUTES();
@@ -488,16 +488,43 @@
{
lxw_xml_empty_tag(self->file, "xdr:clientData", NULL);
}
/*
+ * Write the <a:graphicFrameLocks> element.
+ */
+STATIC void
+_drawing_write_a_graphic_frame_locks(lxw_drawing *self)
+{
+ struct xml_attribute_list attributes;
+ struct xml_attribute *attribute;
+
+ LXW_INIT_ATTRIBUTES();
+ LXW_PUSH_ATTRIBUTES_INT("noGrp", 1);
+
+ lxw_xml_empty_tag(self->file, "a:graphicFrameLocks", &attributes);
+
+ LXW_FREE_ATTRIBUTES();
+}
+
+/*
* Write the <xdr:cNvGraphicFramePr> element.
*/
STATIC void
_drawing_write_c_nv_graphic_frame_pr(lxw_drawing *self)
{
- lxw_xml_empty_tag(self->file, "xdr:cNvGraphicFramePr", NULL);
+ if (self->embedded) {
+ lxw_xml_empty_tag(self->file, "xdr:cNvGraphicFramePr", NULL);
+ }
+ else {
+ lxw_xml_start_tag(self->file, "xdr:cNvGraphicFramePr", NULL);
+
+ /* Write the a:graphicFrameLocks element. */
+ _drawing_write_a_graphic_frame_locks(self);
+
+ lxw_xml_end_tag(self->file, "xdr:cNvGraphicFramePr");
+ }
}
/*
* Write the <xdr:nvGraphicFramePr> element.
*/
@@ -703,10 +730,77 @@
lxw_xml_end_tag(self->file, "xdr:twoCellAnchor");
LXW_FREE_ATTRIBUTES();
}
+/*
+ * Write the <xdr:ext> element.
+ */
+STATIC void
+_drawing_write_ext(lxw_drawing *self, uint32_t cx, uint32_t cy)
+{
+ struct xml_attribute_list attributes;
+ struct xml_attribute *attribute;
+
+ LXW_INIT_ATTRIBUTES();
+ LXW_PUSH_ATTRIBUTES_INT("cx", cx);
+ LXW_PUSH_ATTRIBUTES_INT("cy", cy);
+
+ lxw_xml_empty_tag(self->file, "xdr:ext", &attributes);
+
+ LXW_FREE_ATTRIBUTES();
+}
+
+/*
+ * Write the <xdr:pos> element.
+ */
+STATIC void
+_drawing_write_pos(lxw_drawing *self, int32_t x, int32_t y)
+{
+ struct xml_attribute_list attributes;
+ struct xml_attribute *attribute;
+
+ LXW_INIT_ATTRIBUTES();
+ LXW_PUSH_ATTRIBUTES_INT("x", x);
+ LXW_PUSH_ATTRIBUTES_INT("y", y);
+
+ lxw_xml_empty_tag(self->file, "xdr:pos", &attributes);
+
+ LXW_FREE_ATTRIBUTES();
+}
+
+/*
+ * Write the <xdr:absoluteAnchor> element.
+ */
+STATIC void
+_drawing_write_absolute_anchor(lxw_drawing *self)
+{
+ lxw_xml_start_tag(self->file, "xdr:absoluteAnchor", NULL);
+
+ if (self->orientation == LXW_LANDSCAPE) {
+ /* Write the xdr:pos element. */
+ _drawing_write_pos(self, 0, 0);
+
+ /* Write the xdr:ext element. */
+ _drawing_write_ext(self, 9308969, 6078325);
+ }
+ else {
+ /* Write the xdr:pos element. */
+ _drawing_write_pos(self, 0, -47625);
+
+ /* Write the xdr:ext element. */
+ _drawing_write_ext(self, 6162675, 6124575);
+ }
+
+ _drawing_write_graphic_frame(self, 1);
+
+ /* Write the xdr:clientData element. */
+ _drawing_write_client_data(self);
+
+ lxw_xml_end_tag(self->file, "xdr:absoluteAnchor");
+}
+
/*****************************************************************************
*
* XML file assembly functions.
*
****************************************************************************/
@@ -731,10 +825,13 @@
STAILQ_FOREACH(drawing_object, self->drawing_objects, list_pointers) {
_drawing_write_two_cell_anchor(self, index, drawing_object);
index++;
}
-
+ }
+ else {
+ /* Write the xdr:absoluteAnchor element. Mainly for chartsheets. */
+ _drawing_write_absolute_anchor(self);
}
lxw_xml_end_tag(self->file, "xdr:wsDr");
}