📄 svg_properties.c
字号:
/* * GPAC Multimedia Framework * * Authors: Cyril Concolato - Jean le Feuvre - Jean-Claude Moissinac * Copyright (c) 2005-200X ENST * All rights reserved * * This file is part of GPAC / SVG Loader module * * GPAC is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GPAC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */#include <gpac/scenegraph_svg.h>#include <gpac/internal/scenegraph_dev.h>#include <gpac/nodes_svg_da.h>/* Initialization of properties at the top level before any rendering The value shall not use the 'inherit' value, it uses the initial value. The property values are then updated when going down the tree using svg_properties_apply */GF_EXPORTvoid gf_svg_properties_init_pointers(SVGPropertiesPointers *svg_props) { if (!svg_props) return; GF_SAFEALLOC(svg_props->audio_level, SVG_Number); svg_props->audio_level->type = SVG_NUMBER_VALUE; svg_props->audio_level->value = FIX_ONE; GF_SAFEALLOC(svg_props->color, SVG_Paint); svg_props->color->type = SVG_PAINT_COLOR; svg_props->color->color.type = SVG_COLOR_RGBCOLOR; /* svg_props->color->red, green, blue set to zero, so initial value for color property is black */ GF_SAFEALLOC(svg_props->color_rendering, SVG_RenderingHint); *svg_props->color_rendering = SVG_RENDERINGHINT_AUTO; GF_SAFEALLOC(svg_props->display, SVG_Display); *svg_props->display = SVG_DISPLAY_INLINE; GF_SAFEALLOC(svg_props->display_align, SVG_DisplayAlign); *svg_props->display_align = SVG_DISPLAYALIGN_AUTO; GF_SAFEALLOC(svg_props->fill, SVG_Paint); svg_props->fill->type = SVG_PAINT_COLOR; svg_props->fill->color.type = SVG_COLOR_RGBCOLOR; /* svg_props->fill->color.red, green, blue set to zero, so initial value for fill color is black */ GF_SAFEALLOC(svg_props->fill_opacity, SVG_Number); svg_props->fill_opacity->type = SVG_NUMBER_VALUE; svg_props->fill_opacity->value = FIX_ONE; GF_SAFEALLOC(svg_props->fill_rule, SVG_FillRule); *svg_props->fill_rule = SVG_FILLRULE_NONZERO; GF_SAFEALLOC(svg_props->font_family, SVG_FontFamily); svg_props->font_family->type = SVG_FONTFAMILY_VALUE; svg_props->font_family->value = strdup("Arial"); GF_SAFEALLOC(svg_props->font_size, SVG_FontSize); svg_props->font_size->type = SVG_NUMBER_VALUE; svg_props->font_size->value = 12*FIX_ONE; GF_SAFEALLOC(svg_props->font_style, SVG_FontStyle); *svg_props->font_style = SVG_FONTSTYLE_NORMAL; GF_SAFEALLOC(svg_props->font_variant, SVG_FontVariant); *svg_props->font_variant = SVG_FONTVARIANT_NORMAL; GF_SAFEALLOC(svg_props->font_weight, SVG_FontWeight); *svg_props->font_weight = SVG_FONTWEIGHT_NORMAL; GF_SAFEALLOC(svg_props->image_rendering, SVG_RenderingHint); *svg_props->image_rendering = SVG_RENDERINGHINT_AUTO; GF_SAFEALLOC(svg_props->line_increment, SVG_Number); svg_props->line_increment->type = SVG_NUMBER_AUTO; svg_props->line_increment->value = FIX_ONE; GF_SAFEALLOC(svg_props->opacity, SVG_Number); svg_props->opacity->type = SVG_NUMBER_VALUE; svg_props->opacity->value = FIX_ONE; GF_SAFEALLOC(svg_props->pointer_events, SVG_PointerEvents); *svg_props->pointer_events = SVG_POINTEREVENTS_VISIBLEPAINTED; GF_SAFEALLOC(svg_props->shape_rendering, SVG_RenderingHint); *svg_props->shape_rendering = SVG_RENDERINGHINT_AUTO; GF_SAFEALLOC(svg_props->solid_color, SVG_Paint); svg_props->solid_color->type = SVG_PAINT_COLOR; svg_props->solid_color->color.type = SVG_COLOR_RGBCOLOR; /* svg_props->solid_color->color.red, green, blue set to zero, so initial value for solid_color is black */ GF_SAFEALLOC(svg_props->solid_opacity, SVG_Number); svg_props->solid_opacity->type = SVG_NUMBER_VALUE; svg_props->solid_opacity->value = FIX_ONE; GF_SAFEALLOC(svg_props->stop_color, SVG_Paint); svg_props->stop_color->type = SVG_PAINT_COLOR; svg_props->stop_color->color.type = SVG_COLOR_RGBCOLOR; /* svg_props->stop_color->color.red, green, blue set to zero, so initial value for stop_color is black */ GF_SAFEALLOC(svg_props->stop_opacity, SVG_Number); svg_props->stop_opacity->type = SVG_NUMBER_VALUE; svg_props->stop_opacity->value = FIX_ONE; GF_SAFEALLOC(svg_props->stroke, SVG_Paint); svg_props->stroke->type = SVG_PAINT_NONE; svg_props->stroke->color.type = SVG_COLOR_RGBCOLOR; /* svg_props->stroke->color.red, green, blue set to zero, so initial value for stroke color is black */ GF_SAFEALLOC(svg_props->stroke_dasharray, SVG_StrokeDashArray); svg_props->stroke_dasharray->type = SVG_STROKEDASHARRAY_NONE; GF_SAFEALLOC(svg_props->stroke_dashoffset , SVG_Length); svg_props->stroke_dashoffset->type = SVG_NUMBER_VALUE; svg_props->stroke_dashoffset->value = 0; GF_SAFEALLOC(svg_props->stroke_linecap, SVG_StrokeLineCap); *svg_props->stroke_linecap = SVG_STROKELINECAP_BUTT; GF_SAFEALLOC(svg_props->stroke_linejoin, SVG_StrokeLineJoin); *svg_props->stroke_linejoin = SVG_STROKELINEJOIN_MITER; GF_SAFEALLOC(svg_props->stroke_miterlimit, SVG_Number); svg_props->stroke_miterlimit->type = SVG_NUMBER_VALUE; svg_props->stroke_miterlimit->value = 4*FIX_ONE; GF_SAFEALLOC(svg_props->stroke_opacity, SVG_Number); svg_props->stroke_opacity->type = SVG_NUMBER_VALUE; svg_props->stroke_opacity->value = FIX_ONE; GF_SAFEALLOC(svg_props->stroke_width, SVG_Length); svg_props->stroke_width->type = SVG_NUMBER_VALUE; svg_props->stroke_width->value = FIX_ONE; GF_SAFEALLOC(svg_props->text_align, SVG_TextAlign); *svg_props->text_align = SVG_TEXTALIGN_START; GF_SAFEALLOC(svg_props->text_anchor, SVG_TextAnchor); *svg_props->text_anchor = SVG_TEXTANCHOR_START; GF_SAFEALLOC(svg_props->text_rendering, SVG_RenderingHint); *svg_props->text_rendering = SVG_RENDERINGHINT_AUTO; GF_SAFEALLOC(svg_props->vector_effect, SVG_VectorEffect); *svg_props->vector_effect = SVG_VECTOREFFECT_NONE; GF_SAFEALLOC(svg_props->viewport_fill, SVG_Paint); svg_props->viewport_fill->type = SVG_PAINT_NONE; GF_SAFEALLOC(svg_props->viewport_fill_opacity, SVG_Number); svg_props->viewport_fill_opacity->type = SVG_NUMBER_VALUE; svg_props->viewport_fill_opacity->value = FIX_ONE; GF_SAFEALLOC(svg_props->visibility, SVG_Visibility); *svg_props->visibility = SVG_VISIBILITY_VISIBLE;}GF_EXPORTvoid gf_svg_properties_reset_pointers(SVGPropertiesPointers *svg_props){ if (!svg_props) return; if(svg_props->audio_level) free(svg_props->audio_level); gf_svg_delete_paint(NULL, svg_props->color); if(svg_props->color_rendering) free(svg_props->color_rendering); if(svg_props->display) free(svg_props->display); if(svg_props->display_align) free(svg_props->display_align); gf_svg_delete_paint(NULL, svg_props->fill); if(svg_props->fill_opacity) free(svg_props->fill_opacity); if(svg_props->fill_rule) free(svg_props->fill_rule); if(svg_props->font_family) { if (svg_props->font_family->value) free(svg_props->font_family->value); free(svg_props->font_family); } if(svg_props->font_size) free(svg_props->font_size); if(svg_props->font_style) free(svg_props->font_style); if(svg_props->font_variant) free(svg_props->font_variant); if(svg_props->font_weight) free(svg_props->font_weight); if(svg_props->image_rendering) free(svg_props->image_rendering); if(svg_props->line_increment) free(svg_props->line_increment); if(svg_props->opacity) free(svg_props->opacity); if(svg_props->pointer_events) free(svg_props->pointer_events); if(svg_props->shape_rendering) free(svg_props->shape_rendering); gf_svg_delete_paint(NULL, svg_props->solid_color); if(svg_props->solid_opacity) free(svg_props->solid_opacity); gf_svg_delete_paint(NULL, svg_props->stop_color); if(svg_props->stop_opacity) free(svg_props->stop_opacity); gf_svg_delete_paint(NULL, svg_props->stroke); if(svg_props->stroke_dasharray) { if (svg_props->stroke_dasharray->array.count) free(svg_props->stroke_dasharray->array.vals); free(svg_props->stroke_dasharray); } if(svg_props->stroke_dashoffset) free(svg_props->stroke_dashoffset); if(svg_props->stroke_linecap) free(svg_props->stroke_linecap); if(svg_props->stroke_linejoin) free(svg_props->stroke_linejoin); if(svg_props->stroke_miterlimit) free(svg_props->stroke_miterlimit); if(svg_props->stroke_opacity) free(svg_props->stroke_opacity); if(svg_props->stroke_width) free(svg_props->stroke_width); if(svg_props->text_align) free(svg_props->text_align); if(svg_props->text_anchor) free(svg_props->text_anchor); if(svg_props->text_rendering) free(svg_props->text_rendering); if(svg_props->vector_effect) free(svg_props->vector_effect); gf_svg_delete_paint(NULL, svg_props->viewport_fill); if(svg_props->viewport_fill_opacity) free(svg_props->viewport_fill_opacity); if(svg_props->visibility) free(svg_props->visibility); memset(svg_props, 0, sizeof(SVGPropertiesPointers));}#ifdef GPAC_ENABLE_SVG_SA/* TODO: Check if all properties are implemented */GF_EXPORTu32 gf_svg_sa_apply_inheritance(SVG_SA_Element *elt, SVGPropertiesPointers *render_svg_props) { u32 inherited_flags_mask = 0; if(!elt || !render_svg_props) return 0; /* Perform inheritance of all the properties */ if (render_svg_props && elt->properties) { if (elt->properties->audio_level.type != SVG_NUMBER_INHERIT) render_svg_props->audio_level = &elt->properties->audio_level; if (elt->properties->color.color.type != SVG_COLOR_INHERIT) { render_svg_props->color = &elt->properties->color; } else { inherited_flags_mask |= GF_SG_SVG_COLOR_DIRTY; } if (elt->properties->color_rendering != SVG_RENDERINGHINT_INHERIT) { render_svg_props->color_rendering = &elt->properties->color_rendering; } if (elt->properties->display != SVG_DISPLAY_INHERIT) { render_svg_props->display = &elt->properties->display; } if (elt->properties->display_align != SVG_DISPLAYALIGN_INHERIT) { render_svg_props->display_align = &elt->properties->display_align; } else { inherited_flags_mask |= GF_SG_SVG_DISPLAYALIGN_DIRTY; } if (elt->properties->fill.type != SVG_PAINT_INHERIT) { render_svg_props->fill = &(elt->properties->fill); if (elt->properties->fill.type == SVG_PAINT_COLOR && elt->properties->fill.color.type == SVG_COLOR_CURRENTCOLOR && (inherited_flags_mask & GF_SG_SVG_COLOR_DIRTY)) { inherited_flags_mask |= GF_SG_SVG_FILL_DIRTY; } } else { inherited_flags_mask |= GF_SG_SVG_FILL_DIRTY; } if (elt->properties->fill_opacity.type != SVG_NUMBER_INHERIT) { render_svg_props->fill_opacity = &elt->properties->fill_opacity; } else { inherited_flags_mask |= GF_SG_SVG_FILLOPACITY_DIRTY; } if (elt->properties->fill_rule != SVG_FILLRULE_INHERIT) { render_svg_props->fill_rule = &elt->properties->fill_rule; } else { inherited_flags_mask |= GF_SG_SVG_FILLRULE_DIRTY; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -