📄 svg_base_sa.c
字号:
memcpy(eff->svg_props, &backup_props, styling_size); eff->svg_flags = backup_flags; return; } if (svg_is_display_off(eff->svg_props) || *(eff->svg_props->visibility) == SVG_VISIBILITY_HIDDEN) { } else { svg_sa_apply_local_transformation(eff, node, &backup_matrix); svg_render_node_list(a->children, eff); svg_sa_restore_parent_transformation(eff, &backup_matrix); } memcpy(eff->svg_props, &backup_props, styling_size); eff->svg_flags = backup_flags;}static void SVG_a_HandleEvent(GF_Node *handler, GF_DOM_Event *event){ GF_Renderer *compositor; GF_Event evt; SVG_SA_aElement *a; assert(gf_node_get_tag(event->currentTarget)==TAG_SVG_SA_a); a = (SVG_SA_aElement *) event->currentTarget; compositor = (GF_Renderer *)gf_node_get_private((GF_Node *)handler); if (!compositor->user->EventProc) return; if (event->type==GF_EVENT_MOUSEOVER) { evt.type = GF_EVENT_NAVIGATE_INFO; evt.navigate.to_url = a->xlink->href.iri; if (a->xlink->title) evt.navigate.to_url = a->xlink->title; compositor->user->EventProc(compositor->user->opaque, &evt); return; } evt.type = GF_EVENT_NAVIGATE; if (a->xlink->href.type == XMLRI_STRING) { evt.navigate.to_url = a->xlink->href.iri; if (evt.navigate.to_url) { evt.navigate.param_count = 1; evt.navigate.parameters = (const char **) &a->target; compositor->user->EventProc(compositor->user->opaque, &evt); } } else { u32 tag; if (!a->xlink->href.target) { /* TODO: check if href can be resolved */ return; } tag = gf_node_get_tag((GF_Node *)a->xlink->href.target); if (tag == TAG_SVG_SA_set || tag == TAG_SVG_SA_animate || tag == TAG_SVG_SA_animateColor || tag == TAG_SVG_SA_animateTransform || tag == TAG_SVG_SA_animateMotion || tag == TAG_SVG_SA_discard) { u32 i, count, found; SVG_SA_setElement *set = (SVG_SA_setElement *)a->xlink->href.target; SMIL_Time *begin; GF_SAFEALLOC(begin, SMIL_Time); begin->type = GF_SMIL_TIME_EVENT_RESOLVED; begin->clock = gf_node_get_scene_time((GF_Node *)set); found = 0; count = gf_list_count(set->timing->begin); for (i=0; i<count; i++) { SMIL_Time *first = (SMIL_Time *)gf_list_get(set->timing->begin, i); /*remove past instanciations*/ if ((first->type==GF_SMIL_TIME_EVENT_RESOLVED) && (first->clock < begin->clock)) { gf_list_rem(set->timing->begin, i); free(first); i--; count--; continue; } if ( (first->type == GF_SMIL_TIME_INDEFINITE) || ( (first->type == GF_SMIL_TIME_CLOCK) && (first->clock > begin->clock) ) ) { gf_list_insert(set->timing->begin, begin, i); found = 1; break; } } if (!found) gf_list_add(set->timing->begin, begin); gf_node_changed((GF_Node *)a->xlink->href.target, NULL); } } return;}void svg_sa_init_a(Render2D *sr, GF_Node *node){ SVG_SA_handlerElement *handler; gf_node_set_callback_function(node, SVG_Render_a); /*listener for onClick event*/ handler = gf_dom_listener_build(node, GF_EVENT_CLICK, 0, NULL); /*and overwrite handler*/ handler->handle_event = SVG_a_HandleEvent; gf_node_set_private((GF_Node *)handler, sr->compositor); /*listener for activate event*/ handler = gf_dom_listener_build(node, GF_EVENT_ACTIVATE, 0, NULL); /*and overwrite handler*/ handler->handle_event = SVG_a_HandleEvent; gf_node_set_private((GF_Node *)handler, sr->compositor);#ifndef DANAE /*listener for mouseover event*/ handler = gf_dom_listener_build(node, GF_EVENT_MOUSEOVER, 0, NULL); /*and overwrite handler*/ handler->handle_event = SVG_a_HandleEvent; gf_node_set_private((GF_Node *)handler, sr->compositor);#endif}/* end of Interactive SVG elements */static void SVG_SA_DestroyPaintServer(GF_Node *node){ SVG_GradientStack *st = (SVG_GradientStack *) gf_node_get_private(node); if (st) { gf_sr_texture_destroy(&st->txh); if (st->cols) free(st->cols); if (st->keys) free(st->keys); free(st); }}static void SVG_SA_UpdateGradient(SVG_GradientStack *st, GF_ChildNodeItem *children){ u32 count; Fixed alpha, max_offset; if (!gf_node_dirty_get(st->txh.owner)) return; gf_node_dirty_clear(st->txh.owner, 0); st->txh.needs_refresh = 1; st->txh.transparent = 0; count = gf_node_list_get_count(children); st->nb_col = 0; st->cols = (u32*)realloc(st->cols, sizeof(u32)*count); st->keys = (Fixed*)realloc(st->keys, sizeof(Fixed)*count); max_offset = 0; while (children) { Fixed key; SVG_SA_stopElement *gstop = (SVG_SA_stopElement *) children->node; children = children->next; if (gf_node_get_tag((GF_Node *)gstop) != TAG_SVG_SA_stop) continue; if (gstop->properties->stop_opacity.type==SVG_NUMBER_VALUE) alpha = gstop->properties->stop_opacity.value; else alpha = FIX_ONE; st->cols[st->nb_col] = GF_COL_ARGB_FIXED(alpha, gstop->properties->stop_color.color.red, gstop->properties->stop_color.color.green, gstop->properties->stop_color.color.blue); key = gstop->offset.value; if (gstop->offset.value>FIX_ONE) key/=100; if (key>max_offset) max_offset=key; else key = max_offset; st->keys[st->nb_col] = key; st->nb_col++; if (alpha!=FIX_ONE) st->txh.transparent = 1; } st->txh.compositor->r2d->stencil_set_gradient_interpolation(st->txh.hwtx, st->keys, st->cols, st->nb_col); st->txh.compositor->r2d->stencil_set_gradient_mode(st->txh.hwtx, /*lg->spreadMethod*/ GF_GRADIENT_MODE_PAD);}static void SVG_SA_Render_PaintServer(GF_Node *node, void *rs, Bool is_destroy){ SVGPropertiesPointers backup_props; u32 backup_flags; u32 styling_size = sizeof(SVGPropertiesPointers); SVG_SA_Element *elt = (SVG_SA_Element *)node; RenderEffect2D *eff = (RenderEffect2D *) rs; if (is_destroy) { SVG_SA_DestroyPaintServer(node); return; } svg_sa_render_base(node, eff, &backup_props, &backup_flags); if (eff->traversing_mode == TRAVERSE_GET_BOUNDS) { return; } else { svg_render_node_list(elt->children, eff); } memcpy(eff->svg_props, &backup_props, styling_size); eff->svg_flags = backup_flags;}/* linear gradient */static void SVG_SA_UpdateLinearGradient(GF_TextureHandler *txh){ SVG_SA_linearGradientElement *lg = (SVG_SA_linearGradientElement *) txh->owner; SVG_GradientStack *st = (SVG_GradientStack *) gf_node_get_private(txh->owner); if (!txh->hwtx) txh->hwtx = txh->compositor->r2d->stencil_new(txh->compositor->r2d, GF_STENCIL_LINEAR_GRADIENT); SVG_SA_UpdateGradient(st, lg->children);}static void SVG_SA_LG_ComputeMatrix(GF_TextureHandler *txh, GF_Rect *bounds, GF_Matrix2D *mat){ SFVec2f start, end; SVG_SA_linearGradientElement *lg = (SVG_SA_linearGradientElement *) txh->owner; /*create gradient brush if needed*/ if (!txh->hwtx) return; start.x = lg->x1.value; if (lg->x1.type==SVG_NUMBER_PERCENTAGE) start.x /= 100; start.y = lg->y1.value; if (lg->y1.type==SVG_NUMBER_PERCENTAGE) start.y /= 100; end.x = lg->x2.value; if (lg->x2.type==SVG_NUMBER_PERCENTAGE) end.x /= 100; end.y = lg->y2.value; if (lg->y2.type==SVG_NUMBER_PERCENTAGE) end.x /= 100; txh->compositor->r2d->stencil_set_gradient_mode(txh->hwtx, (GF_GradientMode) lg->spreadMethod); gf_mx2d_copy(*mat, lg->gradientTransform.mat); if (lg->gradientUnits==SVG_GRADIENTUNITS_OBJECT) { /*move to local coord system - cf SVG spec*/ gf_mx2d_add_scale(mat, bounds->width, bounds->height); gf_mx2d_add_translation(mat, bounds->x - 1, bounds->y - bounds->height - 1); } txh->compositor->r2d->stencil_set_linear_gradient(txh->hwtx, start.x, start.y, end.x, end.y);}void svg_sa_init_linearGradient(Render2D *sr, GF_Node *node){ SVG_GradientStack *st; GF_SAFEALLOC(st, SVG_GradientStack); gf_sr_texture_setup(&st->txh, sr->compositor, node); st->txh.update_texture_fcnt = SVG_SA_UpdateLinearGradient; st->txh.compute_gradient_matrix = SVG_SA_LG_ComputeMatrix; gf_node_set_private(node, st); gf_node_set_callback_function(node, SVG_SA_Render_PaintServer);}/* radial gradient */static void SVG_SA_UpdateRadialGradient(GF_TextureHandler *txh){ SVG_SA_radialGradientElement *rg = (SVG_SA_radialGradientElement *) txh->owner; SVG_GradientStack *st = (SVG_GradientStack *) gf_node_get_private(txh->owner); if (!txh->hwtx) txh->hwtx = txh->compositor->r2d->stencil_new(txh->compositor->r2d, GF_STENCIL_RADIAL_GRADIENT); SVG_SA_UpdateGradient(st, rg->children);}static void SVG_SA_RG_ComputeMatrix(GF_TextureHandler *txh, GF_Rect *bounds, GF_Matrix2D *mat){ SFVec2f center, focal; Fixed radius; SVG_SA_radialGradientElement *rg = (SVG_SA_radialGradientElement *) txh->owner; /*create gradient brush if needed*/ if (!txh->hwtx) return; gf_mx2d_copy(*mat, rg->gradientTransform.mat); radius = rg->r.value; if (rg->r.type==SVG_NUMBER_PERCENTAGE) radius /= 100; center.x = rg->cx.value; if (rg->cx.type==SVG_NUMBER_PERCENTAGE) center.x /= 100; center.y = rg->cy.value; if (rg->cy.type==SVG_NUMBER_PERCENTAGE) center.y /= 100; txh->compositor->r2d->stencil_set_gradient_mode(txh->hwtx, (GF_GradientMode) rg->spreadMethod); focal.x = rg->fx.value; if (rg->fx.type==SVG_NUMBER_PERCENTAGE) focal.x /= 100; focal.y = rg->fy.value; if (rg->fy.type==SVG_NUMBER_PERCENTAGE) focal.y /= 100; if (rg->gradientUnits==SVG_GRADIENTUNITS_OBJECT) { /*move to local coord system - cf SVG spec*/ gf_mx2d_add_scale(mat, bounds->width, bounds->height); gf_mx2d_add_translation(mat, bounds->x, bounds->y - bounds->height); } else if ((rg->fx.value==rg->fy.value) && (rg->fx.value==FIX_ONE/2)) { focal.x = center.x; focal.y = center.y; } txh->compositor->r2d->stencil_set_radial_gradient(txh->hwtx, center.x, center.y, focal.x, focal.y, radius, radius);}void svg_sa_init_radialGradient(Render2D *sr, GF_Node *node){ SVG_GradientStack *st; GF_SAFEALLOC(st, SVG_GradientStack); gf_sr_texture_setup(&st->txh, sr->compositor, node); st->txh.update_texture_fcnt = SVG_SA_UpdateRadialGradient; st->txh.compute_gradient_matrix = SVG_SA_RG_ComputeMatrix; gf_node_set_private(node, st); gf_node_set_callback_function(node, SVG_SA_Render_PaintServer);}void svg_sa_init_solidColor(Render2D *sr, GF_Node *node){ gf_node_set_callback_function(node, SVG_SA_Render_PaintServer);}void svg_sa_init_stop(Render2D *sr, GF_Node *node){ gf_node_set_callback_function(node, SVG_SA_Render_PaintServer);}GF_TextureHandler *svg_sa_gradient_get_texture(GF_Node *node){ SVG_SA_Element *g = (SVG_SA_Element *)node; SVG_GradientStack *st; if (g->xlink->href.target) g = g->xlink->href.target; st = (SVG_GradientStack*) gf_node_get_private((GF_Node *)g); return st->nb_col ? &st->txh : NULL;}void svg_sa_render_base(GF_Node *node, RenderEffect2D *eff, SVGPropertiesPointers *backup_props, u32 *backup_flags){ u32 inherited_flags_mask; memcpy(backup_props, eff->svg_props, sizeof(SVGPropertiesPointers)); *backup_flags = eff->svg_flags; /*following has been checked against animate-elem-84-t.svg and animate-elem-78-t.svg (and others)*/ /*first apply animations - all inherit values used during interpolation are resolved against the current property context (ie parent one) during this step*/ gf_svg_apply_animations(node, eff->svg_props); /*then apply inheritance now that all animated attributes are set (potentially to 'inherit') and store groups of inherited properties for dirty rect algo*/ inherited_flags_mask = gf_svg_sa_apply_inheritance((SVG_SA_Element *)node, eff->svg_props); eff->svg_flags &= inherited_flags_mask; eff->svg_flags |= gf_node_dirty_get(node);}/* TODO: FIX ME we actually ignore the given sub_root since it is only valid when animations have been performed, animations evaluation (svg_sa_render_base) should be part of the core renderer */void R2D_render_svg_sa_use(GF_Node *node, GF_Node *sub_root, void *rs){ GF_Matrix2D backup_matrix; GF_Matrix2D translate; GF_Node *prev_use; SVG_SA_useElement *use = (SVG_SA_useElement *)node; SVGPropertiesPointers backup_props; u32 backup_flags; RenderEffect2D *eff = (RenderEffect2D *)rs; svg_sa_render_base(node, eff, &backup_props, &backup_flags); gf_mx2d_init(translate); translate.m[2] = use->x.value; translate.m[5] = use->y.value; if (eff->traversing_mode == TRAVERSE_GET_BOUNDS) { svg_sa_apply_local_transformation(eff, node, &backup_matrix); if (!svg_is_display_off(eff->svg_props)) { gf_node_render((GF_Node*)use->xlink->href.target, eff); gf_mx2d_apply_rect(&translate, &eff->bounds); } svg_sa_restore_parent_transformation(eff, &backup_matrix); goto end; } if (svg_is_display_off(eff->svg_props) || *(eff->svg_props->visibility) == SVG_VISIBILITY_HIDDEN) { goto end; } svg_sa_apply_local_transformation(eff, node, &backup_matrix); gf_mx2d_pre_multiply(&eff->transform, &translate); prev_use = eff->parent_use; eff->parent_use = (GF_Node *)use->xlink->href.target; gf_node_render((GF_Node *)use->xlink->href.target, eff); eff->parent_use = prev_use; svg_sa_restore_parent_transformation(eff, &backup_matrix); end: memcpy(eff->svg_props, &backup_props, sizeof(SVGPropertiesPointers)); eff->svg_flags = backup_flags;}void R2D_render_svg_sa_animation(GF_Node *anim, GF_Node *sub_root, void *rs){ GF_Matrix2D backup_matrix; SVGPropertiesPointers backup_props; u32 backup_flags; RenderEffect2D *eff = (RenderEffect2D*)rs; SVG_SA_animationElement *a = (SVG_SA_animationElement*)anim; GF_Matrix2D translate; SVGPropertiesPointers new_props, *old_props; memset(&new_props, 0, sizeof(SVGPropertiesPointers)); /*for heritage and anims*/ svg_sa_render_base(anim, (RenderEffect2D *)rs, &backup_props, &backup_flags); gf_mx2d_init(translate); translate.m[2] = a->x.value; translate.m[5] = a->y.value; if (svg_is_display_off(eff->svg_props) || *(eff->svg_props->visibility) == SVG_VISIBILITY_HIDDEN) { goto end; } svg_sa_apply_local_transformation(eff, anim, &backup_matrix); gf_mx2d_pre_multiply(&eff->transform, &translate);#if 0 st = gf_node_get_private(n); if (!st->is) return; root = gf_sg_get_root_node(st->is->graph); if (root) { old_props = eff->svg_props; eff->svg_props = &new_props; gf_svg_properties_init_pointers(eff->svg_props); //gf_sr_render_inline(st->is->root_od->term->renderer, root, rs); gf_node_render(root, rs); eff->svg_props = old_props; gf_svg_properties_reset_pointers(&new_props);// }#endif old_props = eff->svg_props; eff->svg_props = &new_props; gf_svg_properties_init_pointers(eff->svg_props); gf_node_render(sub_root, rs); eff->svg_props = old_props; gf_svg_properties_reset_pointers(&new_props); svg_sa_restore_parent_transformation(eff, &backup_matrix); end: memcpy(eff->svg_props, &backup_props, sizeof(SVGPropertiesPointers)); eff->svg_flags = backup_flags;}#endif /*GPAC_ENABLE_SVG_SA*/#endif //GPAC_DISABLE_SVG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -