From 7256870b60b9aa34b538a1d4b59fe455aefbcb29 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Tue, 8 Jun 2004 02:41:32 +0000 Subject: [PATCH] Don't touch compression of original file -- still defaults to 9 for new files. Original patch provided by Javier Donaire Segarra (#912252 in patch tracker). git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@425 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/src/label.c | 32 ++++++++++++++++++++++++++++++++ glabels2/src/label.h | 5 +++++ glabels2/src/xml-label.c | 4 +++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/glabels2/src/label.c b/glabels2/src/label.c index 84a3620f..a5f6de22 100644 --- a/glabels2/src/label.c +++ b/glabels2/src/label.c @@ -45,6 +45,7 @@ struct _glLabelPrivate { gboolean rotate_flag; gchar *filename; + gint compression; gboolean modified_flag; gint untitled_instance; @@ -230,6 +231,8 @@ gl_label_new (void) label = g_object_new (gl_label_get_type(), NULL); + label->private->compression = 9; + label->private->modified_flag = FALSE; gl_debug (DEBUG_LABEL, "END"); @@ -654,4 +657,33 @@ gl_label_clear_modified (glLabel *label) } +/****************************************************************************/ +/* Set compression level. */ +/****************************************************************************/ +void +gl_label_set_compression (glLabel *label, + gint compression) +{ + gl_debug (DEBUG_LABEL, "set %d", compression); + + /* Older versions of libxml2 always return a -1 for documents "read in," so + * default to 9. Also, default to 9 for anything else out of range. */ + if ((compression < 0) || (compression >9)) { + compression = 9; + } + + gl_debug (DEBUG_LABEL, "actual set %d", compression); + label->private->compression = compression; +} + + +/****************************************************************************/ +/* Get compression level. */ +/****************************************************************************/ +gint +gl_label_get_compression (glLabel *label) +{ + gl_debug (DEBUG_LABEL, "return %d", label->private->compression); + return label->private->compression; +} diff --git a/glabels2/src/label.h b/glabels2/src/label.h index f901180b..791dbd23 100644 --- a/glabels2/src/label.h +++ b/glabels2/src/label.h @@ -126,6 +126,11 @@ void gl_label_set_filename (glLabel *label, void gl_label_clear_modified (glLabel *label); +void gl_label_set_compression (glLabel *label, + gint compression); + +gint gl_label_get_compression (glLabel *label); + G_END_DECLS diff --git a/glabels2/src/xml-label.c b/glabels2/src/xml-label.c index d90c89e9..067fe41e 100644 --- a/glabels2/src/xml-label.c +++ b/glabels2/src/xml-label.c @@ -255,6 +255,8 @@ xml_doc_to_label (xmlDocPtr doc, ns = xmlSearchNsByHref (doc, root, GL_XML_NAME_SPACE); if (ns != NULL) { label = xml_parse_label (root, status); + if (label) + gl_label_set_compression (label, xmlGetDocCompressMode (doc)); } else { /* Try compatability mode 0.1 */ ns = xmlSearchNsByHref (doc, root, COMPAT01_NAME_SPACE); @@ -952,7 +954,7 @@ gl_xml_label_save (glLabel *label, if (!filename) g_warning (_("Utf8 conversion error.")); else { - xmlSetDocCompressMode (doc, 9); + xmlSetDocCompressMode (doc, gl_label_get_compression (label)); xml_ret = xmlSaveFormatFile (filename, doc, TRUE); xmlFreeDoc (doc); if (xml_ret == -1) { -- 2.39.5