class MyPrintOperation
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)
Attributes
caller_object[RW]
current_row[RW]
is_test[RW]
moditemid[RW]
myrows[R]
page_setup[RW]
pages[RW]
paper_height[R]
paper_width[R]
parentselected[RW]
Public Class Methods
new(caller_object,moditemid,ids_to_print=nil)
click to toggle source
Calls superclass method
# File lib/Print.rb, line 9 def initialize(caller_object,moditemid,ids_to_print=nil) @parentselected=nil @is_test=ids_to_print.nil? @caller_object=caller_object @ids_to_print=ids_to_print case caller_object.class.name when 'MyEditableList' then @parentselected=caller_object.get_cursor_id when 'WysiwygPrintEditor' else edebug("unknown routing: "+caller_object.class.name,"printing","error") end @moditemid=moditemid if is_test? @moditem=qrow("select moditems.*,gtkprintpages.*,queries.sql from moditems left join queries on moditems.query_sql_id = queries.id left join gtkprintpages on moditems.id = gtkprintpages.moditem_id where moditems.id='#{@moditemid}'") else @moditem=admin.qrow("select moditems.*,gtkprintpages.*,queries.sql from moditems left join queries on moditems.query_sql_id = queries.id left join gtkprintpages on moditems.id = gtkprintpages.moditem_id where moditems.id='#{@moditemid}'") end super() set_show_progress(true) set_use_full_page(false) set_unit(Gtk::PaperSize::UNIT_POINTS) set_default_page_setup(Gtk::PageSetup.new) default_page_setup.paper_size=Gtk::PaperSize.new(@moditem["paper_size_name"]) default_page_setup.orientation=case @moditem["orientation"] when "portrait" then Gtk::PrintSettings::PageOrientation::PORTRAIT when "reverse_portrait" then Gtk::PrintSettings::PageOrientation::REVERSE_PORTRAIT when "landscape" then Gtk::PrintSettings::PageOrientation::LANDSCAPE when "reverse_landscape" then Gtk::PrintSettings::PageOrientation::REVERSE_LANDSCAPE else Gtk::PrintSettings::PageOrientation::PORTRAIT end default_page_setup.set_left_margin(@moditem["left_margin"].to_f,Gtk::PaperSize::UNIT_MM) if !@moditem["left_margin"].nil? default_page_setup.set_right_margin(@moditem["right_margin"].to_f,Gtk::PaperSize::UNIT_MM) if !@moditem["right_margin"].nil? default_page_setup.set_top_margin(@moditem["top_margin"].to_f,Gtk::PaperSize::UNIT_MM) if !@moditem["top_margin"].nil? default_page_setup.set_bottom_margin(@moditem["bottom_margin"].to_f,Gtk::PaperSize::UNIT_MM) if !@moditem["bottom_margin"].nil? signal_connect("begin-print") { |pop, context| edebug("begin print","printing","info") cr = context.cairo_context # page_height=pop.default_page_setup.get_page_height(Gtk::PaperSize::UNIT_POINTS) # paper_height=pop.default_page_setup.get_paper_height(Gtk::PaperSize::UNIT_POINTS) @paper_height = context.page_setup.get_page_height(Gtk::PaperSize::UNIT_POINTS).to_f @paper_width = context.page_setup.get_page_width(Gtk::PaperSize::UNIT_POINTS).to_f @item_res=if is_test? then query("select * from gtkprintitems where printid='#{@moditemid}' order by page_number,y") else item_res=admin.query("select * from gtkprintitems where printid='#{@moditemid}' order by page_number,y") end @items_data=Array.new while itemdata=@item_res.fetch_hash() @items_data.push(itemdata.rehash) end @items_data_iter=nil @items=Array.new @sql=@moditem["sql"] @sql=@moditem["querysql"] if @moditem["querysql"].length>5 if is_test? @sql="#{@sql} limit 1" myres=client.query(@sql) else myres=query(add_where(@sql,"#{guess_base(@sql)}.id in (#{@ids_to_print})")) end @myrows=Hash.new @row_num=0 while myrow=myres.fetch_hash(true) @row_num+=1 @myrows[@row_num]=myrow.rehash end # set_n_pages(@myrows.size*@pages.size) @page_n=0 @current_row=1 @current_page=0 @page_shift=0 @sublist_start_iter=nil pop.set_n_pages(@page_n) } signal_connect('paginate'){|pop,context| cr=context.cairo_context #start iterating PrintItems here @items_data_iter=@items_data.first if @items_data_iter.nil? if @items_data.include?(@items_data_iter) @items.push(i=PrintItem.new(self,@items_data_iter,cr)) #start the broken sublist at top of page i.set_height(i.y+i.height).set_y(0) if @prev_extended and i.type?("list") i.set_txt(text_from_mysql(@myrows[current_row],@items_data_iter["txt"])). set_page_shift(@page_shift). set_start_iter(@sublist_start_iter). update #making sure page_n is max(i.page) @page_n=i.page if @page_n<i.page einfo("paginated: #{i}","printing") #list continuation @sublist_start_iter=i.next_iter @prev_extended=i.extended? end if @sublist_start_iter or i.extended? #we continue on next page @page_shift+=1 einfo("sublist forced page_shift: #{@page_shift}","printing") end unless @sublist_start_iter #iterate through the raw data if @items_data_iter=@items_data[@items_data.index(@items_data_iter)+1] false else if @current_row<@row_num #next mysql row @current_row+=1 @items_data_iter=@items_data.first @page_shift=@page_n+1 einfo("page_shift: #{@page_shift}","printing") false else #finish, setting n_pages pop.set_n_pages(@page_n+1) edebug("finished paginating at #{pop.n_pages}","printing") true end end end } signal_connect('draw-page'){|pop,context,page_number| einfo("drawing page #{page_number+1}/#{pop.n_pages})","printing") cr = context.cairo_context @items.each{|item| cr.set_line_width(1) item.draw(cr) if item.page?(page_number) and !item.type?('image') } #workaround for the not printing text after an image in .ps @items.each{|item| edebug("drawing item #{item}","printing") item.draw(cr) if item.page?(page_number) and item.type?('image') } } self end
Public Instance Methods
is_test?()
click to toggle source
# File lib/Print.rb, line 196 def is_test? @is_test end
run(action)
click to toggle source
Calls superclass method
# File lib/Print.rb, line 155 def run(action) #set_n_pages(pages["page_count"].to_i) # set_default_page_setup(page_setup) self.print_settings=Gtk::PrintSettings.new.deserialize(get_conf(moditemid,0,'print_settings')) run_events(@moditemid,'print-Action') super(action,caller_object.get_ancestor(Gtk::Window)) set_conf(moditemid,0,'print_settings',print_settings.serialize) end
text_from_mysql(mydata,nt=text)
click to toggle source
# File lib/Print.rb, line 164 def text_from_mysql(mydata,nt=text) found=false rett="" while first=nt.index("{") found=true rett=rett+nt[0 .. first-1] if first-1>=0 if last=nt[first .. nt.length].index("}") last=last+first datak=nt[first+1 .. last-1] if mydata.has_key?(datak) rett=rett+mydata[datak].to_s nt=nt[last+1 .. nt.length] else rett=rett+datak nt=nt[last+1 .. nt.length] end#if else nt=nt[first+1 .. nt.length] rett=rett+"{"+nt end#if end if found rett=rett+nt[1 .. nt.length] if nt.length>=1 else rett=rett+nt if !nt.nil? end rett end
to_s()
click to toggle source
# File lib/Print.rb, line 193 def to_s "<MyPrintOperation:#{@moditem["display"]}>" end