2004-08-09 10:28:57 +04:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.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"
|
2005-03-08 03:04:57 +03:00
|
|
|
#include "rufl.h"
|
2004-08-09 10:28:57 +04:00
|
|
|
#include "netsurf/utils/config.h"
|
|
|
|
#include "netsurf/content/content.h"
|
2004-11-04 02:27:15 +03:00
|
|
|
#include "netsurf/desktop/plotters.h"
|
2004-08-11 23:02:32 +04:00
|
|
|
#include "netsurf/render/box.h"
|
2004-08-09 10:28:57 +04:00
|
|
|
#include "netsurf/render/font.h"
|
|
|
|
#include "netsurf/render/html.h"
|
|
|
|
#include "netsurf/render/layout.h"
|
|
|
|
#include "netsurf/riscos/gui.h"
|
2005-04-08 00:46:22 +04:00
|
|
|
#include "netsurf/riscos/menus.h"
|
2004-08-09 10:28:57 +04:00
|
|
|
#include "netsurf/riscos/print.h"
|
|
|
|
#include "netsurf/riscos/wimp.h"
|
|
|
|
#include "netsurf/utils/log.h"
|
2004-11-04 02:27:15 +03:00
|
|
|
#include "netsurf/utils/messages.h"
|
2004-08-09 10:28:57 +04:00
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
/* extern globals */
|
2004-08-09 10:28:57 +04:00
|
|
|
struct gui_window *print_current_window = 0;
|
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;
|
|
|
|
|
|
|
|
#ifdef WITH_PRINT
|
|
|
|
|
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
|
|
|
|
|
|
|
/* static globals */
|
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;
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
/* a font in a document */
|
2004-08-09 10:28:57 +04:00
|
|
|
struct print_font {
|
|
|
|
font_f handle;
|
2004-11-04 02:27:15 +03:00
|
|
|
void *font_name;
|
2004-08-09 10:28:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void print_update_sheets_shaded_state(bool on);
|
|
|
|
static void print_send_printsave(struct content *c);
|
|
|
|
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);
|
|
|
|
static const char *print_declare_fonts(struct box *box);
|
|
|
|
static bool print_find_fonts(struct box *box, struct print_font **print_fonts,
|
|
|
|
int *font_count);
|
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
|
|
|
|
*/
|
2005-04-08 00:46:22 +04:00
|
|
|
void ro_gui_print_prepare(struct gui_window *g) {
|
2004-08-09 10:28:57 +04:00
|
|
|
char *pdName;
|
|
|
|
bool printers_exists = true;
|
|
|
|
os_error *e;
|
|
|
|
|
|
|
|
assert(g != NULL);
|
|
|
|
|
|
|
|
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 */
|
|
|
|
e = xpdriver_info(0, 0, 0, 0, &pdName, 0, 0, 0);
|
|
|
|
if (e) {
|
|
|
|
LOG(("%s", e->errmess));
|
|
|
|
printers_exists = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_bg_images = g->option.background_images;
|
|
|
|
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_TO_BOTTOM, true);
|
|
|
|
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_SHEETS, false);
|
|
|
|
ro_gui_set_icon_integer(dialog_print, ICON_PRINT_SHEETS_VALUE, 1);
|
2004-11-05 00:13:36 +03:00
|
|
|
ro_gui_set_icon_string(dialog_print, ICON_PRINT_SHEETS_TEXT,
|
|
|
|
messages_get("PrintSheetFilled"));
|
2004-08-09 10:28:57 +04:00
|
|
|
print_update_sheets_shaded_state(true);
|
|
|
|
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_FG_IMAGES, true);
|
|
|
|
ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_FG_IMAGES, true);
|
|
|
|
|
2004-08-15 23:06:24 +04:00
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_BG_IMAGES, print_bg_images);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_IN_BACKGROUND, false);
|
|
|
|
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_UPRIGHT, true);
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_SIDEWAYS, false);
|
|
|
|
|
2004-08-19 05:01:31 +04:00
|
|
|
ro_gui_set_icon_selected_state(dialog_print, ICON_PRINT_TEXT_BLACK, false);
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
ro_gui_set_icon_integer(dialog_print, ICON_PRINT_COPIES, 1);
|
|
|
|
|
|
|
|
if (!printers_exists) {
|
|
|
|
ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_PRINT, true);
|
|
|
|
}
|
|
|
|
else {
|
2004-08-15 23:06:24 +04:00
|
|
|
ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_PRINT, false);
|
2004-08-09 10:28:57 +04:00
|
|
|
ro_gui_set_window_title(dialog_print, pdName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
void ro_gui_print_click(wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
|
|
|
if (pointer->buttons == wimp_CLICK_MENU)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (pointer->i) {
|
|
|
|
case ICON_PRINT_SHEETS:
|
|
|
|
/* retain selection state */
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print,
|
|
|
|
pointer->i, true);
|
|
|
|
print_update_sheets_shaded_state(false);
|
|
|
|
break;
|
|
|
|
case ICON_PRINT_TO_BOTTOM:
|
|
|
|
print_update_sheets_shaded_state(true);
|
|
|
|
case ICON_PRINT_UPRIGHT:
|
|
|
|
case ICON_PRINT_SIDEWAYS:
|
|
|
|
/* retain selection state */
|
|
|
|
ro_gui_set_icon_selected_state(dialog_print,
|
|
|
|
pointer->i, true);
|
|
|
|
break;
|
|
|
|
case ICON_PRINT_COPIES_UP: copies += 1; break;
|
|
|
|
case ICON_PRINT_COPIES_DOWN: copies -= 1; break;
|
|
|
|
case ICON_PRINT_SHEETS_UP: sheets += 1; break;
|
|
|
|
case ICON_PRINT_SHEETS_DOWN: sheets -= 1; break;
|
|
|
|
case ICON_PRINT_CANCEL:
|
|
|
|
print_cleanup();
|
|
|
|
break;
|
|
|
|
case ICON_PRINT_PRINT:
|
|
|
|
print_in_background = ro_gui_get_icon_selected_state(dialog_print, ICON_PRINT_IN_BACKGROUND);
|
2004-08-19 05:01:31 +04:00
|
|
|
print_text_black = ro_gui_get_icon_selected_state(dialog_print, ICON_PRINT_TEXT_BLACK);
|
2004-08-09 10:28:57 +04: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;
|
|
|
|
print_current_window->option.background_images = ro_gui_get_icon_selected_state(dialog_print, ICON_PRINT_BG_IMAGES);
|
|
|
|
print_send_printsave(print_current_window->bw->current_content);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (copies < 1)
|
|
|
|
copies = 1;
|
|
|
|
else if (copies > 99)
|
|
|
|
copies = 99;
|
|
|
|
ro_gui_set_icon_integer(dialog_print, ICON_PRINT_COPIES, copies);
|
|
|
|
|
|
|
|
if (sheets < 1)
|
|
|
|
sheets = 1;
|
|
|
|
else if (sheets > 99)
|
|
|
|
sheets = 99;
|
|
|
|
ro_gui_set_icon_integer(dialog_print, ICON_PRINT_SHEETS_VALUE, sheets);
|
|
|
|
if (sheets > 1)
|
2004-11-05 00:13:36 +03:00
|
|
|
ro_gui_set_icon_string(dialog_print, ICON_PRINT_SHEETS_TEXT,
|
|
|
|
messages_get("PrintSheetsFilled"));
|
2004-08-09 10:28:57 +04:00
|
|
|
else
|
2004-11-05 00:13:36 +03:00
|
|
|
ro_gui_set_icon_string(dialog_print, ICON_PRINT_SHEETS_TEXT,
|
|
|
|
messages_get("PrintSheetFilled"));
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle keypresses in print dialog
|
|
|
|
*
|
|
|
|
* \param key wimp_key block
|
|
|
|
* \return true if keypress dealt with, false otherwise.
|
|
|
|
*/
|
|
|
|
bool ro_gui_print_keypress(wimp_key *key)
|
|
|
|
{
|
|
|
|
switch (key->c) {
|
|
|
|
case wimp_KEY_ESCAPE:
|
|
|
|
print_cleanup();
|
|
|
|
return true;
|
|
|
|
case wimp_KEY_RETURN:
|
2004-08-11 20:26:13 +04:00
|
|
|
if (ro_gui_get_icon_shaded_state(dialog_print, ICON_PRINT_PRINT))
|
|
|
|
return true;
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
print_in_background = ro_gui_get_icon_selected_state(dialog_print, ICON_PRINT_IN_BACKGROUND);
|
2004-08-19 05:01:31 +04:00
|
|
|
print_text_black = ro_gui_get_icon_selected_state(dialog_print, ICON_PRINT_TEXT_BLACK);
|
2004-08-09 10:28:57 +04:00
|
|
|
print_num_copies = atoi(ro_gui_get_icon_string(dialog_print, ICON_PRINT_COPIES));
|
|
|
|
if (ro_gui_get_icon_selected_state(dialog_print, ICON_PRINT_SHEETS))
|
|
|
|
print_max_sheets = atoi(ro_gui_get_icon_string(dialog_print, ICON_PRINT_SHEETS_VALUE));
|
|
|
|
else
|
|
|
|
print_max_sheets = -1;
|
|
|
|
print_current_window->option.background_images = ro_gui_get_icon_selected_state(dialog_print, ICON_PRINT_BG_IMAGES);
|
|
|
|
print_send_printsave(print_current_window->bw->current_content);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set shaded state of sheets
|
|
|
|
*
|
|
|
|
* \param on whether to turn shading on or off
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a message_PRINT_SAVE
|
|
|
|
*
|
|
|
|
* \param c content to print
|
|
|
|
*/
|
|
|
|
void print_send_printsave(struct content *c)
|
|
|
|
{
|
|
|
|
wimp_full_message_data_xfer m;
|
|
|
|
os_error *e;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(c->title) + 1;
|
|
|
|
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 */
|
|
|
|
m.file_type = ro_content_filetype(c);
|
|
|
|
strncpy(m.file_name, c->title, 211);
|
|
|
|
m.file_name[211] = 0;
|
|
|
|
e = xwimp_send_message(wimp_USER_MESSAGE_RECORDED,
|
|
|
|
(wimp_message *)&m, 0);
|
|
|
|
if (e) {
|
|
|
|
LOG(("xwimp_send_message: 0x%x: %s",
|
|
|
|
e->errnum, e->errmess));
|
|
|
|
warn_user("WimpError", e->errmess);
|
|
|
|
print_cleanup();
|
|
|
|
}
|
2004-08-12 01:36:30 +04:00
|
|
|
print_prev_message = m.my_ref;
|
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
|
|
|
|
*/
|
|
|
|
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) {
|
|
|
|
LOG(("xwimp_send_message: 0x%x: %s",
|
|
|
|
e->errnum, e->errmess));
|
|
|
|
warn_user("WimpError", e->errmess);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a bounced message_PRINT_SAVE
|
|
|
|
*
|
|
|
|
* \param m the bounced message
|
|
|
|
*/
|
|
|
|
void print_save_bounce(wimp_message *m)
|
|
|
|
{
|
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) */
|
|
|
|
if (print_current_window) {
|
|
|
|
print_document(print_current_window, "printer:");
|
|
|
|
}
|
|
|
|
print_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle message_PRINT_ERROR
|
|
|
|
*
|
|
|
|
* \param m the message containing the error
|
|
|
|
*/
|
|
|
|
void print_error(wimp_message *m)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
print_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle message_PRINT_TYPE_ODD
|
|
|
|
*
|
|
|
|
* \param m the message to handle
|
|
|
|
*/
|
|
|
|
void print_type_odd(wimp_message *m)
|
|
|
|
{
|
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) */
|
|
|
|
if (print_current_window && print_send_printtypeknown(m)) {
|
|
|
|
print_document(print_current_window, "printer:");
|
|
|
|
}
|
|
|
|
print_cleanup();
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2004-08-12 01:36:30 +04:00
|
|
|
bool 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 ||
|
|
|
|
!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) {
|
|
|
|
LOG(("xpdriver_info: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("PrintError", error->errmess);
|
|
|
|
print_cleanup();
|
|
|
|
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 */
|
|
|
|
if (!print_document(print_current_window,
|
|
|
|
m->data.data_xfer.file_name)) {
|
2004-08-09 10:28:57 +04:00
|
|
|
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) {
|
|
|
|
LOG(("xwimp_send_message: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
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
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
void print_dataload_bounce(wimp_message *m)
|
|
|
|
{
|
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);
|
|
|
|
print_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleanup after printing
|
|
|
|
*/
|
|
|
|
void print_cleanup(void)
|
|
|
|
{
|
2004-08-09 21:04:32 +04:00
|
|
|
if (print_current_window)
|
|
|
|
print_current_window->option.background_images =
|
|
|
|
print_bg_images;
|
2004-08-09 10:28:57 +04:00
|
|
|
print_current_window = 0;
|
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;
|
2005-04-08 00:46:22 +04:00
|
|
|
ro_gui_menu_closed();
|
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;
|
|
|
|
int saved_width;
|
|
|
|
int yscroll = 0, sheets = print_max_sheets;
|
2004-08-09 10:28:57 +04:00
|
|
|
struct content *c = g->bw->current_content;
|
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 */
|
2004-11-04 02:27:15 +03:00
|
|
|
if (!c) {
|
|
|
|
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) {
|
|
|
|
LOG(("xpdriver_info: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
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) {
|
|
|
|
LOG(("xpdriver_page_size: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("PrintError", error->errmess);
|
|
|
|
return false;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
width = (right - left) / 800;
|
|
|
|
height = (top - bottom) / 800;
|
|
|
|
|
|
|
|
/* layout the document to the correct width */
|
2004-11-04 02:27:15 +03:00
|
|
|
saved_width = c->width;
|
2004-08-09 10:28:57 +04:00
|
|
|
if (c->type == CONTENT_HTML)
|
2005-04-09 13:47:37 +04:00
|
|
|
layout_document(c, width);
|
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) {
|
|
|
|
LOG(("xosfind_openoutw: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
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) {
|
|
|
|
LOG(("xpdriver_select_jobw: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
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 */
|
2005-03-08 03:04:57 +03:00
|
|
|
/*if (features & pdriver_FEATURE_DECLARE_FONT &&
|
2004-08-09 10:28:57 +04:00
|
|
|
c->type == CONTENT_HTML) {
|
2004-11-04 02:27:15 +03:00
|
|
|
if ((error_message = print_declare_fonts(box)))
|
2004-08-09 10:28:57 +04:00
|
|
|
goto error;
|
2005-03-08 03:04:57 +03:00
|
|
|
}*/
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
plot = ro_plotters;
|
|
|
|
ro_plot_set_scale(print_scale);
|
|
|
|
ro_gui_current_redraw_gui = g;
|
2005-04-15 09:54:44 +04:00
|
|
|
current_redraw_browser = NULL; /* we don't want to print the selection */
|
2004-11-04 02:27:15 +03:00
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
/* print is now active */
|
|
|
|
print_active = true;
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
do {
|
2004-11-04 02:27:15 +03:00
|
|
|
int clip_x0, clip_y0, clip_x1, clip_y1;
|
|
|
|
os_box b = {left / 400 - 2, bottom / 400 - 2,
|
|
|
|
right / 400 + 2, top / 400 + 2};
|
|
|
|
os_hom_trfm t = { { {65536, 0}, {0, 65536} } };
|
2004-08-09 10:28:57 +04:00
|
|
|
os_coord p = {left, bottom};
|
2004-11-04 02:27:15 +03:00
|
|
|
osbool more;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
xhourglass_percentage((int) (yscroll * 100 / c->height));
|
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) {
|
|
|
|
LOG(("xpdriver_give_rectangle: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
error_message = error->errmess;
|
2004-08-09 10:28:57 +04:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +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) {
|
|
|
|
LOG(("xpdriver_draw_page: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
error_message = error->errmess;
|
2004-08-09 10:28:57 +04:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
ro_plot_origin_x = left / 400;
|
|
|
|
ro_plot_origin_y = top / 400 + yscroll * 2;
|
2004-08-09 10:28:57 +04:00
|
|
|
|
|
|
|
while (more) {
|
2004-11-04 02:27:15 +03:00
|
|
|
LOG(("redrawing area: [(%d, %d), (%d, %d)]",
|
|
|
|
b.x0, b.y0, b.x1, b.y1));
|
|
|
|
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;
|
|
|
|
if (!content_redraw(c, 0, 0,
|
|
|
|
c->width, c->height,
|
|
|
|
clip_x0, clip_y0, clip_x1, clip_y1,
|
|
|
|
print_scale,
|
|
|
|
0xFFFFFF)) {
|
|
|
|
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) {
|
|
|
|
LOG(("xpdriver_get_rectangle: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
error_message = error->errmess;
|
2004-08-09 10:28:57 +04:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
yscroll += height;
|
|
|
|
} while (yscroll <= c->height && --sheets != 0);
|
|
|
|
|
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
|
|
|
|
|
|
|
/* clean up */
|
2004-11-04 02:27:15 +03:00
|
|
|
error = xpdriver_end_jobw(fhandle);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xpdriver_end_jobw: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
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) {
|
|
|
|
LOG(("xosfind_closew: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("PrintError", error->errmess);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_job) {
|
|
|
|
error = xpdriver_select_jobw(old_job, 0, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xpdriver_select_jobw: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
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();
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/* restore document layout */
|
|
|
|
if (c->type == CONTENT_HTML)
|
2005-04-09 13:47:37 +04:00
|
|
|
layout_document(c, saved_width);
|
2004-08-09 10:28:57 +04:00
|
|
|
|
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 */
|
|
|
|
if (c->type == CONTENT_HTML)
|
2005-04-09 13:47:37 +04:00
|
|
|
layout_document(c, saved_width);
|
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.
|
|
|
|
*
|
|
|
|
* \param box box tree being printed
|
|
|
|
* \return 0 on success, error message on error
|
|
|
|
*/
|
|
|
|
|
|
|
|
const char *print_declare_fonts(struct box *box)
|
|
|
|
{
|
|
|
|
struct print_font *print_fonts = calloc(255, sizeof (*print_fonts));
|
|
|
|
unsigned int font_count = 0, i;
|
|
|
|
const char *error_message = 0;
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
if (!print_fonts)
|
|
|
|
return messages_get("NoMemory");
|
|
|
|
|
|
|
|
if (!print_find_fonts(box, &print_fonts, &font_count)) {
|
|
|
|
LOG(("print_find_fonts() failed"));
|
|
|
|
error_message = "print_find_fonts() failed";
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i != font_count; ++i) {
|
|
|
|
error = xpdriver_declare_font(print_fonts[i].handle,
|
|
|
|
print_fonts[i].font_name, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xpdriver_declare_font: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
error_message = error->errmess;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = xpdriver_declare_font(0, 0, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xpdriver_declare_font: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
error_message = error->errmess;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
for (i = 0; i != font_count; i++)
|
|
|
|
free(print_fonts[i].font_name);
|
|
|
|
free(print_fonts);
|
|
|
|
|
|
|
|
return error_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
/**
|
|
|
|
* Find all fonts in a document
|
|
|
|
*
|
|
|
|
* \param box Root of box tree
|
|
|
|
* \param print_fonts pointer to array of fonts in document
|
2004-11-04 02:27:15 +03:00
|
|
|
* \paran font_count number of fonts declared
|
2004-08-09 10:28:57 +04:00
|
|
|
* \return true on success, false otherwise
|
|
|
|
*/
|
2004-11-04 02:27:15 +03:00
|
|
|
bool print_find_fonts(struct box *box, struct print_font **print_fonts, int *font_count)
|
2004-08-09 10:28:57 +04:00
|
|
|
{
|
|
|
|
struct box *a;
|
|
|
|
const char *txt;
|
2004-08-14 16:57:02 +04:00
|
|
|
size_t txt_len;
|
|
|
|
size_t width, rolength, consumed;
|
2004-08-09 10:28:57 +04:00
|
|
|
const char *rofontname, *rotext;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(box);
|
2005-02-20 16:19:19 +03:00
|
|
|
#if 0
|
2004-08-09 10:28:57 +04:00
|
|
|
if (box->text && box->font && box->length > 0) {
|
|
|
|
txt = box->text;
|
|
|
|
txt_len = box->length;
|
|
|
|
|
|
|
|
if (box->font->ftype == FONTTYPE_UFONT) {
|
|
|
|
/** \todo handle ufont */
|
|
|
|
LOG(("ufont"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsfont_txtenum(box->font, txt, txt_len,
|
|
|
|
&width, &rofontname,
|
|
|
|
&rotext, &rolength,
|
|
|
|
&consumed);
|
|
|
|
|
|
|
|
if (rotext == NULL) {
|
|
|
|
LOG(("rotext = null (%d)", txt_len));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
for (i = 0; i != *font_count; ++i) {
|
|
|
|
if (!strcmp(((*print_fonts)[i]).font_name, rofontname))
|
2004-08-09 10:28:57 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-11-04 02:27:15 +03:00
|
|
|
if (i == *font_count) {
|
2004-08-09 10:28:57 +04:00
|
|
|
/* max 255 fonts (as per draw) */
|
2004-11-04 02:27:15 +03:00
|
|
|
if (*font_count == 255)
|
2004-08-09 10:28:57 +04:00
|
|
|
return false;
|
2004-11-04 02:27:15 +03:00
|
|
|
if ((((*print_fonts)[*font_count]).font_name = strdup(rofontname)) == NULL) {
|
2004-08-09 10:28:57 +04:00
|
|
|
LOG(("failed to strdup (%s)", rofontname));
|
|
|
|
return false;
|
|
|
|
}
|
2004-11-04 02:27:15 +03:00
|
|
|
((*print_fonts)[(*font_count)++]).handle = (font_f)box->font->handle;
|
2004-08-09 10:28:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free((void*)rotext);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (a = box->children; a; a = a->next) {
|
2004-11-04 02:27:15 +03:00
|
|
|
if (!print_find_fonts(a, print_fonts, font_count))
|
2004-08-09 10:28:57 +04:00
|
|
|
return false;
|
|
|
|
}
|
2005-02-20 16:19:19 +03:00
|
|
|
#endif
|
2004-08-09 10:28:57 +04:00
|
|
|
return true;
|
|
|
|
}
|
2004-08-11 20:26:13 +04:00
|
|
|
|
2004-08-09 10:28:57 +04:00
|
|
|
#endif
|