/** * This function draws one page, beginning with the height offset of done_height * * \param printer The printer interface for the printer to be used * \param settings The settings for printing to use * \return true if successful, false otherwise */ bool print_draw_next_page(const struct printer *printer, struct print_settings *settings) { struct rect clip; struct content_redraw_data data; struct redraw_context ctx = { .interactive = false, .background_images = !nsoption_bool(remove_backgrounds), .plot = printer->plotter }; html_redraw_printing_top_cropped = INT_MAX; clip.x0 = 0; clip.y0 = 0; clip.x1 = page_content_width * settings->scale; clip.y1 = page_content_height * settings->scale; data.x = 0; data.y = -done_height; data.width = 0; data.height = 0; data.background_colour = 0xFFFFFF; data.scale = settings->scale; data.repeat_x = false; data.repeat_y = false; html_redraw_printing = true; html_redraw_printing_border = clip.y1; printer->print_next_page(); if (!content_redraw(printed_content, &data, &clip, &ctx)) return false; done_height += page_content_height - (html_redraw_printing_top_cropped != INT_MAX ? clip.y1 - html_redraw_printing_top_cropped : 0) / settings->scale; return true; } /** * The content passed to the function is duplicated with its boxes, font * measuring functions are being set. * * \param content The content to be printed * \param settings The settings for printing to use * \return true if successful, false otherwise */ hlcache_handle *print_init(hlcache_handle *content, struct print_settings *settings) { hlcache_handle* printed_content; hlcache_handle_clone(content, &printed_content); return printed_content; }
bool save_as_draw(hlcache_handle *h, const char *path) { pencil_code code; char *drawfile_buffer; size_t drawfile_size; os_error *error; ro_save_draw_diagram = pencil_create(); if (!ro_save_draw_diagram) { warn_user("NoMemory", 0); return false; } ro_save_draw_width = content_get_width(h); ro_save_draw_height = content_get_height(h); plot = ro_save_draw_plotters; if (!content_redraw(h, 0, -ro_save_draw_height, ro_save_draw_width, ro_save_draw_height, INT_MIN, INT_MIN, INT_MAX, INT_MAX, 1, 0xFFFFFF)) { pencil_free(ro_save_draw_diagram); return false; } /*pencil_dump(ro_save_draw_diagram);*/ code = pencil_save_drawfile(ro_save_draw_diagram, "NetSurf", &drawfile_buffer, &drawfile_size); if (code != pencil_OK) { warn_user("SaveError", 0); pencil_free(ro_save_draw_diagram); return false; } assert(drawfile_buffer); error = xosfile_save_stamped(path, osfile_TYPE_DRAW, (byte *) drawfile_buffer, (byte *) drawfile_buffer + drawfile_size); if (error) { LOG(("xosfile_save_stamped failed: 0x%x: %s", error->errnum, error->errmess)); warn_user("SaveError", error->errmess); pencil_free(ro_save_draw_diagram); return false; } pencil_free(ro_save_draw_diagram); return true; }
/* exported interface, documented in thumbnail.h */ bool thumbnail_redraw(struct hlcache_handle *content, int width, int height, const struct redraw_context *ctx) { struct redraw_context new_ctx = *ctx; struct rect clip; struct content_redraw_data data; float scale; bool plot_ok = true; assert(content); if (ctx->plot->option_knockout) knockout_plot_start(ctx, &new_ctx); /* Set clip rectangle to required thumbnail size */ clip.x0 = 0; clip.y0 = 0; clip.x1 = width; clip.y1 = height; new_ctx.plot->clip(&clip); /* Plot white background */ plot_ok &= new_ctx.plot->rectangle(clip.x0, clip.y0, clip.x1, clip.y1, plot_style_fill_white); /* Find the scale we're using */ scale = thumbnail_get_redraw_scale(content, width); /* Set up content redraw data */ data.x = 0; data.y = 0; data.width = width; data.height = height; data.background_colour = 0xFFFFFF; data.scale = scale; data.repeat_x = false; data.repeat_y = false; /* Render the content */ plot_ok &= content_redraw(content, &data, &clip, &new_ctx); if (ctx->plot->option_knockout) knockout_plot_end(); return plot_ok; }
void ro_gui_url_bar_redraw(struct url_bar *url_bar, wimp_draw *redraw) { wimp_icon icon; struct rect clip; /* Test for a valid URL bar, and then check that the redraw box * coincides with the bar's favicon extent. */ if (url_bar == NULL || url_bar->hidden || (redraw->clip.x0 - (redraw->box.x0 - redraw->xscroll)) > (url_bar->favicon_extent.x1) || (redraw->clip.y0 - (redraw->box.y1 - redraw->yscroll)) > url_bar->favicon_extent.y1 || (redraw->clip.x1 - (redraw->box.x0 - redraw->xscroll)) < url_bar->favicon_extent.x0 || (redraw->clip.y1 - (redraw->box.y1 - redraw->yscroll)) < url_bar->favicon_extent.y0) return; if (url_bar->favicon_content == NULL) { icon.data.indirected_text.text = null_text_string; icon.data.indirected_text.validation = url_bar->favicon_sprite; icon.data.indirected_text.size = 1; icon.flags = wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_INDIRECTED | wimp_ICON_FILLED | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED; icon.extent.x0 = url_bar->favicon_extent.x0; icon.extent.x1 = url_bar->favicon_extent.x1; icon.extent.y0 = url_bar->favicon_extent.y0; icon.extent.y1 = url_bar->favicon_extent.y1; xwimp_plot_icon(&icon); } else { struct content_redraw_data data; struct redraw_context ctx = { .interactive = true, .background_images = true, .plot = &ro_plotters }; xwimp_set_colour(wimp_COLOUR_WHITE); xos_plot(os_MOVE_TO, (redraw->box.x0 - redraw->xscroll) + url_bar->favicon_extent.x0, (redraw->box.y1 - redraw->yscroll) + url_bar->favicon_extent.y0); xos_plot(os_PLOT_TO | os_PLOT_RECTANGLE, (redraw->box.x0 - redraw->xscroll) + url_bar->favicon_extent.x1, (redraw->box.y1 - redraw->yscroll) + url_bar->favicon_extent.y1); clip.x0 = (redraw->clip.x0 - ro_plot_origin_x) / 2; clip.y0 = (ro_plot_origin_y - redraw->clip.y0) / 2; clip.x1 = (redraw->clip.x1 - ro_plot_origin_x) / 2; clip.y1 = (ro_plot_origin_y - redraw->clip.y1) / 2; data.x = (url_bar->favicon_extent.x0 + url_bar->favicon_offset.x) / 2; data.y = (url_bar->favicon_offset.y - url_bar->favicon_extent.y1) / 2; data.width = url_bar->favicon_width; data.height = url_bar->favicon_height; data.background_colour = 0xFFFFFF; data.scale = 1; data.repeat_x = false; data.repeat_y = false; content_redraw(url_bar->favicon_content, &data, &clip, &ctx); } } /* This is an exported interface documented in url_bar.h */ bool ro_gui_url_bar_click(struct url_bar *url_bar, wimp_pointer *pointer, wimp_window_state *state, url_bar_action *action) { os_coord pos; if (url_bar == NULL || url_bar->hidden || url_bar->display || url_bar->shaded) return false; /* Check that the click was within our part of the window. */ pos.x = pointer->pos.x - state->visible.x0 + state->xscroll; pos.y = pointer->pos.y - state->visible.y1 + state->yscroll; if (pos.x < url_bar->extent.x0 || pos.x > url_bar->extent.x1 || pos.y < url_bar->extent.y0 || pos.y > url_bar->extent.y1) return false; /* If we find a Select or Adjust drag, check if it originated on the * URL bar or over the favicon. If either, then return an event. */ if (pointer->buttons == wimp_DRAG_SELECT || pointer->buttons == wimp_DRAG_ADJUST) { if (pointer->i == url_bar->text_icon) { if (action != NULL) *action = TOOLBAR_URL_DRAG_URL; return true; } if (pos.x >= url_bar->favicon_extent.x0 && pos.x <= url_bar->favicon_extent.x1 && pos.y >= url_bar->favicon_extent.y0 && pos.y <=url_bar->favicon_extent.y1) { if (action != NULL) *action = TOOLBAR_URL_DRAG_FAVICON; return true; } } return false; }
bool save_as_draw(hlcache_handle *h, const char *path) { pencil_code code; char *drawfile_buffer; struct rect clip; struct content_redraw_data data; size_t drawfile_size; os_error *error; struct redraw_context ctx = { .interactive = false, .background_images = true, .plot = &ro_save_draw_plotters }; ro_save_draw_diagram = pencil_create(); if (!ro_save_draw_diagram) { warn_user("NoMemory", 0); return false; } ro_save_draw_width = content_get_width(h); ro_save_draw_height = content_get_height(h); clip.x0 = clip.y0 = INT_MIN; clip.x1 = clip.y1 = INT_MAX; data.x = 0; data.y = -ro_save_draw_height; data.width = ro_save_draw_width; data.height = ro_save_draw_height; data.background_colour = 0xFFFFFF; data.scale = 1; data.repeat_x = false; data.repeat_y = false; if (!content_redraw(h, &data, &clip, &ctx)) { pencil_free(ro_save_draw_diagram); return false; } /*pencil_dump(ro_save_draw_diagram);*/ code = pencil_save_drawfile(ro_save_draw_diagram, "NetSurf", &drawfile_buffer, &drawfile_size); if (code != pencil_OK) { warn_user("SaveError", 0); pencil_free(ro_save_draw_diagram); return false; } assert(drawfile_buffer); error = xosfile_save_stamped(path, osfile_TYPE_DRAW, (byte *) drawfile_buffer, (byte *) drawfile_buffer + drawfile_size); if (error) { LOG("xosfile_save_stamped failed: 0x%x: %s", error->errnum, error->errmess); warn_user("SaveError", error->errmess); pencil_free(ro_save_draw_diagram); return false; } pencil_free(ro_save_draw_diagram); return true; } bool ro_save_draw_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) { pencil_code code; const int path[] = { draw_MOVE_TO, x0 * 2, -y0 * 2 - 1, draw_LINE_TO, x1 * 2, -y0 * 2 - 1, draw_LINE_TO, x1 * 2, -y1 * 2 - 1, draw_LINE_TO, x0 * 2, -y1 * 2 - 1, draw_CLOSE_LINE, draw_END_PATH }; if (style->fill_type != PLOT_OP_TYPE_NONE) { code = pencil_path(ro_save_draw_diagram, path, sizeof path / sizeof path[0], style->fill_colour << 8, pencil_TRANSPARENT, 0, pencil_JOIN_MITRED, pencil_CAP_BUTT, pencil_CAP_BUTT, 0, 0, false, pencil_SOLID); if (code != pencil_OK) return ro_save_draw_error(code); } if (style->stroke_type != PLOT_OP_TYPE_NONE) { code = pencil_path(ro_save_draw_diagram, path, sizeof path / sizeof path[0], pencil_TRANSPARENT, style->stroke_colour << 8, style->stroke_width, pencil_JOIN_MITRED, pencil_CAP_BUTT, pencil_CAP_BUTT, 0, 0, false, pencil_SOLID); if (code != pencil_OK) return ro_save_draw_error(code); } return true; }