1 /* 2 * GPAC - Multimedia Framework C SDK 3 * 4 * Authors: Jean Le Feuvre - Cyril Concolato 5 * Copyright (c) Telecom ParisTech 2004-2019 6 * All rights reserved 7 * 8 * This file is part of GPAC / SVG Scene Graph sub-project 9 * 10 * GPAC is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License as published by 12 * the Free Software Foundation; either version 2, or (at your option) 13 * any later version. 14 * 15 * GPAC is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; see the file COPYING. If not, write to 22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 23 * 24 */ 25 26 #ifndef _GF_SG_SVG_H_ 27 #define _GF_SG_SVG_H_ 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /*! 34 \file <gpac/scenegraph_svg.h> 35 \brief Scenegraph for SVG files 36 */ 37 38 /*! 39 \addtogroup ssvg SVG Scenegraph 40 \ingroup scene_grp 41 \brief Scenegraph for SVG files. 42 43 This section documents the Scenegraph for SVG files. 44 45 @{ 46 */ 47 48 49 #include <gpac/scenegraph.h> 50 #include <gpac/svg_types.h> 51 52 53 /******************************************************************************* 54 * 55 * DOM base scene graph 56 * 57 *******************************************************************************/ 58 /*! DOM attributes tags for xmlspace, xmlev, xlink, SVG and LASeR*/ 59 enum 60 { 61 /*should never be used, this is only a parsing error*/ 62 TAG_DOM_ATTRIBUTE_NULL, 63 /*this tag is set for a full dom attribute only - attribute name is then available*/ 64 TAG_DOM_ATT_any, 65 66 TAG_XML_ATT_RANGE_FIRST, 67 TAG_XML_ATT_id = TAG_XML_ATT_RANGE_FIRST, 68 TAG_XML_ATT_base, 69 TAG_XML_ATT_lang, 70 TAG_XML_ATT_space, 71 TAG_XML_ATT_RANGE_LAST, 72 TAG_XLINK_ATT_RANGE_FIRST, 73 74 TAG_XLINK_ATT_type = TAG_XLINK_ATT_RANGE_FIRST, 75 TAG_XLINK_ATT_role, 76 TAG_XLINK_ATT_arcrole, 77 TAG_XLINK_ATT_title, 78 TAG_XLINK_ATT_href, 79 TAG_XLINK_ATT_show, 80 TAG_XLINK_ATT_actuate, 81 TAG_XLINK_ATT_RANGE_LAST, 82 83 TAG_XMLEV_ATT_RANGE_FIRST, 84 TAG_XMLEV_ATT_event, 85 TAG_XMLEV_ATT_phase, 86 TAG_XMLEV_ATT_propagate, 87 TAG_XMLEV_ATT_defaultAction, 88 TAG_XMLEV_ATT_observer, 89 TAG_XMLEV_ATT_target, 90 TAG_XMLEV_ATT_handler, 91 TAG_XMLEV_ATT_RANGE_LAST, 92 93 TAG_LSR_ATT_RANGE_FIRST, 94 TAG_LSR_ATT_enabled, 95 TAG_LSR_ATT_RANGE_LAST, 96 /*these attribute types are only use for binary purpose*/ 97 TAG_LSR_ATT_children, 98 TAG_LSR_ATT_overflow, 99 TAG_LSR_ATT_rotation, 100 TAG_LSR_ATT_scale, 101 TAG_LSR_ATT_translation, 102 TAG_LSR_ATT_svg_width, 103 TAG_LSR_ATT_svg_height, 104 TAG_LSR_ATT_textContent, 105 TAG_LSR_ATT_text_display, 106 107 TAG_SVG_ATT_RANGE_FIRST, 108 109 TAG_SVG_ATT_id = TAG_SVG_ATT_RANGE_FIRST, 110 TAG_SVG_ATT__class, 111 TAG_SVG_ATT_requiredFeatures, 112 TAG_SVG_ATT_requiredExtensions, 113 TAG_SVG_ATT_requiredFormats, 114 TAG_SVG_ATT_requiredFonts, 115 TAG_SVG_ATT_systemLanguage, 116 TAG_SVG_ATT_display, 117 TAG_SVG_ATT_visibility, 118 TAG_SVG_ATT_image_rendering, 119 TAG_SVG_ATT_pointer_events, 120 TAG_SVG_ATT_shape_rendering, 121 TAG_SVG_ATT_text_rendering, 122 TAG_SVG_ATT_audio_level, 123 TAG_SVG_ATT_viewport_fill, 124 TAG_SVG_ATT_viewport_fill_opacity, 125 TAG_SVG_ATT_overflow, 126 TAG_SVG_ATT_fill_opacity, 127 TAG_SVG_ATT_stroke_opacity, 128 TAG_SVG_ATT_fill, 129 TAG_SVG_ATT_fill_rule, 130 TAG_SVG_ATT_filter, 131 TAG_SVG_ATT_stroke, 132 TAG_SVG_ATT_stroke_dasharray, 133 TAG_SVG_ATT_stroke_dashoffset, 134 TAG_SVG_ATT_stroke_linecap, 135 TAG_SVG_ATT_stroke_linejoin, 136 TAG_SVG_ATT_stroke_miterlimit, 137 TAG_SVG_ATT_stroke_width, 138 TAG_SVG_ATT_color, 139 TAG_SVG_ATT_color_rendering, 140 TAG_SVG_ATT_vector_effect, 141 TAG_SVG_ATT_solid_color, 142 TAG_SVG_ATT_solid_opacity, 143 TAG_SVG_ATT_display_align, 144 TAG_SVG_ATT_line_increment, 145 TAG_SVG_ATT_stop_color, 146 TAG_SVG_ATT_stop_opacity, 147 TAG_SVG_ATT_font_family, 148 TAG_SVG_ATT_font_size, 149 TAG_SVG_ATT_font_style, 150 TAG_SVG_ATT_font_variant, 151 TAG_SVG_ATT_font_weight, 152 TAG_SVG_ATT_text_anchor, 153 TAG_SVG_ATT_text_align, 154 TAG_SVG_ATT_text_decoration, 155 TAG_SVG_ATT_focusHighlight, 156 TAG_SVG_ATT_externalResourcesRequired, 157 TAG_SVG_ATT_focusable, 158 TAG_SVG_ATT_nav_next, 159 TAG_SVG_ATT_nav_prev, 160 TAG_SVG_ATT_nav_up, 161 TAG_SVG_ATT_nav_up_right, 162 TAG_SVG_ATT_nav_right, 163 TAG_SVG_ATT_nav_down_right, 164 TAG_SVG_ATT_nav_down, 165 TAG_SVG_ATT_nav_down_left, 166 TAG_SVG_ATT_nav_left, 167 TAG_SVG_ATT_nav_up_left, 168 TAG_SVG_ATT_transform, 169 TAG_SVG_ATT_target, 170 TAG_SVG_ATT_attributeName, 171 TAG_SVG_ATT_attributeType, 172 TAG_SVG_ATT_begin, 173 TAG_SVG_ATT_dur, 174 TAG_SVG_ATT_end, 175 TAG_SVG_ATT_repeatCount, 176 TAG_SVG_ATT_repeatDur, 177 TAG_SVG_ATT_restart, 178 TAG_SVG_ATT_smil_fill, 179 TAG_SVG_ATT_min, 180 TAG_SVG_ATT_max, 181 TAG_SVG_ATT_to, 182 TAG_SVG_ATT_calcMode, 183 TAG_SVG_ATT_values, 184 TAG_SVG_ATT_keyTimes, 185 TAG_SVG_ATT_keySplines, 186 TAG_SVG_ATT_from, 187 TAG_SVG_ATT_by, 188 TAG_SVG_ATT_additive, 189 TAG_SVG_ATT_accumulate, 190 TAG_SVG_ATT_path, 191 TAG_SVG_ATT_keyPoints, 192 TAG_SVG_ATT_rotate, 193 TAG_SVG_ATT_origin, 194 TAG_SVG_ATT_transform_type, 195 TAG_SVG_ATT_clipBegin, 196 TAG_SVG_ATT_clipEnd, 197 TAG_SVG_ATT_syncBehavior, 198 TAG_SVG_ATT_syncTolerance, 199 TAG_SVG_ATT_syncMaster, 200 TAG_SVG_ATT_syncReference, 201 TAG_SVG_ATT_x, 202 TAG_SVG_ATT_y, 203 TAG_SVG_ATT_width, 204 TAG_SVG_ATT_height, 205 TAG_SVG_ATT_preserveAspectRatio, 206 TAG_SVG_ATT_initialVisibility, 207 TAG_SVG_ATT_type, 208 TAG_SVG_ATT_cx, 209 TAG_SVG_ATT_cy, 210 TAG_SVG_ATT_r, 211 TAG_SVG_ATT_cursorManager_x, 212 TAG_SVG_ATT_cursorManager_y, 213 TAG_SVG_ATT_rx, 214 TAG_SVG_ATT_ry, 215 TAG_SVG_ATT_horiz_adv_x, 216 TAG_SVG_ATT_horiz_origin_x, 217 TAG_SVG_ATT_font_stretch, 218 TAG_SVG_ATT_unicode_range, 219 TAG_SVG_ATT_panose_1, 220 TAG_SVG_ATT_widths, 221 TAG_SVG_ATT_bbox, 222 TAG_SVG_ATT_units_per_em, 223 TAG_SVG_ATT_stemv, 224 TAG_SVG_ATT_stemh, 225 TAG_SVG_ATT_slope, 226 TAG_SVG_ATT_cap_height, 227 TAG_SVG_ATT_x_height, 228 TAG_SVG_ATT_accent_height, 229 TAG_SVG_ATT_ascent, 230 TAG_SVG_ATT_descent, 231 TAG_SVG_ATT_ideographic, 232 TAG_SVG_ATT_alphabetic, 233 TAG_SVG_ATT_mathematical, 234 TAG_SVG_ATT_hanging, 235 TAG_SVG_ATT_underline_position, 236 TAG_SVG_ATT_underline_thickness, 237 TAG_SVG_ATT_strikethrough_position, 238 TAG_SVG_ATT_strikethrough_thickness, 239 TAG_SVG_ATT_overline_position, 240 TAG_SVG_ATT_overline_thickness, 241 TAG_SVG_ATT_d, 242 TAG_SVG_ATT_unicode, 243 TAG_SVG_ATT_glyph_name, 244 TAG_SVG_ATT_arabic_form, 245 TAG_SVG_ATT_lang, 246 TAG_SVG_ATT_u1, 247 TAG_SVG_ATT_g1, 248 TAG_SVG_ATT_u2, 249 TAG_SVG_ATT_g2, 250 TAG_SVG_ATT_k, 251 TAG_SVG_ATT_opacity, 252 TAG_SVG_ATT_x1, 253 TAG_SVG_ATT_y1, 254 TAG_SVG_ATT_x2, 255 TAG_SVG_ATT_y2, 256 TAG_SVG_ATT_filterUnits, 257 TAG_SVG_ATT_gradientUnits, 258 TAG_SVG_ATT_spreadMethod, 259 TAG_SVG_ATT_gradientTransform, 260 TAG_SVG_ATT_pathLength, 261 TAG_SVG_ATT_points, 262 TAG_SVG_ATT_mediaSize, 263 TAG_SVG_ATT_mediaTime, 264 TAG_SVG_ATT_mediaCharacterEncoding, 265 TAG_SVG_ATT_mediaContentEncodings, 266 TAG_SVG_ATT_bandwidth, 267 TAG_SVG_ATT_fx, 268 TAG_SVG_ATT_fy, 269 TAG_SVG_ATT_size, 270 TAG_SVG_ATT_choice, 271 TAG_SVG_ATT_delta, 272 TAG_SVG_ATT_offset, 273 TAG_SVG_ATT_syncBehaviorDefault, 274 TAG_SVG_ATT_syncToleranceDefault, 275 TAG_SVG_ATT_viewBox, 276 TAG_SVG_ATT_zoomAndPan, 277 TAG_SVG_ATT_version, 278 TAG_SVG_ATT_baseProfile, 279 TAG_SVG_ATT_contentScriptType, 280 TAG_SVG_ATT_snapshotTime, 281 TAG_SVG_ATT_timelineBegin, 282 TAG_SVG_ATT_playbackOrder, 283 TAG_SVG_ATT_editable, 284 TAG_SVG_ATT_text_x, 285 TAG_SVG_ATT_text_y, 286 TAG_SVG_ATT_text_rotate, 287 TAG_SVG_ATT_transformBehavior, 288 TAG_SVG_ATT_overlay, 289 TAG_SVG_ATT_fullscreen, 290 TAG_SVG_ATT_motionTransform, 291 292 TAG_SVG_ATT_filter_transfer_type, 293 TAG_SVG_ATT_filter_table_values, 294 TAG_SVG_ATT_filter_intercept, 295 TAG_SVG_ATT_filter_amplitude, 296 TAG_SVG_ATT_filter_exponent, 297 298 299 TAG_GSVG_ATT_useAsPrimary, 300 TAG_GSVG_ATT_depthOffset, 301 TAG_GSVG_ATT_depthGain, 302 }; 303 304 /*! macro for DOM base attribute*/ 305 #define GF_DOM_BASE_ATTRIBUTE \ 306 u16 tag; /*attribute identifier*/ \ 307 u16 data_type; /*attribute datatype*/ \ 308 void *data; /*data pointer*/ \ 309 struct __dom_base_attribute *next; /*next attribute*/ 310 311 /*! macro for DOM full attribute*/ 312 #define GF_DOM_FULL_ATTRIBUTE \ 313 GF_DOM_ATTRIBUTE \ 314 315 /*! DOM attribute*/ 316 typedef struct __dom_base_attribute 317 { 318 GF_DOM_BASE_ATTRIBUTE 319 } GF_DOMAttribute; 320 321 /*! DOM full attribute*/ 322 typedef struct __dom_full_attribute 323 { 324 GF_DOM_BASE_ATTRIBUTE 325 u32 xmlns; 326 char *name; /*attribute name - in this case, the data field is the attribute literal value*/ 327 } GF_DOMFullAttribute; 328 329 /*! macro for DOM base node*/ 330 #define GF_DOM_BASE_NODE \ 331 BASE_NODE \ 332 CHILDREN \ 333 GF_DOMAttribute *attributes; 334 335 /*! DOM base node*/ 336 typedef struct __dom_base_node 337 { 338 GF_DOM_BASE_NODE 339 } GF_DOMNode; 340 341 /*! DOM full node*/ 342 typedef struct __dom_full_node 343 { 344 GF_DOM_BASE_NODE 345 char *name; 346 u32 ns; 347 } GF_DOMFullNode; 348 349 /*! DOM built-in namespaces*/ 350 typedef enum 351 { 352 /*XMLNS is undefined*/ 353 GF_XMLNS_UNDEFINED = 0, 354 355 GF_XMLNS_XML, 356 GF_XMLNS_XLINK, 357 GF_XMLNS_XMLEV, 358 GF_XMLNS_LASER, 359 GF_XMLNS_SVG, 360 GF_XMLNS_XBL, 361 362 GF_XMLNS_SVG_GPAC_EXTENSION, 363 364 /*any other namespace uses the CRC32 of the namespace as an identifier*/ 365 } GF_NamespaceType; 366 367 /*! gets built-in XMLNS id for this namespace 368 \param name name of the namespace 369 \return namespace ID if known, otherwise GF_XMLNS_UNDEFINED*/ 370 GF_NamespaceType gf_xml_get_namespace_id(char *name); 371 /*! adds a new namespace 372 \param sg the target scene graph 373 \param name name of the namespace (full URL) 374 \param qname QName of the namespace (short name in doc, eg "ev") 375 \return error if any 376 */ 377 GF_Err gf_sg_add_namespace(GF_SceneGraph *sg, char *name, char *qname); 378 /*! removes a new namespace 379 \param sg the target scene graph 380 \param name name of the namespace 381 \param qname QName of the namespace 382 \return error if any 383 */ 384 GF_Err gf_sg_remove_namespace(GF_SceneGraph *sg, char *name, char *qname); 385 /*! gets namespace code 386 \param sg the target scene graph 387 \param qname QName of the namespace 388 \return namespace code 389 */ 390 GF_NamespaceType gf_sg_get_namespace_code(GF_SceneGraph *sg, char *qname); 391 /*! gets namespace code from name 392 \param sg the target scene graph 393 \param name name of the namespace 394 \return namespace code 395 */ 396 GF_NamespaceType gf_sg_get_namespace_code_from_name(GF_SceneGraph *sg, char *name); 397 398 /*! gets namespace qname from ID 399 \param sg the target scene graph 400 \param xmlns_id ID of the namespace 401 \return namespace qname 402 */ 403 const char *gf_sg_get_namespace_qname(GF_SceneGraph *sg, GF_NamespaceType xmlns_id); 404 /*! gets namespace from ID 405 \param sg the target scene graph 406 \param xmlns_id ID of the namespace 407 \return namespace name 408 */ 409 const char *gf_sg_get_namespace(GF_SceneGraph *sg, GF_NamespaceType xmlns_id); 410 /*! push namespace parsing state 411 \param elt the current node being parsed 412 */ 413 void gf_xml_push_namespaces(GF_DOMNode *elt); 414 /*! pop namespace parsing state 415 \param elt the current node being parsed 416 */ 417 void gf_xml_pop_namespaces(GF_DOMNode *elt); 418 419 /*! gets namespace of an element 420 \param n the target node 421 \return namespace ID 422 */ 423 GF_NamespaceType gf_xml_get_element_namespace(GF_Node *n); 424 425 426 /*! DOM text node type*/ 427 enum 428 { 429 /*! regular text*/ 430 GF_DOM_TEXT_REGULAR = 0, 431 /*! CDATA section*/ 432 GF_DOM_TEXT_CDATA, 433 /*! inserted text node (typically external script)*/ 434 GF_DOM_TEXT_INSERTED 435 }; 436 437 /*! DOM text node*/ 438 typedef struct 439 { 440 BASE_NODE 441 CHILDREN 442 char *textContent; 443 u32 type; 444 } GF_DOMText; 445 446 /*! creates a new text node, assign string (does NOT duplicate it) and register node with parent if desired 447 \param parent the target parent node 448 \param text_data UTF-8 data to add as a text node 449 \return the new inserted DOM text node or NULL if error 450 */ 451 GF_DOMText *gf_dom_add_text_node(GF_Node *parent, char *text_data); 452 453 /*! replaces text content of node by the specified string 454 \param n the target DOM node 455 \param text the replacement string in UTF-8. If NULL, only resets the children of the node data to add as a text node 456 */ 457 void gf_dom_set_textContent(GF_Node *n, char *text); 458 459 /*! flattens text content of the node 460 \param n the target DOM node 461 \return the flattened text - shall be free'ed by the caller*/ 462 char *gf_dom_flatten_textContent(GF_Node *n); 463 464 /*! creates a new text node - this DOES NOT register the node 465 \param sg the target scene graph for the node 466 \return the new text node*/ 467 GF_DOMText *gf_dom_new_text_node(GF_SceneGraph *sg); 468 469 /*! DOM update (DIMS/LASeR) node*/ 470 typedef struct 471 { 472 BASE_NODE 473 CHILDREN 474 char *data; 475 u32 data_size; 476 GF_List *updates; 477 } GF_DOMUpdates; 478 479 /*! creates a new updates node and register node with parent 480 \param parent the target parent node 481 \return a new DOM updates node 482 */ 483 GF_DOMUpdates *gf_dom_add_updates_node(GF_Node *parent); 484 485 /*! DOM Event phases*/ 486 typedef enum 487 { 488 GF_DOM_EVENT_PHASE_CAPTURE = 1, 489 GF_DOM_EVENT_PHASE_AT_TARGET = 2, 490 GF_DOM_EVENT_PHASE_BUBBLE = 3, 491 492 GF_DOM_EVENT_CANCEL_MASK = 0xE0, 493 /*special phase indicating the event has been canceled*/ 494 GF_DOM_EVENT_PHASE_CANCEL = 1<<5, 495 /*special phase indicating the event has been canceled immediately*/ 496 GF_DOM_EVENT_PHASE_CANCEL_ALL = 1<<6, 497 /*special phase indicating the default action of the event is prevented*/ 498 GF_DOM_EVENT_PHASE_PREVENT = 1<<7, 499 } GF_DOMEventPhase; 500 501 /*! DOM Event possible targets*/ 502 typedef enum 503 { 504 GF_DOM_EVENT_TARGET_NODE, 505 GF_DOM_EVENT_TARGET_DOCUMENT, 506 GF_DOM_EVENT_TARGET_MSE_MEDIASOURCE, 507 GF_DOM_EVENT_TARGET_MSE_SOURCEBUFFERLIST, 508 GF_DOM_EVENT_TARGET_MSE_SOURCEBUFFER, 509 GF_DOM_EVENT_TARGET_XHR, 510 } GF_DOMEventTargetType; 511 512 513 /*! DOM EventTarget Interface*/ 514 typedef struct 515 { 516 /*! list of SVG Listener nodes attached to this Event Target*/ 517 GF_List *listeners; 518 /*! pointer to the object implementing the DOM Event Target Interface*/ 519 void *ptr; 520 /*! type of the object implementing the DOM Event Target Interface*/ 521 GF_DOMEventTargetType ptr_type; 522 } GF_DOMEventTarget; 523 524 /*! creates a new event target 525 \param type the type of the event target 526 \param obj opaque data passed to the event target 527 \return a new DOM event target 528 */ 529 GF_DOMEventTarget *gf_dom_event_target_new(GF_DOMEventTargetType type, void *obj); 530 /*! associates a listener node and a event target node 531 - adds the listener node in the list of event listener nodes for the target node 532 - sets the target node as the user of the listener 533 \param listener the target listener 534 \param evt_target the event target 535 \return error if any 536 */ 537 GF_Err gf_sg_listener_associate(GF_Node *listener, GF_DOMEventTarget *evt_target); 538 539 /*! DOM Event media information*/ 540 typedef struct 541 { 542 Bool bufferValid; 543 u32 level; 544 Fixed remaining_time; 545 u16 status; 546 const char *session_name; 547 u64 loaded_size, total_size; 548 } GF_DOMMediaEvent; 549 550 /*! DOM Event structure*/ 551 typedef struct 552 { 553 /*event type, as defined in <gpac/events.h>*/ 554 GF_EventType type; 555 /*event phase type, READ-ONLY 556 0: at target, 1: bubbling, 2: capturing , 3: canceled 557 */ 558 u8 event_phase; 559 u8 bubbles; 560 u8 cancelable; 561 /*output only - indicates UI events (mouse) have been detected*/ 562 u8 has_ui_events; 563 564 /*we don't use a GF_DOMEventTarget here since the structure is only created when events are attached */ 565 void *target; 566 GF_DOMEventTargetType target_type; 567 568 GF_DOMEventTarget *currentTarget; 569 Double timestamp; 570 /*UIEvent extension. 571 For mouse extensions: number of clicks 572 For key event: the key code 573 For SMIL event: number of iteration (repeat) 574 */ 575 u32 detail; 576 577 /*MouseEvent extension*/ 578 s32 screenX, screenY; 579 s32 clientX, clientY; 580 u32 button; 581 /*key flags*/ 582 u32 key_flags; 583 /*key hardware code*/ 584 u32 key_hw_code; 585 GF_Node *relatedTarget; 586 /*Zoom event*/ 587 GF_Rect screen_rect; 588 GF_Point2D prev_translate, new_translate; 589 Fixed prev_scale, new_scale; 590 /* CPU */ 591 u32 cpu_percentage; 592 /* Battery */ 593 Bool onBattery; 594 u32 batteryState, batteryLevel; 595 /*smil event time*/ 596 Double smil_event_time; 597 /* mutation event */ 598 GF_Node *relatedNode; 599 600 /*DOM event used in VRML (GPAC's internal)*/ 601 Bool is_vrml; 602 /*media event*/ 603 GF_DOMMediaEvent media_event; 604 605 /*number of listeners triggered by the event*/ 606 u32 consumed; 607 608 /*for GF_EVENT_ATTR_MODIFIED*/ 609 GF_FieldInfo *attr; 610 GF_Err error_state; 611 612 /* ADDON_DETECTED event*/ 613 const char *addon_url; 614 } GF_DOM_Event; 615 616 /*! fires an event on the specified node 617 \warning event execution may very well destroy ANY node, especially the event target node !! 618 \param node the target node 619 \param event the DOM event 620 \return GF_TRUE if event is consumed/aborted after this call, GF_FALSE otherwise (event now pending) 621 */ 622 Bool gf_dom_event_fire(GF_Node *node, GF_DOM_Event *event); 623 /*! fires a DOM event on the specified node 624 \warning event execution may very well destroy ANY node, especially the event target node !! 625 \param et the event target 626 \param event the dom event 627 \param sg the parent graph 628 \param n the event current target, can be NULL 629 \return GF_TRUE if event is consumed/aborted after this call, GF_FALSE otherwise (event now pending) 630 */ 631 Bool gf_sg_fire_dom_event(GF_DOMEventTarget *et, GF_DOM_Event *event, GF_SceneGraph *sg, GF_Node *n); 632 633 /*! fires event on the specified node 634 \warning event execution may very well destroy ANY node, especially the event target node !! 635 \param node the target node 636 \param event the DOM event 637 \param use_stack a list of parent node/use node pairs for bubbling phase - may be NULL 638 \return GF_TRUE if event is consumed/aborted after this call, GF_FALSE otherwise (event now pending) 639 */ 640 Bool gf_dom_event_fire_ex(GF_Node *node, GF_DOM_Event *event, GF_List *use_stack); 641 642 /*! gets event type by name 643 \param name the event name 644 \return the event type*/ 645 GF_EventType gf_dom_event_type_by_name(const char *name); 646 /*! gets event name by type 647 \param type the event type 648 \return the event name*/ 649 const char *gf_dom_event_get_name(GF_EventType type); 650 651 /*! gets key name by type 652 \param key_identifier the key type 653 \return the key name*/ 654 const char *gf_dom_get_key_name(GF_KeyCode key_identifier); 655 /*! gets key type by name 656 \param key_name the key name 657 \return the key type*/ 658 GF_KeyCode gf_dom_get_key_type(char *key_name); 659 660 661 /*! macro for DOM listener 662 DOM listener is simply a node added to the node events list. 663 Only one observer can be attached to a listener. The listener will remove itself from the observer 664 event list when destructed.*/ 665 #define GF_DOM_BASE_LISTENER \ 666 /* JavaScript context in which the listener is applicable */ \ 667 struct js_handler_context *js_data;\ 668 /* text content of the callback */ \ 669 char *callback; 670 671 /*! DOM Event handler*/ 672 typedef struct __xml_ev_handler 673 { 674 GF_DOM_BASE_NODE 675 /*! handler callback function*/ 676 void (*handle_event)(GF_Node *hdl, GF_DOM_Event *event, GF_Node *observer); 677 GF_DOM_BASE_LISTENER 678 } GF_DOMHandler; 679 680 /*! DOM Event category*/ 681 typedef enum 682 { 683 GF_DOM_EVENT_UNKNOWN_CATEGORY, 684 /*basic DOM events*/ 685 GF_DOM_EVENT_DOM = 1, 686 /*DOM mutation events*/ 687 GF_DOM_EVENT_MUTATION = 1<<1, 688 /*DOM mouse events*/ 689 GF_DOM_EVENT_MOUSE = 1<<2, 690 /*DOM focus events*/ 691 GF_DOM_EVENT_FOCUS = 1<<3, 692 /*DOM key events*/ 693 GF_DOM_EVENT_KEY = 1<<4, 694 /*DOM/SVG/HTML UI events (resize, scroll, ...)*/ 695 GF_DOM_EVENT_UI = 1<<5, 696 /*text events*/ 697 GF_DOM_EVENT_TEXT = 1<<6, 698 /*SVG events*/ 699 GF_DOM_EVENT_SVG = 1<<7, 700 /*SMIL events*/ 701 GF_DOM_EVENT_SMIL = 1<<8, 702 /*LASeR events*/ 703 GF_DOM_EVENT_LASER = 1<<9, 704 /*HTML Media events*/ 705 GF_DOM_EVENT_MEDIA = 1<<10, 706 /*HTML Media Source events*/ 707 GF_DOM_EVENT_MEDIASOURCE = 1<<11, 708 709 /*Internal GPAC events*/ 710 GF_DOM_EVENT_GPAC = 1<<30, 711 /*fake events - these events are NEVER fired*/ 712 GF_DOM_EVENT_FAKE = 0x80000000 //1<<31 713 } GF_DOMEventCategory; 714 715 /*! gets category of DOM event 716 \param type type of event 717 \return event category 718 */ 719 GF_DOMEventCategory gf_dom_event_get_category(GF_EventType type); 720 721 /*! registers an event category with the scene graph. Event with unregistered categories will not be fired 722 \param sg the target scene graph 723 \param category the DOM event category to add 724 */ 725 void gf_sg_register_event_type(GF_SceneGraph *sg, GF_DOMEventCategory category); 726 /*! unregisters an event category with the scene graph 727 \param sg the target scene graph 728 \param category the DOM event category to add 729 */ 730 void gf_sg_unregister_event_type(GF_SceneGraph *sg, GF_DOMEventCategory category); 731 732 /*! adds a listener to the node. 733 \param n the target node 734 \param listener a listenerElement (XML event). The listener node is NOT registered with the node (it may very well not be a direct child of the node) 735 \return error if any 736 */ 737 GF_Err gf_node_dom_listener_add(GF_Node *n, GF_Node *listener); 738 /*! gets number of listener of a node 739 \param n the target node 740 \return number of listeners 741 */ 742 u32 gf_dom_listener_count(GF_Node *n); 743 /*! gets a listener of a node 744 \param n the target node 745 \param idx 0-based index of the listener to query 746 \return listener node or NULL if error 747 */ 748 GF_Node *gf_dom_listener_get(GF_Node *n, u32 idx); 749 750 /*! creates a default listener/handler for the given event on the given node 751 Listener/handler are stored at the node level 752 \param observer the observer node 753 \param event_type the event type 754 \param event_param the event parameter 755 \return the created handler element to allow for handler function override 756 */ 757 GF_DOMHandler *gf_dom_listener_build(GF_Node *observer, GF_EventType event_type, u32 event_param); 758 759 /*! registers a XML IRI with the scene graph - this is needed to handle replacement of IRI (SMIL anim, DOM / LASeR updates) 760 \warning \ref gf_node_unregister_iri shall be called when the parent node of the IRI is destroyed 761 \param sg the target scene graph 762 \param iri the IRI to register 763 */ 764 void gf_node_register_iri(GF_SceneGraph *sg, XMLRI *iri); 765 /*! unregisters a XML IRI with the scene graph 766 \param sg the target scene graph 767 \param iri the IRI to unregister 768 */ 769 void gf_node_unregister_iri(GF_SceneGraph *sg, XMLRI *iri); 770 /*! gets number of animation targeting this node 771 \param n the target node 772 \return the number of animations 773 */ 774 u32 gf_node_animation_count(GF_Node *n); 775 776 /*! writes data embedded in IRI (such as base64 data) to the indicated cahce directory, and updates the IRI accordingly 777 \param iri the IRI to store 778 \param cache_dir location of the directory to which the data should be extracted 779 \param base_filename location of the file the IRI was declared in 780 \return error if any 781 */ 782 GF_Err gf_node_store_embedded_data(XMLRI *iri, const char *cache_dir, const char *base_filename); 783 784 785 /************************************************** 786 * SVG's styling properties (see 6.1 in REC 1.1) * 787 *************************************************/ 788 789 /*! SVG properties of node*/ 790 typedef struct { 791 /* Tiny 1.2 properties*/ 792 SVG_Paint *color; 793 SVG_Paint *fill; 794 SVG_Paint *stroke; 795 SVG_Paint *solid_color; 796 SVG_Paint *stop_color; 797 SVG_Paint *viewport_fill; 798 799 SVG_Number *fill_opacity; 800 SVG_Number *solid_opacity; 801 SVG_Number *stop_opacity; 802 SVG_Number *stroke_opacity; 803 SVG_Number *viewport_fill_opacity; 804 SVG_Number *opacity; /* Restricted property in Tiny 1.2 */ 805 806 SVG_Number *audio_level; 807 Fixed computed_audio_level; 808 809 SVG_RenderingHint *color_rendering; 810 SVG_RenderingHint *image_rendering; 811 SVG_RenderingHint *shape_rendering; 812 SVG_RenderingHint *text_rendering; 813 814 SVG_Display *display; 815 SVG_Visibility *visibility; 816 SVG_Overflow *overflow; /* Restricted property in Tiny 1.2 */ 817 818 SVG_FontFamily *font_family; 819 SVG_FontSize *font_size; 820 SVG_FontStyle *font_style; 821 SVG_FontWeight *font_weight; 822 SVG_FontVariant *font_variant; 823 SVG_Number *line_increment; 824 SVG_TextAnchor *text_anchor; 825 SVG_DisplayAlign *display_align; 826 SVG_TextAlign *text_align; 827 828 SVG_PointerEvents *pointer_events; 829 830 SVG_FillRule *fill_rule; 831 832 SVG_StrokeDashArray *stroke_dasharray; 833 SVG_Length *stroke_dashoffset; 834 SVG_StrokeLineCap *stroke_linecap; 835 SVG_StrokeLineJoin *stroke_linejoin; 836 SVG_Number *stroke_miterlimit; 837 SVG_Length *stroke_width; 838 SVG_VectorEffect *vector_effect; 839 840 /* Full 1.1 props, i.e. not implemented */ 841 /* 842 SVG_String *font; 843 SVG_String *font_size_adjust; 844 SVG_String *font_stretch; 845 SVG_String *direction; 846 SVG_String *letter_spacing; 847 SVG_String *text_decoration; 848 SVG_String *unicode_bidi; 849 SVG_String *word_spacing; 850 SVG_String *clip; 851 SVG_String *cursor; 852 SVG_String *clip_path; 853 SVG_String *clip_rule; 854 SVG_String *mask; 855 SVG_String *enable_background; 856 SVG_String *filter; 857 SVG_String *flood_color; 858 SVG_String *flood_opacity; 859 SVG_String *lighting_color; 860 SVG_String *color_interpolation; 861 SVG_String *color_interpolation_filters; 862 SVG_String *color_profile; 863 SVG_String *marker; 864 SVG_String *marker_end; 865 SVG_String *marker_mid; 866 SVG_String *marker_start; 867 SVG_String *alignment_baseline; 868 SVG_String *baseline_shift; 869 SVG_String *dominant_baseline; 870 SVG_String *glyph_orientation_horizontal; 871 SVG_String *glyph_orientation_vertical; 872 SVG_String *kerning; 873 SVG_String *writing_mode; 874 */ 875 } SVGPropertiesPointers; 876 877 878 /*! initializes an SVGPropertiesPointers 879 \param svg_props pointer to structure to initialize 880 */ 881 void gf_svg_properties_init_pointers(SVGPropertiesPointers *svg_props); 882 /*! resets an SVGPropertiesPointers 883 \param svg_props pointer to structure to reset 884 */ 885 void gf_svg_properties_reset_pointers(SVGPropertiesPointers *svg_props); 886 887 /*! applies animations for the node 888 \param n the target node 889 \param render_svg_props pointer to rendering SVG properties of the node 890 */ 891 void gf_svg_apply_animations(GF_Node *n, SVGPropertiesPointers *render_svg_props); 892 /*! check if appearance flag is set 893 \param flags flags to test 894 \return GF_TRUE if appearance dirty flag is set 895 */ 896 Bool gf_svg_has_appearance_flag_dirty(u32 flags); 897 898 /*! checks if node tag indicates a transformable elemnt 899 \param tag tag to check 900 \return GF_TRUE if element is transformable 901 */ 902 Bool gf_svg_is_element_transformable(u32 tag); 903 /*! creates an SVG attribute value for the given type 904 \param attribute_type type of attribute to delete 905 \return newly allocated attribute value*/ 906 void *gf_svg_create_attribute_value(u32 attribute_type); 907 /*! destroys an SVG attribute value 908 \param attribute_type type of attribute to delete 909 \param value the value to destroy 910 \param sg the parent scenegraph (needed for IRI registration) 911 */ 912 void gf_svg_delete_attribute_value(u32 attribute_type, void *value, GF_SceneGraph *sg); 913 914 /*! checks if two SVG attributes are equal 915 \param a first attribute 916 \param b second attribute 917 \return GF_TRUE if equal 918 */ 919 Bool gf_svg_attributes_equal(GF_FieldInfo *a, GF_FieldInfo *b); 920 /*! copies attributes (a = b) 921 \param a destination attribute 922 \param b source attribute 923 \param clamp if GF_TRUE, the interpolated value is clamped to its min/max possible values 924 \return error if any 925 */ 926 GF_Err gf_svg_attributes_copy(GF_FieldInfo *a, GF_FieldInfo *b, Bool clamp); 927 /*! adds attributes ( c = a + b) 928 \param a first attribute 929 \param b second attribute 930 \param c destination attribute 931 \param clamp if GF_TRUE, the interpolated value is clamped to its min/max possible values 932 \return error if any 933 */ 934 GF_Err gf_svg_attributes_add(GF_FieldInfo *a, GF_FieldInfo *b, GF_FieldInfo *c, Bool clamp); 935 /*! checks if attribute type can be interpolated 936 \param type attribute type 937 \return GF_TRUE if type can be interpolation*/ 938 Bool gf_svg_attribute_is_interpolatable(u32 type); 939 /*! interpolates attributes ( c = coef * a + (1 - coef) * b ) 940 \param a first attribute 941 \param b second attribute 942 \param c destination attribute 943 \param coef interpolation coeficient 944 \param clamp if GF_TRUE, the interpolated value is clamped to its min/max possible values 945 \return error if any 946 */ 947 GF_Err gf_svg_attributes_interpolate(GF_FieldInfo *a, GF_FieldInfo *b, GF_FieldInfo *c, Fixed coef, Bool clamp); 948 /*! multiply and add attributes (c = alpha * a + beta * b) 949 \param a first attribute 950 \param alpha first multiplier 951 \param b second attribute 952 \param beta second multiplier 953 \param c destination attribute 954 \param clamp if GF_TRUE, the interpolated value is clamped to its min/max possible values 955 \return error if any 956 */ 957 GF_Err gf_svg_attributes_muladd(Fixed alpha, GF_FieldInfo *a, Fixed beta, GF_FieldInfo *b, GF_FieldInfo *c, Bool clamp); 958 /*! gets an attribute by its tag (built-in name) 959 \param n the target node 960 \param attribute_tag the attribute tag 961 \param create_if_not_found if GF_TRUE, adds the attribute if not found 962 \param set_default if GF_TRUE, sets the attribute to default when creating it 963 \param field set to the attribute information 964 \return error if any 965 */ 966 GF_Err gf_node_get_attribute_by_tag(GF_Node *n, u32 attribute_tag, Bool create_if_not_found, Bool set_default, GF_FieldInfo *field); 967 968 /*! gets name of an attribute type 969 \param att_type the attribute type 970 \return the attribute name*/ 971 const char *gf_svg_attribute_type_to_string(u32 att_type); 972 /*! parses an attribute 973 \param n the target node 974 \param info the attribute information 975 \param attribute_content the UTF-8 string to parse 976 \param anim_value_type the SMIL animation value type for this attribute, 0 if not animatable 977 \return error if any 978 */ 979 GF_Err gf_svg_parse_attribute(GF_Node *n, GF_FieldInfo *info, char *attribute_content, u8 anim_value_type); 980 /*! parses an SVG style 981 \param n the target node 982 \param style the UTF-8 style string to parse 983 */ 984 void gf_svg_parse_style(GF_Node *n, char *style); 985 986 /*! dumps an SVG attribute 987 \param n the target node 988 \param info the attribute information 989 \return the textural representation of the value - shall be destroyed by caller 990 */ 991 char *gf_svg_dump_attribute(GF_Node *n, GF_FieldInfo *info); 992 /*! dumps an SVG indexed attribute (special 1-D version of a N dimensional attribute, used by LASeR and DOM updates) 993 \param n the target node 994 \param info the attribute information 995 \return the textural representation of the value - shall be destroyed by caller 996 */ 997 char *gf_svg_dump_attribute_indexed(GF_Node *n, GF_FieldInfo *info); 998 999 #if USE_GF_PATH 1000 /*! builds a path from its SVG representation 1001 \param path a 2D graphical path object 1002 \param commands a list of SVG path commands 1003 \param points a list of SVG path points 1004 */ 1005 void gf_svg_path_build(GF_Path *path, GF_List *commands, GF_List *points); 1006 #endif 1007 /*! parses an SVG element ID 1008 \param n the target node 1009 \param nodename the node name to parse 1010 \param warning_if_defined if GF_TRUE, throws a warning when the node name is already defined 1011 \return error if any 1012 */ 1013 GF_Err gf_svg_parse_element_id(GF_Node *n, const char *nodename, Bool warning_if_defined); 1014 1015 /*! gets the name of a paint server type 1016 \param paint_type the paint server type 1017 \return paint server name*/ 1018 const char *gf_svg_get_system_paint_server_name(u32 paint_type); 1019 /*! gets the type of a paint server by name 1020 \param name the paint server name 1021 \return paint server type*/ 1022 u32 gf_svg_get_system_paint_server_type(const char *name); 1023 1024 /*! notifies the scene time to all the timed elements in the given scene graph (including sub-scenes). 1025 \param sg the target scene graph 1026 \return the number of active timed elements, or 0 if no changes in SMIL timing nodes (no redraw/reevaluate needed) 1027 */ 1028 Bool gf_smil_notify_timed_elements(GF_SceneGraph *sg); 1029 /*! inserts a new resolved time instant in the begin or end attribute. 1030 The insertion preserves the sorting and removes the previous insertions which have become obsolete 1031 \warning Only used for inserting time when an <a> element, whose target is a timed element, is activated 1032 \param n the target element 1033 \param is_end if GF_TRUE, the SMIL clock is an end clock 1034 \param clock clock time in seconds 1035 */ 1036 void gf_smil_timing_insert_clock(GF_Node *n, Bool is_end, Double clock); 1037 /*! parses a transformation list into a 2D matrix 1038 \param mat the matrix to fill 1039 \param attribute_content the UTF8 string representin the SVG transformation 1040 \return GF_TRUE if success*/ 1041 Bool gf_svg_parse_transformlist(GF_Matrix2D *mat, char *attribute_content); 1042 1043 /*! SMIL runtime timing information*/ 1044 typedef struct _smil_timing_rti SMIL_Timing_RTI; 1045 1046 /*! SMIL timing evaluation state*/ 1047 typedef enum 1048 { 1049 SMIL_TIMING_EVAL_NONE = 0, 1050 SMIL_TIMING_EVAL_UPDATE, 1051 SMIL_TIMING_EVAL_FREEZE, 1052 SMIL_TIMING_EVAL_REMOVE, 1053 SMIL_TIMING_EVAL_REPEAT, 1054 SMIL_TIMING_EVAL_FRACTION, 1055 SMIL_TIMING_EVAL_DISCARD, 1056 /*signaled the animation element has been inserted in the DOM tree*/ 1057 SMIL_TIMING_EVAL_ACTIVATE, 1058 /*signaled the animation element has been removed from the DOM tree*/ 1059 SMIL_TIMING_EVAL_DEACTIVATE, 1060 } GF_SGSMILTimingEvalState; 1061 1062 /*! SMIL timing evaluation callback 1063 \param rti SMIL runtime info 1064 \param normalized_simple_time SMIL normalized time 1065 \param state SMIL evaluation state 1066 */ 1067 typedef void gf_sg_smil_evaluate(struct _smil_timing_rti *rti, Fixed normalized_simple_time, GF_SGSMILTimingEvalState state); 1068 /*! sets the SMIL evaluation callback for a node 1069 \param smil_time the target SMIL node 1070 \param smil_evaluate the callback function 1071 */ 1072 void gf_smil_set_evaluation_callback(GF_Node *smil_time, gf_sg_smil_evaluate smil_evaluate); 1073 /*! assigns media duration for a SMIL node 1074 \param rti the target SMIL runtime info of the node 1075 \param media_duration the media duration in seconds*/ 1076 void gf_smil_set_media_duration(SMIL_Timing_RTI *rti, Double media_duration); 1077 /*! gets media duration of a SMIL node 1078 \param rti the target SMIL runtime info of the node 1079 \return the media duration in seconds*/ 1080 Double gf_smil_get_media_duration(SMIL_Timing_RTI *rti); 1081 /*! gets node from a SMIL runtime info 1082 \param rti the target SMIL runtime info of the node 1083 \return the associated node*/ 1084 GF_Node *gf_smil_get_element(SMIL_Timing_RTI *rti); 1085 /*! checks if a SMIL node is active 1086 \param node the target node 1087 \return GF_TRUE if node is active*/ 1088 Bool gf_smil_timing_is_active(GF_Node *node); 1089 /*! notifies a SMIL node that it has been modified 1090 \param node the target SMIL node 1091 \param field the field information describing the modified attribute, may be NULL 1092 */ 1093 void gf_smil_timing_modified(GF_Node *node, GF_FieldInfo *field); 1094 1095 /******************************************************************************* 1096 * 1097 * SVG Scene Graph for dynamic allocation of attributes * 1098 * 1099 *******************************************************************************/ 1100 1101 /*SVG attributes are just DOM ones*/ 1102 /*! SVG attribute - same as DOM attribute*/ 1103 typedef struct __dom_base_attribute SVGAttribute; 1104 /*! SVG extended attribute - same as DOM extended attribute*/ 1105 typedef struct __dom_full_attribute SVGExtendedAttribute; 1106 /*! SVG node - same as DOM node*/ 1107 typedef struct __dom_base_node SVG_Element; 1108 /*! SVG handler node - same as DOM Event handler*/ 1109 typedef struct __xml_ev_handler SVG_handlerElement; 1110 /*! SVG all attributes*/ 1111 typedef struct _all_atts SVGAllAttributes; 1112 1113 /*! flattens all SVG attributes in a structure 1114 \param n the target SVG node 1115 \param all_atts filled with all SVG attributes defined fo node 1116 */ 1117 void gf_svg_flatten_attributes(SVG_Element *n, SVGAllAttributes *all_atts); 1118 /*! gets SVG attribute name for a node 1119 \param n the target SVG node 1120 \param tag the attribute tag 1121 \return the attribute name 1122 */ 1123 const char *gf_svg_get_attribute_name(GF_Node *n, u32 tag); 1124 /*! applies inheritance of SVG attributes to a render_svg_props 1125 \note Some properties (audio-level, display, opacity, solid*, stop*, vector-effect, viewport*) are inherited only when they are specified with the value 'inherit' otherwise they default to their initial value which for the function below means NULL, the compositor will take care of the rest 1126 1127 \param all_atts the flatten SVG attributes of the node 1128 \param render_svg_props the set of properties applying to the parent node (initialize this one to 0 for root element) 1129 \return the set of inherited flags (from node dirty flags) 1130 */ 1131 u32 gf_svg_apply_inheritance(SVGAllAttributes *all_atts, SVGPropertiesPointers *render_svg_props) ; 1132 1133 /*! creates a DOM Attribute for the given tag 1134 \warning the attribute is not added to the node's attributes 1135 \param n the target node 1136 \param tag the target built-in tag 1137 \return a new DOM Attribute 1138 */ 1139 GF_DOMAttribute *gf_xml_create_attribute(GF_Node *n, u32 tag); 1140 /*! gets the type of a built-in XML/SVG/SMIL attribute tag 1141 \param tag the target attribute tag 1142 \return the attribute type*/ 1143 u32 gf_xml_get_attribute_type(u32 tag); 1144 1145 /*! gets the built-in tag of a node's attribute 1146 \param n the target node 1147 \param attribute_name the target attribute name 1148 \param ns the target namespace 1149 \return the attribute tag*/ 1150 u32 gf_xml_get_attribute_tag(GF_Node *n, char *attribute_name, GF_NamespaceType ns); 1151 1152 /*! gets the built-in tag of a node 1153 \param node_name the target node name 1154 \param xmlns the target namespace 1155 \return the node tag*/ 1156 u32 gf_xml_get_element_tag(const char *node_name, u32 xmlns); 1157 1158 /*! @} */ 1159 1160 #ifdef __cplusplus 1161 } 1162 #endif 1163 1164 #endif //_GF_SG_SVG_H_ 1165