Beispiel #1
0
/**
 * Begin pdf plotting - initialize a new document
 * \param path Output file path
 * \param pg_width page width
 * \param pg_height page height
 */
bool pdf_begin(struct print_settings *print_settings)
{
	pdfw_gs_init();

	if (pdf_doc != NULL)
		HPDF_Free(pdf_doc);
	pdf_doc = HPDF_New(error_handler, NULL);
	if (!pdf_doc) {
		NSLOG(netsurf, INFO, "Error creating pdf_doc");
		return false;
	}

	settings = print_settings;

	page_width = settings->page_width -
			FIXTOFLT(FSUB(settings->margins[MARGINLEFT],
			settings->margins[MARGINRIGHT]));

	page_height = settings->page_height -
			FIXTOFLT(settings->margins[MARGINTOP]);


#ifndef PDF_DEBUG
	if (option_enable_PDF_compression)
		HPDF_SetCompressionMode(pdf_doc, HPDF_COMP_ALL); /*Compression on*/
#endif
	HPDF_SetInfoAttr(pdf_doc, HPDF_INFO_CREATOR, user_agent_string());

	pdf_page = NULL;

#ifdef PDF_DEBUG
	NSLOG(netsurf, INFO, "pdf_begin finishes");
#endif
	return true;
}
Beispiel #2
0
/**
 * The content is resized to fit page width.
 *
 * \param content The content to be printed
 * \param settings The settings for printing to use
 * \return true if successful, false otherwise
 */
bool print_apply_settings(hlcache_handle *content,
			  struct print_settings *settings)
{
	if (settings == NULL)
		return false;
	
	/* Apply settings - adjust page size etc */

	page_content_width = (settings->page_width - 
			FIXTOFLT(FSUB(settings->margins[MARGINLEFT],
			settings->margins[MARGINRIGHT]))) / settings->scale;
	
	page_content_height = (settings->page_height - 
			FIXTOFLT(FSUB(settings->margins[MARGINTOP],
			settings->margins[MARGINBOTTOM]))) / settings->scale;
	
	content_reformat(content, false, page_content_width, 0);

	LOG("New layout applied.New height = %d ; New width = %d ", content_get_height(content), content_get_width(content));
	
	return true;
}
Beispiel #3
0
bool pdf_next_page(void)
{
#ifdef PDF_DEBUG
	NSLOG(netsurf, INFO, "pdf_next_page begins");
#endif
	clip_update_needed = false;
	if (pdf_page != NULL) {
		apply_clip_and_mode(false, NS_TRANSPARENT, NS_TRANSPARENT, 0.,
				DashPattern_eNone);
		pdfw_gs_restore(pdf_page);
	}

#ifdef PDF_DEBUG_DUMPGRID
	if (pdf_page != NULL) {
		pdf_plot_grid(10, 10, 0xCCCCCC);
		pdf_plot_grid(100, 100, 0xCCCCFF);
	}
#endif
	pdf_page = HPDF_AddPage(pdf_doc);
	if (pdf_page == NULL)
		return false;

	HPDF_Page_SetWidth (pdf_page, settings->page_width);
	HPDF_Page_SetHeight(pdf_page, settings->page_height);

	HPDF_Page_Concat(pdf_page, 1, 0, 0, 1,
			FIXTOFLT(settings->margins[MARGINLEFT]), 0);

	pdfw_gs_save(pdf_page);

#ifdef PDF_DEBUG
	NSLOG(netsurf, INFO, "%f %f", page_width, page_height);
#endif

	return true;
}
Beispiel #4
0
/**
 * Initialize GTK interface.
 */
static void gui_init(int argc, char** argv, char **respath)
{
	char buf[PATH_MAX];
	const char *addr = NETSURF_HOMEPAGE;
	char *resource_filename;

	/* check user options */
	check_options(respath);

	/* find the languages file */	
	languages_file_location = filepath_find(respath, "languages");
	if ((languages_file_location == NULL) || 
	    (strlen(languages_file_location) < 10)) {
		die("Unable to find resources.\n");		
	}

	/* Obtain resources path location. 
	 *
	 * Uses the directory the languages file was found in,
	 * @todo find and slaughter all references to this!
	 */
	res_dir_location = calloc(1, strlen(languages_file_location) - 8);
	memcpy(res_dir_location, 
	       languages_file_location, 
	       strlen(languages_file_location) - 9);
	LOG(("Using '%s' for resource path", res_dir_location));

	/* initialise the glade templates */
	nsgtk_init_glade(respath);

	/* set default icon if its available */
	resource_filename = filepath_find(respath, "netsurf.xpm");
	if (resource_filename != NULL) {
		gtk_window_set_default_icon_from_file(resource_filename, NULL);
		free(resource_filename);
	}

	/* Search engine sources */
	search_engines_file_location = filepath_find(respath, "SearchEngines");
	LOG(("Using '%s' as Search Engines file", search_engines_file_location));

	/* Default Icon */
	search_default_ico_location = filepath_find(respath, "default.ico");
	LOG(("Using '%s' as default search ico", search_default_ico_location));

	/* Default favicon */
	resource_filename = filepath_find(respath, "favicon.png");
	if (resource_filename != NULL) {
		favicon_pixbuf = gdk_pixbuf_new_from_file(resource_filename, NULL);
		free(resource_filename);
		if (favicon_pixbuf == NULL) {
			favicon_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16,16);
			
		}
	}

	/* Toolbar inicies file */
	toolbar_indices_file_location = filepath_find(respath, "toolbarIndices");
	LOG(("Using '%s' as custom toolbar settings file", toolbar_indices_file_location));

        /* load throbber images */
	if (nsgtk_throbber_init(respath, THROBBER_FRAMES) == false)
		die("Unable to load throbber image.\n");

	/* Initialise completions - cannot fail */
	nsgtk_completion_init();

	filepath_sfinddef(respath, buf, "mime.types", "/etc/");
	gtk_fetch_filetype_init(buf);

	urldb_load(nsoption_charp(url_file));
	urldb_load_cookies(nsoption_charp(cookie_file));

	/* The tree view system needs to know the screen's DPI, so we
	 * find that out here, rather than when we create a first browser
	 * window.
	 */

	nscss_screen_dpi = FLTTOFIX(gdk_screen_get_resolution(
					    gdk_screen_get_default()));
	LOG(("Set CSS DPI to %f", FIXTOFLT(nscss_screen_dpi)));

	if (nsgtk_history_init(glade_file_location->history) == false)
		die("Unable to initialise history window.\n");

	if (nsgtk_download_init(glade_file_location->downloads) == false)
		die("Unable to initialise download window.\n");

	if (nsgtk_cookies_init(glade_file_location->cookies) == false)
		die("Unable to initialise cookies window.\n");

	if (nsgtk_hotlist_init(glade_file_location->hotlist) == false)
		die("Unable to initialise hotlist window.\n");

	sslcert_init(tree_content_icon_name);

        if (nsoption_charp(homepage_url) != NULL) {
                addr = nsoption_charp(homepage_url);
	}

	if (2 <= argc)
		addr = argv[1];

        /* Last step of initialization. Opens the main browser window. */
	browser_window_create(addr, 0, 0, true, false);
}