Until now, group_items and text_items have had a command name, but SPV
files make the command name part of every output_item. This change
make output_item better aligned.
result = CMD_FAILURE;
goto finish;
}
result = CMD_FAILURE;
goto finish;
}
- group_open_item_submit (group_open_item_create_nocopy (
- utf8_to_title (command->name), NULL));
+ group_open_item_submit (
+ group_open_item_create_nocopy (utf8_to_title (command->name),
+ utf8_to_title (command->name)));
opened = true;
if (command->function == NULL)
opened = true;
if (command->function == NULL)
{
parent_group_id = add_outline (
p->cr, parent_group_id,
{
parent_group_id = add_outline (
p->cr, parent_group_id,
- p->group_opens[i]->command_name, attrs,
- CAIRO_PDF_OUTLINE_FLAG_OPEN);
+ output_item_get_label (&p->group_opens[i]->output_item),
+ attrs, CAIRO_PDF_OUTLINE_FLAG_OPEN);
group_open_item_unref (p->group_opens[i]);
if (p->n_group_ids >= p->allocated_group_ids)
group_open_item_unref (p->group_opens[i]);
if (p->n_group_ids >= p->allocated_group_ids)
e->groups = x2nrealloc (e->groups, &e->allocated_groups,
sizeof *e->groups);
e->groups[e->n_groups] = xstrdup_if_nonnull (
e->groups = x2nrealloc (e->groups, &e->allocated_groups,
sizeof *e->groups);
e->groups[e->n_groups] = xstrdup_if_nonnull (
- group_open_item->command_name);
+ group_open_item->output_item.command_name);
e->n_groups++;
}
else if (is_group_close_item (item))
e->n_groups++;
}
else if (is_group_close_item (item))
*item = (struct group_open_item) {
.output_item = OUTPUT_ITEM_INITIALIZER (&group_open_item_class),
.output_item.label = label,
*item = (struct group_open_item) {
.output_item = OUTPUT_ITEM_INITIALIZER (&group_open_item_class),
.output_item.label = label,
- .command_name = command_name,
+ .output_item.command_name = command_name,
{
struct group_open_item *item = to_group_open_item (output_item);
{
struct group_open_item *item = to_group_open_item (output_item);
- return item->command_name ? item->command_name : _("Group");
+ return (item->output_item.command_name
+ ? item->output_item.command_name
+ : _("Group"));
{
struct group_open_item *item = to_group_open_item (output_item);
{
struct group_open_item *item = to_group_open_item (output_item);
- free (item->command_name);
struct group_open_item
{
struct output_item output_item;
struct group_open_item
{
struct output_item output_item;
-
- /* Locale-invariant name of the command that produced the enclosed output.
- May be NULL if the group doesn't enclose a particular command's
- output. */
- char *command_name;
};
struct group_open_item *group_open_item_create (const char *command_name,
};
struct group_open_item *group_open_item_create (const char *command_name,
.class = (SRC)->class, \
.ref_cnt = 1, \
.label = xstrdup_if_nonnull ((SRC)->label), \
.class = (SRC)->class, \
.ref_cnt = 1, \
.label = xstrdup_if_nonnull ((SRC)->label), \
+ .command_name = xstrdup_if_nonnull ((SRC)->command_name), \
}
#endif /* output/output-item-provider.h */
}
#endif /* output/output-item-provider.h */
if (--item->ref_cnt == 0)
{
char *label = item->label;
if (--item->ref_cnt == 0)
{
char *label = item->label;
+ char *command_name = item->command_name;
item->class->destroy (item);
free (label);
item->class->destroy (item);
free (label);
Use output_item_get_label() to read an item's label. */
char *label;
Use output_item_get_label() to read an item's label. */
char *label;
+
+ /* A locale-invariant identifier for the command that produced the output,
+ which may be NULL if unknown or if a command did not produce this
+ output. */
+ char *command_name;
};
struct output_item *output_item_ref (const struct output_item *);
};
struct output_item *output_item_ref (const struct output_item *);
-spv_writer_open_heading (struct spv_writer *w, const char *command_id,
- const char *label)
+spv_writer_open_heading (struct spv_writer *w, const struct output_item *item)
w->heading_depth++;
start_elem (w, "heading");
w->heading_depth++;
start_elem (w, "heading");
- write_attr (w, "commandName", command_id);
+ if (item->command_name)
+ write_attr (w, "commandName", item->command_name);
/* XXX locale */
/* XXX olang */
start_elem (w, "label");
/* XXX locale */
/* XXX olang */
start_elem (w, "label");
+ write_text (w, output_item_get_label (item));
-start_container (struct spv_writer *w, const struct output_item *item)
+open_container (struct spv_writer *w, const struct output_item *item,
+ const char *inner_elem)
{
start_elem (w, "container");
write_attr (w, "visibility", "visible");
{
start_elem (w, "container");
write_attr (w, "visibility", "visible");
start_elem (w, "label");
write_text (w, output_item_get_label (item));
end_elem (w);
start_elem (w, "label");
write_text (w, output_item_get_label (item));
end_elem (w);
+
+ start_elem (w, inner_elem);
+ if (item->command_name)
+ write_attr (w, "commandName", item->command_name);
+}
+
+static void
+close_container (struct spv_writer *w)
+{
+ end_elem (w);
+ end_elem (w);
-spv_writer_put_text (struct spv_writer *w, const struct text_item *text,
- const char *command_id)
+spv_writer_put_text (struct spv_writer *w, const struct text_item *text)
{
bool initial_depth = w->heading_depth;
if (!initial_depth)
spv_writer_open_file (w);
{
bool initial_depth = w->heading_depth;
if (!initial_depth)
spv_writer_open_file (w);
- start_container (w, &text->output_item);
-
- start_elem (w, "vtx:text");
+ open_container (w, &text->output_item, "vtx:text");
write_attr (w, "type", (text->type == TEXT_ITEM_TITLE ? "title"
: text->type == TEXT_ITEM_PAGE_TITLE ? "page-title"
: "log"));
write_attr (w, "type", (text->type == TEXT_ITEM_TITLE ? "title"
: text->type == TEXT_ITEM_PAGE_TITLE ? "page-title"
: "log"));
- if (command_id)
- write_attr (w, "commandName", command_id);
start_elem (w, "html");
char *s = text_item_get_plain_text (text);
write_text (w, s);
free (s);
start_elem (w, "html");
char *s = text_item_get_plain_text (text);
write_text (w, s);
free (s);
- end_elem (w); /* html */
- end_elem (w); /* vtx:text */
- end_elem (w); /* container */
+ end_elem (w);
+
+ close_container (w);
if (!initial_depth)
spv_writer_close_file (w, "");
if (!initial_depth)
spv_writer_close_file (w, "");
char *uri = xasprintf ("%010d_Imagegeneric.png", ++w->n_tables);
char *uri = xasprintf ("%010d_Imagegeneric.png", ++w->n_tables);
- start_container (w, item);
-
- start_elem (w, "object");
+ open_container (w, item, "object");
write_attr (w, "type", "unknown");
write_attr (w, "uri", uri);
write_attr (w, "type", "unknown");
write_attr (w, "uri", uri);
- end_elem (w); /* object */
- end_elem (w); /* container */
if (!initial_depth)
spv_writer_close_file (w, "");
if (!initial_depth)
spv_writer_close_file (w, "");
if (!initial_depth)
spv_writer_open_file (w);
if (!initial_depth)
spv_writer_open_file (w);
- start_container (w, &item->output_item);
+ open_container (w, &item->output_item, "vtb:table");
+ write_attr (w, "type", "table"); /* XXX */
+ write_attr_format (w, "tableId", "%d", table_id);
char *subtype = (item->pt->subtype
? pivot_value_to_string (item->pt->subtype, item->pt)
: xstrdup ("unknown"));
char *subtype = (item->pt->subtype
? pivot_value_to_string (item->pt->subtype, item->pt)
: xstrdup ("unknown"));
-
- start_elem (w, "vtb:table");
- write_attr (w, "commandName", item->pt->command_c);
- write_attr (w, "type", "table"); /* XXX */
write_attr (w, "subType", subtype);
write_attr (w, "subType", subtype);
- write_attr_format (w, "tableId", "%d", table_id);
-
free (subtype);
start_elem (w, "vtb:tableStructure");
free (subtype);
start_elem (w, "vtb:tableStructure");
write_text (w, data_path);
end_elem (w); /* vtb:dataPath */
end_elem (w); /* vtb:tableStructure */
write_text (w, data_path);
end_elem (w); /* vtb:dataPath */
end_elem (w); /* vtb:tableStructure */
- end_elem (w); /* vtb:table */
- end_elem (w); /* container */
if (!initial_depth)
spv_writer_close_file (w, "");
if (!initial_depth)
spv_writer_close_file (w, "");
spv_writer_write (struct spv_writer *w, const struct output_item *item)
{
if (is_group_open_item (item))
spv_writer_write (struct spv_writer *w, const struct output_item *item)
{
if (is_group_open_item (item))
- spv_writer_open_heading (w,
- to_group_open_item (item)->command_name,
- to_group_open_item (item)->command_name);
+ spv_writer_open_heading (w, item);
else if (is_group_close_item (item))
spv_writer_close_heading (w);
else if (is_table_item (item))
else if (is_group_close_item (item))
spv_writer_close_heading (w);
else if (is_table_item (item))
else if (is_image_item (item))
spv_writer_put_image (w, item, to_image_item (item)->image);
else if (is_text_item (item))
else if (is_image_item (item))
spv_writer_put_image (w, item, to_image_item (item)->image);
else if (is_text_item (item))
- spv_writer_put_text (w, to_text_item (item),
- output_get_command_name ());
+ spv_writer_put_text (w, to_text_item (item));
else if (is_page_break_item (item))
w->need_page_break = true;
else if (is_page_setup_item (item))
else if (is_page_break_item (item))
w->need_page_break = true;
else if (is_page_setup_item (item))
struct table_item *item = xmalloc (sizeof *item);
*item = (struct table_item) {
.output_item = OUTPUT_ITEM_INITIALIZER (&table_item_class),
struct table_item *item = xmalloc (sizeof *item);
*item = (struct table_item) {
.output_item = OUTPUT_ITEM_INITIALIZER (&table_item_class),
+ .output_item.command_name = xstrdup_if_nonnull (pt->command_c),
.pt = pt,
};
return item;
.pt = pt,
};
return item;
struct text_item *item = xzalloc (sizeof *item);
*item = (struct text_item) {
.output_item = OUTPUT_ITEM_INITIALIZER (&text_item_class),
struct text_item *item = xzalloc (sizeof *item);
*item = (struct text_item) {
.output_item = OUTPUT_ITEM_INITIALIZER (&text_item_class),
+ .output_item.command_name = xstrdup_if_nonnull (output_get_command_name ()),
.output_item.label = label,
.type = type,
.text = value,
.output_item.label = label,
.type = type,
.text = value,