2004-08-09 10:28:57 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
|
2006-03-05 15:24:18 +03:00
|
|
|
* Copyright 2006 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-08-09 10:28:57 +04:00
|
|
|
*/
|
|
|
|
|
2008-07-27 03:42:24 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2014-06-05 18:14:49 +04:00
|
|
|
#include <swis.h>
|
|
|
|
#include <oslib/font.h>
|
|
|
|
#include <oslib/hourglass.h>
|
|
|
|
#include <oslib/osfile.h>
|
|
|
|
#include <oslib/osfind.h>
|
|
|
|
#include <oslib/pdriver.h>
|
|
|
|
#include <oslib/wimp.h>
|
|
|
|
#include <rufl.h>
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2014-06-05 18:14:49 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/nsoption.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/content.h"
|
2010-04-07 20:08:24 +04:00
|
|
|
#include "content/hlcache.h"
|
2014-08-22 19:35:39 +04:00
|
|
|
#include "desktop/browser.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/plotters.h"
|
2014-06-05 18:14:49 +04:00
|
|
|
|
2014-06-06 02:01:37 +04:00
|
|
|
#include "riscos/gui.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/dialog.h"
|
|
|
|
#include "riscos/menus.h"
|
|
|
|
#include "riscos/print.h"
|
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
2014-06-04 19:44:29 +04:00
|
|
|
#include "riscos/filetype.h"
|
2014-06-05 18:14:49 +04:00
|
|
|
#include "riscos/font.h"
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2006-01-02 03:37:10 +03:00
|
|
|
|
|
|
|
#define ICON_PRINT_TO_BOTTOM 1
|
|
|
|
#define ICON_PRINT_SHEETS 2
|
|
|
|
#define ICON_PRINT_SHEETS_VALUE 3
|
|
|
|
#define ICON_PRINT_SHEETS_DOWN 4
|
|
|
|
#define ICON_PRINT_SHEETS_UP 5
|
|
|
|
#define ICON_PRINT_SHEETS_TEXT 6
|
|
|
|
#define ICON_PRINT_FG_IMAGES 7
|
|
|
|
#define ICON_PRINT_BG_IMAGES 8
|
|
|
|
#define ICON_PRINT_IN_BACKGROUND 9
|
|
|
|
#define ICON_PRINT_UPRIGHT 10
|
|
|
|
#define ICON_PRINT_SIDEWAYS 11
|
|
|
|
#define ICON_PRINT_COPIES 12
|
|
|
|
#define ICON_PRINT_COPIES_DOWN 13
|
|
|
|
#define ICON_PRINT_COPIES_UP 14
|
|
|
|
#define ICON_PRINT_CANCEL 15
|
|
|
|
#define ICON_PRINT_PRINT 16
|
|
|
|
#define ICON_PRINT_TEXT_BLACK 20
|
|
|
|
|
|
|
|
|
2004-08-15 23:06:24 +04:00
|
|
|
/** \todo landscape format pages
|
2004-08-09 10:28:57 +04:00
|
|
|
* \todo be somewhat more intelligent and try not to crop pages
|
|
|
|
* half way up a line of text
|
|
|
|
* \todo make use of print stylesheets
|
|
|
|
*/
|
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
struct gui_window *ro_print_current_window = NULL;
|
2004-08-19 05:01:31 +04:00
|
|
|
bool print_text_black = false;
|
2004-09-14 03:59:30 +04:00
|
|
|
bool print_active = false;
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
/* 1 millipoint == 1/400 OS unit == 1/800 browser units */
|
2004-08-11 20:26:13 +04:00
|
|
|
|
2004-08-12 01:36:30 +04:00
|
|
|
static int print_prev_message = 0;
|
2004-08-09 10:28:57 +04:00
|
|
|
static bool print_in_background = false;
|
2004-08-09 21:04:32 +04:00
|
|
|
static float print_scale = 1.0;
|
2004-08-09 10:28:57 +04:00
|
|
|
static int print_num_copies = 1;
|
2004-08-11 20:26:13 +04:00
|
|
|
static bool print_bg_images = false;
|
2004-08-09 10:28:57 +04:00
|
|
|
static int print_max_sheets = -1;
|
2010-07-28 02:50:51 +04:00
|
|
|
static bool print_sideways = false;
|
2006-03-05 15:24:18 +03:00
|
|
|
/** List of fonts in current print. */
|
|
|
|
static char **print_fonts_list = 0;
|
|
|
|
/** Number of entries in print_fonts_list. */
|
|
|
|
static unsigned int print_fonts_count;
|
|
|
|
/** Error in print_fonts_plot_text() or print_fonts_callback(). */
|
|
|
|
static const char *print_fonts_error;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2014-01-13 03:50:54 +04:00
|
|
|
void gui_window_redraw_window(struct gui_window *g);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
static bool ro_gui_print_click(wimp_pointer *pointer);
|
|
|
|
static bool ro_gui_print_apply(wimp_w w);
|
2004-08-09 10:28:57 +04:00
|
|
|
static void print_update_sheets_shaded_state(bool on);
|
2010-04-07 20:08:24 +04:00
|
|
|
static void print_send_printsave(hlcache_handle *h);
|
2004-08-09 10:28:57 +04:00
|
|
|
static bool print_send_printtypeknown(wimp_message *m);
|
2004-11-04 02:27:15 +03:00
|
|
|
static bool print_document(struct gui_window *g, const char *filename);
|
2010-04-07 20:08:24 +04:00
|
|
|
static const char *print_declare_fonts(hlcache_handle *h);
|
2009-07-09 02:04:40 +04:00
|
|
|
static bool print_fonts_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style);
|
2009-07-10 22:36:49 +04:00
|
|
|
static bool print_fonts_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style);
|
2009-07-14 14:03:58 +04:00
|
|
|
static bool print_fonts_plot_polygon(const int *p, unsigned int n, const plot_style_t *style);
|
2011-02-15 01:05:39 +03:00
|
|
|
static bool print_fonts_plot_clip(const struct rect *clip);
|
2009-07-21 14:59:53 +04:00
|
|
|
static bool print_fonts_plot_text(int x, int y, const char *text, size_t length,
|
|
|
|
const plot_font_style_t *fstyle);
|
2009-07-14 14:03:58 +04:00
|
|
|
static bool print_fonts_plot_disc(int x, int y, int radius, const plot_style_t *style);
|
|
|
|
static bool print_fonts_plot_arc(int x, int y, int radius, int angle1, int angle2, const plot_style_t *style);
|
2006-03-05 15:24:18 +03:00
|
|
|
static bool print_fonts_plot_bitmap(int x, int y, int width, int height,
|
2008-07-27 02:29:15 +04:00
|
|
|
struct bitmap *bitmap, colour bg,
|
2009-06-30 17:02:23 +04:00
|
|
|
bitmap_flags_t flags);
|
2009-02-03 04:27:54 +03:00
|
|
|
static bool print_fonts_plot_path(const float *p, unsigned int n, colour fill, float width,
|
|
|
|
colour c, const float transform[6]);
|
2006-03-05 15:24:18 +03:00
|
|
|
static void print_fonts_callback(void *context,
|
|
|
|
const char *font_name, unsigned int font_size,
|
|
|
|
const char *s8, unsigned short *s16, unsigned int n,
|
|
|
|
int x, int y);
|
|
|
|
|
|
|
|
|
|
|
|
/** Plotter for print_declare_fonts(). All the functions do nothing except for
|
|
|
|
* print_fonts_plot_text, which records the fonts used. */
|
|
|
|
static const struct plotter_table print_fonts_plotters = {
|
2009-06-30 17:02:23 +04:00
|
|
|
.rectangle = print_fonts_plot_rectangle,
|
|
|
|
.line = print_fonts_plot_line,
|
|
|
|
.polygon = print_fonts_plot_polygon,
|
|
|
|
.clip = print_fonts_plot_clip,
|
|
|
|
.text = print_fonts_plot_text,
|
|
|
|
.disc = print_fonts_plot_disc,
|
|
|
|
.arc = print_fonts_plot_arc,
|
|
|
|
.bitmap = print_fonts_plot_bitmap,
|
|
|
|
.path = print_fonts_plot_path,
|
|
|
|
.option_knockout = false,
|
2006-03-05 15:24:18 +03:00
|
|
|
};
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2005-12-31 07:40:49 +03:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
/**
|
|
|
|
* Initialise the print dialog.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_print_init(void)
|
|
|
|
{
|
|
|
|
wimp_i radio_print_type[] = {ICON_PRINT_TO_BOTTOM, ICON_PRINT_SHEETS,
|
|
|
|
-1};
|
|
|
|
wimp_i radio_print_orientation[] = {ICON_PRINT_UPRIGHT,
|
|
|
|
ICON_PRINT_SIDEWAYS, -1};
|
2005-12-31 07:40:49 +03:00
|
|
|
|
|
|
|
dialog_print = ro_gui_dialog_create("print");
|
|
|
|
ro_gui_wimp_event_register_radio(dialog_print, radio_print_type);
|
|
|
|
ro_gui_wimp_event_register_radio(dialog_print, radio_print_orientation);
|
2006-01-02 03:09:11 +03:00
|
|
|
ro_gui_wimp_event_register_checkbox(dialog_print, ICON_PRINT_FG_IMAGES);
|
|
|
|
ro_gui_wimp_event_register_checkbox(dialog_print, ICON_PRINT_BG_IMAGES);
|
2006-03-05 15:24:18 +03:00
|
|
|
ro_gui_wimp_event_register_checkbox(dialog_print,
|
|
|
|
ICON_PRINT_IN_BACKGROUND);
|
|
|
|
ro_gui_wimp_event_register_checkbox(dialog_print,
|
|
|
|
ICON_PRINT_TEXT_BLACK);
|
|
|
|
ro_gui_wimp_event_register_text_field(dialog_print,
|
|
|
|
ICON_PRINT_SHEETS_TEXT);
|
|
|
|
ro_gui_wimp_event_register_numeric_field(dialog_print,
|
|
|
|
ICON_PRINT_COPIES, ICON_PRINT_COPIES_UP,
|
|
|
|
ICON_PRINT_COPIES_DOWN, 1, 99, 1, 0);
|
|
|
|
ro_gui_wimp_event_register_numeric_field(dialog_print,
|
|
|
|
ICON_PRINT_SHEETS_VALUE, ICON_PRINT_SHEETS_UP,
|
|
|
|
ICON_PRINT_SHEETS_DOWN, 1, 99, 1, 0);
|
2005-12-31 07:40:49 +03:00
|
|
|
ro_gui_wimp_event_register_cancel(dialog_print, ICON_PRINT_CANCEL);
|
2006-03-05 15:24:18 +03:00
|
|
|
ro_gui_wimp_event_register_mouse_click(dialog_print,
|
|
|
|
ro_gui_print_click);
|
2005-12-31 07:40:49 +03:00
|
|
|
ro_gui_wimp_event_register_ok(dialog_print, ICON_PRINT_PRINT,
|
|
|
|
ro_gui_print_apply);
|
2006-12-01 17:37:21 +03:00
|
|
|
ro_gui_wimp_event_set_help_prefix(dialog_print, "HelpPrint");
|
2005-12-31 07:40:49 +03:00
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
2005-04-08 00:46:22 +04:00
|
|
|
* Prepares all aspects of the print dialog prior to opening.
|
2004-08-09 10:28:57 +04:00
|
|
|
*
|
|
|
|
* \param g parent window
|
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
|
|
|
void ro_gui_print_prepare(struct gui_window *g)
|
|
|
|
{
|
|
|
|
char *desc;
|
2004-08-09 10:28:57 +04:00
|
|
|
bool printers_exists = true;
|
2006-03-05 15:24:18 +03:00
|
|
|
os_error *error;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
assert(g);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_current_window = g;
|
2004-08-12 01:36:30 +04:00
|
|
|
print_prev_message = 0;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
/* Read Printer Driver name */
|
2006-03-05 15:24:18 +03:00
|
|
|
error = xpdriver_info(0, 0, 0, 0, &desc, 0, 0, 0);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_info: 0x%x: %s", error->errnum, error->errmess);
|
2004-08-09 10:28:57 +04:00
|
|
|
printers_exists = false;
|
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_TO_BOTTOM,
|
|
|
|
true);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_SHEETS, false);
|
|
|
|
ro_gui_set_icon_integer(dialog_print, ICON_PRINT_SHEETS_VALUE, 1);
|
|
|
|
print_update_sheets_shaded_state(true);
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_FG_IMAGES,
|
|
|
|
true);
|
2004-08-09 10:28:57 +04:00
|
|
|
ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_FG_IMAGES, true);
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_BG_IMAGES,
|
|
|
|
print_bg_images);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_IN_BACKGROUND,
|
|
|
|
false);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_UPRIGHT, true);
|
2006-03-05 15:24:18 +03:00
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_SIDEWAYS,
|
|
|
|
false);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_TEXT_BLACK,
|
|
|
|
false);
|
2004-08-19 05:01:31 +04:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
ro_gui_set_icon_integer(dialog_print, ICON_PRINT_COPIES, 1);
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_PRINT,
|
|
|
|
!printers_exists);
|
|
|
|
if (printers_exists)
|
|
|
|
ro_gui_set_window_title(dialog_print, desc);
|
|
|
|
|
2005-12-31 07:40:49 +03:00
|
|
|
ro_gui_wimp_event_memorise(dialog_print);
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Handle mouse clicks in print dialog
|
|
|
|
*
|
|
|
|
* \param pointer wimp_pointer block
|
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2005-12-31 07:40:49 +03:00
|
|
|
bool ro_gui_print_click(wimp_pointer *pointer)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
|
|
|
if (pointer->buttons == wimp_CLICK_MENU)
|
2005-12-31 07:40:49 +03:00
|
|
|
return true;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
switch (pointer->i) {
|
|
|
|
case ICON_PRINT_TO_BOTTOM:
|
2006-01-02 03:09:11 +03:00
|
|
|
case ICON_PRINT_SHEETS:
|
2006-03-05 15:24:18 +03:00
|
|
|
print_update_sheets_shaded_state(pointer->i !=
|
|
|
|
ICON_PRINT_SHEETS);
|
2004-08-09 10:28:57 +04:00
|
|
|
break;
|
|
|
|
}
|
2005-12-31 07:40:49 +03:00
|
|
|
return false;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
/**
|
|
|
|
* Handle click on the Print button in the print dialog.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ro_gui_print_apply(wimp_w w)
|
|
|
|
{
|
2005-12-31 07:40:49 +03:00
|
|
|
int copies = atoi(ro_gui_get_icon_string(dialog_print,
|
|
|
|
ICON_PRINT_COPIES));
|
|
|
|
int sheets = atoi(ro_gui_get_icon_string(dialog_print,
|
|
|
|
ICON_PRINT_SHEETS_VALUE));
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
print_in_background = ro_gui_get_icon_selected_state(dialog_print,
|
|
|
|
ICON_PRINT_IN_BACKGROUND);
|
|
|
|
print_text_black = ro_gui_get_icon_selected_state(dialog_print,
|
|
|
|
ICON_PRINT_TEXT_BLACK);
|
2010-07-28 02:50:51 +04:00
|
|
|
print_sideways = ro_gui_get_icon_selected_state(dialog_print,
|
|
|
|
ICON_PRINT_SIDEWAYS);
|
2005-12-31 07:40:49 +03:00
|
|
|
print_num_copies = copies;
|
|
|
|
if (ro_gui_get_icon_selected_state(dialog_print, ICON_PRINT_SHEETS))
|
|
|
|
print_max_sheets = sheets;
|
|
|
|
else
|
|
|
|
print_max_sheets = -1;
|
2011-12-24 02:52:40 +04:00
|
|
|
print_bg_images = ro_gui_get_icon_selected_state(dialog_print,
|
2011-12-24 01:49:13 +04:00
|
|
|
ICON_PRINT_BG_IMAGES);
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2014-08-22 19:35:39 +04:00
|
|
|
print_send_printsave(browser_window_get_content(
|
|
|
|
ro_print_current_window->bw));
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2005-12-31 07:40:49 +03:00
|
|
|
return true;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Set shaded state of sheets
|
|
|
|
*
|
|
|
|
* \param on whether to turn shading on or off
|
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
void print_update_sheets_shaded_state(bool on)
|
|
|
|
{
|
|
|
|
ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_SHEETS_VALUE, on);
|
|
|
|
ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_SHEETS_DOWN, on);
|
|
|
|
ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_SHEETS_UP, on);
|
|
|
|
ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_SHEETS_TEXT, on);
|
|
|
|
ro_gui_set_caret_first(dialog_print);
|
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Send a message_PRINT_SAVE
|
|
|
|
*
|
2014-11-10 20:00:15 +03:00
|
|
|
* \param h handle to content to print.
|
2004-08-09 10:28:57 +04:00
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2010-04-07 20:08:24 +04:00
|
|
|
void print_send_printsave(hlcache_handle *h)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
|
|
|
wimp_full_message_data_xfer m;
|
|
|
|
os_error *e;
|
|
|
|
int len;
|
|
|
|
|
2010-04-07 20:08:24 +04:00
|
|
|
len = strlen(content_get_title(h)) + 1;
|
2004-08-09 10:28:57 +04:00
|
|
|
if (212 < len)
|
|
|
|
len = 212;
|
|
|
|
|
|
|
|
m.size = ((44+len+3) & ~3);
|
|
|
|
m.your_ref = 0;
|
|
|
|
m.action = message_PRINT_SAVE;
|
|
|
|
m.w = (wimp_w)0;
|
|
|
|
m.i = m.pos.x = m.pos.y = 0;
|
|
|
|
m.est_size = 1024; /* arbitrary value - it really doesn't matter */
|
2010-04-07 20:08:24 +04:00
|
|
|
m.file_type = ro_content_filetype(h);
|
|
|
|
strncpy(m.file_name, content_get_title(h), 211);
|
2004-08-09 10:28:57 +04:00
|
|
|
m.file_name[211] = 0;
|
|
|
|
e = xwimp_send_message(wimp_USER_MESSAGE_RECORDED,
|
|
|
|
(wimp_message *)&m, 0);
|
|
|
|
if (e) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_send_message: 0x%x: %s", e->errnum, e->errmess);
|
2004-08-09 10:28:57 +04:00
|
|
|
warn_user("WimpError", e->errmess);
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_cleanup();
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
2004-08-12 01:36:30 +04:00
|
|
|
print_prev_message = m.my_ref;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Send a message_PRINT_TYPE_KNOWN
|
|
|
|
*
|
|
|
|
* \param m message to reply to
|
|
|
|
* \return true on success, false otherwise
|
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
bool print_send_printtypeknown(wimp_message *m)
|
|
|
|
{
|
|
|
|
os_error *e;
|
|
|
|
|
|
|
|
m->size = 20;
|
|
|
|
m->your_ref = m->my_ref;
|
|
|
|
m->action = message_PRINT_TYPE_KNOWN;
|
|
|
|
e = xwimp_send_message(wimp_USER_MESSAGE, m, m->sender);
|
|
|
|
if (e) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_send_message: 0x%x: %s", e->errnum, e->errmess);
|
2004-08-09 10:28:57 +04:00
|
|
|
warn_user("WimpError", e->errmess);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Handle a bounced message_PRINT_SAVE
|
|
|
|
*
|
|
|
|
* \param m the bounced message
|
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
void ro_print_save_bounce(wimp_message *m)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
2004-08-12 01:36:30 +04:00
|
|
|
if (m->my_ref == 0 || m->my_ref != print_prev_message)
|
|
|
|
return;
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/* try to print anyway (we're graphics printing) */
|
2008-08-03 00:07:44 +04:00
|
|
|
if (ro_print_current_window) {
|
|
|
|
print_document(ro_print_current_window, "printer:");
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_cleanup();
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Handle message_PRINT_ERROR
|
|
|
|
*
|
|
|
|
* \param m the message containing the error
|
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
void ro_print_error(wimp_message *m)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
|
|
|
pdriver_message_print_error *p = (pdriver_message_print_error*)&m->data;
|
2004-08-12 01:36:30 +04:00
|
|
|
if (m->your_ref == 0 || m->your_ref != print_prev_message)
|
|
|
|
return;
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
if (m->size == 20)
|
|
|
|
warn_user("PrintErrorRO2", 0);
|
|
|
|
else
|
|
|
|
warn_user("PrintError", p->errmess);
|
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_cleanup();
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Handle message_PRINT_TYPE_ODD
|
|
|
|
*
|
|
|
|
* \param m the message to handle
|
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
void ro_print_type_odd(wimp_message *m)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
2004-08-12 01:36:30 +04:00
|
|
|
if ((m->your_ref == 0 || m->your_ref == print_prev_message) &&
|
|
|
|
!print_in_background) {
|
2004-08-09 10:28:57 +04:00
|
|
|
/* reply to a previous message (ie printsave) */
|
2008-08-03 00:07:44 +04:00
|
|
|
if (ro_print_current_window && print_send_printtypeknown(m)) {
|
|
|
|
print_document(ro_print_current_window, "printer:");
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_cleanup();
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* broadcast message */
|
|
|
|
/* no need to do anything */
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
2004-11-04 02:27:15 +03:00
|
|
|
* Handle message_DATASAVE_ACK for the printing protocol.
|
2004-08-09 10:28:57 +04:00
|
|
|
*
|
2004-11-04 02:27:15 +03:00
|
|
|
* \param m the message to handle
|
2004-08-12 01:36:30 +04:00
|
|
|
* \return true if message successfully handled, false otherwise
|
2004-11-04 02:27:15 +03:00
|
|
|
*
|
|
|
|
* We cheat here and, instead of giving Printers what it asked for (a copy of
|
|
|
|
* the file so it can poke us later via a broadcast of PrintTypeOdd), we give
|
|
|
|
* it a file that it can print itself without having to bother us further. For
|
|
|
|
* PostScript printers (type 0) we give it a PostScript file. Otherwise, we give
|
|
|
|
* it a PrintOut file.
|
|
|
|
*
|
|
|
|
* This method has a couple of advantages:
|
|
|
|
* - we can reuse this code for background printing (we simply ignore the
|
|
|
|
* PrintTypeOdd reply)
|
|
|
|
* - there's no need to ensure all components of a page queued to be printed
|
|
|
|
* still exist when it reaches the top of the queue. (which reduces complexity
|
|
|
|
* a fair bit)
|
2004-08-09 10:28:57 +04:00
|
|
|
*/
|
2004-11-04 02:27:15 +03:00
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
bool ro_print_ack(wimp_message *m)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
2004-11-04 02:27:15 +03:00
|
|
|
pdriver_info_type info_type;
|
|
|
|
pdriver_type type;
|
|
|
|
os_error *error;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
if (m->your_ref == 0 || m->your_ref != print_prev_message ||
|
2008-08-03 00:07:44 +04:00
|
|
|
!ro_print_current_window)
|
2004-08-12 01:36:30 +04:00
|
|
|
return false;
|
2004-11-04 02:27:15 +03:00
|
|
|
|
|
|
|
/* read printer driver type */
|
|
|
|
error = xpdriver_info(&info_type, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_info: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
warn_user("PrintError", error->errmess);
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_cleanup();
|
2004-11-04 02:27:15 +03:00
|
|
|
return true;
|
2004-08-12 01:36:30 +04:00
|
|
|
}
|
2004-11-04 02:27:15 +03:00
|
|
|
type = info_type >> 16;
|
2004-08-12 01:36:30 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
/* print to file */
|
2008-08-03 00:07:44 +04:00
|
|
|
if (!print_document(ro_print_current_window,
|
2004-11-04 02:27:15 +03:00
|
|
|
m->data.data_xfer.file_name)) {
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_cleanup();
|
2004-08-12 01:36:30 +04:00
|
|
|
return true;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
/* send dataload */
|
|
|
|
m->your_ref = m->my_ref;
|
|
|
|
m->action = message_DATA_LOAD;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
if (type == pdriver_TYPE_PS)
|
|
|
|
m->data.data_xfer.file_type = osfile_TYPE_POSTSCRIPT;
|
|
|
|
else
|
|
|
|
m->data.data_xfer.file_type = osfile_TYPE_PRINTOUT;
|
|
|
|
|
|
|
|
error = xwimp_send_message(wimp_USER_MESSAGE_RECORDED, m, m->sender);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xwimp_send_message: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
warn_user("WimpError", error->errmess);
|
|
|
|
/* and delete temporary file */
|
|
|
|
xosfile_delete(m->data.data_xfer.file_name,
|
|
|
|
0, 0, 0, 0, 0);
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
2004-11-04 02:27:15 +03:00
|
|
|
print_prev_message = m->my_ref;
|
2004-08-12 01:36:30 +04:00
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_cleanup();
|
2004-08-12 01:36:30 +04:00
|
|
|
return true;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Handle a bounced dataload message
|
|
|
|
*
|
|
|
|
* \param m the message to handle
|
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
void ro_print_dataload_bounce(wimp_message *m)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
2004-08-12 01:36:30 +04:00
|
|
|
if (m->your_ref == 0 || m->your_ref != print_prev_message)
|
|
|
|
return;
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
xosfile_delete(m->data.data_xfer.file_name, 0, 0, 0, 0, 0);
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_cleanup();
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Cleanup after printing
|
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2008-08-03 00:07:44 +04:00
|
|
|
void ro_print_cleanup(void)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
2008-08-03 00:07:44 +04:00
|
|
|
ro_print_current_window = NULL;
|
2004-08-19 05:01:31 +04:00
|
|
|
print_text_black = false;
|
2004-08-12 01:36:30 +04:00
|
|
|
print_prev_message = 0;
|
2004-08-09 10:28:57 +04:00
|
|
|
print_max_sheets = -1;
|
2014-01-29 20:54:34 +04:00
|
|
|
ro_gui_menu_destroy();
|
2004-08-09 10:28:57 +04:00
|
|
|
ro_gui_dialog_close(dialog_print);
|
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
2004-11-04 02:27:15 +03:00
|
|
|
* Print a document.
|
2004-08-09 10:28:57 +04:00
|
|
|
*
|
2004-11-04 02:27:15 +03:00
|
|
|
* \param g gui_window containing the document to print
|
|
|
|
* \param filename name of file to print to
|
|
|
|
* \return true on success, false on error and error reported
|
2004-08-09 10:28:57 +04:00
|
|
|
*/
|
2004-11-04 02:27:15 +03:00
|
|
|
|
|
|
|
bool print_document(struct gui_window *g, const char *filename)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
2004-11-04 02:27:15 +03:00
|
|
|
int left, right, top, bottom, width, height;
|
2005-07-02 22:17:51 +04:00
|
|
|
int saved_width, saved_height;
|
2004-11-04 02:27:15 +03:00
|
|
|
int yscroll = 0, sheets = print_max_sheets;
|
2014-08-22 19:35:39 +04:00
|
|
|
hlcache_handle *h = browser_window_get_content(g->bw);
|
2004-11-04 02:27:15 +03:00
|
|
|
const char *error_message;
|
2004-08-09 10:28:57 +04:00
|
|
|
pdriver_features features;
|
|
|
|
os_fw fhandle, old_job = 0;
|
2004-11-04 02:27:15 +03:00
|
|
|
os_error *error;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
/* no point printing a blank page */
|
2010-04-07 20:08:24 +04:00
|
|
|
if (!h) {
|
2004-11-04 02:27:15 +03:00
|
|
|
warn_user("PrintError", "nothing to print");
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
/* read printer driver features */
|
|
|
|
error = xpdriver_info(0, 0, 0, &features, 0, 0, 0, 0);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_info: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
warn_user("PrintError", error->errmess);
|
|
|
|
return false;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
/* read page size */
|
|
|
|
error = xpdriver_page_size(0, 0, &left, &bottom, &right, &top);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_page_size: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
warn_user("PrintError", error->errmess);
|
|
|
|
return false;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2010-07-28 02:50:51 +04:00
|
|
|
if (print_sideways) {
|
|
|
|
width = (top - bottom) / 800;
|
|
|
|
height = (right - left) / 800;
|
|
|
|
} else {
|
|
|
|
width = (right - left) / 800;
|
|
|
|
height = (top - bottom) / 800;
|
|
|
|
}
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
/* layout the document to the correct width */
|
2010-04-07 20:08:24 +04:00
|
|
|
saved_width = content_get_width(h);
|
|
|
|
saved_height = content_get_height(h);
|
|
|
|
if (content_get_type(h) == CONTENT_HTML)
|
2011-06-24 13:30:33 +04:00
|
|
|
content_reformat(h, false, width, height);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
/* open printer file */
|
|
|
|
error = xosfind_openoutw(osfind_NO_PATH | osfind_ERROR_IF_DIR |
|
|
|
|
osfind_ERROR_IF_ABSENT, filename, 0, &fhandle);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosfind_openoutw: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
warn_user("PrintError", error->errmess);
|
|
|
|
return false;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* select print job */
|
2004-11-04 02:27:15 +03:00
|
|
|
error = xpdriver_select_jobw(fhandle, "NetSurf", &old_job);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_select_jobw: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
warn_user("PrintError", error->errmess);
|
2004-08-09 10:28:57 +04:00
|
|
|
xosfind_closew(fhandle);
|
2004-11-04 02:27:15 +03:00
|
|
|
return false;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2005-03-08 03:04:57 +03:00
|
|
|
rufl_invalidate_cache();
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/* declare fonts, if necessary */
|
2006-03-05 15:24:18 +03:00
|
|
|
if (features & pdriver_FEATURE_DECLARE_FONT) {
|
2010-04-07 20:08:24 +04:00
|
|
|
if ((error_message = print_declare_fonts(h)))
|
2004-08-09 10:28:57 +04:00
|
|
|
goto error;
|
2006-03-05 15:24:18 +03:00
|
|
|
}
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
ro_gui_current_redraw_gui = g;
|
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
/* print is now active */
|
|
|
|
print_active = true;
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
do {
|
2011-02-14 01:25:11 +03:00
|
|
|
struct rect clip;
|
2010-07-28 02:50:51 +04:00
|
|
|
os_box b;
|
|
|
|
os_hom_trfm t;
|
|
|
|
os_coord p;
|
2004-11-04 02:27:15 +03:00
|
|
|
osbool more;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2010-07-28 02:50:51 +04:00
|
|
|
if (print_sideways) {
|
|
|
|
b.x0 = bottom / 400 -2;
|
|
|
|
b.y0 = left / 400 - 2;
|
|
|
|
b.x1 = top / 400 + 2;
|
|
|
|
b.y1 = right / 400 + 2;
|
|
|
|
t.entries[0][0] = 0;
|
|
|
|
t.entries[0][1] = 65536;
|
|
|
|
t.entries[1][0] = -65536;
|
|
|
|
t.entries[1][1] = 0;
|
|
|
|
p.x = right;
|
|
|
|
p.y = bottom;
|
|
|
|
ro_plot_origin_x = bottom / 400;
|
|
|
|
ro_plot_origin_y = right / 400 + yscroll * 2;
|
|
|
|
} else {
|
|
|
|
b.x0 = left / 400 -2;
|
|
|
|
b.y0 = bottom / 400 - 2;
|
|
|
|
b.x1 = right / 400 + 2;
|
|
|
|
b.y1 = top / 400 + 2;
|
|
|
|
t.entries[0][0] = 65536;
|
|
|
|
t.entries[0][1] = 0;
|
|
|
|
t.entries[1][0] = 0;
|
|
|
|
t.entries[1][1] = 65536;
|
|
|
|
p.x = left;
|
|
|
|
p.y = bottom;
|
|
|
|
ro_plot_origin_x = left / 400;
|
|
|
|
ro_plot_origin_y = top / 400 + yscroll * 2;
|
|
|
|
}
|
|
|
|
|
2010-04-07 20:08:24 +04:00
|
|
|
xhourglass_percentage((int) (yscroll * 100 /
|
|
|
|
content_get_height(h)));
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
/* give page rectangle */
|
|
|
|
error = xpdriver_give_rectangle(0, &b, &t, &p, os_COLOUR_WHITE);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_give_rectangle: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
error_message = error->errmess;
|
2004-08-09 10:28:57 +04:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("given rectangle: [(%d, %d), (%d, %d)]", b.x0, b.y0, b.x1, b.y1);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
/* and redraw the document */
|
2004-11-04 02:27:15 +03:00
|
|
|
error = xpdriver_draw_page(print_num_copies, &b, 0, 0,
|
|
|
|
&more, 0);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_draw_page: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
error_message = error->errmess;
|
2004-08-09 10:28:57 +04:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (more) {
|
2011-06-29 00:17:39 +04:00
|
|
|
struct content_redraw_data data;
|
2011-06-30 19:48:07 +04:00
|
|
|
/* TODO: turn knockout off for print */
|
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = false,
|
2011-12-24 02:52:40 +04:00
|
|
|
.background_images = print_bg_images,
|
2011-06-30 19:48:07 +04:00
|
|
|
.plot = &ro_plotters
|
|
|
|
};
|
2011-06-29 00:17:39 +04:00
|
|
|
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("redrawing area: [(%d, %d), (%d, %d)]", b.x0, b.y0, b.x1, b.y1);
|
2011-02-14 01:25:11 +03:00
|
|
|
clip.x0 = (b.x0 - ro_plot_origin_x) / 2;
|
|
|
|
clip.y0 = (ro_plot_origin_y - b.y1) / 2;
|
|
|
|
clip.x1 = (b.x1 - ro_plot_origin_x) / 2;
|
|
|
|
clip.y1 = (ro_plot_origin_y - b.y0) / 2;
|
2011-06-29 00:17:39 +04:00
|
|
|
|
|
|
|
data.x = 0;
|
|
|
|
data.y = 0;
|
|
|
|
data.width = content_get_width(h);
|
|
|
|
data.height = content_get_height(h);
|
|
|
|
data.background_colour = 0xFFFFFF;
|
|
|
|
data.scale = print_scale;
|
|
|
|
data.repeat_x = false;
|
|
|
|
data.repeat_y = false;
|
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
if (!content_redraw(h, &data, &clip, &ctx)) {
|
2004-11-04 02:27:15 +03:00
|
|
|
error_message = "redraw error";
|
|
|
|
goto error;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
2004-08-11 20:26:13 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
error = xpdriver_get_rectangle(&b, &more, 0);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_get_rectangle: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
error_message = error->errmess;
|
2004-08-09 10:28:57 +04:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
yscroll += height;
|
2010-04-07 20:08:24 +04:00
|
|
|
} while (yscroll <= content_get_height(h) && --sheets != 0);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
/* make print inactive */
|
|
|
|
print_active = false;
|
2004-11-04 02:27:15 +03:00
|
|
|
ro_gui_current_redraw_gui = 0;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2010-07-15 03:03:08 +04:00
|
|
|
/* clean up
|
|
|
|
*
|
|
|
|
* Call PDriver_EndJob via _swix() so that r9 is preserved. This
|
|
|
|
* prevents a crash if the SWI corrupts it on exit (as seems to
|
|
|
|
* happen on some versions of RISC OS 6).
|
|
|
|
*/
|
|
|
|
|
|
|
|
error = (os_error *) _swix(PDriver_EndJob, _IN(0), (int) fhandle);
|
2004-11-04 02:27:15 +03:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_end_jobw: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
error_message = error->errmess;
|
2004-08-09 10:28:57 +04:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
error = xosfind_closew(fhandle);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xosfind_closew: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
warn_user("PrintError", error->errmess);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_job) {
|
|
|
|
error = xpdriver_select_jobw(old_job, 0, 0);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_select_jobw: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
warn_user("PrintError", error->errmess);
|
|
|
|
/* the printing succeeded anyway */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2005-03-08 03:04:57 +03:00
|
|
|
rufl_invalidate_cache();
|
|
|
|
|
2010-07-16 01:06:10 +04:00
|
|
|
/* restore document layout and redraw browser window */
|
2010-04-07 20:08:24 +04:00
|
|
|
if (content_get_type(h) == CONTENT_HTML)
|
2011-06-24 13:30:33 +04:00
|
|
|
content_reformat(h, false, saved_width, saved_height);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2010-07-16 01:06:10 +04:00
|
|
|
gui_window_redraw_window(g);
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
return true;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
error:
|
|
|
|
xpdriver_abort_job(fhandle);
|
2004-11-04 02:27:15 +03:00
|
|
|
xosfind_closew(fhandle);
|
|
|
|
if (old_job)
|
|
|
|
xpdriver_select_jobw(old_job, 0, 0);
|
2004-08-11 20:26:13 +04:00
|
|
|
print_active = false;
|
2004-11-04 02:27:15 +03:00
|
|
|
ro_gui_current_redraw_gui = 0;
|
|
|
|
|
|
|
|
warn_user("PrintError", error_message);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2005-03-08 03:04:57 +03:00
|
|
|
rufl_invalidate_cache();
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/* restore document layout */
|
2010-04-07 20:08:24 +04:00
|
|
|
if (content_get_type(h) == CONTENT_HTML)
|
2011-06-24 13:30:33 +04:00
|
|
|
content_reformat(h, false, saved_width, saved_height);
|
2004-11-04 02:27:15 +03:00
|
|
|
|
|
|
|
return false;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Declare fonts to the printer driver.
|
|
|
|
*
|
2014-11-10 20:00:15 +03:00
|
|
|
* \param h handle to content being printed
|
2004-11-04 02:27:15 +03:00
|
|
|
* \return 0 on success, error message on error
|
|
|
|
*/
|
|
|
|
|
2010-04-07 20:08:24 +04:00
|
|
|
const char *print_declare_fonts(hlcache_handle *h)
|
2004-11-04 02:27:15 +03:00
|
|
|
{
|
2006-03-05 15:24:18 +03:00
|
|
|
unsigned int i;
|
2011-02-14 01:25:11 +03:00
|
|
|
struct rect clip;
|
2011-06-29 00:17:39 +04:00
|
|
|
struct content_redraw_data data;
|
2004-11-04 02:27:15 +03:00
|
|
|
const char *error_message = 0;
|
|
|
|
os_error *error;
|
2011-06-30 19:48:07 +04:00
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = false,
|
2011-12-24 02:39:25 +04:00
|
|
|
.background_images = false,
|
2011-06-30 19:48:07 +04:00
|
|
|
.plot = &print_fonts_plotters
|
|
|
|
};
|
2004-11-04 02:27:15 +03:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
free(print_fonts_list);
|
|
|
|
print_fonts_list = 0;
|
|
|
|
print_fonts_count = 0;
|
|
|
|
print_fonts_error = 0;
|
|
|
|
|
2011-02-14 01:25:11 +03:00
|
|
|
clip.x0 = clip.y0 = INT_MIN;
|
|
|
|
clip.x1 = clip.y1 = INT_MAX;
|
|
|
|
|
2011-06-29 00:17:39 +04:00
|
|
|
data.x = 0;
|
|
|
|
data.y = 0;
|
|
|
|
data.width = content_get_width(h);
|
|
|
|
data.height = content_get_height(h);
|
|
|
|
data.background_colour = 0xFFFFFF;
|
|
|
|
data.scale = 1;
|
|
|
|
data.repeat_x = false;
|
|
|
|
data.repeat_y = false;
|
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
if (!content_redraw(h, &data, &clip, &ctx)) {
|
2006-03-05 15:24:18 +03:00
|
|
|
if (print_fonts_error)
|
|
|
|
return print_fonts_error;
|
|
|
|
return "Declaring fonts failed.";
|
2004-11-04 02:27:15 +03:00
|
|
|
}
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
for (i = 0; i != print_fonts_count; ++i) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("%u %s", i, print_fonts_list[i]);
|
2006-03-05 15:24:18 +03:00
|
|
|
error = xpdriver_declare_font(0, print_fonts_list[i],
|
|
|
|
pdriver_KERNED);
|
2004-11-04 02:27:15 +03:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_declare_font: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
error_message = error->errmess;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = xpdriver_declare_font(0, 0, 0);
|
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xpdriver_declare_font: 0x%x: %s", error->errnum, error->errmess);
|
2004-11-04 02:27:15 +03:00
|
|
|
error_message = error->errmess;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
2006-03-05 15:24:18 +03:00
|
|
|
for (i = 0; i != print_fonts_count; i++)
|
|
|
|
free(print_fonts_list[i]);
|
|
|
|
free(print_fonts_list);
|
|
|
|
print_fonts_list = 0;
|
2004-11-04 02:27:15 +03:00
|
|
|
|
|
|
|
return error_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-09 02:04:40 +04:00
|
|
|
bool print_fonts_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-01 17:53:06 +04:00
|
|
|
|
2009-07-09 02:04:40 +04:00
|
|
|
|
2009-07-10 22:36:49 +04:00
|
|
|
bool print_fonts_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-01 17:53:06 +04:00
|
|
|
|
2009-07-14 14:03:58 +04:00
|
|
|
bool print_fonts_plot_polygon(const int *p, unsigned int n, const plot_style_t *style)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-01 17:53:06 +04:00
|
|
|
|
2009-06-30 17:02:23 +04:00
|
|
|
|
2011-02-15 01:05:39 +03:00
|
|
|
bool print_fonts_plot_clip(const struct rect *clip)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-06-30 17:02:23 +04:00
|
|
|
|
2009-07-14 14:03:58 +04:00
|
|
|
bool print_fonts_plot_disc(int x, int y, int radius, const plot_style_t *style)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-06-30 17:02:23 +04:00
|
|
|
|
2006-03-24 06:44:37 +03:00
|
|
|
bool print_fonts_plot_arc(int x, int y, int radius, int angle1, int angle2,
|
2009-07-14 14:03:58 +04:00
|
|
|
const plot_style_t *style)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-06-30 17:02:23 +04:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
bool print_fonts_plot_bitmap(int x, int y, int width, int height,
|
2009-06-30 17:02:23 +04:00
|
|
|
struct bitmap *bitmap, colour bg, bitmap_flags_t flags)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-06-30 17:02:23 +04:00
|
|
|
|
2009-02-03 04:27:54 +03:00
|
|
|
bool print_fonts_plot_path(const float *p, unsigned int n, colour fill, float width,
|
|
|
|
colour c, const float transform[6])
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2006-03-05 15:24:18 +03:00
|
|
|
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
2006-03-05 15:24:18 +03:00
|
|
|
* Plotter for text plotting during font listing.
|
2004-08-09 10:28:57 +04:00
|
|
|
*/
|
2006-03-05 15:24:18 +03:00
|
|
|
|
2010-05-02 14:50:46 +04:00
|
|
|
bool print_fonts_plot_text(int x, int y, const char *text, size_t length,
|
2009-07-21 14:59:53 +04:00
|
|
|
const plot_font_style_t *fstyle)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
2006-03-05 15:24:18 +03:00
|
|
|
const char *font_family;
|
|
|
|
unsigned int font_size;
|
|
|
|
rufl_style font_style;
|
|
|
|
rufl_code code;
|
|
|
|
|
2009-07-21 14:59:53 +04:00
|
|
|
nsfont_read_style(fstyle, &font_family, &font_size, &font_style);
|
2006-03-05 15:24:18 +03:00
|
|
|
|
|
|
|
code = rufl_paint_callback(font_family, font_style, font_size,
|
|
|
|
text, length, 0, 0, print_fonts_callback, 0);
|
|
|
|
if (code != rufl_OK) {
|
|
|
|
if (code == rufl_FONT_MANAGER_ERROR) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("rufl_paint_callback: rufl_FONT_MANAGER_ERROR: ""0x%x: %s", rufl_fm_error->errnum, rufl_fm_error->errmess);
|
2006-03-05 15:24:18 +03:00
|
|
|
print_fonts_error = rufl_fm_error->errmess;
|
|
|
|
} else {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("rufl_paint_callback: 0x%x", code);
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
2006-03-05 15:24:18 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (print_fonts_error)
|
|
|
|
return false;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
/**
|
|
|
|
* Callback for print_fonts_plot_text().
|
|
|
|
*
|
|
|
|
* The font name is added to print_fonts_list.
|
|
|
|
*/
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
void print_fonts_callback(void *context,
|
|
|
|
const char *font_name, unsigned int font_size,
|
|
|
|
const char *s8, unsigned short *s16, unsigned int n,
|
|
|
|
int x, int y)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
char **fonts_list;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
(void) context; /* unused */
|
|
|
|
(void) font_size; /* unused */
|
|
|
|
(void) x; /* unused */
|
|
|
|
(void) y; /* unused */
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2006-03-05 15:24:18 +03:00
|
|
|
assert(s8 || s16);
|
|
|
|
|
|
|
|
/* check if the font name is new */
|
|
|
|
for (i = 0; i != print_fonts_count &&
|
|
|
|
strcmp(print_fonts_list[i], font_name) != 0; i++)
|
|
|
|
;
|
|
|
|
if (i != print_fonts_count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* add to list of fonts */
|
|
|
|
fonts_list = realloc(print_fonts_list,
|
|
|
|
sizeof print_fonts_list[0] *
|
|
|
|
(print_fonts_count + 1));
|
|
|
|
if (!fonts_list) {
|
|
|
|
print_fonts_error = messages_get("NoMemory");
|
|
|
|
return;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
2006-03-05 15:24:18 +03:00
|
|
|
fonts_list[print_fonts_count] = strdup(font_name);
|
|
|
|
if (!fonts_list[print_fonts_count]) {
|
|
|
|
print_fonts_error = messages_get("NoMemory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
print_fonts_list = fonts_list;
|
|
|
|
print_fonts_count++;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
2004-08-11 20:26:13 +04:00
|
|
|
|