Пример #1
0
svg_status_t
svg_render (svg_t		*svg,
	    svg_render_engine_t	*engine,
	    void		*closure)
{
    svg_status_t status;
    char orig_dir[MAXPATHLEN];

    if (svg->group_element == NULL)
	return SVG_STATUS_SUCCESS;

    /* XXX: Currently, the SVG parser doesn't resolve relative URLs
       properly, so I'll just cheese things in by changing the current
       directory -- at least I'll be nice about it and restore it
       afterwards. */

    getcwd (orig_dir, MAXPATHLEN);
    chdir (svg->dir_name);
    
    status = svg_element_render (svg->group_element, engine, closure);

    chdir (orig_dir);

    return status;
}
svg_status_t _svg_android_set_pattern (svg_android_t *svg_android,
				       svg_element_t *pattern_element,
				       svg_android_render_type_t type)
{
	svg_pattern_t *pattern = svg_element_pattern (pattern_element);
	jobject pattern_bitmap;
	jobject pattern_shader;
	double x_px, y_px, width_px, height_px;
	jobject path;

	_svg_android_length_to_pixel (svg_android, &pattern->x, &x_px);
	_svg_android_length_to_pixel (svg_android, &pattern->y, &y_px);
	_svg_android_length_to_pixel (svg_android, &pattern->width, &width_px);
	_svg_android_length_to_pixel (svg_android, &pattern->height, &height_px);

	/* OK. We've got the final path to be filled/stroked inside the
	 * android context right now. But we're also going to re-use that
	 * same context to draw the pattern. And since the path is no
	 * longer in the graphics state, android_save/restore will not help
	 * us here.
	 *
	 * Currently we deal with this by manually saving/restoring the
	 * path.
	 *
	 */
	path = svg_android->state->path;
	svg_android->state->path = ANDROID_PATH_CREATE(svg_android);
	ANDROID_SAVE(svg_android);

	pattern_bitmap = ANDROID_CREATE_BITMAP(svg_android,
					       (int) (width_px + 0.5),
					       (int) (height_px + 0.5));
	
	_svg_android_push_state (svg_android, pattern_bitmap, NULL);

	svg_android->state->matrix = ANDROID_IDENTITY_MATRIX(svg_android);
    
	svg_android->state->fill_paint.type = SVG_PAINT_TYPE_NONE;
	svg_android->state->stroke_paint.type = SVG_PAINT_TYPE_NONE;
    
	svg_element_render (pattern->group_element, &SVG_ANDROID_RENDER_ENGINE, svg_android);
	_svg_android_pop_state (svg_android);

	ANDROID_RESTORE(svg_android);

	svg_android->state->path = path ;

	pattern_shader = ANDROID_CREATE_BITMAP_SHADER(svg_android, pattern_bitmap);
	ANDROID_PAINT_SET_SHADER(svg_android, pattern_shader);
	
	return SVG_STATUS_SUCCESS;
}
Пример #3
0
svg_status_t
_svg_group_render (svg_group_t		*group,
		   svg_render_engine_t	*engine,
		   void			*closure)
{
    int i;
    svg_status_t status, return_status = SVG_STATUS_SUCCESS;

    /* XXX: Perhaps this isn't the cleanest way to do this. It would
       be cleaner to just immediately abort on an error I think. In
       order to do that, we'd need to fix the parser so that it
       doesn't include images with null data in the tree for
       example. */
    for (i=0; i < group->num_elements; i++) {
	status = svg_element_render (group->element[i],
				     engine, closure);
	if (status && !return_status)
		return_status = status;
    }

    return return_status;
}
svg_status_t _svg_android_set_pattern (svg_android_t *svg_android,
			  svg_element_t *pattern_element,
			  svg_android_render_type_t type)
{
	svg_pattern_t *pattern = svg_element_pattern (pattern_element);
	jobject pattern_bitmap;
	jobject pattern_shader;
	double x_px, y_px, width_px, height_px;
	jobject path;

	_svg_android_length_to_pixel (svg_android, &pattern->x, &x_px);
	_svg_android_length_to_pixel (svg_android, &pattern->y, &y_px);
	_svg_android_length_to_pixel (svg_android, &pattern->width, &width_px);
	_svg_android_length_to_pixel (svg_android, &pattern->height, &height_px);

	/* OK. We've got the final path to be filled/stroked inside the
	 * android context right now. But we're also going to re-use that
	 * same context to draw the pattern. And since the path is no
	 * longer in the graphics state, android_save/restore will not help
	 * us here.
	 *
	 * Currently we deal with this by manually saving/restoring the
	 * path.
	 *
	 * It might be simpler to just use a new cairo_t for drawing the
	 * pattern.
	 */
	path = svg_android->state->path; //cairo_copy_path (svg_android->cr);
	svg_android->state->path = ANDROID_PATH_CREATE(svg_android); // cairo_new_path (svg_android->cr);
	ANDROID_SAVE(svg_android);

	pattern_bitmap = ANDROID_CREATE_BITMAP(svg_android,
					       (int) (width_px + 0.5),
					       (int) (height_px + 0.5));
#if 0
	pattern_surface = cairo_surface_create_similar (cairo_get_target (svg_android->cr),
							CAIRO_FORMAT_ARGB32,
							(int) (width_px + 0.5),
							(int) (height_px + 0.5));
#endif
	
	_svg_android_push_state (svg_android, pattern_bitmap);

	svg_android->state->matrix = ANDROID_IDENTITY_MATRIX(svg_android);
	//cairo_identity_matrix (svg_android->cr);
    
	svg_android->state->fill_paint.type = SVG_PAINT_TYPE_NONE;
	svg_android->state->stroke_paint.type = SVG_PAINT_TYPE_NONE;
    
	svg_element_render (pattern->group_element, &SVG_ANDROID_RENDER_ENGINE, svg_android);
	_svg_android_pop_state (svg_android);

	ANDROID_RESTORE(svg_android);

	svg_android->state->path = path ;
#if 0
	cairo_new_path (svg_android->cr);
	cairo_append_path (svg_android->cr, path);
	cairo_path_destroy (path);
#endif

	pattern_shader = ANDROID_CREATE_BITMAP_SHADER(svg_android, pattern_bitmap);
	ANDROID_PAINT_SET_SHADER(svg_android, pattern_shader);

#if 0
	surface_pattern = cairo_pattern_create_for_surface (pattern_surface);
	cairo_surface_destroy (pattern_surface);
    
	cairo_pattern_set_extend (surface_pattern, CAIRO_EXTEND_REPEAT);
    
	cairo_set_source (svg_android->cr, surface_pattern);
    
	cairo_pattern_destroy (surface_pattern);
#endif
	
	return SVG_STATUS_SUCCESS;
}