int		db_meters(t_engine *e)
{
  int		i;

  if (!xml_next("meters"))
    return (put_error("Not found meters in xml"));
  e->db.meters = (t_base_meter*)xmalloc(sizeof(*e->db.meters));
  i = 0;
  while (i < e->db.nb_meters)
    {
      if (!xml_next("meter"))
	return (put_error("Not enough meter with the index table\n"));
      e->db.meters[i].name = xml_getstr("name");
      e->db.meters[i].type = xml_getstr("type");
      e->db.meters[i].value = xml_getint("value");
      e->db.meters[i].rr = xml_getint("rr");
      e->db.meters[i].is = xml_getint("is");
      e->db.meters[i].sr = xml_getint("sr");
      e->db.meters[i].sx = xml_getint("sx");
      e->db.meters[i].kv = xml_getint("kv");
      e->db.meters[i].min = xml_getint("min");
      e->db.meters[i++].max = xml_getint("max");
      e->db.meters = (t_base_meter*)xrealloc(e->db.meters,
					     sizeof(*e->db.meters) * (i + 1));
      xml_out();
    }
  e->db.meters[i].name = 0;
  xml_out();
  return (0);
}
int		db_weapon(t_engine *e, t_db_ind *ind)
{
  int		i;
  char		*buf;
  int		n;

  if (!xml_next("weapons"))
    return (put_error("Weapons not found in xml"));
  for (i = 0; i < ind->nb[TYPE_WEAPONS]; i++)
    {
      if (!xml_next("weapon"))
	return (put_error("Not enough weapon in xml"));
      if (!(e->db.weapons[i].name = xml_getstr("name")))
	return (put_error("Weapon without name !"));
      e->db.weapons[i].dmg = xml_getint("damage");
      e->db.weapons[i].rof = xml_getint("rof");
      e->db.weapons[i].range = xml_getint("range");
      buf = xml_getstr("projectile");
      for (n = 0; n < e->db.nb_instants; n++)
	if (!strcmp(e->db.instants[n].name, buf))
	  break;
      free(buf);
      if (n && n >= e->db.nb_instants)
	return (put_error("Weapon with Projectile not found"));
      e->db.weapons[i].projectile = &e->db.instants[n];
      if (!xml_next("types"))
	return (put_error("Weapon without type was found"));
      e->db.weapons[i].allowed = db_get_types(e);
      xml_out();
      xml_out();
    }
  xml_out();
  return (0);
}
Ejemplo n.º 3
0
static int
xps_find_doc_props_path(xps_context *ctx, char path[1024])
{
	xml_element *root;

	int code = xps_open_and_parse(ctx, "/_rels/.rels", &root);
	if (code != fz_okay)
		return code;

	*path = '\0';
	if (!strcmp(xml_tag(root), "Relationships"))
	{
		xml_element *item;
		for (item = xml_down(root); item; item = xml_next(item))
		{
			if (!strcmp(xml_tag(item), "Relationship") && xml_att(item, "Type") &&
				!strcmp(xml_att(item, "Type"), REL_CORE_PROPERTIES) && xml_att(item, "Target"))
			{
				xps_absolute_path(path, "", xml_att(item, "Target"), 1024);
			}
		}
	}
	else
		code = fz_error_make(ctx->ctx, "couldn't parse part '/_rels/.rels'");

	xml_free_element(ctx->ctx, root);

	return code;
}
Ejemplo n.º 4
0
static int
xps_find_doc_props_path(xps_context *ctx, char path[1024])
{
	xml_element *root;

	int code = xps_open_and_parse(ctx, "/[Content_Types].xml", &root);
	if (code != fz_okay)
		return code;

	*path = '\0';
	if (root && !strcmp(xml_tag(root), "Types"))
	{
		xml_element *item;
		for (item = xml_down(root); item; item = xml_next(item))
		{
			if (!strcmp(xml_tag(item), "Override") && xml_att(item, "ContentType") &&
				!strcmp(xml_att(item, "ContentType"), CONTENT_TYPE_CORE_PROPS) &&
				xml_att(item, "PartName"))
			{
				fz_strlcpy(path, xml_att(item, "PartName"), 1024);
			}
		}
	}
	else
		code = fz_throw("couldn't parse part '[Content_Types].xml'");

	xml_free_element(root);

	return code;
}
Ejemplo n.º 5
0
void
xps_parse_visual_brush(xps_context *ctx, fz_matrix ctm, fz_rect area,
	char *base_uri, xps_resource *dict, xml_element *root)
{
	xml_element *node;

	char *visual_uri;
	char *visual_att;
	xml_element *visual_tag = NULL;

	visual_att = xml_att(root, "Visual");

	for (node = xml_down(root); node; node = xml_next(node))
	{
		if (!strcmp(xml_tag(node), "VisualBrush.Visual"))
			visual_tag = xml_down(node);
	}

	visual_uri = base_uri;
	xps_resolve_resource_reference(ctx, dict, &visual_att, &visual_tag, &visual_uri);

	if (visual_tag)
	{
		xps_parse_tiling_brush(ctx, ctm, area,
			visual_uri, dict, root, xps_paint_visual_brush, visual_tag);
	}
}
Ejemplo n.º 6
0
static void
xps_parse_outline_imp(xps_outline **outlinep, xml_element *item, char *base_uri)
{
	int lastLevel = 0;
	for (; item; item = xml_next(item))
	{
		char *description, *target;
		int level;
		char tgtbuf[1024];
		xps_outline *outline;

		xps_parse_outline_imp(outlinep, xml_down(item), base_uri);

		if (strcmp(xml_tag(item), "OutlineEntry") != 0 ||
			!(description = xml_att(item, "Description")) ||
			!(target = xml_att(item, "OutlineTarget")))
			continue;
		if (xml_att(item, "OutlineLevel"))
			level = atoi(xml_att(item, "OutlineLevel"));
		else
			level = lastLevel;

		xps_absolute_path(tgtbuf, base_uri, target, sizeof(tgtbuf));
		outline = xps_new_outline(description, tgtbuf);
		if (!*outlinep)
			*outlinep = outline;
		else if (level > lastLevel)
			xps_get_insertion_point(*outlinep, lastLevel)->child = outline;
		else
			xps_get_insertion_point(*outlinep, level)->next = outline;
		lastLevel = level;
	}
}
Ejemplo n.º 7
0
static void
xps_parse_path_figure(fz_context *doc, fz_path *path, xml_element *root, int stroking)
{
    xml_element *node;

    char *is_closed_att;
    char *start_point_att;
    char *is_filled_att;

    int is_closed = 0;
    int is_filled = 1;
    float start_x = 0;
    float start_y = 0;

    int skipped_stroke = 0;

    is_closed_att = xml_att(root, "IsClosed");
    start_point_att = xml_att(root, "StartPoint");
    is_filled_att = xml_att(root, "IsFilled");

    if (is_closed_att)
        is_closed = !strcmp(is_closed_att, "true");
    if (is_filled_att)
        is_filled = !strcmp(is_filled_att, "true");
    if (start_point_att)
        xps_get_point(start_point_att, &start_x, &start_y);

    if (!stroking && !is_filled) /* not filled, when filling */
        return;

    fz_moveto(doc, path, start_x, start_y);

    for (node = xml_down(root); node; node = xml_next(node))
    {
        if (!strcmp(xml_tag(node), "ArcSegment"))
            xps_parse_arc_segment(doc, path, node, stroking, &skipped_stroke);
        if (!strcmp(xml_tag(node), "PolyBezierSegment"))
            xps_parse_poly_bezier_segment(doc, path, node, stroking, &skipped_stroke);
        if (!strcmp(xml_tag(node), "PolyLineSegment"))
            xps_parse_poly_line_segment(doc, path, node, stroking, &skipped_stroke);
        if (!strcmp(xml_tag(node), "PolyQuadraticBezierSegment"))
            xps_parse_poly_quadratic_bezier_segment(doc, path, node, stroking, &skipped_stroke);
    }

    if (is_closed)
    {
        if (stroking && skipped_stroke)
            fz_lineto(doc, path, start_x, start_y); /* we've skipped using fz_moveto... */
        else
            fz_closepath(doc, path); /* no skipped segments, safe to closepath properly */
    }
}
Ejemplo n.º 8
0
static int
xps_read_and_process_document_outline(xps_outline **outlinep, xps_context *ctx, xps_document *doc)
{
	char base_uri[1024];
	xml_element *root;
	xml_element *item;
	int code = fz_okay;

	xps_rels_for_part(base_uri, doc->name, sizeof(base_uri));

	code = xps_open_and_parse(ctx, base_uri, &root);
	if (code != fz_okay)
		return code;
	*strstr(base_uri, "/_rels/") = '\0';

	for (item = root; item; item = xml_next(item))
	{
		xml_element *relItem;
		if (strcmp(xml_tag(item), "Relationships") != 0)
			continue;
		for (relItem = xml_down(item); relItem; relItem = xml_next(relItem))
		{
			char *target, *type;
			if (!strcmp(xml_tag(relItem), "Relationship") &&
				(target = xml_att(relItem, "Target")) && (type = xml_att(relItem, "Type")) &&
				!strcmp(type, REL_DOC_STRUCTURE))
			{
				char tgtbuf[1024];
				xps_absolute_path(tgtbuf, base_uri, target, sizeof(tgtbuf));
				code = xps_parse_outline_structure(outlinep, ctx, tgtbuf);
			}
		}
	}

	xml_free_element(root);

	return code;
}
Ejemplo n.º 9
0
static void
xps_parse_metadata_imp(xps_context *ctx, xml_element *item)
{
	while (item)
	{
		xps_parse_metadata_imp(ctx, xml_down(item));

		if (!strcmp(xml_tag(item), "Relationship"))
		{
			char *target = xml_att(item, "Target");
			char *type = xml_att(item, "Type");
			if (target && type)
			{
				char tgtbuf[1024];
				xps_absolute_path(tgtbuf, ctx->base_uri, target, sizeof tgtbuf);
				if (!strcmp(type, REL_START_PART))
					ctx->start_part = fz_strdup(tgtbuf);
			}
		}

		if (!strcmp(xml_tag(item), "DocumentReference"))
		{
			char *source = xml_att(item, "Source");
			if (source)
			{
				char srcbuf[1024];
				xps_absolute_path(srcbuf, ctx->base_uri, source, sizeof srcbuf);
				xps_add_fixed_document(ctx, srcbuf);
			}
		}

		if (!strcmp(xml_tag(item), "PageContent"))
		{
			char *source = xml_att(item, "Source");
			char *width_att = xml_att(item, "Width");
			char *height_att = xml_att(item, "Height");
			int width = width_att ? atoi(width_att) : 0;
			int height = height_att ? atoi(height_att) : 0;
			if (source)
			{
				char srcbuf[1024];
				xps_absolute_path(srcbuf, ctx->base_uri, source, sizeof srcbuf);
				xps_add_fixed_page(ctx, srcbuf, width, height);
			}
		}

		item = xml_next(item);
	}
}
Ejemplo n.º 10
0
static fz_outline *
xps_parse_document_outline(xps_context *ctx, xml_element *root)
{
	xml_element *node;
	fz_outline *head = NULL, *entry, *tail;
	int last_level = 1, this_level;
	for (node = xml_down(root); node; node = xml_next(node))
	{
		if (!strcmp(xml_tag(node), "OutlineEntry"))
		{
			char *level = xml_att(node, "OutlineLevel");
			char *target = xml_att(node, "OutlineTarget");
			char *description = xml_att(node, "Description");
			/* SumatraPDF: allow target-less outline entries */
			if (!description)
				continue;

			entry = fz_malloc(ctx->ctx, sizeof *entry);
			entry->title = fz_strdup(ctx->ctx, description);
			entry->page = -1;
			/* SumatraPDF: extended outline actions */
			entry->data = target ? fz_strdup(ctx->ctx, target) : NULL;
			if (target && !xps_is_external_uri(target))
				entry->page = xps_find_link_target(ctx, target);
			entry->free_data = fz_free;
			entry->down = NULL;
			entry->next = NULL;

			this_level = level ? atoi(level) : 1;
			entry->is_open = this_level == 1; /* SumatraPDF: support expansion states */

			if (!head)
{
				head = entry;
}
			else
{
				tail = xps_find_last_outline_at_level(head, 1, this_level);
				if (this_level > last_level)
					tail->down = entry;
				else
					tail->next = entry;
}

			last_level = this_level;
}
}
	return head;
}
Ejemplo n.º 11
0
int
xps_parse_resource_dictionary(xps_context *ctx, xps_resource **dictp, char *base_uri, xml_element *root)
{
	xps_resource *head;
	xps_resource *entry;
	xml_element *node;
	char *source;
	char *key;
	int code;

	source = xml_att(root, "Source");
	if (source)
	{
		code = xps_parse_remote_resource_dictionary(ctx, dictp, base_uri, source);
		if (code)
			return fz_rethrow(code, "cannot parse remote resource dictionary");
		return fz_okay;
	}

	head = NULL;

	for (node = xml_down(root); node; node = xml_next(node))
	{
		key = xml_att(node, "x:Key");
		if (key)
		{
			entry = fz_malloc(sizeof(xps_resource));
			entry->name = key;
			entry->base_uri = NULL;
			entry->base_xml = NULL;
			entry->data = node;
			entry->next = head;
			entry->parent = NULL;
			head = entry;
		}
	}

	if (head)
	{
		head->base_uri = fz_strdup(base_uri);
	}

	*dictp = head;
	return fz_okay;
}
Ejemplo n.º 12
0
xml_element *
xps_lookup_alternate_content(xml_element *node)
{
	for (node = xml_down(node); node; node = xml_next(node))
	{
		if (!strcmp(xml_tag(node), "mc:Choice") && xml_att(node, "Requires"))
		{
			char list[64];
			char *next = list, *item;
			fz_strlcpy(list, xml_att(node, "Requires"), sizeof(list));
			while ((item = fz_strsep(&next, " \t\r\n")) && (!*item || !strcmp(item, "xps")));
			if (!item)
				return xml_down(node);
		}
		else if (!strcmp(xml_tag(node), "mc:Fallback"))
			return xml_down(node);
	}
	return NULL;
}
int		db_base_instant(t_engine *e, t_db_ind *ind)
{
  int		i;

  for (i = 0; i < ind->nb[TYPE_INSTANTS]; i++)
    {
      if (!xml_next("instant"))
	return (put_error("Not found instants in xml"));
      e->db.instants[i].name = xml_getstr("name");
      e->db.instants[i].idsprite = unpack_sprite(xml_getstr("sprite"));
      e->db.instants[i].idtaunt = unpack_taunt(xml_getstr("taunt"));
      e->db.instants[i].damage = xml_getint("damage");
      e->db.instants[i].splash = xml_getint("splash");
      e->db.instants[i].speed = xml_getint("speed");
      e->db.instants[i].time = xml_getint("time");
      xml_out();
    }
  return (0);
}
Ejemplo n.º 14
0
void
xps_parse_fixed_page(xps_context *ctx, fz_matrix ctm, xps_page *page)
{
	xml_element *node;
	xps_resource *dict;
	char base_uri[1024];
	fz_rect area;
	char *s;
	int code;

	fz_strlcpy(base_uri, page->name, sizeof base_uri);
	s = strrchr(base_uri, '/');
	if (s)
		s[1] = 0;

	dict = NULL;

	ctx->opacity_top = 0;
	ctx->opacity[0] = 1;

	if (!page->root)
		return;

	area = fz_transform_rect(fz_scale(page->width, page->height), fz_unit_rect);

	for (node = xml_down(page->root); node; node = xml_next(node))
	{
		if (!strcmp(xml_tag(node), "FixedPage.Resources") && xml_down(node))
		{
			code = xps_parse_resource_dictionary(ctx, &dict, base_uri, xml_down(node));
			if (code)
				fz_catch(code, "cannot load FixedPage.Resources");
		}
		xps_parse_element(ctx, ctm, area, base_uri, dict, node);
	}

	if (dict)
	{
		xps_free_resource_dictionary(ctx, dict);
	}
}
Ejemplo n.º 15
0
static void
xps_parse_names_imp(xps_named_dest **destsp, xps_context *ctx, xps_document *doc, xml_element *item, char *base_uri, int page)
{
	char tgtbuf[1024];

	for (; item; item = xml_next(item))
	{
		if (!strcmp(xml_tag(item), "PageContent") && xml_att(item, "Source") && page == 0)
		{
			int i;
			xps_page *page;
			xps_absolute_path(tgtbuf, base_uri, xml_att(item, "Source"), sizeof(tgtbuf));
			for (page = ctx->first_page, i = 0; page; page = page->next, i++)
			{
				if (strcmp(page->name, tgtbuf) != 0)
					continue;
				xps_parse_names_imp(destsp, ctx, doc, xml_down(item), base_uri, i + 1);
				break;
			}
		}
		else if (!strcmp(xml_tag(item), "LinkTarget") && xml_att(item, "Name") && page != 0)
		{
			xps_named_dest *dest;
			fz_strlcpy(tgtbuf, doc->name, sizeof(tgtbuf));
			fz_strlcat(tgtbuf, "#", sizeof(tgtbuf));
			fz_strlcat(tgtbuf, xml_att(item, "Name"), sizeof(tgtbuf));
			dest = xps_new_named_dest(tgtbuf, page);
			if (!*destsp)
				*destsp = dest;
			else
			{
				xps_named_dest *next;
				for (next = *destsp; next->next; next = next->next);
				next->next = dest;
			}
		}
		else
			xps_parse_names_imp(destsp, ctx, doc, xml_down(item), base_uri, page);
	}
}
Ejemplo n.º 16
0
xps_resource *
xps_parse_resource_dictionary(xps_document *doc, char *base_uri, xml_element *root)
{
	xps_resource *head;
	xps_resource *entry;
	xml_element *node;
	char *source;
	char *key;

	source = xml_att(root, "Source");
	if (source)
		return xps_parse_remote_resource_dictionary(doc, base_uri, source);

	head = NULL;

	for (node = xml_down(root); node; node = xml_next(node))
	{
		key = xml_att(node, "x:Key");
		if (key)
		{
			entry = fz_malloc_struct(doc->ctx, xps_resource);
			entry->name = key;
			entry->base_uri = NULL;
			entry->base_xml = NULL;
			entry->data = node;
			entry->next = head;
			entry->parent = NULL;
			head = entry;
		}
	}

	if (head)
		head->base_uri = fz_strdup(doc->ctx, base_uri);
	else
		fz_warn(doc->ctx, "empty resource dictionary");

	return head;
}
Ejemplo n.º 17
0
void
xps_parse_canvas(xps_context *ctx, fz_matrix ctm, fz_rect area, char *base_uri, xps_resource *dict, xml_element *root)
{
	xps_resource *new_dict = NULL;
	xml_element *node;
	char *opacity_mask_uri;
	int code;

	char *transform_att;
	char *clip_att;
	char *opacity_att;
	char *opacity_mask_att;

	xml_element *transform_tag = NULL;
	xml_element *clip_tag = NULL;
	xml_element *opacity_mask_tag = NULL;

	fz_matrix transform;

	transform_att = xml_att(root, "RenderTransform");
	clip_att = xml_att(root, "Clip");
	opacity_att = xml_att(root, "Opacity");
	opacity_mask_att = xml_att(root, "OpacityMask");

	for (node = xml_down(root); node; node = xml_next(node))
	{
		if (!strcmp(xml_tag(node), "Canvas.Resources") && xml_down(node))
		{
			code = xps_parse_resource_dictionary(ctx, &new_dict, base_uri, xml_down(node));
			if (code)
				fz_catch(code, "cannot load Canvas.Resources");
			else
			{
				new_dict->parent = dict;
				dict = new_dict;
			}
		}

		if (!strcmp(xml_tag(node), "Canvas.RenderTransform"))
			transform_tag = xml_down(node);
		if (!strcmp(xml_tag(node), "Canvas.Clip"))
			clip_tag = xml_down(node);
		if (!strcmp(xml_tag(node), "Canvas.OpacityMask"))
			opacity_mask_tag = xml_down(node);
	}

	opacity_mask_uri = base_uri;
	xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL);
	xps_resolve_resource_reference(ctx, dict, &clip_att, &clip_tag, NULL);
	xps_resolve_resource_reference(ctx, dict, &opacity_mask_att, &opacity_mask_tag, &opacity_mask_uri);

	transform = fz_identity;
	if (transform_att)
		xps_parse_render_transform(ctx, transform_att, &transform);
	if (transform_tag)
		xps_parse_matrix_transform(ctx, transform_tag, &transform);
	ctm = fz_concat(transform, ctm);

	if (clip_att || clip_tag)
		xps_clip(ctx, ctm, dict, clip_att, clip_tag);

	xps_begin_opacity(ctx, ctm, area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag);

	for (node = xml_down(root); node; node = xml_next(node))
	{
		xps_parse_element(ctx, ctm, area, base_uri, dict, node);
	}

	xps_end_opacity(ctx, opacity_mask_uri, dict, opacity_att, opacity_mask_tag);

	if (clip_att || clip_tag)
		fz_pop_clip(ctx->dev);

	if (new_dict)
		xps_free_resource_dictionary(ctx, new_dict);
}
Ejemplo n.º 18
0
void
xps_parse_tiling_brush(xps_context *ctx, fz_matrix ctm, fz_rect area,
	char *base_uri, xps_resource *dict, xml_element *root,
	void (*func)(xps_context*, fz_matrix, fz_rect, char*, xps_resource*, xml_element*, void*), void *user)
{
	xml_element *node;
	struct closure c;

	char *opacity_att;
	char *transform_att;
	char *viewbox_att;
	char *viewport_att;
	char *tile_mode_att;
	char *viewbox_units_att;
	char *viewport_units_att;

	xml_element *transform_tag = NULL;

	fz_matrix transform;
	fz_rect viewbox;
	fz_rect viewport;
	float xstep, ystep;
	float xscale, yscale;
	int tile_mode;

	opacity_att = xml_att(root, "Opacity");
	transform_att = xml_att(root, "Transform");
	viewbox_att = xml_att(root, "Viewbox");
	viewport_att = xml_att(root, "Viewport");
	tile_mode_att = xml_att(root, "TileMode");
	viewbox_units_att = xml_att(root, "ViewboxUnits");
	viewport_units_att = xml_att(root, "ViewportUnits");

	c.base_uri = base_uri;
	c.dict = dict;
	c.root = root;
	c.user = user;
	c.func = func;

	for (node = xml_down(root); node; node = xml_next(node))
	{
		if (!strcmp(xml_tag(node), "ImageBrush.Transform"))
			transform_tag = xml_down(node);
		if (!strcmp(xml_tag(node), "VisualBrush.Transform"))
			transform_tag = xml_down(node);
	}

	xps_resolve_resource_reference(ctx, dict, &transform_att, &transform_tag, NULL);

	transform = fz_identity;
	if (transform_att)
		xps_parse_render_transform(ctx, transform_att, &transform);
	if (transform_tag)
		xps_parse_matrix_transform(ctx, transform_tag, &transform);
	ctm = fz_concat(transform, ctm);

	viewbox = fz_unit_rect;
	if (viewbox_att)
		xps_parse_rectangle(ctx, viewbox_att, &viewbox);

	viewport = fz_unit_rect;
	if (viewport_att)
		xps_parse_rectangle(ctx, viewport_att, &viewport);

	/* some sanity checks on the viewport/viewbox size */
	if (fabsf(viewport.x1 - viewport.x0) < 0.01f) return;
	if (fabsf(viewport.y1 - viewport.y0) < 0.01f) return;
	if (fabsf(viewbox.x1 - viewbox.x0) < 0.01f) return;
	if (fabsf(viewbox.y1 - viewbox.y0) < 0.01f) return;

	xstep = viewbox.x1 - viewbox.x0;
	ystep = viewbox.y1 - viewbox.y0;

	xscale = (viewport.x1 - viewport.x0) / xstep;
	yscale = (viewport.y1 - viewport.y0) / ystep;

	tile_mode = TILE_NONE;
	if (tile_mode_att)
	{
		if (!strcmp(tile_mode_att, "None"))
			tile_mode = TILE_NONE;
		if (!strcmp(tile_mode_att, "Tile"))
			tile_mode = TILE_TILE;
		if (!strcmp(tile_mode_att, "FlipX"))
			tile_mode = TILE_FLIP_X;
		if (!strcmp(tile_mode_att, "FlipY"))
			tile_mode = TILE_FLIP_Y;
		if (!strcmp(tile_mode_att, "FlipXY"))
			tile_mode = TILE_FLIP_X_Y;
	}

	if (tile_mode == TILE_FLIP_X || tile_mode == TILE_FLIP_X_Y)
		xstep *= 2;
	if (tile_mode == TILE_FLIP_Y || tile_mode == TILE_FLIP_X_Y)
		ystep *= 2;

	xps_begin_opacity(ctx, ctm, area, base_uri, dict, opacity_att, NULL);

	ctm = fz_concat(fz_translate(viewport.x0, viewport.y0), ctm);
	ctm = fz_concat(fz_scale(xscale, yscale), ctm);
	ctm = fz_concat(fz_translate(-viewbox.x0, -viewbox.y0), ctm);

	if (tile_mode != TILE_NONE)
	{
		int x0, y0, x1, y1;
		fz_matrix invctm = fz_invert_matrix(ctm);
		area = fz_transform_rect(invctm, area);
		x0 = floorf(area.x0 / xstep);
		y0 = floorf(area.y0 / ystep);
		x1 = ceilf(area.x1 / xstep);
		y1 = ceilf(area.y1 / ystep);

#ifdef TILE
		if ((x1 - x0) * (y1 - y0) > 1)
#else
		if (0)
#endif
		{
			fz_rect bigview = viewbox;
			bigview.x1 = bigview.x0 + xstep;
			bigview.y1 = bigview.y0 + ystep;
			fz_begin_tile(ctx->dev, area, bigview, xstep, ystep, ctm);
			xps_paint_tiling_brush(ctx, ctm, viewbox, tile_mode, &c);
			fz_end_tile(ctx->dev);
		}
		else
		{
			int x, y;
			for (y = y0; y < y1; y++)
			{
				for (x = x0; x < x1; x++)
				{
					fz_matrix ttm = fz_concat(fz_translate(xstep * x, ystep * y), ctm);
					xps_paint_tiling_brush(ctx, ttm, viewbox, tile_mode, &c);
				}
			}
		}
	}
	else
	{
		xps_paint_tiling_brush(ctx, ctm, viewbox, tile_mode, &c);
	}

	xps_end_opacity(ctx, base_uri, dict, opacity_att, NULL);
}
Ejemplo n.º 19
0
int pi_rrd_load (xml_node_t * base)
{
  xml_node_t *node;
  rrd_ctxt_t *rrd;
  unsigned char *name = NULL, *file = NULL, *dp = NULL, *spec = NULL;
  unsigned long period;

  base = xml_node_find (base, "RRDs");
  if (!base)
    return PLUGIN_RETVAL_CONTINUE;

  for (rrd = rrdlist.next; rrd != &rrdlist; rrd = rrdlist.next)
    pi_rrd_delete (rrd);

  for (node = base->children; node; node = xml_next (node)) {
    if (!xml_child_get (node, "Name", XML_TYPE_STRING, &name))
      continue;
    if (!xml_child_get (node, "File", XML_TYPE_STRING, &file))
      continue;
    if (!xml_child_get (node, "Period", XML_TYPE_ULONG, &period))
      continue;


    rrd = pi_rrd_create (name, file, period);
    if (!rrd)
      continue;

    base = node;
    node = xml_node_find (base, "DataPoints");
    for (node = node->children; node; node = xml_next (node)) {
      if (!xml_child_get (node, "Name", XML_TYPE_STRING, &name))
	continue;
      if (!xml_child_get (node, "Specification", XML_TYPE_STRING, &spec))
	continue;

      rrd->npoints++;
      pi_rrd_datapoint_create (NULL, &rrd->points, name, spec);
    }

    node = xml_node_find (base, "RRAs");
    for (node = node->children; node; node = xml_next (node)) {
      pi_rrd_datapoint_create (NULL, &rrd->rras, NULL, node->value);
      rrd->nrras++;
    }

    node = base;

    pi_rrd_start (rrd);
  }

  if (name)
    free (name);
  if (file)
    free (file);
  if (dp)
    free (dp);
  if (spec)
    free (spec);

  return PLUGIN_RETVAL_CONTINUE;
}
Ejemplo n.º 20
0
void
xps_parse_path(xps_document *doc, fz_matrix ctm, char *base_uri, xps_resource *dict, xml_element *root)
{
    xml_element *node;

    char *fill_uri;
    char *stroke_uri;
    char *opacity_mask_uri;

    char *transform_att;
    char *clip_att;
    char *data_att;
    char *fill_att;
    char *stroke_att;
    char *opacity_att;
    char *opacity_mask_att;

    xml_element *transform_tag = NULL;
    xml_element *clip_tag = NULL;
    xml_element *data_tag = NULL;
    xml_element *fill_tag = NULL;
    xml_element *stroke_tag = NULL;
    xml_element *opacity_mask_tag = NULL;

    char *fill_opacity_att = NULL;
    char *stroke_opacity_att = NULL;

    char *stroke_dash_array_att;
    char *stroke_dash_cap_att;
    char *stroke_dash_offset_att;
    char *stroke_end_line_cap_att;
    char *stroke_start_line_cap_att;
    char *stroke_line_join_att;
    char *stroke_miter_limit_att;
    char *stroke_thickness_att;
    char *navigate_uri_att;

    fz_stroke_state stroke;
    fz_matrix transform;
    float samples[32];
    fz_colorspace *colorspace;
    fz_path *path;
    fz_rect area;
    int fill_rule;

    /*
     * Extract attributes and extended attributes.
     */

    transform_att = xml_att(root, "RenderTransform");
    clip_att = xml_att(root, "Clip");
    data_att = xml_att(root, "Data");
    fill_att = xml_att(root, "Fill");
    stroke_att = xml_att(root, "Stroke");
    opacity_att = xml_att(root, "Opacity");
    opacity_mask_att = xml_att(root, "OpacityMask");

    stroke_dash_array_att = xml_att(root, "StrokeDashArray");
    stroke_dash_cap_att = xml_att(root, "StrokeDashCap");
    stroke_dash_offset_att = xml_att(root, "StrokeDashOffset");
    stroke_end_line_cap_att = xml_att(root, "StrokeEndLineCap");
    stroke_start_line_cap_att = xml_att(root, "StrokeStartLineCap");
    stroke_line_join_att = xml_att(root, "StrokeLineJoin");
    stroke_miter_limit_att = xml_att(root, "StrokeMiterLimit");
    stroke_thickness_att = xml_att(root, "StrokeThickness");
    navigate_uri_att = xml_att(root, "FixedPage.NavigateUri");

    for (node = xml_down(root); node; node = xml_next(node))
    {
        if (!strcmp(xml_tag(node), "Path.RenderTransform"))
            transform_tag = xml_down(node);
        if (!strcmp(xml_tag(node), "Path.OpacityMask"))
            opacity_mask_tag = xml_down(node);
        if (!strcmp(xml_tag(node), "Path.Clip"))
            clip_tag = xml_down(node);
        if (!strcmp(xml_tag(node), "Path.Fill"))
            fill_tag = xml_down(node);
        if (!strcmp(xml_tag(node), "Path.Stroke"))
            stroke_tag = xml_down(node);
        if (!strcmp(xml_tag(node), "Path.Data"))
            data_tag = xml_down(node);
    }

    fill_uri = base_uri;
    stroke_uri = base_uri;
    opacity_mask_uri = base_uri;

    xps_resolve_resource_reference(doc, dict, &data_att, &data_tag, NULL);
    xps_resolve_resource_reference(doc, dict, &clip_att, &clip_tag, NULL);
    xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL);
    xps_resolve_resource_reference(doc, dict, &fill_att, &fill_tag, &fill_uri);
    xps_resolve_resource_reference(doc, dict, &stroke_att, &stroke_tag, &stroke_uri);
    xps_resolve_resource_reference(doc, dict, &opacity_mask_att, &opacity_mask_tag, &opacity_mask_uri);

    /*
     * Act on the information we have gathered:
     */

    if (!data_att && !data_tag)
        return;

    if (fill_tag && !strcmp(xml_tag(fill_tag), "SolidColorBrush"))
    {
        fill_opacity_att = xml_att(fill_tag, "Opacity");
        fill_att = xml_att(fill_tag, "Color");
        fill_tag = NULL;
    }

    if (stroke_tag && !strcmp(xml_tag(stroke_tag), "SolidColorBrush"))
    {
        stroke_opacity_att = xml_att(stroke_tag, "Opacity");
        stroke_att = xml_att(stroke_tag, "Color");
        stroke_tag = NULL;
    }

    stroke.start_cap = xps_parse_line_cap(stroke_start_line_cap_att);
    stroke.dash_cap = xps_parse_line_cap(stroke_dash_cap_att);
    stroke.end_cap = xps_parse_line_cap(stroke_end_line_cap_att);

    stroke.linejoin = FZ_LINEJOIN_MITER_XPS;
    if (stroke_line_join_att)
    {
        if (!strcmp(stroke_line_join_att, "Miter")) stroke.linejoin = FZ_LINEJOIN_MITER_XPS;
        if (!strcmp(stroke_line_join_att, "Round")) stroke.linejoin = FZ_LINEJOIN_ROUND;
        if (!strcmp(stroke_line_join_att, "Bevel")) stroke.linejoin = FZ_LINEJOIN_BEVEL;
    }

    stroke.miterlimit = 10;
    if (stroke_miter_limit_att)
        stroke.miterlimit = fz_atof(stroke_miter_limit_att);

    stroke.linewidth = 1;
    if (stroke_thickness_att)
        stroke.linewidth = fz_atof(stroke_thickness_att);

    stroke.dash_phase = 0;
    stroke.dash_len = 0;
    if (stroke_dash_array_att)
    {
        char *s = stroke_dash_array_att;

        if (stroke_dash_offset_att)
            stroke.dash_phase = fz_atof(stroke_dash_offset_att) * stroke.linewidth;

        while (*s && stroke.dash_len < nelem(stroke.dash_list))
        {
            while (*s == ' ')
                s++;
            if (*s) /* needed in case of a space before the last quote */
                stroke.dash_list[stroke.dash_len++] = fz_atof(s) * stroke.linewidth;
            while (*s && *s != ' ')
                s++;
        }
    }

    transform = fz_identity;
    if (transform_att)
        xps_parse_render_transform(doc, transform_att, &transform);
    if (transform_tag)
        xps_parse_matrix_transform(doc, transform_tag, &transform);
    ctm = fz_concat(transform, ctm);

    if (clip_att || clip_tag)
        xps_clip(doc, ctm, dict, clip_att, clip_tag);

    fill_rule = 0;
    if (data_att)
        path = xps_parse_abbreviated_geometry(doc, data_att, &fill_rule);
    else if (data_tag)
        path = xps_parse_path_geometry(doc, dict, data_tag, 0, &fill_rule);

    if (stroke_att || stroke_tag)
        area = fz_bound_path(doc->ctx, path, &stroke, ctm);
    else
        area = fz_bound_path(doc->ctx, path, NULL, ctm);

    if (navigate_uri_att)
        xps_add_link(doc, area, base_uri, navigate_uri_att);

    xps_begin_opacity(doc, ctm, area, opacity_mask_uri, dict, opacity_att, opacity_mask_tag);

    if (fill_att)
    {
        xps_parse_color(doc, base_uri, fill_att, &colorspace, samples);
        if (fill_opacity_att)
            samples[0] = fz_atof(fill_opacity_att);
        xps_set_color(doc, colorspace, samples);

        fz_fill_path(doc->dev, path, fill_rule == 0, ctm,
                     doc->colorspace, doc->color, doc->alpha);
    }

    if (fill_tag)
    {
        area = fz_bound_path(doc->ctx, path, NULL, ctm);

        fz_clip_path(doc->dev, path, NULL, fill_rule == 0, ctm);
        xps_parse_brush(doc, ctm, area, fill_uri, dict, fill_tag);
        fz_pop_clip(doc->dev);
    }

    if (stroke_att)
    {
        xps_parse_color(doc, base_uri, stroke_att, &colorspace, samples);
        if (stroke_opacity_att)
            samples[0] = fz_atof(stroke_opacity_att);
        xps_set_color(doc, colorspace, samples);

        fz_stroke_path(doc->dev, path, &stroke, ctm,
                       doc->colorspace, doc->color, doc->alpha);
    }

    if (stroke_tag)
    {
        fz_clip_stroke_path(doc->dev, path, NULL, &stroke, ctm);
        xps_parse_brush(doc, ctm, area, stroke_uri, dict, stroke_tag);
        fz_pop_clip(doc->dev);
    }

    xps_end_opacity(doc, opacity_mask_uri, dict, opacity_att, opacity_mask_tag);

    fz_free_path(doc->ctx, path);
    path = NULL;

    if (clip_att || clip_tag)
        fz_pop_clip(doc->dev);
}
Ejemplo n.º 21
0
fz_path *
xps_parse_path_geometry(xps_document *doc, xps_resource *dict, xml_element *root, int stroking, int *fill_rule)
{
    xml_element *node;

    char *figures_att;
    char *fill_rule_att;
    char *transform_att;

    xml_element *transform_tag = NULL;
    xml_element *figures_tag = NULL; /* only used by resource */

    fz_matrix transform;
    fz_path *path;

    figures_att = xml_att(root, "Figures");
    fill_rule_att = xml_att(root, "FillRule");
    transform_att = xml_att(root, "Transform");

    for (node = xml_down(root); node; node = xml_next(node))
    {
        if (!strcmp(xml_tag(node), "PathGeometry.Transform"))
            transform_tag = xml_down(node);
    }

    xps_resolve_resource_reference(doc, dict, &transform_att, &transform_tag, NULL);
    xps_resolve_resource_reference(doc, dict, &figures_att, &figures_tag, NULL);

    if (fill_rule_att)
    {
        if (!strcmp(fill_rule_att, "NonZero"))
            *fill_rule = 1;
        if (!strcmp(fill_rule_att, "EvenOdd"))
            *fill_rule = 0;
    }

    transform = fz_identity;
    if (transform_att)
        xps_parse_render_transform(doc, transform_att, &transform);
    if (transform_tag)
        xps_parse_matrix_transform(doc, transform_tag, &transform);

    if (figures_att)
        path = xps_parse_abbreviated_geometry(doc, figures_att, fill_rule);
    else
        path = fz_new_path(doc->ctx);

    if (figures_tag)
        xps_parse_path_figure(doc->ctx, path, figures_tag, stroking);

    for (node = xml_down(root); node; node = xml_next(node))
    {
        if (!strcmp(xml_tag(node), "PathFigure"))
            xps_parse_path_figure(doc->ctx, path, node, stroking);
    }

    if (transform_att || transform_tag)
        fz_transform_path(doc->ctx, path, transform);

    return path;
}
Ejemplo n.º 22
0
unsigned long pi_configlock_event_load (plugin_user_t * user, void *dummy, unsigned long event,
                                        void *arg)
{
    FILE *fp;
    configlock_t *lock;
    config_element_t *elem;
    xml_node_t *base, *node;

    if (!arg)
        goto leave;

    while (locklist) {
        lock = locklist;
        locklist = locklist->next;
        free (lock);
    }

    fp = fopen ("configlock.xml", "r");
    if (!fp)
        goto leave;

    base = xml_read (fp);
    if (!base) {
        fclose (fp);
        goto leave;
    }

    if (strcmp (base->name, HUBSOFT_NAME)) {
        xml_free (base);
        goto leave;
    }

    config_load (base);

    node = xml_node_find (base, "Config");
    for (node = node->children; node; node = xml_next (node)) {
        elem = config_find (node->name);
        if (!elem)
            continue;

        lock = malloc (sizeof (configlock_t));
        memset (lock, 0, sizeof (configlock_t));

        lock->elem = elem;
        strncpy (lock->name, elem->name, CONFIG_NAMELENGTH);

        xml_node_get (node, elem->type, &lock->data.v_ptr);

        lock->next = locklist;
        locklist = lock;
    }

    xml_free (base);

    fclose (fp);

    return PLUGIN_RETVAL_CONTINUE;

leave:
    return pi_configlock_event_load_old (user, dummy, event, NULL);
}