From f84a189d5f94250e46d2cbd1a75aba00130e2dd6 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 21 Jan 2015 16:42:45 +0100 Subject: Add ctx parameter and remove embedded contexts for API regularity. Purge several embedded contexts: Remove embedded context in fz_output. Remove embedded context in fz_stream. Remove embedded context in fz_device. Remove fz_rebind_stream (since it is no longer necessary). Remove embedded context in svg_device. Remove embedded context in XML parser. Add ctx argument to fz_document functions. Remove embedded context in fz_document. Remove embedded context in pdf_document. Remove embedded context in pdf_obj. Make fz_page independent of fz_document in the interface. We shouldn't need to pass the document to all functions handling a page. If a page is tied to the source document, it's redundant; otherwise it's just pointless. Fix reference counting oddity in fz_new_image_from_pixmap. --- source/fitz/stext-output.c | 172 ++++++++++++++++++++++----------------------- 1 file changed, 86 insertions(+), 86 deletions(-) (limited to 'source/fitz/stext-output.c') diff --git a/source/fitz/stext-output.c b/source/fitz/stext-output.c index 6ed595fc..f090020d 100644 --- a/source/fitz/stext-output.c +++ b/source/fitz/stext-output.c @@ -29,39 +29,39 @@ static int font_is_italic(fz_font *font) } static void -fz_print_style_begin(fz_output *out, fz_text_style *style) +fz_print_style_begin(fz_context *ctx, fz_output *out, fz_text_style *style) { int script = style->script; - fz_printf(out, "", style->id); + fz_printf(ctx, out, "", style->id); while (script-- > 0) - fz_printf(out, ""); + fz_printf(ctx, out, ""); while (++script < 0) - fz_printf(out, ""); + fz_printf(ctx, out, ""); } static void -fz_print_style_end(fz_output *out, fz_text_style *style) +fz_print_style_end(fz_context *ctx, fz_output *out, fz_text_style *style) { int script = style->script; while (script-- > 0) - fz_printf(out, ""); + fz_printf(ctx, out, ""); while (++script < 0) - fz_printf(out, ""); - fz_printf(out, ""); + fz_printf(ctx, out, ""); + fz_printf(ctx, out, ""); } static void -fz_print_style(fz_output *out, fz_text_style *style) +fz_print_style(fz_context *ctx, fz_output *out, fz_text_style *style) { char *s = strchr(style->font->name, '+'); s = s ? s + 1 : style->font->name; - fz_printf(out, "span.s%d{font-family:\"%s\";font-size:%gpt;", + fz_printf(ctx, out, "span.s%d{font-family:\"%s\";font-size:%gpt;", style->id, s, style->size); if (font_is_italic(style->font)) - fz_printf(out, "font-style:italic;"); + fz_printf(ctx, out, "font-style:italic;"); if (font_is_bold(style->font)) - fz_printf(out, "font-weight:bold;"); - fz_printf(out, "}\n"); + fz_printf(ctx, out, "font-weight:bold;"); + fz_printf(ctx, out, "}\n"); } void @@ -69,11 +69,11 @@ fz_print_text_sheet(fz_context *ctx, fz_output *out, fz_text_sheet *sheet) { fz_text_style *style; for (style = sheet->style; style; style = style->next) - fz_print_style(out, style); + fz_print_style(ctx, out, style); } static void -send_data_base64(fz_output *out, fz_buffer *buffer) +send_data_base64(fz_context *ctx, fz_output *out, fz_buffer *buffer) { int i, len; static const char set[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -85,8 +85,8 @@ send_data_base64(fz_output *out, fz_buffer *buffer) int d = buffer->data[3*i+1]; int e = buffer->data[3*i+2]; if ((i & 15) == 0) - fz_printf(out, "\n"); - fz_printf(out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); + fz_printf(ctx, out, "\n"); + fz_printf(ctx, out, "%c%c%c%c", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)|(e>>6)], set[e & 63]); } i *= 3; switch (buffer->len-i) @@ -95,13 +95,13 @@ send_data_base64(fz_output *out, fz_buffer *buffer) { int c = buffer->data[i]; int d = buffer->data[i+1]; - fz_printf(out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); + fz_printf(ctx, out, "%c%c%c=", set[c>>2], set[((c&3)<<4)|(d>>4)], set[((d&15)<<2)]); break; } case 1: { int c = buffer->data[i]; - fz_printf(out, "%c%c==", set[c>>2], set[(c&3)<<4]); + fz_printf(ctx, out, "%c%c==", set[c>>2], set[(c&3)<<4]); break; } default: @@ -119,7 +119,7 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) fz_text_span *span; void *last_region = NULL; - fz_printf(out, "
\n"); + fz_printf(ctx, out, "
\n"); for (block_n = 0; block_n < page->len; block_n++) { @@ -128,7 +128,7 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) case FZ_PAGE_BLOCK_TEXT: { fz_text_block * block = page->blocks[block_n].u.text; - fz_printf(out, "

