[lasem] render: allows to give an element to render
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lasem] render: allows to give an element to render
- Date: Tue, 28 Jun 2016 18:59:45 +0000 (UTC)
commit 449c86f8ae73b272a2b70d64b3f3a1b329cd20da
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Tue Jun 28 20:55:51 2016 +0200
render: allows to give an element to render
Only SVG is supported for now. It only hides other elements and doesn't
affect the rendered image size.
src/lasemrender.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 47 insertions(+), 1 deletions(-)
---
diff --git a/src/lasemrender.c b/src/lasemrender.c
index de2ca2f..f797277 100644
--- a/src/lasemrender.c
+++ b/src/lasemrender.c
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <lsm.h>
#include <lsmmathml.h>
+#include <lsmsvg.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
@@ -39,6 +40,7 @@ static char *option_debug_domains = NULL;
static char *option_output_file_format = NULL;
static char **option_input_filenames = NULL;
static char *option_output_filename = NULL;
+static char *option_element_id = NULL;
double option_ppi = 72.0;
double option_zoom = 1.0;
@@ -70,12 +72,49 @@ static const GOptionEntry entries[] =
&option_ppi, N_("Pixel per inch"), NULL },
{ "zoom", 'z', 0, G_OPTION_ARG_DOUBLE,
&option_zoom, N_("Zoom"), NULL },
+ { "id", 'i', 0, G_OPTION_ARG_STRING,
+ &option_element_id, N_("Element id"), NULL },
{ "debug", 'd', 0, G_OPTION_ARG_STRING,
&option_debug_domains, N_("Debug domains"), NULL },
{ NULL }
};
-int main(int argc, char **argv)
+static gboolean
+_hide_before_object (LsmDomDocument *document, const char *id)
+{
+ LsmDomNode *node;
+ LsmDomNode *sibling;
+ LsmDomNode *parent;
+
+ /* TODO: Handle other document types */
+ if (!LSM_IS_SVG_DOCUMENT (document)) {
+ fprintf (stderr, "%s\n", _("Invalid document type (SVG expected)"));
+ return FALSE;
+ }
+
+ node = LSM_DOM_NODE (lsm_svg_document_get_element_by_id (LSM_SVG_DOCUMENT (document), id));
+ if (!LSM_IS_DOM_NODE (node)) {
+ fprintf (stderr, _("Element '%s' not found"), id);
+ fprintf (stderr, "\n");
+ return FALSE;
+ }
+
+ for (parent = lsm_dom_node_get_parent_node (node);
+ LSM_IS_DOM_NODE (parent);
+ node = parent, parent = lsm_dom_node_get_parent_node (parent)) {
+ for (sibling = lsm_dom_node_get_first_child (parent);
+ LSM_IS_DOM_NODE (sibling);
+ sibling = lsm_dom_node_get_next_sibling (sibling)) {
+ if (sibling != node && LSM_IS_SVG_ELEMENT (sibling))
+ lsm_dom_element_set_attribute (LSM_DOM_ELEMENT (sibling), "display", "none");
+ }
+ }
+
+ return TRUE;
+}
+
+int
+main(int argc, char **argv)
{
LsmDomDocument *document;
LsmDomView *view;
@@ -187,6 +226,13 @@ int main(int argc, char **argv)
}
}
+ if (document != NULL && option_element_id != NULL) {
+ if (!_hide_before_object (document, option_element_id)) {
+ g_object_unref (document);
+ return EXIT_FAILURE;
+ }
+ }
+
if (document != NULL) {
if (lsm_debug_check (&lsm_debug_category_dom, LSM_DEBUG_LEVEL_LOG)) {
void *buffer;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]