LCOV - code coverage report
Current view: top level - scene_manager - swf_svg.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 234 259 90.3 %
Date: 2021-04-29 23:48:07 Functions: 23 23 100.0 %

          Line data    Source code
       1             : /*
       2             :  *          GPAC - Multimedia Framework C SDK
       3             :  *
       4             :  *          Authors: Cyril Concolato, Jean Le Feuvre
       5             :  *          Copyright (c) Telecom ParisTech 2000-2020
       6             :  *                  All rights reserved
       7             :  *
       8             :  *  This file is part of GPAC / Scene Management 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             : #include <gpac/utf.h>
      26             : #include <gpac/xml.h>
      27             : #include <gpac/internal/swf_dev.h>
      28             : #include <gpac/internal/scenegraph_dev.h>
      29             : #include <gpac/internal/isomedia_dev.h>
      30             : #include <gpac/internal/media_dev.h>
      31             : #include <gpac/constants.h>
      32             : 
      33             : #ifndef GPAC_DISABLE_VVG
      34             : 
      35             : #ifndef GPAC_DISABLE_SWF_IMPORT
      36             : 
      37             : #define SWF_TEXT_SCALE              (1/1024.0f)
      38             : 
      39             : typedef struct _swf_svg_sample
      40             : {
      41             :         u64 start;
      42             :         u64 end;
      43             :         char *data;
      44             : } GF_SWF_SVG_Sample;
      45             : 
      46      179180 : static void swf_svg_print(SWFReader *read, const char *format, ...) {
      47             :         char line[2000];
      48             :         u32 line_length;
      49             :         u32 new_size;
      50             :         va_list args;
      51             : 
      52             :         /* print the line */
      53      179180 :         va_start(args, format);
      54             :         vsnprintf(line, 2000, format, args);
      55      179180 :         va_end(args);
      56             :         /* add the line to the buffer */
      57      179180 :         line_length = (u32)strlen(line);
      58      179180 :         new_size = read->svg_data_size+line_length;
      59      179180 :         read->svg_data = (char *)gf_realloc(read->svg_data, new_size+1);
      60      179180 :         if (read->print_frame_header) {
      61             :                 /* write at the beginning of the buffer */
      62        6875 :                 memmove(read->svg_data+read->frame_header_offset+line_length, read->svg_data+read->frame_header_offset, (read->svg_data_size-read->frame_header_offset)+1);
      63        6875 :                 memcpy(read->svg_data+read->frame_header_offset, line, line_length);
      64        6875 :                 read->frame_header_offset += line_length;
      65             :         } else {
      66      172305 :                 strcpy(read->svg_data+read->svg_data_size, line);
      67             :         }
      68      179180 :         read->svg_data_size = new_size;
      69      179180 : }
      70             : 
      71        1069 : static void swf_svg_print_color(SWFReader *read, u32 ARGB)
      72             : {
      73             :         SFColor val;
      74        1069 :         val.red = INT2FIX((ARGB>>16)&0xFF) / 255*100;
      75        1069 :         val.green = INT2FIX((ARGB>>8)&0xFF) / 255*100;
      76        1069 :         val.blue = INT2FIX((ARGB)&0xFF) / 255*100;
      77        1069 :         swf_svg_print(read, "rgb(%g%%,%g%%,%g%%)", FIX2FLT(val.red), FIX2FLT(val.green), FIX2FLT(val.blue));
      78        1069 : }
      79             : 
      80             : static void swf_svg_print_alpha(SWFReader *read, u32 ARGB)
      81             : {
      82             :         Fixed alpha;
      83        1069 :         alpha = INT2FIX((ARGB>>24)&0xFF)/255;
      84        1069 :         swf_svg_print(read, "%g", FIX2FLT(alpha));
      85             : }
      86             : 
      87        1173 : static void swg_svg_print_shape_record_to_fill_stroke(SWFReader *read, SWFShapeRec *srec, Bool is_fill)
      88             : {
      89             :         /*get regular appearance reuse*/
      90        1173 :         if (is_fill) {
      91         828 :                 switch (srec->type) {
      92             :                 /*solid/alpha fill*/
      93         724 :                 case 0x00:
      94         724 :                         swf_svg_print(read, "fill=\"");
      95         724 :                         swf_svg_print_color(read, srec->solid_col);
      96         724 :                         swf_svg_print(read, "\" ");
      97         724 :                         swf_svg_print(read, "fill-opacity=\"");
      98         724 :                         swf_svg_print_alpha(read, srec->solid_col);
      99         724 :                         swf_svg_print(read, "\" ");
     100         724 :                         break;
     101         104 :                 case 0x10:
     102             :                 case 0x12:
     103             :                 //if (read->flags & GF_SM_SWF_NO_GRADIENT) {
     104             :                 //      u32 col = srec->grad_col[srec->nbGrad/2];
     105             :                 //      col |= 0xFF000000;
     106             :                 //      n->appearance = s2b_get_appearance(read, (GF_Node *) n, col, 0, 0);
     107             :                 //} else {
     108             :                 //      n->appearance = s2b_get_gradient(read, (GF_Node *) n, shape, srec);
     109             :                 //}
     110             :                 //break;
     111             :                 case 0x40:
     112             :                 case 0x41:
     113             :                 case 0x42:
     114             :                 case 0x43:
     115             :                 //n->appearance = s2b_get_bitmap(read, (GF_Node *) n, shape, srec);
     116             :                 //break;
     117             :                 default:
     118         104 :                         swf_report(read, GF_NOT_SUPPORTED, "fill_style %x not supported", srec->type);
     119         104 :                         break;
     120             :                 }
     121             :         } else {
     122         345 :                 swf_svg_print(read, "fill=\"none\" ");
     123         345 :                 swf_svg_print(read, "stroke=\"");
     124         345 :                 swf_svg_print_color(read, srec->solid_col);
     125         345 :                 swf_svg_print(read, "\" ");
     126         345 :                 swf_svg_print(read, "stroke-opacity=\"");
     127         345 :                 swf_svg_print_alpha(read, srec->solid_col);
     128         345 :                 swf_svg_print(read, "\" ");
     129         345 :                 swf_svg_print(read, "stroke-width=\"%g\" ", FIX2FLT(srec->width));
     130             :         }
     131        1173 : }
     132             : 
     133        1173 : static void swf_svg_print_shape_record_to_path_d(SWFReader *read, SWFShapeRec *srec)
     134             : {
     135             :         u32     pt_idx;
     136             :         u32     i;
     137             : 
     138             :         pt_idx = 0;
     139       35832 :         for (i=0; i<srec->path->nbType; i++) {
     140       35832 :                 switch (srec->path->types[i]) {
     141             :                 /*moveTo*/
     142        2200 :                 case 0:
     143        2200 :                         swf_svg_print(read, "M%g,%g", FIX2FLT(srec->path->pts[pt_idx].x), FIX2FLT(srec->path->pts[pt_idx].y));
     144        2200 :                         pt_idx++;
     145             :                         break;
     146             :                 /*lineTo*/
     147       26431 :                 case 1:
     148       26431 :                         swf_svg_print(read, "L%g,%g", FIX2FLT(srec->path->pts[pt_idx].x), FIX2FLT(srec->path->pts[pt_idx].y));
     149       26431 :                         pt_idx++;
     150             :                         break;
     151             :                 /*curveTo*/
     152        7201 :                 case 2:
     153        7201 :                         swf_svg_print(read, "Q%g,%g", FIX2FLT(srec->path->pts[pt_idx].x), FIX2FLT(srec->path->pts[pt_idx].y));
     154        7201 :                         pt_idx++;
     155        7201 :                         swf_svg_print(read, ",%g,%g", FIX2FLT(srec->path->pts[pt_idx].x), FIX2FLT(srec->path->pts[pt_idx].y));
     156        7201 :                         pt_idx++;
     157             :                         break;
     158             :                 }
     159             :         }
     160        1173 : }
     161             : 
     162       20670 : static void swf_svg_print_matrix(SWFReader *read, GF_Matrix2D *mat)
     163             : {
     164       20670 :         if (!gf_mx2d_is_identity(*mat))
     165             :         {
     166             :                 GF_Point2D  scale;
     167             :                 GF_Point2D  translate;
     168             :                 Fixed       rotate;
     169       19967 :                 if( gf_mx2d_decompose(mat, &scale, &rotate, &translate))
     170             :                 {
     171       17495 :                         swf_svg_print(read, "transform=\"");
     172       17495 :                         if (translate.x != 0 || translate.y != 0)
     173             :                         {
     174       17495 :                                 swf_svg_print(read, "translate(%g, %g) ", FIX2FLT(translate.x), FIX2FLT(translate.y));
     175             :                         }
     176       17495 :                         if (rotate != 0)
     177             :                         {
     178        1759 :                                 swf_svg_print(read, "rotate(%g) ", FIX2FLT(rotate));
     179             :                         }
     180       17495 :                         if (scale.x != FIX_ONE || scale.y != FIX_ONE)
     181             :                         {
     182       15657 :                                 swf_svg_print(read, "scale(%g, %g) ", FIX2FLT(scale.x), FIX2FLT(scale.y));
     183             :                         }
     184       17495 :                         swf_svg_print(read, "\" ");
     185             :                 }
     186             :                 else
     187             :                 {
     188        2472 :                         swf_svg_print(read, "transform=\"matrix(%g,%g,%g,%g,%g,%g)\" ", FIX2FLT(mat->m[0]), FIX2FLT(mat->m[3]), FIX2FLT(mat->m[1]), FIX2FLT(mat->m[4]), FIX2FLT(mat->m[2]), FIX2FLT(mat->m[5]) );
     189             :                 }
     190             :         }
     191       20670 : }
     192             : 
     193             : /*translates Flash to SVG shapes*/
     194         762 : static GF_Err swf_svg_define_shape(SWFReader *read, SWFShape *shape, SWFFont *parent_font, Bool last_sub_shape)
     195             : {
     196             :         u32 i;
     197             :         SWFShapeRec *srec;
     198             : 
     199         762 :         if (parent_font && (read->flags & GF_SM_SWF_NO_FONT))
     200             :         {
     201             :                 return GF_OK;
     202             :         }
     203             : 
     204         762 :         if (!read->svg_shape_started)
     205             :         {
     206         631 :                 swf_svg_print(read, "<defs>\n");
     207         631 :                 if (!parent_font)
     208             :                 {
     209         448 :                         swf_svg_print(read, "<g id=\"S%d\" >\n", shape->ID);
     210             :                 }
     211             :                 else
     212             :                 {
     213             :                         char    szGlyphId[256];
     214         183 :                         sprintf(szGlyphId, "Font%d_Glyph%d", parent_font->fontID, gf_list_count(parent_font->glyphs));
     215         183 :                         swf_svg_print(read, "<g id=\"%s\" >\n", szGlyphId);
     216         183 :                         gf_list_add(parent_font->glyphs, szGlyphId);
     217             :                 }
     218             :         }
     219         762 :         read->empty_frame = GF_FALSE;
     220         762 :         read->svg_shape_started = GF_TRUE;
     221             : 
     222         762 :         i=0;
     223        2352 :         while ((srec = (SWFShapeRec*)gf_list_enum(shape->fill_left, &i))) {
     224         828 :                 swf_svg_print(read, "<path d=\"");
     225         828 :                 swf_svg_print_shape_record_to_path_d(read, srec);
     226         828 :                 swf_svg_print(read, "\" ");
     227         828 :                 swg_svg_print_shape_record_to_fill_stroke(read, srec, 1);
     228         828 :                 swf_svg_print(read, "/>\n");
     229             :         }
     230         762 :         i=0;
     231        1869 :         while ((srec = (SWFShapeRec*)gf_list_enum(shape->lines, &i))) {
     232         345 :                 swf_svg_print(read, "<path d=\"");
     233         345 :                 swf_svg_print_shape_record_to_path_d(read, srec);
     234         345 :                 swf_svg_print(read, "\" ");
     235         345 :                 swg_svg_print_shape_record_to_fill_stroke(read, srec, 0);
     236         345 :                 swf_svg_print(read, "/>\n");
     237             :         }
     238             : 
     239         762 :         if (last_sub_shape)
     240             :         {
     241         631 :                 read->svg_shape_started = GF_FALSE;
     242         631 :                 swf_svg_print(read, "</g>\n");
     243         631 :                 swf_svg_print(read, "</defs>\n");
     244             :         }
     245             :         return GF_OK;
     246             : }
     247             : 
     248          36 : static GF_Err swf_svg_define_text(SWFReader *read, SWFText *text)
     249             : {
     250             :         Bool            use_text;
     251             :         u32             i;
     252             :         u32             j;
     253             :         SWFGlyphRec     *gr;
     254             :         SWFFont         *ft;
     255             : 
     256          36 :         use_text = (read->flags & GF_SM_SWF_NO_FONT) ? 1 : 0;
     257             : 
     258          36 :         swf_svg_print(read, "<defs>\n");
     259          36 :         swf_svg_print(read, "<g id=\"S%d\" ", text->ID);
     260          36 :         swf_svg_print_matrix(read, &text->mat);
     261          36 :         swf_svg_print(read, ">\n");
     262             : 
     263          36 :         i=0;
     264         114 :         while ((gr = (SWFGlyphRec*)gf_list_enum(text->text, &i)))
     265             :         {
     266             :                 ft = NULL;
     267          42 :                 if (use_text) {
     268           0 :                         ft = swf_find_font(read, gr->fontID);
     269           0 :                         if (!ft->glyph_codes) {
     270             :                                 use_text = 0;
     271           0 :                                 swf_report(read, GF_BAD_PARAM, "Font glyphs are not defined, cannot reference extern font - Forcing glyph embedding");
     272             :                         }
     273             :                 }
     274          42 :                 if (use_text) {
     275             :                         /*restore back the font height in pixels (it's currently in SWF glyph design units)*/
     276           0 :                         swf_svg_print(read, "<text ");
     277           0 :                         swf_svg_print(read, "x=\"%g \" ", FIX2FLT(gr->orig_x));
     278           0 :                         swf_svg_print(read, "y=\"%g \" ", FIX2FLT(gr->orig_y));
     279           0 :                         swf_svg_print(read, "font-size=\"%d\" ", (u32)(gr->fontSize * SWF_TWIP_SCALE));
     280           0 :                         if (ft->fontName)
     281             :                         {
     282           0 :                                 swf_svg_print(read, "font-family=\"%s\" ", ft->fontName);
     283             :                         }
     284           0 :                         if (ft->is_italic)
     285             :                         {
     286           0 :                                 swf_svg_print(read, "font-style=\"italic\" ");
     287             :                         }
     288           0 :                         if (ft->is_bold)
     289             :                         {
     290           0 :                                 swf_svg_print(read, "font-weight=\"bold\" ");
     291             :                         }
     292           0 :                         swf_svg_print(read, ">");
     293             :                         /*convert to UTF-8*/
     294             :                         {
     295             :                                 size_t _len;
     296             :                                 u16     *str_w;
     297             :                                 u16     *widestr;
     298             :                                 char    *str;
     299             : 
     300           0 :                                 str_w = (u16*)gf_malloc(sizeof(u16) * (gr->nbGlyphs+1));
     301           0 :                                 for (j=0; j<gr->nbGlyphs; j++)
     302             :                                 {
     303           0 :                                         str_w[j] = ft->glyph_codes[gr->indexes[j]];
     304             :                                 }
     305           0 :                                 str_w[j] = 0;
     306           0 :                                 str = (char*)gf_malloc(sizeof(char) * (gr->nbGlyphs+2));
     307           0 :                                 widestr = str_w;
     308           0 :                                 _len = gf_utf8_wcstombs(str, sizeof(u8) * (gr->nbGlyphs+1), (const unsigned short **) &widestr);
     309           0 :                                 if (_len != (size_t) -1) {
     310           0 :                                         str[(u32) _len] = 0;
     311           0 :                                         swf_svg_print(read, "%s", str);
     312             :                                 }
     313             :                         }
     314           0 :                         swf_svg_print(read, "</text>\n");
     315             :                 }
     316             :                 else
     317             :                 {
     318             :                         /*convert glyphs*/
     319             :                         Fixed       dx;
     320          42 :                         swf_svg_print(read, "<g tranform=\"scale(1,-1) ");
     321          42 :                         swf_svg_print(read, "translate(%g, %g)\" >\n", FIX2FLT(gr->orig_x), FIX2FLT(gr->orig_y));
     322             : 
     323             :                         dx = 0;
     324         788 :                         for (j=0; j<gr->nbGlyphs; j++)
     325             :                         {
     326         746 :                                 swf_svg_print(read, "<use xlink:href=\"#Font%d_Glyph%d\" transform=\"translate(%g)\" />\n", gr->fontID, gr->indexes[j], FIX2FLT(gf_divfix(dx, FLT2FIX(gr->fontSize * SWF_TEXT_SCALE))));
     327         746 :                                 dx += gr->dx[j];
     328             :                         }
     329          42 :                         swf_svg_print(read, "</g>\n");
     330             :                 }
     331             :         }
     332          36 :         read->empty_frame = GF_FALSE;
     333          36 :         swf_svg_print(read, "</g>\n");
     334          36 :         swf_svg_print(read, "</defs>\n");
     335          36 :         return GF_OK;
     336             : }
     337             : 
     338           2 : static GF_Err swf_svg_define_edit_text(SWFReader *read, SWFEditText *text)
     339             : {
     340           2 :         return GF_OK;
     341             : }
     342             : 
     343             : #if 0
     344             : /*called upon end of sprite or clip*/
     345             : static void swf_svg_end_of_clip(SWFReader *read)
     346             : {
     347             : }
     348             : #endif
     349             : 
     350        2247 : static Bool swf_svg_allocate_depth(SWFReader *read, u32 depth)
     351             : {
     352        2247 :         return GF_FALSE;
     353             : }
     354             : 
     355           9 : static GF_Err swf_svg_define_sprite(SWFReader *read, u32 nb_frames)
     356             : {
     357           9 :         return GF_OK;
     358             : }
     359             : 
     360           3 : static GF_Err swf_svg_setup_sound(SWFReader *read, SWFSound *snd, Bool soundstream_first_block)
     361             : {
     362           3 :         return GF_OK;
     363             : }
     364             : 
     365           1 : static GF_Err swf_svg_setup_image(SWFReader *read, u32 ID, char *fileName)
     366             : {
     367           1 :         swf_svg_print(read, "<defs>\n");
     368           1 :         swf_svg_print(read, "<image id=\"S%d\" xlink:href=\"\"/>", ID, fileName);
     369           1 :         swf_svg_print(read, "</defs>\n");
     370           1 :         return GF_OK;
     371             : }
     372             : 
     373           6 : static GF_Err swf_svg_set_backcol(SWFReader *read, u32 xrgb)
     374             : {
     375             : 
     376             :         //rgb.red = INT2FIX((xrgb>>16) & 0xFF) / 255;
     377             :         //rgb.green = INT2FIX((xrgb>>8) & 0xFF) / 255;
     378             :         //rgb.blue = INT2FIX((xrgb) & 0xFF) / 255;
     379           6 :         return GF_OK;
     380             : }
     381             : 
     382           1 : static GF_Err swf_svg_start_sound(SWFReader *read, SWFSound *snd, Bool stop)
     383             : {
     384           1 :         return GF_OK;
     385             : }
     386             : 
     387        2247 : static GF_Err swf_svg_place_obj(SWFReader *read, u32 depth, u32 ID, u32 prev_id, u32 type, GF_Matrix2D *mat, GF_ColorMatrix *cmat, GF_Matrix2D *prev_mat, GF_ColorMatrix *prev_cmat)
     388             : {
     389        2247 :         read->empty_frame = GF_FALSE;
     390        2247 :         return GF_OK;
     391             : }
     392             : 
     393         241 : static GF_Err swf_svg_remove_obj(SWFReader *read, u32 depth, u32 ID)
     394             : {
     395         241 :         read->empty_frame = GF_FALSE;
     396         241 :         return GF_OK;
     397             : }
     398             : 
     399        1375 : static GF_Err swf_svg_show_frame(SWFReader *read)
     400             : {
     401             :         u32     i;
     402             :         u32     len;
     403        1375 :         GF_List *sdl = gf_list_new(); // sorted display list
     404             : 
     405             :         /* sorting the display list because SVG/CSS z-index is not well supported */
     406       23384 :         while (gf_list_count(read->display_list))
     407             :         {
     408             :                 Bool        inserted = GF_FALSE;
     409             :                 DispShape   *s;
     410             : 
     411       20634 :                 s = (DispShape *)gf_list_get(read->display_list, 0);
     412       20634 :                 gf_list_rem(read->display_list, 0);
     413             : 
     414      190504 :                 for (i = 0; i < gf_list_count(sdl); i++)
     415             :                 {
     416      169885 :                         DispShape *s2 = (DispShape *)gf_list_get(sdl, i);
     417      169885 :                         if (s->depth < s2->depth)
     418             :                         {
     419          15 :                                 gf_list_insert(sdl, s, i);
     420             :                                 inserted = GF_TRUE;
     421             :                                 break;
     422             :                         }
     423             :                 }
     424             :                 if (!inserted)
     425             :                 {
     426       20619 :                         gf_list_add(sdl, s);
     427             :                 }
     428             :         }
     429        1375 :         gf_list_del(read->display_list);
     430        1375 :         read->display_list = sdl;
     431             : 
     432             :         /* dumping the display list */
     433        1375 :         len = gf_list_count(read->display_list);
     434       22009 :         for (i=0; i<len; i++)
     435             :         {
     436             :                 DispShape   *s;
     437       20634 :                 s = (DispShape *)gf_list_get(read->display_list, i);
     438       20634 :                 swf_svg_print(read, "<use xlink:href=\"#S%d\" ", s->char_id);
     439             :                 //swf_svg_print(read, "z-index=\"%d\" ", s->depth);
     440       20634 :                 swf_svg_print_matrix(read, &s->mat);
     441       20634 :                 swf_svg_print(read, "/>\n");
     442       20634 :                 read->empty_frame = GF_FALSE;
     443             :         }
     444        1375 :         if (!read->empty_frame) {
     445        1375 :                 read->print_frame_header = GF_TRUE;
     446        1375 :                 read->frame_header_offset = 0;
     447        1375 :                 swf_svg_print(read, "<g display=\"none\">\n");
     448        1375 :                 swf_svg_print(read, "<animate id=\"frame%d_anim\" attributeName=\"display\" to=\"inline\" ", read->current_frame);
     449        1375 :                 swf_svg_print(read, "begin=\"%g\" ", 1.0*(read->current_frame)/read->frame_rate);
     450        1375 :                 if (read->current_frame+1 < read->frame_count) {
     451        1369 :                         swf_svg_print(read, "end=\"frame%d_anim.begin\" fill=\"remove\" ", (read->current_frame+1));
     452             :                 } else {
     453           6 :                         swf_svg_print(read, "fill=\"freeze\" ");
     454             :                 }
     455        1375 :                 swf_svg_print(read, "/>\n");
     456        1375 :                 read->print_frame_header = GF_FALSE;
     457             : 
     458        1375 :                 swf_svg_print(read, "</g>\n");
     459             :         }
     460        1375 :         read->add_sample(read->user, read->svg_data, read->svg_data_size, read->current_frame*1000/read->frame_rate, (read->current_frame == 0));
     461        1375 :         gf_free(read->svg_data);
     462        1375 :         read->svg_data = NULL;
     463        1375 :         read->svg_data_size = 0;
     464             : 
     465        1375 :         read->empty_frame = GF_TRUE;
     466        1375 :         return GF_OK;
     467             : }
     468             : 
     469           6 : static void swf_svg_finalize(SWFReader *read)
     470             : {
     471           6 :         swf_svg_print(read, "</svg>\n");
     472           6 :         read->add_header(read->user, read->svg_data, read->svg_data_size, GF_FALSE);
     473           6 :         gf_free(read->svg_data);
     474           6 :         read->svg_data = NULL;
     475           6 :         read->svg_data_size = 0;
     476           6 : }
     477             : 
     478           8 : static GF_Err swf_svg_define_button(SWFReader *read, SWF_Button *btn)
     479             : {
     480           8 :         return GF_OK;
     481             : }
     482             : 
     483          10 : static Bool swf_svg_action(SWFReader *read, SWFAction *act)
     484             : {
     485          10 :         return GF_TRUE;
     486             : }
     487             : 
     488           6 : GF_Err swf_to_svg_init(SWFReader *read, u32 swf_flags, Float swf_flatten_angle)
     489             : {
     490           6 :         if (!read->user) return GF_BAD_PARAM;
     491             : 
     492             :         /*init callbacks*/
     493           6 :         read->show_frame = swf_svg_show_frame;
     494           6 :         read->allocate_depth = swf_svg_allocate_depth;
     495           6 :         read->place_obj = swf_svg_place_obj;
     496           6 :         read->remove_obj = swf_svg_remove_obj;
     497           6 :         read->define_shape = swf_svg_define_shape;
     498           6 :         read->define_sprite = swf_svg_define_sprite;
     499           6 :         read->set_backcol = swf_svg_set_backcol;
     500           6 :         read->define_button = swf_svg_define_button;
     501           6 :         read->define_text = swf_svg_define_text;
     502           6 :         read->define_edit_text = swf_svg_define_edit_text;
     503           6 :         read->setup_sound = swf_svg_setup_sound;
     504           6 :         read->start_sound = swf_svg_start_sound;
     505           6 :         read->setup_image = swf_svg_setup_image;
     506           6 :         read->action = swf_svg_action;
     507           6 :         read->finalize = swf_svg_finalize;
     508             : 
     509           6 :         read->flags = swf_flags;
     510           6 :         read->flat_limit = FLT2FIX(swf_flatten_angle);
     511             : 
     512           6 :         read->print_stream_header = GF_TRUE;
     513           6 :         swf_svg_print(read, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
     514           6 :         swf_svg_print(read, "<svg xmlns=\"http://www.w3.org/2000/svg\" ");
     515           6 :         swf_svg_print(read, "xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
     516           6 :         swf_svg_print(read, "width=\"100%%\" ");
     517           6 :         swf_svg_print(read, "height=\"100%%\" ");
     518           6 :         swf_svg_print(read, "viewBox=\"0 0 %d %d\" ", FIX2INT(read->width), FIX2INT(read->height));
     519           6 :         swf_svg_print(read, "viewport-fill=\"rgb(255,255,255)\" ");
     520           6 :         swf_svg_print(read, ">\n");
     521           6 :         read->print_stream_header = GF_FALSE;
     522             : 
     523             :         /* update sample description */
     524           6 :         read->add_header(read->user, read->svg_data, read->svg_data_size, GF_TRUE);
     525           6 :         gf_free(read->svg_data);
     526           6 :         read->svg_data = NULL;
     527           6 :         read->svg_data_size = 0;
     528             : 
     529           6 :         return GF_OK;
     530             : }
     531             : 
     532         490 : GF_Err swf_svg_write_text_sample(void *user, const u8 *data, u32 length, u64 timestamp, Bool isRap)
     533             : {
     534             :         FILE *svgFile = (FILE *)user;
     535             :         u32  lengthWritten;
     536             : 
     537         490 :         lengthWritten = (u32) gf_fwrite(data, length, svgFile);
     538         490 :         if (length != lengthWritten) {
     539             :                 return GF_BAD_PARAM;
     540             :         } else {
     541         490 :                 return GF_OK;
     542             :         }
     543             : }
     544             : 
     545           2 : GF_Err swf_svg_write_text_header(void *user, const u8 *data, u32 length, Bool isHeader)
     546             : {
     547             :         FILE *svgFile = (FILE *)user;
     548             :         u32  lengthWritten;
     549             : 
     550           2 :         lengthWritten = (u32) gf_fwrite(data, length, svgFile);
     551           2 :         if (length != lengthWritten) {
     552             :                 return GF_BAD_PARAM;
     553             :         } else {
     554           2 :                 return GF_OK;
     555             :         }
     556             : }
     557             : #endif /*GPAC_DISABLE_SWF_IMPORT*/
     558             : 
     559             : #endif /*GPAC_DISABLE_SVG*/

Generated by: LCOV version 1.13