\n"); + fz_printf(ctx, out, "

\n"); for (line_n = 0; line_n < block->len; line_n++) { int lastcol=-1; @@ -138,16 +138,16 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) if (line->region != last_region) { if (last_region) - fz_printf(out, "

"); - fz_printf(out, "
"); + fz_printf(ctx, out, "
"); + fz_printf(ctx, out, "
"); last_region = line->region; } - fz_printf(out, "
region) - fz_printf(out, " region=\"%x\"", line->region); + fz_printf(ctx, out, " region=\"%x\"", line->region); #endif - fz_printf(out, ">"); + fz_printf(ctx, out, ">"); for (span = line->first_span; span; span = span->next) { float size = fz_matrix_expansion(&span->transform); @@ -157,17 +157,17 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) { if (lastcol >= 0) { - fz_printf(out, "
"); + fz_printf(ctx, out, "
"); } /* If we skipped any columns then output some spacer spans */ while (lastcol < span->column-1) { - fz_printf(out, "
"); + fz_printf(ctx, out, "
"); lastcol++; } lastcol++; /* Now output the span to contain this entire column */ - fz_printf(out, "
next; sn; sn = sn->next) @@ -175,103 +175,103 @@ fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) if (sn->column != lastcol) break; } - fz_printf(out, "width:%g%%;align:%s", span->column_width, (span->align == 0 ? "left" : (span->align == 1 ? "center" : "right"))); + fz_printf(ctx, out, "width:%g%%;align:%s", span->column_width, (span->align == 0 ? "left" : (span->align == 1 ? "center" : "right"))); } if (span->indent > 1) - fz_printf(out, ";padding-left:1em;text-indent:-1em"); + fz_printf(ctx, out, ";padding-left:1em;text-indent:-1em"); if (span->indent < -1) - fz_printf(out, ";text-indent:1em"); - fz_printf(out, "\">"); + fz_printf(ctx, out, ";text-indent:1em"); + fz_printf(ctx, out, "\">"); } #ifdef DEBUG_INTERNALS - fz_printf(out, "column) - fz_printf(out, " col=\"%x\"", span->column); - fz_printf(out, ">"); + fz_printf(ctx, out, " col=\"%x\"", span->column); + fz_printf(ctx, out, ">"); #endif if (span->spacing >= 1) - fz_printf(out, " "); + fz_printf(ctx, out, " "); if (base_offset > SUBSCRIPT_OFFSET) - fz_printf(out, ""); + fz_printf(ctx, out, ""); else if (base_offset < SUPERSCRIPT_OFFSET) - fz_printf(out, ""); + fz_printf(ctx, out, ""); for (ch_n = 0; ch_n < span->len; ch_n++) { fz_text_char *ch = &span->text[ch_n]; if (style != ch->style) { if (style) - fz_print_style_end(out, style); - fz_print_style_begin(out, ch->style); + fz_print_style_end(ctx, out, style); + fz_print_style_begin(ctx, out, ch->style); style = ch->style; } if (ch->c == '<') - fz_printf(out, "<"); + fz_printf(ctx, out, "<"); else if (ch->c == '>') - fz_printf(out, ">"); + fz_printf(ctx, out, ">"); else if (ch->c == '&') - fz_printf(out, "&"); + fz_printf(ctx, out, "&"); else if (ch->c >= 32 && ch->c <= 127) - fz_printf(out, "%c", ch->c); + fz_printf(ctx, out, "%c", ch->c); else - fz_printf(out, "&#x%x;", ch->c); + fz_printf(ctx, out, "&#x%x;", ch->c); } if (style) { - fz_print_style_end(out, style); + fz_print_style_end(ctx, out, style); style = NULL; } if (base_offset > SUBSCRIPT_OFFSET) - fz_printf(out, ""); + fz_printf(ctx, out, ""); else if (base_offset < SUPERSCRIPT_OFFSET) - fz_printf(out, ""); + fz_printf(ctx, out, ""); #ifdef DEBUG_INTERNALS - fz_printf(out, ""); + fz_printf(ctx, out, ""); #endif } /* Close our floating span */ - fz_printf(out, "
"); + fz_printf(ctx, out, "
"); /* Close the line */ - fz_printf(out, "
"); - fz_printf(out, "\n"); + fz_printf(ctx, out, "
"); + fz_printf(ctx, out, "\n"); } /* Close the metaline */ - fz_printf(out, ""); + fz_printf(ctx, out, ""); last_region = NULL; - fz_printf(out, "

\n"); + fz_printf(ctx, out, "

\n"); break; } case FZ_PAGE_BLOCK_IMAGE: { fz_image_block *image = page->blocks[block_n].u.image; - fz_printf(out, "image->w, image->image->h); + fz_printf(ctx, out, "image->w, image->image->h); switch (image->image->buffer == NULL ? FZ_IMAGE_JPX : image->image->buffer->params.type) { case FZ_IMAGE_JPEG: - fz_printf(out, "image/jpeg;base64,"); - send_data_base64(out, image->image->buffer->buffer); + fz_printf(ctx, out, "image/jpeg;base64,"); + send_data_base64(ctx, out, image->image->buffer->buffer); break; case FZ_IMAGE_PNG: - fz_printf(out, "image/png;base64,"); - send_data_base64(out, image->image->buffer->buffer); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, image->image->buffer->buffer); break; default: { fz_buffer *buf = fz_new_png_from_image(ctx, image->image, image->image->w, image->image->h); - fz_printf(out, "image/png;base64,"); - send_data_base64(out, buf); + fz_printf(ctx, out, "image/png;base64,"); + send_data_base64(ctx, out, buf); fz_drop_buffer(ctx, buf); break; } } - fz_printf(out, "\">\n"); + fz_printf(ctx, out, "\">\n"); break; } } } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } void @@ -279,7 +279,7 @@ fz_print_text_page_xml(fz_context *ctx, fz_output *out, fz_text_page *page) { int block_n; - fz_printf(out, "\n", + fz_printf(ctx, out, "\n", page->mediabox.x1 - page->mediabox.x0, page->mediabox.y1 - page->mediabox.y0); @@ -293,12 +293,12 @@ fz_print_text_page_xml(fz_context *ctx, fz_output *out, fz_text_page *page) fz_text_line *line; char *s; - fz_printf(out, "\n", + fz_printf(ctx, out, "\n", block->bbox.x0, block->bbox.y0, block->bbox.x1, block->bbox.y1); for (line = block->lines; line < block->lines + block->len; line++) { fz_text_span *span; - fz_printf(out, "\n", + fz_printf(ctx, out, "\n", line->bbox.x0, line->bbox.y0, line->bbox.x1, line->bbox.y1); for (span = line->first_span; span; span = span->next) { @@ -311,43 +311,43 @@ fz_print_text_page_xml(fz_context *ctx, fz_output *out, fz_text_page *page) { if (style) { - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } style = ch->style; s = strchr(style->font->name, '+'); s = s ? s + 1 : style->font->name; - fz_printf(out, "\n", + fz_printf(ctx, out, "\n", span->bbox.x0, span->bbox.y0, span->bbox.x1, span->bbox.y1, s, style->size); } { fz_rect rect; - fz_text_char_bbox(&rect, span, char_num); - fz_printf(out, "p.x, ch->p.y); } switch (ch->c) { - case '<': fz_printf(out, "<"); break; - case '>': fz_printf(out, ">"); break; - case '&': fz_printf(out, "&"); break; - case '"': fz_printf(out, """); break; - case '\'': fz_printf(out, "'"); break; + case '<': fz_printf(ctx, out, "<"); break; + case '>': fz_printf(ctx, out, ">"); break; + case '&': fz_printf(ctx, out, "&"); break; + case '"': fz_printf(ctx, out, """); break; + case '\'': fz_printf(ctx, out, "'"); break; default: if (ch->c >= 32 && ch->c <= 127) - fz_printf(out, "%c", ch->c); + fz_printf(ctx, out, "%c", ch->c); else - fz_printf(out, "&#x%x;", ch->c); + fz_printf(ctx, out, "&#x%x;", ch->c); break; } - fz_printf(out, "\"/>\n"); + fz_printf(ctx, out, "\"/>\n"); } if (style) - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); break; } case FZ_PAGE_BLOCK_IMAGE: @@ -356,7 +356,7 @@ fz_print_text_page_xml(fz_context *ctx, fz_output *out, fz_text_page *page) } } } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } void @@ -385,12 +385,12 @@ fz_print_text_page(fz_context *ctx, fz_output *out, fz_text_page *page) { n = fz_runetochar(utf, ch->c); for (i = 0; i < n; i++) - fz_printf(out, "%c", utf[i]); + fz_printf(ctx, out, "%c", utf[i]); } } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); break; } case FZ_PAGE_BLOCK_IMAGE: -- cgit v1.2.3