Re: wxPrinting

new topic     » goto parent     » topic index » view thread      » older message » newer message

Ops, it seams that was not a problem with PrintPreview but it was a problem with wxGrid ( I gets data for printing from it ). There is an example of code for Printing with preview (my proc PrintGridWithPreviw), its working wery well ( I used wxEuphoria ver. 9.1 ) :

atom printobject 
integer linetopage 
sequence sepcols, title, data, colors 
constant LINEH = 0.2 
 
linetopage = 80 
sepcols = {} 
 
procedure GetPagesPerPage (atom printout) 
 sequence factor, ppi, pps, ppx 
 atom csize, x 
 integer lp, cfrom, cto, size 
 	sepcols = {} 
 	ppi = get_ppi_printer (printout) 
 	pps = get_ppi_screen (printout) 
 	ppx = get_page_pixels (printout) 
 	size = length (data [1]) 
 	cfrom = 1 
	cto = size 
 	if not pps [1] then 
 		sepcols = append (sepcols, {cfrom, cto}) 
 		return 
 	end if 
	x = 0 
	for j = 1 to size do 
		csize = get_col_size (printobject, j - 1) / pps [1] * 1.2 
		x += csize 
		if x >= ppx [1] / ppi [1] then 
			sepcols = append (sepcols, {cfrom, j - 1}) 
			cfrom = j 
			x = 0 
		end if 
	end for 
	if cfrom < size then 
		sepcols = append (sepcols, {cfrom, size}) 
	end if 
end procedure 
 
procedure GetPages (atom printout) 
 integer rsize, pages, size 
 sequence ppx, ppi 
 atom pix 
  	ppi = get_ppi_printer (printout) 
	pix = ppi [2] * LINEH 
	ppx = get_page_pixels (printout) 
	linetopage = floor (ppx [2] / pix) - 1 
	size = length (data) 
	pages = floor (size / linetopage) + 1 
	pages *= length (sepcols) 
	set_page_info (printout, 1, pages) 
end procedure 
 
procedure do_pages_grid (atom printout, atom dc) 
	GetPagesPerPage (printout) 
	GetPages (printout) 
end procedure 
 
function do_print_grid (atom this, atom page, atom dc) 
 sequence factor, ppi, size, pps, ppx 
 atom csize, x, y, tr, tc 
 integer lp, cpage, cfrom, cto, rfrom, rto 
 	ppi = get_ppi_printer (this) 
 	pps = get_ppi_screen (this) 
 	ppx = get_page_pixels (this) 
	if is_preview (this) then 
		factor = get_dc_size (dc) / ppx 
		set_user_scale (dc, factor [1], factor [2]) 
	else 
		set_user_scale (dc, 1, 1) 
	end if 
	tr = length (data) 
	tc = length (data [1]) 
	if length (sepcols) < 2 then 
		rfrom = 2 
	else 
		rfrom = floor ((page - 1) / (length (sepcols))) * linetopage + 2 
	end if 
	rto = rfrom + linetopage 
	if rto > tr then rto = tr end if 
 
	if page >= length (sepcols) then 
		cpage = length (sepcols) 
	else 
		cpage = page 
	end if 
	cfrom = sepcols [cpage][1] 
	cto = sepcols [cpage][2] 
 
--? {page, cpage, cfrom, cto} 
	y = 0 
	x = 0 
	wx_printf ({0, 0, 0, dc}, "Strana %d, %s", {page, title}) 
	y += LINEH 
	for j = cfrom to cto do 
		csize = get_col_size (printobject, j - 1) / pps [1] * 1.2 
		set_text_color (dc, colors [1][j]) 
		wx_puts (0 & ppi * {x, y} & dc, data [1][j]) 
		x += csize 
	end for 
	for r = rfrom to rto do 
		x = 0 
		y += LINEH 
		for c = cfrom to cto do 
			csize = get_col_size (printobject, c - 1) / pps [1] * 1.2 
			set_text_color (dc, colors [r][c]) 
			wx_puts (0 & ppi * {x, y} & dc, data [r][c]) 
			x += csize 
		end for 
	end for 
 	return 1 
end function 
 
global procedure PrintGrid (sequence name, atom grid, sequence n, sequence d, sequence c) 
 integer pages 
 sequence size 
 atom printer, printout 
  	title = n 
  	data = d 
  	colors = c 
  	printobject = grid 
 	size = grid_size (printobject) 
	pages = floor (size [1] / linetopage) + 1 
	sepcols = {{0, size [2] - 1}} 
	pages *= length (sepcols) 
	printer = create (wxPrinter, 0) 
	printout = create (wxPrintout, {name, routine_id ("do_print_grid"), -1, {1, pages}}) 
	tmp = start_print (printer, Vizio32MainWindow, printout, 1) 
	delete_instance (printout) 
	delete_instance (printer) 
end procedure 
 
global procedure PrintPreviewGrid (sequence name, atom grid, sequence n, sequence d, sequence c) 
 atom preview, printout, pframe 
 	title = n 
  	data = d 
  	colors = c 
  	printobject = grid 
	printout = create (wxPrintout, {name, routine_id ("do_print_grid"), routine_id ("do_pages_grid"), {1,1}}) 
	preview = create (wxPrintPreview, printout) 
	if preview then 
		pframe = get_preview_frame (preview) 
		show_window (pframe, 1) 
	else 
		destroy (printout) 
	end if 
end procedure 
 
global procedure PrintGridWithPreviw (sequence name, atom grid, sequence n, sequence d, sequence c) 
 atom printout1, printout, preview, pframe 
  	title = n 
  	data = d 
  	colors = c 
  	printobject = grid 
	printout = create (wxPrintout, {name, routine_id ("do_print_grid"), routine_id ("do_pages_grid"), {1,1}}) 
	preview = create (wxPrintPreview, {printout, printout}) 
	if preview then 
		pframe = get_preview_frame (preview) 
		set_title (pframe, "Náhled tisku") 
		show_window (pframe, 1) 
	else 
		destroy (printout) 
	end if 
end procedure 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu