Пример #1
0
static GF_Err swf_svg_show_frame(SWFReader *read)
{
    u32     i;
    u32     len;
    GF_List *sdl = gf_list_new(); // sorted display list

    /* sorting the display list */
    while (gf_list_count(read->display_list))
    {
        Bool        inserted = 0;
        DispShape   *s;

        s = (DispShape *)gf_list_get(read->display_list, 0);
        gf_list_rem(read->display_list, 0);
        
        for (i = 0; i < gf_list_count(sdl); i++)
        {
            DispShape *s2 = (DispShape *)gf_list_get(sdl, i);
            if (s->depth < s2->depth) 
            {
                gf_list_insert(sdl, s, i);
                inserted = 1;
                break;
            }
        }
        if (!inserted)
        {
            gf_list_add(sdl, s);
        }
    }
    gf_list_del(read->display_list);
    read->display_list = sdl;

    /* dumping the display list */
    len = gf_list_count(read->display_list);
    for (i=0; i<len; i++)
    {
        DispShape   *s;
        s = (DispShape *)gf_list_get(read->display_list, i);
        fprintf(read->svg_output, "<use xlink:href=\"#S%d\" z-index=\"%d\" ", s->char_id, s->depth);
        swf_svg_print_matrix(read, &s->mat);
        fprintf(read->svg_output, "/>\n");
    }
    fprintf(read->svg_output, "</g>\n");

    fprintf(read->svg_output, "<g id=\"frame%d\" display=\"none\">\n",read->current_frame+1);
    fprintf(read->svg_output, "<animate attributeName=\"display\" to=\"inline\" begin=\"%f\" end=\"%f\" fill=\"%s\" restart=\"never\"/>\n", 
        1.0*(read->current_frame+1)/read->frame_rate, 1.0*(read->current_frame+2)/read->frame_rate,
        (((read->current_frame+1) <= (read->frame_count-1)) ? "remove" : "freeze"));
    return GF_OK;
}
Пример #2
0
static GF_Err swf_svg_show_frame(SWFReader *read)
{
	u32     i;
	u32     len;
	GF_List *sdl = gf_list_new(); // sorted display list

	/* sorting the display list because SVG/CSS z-index is not well supported */
	while (gf_list_count(read->display_list))
	{
		Bool        inserted = GF_FALSE;
		DispShape   *s;

		s = (DispShape *)gf_list_get(read->display_list, 0);
		gf_list_rem(read->display_list, 0);

		for (i = 0; i < gf_list_count(sdl); i++)
		{
			DispShape *s2 = (DispShape *)gf_list_get(sdl, i);
			if (s->depth < s2->depth)
			{
				gf_list_insert(sdl, s, i);
				inserted = GF_TRUE;
				break;
			}
		}
		if (!inserted)
		{
			gf_list_add(sdl, s);
		}
	}
	gf_list_del(read->display_list);
	read->display_list = sdl;

	/* dumping the display list */
	len = gf_list_count(read->display_list);
	for (i=0; i<len; i++)
	{
		DispShape   *s;
		s = (DispShape *)gf_list_get(read->display_list, i);
		swf_svg_print(read, "<use xlink:href=\"#S%d\" ", s->char_id);
		//swf_svg_print(read, "z-index=\"%d\" ", s->depth);
		swf_svg_print_matrix(read, &s->mat);
		swf_svg_print(read, "/>\n");
		read->empty_frame = GF_FALSE;
	}
	if (!read->empty_frame) {
		read->print_frame_header = GF_TRUE;
		read->frame_header_offset = 0;
		swf_svg_print(read, "<g display=\"none\">\n");
		swf_svg_print(read, "<animate id=\"frame%d_anim\" attributeName=\"display\" to=\"inline\" ", read->current_frame);
		swf_svg_print(read, "begin=\"%g\" ", 1.0*(read->current_frame)/read->frame_rate);
		if (read->current_frame+1 < read->frame_count) {
			swf_svg_print(read, "end=\"frame%d_anim.begin\" fill=\"remove\" ", (read->current_frame+1));
		} else {
			swf_svg_print(read, "fill=\"freeze\" ");
		}
		swf_svg_print(read, "/>\n");
		read->print_frame_header = GF_FALSE;

		swf_svg_print(read, "</g>\n");
	}
	read->add_sample(read->user, read->svg_data, read->svg_data_size, read->current_frame*1000/read->frame_rate, (read->current_frame == 0));
	gf_free(read->svg_data);
	read->svg_data = NULL;
	read->svg_data_size = 0;

	read->empty_frame = GF_TRUE;
	return GF_OK;
}
Пример #3
0
static GF_Err swf_svg_define_text(SWFReader *read, SWFText *text)
{
	Bool            use_text;
	u32             i;
	u32             j;
	SWFGlyphRec     *gr;
	SWFFont         *ft;

	use_text = (read->flags & GF_SM_SWF_NO_FONT) ? 1 : 0;

	swf_svg_print(read, "<defs>\n");
	swf_svg_print(read, "<g id=\"S%d\" ", text->ID);
	swf_svg_print_matrix(read, &text->mat);
	swf_svg_print(read, ">\n");

	i=0;
	while ((gr = (SWFGlyphRec*)gf_list_enum(text->text, &i)))
	{
		ft = NULL;
		if (use_text) {
			ft = swf_find_font(read, gr->fontID);
			if (!ft->glyph_codes) {
				use_text = 0;
				swf_report(read, GF_BAD_PARAM, "Font glyphs are not defined, cannot reference extern font - Forcing glyph embedding");
			}
		}
		if (use_text) {
			/*restore back the font height in pixels (it's currently in SWF glyph design units)*/
			swf_svg_print(read, "<text ");
			swf_svg_print(read, "x=\"%g \" ", FIX2FLT(gr->orig_x));
			swf_svg_print(read, "y=\"%g \" ", FIX2FLT(gr->orig_y));
			swf_svg_print(read, "font-size=\"%d\" ", (u32)(gr->fontSize * SWF_TWIP_SCALE));
			if (ft->fontName)
			{
				swf_svg_print(read, "font-family=\"%s\" ", ft->fontName);
			}
			if (ft->is_italic)
			{
				swf_svg_print(read, "font-style=\"italic\" ");
			}
			if (ft->is_bold)
			{
				swf_svg_print(read, "font-weight=\"bold\" ");
			}
			swf_svg_print(read, ">");
			/*convert to UTF-8*/
			{
				size_t _len;
				u16     *str_w;
				u16     *widestr;
				char    *str;

				str_w = (u16*)gf_malloc(sizeof(u16) * (gr->nbGlyphs+1));
				for (j=0; j<gr->nbGlyphs; j++)
				{
					str_w[j] = ft->glyph_codes[gr->indexes[j]];
				}
				str_w[j] = 0;
				str = (char*)gf_malloc(sizeof(char) * (gr->nbGlyphs+2));
				widestr = str_w;
				_len = gf_utf8_wcstombs(str, sizeof(u8) * (gr->nbGlyphs+1), (const unsigned short **) &widestr);
				if (_len != (size_t) -1) {
					str[(u32) _len] = 0;
					swf_svg_print(read, "%s", str);
				}
			}
			swf_svg_print(read, "</text>\n");
		}
		else
		{
			/*convert glyphs*/
			Fixed       dx;
			swf_svg_print(read, "<g tranform=\"scale(1,-1) ");
			swf_svg_print(read, "translate(%g, %g)\" >\n", FIX2FLT(gr->orig_x), FIX2FLT(gr->orig_y));

			dx = 0;
			for (j=0; j<gr->nbGlyphs; j++)
			{
				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))));
				dx += gr->dx[j];
			}
			swf_svg_print(read, "</g>\n");
		}
	}
	read->empty_frame = GF_FALSE;
	swf_svg_print(read, "</g>\n");
	swf_svg_print(read, "</defs>\n");
	return GF_OK;
}