📄 svg_base_sa.c
字号:
found = count ? 0 : 1; for (i=0;i<count;i++) { char *lang = (char*)gf_list_get(elt->conditional->systemLanguage, i); /*3 char-code*/ if (strlen(lang)==3) { if (!stricmp(lang, lang_3cc)) { found = 1; break; } } /*2 char-code, only check first 2 chars - TODO FIXME*/ else if (!strnicmp(lang, lang_2cc, 2)) { found = 1; break; } } if (!found) return 0; return 1;}static void SVG_Render_switch(GF_Node *node, void *rs, Bool is_destroy){ GF_Matrix2D backup_matrix; SVGPropertiesPointers backup_props; u32 backup_flags; u32 styling_size = sizeof(SVGPropertiesPointers); SVG_SA_switchElement *s = (SVG_SA_switchElement *)node; RenderEffect2D *eff = (RenderEffect2D *) rs; if (is_destroy) return; svg_sa_render_base(node, eff, &backup_props, &backup_flags); if (svg_is_display_off(eff->svg_props)) { svg_sa_restore_parent_transformation(eff, &backup_matrix); memcpy(eff->svg_props, &backup_props, styling_size); eff->svg_flags = backup_flags; return; } svg_sa_apply_local_transformation(eff, node, &backup_matrix); if (eff->traversing_mode == TRAVERSE_GET_BOUNDS) { svg_get_nodes_bounds(node, s->children, eff); } else { GF_ChildNodeItem *l = s->children; while (l) { if (eval_conditional(eff->surface->render->compositor, (SVG_SA_Element*)l->node)) { svg_render_node((GF_Node*)l->node, eff); break; } l = l->next; } } svg_sa_restore_parent_transformation(eff, &backup_matrix); memcpy(eff->svg_props, &backup_props, styling_size); eff->svg_flags = backup_flags;}void svg_sa_init_switch(Render2D *sr, GF_Node *node){ gf_node_set_callback_function(node, SVG_Render_switch);}static void SVG_DrawablePostRender(Drawable *cs, SVGPropertiesPointers *backup_props, u32 *backup_flags, SVGTransformableElement *elt, RenderEffect2D *eff, Bool rectangular, Fixed path_length){ GF_Matrix2D backup_matrix; DrawableContext *ctx; if (eff->traversing_mode == TRAVERSE_GET_BOUNDS) { if (svg_is_display_off(eff->svg_props)) gf_path_get_bounds(cs->path, &eff->bounds); 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, (GF_Node *)elt, &backup_matrix); ctx = SVG_drawable_init_context(cs, eff); if (ctx) { if (rectangular) { if (ctx->h_texture && ctx->h_texture->transparent) {} else if (GF_COL_A(ctx->aspect.fill_color) != 0xFF) {} else if (ctx->transform.m[1] || ctx->transform.m[3]) {} else { ctx->flags &= ~CTX_IS_TRANSPARENT; } } if (path_length) ctx->aspect.pen_props.path_length = path_length; drawable_finalize_render(ctx, eff, NULL); } svg_sa_restore_parent_transformation(eff, &backup_matrix);end: memcpy(eff->svg_props, backup_props, sizeof(SVGPropertiesPointers)); eff->svg_flags = *backup_flags;}static void SVG_Render_rect(GF_Node *node, void *rs, Bool is_destroy){ SVGPropertiesPointers backup_props; u32 backup_flags; RenderEffect2D *eff = (RenderEffect2D *)rs; Drawable *cs = (Drawable *)gf_node_get_private(node); SVG_SA_rectElement *rect = (SVG_SA_rectElement *)node; if (is_destroy) { DestroyDrawableNode(node); return; } if (eff->traversing_mode==TRAVERSE_DRAW) { drawable_draw(eff); return; } else if (eff->traversing_mode==TRAVERSE_PICK) { drawable_pick(eff); return; } svg_sa_render_base(node, eff, &backup_props, &backup_flags); /* 3) for a leaf node Recreates the path (i.e the shape) only if the node is dirty (has changed compared to the previous rendering phase) */ if (gf_node_dirty_get(node) & GF_SG_SVG_GEOMETRY_DIRTY) { Fixed rx = rect->rx.value; Fixed ry = rect->ry.value; Fixed x = rect->x.value; Fixed y = rect->y.value; Fixed width = rect->width.value; Fixed height = rect->height.value; drawable_reset_path(cs); if (rx || ry) { if (rx >= width/2) rx = width/2; if (ry >= height/2) ry = height/2; if (rx == 0) rx = ry; if (ry == 0) ry = rx; gf_path_add_move_to(cs->path, x+rx, y); gf_path_add_line_to(cs->path, x+width-rx, y); gf_path_add_quadratic_to(cs->path, x+width, y, x+width, y+ry); gf_path_add_line_to(cs->path, x+width, y+height-ry); gf_path_add_quadratic_to(cs->path, x+width, y+height, x+width-rx, y+height); gf_path_add_line_to(cs->path, x+rx, y+height); gf_path_add_quadratic_to(cs->path, x, y+height, x, y+height-ry); gf_path_add_line_to(cs->path, x, y+ry); gf_path_add_quadratic_to(cs->path, x, y, x+rx, y); gf_path_close(cs->path); } else { gf_path_add_move_to(cs->path, x, y); gf_path_add_line_to(cs->path, x+width, y); gf_path_add_line_to(cs->path, x+width, y+height); gf_path_add_line_to(cs->path, x, y+height); gf_path_close(cs->path); } gf_node_dirty_clear(node, GF_SG_SVG_GEOMETRY_DIRTY); cs->flags |= DRAWABLE_HAS_CHANGED; } SVG_DrawablePostRender(cs, &backup_props, &backup_flags, (SVGTransformableElement *)rect, eff, 1, 0);}void svg_sa_init_rect(Render2D *sr, GF_Node *node){ drawable_stack_new(sr, node); gf_node_set_callback_function(node, SVG_Render_rect);}static void SVG_Render_circle(GF_Node *node, void *rs, Bool is_destroy){ SVG_SA_circleElement *circle = (SVG_SA_circleElement *)node; SVGPropertiesPointers backup_props; u32 backup_flags; Drawable *cs = (Drawable *)gf_node_get_private(node); RenderEffect2D *eff = (RenderEffect2D *)rs; if (is_destroy) { DestroyDrawableNode(node); return; } if (eff->traversing_mode==TRAVERSE_DRAW) { drawable_draw(eff); return; } else if (eff->traversing_mode==TRAVERSE_PICK) { drawable_pick(eff); return; } svg_sa_render_base(node, eff, &backup_props, &backup_flags); if (gf_node_dirty_get(node) & GF_SG_SVG_GEOMETRY_DIRTY) { Fixed r = 2*circle->r.value; drawable_reset_path(cs); gf_path_add_ellipse(cs->path, circle->cx.value, circle->cy.value, r, r); gf_node_dirty_clear(node, GF_SG_SVG_GEOMETRY_DIRTY); cs->flags |= DRAWABLE_HAS_CHANGED; } SVG_DrawablePostRender(cs, &backup_props, &backup_flags, (SVGTransformableElement *)circle, eff, 0, 0);}void svg_sa_init_circle(Render2D *sr, GF_Node *node){ drawable_stack_new(sr, node); gf_node_set_callback_function(node, SVG_Render_circle);}static void SVG_Render_ellipse(GF_Node *node, void *rs, Bool is_destroy){ SVG_SA_ellipseElement *ellipse = (SVG_SA_ellipseElement *)node; SVGPropertiesPointers backup_props; u32 backup_flags; Drawable *cs = (Drawable *)gf_node_get_private(node); RenderEffect2D *eff = (RenderEffect2D *)rs; if (is_destroy) { DestroyDrawableNode(node); return; } if (eff->traversing_mode==TRAVERSE_DRAW) { drawable_draw(eff); return; } else if (eff->traversing_mode==TRAVERSE_PICK) { drawable_pick(eff); return; } svg_sa_render_base(node, eff, &backup_props, &backup_flags); if (gf_node_dirty_get(node) & GF_SG_SVG_GEOMETRY_DIRTY) { drawable_reset_path(cs); gf_path_add_ellipse(cs->path, ellipse->cx.value, ellipse->cy.value, 2*ellipse->rx.value, 2*ellipse->ry.value); gf_node_dirty_clear(node, GF_SG_SVG_GEOMETRY_DIRTY); cs->flags |= DRAWABLE_HAS_CHANGED; } SVG_DrawablePostRender(cs, &backup_props, &backup_flags, (SVGTransformableElement *)ellipse, eff, 0, 0);}void svg_sa_init_ellipse(Render2D *sr, GF_Node *node){ drawable_stack_new(sr, node); gf_node_set_callback_function(node, SVG_Render_ellipse);}static void SVG_Render_line(GF_Node *node, void *rs, Bool is_destroy){ SVG_SA_lineElement *line = (SVG_SA_lineElement *)node; SVGPropertiesPointers backup_props; u32 backup_flags; Drawable *cs = (Drawable *)gf_node_get_private(node); RenderEffect2D *eff = (RenderEffect2D *)rs; if (is_destroy) { DestroyDrawableNode(node); return; } if (eff->traversing_mode==TRAVERSE_DRAW) { drawable_draw(eff); return; } else if (eff->traversing_mode==TRAVERSE_PICK) { drawable_pick(eff); return; } svg_sa_render_base(node, eff, &backup_props, &backup_flags); if (gf_node_dirty_get(node) & GF_SG_SVG_GEOMETRY_DIRTY) { drawable_reset_path(cs); gf_path_add_move_to(cs->path, line->x1.value, line->y1.value); gf_path_add_line_to(cs->path, line->x2.value, line->y2.value); gf_node_dirty_clear(node, GF_SG_SVG_GEOMETRY_DIRTY); cs->flags |= DRAWABLE_HAS_CHANGED; } SVG_DrawablePostRender(cs, &backup_props, &backup_flags, (SVGTransformableElement *)line, eff, 0, 0);}void svg_sa_init_line(Render2D *sr, GF_Node *node){ drawable_stack_new(sr, node); gf_node_set_callback_function(node, SVG_Render_line);}static void SVG_Render_polyline(GF_Node *node, void *rs, Bool is_destroy){ SVG_SA_polylineElement *polyline = (SVG_SA_polylineElement *)node; SVGPropertiesPointers backup_props; u32 backup_flags; Drawable *cs = (Drawable *)gf_node_get_private(node); RenderEffect2D *eff = (RenderEffect2D *)rs; if (is_destroy) { DestroyDrawableNode(node); return; } if (eff->traversing_mode==TRAVERSE_DRAW) { drawable_draw(eff); return; } else if (eff->traversing_mode==TRAVERSE_PICK) { drawable_pick(eff); return; } svg_sa_render_base(node, eff, &backup_props, &backup_flags); if (gf_node_dirty_get(node) & GF_SG_SVG_GEOMETRY_DIRTY) { u32 i; u32 nbPoints = gf_list_count(polyline->points); drawable_reset_path(cs); if (nbPoints) { SVG_Point *p = (SVG_Point *)gf_list_get(polyline->points, 0); gf_path_add_move_to(cs->path, p->x, p->y); for (i = 1; i < nbPoints; i++) { p = (SVG_Point *)gf_list_get(polyline->points, i); gf_path_add_line_to(cs->path, p->x, p->y); } } else { gf_path_add_move_to(cs->path, 0, 0); } gf_node_dirty_clear(node, GF_SG_SVG_GEOMETRY_DIRTY); cs->flags |= DRAWABLE_HAS_CHANGED; } SVG_DrawablePostRender(cs, &backup_props, &backup_flags, (SVGTransformableElement *)polyline, eff, 0, 0);}void svg_sa_init_polyline(Render2D *sr, GF_Node *node){ drawable_stack_new(sr, node); gf_node_set_callback_function(node, SVG_Render_polyline);}static void SVG_Render_polygon(GF_Node *node, void *rs, Bool is_destroy){ SVG_SA_polygonElement *polygon = (SVG_SA_polygonElement *)node; SVGPropertiesPointers backup_props; u32 backup_flags; Drawable *cs = (Drawable *)gf_node_get_private(node); RenderEffect2D *eff = (RenderEffect2D *)rs; if (is_destroy) { DestroyDrawableNode(node); return; } if (eff->traversing_mode==TRAVERSE_DRAW) { drawable_draw(eff); return; } else if (eff->traversing_mode==TRAVERSE_PICK) { drawable_pick(eff); return; } svg_sa_render_base(node, (RenderEffect2D *)rs, &backup_props, &backup_flags); if (gf_node_dirty_get(node) & GF_SG_SVG_GEOMETRY_DIRTY) { u32 i; u32 nbPoints = gf_list_count(polygon->points); drawable_reset_path(cs); if (nbPoints) { SVG_Point *p = (SVG_Point *)gf_list_get(polygon->points, 0); gf_path_add_move_to(cs->path, p->x, p->y); for (i = 1; i < nbPoints; i++) { p = (SVG_Point *)gf_list_get(polygon->points, i); gf_path_add_line_to(cs->path, p->x, p->y); } gf_path_close(cs->path); } else { gf_path_add_move_to(cs->path, 0, 0); } gf_node_dirty_clear(node, GF_SG_SVG_GEOMETRY_DIRTY); cs->flags |= DRAWABLE_HAS_CHANGED; } SVG_DrawablePostRender(cs, &backup_props, &backup_flags, (SVGTransformableElement *)polygon, (RenderEffect2D *)rs, 0, 0);}void svg_sa_init_polygon(Render2D *sr, GF_Node *node){ drawable_stack_new(sr, node); gf_node_set_callback_function(node, SVG_Render_polygon);}static void SVG_Destroy_path(GF_Node *node){ Drawable *dr = gf_node_get_private(node);#if USE_GF_PATH /* The path is the same as the one in the SVG node, don't delete it here */ dr->path = NULL;#endif drawable_del(dr);}static void SVG_Render_path(GF_Node *node, void *rs, Bool is_destroy){ SVG_SA_pathElement *path = (SVG_SA_pathElement *)node; SVGPropertiesPointers backup_props; u32 backup_flags; Drawable *cs = (Drawable *)gf_node_get_private(node); RenderEffect2D *eff = (RenderEffect2D *)rs; if (is_destroy) { SVG_Destroy_path(node); return; } if (eff->traversing_mode==TRAVERSE_DRAW) { drawable_draw(eff); return; } else if (eff->traversing_mode==TRAVERSE_PICK) { drawable_pick(eff); return; } svg_sa_render_base(node, eff, &backup_props, &backup_flags); if (gf_node_dirty_get(node) & GF_SG_SVG_GEOMETRY_DIRTY) { #if USE_GF_PATH cs->path = &path->d;#else drawable_reset_path(cs); gf_svg_path_build(cs->path, path->d.commands, path->d.points);#endif if (*(eff->svg_props->fill_rule)==GF_PATH_FILL_ZERO_NONZERO) cs->path->flags |= GF_PATH_FILL_ZERO_NONZERO; gf_node_dirty_clear(node, 0); cs->flags |= DRAWABLE_HAS_CHANGED; } SVG_DrawablePostRender(cs, &backup_props, &backup_flags, (SVGTransformableElement *)path, eff, 0, (path->pathLength.type==SVG_NUMBER_VALUE) ? path->pathLength.value : 0);}void svg_sa_init_path(Render2D *sr, GF_Node *node){ Drawable *st = drawable_stack_new(sr, node);#if USE_GF_PATH gf_path_del(st->path); st->path = NULL;#endif gf_node_set_callback_function(node, SVG_Render_path);}/* end of rendering of basic shapes */static void SVG_Render_a(GF_Node *node, void *rs, Bool is_destroy){ GF_Matrix2D backup_matrix; SVGPropertiesPointers backup_props; u32 backup_flags; u32 styling_size = sizeof(SVGPropertiesPointers); SVG_SA_aElement *a = (SVG_SA_aElement *) node; RenderEffect2D *eff = (RenderEffect2D *)rs; if (is_destroy) return; svg_sa_render_base(node, eff, &backup_props, &backup_flags); if (eff->traversing_mode == TRAVERSE_GET_BOUNDS) { svg_sa_apply_local_transformation(eff, node, &backup_matrix); if (!svg_is_display_off(eff->svg_props) svg_get_nodes_bounds(node, a->children, eff); svg_sa_restore_parent_transformation(eff, &backup_matrix);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -