static void svg_dev_fill_image(fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) { svg_device *sdev = (svg_device *)dev->user; fz_context *ctx = dev->ctx; fz_output *out = sdev->out; fz_matrix local_ctm = *ctm; fz_matrix scale = { 1.0f/image->w, 0, 0, 1.0f/image->h, 0, 0}; fz_concat(&local_ctm, &scale, ctm); fz_printf(out, "<image"); svg_dev_ctm(sdev, &local_ctm); fz_printf(out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); switch (image->buffer == NULL ? FZ_IMAGE_JPX : image->buffer->params.type) { case FZ_IMAGE_JPEG: fz_printf(out, "image/jpeg;base64,"); send_data_base64(out, image->buffer->buffer); break; case FZ_IMAGE_PNG: fz_printf(out, "image/png;base64,"); send_data_base64(out, image->buffer->buffer); break; default: { fz_buffer *buf = fz_image_as_png(ctx, image, image->w, image->h); fz_printf(out, "image/png;base64,"); send_data_base64(out, buf); fz_drop_buffer(ctx, buf); break; } } fz_printf(out, "\"/>\n"); }
static void svg_dev_fill_image_mask(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, fz_colorspace *colorspace, const float *color, float alpha) { svg_device *sdev = (svg_device*)dev; fz_compressed_buffer *buffer; fz_output *out; fz_matrix local_ctm = *ctm; fz_matrix scale = { 0 }; int mask = sdev->id++; scale.a = 1.0f / image->w; scale.d = 1.0f / image->h; fz_concat(&local_ctm, &scale, ctm); out = start_def(ctx, sdev); fz_printf(ctx, out, "<mask id=\"ma%d\"><image", mask); fz_printf(ctx, out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); buffer = fz_compressed_image_buffer(ctx, image); switch (buffer == NULL ? FZ_IMAGE_JPX : buffer->params.type) { case FZ_IMAGE_JPEG: fz_printf(ctx, out, "image/jpeg;base64,"); send_data_base64(ctx, out, buffer->buffer); break; case FZ_IMAGE_PNG: fz_printf(ctx, out, "image/png;base64,"); send_data_base64(ctx, out, buffer->buffer); break; default: { fz_buffer *buf = fz_new_buffer_from_image_as_png(ctx, image); fz_printf(ctx, out, "image/png;base64,"); send_data_base64(ctx, out, buf); fz_drop_buffer(ctx, buf); break; } } fz_printf(ctx, out, "\"/></mask>\n"); out = end_def(ctx, sdev); fz_printf(ctx, out, "<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\"", image->w, image->h); svg_dev_fill_color(ctx, sdev, colorspace, color, alpha); svg_dev_ctm(ctx, sdev, &local_ctm); fz_printf(ctx, out, " mask=\"url(#ma%d)\"/>\n", mask); }
static void svg_dev_fill_image(fz_context *ctx, fz_device *dev, fz_image *image, const fz_matrix *ctm, float alpha) { svg_device *sdev = (svg_device*)dev; fz_output *out = sdev->out; fz_compressed_buffer *buffer; fz_matrix local_ctm = *ctm; fz_matrix scale = { 0 }; scale.a = 1.0f / image->w; scale.d = 1.0f / image->h; fz_concat(&local_ctm, &scale, ctm); if (alpha != 1.0f) fz_printf(ctx, out, "<g opacity=\"%g\">", alpha); fz_printf(ctx, out, "<image"); svg_dev_ctm(ctx, sdev, &local_ctm); buffer = fz_compressed_image_buffer(ctx, image); fz_printf(ctx, out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); switch (buffer == NULL ? FZ_IMAGE_JPX : buffer->params.type) { case FZ_IMAGE_JPEG: fz_printf(ctx, out, "image/jpeg;base64,"); send_data_base64(ctx, out, buffer->buffer); break; case FZ_IMAGE_PNG: fz_printf(ctx, out, "image/png;base64,"); send_data_base64(ctx, out, buffer->buffer); break; default: { fz_buffer *buf = fz_new_buffer_from_image_as_png(ctx, image); fz_printf(ctx, out, "image/png;base64,"); send_data_base64(ctx, out, buf); fz_drop_buffer(ctx, buf); break; } } fz_printf(ctx, out, "\"/>\n"); if (alpha != 1.0f) fz_printf(ctx, out, "</g>"); }
static void svg_dev_clip_image_mask(fz_device *dev, fz_image *image, const fz_rect *rect, const fz_matrix *ctm) { svg_device *sdev = (svg_device *)dev->user; fz_context *ctx = dev->ctx; fz_output *out; fz_matrix local_ctm = *ctm; fz_matrix scale = { 0 }; int mask = sdev->id++; scale.a = 1.0f / image->w; scale.d = 1.0f / image->h; fz_concat(&local_ctm, &scale, ctm); out = start_def(sdev); fz_printf(out, "<mask id=\"ma%d\"><image", mask); svg_dev_ctm(sdev, &local_ctm); fz_printf(out, " width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:", image->w, image->h); switch (image->buffer == NULL ? FZ_IMAGE_JPX : image->buffer->params.type) { case FZ_IMAGE_JPEG: fz_printf(out, "image/jpeg;base64,"); send_data_base64(out, image->buffer->buffer); break; case FZ_IMAGE_PNG: fz_printf(out, "image/png;base64,"); send_data_base64(out, image->buffer->buffer); break; default: { fz_buffer *buf = fz_new_png_from_image(ctx, image, image->w, image->h); fz_printf(out, "image/png;base64,"); send_data_base64(out, buf); fz_drop_buffer(ctx, buf); break; } } fz_printf(out, "\"/></mask>\n"); out = end_def(sdev); fz_printf(out, "<g mask=\"url(#ma%d)\">\n", mask); }
static void svg_dev_fill_shade(fz_context *ctx, fz_device *dev, fz_shade *shade, const fz_matrix *ctm, float alpha) { svg_device *sdev = (svg_device*)dev; fz_output *out = sdev->out; fz_rect rect; fz_irect bbox; fz_pixmap *pix; fz_buffer *buf = NULL; fz_var(buf); if (dev->container_len == 0) return; fz_round_rect(&bbox, fz_intersect_rect(fz_bound_shade(ctx, shade, ctm, &rect), &dev->container[dev->container_len-1].scissor)); if (fz_is_empty_irect(&bbox)) return; pix = fz_new_pixmap_with_bbox(ctx, fz_device_rgb(ctx), &bbox); fz_clear_pixmap(ctx, pix); fz_try(ctx) { fz_paint_shade(ctx, shade, ctm, pix, &bbox); buf = fz_new_buffer_from_pixmap_as_png(ctx, pix); if (alpha != 1.0f) fz_printf(ctx, out, "<g opacity=\"%g\">", alpha); fz_printf(ctx, out, "<image x=\"%dpx\" y=\"%dpx\" width=\"%dpx\" height=\"%dpx\" xlink:href=\"data:image/png;base64,", pix->x, pix->y, pix->w, pix->h); send_data_base64(ctx, out, buf); fz_printf(ctx, out, "\"/>\n"); if (alpha != 1.0f) fz_printf(ctx, out, "</g>"); } fz_always(ctx) { fz_drop_buffer(ctx, buf); fz_drop_pixmap(ctx, pix); } fz_catch(ctx) { fz_rethrow(ctx); } }
void fz_print_text_page_html(fz_context *ctx, fz_output *out, fz_text_page *page) { int block_n, line_n, ch_n; fz_text_style *style = NULL; fz_text_line *line; fz_text_span *span; void *last_region = NULL; fz_printf(out, "<div class=\"page\">\n"); for (block_n = 0; block_n < page->len; block_n++) { switch (page->blocks[block_n].type) { case FZ_PAGE_BLOCK_TEXT: { fz_text_block * block = page->blocks[block_n].u.text; fz_printf(out, "<div class=\"block\"><p>\n"); for (line_n = 0; line_n < block->len; line_n++) { int lastcol=-1; line = &block->lines[line_n]; style = NULL; if (line->region != last_region) { if (last_region) fz_printf(out, "</div>"); fz_printf(out, "<div class=\"metaline\">"); last_region = line->region; } fz_printf(out, "<div class=\"line\""); #ifdef DEBUG_INTERNALS if (line->region) fz_printf(out, " region=\"%x\"", line->region); #endif fz_printf(out, ">"); for (span = line->first_span; span; span = span->next) { float size = fz_matrix_expansion(&span->transform); float base_offset = span->base_offset / size; if (lastcol != span->column) { if (lastcol >= 0) { fz_printf(out, "</div>"); } /* If we skipped any columns then output some spacer spans */ while (lastcol < span->column-1) { fz_printf(out, "<div class=\"cell\"></div>"); lastcol++; } lastcol++; /* Now output the span to contain this entire column */ fz_printf(out, "<div class=\"cell\" style=\""); { fz_text_span *sn; for (sn = span->next; sn; sn = sn->next) { if (sn->column != lastcol) break; } fz_printf(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"); if (span->indent < -1) fz_printf(out, ";text-indent:1em"); fz_printf(out, "\">"); } #ifdef DEBUG_INTERNALS fz_printf(out, "<span class=\"internal_span\""); if (span->column) fz_printf(out, " col=\"%x\"", span->column); fz_printf(out, ">"); #endif if (span->spacing >= 1) fz_printf(out, " "); if (base_offset > SUBSCRIPT_OFFSET) fz_printf(out, "<sub>"); else if (base_offset < SUPERSCRIPT_OFFSET) fz_printf(out, "<sup>"); 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); style = ch->style; } if (ch->c == '<') fz_printf(out, "<"); else if (ch->c == '>') fz_printf(out, ">"); else if (ch->c == '&') fz_printf(out, "&"); else if (ch->c >= 32 && ch->c <= 127) fz_printf(out, "%c", ch->c); else fz_printf(out, "&#x%x;", ch->c); } if (style) { fz_print_style_end(out, style); style = NULL; } if (base_offset > SUBSCRIPT_OFFSET) fz_printf(out, "</sub>"); else if (base_offset < SUPERSCRIPT_OFFSET) fz_printf(out, "</sup>"); #ifdef DEBUG_INTERNALS fz_printf(out, "</span>"); #endif } /* Close our floating span */ fz_printf(out, "</div>"); /* Close the line */ fz_printf(out, "</div>"); fz_printf(out, "\n"); } /* Close the metaline */ fz_printf(out, "</div>"); last_region = NULL; fz_printf(out, "</p></div>\n"); break; } case FZ_PAGE_BLOCK_IMAGE: { fz_image_block *image = page->blocks[block_n].u.image; fz_printf(out, "<img width=%d height=%d src=\"data:", image->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); break; case FZ_IMAGE_PNG: fz_printf(out, "image/png;base64,"); send_data_base64(out, image->image->buffer->buffer); break; default: { fz_buffer *buf = fz_image_as_png(ctx, image->image, image->image->w, image->image->h); fz_printf(out, "image/png;base64,"); send_data_base64(out, buf); fz_drop_buffer(ctx, buf); break; } } fz_printf(out, "\">\n"); break; } } } fz_printf(out, "</div>\n"); }