static LsmDomDocument * _parse_memory (LsmDomDocument *document, LsmDomNode *node, const void *buffer, int size, GError **error) { static LsmDomSaxParserState state; state.document = document; if (node != NULL) state.current_node = node; else state.current_node = LSM_DOM_NODE (document); if (size < 0) size = strlen (buffer); if (xmlSAXUserParseMemory (&sax_handler, &state, buffer, size) < 0) { if (state.document != NULL) g_object_unref (state.document); state.document = NULL; lsm_debug_dom ("[LsmDomParser::from_memory] Invalid document"); g_set_error (error, LSM_DOM_DOCUMENT_ERROR, LSM_DOM_DOCUMENT_ERROR_INVALID_XML, "Invalid document."); } return state.document; }
LsmMathmlDocument * lsm_mathml_document_new_from_itex (const char *itex, int size, GError **error) { LsmDomDocument *document; char *mathml; mathml = lsm_itex_to_mathml (itex, size); if (mathml == NULL) { lsm_debug_dom ("[LsmMathmlDocument::new_from_itex] Invalid document"); g_set_error (error, LSM_MATHML_DOCUMENT_ERROR, LSM_MATHML_DOCUMENT_ERROR_INVALID_ITEX, "Invalid itex document."); return NULL; } document = lsm_dom_document_new_from_memory (mathml, -1, error); lsm_itex_free_mathml_buffer (mathml); if (document == NULL) return NULL; if (!LSM_IS_MATHML_DOCUMENT (document)) { g_object_unref (document); return NULL; } return LSM_MATHML_DOCUMENT (document); }
LsmSvgElement * lsm_svg_document_get_element_by_id (LsmSvgDocument *self, const char *id) { g_return_val_if_fail (LSM_IS_SVG_DOCUMENT (self), NULL); g_return_val_if_fail (id != NULL, NULL); lsm_debug_dom ("[LsmSvgDocument::get_element_by_id] Lookup '%s'", id); return g_hash_table_lookup (self->ids, id); }
void lsm_svg_document_register_element (LsmSvgDocument *self, LsmSvgElement *element, const char *id, const char *old_id) { g_return_if_fail (LSM_IS_SVG_DOCUMENT (self)); g_return_if_fail (LSM_IS_SVG_ELEMENT (element)); if (old_id != NULL) { lsm_debug_dom ("[LsmSvgDocument::register_element] Unregister '%s'", old_id); g_hash_table_remove (self->ids, old_id); } if (id != NULL) { char *new_id = g_strdup (id); lsm_debug_dom ("[LsmSvgDocument::register_element] Register '%s'", id); g_hash_table_replace (self->ids, new_id, element); } }
LsmDomDocument * lsm_dom_implementation_create_document (const char *namespace_uri, const char *qualified_name) { LsmDomDocumentCreateFunction create_function; g_return_val_if_fail (qualified_name != NULL, NULL); if (document_types == NULL) { lsm_dom_implementation_add_document_create_function ("math", lsm_mathml_document_new); lsm_dom_implementation_add_document_create_function ("svg", lsm_svg_document_new); } create_function = g_hash_table_lookup (document_types, qualified_name); if (create_function == NULL) { lsm_debug_dom ("[LsmDomImplementation::create_document] Unknow document type (%s)", qualified_name); return NULL; } return create_function (); }
static LsmDomElement * _create_element (LsmDomDocument *document, const char *tag_name) { LsmDomNode *node = NULL; if (strcmp (tag_name, "svg") == 0) node = lsm_svg_svg_element_new (); else if (strcmp (tag_name, "g") == 0) node = lsm_svg_g_element_new (); else if (strcmp (tag_name, "rect") == 0) node = lsm_svg_rect_element_new (); else if (strcmp (tag_name, "circle") == 0) node = lsm_svg_circle_element_new (); else if (strcmp (tag_name, "ellipse") == 0) node = lsm_svg_ellipse_element_new (); else if (strcmp (tag_name, "path") == 0) node = lsm_svg_path_element_new (); else if (strcmp (tag_name, "line") == 0) node = lsm_svg_line_element_new (); else if (strcmp (tag_name, "polyline") == 0) node = lsm_svg_polyline_element_new (); else if (strcmp (tag_name, "polygon") == 0) node = lsm_svg_polygon_element_new (); else if (strcmp (tag_name, "text") == 0) node = lsm_svg_text_element_new (); else if (strcmp (tag_name, "tspan") == 0) node = lsm_svg_tspan_element_new (); else if (strcmp (tag_name, "linearGradient") == 0) node = lsm_svg_linear_gradient_element_new (); else if (strcmp (tag_name, "radialGradient") == 0) node = lsm_svg_radial_gradient_element_new (); else if (strcmp (tag_name, "stop") == 0) node = lsm_svg_stop_element_new (); else if (strcmp (tag_name, "pattern") == 0) node = lsm_svg_pattern_element_new (); else if (strcmp (tag_name, "mask") == 0) node = lsm_svg_mask_element_new (); else if (strcmp (tag_name, "use") == 0) node = lsm_svg_use_element_new (); else if (strcmp (tag_name, "image") == 0) node = lsm_svg_image_element_new (); else if (strcmp (tag_name, "defs") == 0) node = lsm_svg_defs_element_new (); else if (strcmp (tag_name, "symbol") == 0) node = lsm_svg_symbol_element_new (); else if (strcmp (tag_name, "marker") == 0) node = lsm_svg_marker_element_new (); else if (strcmp (tag_name, "clipPath") == 0) node = lsm_svg_clip_path_element_new (); else if (strcmp (tag_name, "switch") == 0) node = lsm_svg_switch_element_new (); else if (strcmp (tag_name, "a") == 0) node = lsm_svg_a_element_new (); else if (strcmp (tag_name, "filter") == 0) node = lsm_svg_filter_element_new (); else if (strcmp (tag_name, "feBlend") == 0) node = lsm_svg_filter_blend_new (); else if (strcmp (tag_name, "feComposite") == 0) node = lsm_svg_filter_composite_new (); else if (strcmp (tag_name, "feColorMatrix") == 0) node = lsm_svg_filter_color_matrix_new (); else if (strcmp (tag_name, "feConvolveMatrix") == 0) node = lsm_svg_filter_convolve_matrix_new (); else if (strcmp (tag_name, "feDisplacementMap") == 0) node = lsm_svg_filter_displacement_map_new (); else if (strcmp (tag_name, "feFlood") == 0) node = lsm_svg_filter_flood_new (); else if (strcmp (tag_name, "feGaussianBlur") == 0) node = lsm_svg_filter_gaussian_blur_new (); else if (strcmp (tag_name, "feImage") == 0) node = lsm_svg_filter_image_new (); else if (strcmp (tag_name, "feMerge") == 0) node = lsm_svg_filter_merge_new (); else if (strcmp (tag_name, "feMergeNode") == 0) node = lsm_svg_filter_merge_node_new (); else if (strcmp (tag_name, "feMorphology") == 0) node = lsm_svg_filter_morphology_new (); else if (strcmp (tag_name, "feOffset") == 0) node = lsm_svg_filter_offset_new (); else if (strcmp (tag_name, "feSpecularLighting") == 0) node = lsm_svg_filter_specular_lighting_new (); else if (strcmp (tag_name, "feTile") == 0) node = lsm_svg_filter_tile_new (); else if (strcmp (tag_name, "feTurbulence") == 0) node = lsm_svg_filter_turbulence_new (); if (node != NULL) lsm_debug_dom ("[LsmSvgDocument::create_element] Create a %s element", tag_name); return LSM_DOM_ELEMENT (node); }
static LsmDomElement * _create_element (LsmDomDocument *document, const char *tag_name) { LsmDomNode *node = NULL; if (strcmp (tag_name, "math") == 0) node = lsm_mathml_math_element_new (); else if (strcmp (tag_name, "mtable") == 0) node = lsm_mathml_table_element_new (); else if (strcmp (tag_name, "mtr") == 0) node = lsm_mathml_table_row_element_new (); else if (strcmp (tag_name, "mlabeledtr") == 0) node = lsm_mathml_labeled_table_row_element_new (); else if (strcmp (tag_name, "mtd") == 0) node = lsm_mathml_table_cell_element_new (); else if (strcmp (tag_name, "mspace") == 0) node = lsm_mathml_space_element_new (); else if (strcmp (tag_name, "msqrt") == 0) node = lsm_mathml_sqrt_element_new (); else if (strcmp (tag_name, "mroot") == 0) node = lsm_mathml_root_element_new (); else if (strcmp (tag_name, "msub") == 0) node = lsm_mathml_sub_element_new (); else if (strcmp (tag_name, "msup") == 0) node = lsm_mathml_sup_element_new (); else if (strcmp (tag_name, "msubsup") == 0) node = lsm_mathml_sub_sup_element_new (); else if (strcmp (tag_name, "mfrac") == 0) node = lsm_mathml_fraction_element_new (); else if (strcmp (tag_name, "munder") == 0) node = lsm_mathml_under_element_new (); else if (strcmp (tag_name, "mover") == 0) node = lsm_mathml_over_element_new (); else if (strcmp (tag_name, "munderover") == 0) node = lsm_mathml_under_over_element_new (); else if (strcmp (tag_name, "mo") == 0) node = lsm_mathml_operator_element_new (); else if (strcmp (tag_name, "mrow") == 0) node = lsm_mathml_row_element_new (); else if (strcmp (tag_name, "mn") == 0) node = lsm_mathml_number_element_new (); else if (strcmp (tag_name, "mi") == 0) node = lsm_mathml_identifier_element_new (); else if (strcmp (tag_name, "mtext") == 0) node = lsm_mathml_text_element_new (); else if (strcmp (tag_name, "ms") == 0) node = lsm_mathml_string_element_new (); else if (strcmp (tag_name, "mstyle") == 0) node = lsm_mathml_style_element_new (); else if (strcmp (tag_name, "mphantom") == 0) node = lsm_mathml_phantom_element_new (); else if (strcmp (tag_name, "mpadded") == 0) node = lsm_mathml_padded_element_new (); else if (strcmp (tag_name, "mfenced") == 0) node = lsm_mathml_fenced_element_new (); else if (strcmp (tag_name, "merror") == 0) node = lsm_mathml_error_element_new (); else if (strcmp (tag_name, "maction") == 0) node = lsm_mathml_action_element_new (); else if (strcmp (tag_name, "malignmark") == 0) node = lsm_mathml_align_mark_element_new (); else if (strcmp (tag_name, "maligngroup") == 0) node = lsm_mathml_align_group_element_new (); else if (strcmp (tag_name, "semantics") == 0) node = lsm_mathml_semantics_element_new (); else if (strcmp (tag_name, "lasem:itex") == 0) node = lsm_mathml_itex_element_new (); else lsm_debug_dom ("[MathmlDocument::create_element] Unknown tag (%s)", tag_name); return LSM_DOM_ELEMENT (node); }