Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-16 Thread Eric Cashon via gtk-app-devel-list

 Hi Attila,

The text buffer does return the correct number of chars with spaces. If I get a 
char count on the lines with or without numbers it returns the correct number. 
When I export to PDF the layout is the same as the print preview. When I test 
with pdftotext then, as you say, it doesn't maintain the correct layout. 
Looking at pdftotext --help, the website is given.

The Poppler Developers - http://poppler.freedesktop.org  

They do have a mailing list to contact the developers. Have you asked them 
about it? Maybe it is something that they can fix or have a solution for. 

The other option is if the text output is consistent from pdftotext then you 
could parse the text and format it correctly before importing into a new 
program. 

Eric 

Test char count.
...
#Get the lines of text to put on the page.
cr.set_source_rgb(0.0, 0.0, 0.0)
line_offset = page_number * self.lines_per_page
start = self.textbuffer.get_iter_at_line(line_offset)
end = self.textbuffer.get_iter_at_line(line_offset + self.lines_per_page - 
1)
#Test how far end of line is.
print("Line chars " + str(end.get_chars_in_line()))
end.forward_to_line_end()
...

 


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-15 Thread Hammer Attila

Hi Eric,

This test code me works correctly too if keeping the line numbers each 
blank lines.
If have a number before a simple \n line, the correct line positioning 
happening when I trying convert back the generated pdf file with 
pdftotext -layout command.
The last line of the first page right positioned the 28TH line (line 
number is real 28 in the txt file), but before the 1 number have only 7 
space characters, not 32 space characters.


If I remove the line numbers before the \n characters, the first page 
last line again not right positioned the txt file when I ran the 
pdftotext -layout pdf file command (real line number now 6, and before 
the 1 number have 9 space characters, not 32).
I tried replacing the blank lines with simple space characters, but this 
is not help of course.


Attila
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-15 Thread Eric Cashon via gtk-app-devel-list

 

OK, you got me on the PDF. I don't know about that. I think a monospace font 
will help though because they are easier to keep track of rows and columns 
since all the characters are in the same sized rectangle. The Marburg font is 
also in a constant sized rectangle. I don't know how to put together a layout 
with the two  different fonts sized correctly but I am sure it can be done to 
fit on a A4 page and have everything work correctly. 

This is my latest try at it. It has the A4 page size with a monospace font that 
will fit at 28 rows per page. Maybe it is a step in the right direction.

Eric

#!/usr/bin/env python3

#Needed for cairo context: sudo apt-get install python-gi-cairo
#Tested on Ubuntu16.04 with GTK3.18 and Python3.

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GtkSource', '3.0')
gi.require_version('PangoCairo', '1.0')
from gi.repository import Gtk, GtkSource, PangoCairo, Pango
import math

class TextBox(GtkSource.View):
def __init__(self, win):
GtkSource.View.__init__(self)
self.parent_win = win
self.page_width = 0
self.page_height = 0
self.lines = 0
self.font_width = 0
self.font_height = 0
self.lines_per_page = 0
self.set_wrap_mode(1)
self.set_cursor_visible(True)
self.set_vexpand(True);
self.set_hexpand(True);
self.textbuffer = self.get_buffer() 
self.textbuffer.set_text("1 
alma\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28
 1\n1 
alma2\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28
 1")

def print_dialog(self):
operation = Gtk.PrintOperation()
page_setup = Gtk.PageSetup()
#Try the A4 paper size. 
paper_size = Gtk.PaperSize("iso_a4")
page_setup.set_paper_size(paper_size)
operation.set_default_page_setup(page_setup)
operation.connect("begin_print", self.begin_print)
operation.connect("draw_page", self.draw_page)
result = operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, 
self.parent_win)

def begin_print(self, operation, gtk_context):
self.page_width = gtk_context.get_width()
self.page_height = gtk_context.get_height()
pango_context = self.get_pango_context()
description = pango_context.get_font_description()
#Set a monospace font. Easier for figuring out layouts.
new_font = Pango.FontDescription("Monospace 24")
self.pango_layout = gtk_context.create_pango_layout()
self.pango_layout.set_font_description(new_font)
self.pango_layout.set_width(int(self.page_width*Pango.SCALE));
self.pango_layout.set_wrap(Pango.WrapMode.CHAR)

#Get font width and height for a monospace font.
self.pango_layout.set_markup("5")
rectangle_ink, rectangle_log = self.pango_layout.get_extents()
self.font_width = rectangle_log.width/Pango.SCALE
self.font_height = rectangle_log.height/Pango.SCALE

#Calculate lines per page. 28 lines of monspace 24 font fit on a A4 one 
page. 
self.lines = self.textbuffer.get_line_count() 
self.lines_per_page = int(self.page_height / self.font_height)
operation.set_n_pages(math.ceil(self.lines / self.lines_per_page))

def draw_page(self, operation, gtk_context, page_number):
cr = gtk_context.get_cairo_context()
   
#Draw rectangles around monospaced text.
cr.set_source_rgb(1.0, 0.0, 1.0)
cr.set_line_width(1)
for x in range(28): 
for y in range(32):
cr.rectangle(y * self.font_width, x * self.font_height, 
self.font_width, self.font_height)
cr.stroke()

#Page border rectangle.
cr.set_source_rgb(0.0, 0.0, 1.0)
cr.set_line_width(2)
cr.rectangle(0, 0, self.page_width, self.page_height)
cr.stroke()
  
#Get the lines of text to put on the page.
cr.set_source_rgb(0.0, 0.0, 0.0)
line_offset = page_number * self.lines_per_page
start = self.textbuffer.get_iter_at_line(line_offset)
end = self.textbuffer.get_iter_at_line(line_offset + 
self.lines_per_page - 1)
end.forward_to_line_end()
string = self.textbuffer.get_text(start, end, False)
self.pango_layout.set_markup(string)
PangoCairo.show_layout(cr, self.pango_layout)

class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("Print")
self.set_default_size(300,700)
self.TextBox1 = TextBox(self)
self.scrolledwindow = Gtk.ScrolledWindow()
self.scrolledwindow.add(self.TextBox1)
self.button1 = Gtk.Button("Print Dialog")
self.button1.connect("clicked", self.print_dialog)
self.grid = Gtk.Grid()
self.gri

Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-15 Thread Hammer Attila

Hi,

I think the last post described exactly what the problem.
I using the pdftotext test only because me not have a Braille printer 
hardware, and any way need verifying the real printed output with equals 
exactly the LiblouisUTDML file2brl command generated formatted text 
braille output file when the printing real happening, character to 
character.


Me have a visual printer, but this verification is not possible, because 
I am a blind person.


With Braille printers insensitive the visual lookup the input text, only 
important when the draw_page function sends the printed output to the 
user selected Braille printer, the already generated text formattings is 
not lost during page drawing (space characters doed indentations, blank 
lines when more blank lines have a page, etc).


In the begin-print signal possible calculating how many Braille pages 
fit the document, simple need divmod the document line numbers with 
lines/page property.


For example, if a document have 29 braille lines, and lines/page 
property is 28 lines, need generating two pages in the begin-print 
signal function the operation.set_n_pages(2) function call.

Me this calculation always estimated right the braille pages count.

Possible in the draving operation need moving the pen the next line if 
have a blank line? If the text more blank lines, possible doing more 
move operations only to move the real paper with the correct position 
when the printing happening a real hardware?


When page draving is happening, Not possible need processing the page 
layout content with layoutLine to layoutLine object, and if the 
layoutLine object text is blank, need moving the pen the next line left 
margin position to resulting a real blank line before the next paragraph?
Left, top, bottom and right margin positions possible querying the 
print_context.get_page_setup() sub functions.


I begin thinking with Pango Layout or CairoContext.show_layout function 
insensitive the \n\n\n\n formatting style text.


When you need drawing a blank line a page, what need you doing the 
draw_page signal?


I not full understanding the line and character positions calculations 
when I need give exactly a line number and a column position coordinates.


Attila
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-15 Thread Yuri Khan
On Sun, Oct 15, 2017 at 1:42 AM, Eric Cashon via gtk-app-devel-list
 wrote:

> The first thing that I would try out is to change the font that is being 
> drawn to see if that works.

I am getting an impression that fonts are not going to make any
difference. The OP seems not interested in how the PDF *looks* at all;
rather, what it *means*.

Disclaimer: I am not an expert on the PDF format so the below may not
be completely accurate. Take it as a simplified description.

Disclaimer #2: I have not verified the original claim of what appears on output.


A PDF page is, essentially, a list of instructions of the form “at
position (X, Y), using the font F, render the string S”.

On input, the OP is feeding a text file with lots of blank lines and
spaces used for layout.

On output, the PDF seems to only contain instructions to render the
non-blank lines. pdftotext(1) without the -layout option simply
outputs the text from the instructions present in the PDF.

(pdftotext -layout interprets the instructions and attempts to
reconstruct page layout based on positions.)

For a sighted person, there is no difference in appearance between this PDF:

At 0 inches down, 0 inches across, render "alma"
At 4.667 inches down, 3.1 inches across, render "1"

and this PDF:

At 0 inches down, 0 inches across, render "alma"
At 0.167 inches down, 0 inches across, render ""
At 0.333 inches down, 0 inches across, render ""
…
At 4.5 inches down, 0 inches across render, ""
At 4.667 inches down, 0 inches across render "<31 spaces>1"

For a blind user and/or a third-party tool aimed at blind users, there
seems to be.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-14 Thread Eric Cashon via gtk-app-devel-list

 
Here is something else that might help. Try a monospace font to test with. If 
you use a monospace font then your spacing should be kept correct. If I draw a 
grid around the characters, monospace will hold the spacing to the 28x32 grid.

Eric

...
new_font = Pango.FontDescription("Monospace 20")
...
def draw_page(self, operation, gtk_context, page_number):
cr = gtk_context.get_cairo_context()

#Get rectangle for one monospace char for sizing.
self.pango_layout.set_markup("5")
rectangle_ink, rectangle_log = self.pango_layout.get_extents()
   
#Draw rectangles around monospaced text.
cr.set_source_rgb(1.0, 0.0, 1.0)
cr.set_line_width(1)
font_width = rectangle_log.width/Pango.SCALE
font_height = rectangle_log.height/Pango.SCALE
for x in range(28): 
for y in range(32):
cr.rectangle(y * font_width, x * font_height, font_width, 
font_height)
cr.stroke()
  
#Show Text.
cr.set_source_rgb(0.0, 0.0, 0.0)
start = self.textbuffer.get_start_iter()
end = self.textbuffer.get_end_iter()
string = self.textbuffer.get_text(start, end, False)
self.pango_layout.set_markup(string)
PangoCairo.show_layout(cr, self.pango_layout)

 


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-14 Thread Eric Cashon via gtk-app-devel-list

 
Hi Attila,

I don't know the internals of how Pango deals with the different fonts for 
putting them on a layout. I have bumped into utf8_casefold() and 
utf8_normalize() before so I know fonts can get complicated. Maybe someone with 
more knowledge than I have about this can help. The first thing that I would 
try out is to change the font that is being drawn to see if that works. Maybe 
you can get a font that Pango will draw correctly so that it can be converted 
from txt to pdf and back again. Have you tested a few different fonts to see if 
they do the same thing? Something like the following. I am doing some guessing 
here.

Eric

...
def begin_print(self, operation, gtk_context):
self.page_width = gtk_context.get_width()
self.page_height = gtk_context.get_height()
pango_context = self.get_pango_context()
description = pango_context.get_font_description()
font = description.to_string()
print(font)
#Test some fonts.
new_font = Pango.FontDescription("Arial 20")
self.pango_layout = gtk_context.create_pango_layout()
self.pango_layout.set_font_description(new_font)
self.pango_layout.set_width(int(self.page_width*Pango.SCALE));
self.pango_layout.set_wrap(Pango.WrapMode.CHAR)
...

 


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-14 Thread Hammer Attila

Hi,

I forgot to attach Marburg medium standard specification link:
http://webcache.googleusercontent.com/search?q=cache:g7kWlTjQ24YJ:https://www.pharmabraille.com/pharmaceutical-braille/marburg-medium-font-standard/%2Bmarburg%2Bmedium%2Bstandard&client=ubuntu&hs=ZxJ&channel=fs&dcr=0&hl=hu&ct=clnk

Attila
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-14 Thread Hammer Attila

Hi Eric,

Unfortunatelly I only possible testing the printed PDF output with 
pdftotext command and Orca screen reader, because I entire not seeing 
the screen.

I looked the test program generated pdf output.
When I converted the test file with pdftotext test.pdf -layout command, 
the .txt file I seeing following output:

"alma




   1"

When I converting without the --layout switch, I seeing following output:
"alma

1"

For example, an a4 paper size braille output fit only 28 lines, and the 
maximum line length is 32 characters.
The hungarian user future possible setting smaller maximum line numbers 
in the application.


If an user printing future the yesterday attached text with a Braille 
printer, the page format need looking following if the maximum 
lines/page length is 28 lines:
The first line before the alma word need have two spaces. Usual, in 
hungarian braille the paragraphs first line always need indenting with 
two spaces.
When have a title with a Braille document, the title texts is indented 
with more spaces.


After this, the next 26 lines is blank, so need move down the paper if 
have a blank line.
Final, the last line now have 31 space characters, and the last 1 number 
the 32 TH character.
This situation the 1 number need have the last row bottom right corner 
of the 28TH line.


I sending you an example english grade1 Braille file.
When you loading this file your test program (simple paste the text 
file, you see the paragraphs first line indented with two spaces, and 
the last line indented with 30 spaces.

This sent file have two paragraphs.

LiblouisUTDML file2brl command generating this standard braille documents.

So, if the GNOME PrintOperation object allows, the text output should be 
sent unchanged without the Cairo and Pango publishers cutting blank 
lines and already doed indentations. I think this form is called raw 
output when printing happening.


You will be seeing, Liblouis UTDML already putted the page break 
character with end of the page (U+000C character).


Attila
  ,this is ;a test message for
,eric4
  ,this is an another line4
























  #a
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-13 Thread Eric Cashon via gtk-app-devel-list

 
Hi Attila,

You have a print dialog and click on "Print to File" to save the contents to a 
PDF file and that file is not being formatted correctly and isn't the same as 
what is in the print preview? 

I tried a small test program. It prints well to PDF with the extra lines. Does 
this program work OK or does it cause the same problem.

Eric

#!/usr/bin/env python3

#Needed for cairo context: sudo apt-get install python-gi-cairo
#Tested on Ubuntu16.04 with GTK3.18 and Python3.

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GtkSource', '3.0')
gi.require_version('PangoCairo', '1.0')
from gi.repository import Gtk, GtkSource, PangoCairo, Pango
import math

class TextBox(GtkSource.View):
def __init__(self, win):
GtkSource.View.__init__(self)
self.parent_win = win
self.page_width = 0
self.page_height = 0
self.set_wrap_mode(1)
self.set_cursor_visible(True)
self.set_vexpand(True);
self.set_hexpand(True);
self.textbuffer = self.get_buffer() 
self.textbuffer.set_text("  
alma\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
   1")

def print_dialog(self):
operation = Gtk.PrintOperation()
#Just print 1 page.
operation.set_n_pages(1)
operation.connect("begin_print", self.begin_print)
operation.connect("draw_page", self.draw_page)
result = operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, 
self.parent_win)

def begin_print(self, operation, gtk_context):
self.page_width = gtk_context.get_width()
self.page_height = gtk_context.get_height()
pango_context = self.get_pango_context()
description = pango_context.get_font_description()
self.pango_layout = gtk_context.create_pango_layout()
self.pango_layout.set_font_description(description)
self.pango_layout.set_width(int(self.page_width*Pango.SCALE));
self.pango_layout.set_wrap(Pango.WrapMode.CHAR)

def draw_page(self, operation, gtk_context, page_number):
cr = gtk_context.get_cairo_context()

#Draw a rectangle.
cr.set_source_rgb(1.0, 0.0, 1.0)
cr.set_line_width(5)
cr.rectangle(40, 40, self.page_width-80, self.page_height-500)
cr.stroke()

#Show Text.
cr.set_source_rgb(0.0, 0.0, 0.0)
start = self.textbuffer.get_start_iter()
end = self.textbuffer.get_end_iter()
string = self.textbuffer.get_text(start, end, False)
self.pango_layout.set_markup(string)
PangoCairo.show_layout(cr, self.pango_layout)

class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("Print")
self.set_default_size(300, 700)
self.TextBox1 = TextBox(self)
self.scrolledwindow = Gtk.ScrolledWindow()
self.scrolledwindow.add(self.TextBox1)
self.button1 = Gtk.Button("Print Dialog")
self.button1.connect("clicked", self.print_dialog)
self.grid = Gtk.Grid()
self.grid.attach(self.scrolledwindow, 0, 0, 4, 4)
self.grid.attach(self.button1, 0, 5, 4, 1)
self.add(self.grid)

def print_dialog(self, button1):
self.TextBox1.print_dialog()

win = MainWindow()
win.connect("delete-event", Gtk.main_quit) 
win.show_all()
Gtk.main()



 


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-13 Thread Hammer Attila

Hi List,

Sorry, but unfortunatelly duplicated sent my letter.
When first time sent my letter, longer time later I not seeing my post 
this list.


Attila
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-13 Thread Hammer Attila

Dear list,

Possible you have an ydea with following problem:
I have a little Python3 code part with uses GtkSource.View and 
GtkSource.PrintCompositor to print native text file content with 
Gtk.Printoperation class.

The example code is following:
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GtkSource', '3.0')
from gi.repository import Gtk, GtkSource, Gio, GLib
def begin_printing(operation, context, compositor):
while not compositor.paginate(context):
pass
n_pages = compositor.get_n_pages()
operation.set_n_pages(n_pages)

def draw_page(operation, context, page_nr, compositor):
compositor.draw_page(context, page_nr)

view=GtkSource.View()
filename = GtkSource.File()
filename.set_location(Gio.File.new_for_path('test.txt'))
fileloader= GtkSource.FileLoader.new(view.get_buffer(), filename)
fileloader.load_async(GLib.PRIORITY_LOW, None, None, None, None, filename)
printop=Gtk.PrintOperation()
printcompositor=GtkSource.PrintCompositor.new_from_view(view)
printop.connect('begin-print', begin_printing, printcompositor)
printop.connect('draw-page', draw_page, printcompositor)
printop.run(Gtk.PrintOperationAction.PRINT_DIALOG, None)

The test.txt file is very simple, but important to keep entire content 
when the printing is happening the begin_printing and draw_page code parts:

The first line have two spaces and the hungarian alma word.
After this line have 26 blank lines (this is need to keeping future).
The 28 TH line have 31 space characters, and the 32. column have an 1 
number.

This is a typical braille document similar content.

What happening when I running this example code and generating a .pdf 
file document?
The logic answer is the printed file content is not changed in the PDF 
file (I think this previous).

But, not this is the case.

If I my Ubuntu system running for example with pdftotext -layout 
test.pdf command, the converted text file result is following:

"alma





   1"

The -layout switch tells pdftotext converter to keep original layout.

If I running pdftotext test.pdf command, the converted text file 
containing following text:

"alma

1"

Unfortunatelly I only this way possible testing printed output, because 
I not see entire the screen, I using Ubuntu system with the Orca Screen 
Reader.


The interesting bonus thing:
If I turning on the line number printing related property before 
paginate and set line numbering related property with 1, everi blank 
line inserted with the printed output.


I experiencing similar working method with Gedit text editor with this 
example text.


I tried debugging the begin_printing code part with the printcompositor 
buffer inserted text.

The text is equals my original text file content.

I haven't got another idea to how can possible keeping the original 
content when GtkSource Print compositor drawing the printed pages.


I tryed replacing GtkSource.PrintCompositor related code part with 
general Cairo and Pangolayout related codes, without success.
In the Pangolayout.get_text() code returns the original content, but the 
printed .pdf file dropped lot of blank lines.


Why important this?
I working a hungarian language specific application with converts from 
normal documents to braille documents using with Liblouis UTDML tool.

Everithing working right, except the printing.
So, when the printing is happening, need sending the printer the 
generated raw braille content without format loss from the 
GTKSource.PrintCompositor buffer.


Have chance to I forgot a very simple think. I already readed lot of GTK 
documentation with GtkPrintOperation printing related, but not yet 
founding a solution this issue related.


I attaching the example code, the test.txt file and a generated .pdf 
document with I created from the GtkPrintoperation print dialog.


Kind regards,

Attila Hammer
  alma


























   1
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

GtkSource.PrintCompositor: How to possible printing plain text documents without lost blank lines and indentations?

2017-10-13 Thread Hammer Attila

Dear list,

Possible you have an ydea with following problem:
I have a little Python3 code part with uses GtkSource.View and 
GtkSource.PrintCompositor to print native text file content with 
Gtk.Printoperation class.

The example code is following:
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GtkSource', '3.0')
from gi.repository import Gtk, GtkSource, Gio, GLib
def begin_printing(operation, context, compositor):
 while not compositor.paginate(context):
 pass
 n_pages = compositor.get_n_pages()
 operation.set_n_pages(n_pages)

def draw_page(operation, context, page_nr, compositor):
 compositor.draw_page(context, page_nr)

view=GtkSource.View()
filename = GtkSource.File()
filename.set_location(Gio.File.new_for_path('test.txt'))
fileloader= GtkSource.FileLoader.new(view.get_buffer(), filename)
fileloader.load_async(GLib.PRIORITY_LOW, None, None, None, None, filename)
printop=Gtk.PrintOperation()
printcompositor=GtkSource.PrintCompositor.new_from_view(view)
printop.connect('begin-print', begin_printing, printcompositor)
printop.connect('draw-page', draw_page, printcompositor)
printop.run(Gtk.PrintOperationAction.PRINT_DIALOG, None)

The test.txt file is very simple, but important to keep entire content 
when the printing is happening the begin_printing and draw_page code parts:

The first line have two spaces and the hungarian alma word.
After this line have 26 blank lines (this is need to keeping future).
The 28 TH line have 31 space characters, and the 32. column have an 1 
number.

This is a typical braille document similar content.

What happening when I running this example code and generating a .pdf 
file document?
The logic answer is the printed file content is not changed in the PDF 
file (I think this previous).

But, not this is the case.

If I my Ubuntu system running for example with pdftotext -layout 
test.pdf command, the converted text file result is following:

"alma





1"

The -layout switch tells pdftotext converter to keep original layout.

If I running pdftotext test.pdf command, the converted text file 
containing following text:

"alma

1"

Unfortunatelly I only this way possible testing printed output, because 
I not see entire the screen, I using Ubuntu system with the Orca Screen 
Reader.


The interesting bonus thing:
If I turning on the line number printing related property before 
paginate and set line numbering related property with 1, everi blank 
line inserted with the printed output.


I experiencing similar working method with Gedit text editor with this 
example text.


I tried debugging the begin_printing code part with the printcompositor 
buffer inserted text.

The text is equals my original text file content.

I haven't got another idea to how can possible keeping the original 
content when GtkSource Print compositor drawing the printed pages.


I tryed replacing GtkSource.PrintCompositor related code part with 
general Cairo and Pangolayout related codes, without success.
In the Pangolayout.get_text() code returns the original content, but the 
printed .pdf file dropped lot of blank lines.


Why important this?
I working a hungarian language specific application with converts from 
normal documents to braille documents using with Liblouis UTDML tool.

Everithing working right, except the printing.
So, when the printing is happening, need sending the printer the 
generated raw braille content without format loss from the 
GTKSource.PrintCompositor buffer.


Have chance to I forgot a very simple think. I already readed lot of GTK 
documentation with GtkPrintOperation printing related, but not yet 
founding a solution this issue related.


I attaching the example code, the test.txt file and a generated .pdf 
document with I created from the GtkPrintoperation print dialog.


Kind regards,

Attila Hammer

  alma


























   1

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Show printing dialogue

2013-10-21 Thread Satz Klauer
Hi,

currently I'm using following code to initialise for printing:

GtkPrintOperation *op;

op = gtk_print_operation_new();
gtk_print_operation_set_allow_async(op,TRUE);
gtk_print_operation_set_n_pages(op, 1);
gtk_print_operation_set_unit (op,GTK_UNIT_POINTS);
g_signal_connect (op, "draw_page", G_CALLBACK(draw_page), NULL);
gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT,NULL, NULL);

This works fine with default printer and its default settings. But how
can I tell GTK to open a print dialogue where user can choose a
different printer and change print parameters?

Thanks!
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Printing with GTK/Cairo produces only empty pages

2013-10-14 Thread Satz Klauer
I just want to draw a bunch of lines  - simple polygons, no filling...

On Mon, Oct 14, 2013 at 7:55 PM, Chris Vine  wrote:
> On Mon, 14 Oct 2013 19:34:53 +0200
> Satz Klauer  wrote:
>
>> Hi,
>>
>> I try to print some vector data using GTK/Cairo. Unfortunately my
>> printer only produces empty pages, means there is no print operation,
>> the paper sheets are just moved.
>>
>> That's how I'm initialising everything:
>>
>> GtkPrintOperation *op;
>>
>> op = gtk_print_operation_new();
>> gtk_print_operation_set_allow_async(op,TRUE);
>> gtk_print_operation_set_n_pages(op, 1);
>> gtk_print_operation_set_unit (op,GTK_UNIT_POINTS);
>> g_signal_connect (op, "draw_page", G_CALLBACK(draw_page), NULL);
>> gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT,NULL,
>> NULL);
>>
>> The print-callback (which is called successfuly) looks like this:
>>
>> static void draw_page (GtkPrintOperation *operation,GtkPrintContext
>> *context,int page_nr)
>> {
>>GtkPrintSettings *settings;
>>
>>cairo_t *cr = gtk_print_context_get_cairo_context (context);
>>settings = gtk_print_operation_get_print_settings (operation);
>>cairo_set_source_rgb(dc,0,0,0);
>>cairo_set_line_width(dc,m_data->config.m_linewidth);
>>
>>cairo_move_to (cr,x0,y0);
>>cairo_line_to (cr,x1,y1);
>>cairo_line_to (cr,x2,y2);
>>...
>>// some more lines...
>> }
>>
>> What could be missing here? Do I have to close/finish the drawing
>> operation somehow?
>
> That depends on what you are trying to draw.  I suspect you are looking
> for cairo_stroke(), but you could also consider cairo_fill(). Note also
> the *_preserve() variants.
>
> Chris
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Printing with GTK/Cairo produces only empty pages

2013-10-14 Thread Chris Vine
On Mon, 14 Oct 2013 19:34:53 +0200
Satz Klauer  wrote:

> Hi,
> 
> I try to print some vector data using GTK/Cairo. Unfortunately my
> printer only produces empty pages, means there is no print operation,
> the paper sheets are just moved.
> 
> That's how I'm initialising everything:
> 
> GtkPrintOperation *op;
> 
> op = gtk_print_operation_new();
> gtk_print_operation_set_allow_async(op,TRUE);
> gtk_print_operation_set_n_pages(op, 1);
> gtk_print_operation_set_unit (op,GTK_UNIT_POINTS);
> g_signal_connect (op, "draw_page", G_CALLBACK(draw_page), NULL);
> gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT,NULL,
> NULL);
> 
> The print-callback (which is called successfuly) looks like this:
> 
> static void draw_page (GtkPrintOperation *operation,GtkPrintContext
> *context,int page_nr)
> {
>GtkPrintSettings *settings;
> 
>cairo_t *cr = gtk_print_context_get_cairo_context (context);
>settings = gtk_print_operation_get_print_settings (operation);
>cairo_set_source_rgb(dc,0,0,0);
>cairo_set_line_width(dc,m_data->config.m_linewidth);
> 
>cairo_move_to (cr,x0,y0);
>cairo_line_to (cr,x1,y1);
>cairo_line_to (cr,x2,y2);
>...
>// some more lines...
> }
> 
> What could be missing here? Do I have to close/finish the drawing
> operation somehow?

That depends on what you are trying to draw.  I suspect you are looking
for cairo_stroke(), but you could also consider cairo_fill(). Note also
the *_preserve() variants.

Chris
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Printing with GTK/Cairo produces only empty pages

2013-10-14 Thread Satz Klauer
Hi,

I try to print some vector data using GTK/Cairo. Unfortunately my
printer only produces empty pages, means there is no print operation,
the paper sheets are just moved.

That's how I'm initialising everything:

GtkPrintOperation *op;

op = gtk_print_operation_new();
gtk_print_operation_set_allow_async(op,TRUE);
gtk_print_operation_set_n_pages(op, 1);
gtk_print_operation_set_unit (op,GTK_UNIT_POINTS);
g_signal_connect (op, "draw_page", G_CALLBACK(draw_page), NULL);
gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT,NULL, NULL);

The print-callback (which is called successfuly) looks like this:

static void draw_page (GtkPrintOperation *operation,GtkPrintContext
*context,int page_nr)
{
   GtkPrintSettings *settings;

   cairo_t *cr = gtk_print_context_get_cairo_context (context);
   settings = gtk_print_operation_get_print_settings (operation);
   cairo_set_source_rgb(dc,0,0,0);
   cairo_set_line_width(dc,m_data->config.m_linewidth);

   cairo_move_to (cr,x0,y0);
   cairo_line_to (cr,x1,y1);
   cairo_line_to (cr,x2,y2);
   ...
   // some more lines...
}

What could be missing here? Do I have to close/finish the drawing
operation somehow?

Thanks!
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Printing GtkTextView contents

2013-08-23 Thread John Coppens
On Tue, 20 Aug 2013 15:25:23 -0700 (PDT)
Marco Ricci  wrote:

> Is there a way by which I can query for the printer and use the results of 
> the query to send the contents of the GtkTextView? Can someone please point 
> me to a small example that does what I describe? I program using C on Linux.

Normally, there is a default printer configured for your machine. So, you 
could, for example,
save the text of your TextView to a temp file, and execute (eg. with 'system') 
'lpr '
Of course, it will be formated using default character sizes etc (probably some 
monospaced font).
But in the case of tech info, this simple trick might be useful.

John
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Printing GtkTextView contents

2013-08-20 Thread Marco Ricci
I want to obtain information about the printer connected to my USB port and 
send the contents of my GtkTextBuffer to the printer. However, I do not want 
any settings dialog to show up because I want to eliminate human interaction.

Is there a way by which I can query for the printer and use the results of the 
query to send the contents of the GtkTextView? Can someone please point me to a 
small example that does what I describe? I program using C on Linux.

Thanks,
marco
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Printing

2013-07-09 Thread Thomas Rønshof

Hi,


Does anybody have an example in C using GtkPrintUnixDialog, 
gtk_print_job_new and gtk_print_job_send using Pango/Cairo for ordinary 
text output on a printer ?


I know one should use GtkPrintOperation now a days, but some design 
matters in my project, makes it better for me to use GtkPrintUnixDialog 
directly.


GtkPrintOperation relies on GtkPrintUnixDialog underneath, so it should 
be okay to use.




Best regards.

Thomas Rønshof.





___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: switch printer tray during printing

2013-03-13 Thread Liam R E Quin
On Mon, 2013-03-11 at 16:13 -0500, Michael Cronenworth wrote:

> Changing trays may be out of the question, but I do know that Postscript
> allows per-page paper orientation changes. I have a few PDFs that do so.

You can change paper sizes too, which will generally cause a different
paper tray to be used; you might also be able to tell the printer
directly to switch trays, just as you can turn duplex, stapling and
collation features off and on. I've used software that did this in the
past. Whether gtk can do it I have no idea.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: switch printer tray during printing

2013-03-11 Thread Michael Cronenworth
On 03/11/2013 03:46 PM, Adam Tauno Williams wrote:
> I'm not sure this is even possible.   Tray select, duplex, etc... are
> often encoded in either the PCL preamble of a print job or in a PJL
> envelope [common for Postscript].  They really are attributes of the
> *job*.
>
> I'd guess that Gtk/GNOME would have to 'emulate' this behavior by
> splitting the ob silently into multiple jobs.  That could get wierd.

At the time I wrote my message I was under the impression I was sending
one stream of PCL to the printer and switching trays, but in fact I am
sending two separate streams. (with my non-GTK software)

Changing trays may be out of the question, but I do know that Postscript
allows per-page paper orientation changes. I have a few PDFs that do so.

The software that is demanding this is in the pharmaceutical industry
where they need all sorts of odd shaped data to print in different ways
to different paper sizes and trays in one go. I have it working for me
now without too much pain, but if I ever have an epiphany I'll be sure
to share it.

Thanks,
Michael
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: switch printer tray during printing

2013-03-11 Thread Adam Tauno Williams
On Thu, 2013-02-21 at 14:51 -0600, Michael Cronenworth wrote:
> Michael Cronenworth wrote:
> > Does anyone know if GTK allows switching print trays in the middle of a
> > GtkPrintOperation?
> > I tried setting the source to Tray 2 in the "request-page-setup" signal
> > for the second page, but this did not work. The second page printed to
> > Tray 1 (default).
> Old message, but I still wanted to reply for the Google archives.
> I cannot get GTK to change tray during a print job. I had to break the
> print job into two jobs and manually call
> gtk_print_settings_set_default_source() inbetween jobs.
> Ideally GTK should be able to change tray *and* paper orientation/size
> during a print job. There doesn't seem to be an RFE for this, but I
> think it would be a good feature.

I'm not sure this is even possible.   Tray select, duplex, etc... are
often encoded in either the PCL preamble of a print job or in a PJL
envelope [common for Postscript].  They really are attributes of the
*job*.

I'd guess that Gtk/GNOME would have to 'emulate' this behavior by
splitting the ob silently into multiple jobs.  That could get wierd.

-- 
Adam Tauno Williams  GPG D95ED383
Systems Administrator, Python Developer, LPI / NCLA

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: switch printer tray during printing

2013-02-21 Thread Michael Cronenworth
Michael Cronenworth wrote:
> Does anyone know if GTK allows switching print trays in the middle of a
> GtkPrintOperation?
>
> I tried setting the source to Tray 2 in the "request-page-setup" signal
> for the second page, but this did not work. The second page printed to
> Tray 1 (default).

Old message, but I still wanted to reply for the Google archives.

I cannot get GTK to change tray during a print job. I had to break the
print job into two jobs and manually call
gtk_print_settings_set_default_source() inbetween jobs.

Ideally GTK should be able to change tray *and* paper orientation/size
during a print job. There doesn't seem to be an RFE for this, but I
think it would be a good feature.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Simple vector graphics printing example?

2013-01-25 Thread Satz Klauer
Hi,

I plan to print out some vector data using the GTK printing system.

I already found the API description but what I'm missing is a general
overview that describes what has to be used in which order to send such
graphics to a printer.

So my question: is there a simple printing example code or a tutorial
available somewhere that describes how to use the printing functions?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


A problem with printing files

2012-11-24 Thread Jakub Kucharski
I was trying to write a simple application for printing a file. Nothing 
important. Just to learn basics. I've written this short piece of code:


#include 
#include 

static void
print_end(GtkPrintJob *print_job, gpointer user_data, const GError *err)
{
if (err == NULL)
return;
g_assert(err == NULL);
}

static void
print_page(GtkWidget *widget, gpointer user_data)
{
GtkWindow*parent = user_data;
GtkPrintJob*print_job;
GtkPrinter*printer;
GtkPrintSettings*settings;
GtkPageSetup*page_setup;
GtkWidget*dialog;
GError*err = NULL;
gbooleanstatus;

dialog = gtk_print_unix_dialog_new(NULL, parent);
if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_APPLY) {
gtk_widget_destroy(dialog);
return;
}
printer= gtk_print_unix_dialog_get_selected_printer(
GTK_PRINT_UNIX_DIALOG(dialog));
settings= gtk_print_unix_dialog_get_settings(
GTK_PRINT_UNIX_DIALOG(dialog));
page_setup= gtk_print_unix_dialog_get_page_setup(
GTK_PRINT_UNIX_DIALOG(dialog));
gtk_widget_destroy(dialog);

print_job= gtk_print_job_new("Example title", printer, settings,
page_setup);
status = gtk_print_job_set_source_file(print_job,
"/home/dexcret/Dokumenty/napisy.pdf", &err);
if (err != NULL) {
g_assert(status != FALSE);
fprintf(stderr, "Unable to print file: %s\n", err->message);
g_error_free(err);
err = NULL;
}
gtk_print_job_send(print_job, print_end, NULL, NULL);
g_object_unref(print_job);
g_object_unref(page_setup);
g_object_unref(settings);
g_object_unref(printer);
}

main(int argc, char **argv)
{
GtkWidget*window;
GtkWidget*button;

gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);

button = gtk_button_new_with_label("Print");
gtk_container_add(GTK_CONTAINER(window), button);
g_signal_connect(button, "clicked", G_CALLBACK(print_page),
GTK_WINDOW(window));
gtk_widget_show_all(window);
gtk_main();
return 0;
}

But it doesn't work. What have I done wrong?

--
Regards.
Jakub Kucharski

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


switch printer tray during printing

2012-10-31 Thread Michael Cronenworth
Does anyone know if GTK allows switching print trays in the middle of a
GtkPrintOperation?

I tried setting the source to Tray 2 in the "request-page-setup" signal
for the second page, but this did not work. The second page printed to
Tray 1 (default).

Thanks,
Michael
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


printing from gtksourceview on Windows

2011-09-25 Thread Allin Cottrell
I'm experimenting with using GtkSourceview plus GtkPrint to get 
syntax-highlighted printout from my app. I'm using gtksourceview 
2.10.5, in conjunction with


* gtk 2.24.6 on Linux
* gtk 2.14.3 on OS X
* gtk 2.16.6 on MS Windows

On Linux and OS X the printing works fine, but with the same code on 
Windows there's some sort of problem with units of measurement.


At first, on Windows I got a virtual "page size" of about 2 x 3 
centimeters: lines were ellipsized after just a few characters and a 
new page was started every few lines. I tried working around this by 
using gtk_print_operation_set_unit (with GTK_UNIT_MM) before doing 
the printing. This changed the output, but it's still wrong: now the 
virtual page size is much too big: there's no bottom margin and the 
text "runs off the bottom of the page" and disappears.


Does anyone have any suggestions for fixing this? I'm wondering if 
this might be a known issue that is solved in more recent gtk, or if 
there's any known workaround for use with gtk 2.16.6. Thanks!


--
Allin Cottrell
Department of Economics
Wake Forest University
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


gtk print for printing an image

2011-06-30 Thread Nicolas Soubeiran
Hi all,
I try to use GtkPrintOperation for printing an image and there is
something I do not understand.
When I am in the draw-page callback, I get the cairo context from
GtkPrintContext which is at 72dpi and the "draw rectangle" is smaller
than 1000x1000 (for A4 sheet) and my image pixbuf is 2000x3200. So I
need to rescale it (and loose resolution) to have a "full image"
print.

I have understood that I should not change the resolution of the given
print context when printing so I do not know how I can avoid
rescaling.

sample code :
static void s_draw_page(GtkPrintOperation *operation,GtkPrintContext
*context, gint page_nr, GdkPixbuf* image)
{
  GdkPixbuf* render;
  GtkPrintSettings * settings;
  cairo_t *cr;
  gdouble width, height;
  gint image_width, image_height;

  settings = gtk_print_operation_get_print_settings(operation);
  width = gtk_print_context_get_width (context);
  height = gtk_print_context_get_height(context);
  image_width = gdk_pixbuf_get_width(image);
  image_height = gdk_pixbuf_get_height(image);
  g_message("GtkPrintContext  dpi : %f, setting dpi %d",
gtk_print_context_get_dpi_x(context),
gtk_print_settings_get_resolution(settings));
  if(image_width >  width || image_height > height )
  {
g_warning("image is larger than printing zone : rescale");
render = gdk_pixbuf_scale_simple(image, (int) width , (int)height );
  }
  else
  {
render = GDK_PIXBUF(g_object_ref( image));
  }
  cairo_rectangle (cr, 0, 0, width, height);
  gdk_cairo_set_source_pixbuf(cr, render );
  cairo_fill(cr),
  g_object_unref(render);
}

output look likes:
message ** GtkPrintContext  dpi : 72.00, setting dpi 600
warning ** image is larger than printing zone : rescale
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Windows printing problem

2010-08-22 Thread James
On Fri, 2010-08-20 at 15:55 +1000, James wrote:
> Hi,
> 
> I've refined the code a bit.
> 
> This I can print to PDF using pdfFactory Pro, and it is displayed in the
> pdfFactory Pro preview window properly, but Windows always errors out on
> the actual printing.
> 
> Printing direct to the printer (HP laserjet) also causes windows to
> report an error trying to print.
> 
> (The printer works fine for every other app on Windows and Ubuntu).
> 
> Draw page code below.



Ok, I think I found the reason the darn thing wont print under windows.
It seems that because I have about 1 lines drawn in cairo onto the
print surface, the printer chucks a fit.  Now I draw to a separate cairo
surface and copy to the print context, which generates somewhat fuzzy
lines, but at least works.

Is there something I can do to improve the fuzzy lines?

James.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Windows printing problem

2010-08-19 Thread James
Hi,

I've refined the code a bit.

This I can print to PDF using pdfFactory Pro, and it is displayed in the
pdfFactory Pro preview window properly, but Windows always errors out on
the actual printing.

Printing direct to the printer (HP laserjet) also causes windows to
report an error trying to print.

(The printer works fine for every other app on Windows and Ubuntu).

Draw page code below.

Regards,
James.

static void draw_page (GtkPrintOperation *operation,
GtkPrintContext   *context,
gint   page_nr,
gpointer   user_data)
{
g_print("Draw page %d\n", page_nr);


int i;
char text[256];
int len;
PangoLayout *layout;
PangoFontDescription *desc;
GError *gerror = NULL;
GdkPixbuf *pb;

cairo_t *cr;
gdouble width, height;

cr = gtk_print_context_get_cairo_context (context);
width = gtk_print_context_get_width (context);
height = gtk_print_context_get_height (context);

pb = gdk_pixbuf_new_from_file("./Logo.jpg", &gerror);
if(!pb) {
eprintf("error message: %s\n", gerror->message);
return;
}

int pb_width = gdk_pixbuf_get_width (pb);
int pb_height = gdk_pixbuf_get_height (pb);

cairo_operator_t op = cairo_get_operator(cr);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
gdk_cairo_set_source_pixbuf(cr, pb, 0.0, 0.0);
cairo_paint (cr);
cairo_set_operator(cr, op);

cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);

layout = gtk_print_context_create_pango_layout (context);
desc = pango_font_description_from_string ("sans 14");
pango_layout_set_font_description (layout, desc);

sprintf(text, "Title details");

cairo_move_to(cr, pb_width+10, 0);
pango_layout_set_text (layout, text, -1);
pango_cairo_update_layout (cr, layout);
pango_cairo_show_layout (cr, layout);

pango_layout_set_text (layout, text, -1);

pango_font_description_free (desc);
g_object_unref (layout);

for (i = 0; i < 6; i++) {
layout = gtk_print_context_create_pango_layout (context);

len = 0;
len += sprintf(&text[len], "Stuff\n");
len += sprintf(&text[len], "More stuff\n");

pango_layout_set_text (layout, text, -1);

desc = pango_font_description_from_string ("sans 9");
pango_layout_set_font_description (layout, desc);
pango_font_description_free (desc);
pango_cairo_update_layout (cr, layout);

cairo_move_to(cr, (5 - i) * (width - GAP_X_AXIS) / 6, height - 
80);
pango_cairo_show_layout (cr, layout);

g_object_unref (layout);
}

cairo_translate(cr, 0, pb_height);

if (page_nr == 0) {
#if 1
//Various text and line drawing 
//with pango and cairo functions.
#endif
} else if (page_nr == 1) {
#if 1
//Various text and line drawing 
//with pango and cairo functions.
#endif
}
}


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Windows printing problem

2010-08-19 Thread James
Hi,

I have an app that prints 2 pages with an image in one corner of the
page, and some plotted data in the middle, the rest is text.

The page is oriented in landscape.

On Ubuntu the printing works fine.

On Windows XP I can get the text only to work.

Printing the image creates blank pages.

Printing the plotted data causes printing errors.

I'm using gtk+-bundle_2.18.7-20100213_win32

Any clues?

Code below.

Regards,
James.

pb = gdk_pixbuf_new_from_file("./Logo.jpg", &gerror);
if(!pb) {
eprintf("error message: %s\n", gerror->message);
return;
}

int pb_width = gdk_pixbuf_get_width (pb);
int pb_height = gdk_pixbuf_get_height (pb);

//set to 1 makes the whole page blank on Win32, Linux fine.
#if 0
cairo_surface_t *image = cairo_image_surface_create_for_data(
gdk_pixbuf_get_pixels(pb),
CAIRO_FORMAT_RGB24,
pb_width,
pb_height,
gdk_pixbuf_get_rowstride(pb));

do {
int rowstride, n_channels, x, y;
guchar *pixels, *p, tmp;

pixels = gdk_pixbuf_get_pixels (pb);
rowstride = gdk_pixbuf_get_rowstride(pb);
n_channels = gdk_pixbuf_get_n_channels (pb);

for (y = 0; y < pb_height; y++) {
for (x = 0; x < pb_width; x++) {
p = pixels + y * rowstride + x *
n_channels;
tmp = p[0];
p[0] = p[2];
p[2] = tmp;
}
}
} while (0);

cairo_save (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface(cr, image, 0, 0);
cairo_paint (cr);

cairo_restore (cr);


cairo_surface_destroy(image);
#endif



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: image printing

2010-07-23 Thread Tadej Borovšak
Hi.

You need to unref your pixbuf only after it has been rendererd to
cairo context, since GList will not take ownership of it. Call
_unref() just after cairo_paint() call and you should be fine.

Tadej

-- 
Tadej Borovšak
tadeboro.blogspot.com
tadeb...@gmail.com
tadej.borov...@gmail.com
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: image printing

2010-07-23 Thread Claudio Saavedra
On Fri, 2010-07-23 at 22:50 +0700, Alexander Kuleshov wrote:
> GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file("home/shk/photo.jpg",
> NULL);

You are missing a '/' in the path.

Claudio


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


image printing

2010-07-23 Thread Alexander Kuleshov
Hello,

I need to print image in my gtk+ application. I have code:

GList* list;

void begin_print (GtkPrintOperation * oper, GtkPrintContext * context,
   gint nr, gpointer user_data)
{
   GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file("home/shk/photo.jpg", NULL);

   list = g_list_prepend (list, pixbuf);
   gtk_print_operation_set_n_pages(oper,1);

   g_object_unref(pixbuf);
}

Then draw-page:

void draw_page (GtkPrintOperation * oper, GtkPrintContext * context,
   gint nr, gpointer user_data)
{
 cairo_t *cr = gtk_print_context_get_cairo_context (context);
gdk_cairo_set_source_pixbuf(cr,
(GdkPixbuf*)g_list_nth_data(list, 0), 0, 0);

   cairo_paint (cr);
}

and print setup:

void   print_pixbuf(GtkWidget* widget, MainWin* mw)
{
GtkPrintOperation *op;
GtkPrintOperationResult res;

op = gtk_print_operation_new ();

gtk_print_operation_set_unit (op, GTK_UNIT_MM);
g_signal_connect (op, "begin-print", G_CALLBACK (begin_print), mw);
   g_signal_connect (op, "draw-page", G_CALLBACK (draw_page), mw);

res = gtk_print_operation_run (op,
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, mw, NULL);

   g_object_unref (op);
}

But when i try to print image, i see segfault:

IA__gdk_cairo_set_source_pixbuf (cr=0x8333c00, pixbuf=0x0, pixbuf_x=0,
pixbuf_y=0) at gdkcairo.c:210 210 gdkcairo.c: No such file or
directory. in gdkcairo.c

What's wrong?

Thank you
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


RE: Random crashes when printing on OS X

2010-02-04 Thread Shawn Bakhtiar



I am now also getting this when I print, after having added a cairo_clip() to 
bound my drawings into a (0,0),(1,1) region. But I do not get it when I am 
displaying to screen, only printing, and I use the same function for both, one 
simply gets the cairo_t from the drawing area, the other retrieves it from the 
printer.

Any ideas?

Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFont: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFontSize: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetTextMatrix: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextClearRect: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetRGBFillColor: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextShowGlyphsAtPoint: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFont: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFontSize: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetTextMatrix: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextClearRect: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetRGBFillColor: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextShowGlyphsAtPoint: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFont: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFontSize: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetTextMatrix: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextClearRect: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetRGBFillColor: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextShowGlyphsAtPoint: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFont: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFontSize: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetTextMatrix: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextClearRect: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetRGBFillColor: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextShowGlyphsAtPoint: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFont: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFontSize: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetTextMatrix: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextClearRect: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetRGBFillColor: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextShowGlyphsAtPoint: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFont: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFontSize: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetTextMatrix: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextClearRect: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetRGBFillColor: invalid context 0x0
Thu Feb  4 17:04:16 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextShowGlyphsAtPoint: invalid context 0x0
Thu Feb  4 17:04:18 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFont: invalid context 0x0
Thu Feb  4 17:04:18 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetFontSize: invalid context 0x0
Thu Feb  4 17:04:18 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetTextMatrix: invalid context 0x0
Thu Feb  4 17:04:18 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextClearRect: invalid context 0x0
Thu Feb  4 17:04:18 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextSetRGBFillColor: invalid context 0x0
Thu Feb  4 17:04:18 Shawn-Bakhtiars-iMac.local orderdesk[39199] : 
CGContextShowGlyphsAtPoint: invalid context 0x0
Thu Feb  4 17:04:18 Shawn-Bakhtiars

Random crashes when printing on OS X

2010-02-04 Thread Shawn Bakhtiar



I am using the GtkPrint* functions to print. However at what seems to be random 
occurrences the application crashes with the following error:

Gdk:ERROR:gdkeventloop-quartz.c:559:select_thread_collect_poll: assertion 
failed: (ufds[i].fd == current_pollfds[i].fd)

Abort trap
 


When the user clicks on the print button a signal is generated and the 
application comand function executes based on the following case statement:


...

case ISI_PERM_MENU_COMPONENT_FORMULA_PRINT:

if( isi_app_check_permission(prev_self, 
ISI_PERM_MENU_COMPONENT_FORMULA_PRINT) && prev_self->component != NULL){

isi_display_page_setup( prev_self->display, 
prev_self->component,FALSE);
isi_display_print(prev_self->display);

} else {

isi_user_message(NULL,"Not Allowed","You do not have 
permission to print formulas.",0);
}

break;

...


void isi_display_print(IsiDisplay *self){

   
GtkPrintOperation *print = NULL;
GtkPrintSettings *printer_settings = NULL;
GtkPageSetup *page_setup = NULL;
GtkPaperSize *paper_size = NULL;
guint ctype;

/* Sanity Check */
g_return_if_fail(self != NULL);
g_return_if_fail(ISI_IS_DISPLAY(self) != FALSE);
g_return_if_fail(self->priv != NULL);
g_return_if_fail(self->priv->dispose_has_run != TRUE);

/* Create a new print operation */
print = gtk_print_operation_new();

/* Create new page setup and paper size */
page_setup = gtk_page_setup_new();
paper_size = gtk_paper_size_new(GTK_PAPER_NAME_LETTER);
gtk_page_setup_set_paper_size(page_setup,paper_size);

/* Set the default to the new page setup */
gtk_print_operation_set_default_page_setup(print,page_setup);
    

/* Make sure we always do full page printing*/
gtk_print_operation_set_unit(print,GTK_UNIT_INCH);
gtk_print_operation_set_use_full_page(print,TRUE);
gtk_print_operation_set_n_pages (print, self->priv->page_count);

g_signal_connect(print, "draw-page", 
G_CALLBACK(isi_display_print_event),(gpointer)self);



/* SOMEWHERE IN THIS FUNCTION THE DIALOG BLOWS UP!! */

gtk_print_operation_run(print,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,NULL,NULL);


return;}


Any help would be greatly appreciated.

The problem is pervasive will most printer types, but is exacerbated with the 
HP CP3525 Color Laserjet printer. 
Shawn






 EMAILING FOR THE GREATER GOOD
Join me   
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Printing a .png using GtkPrint

2009-11-17 Thread Richard Shann
I am trying to use GtkPrint* to print a .png file, the code I have tried
pops up the print dialog but nothing arrives in the printer queue. The
draw page signal is being received when I ok the print dialog.

The function I am using for the draw-page signal to try and print is
this:

static void
draw_page (GtkPrintOperation *operation,
   GtkPrintContext   *context,
   gint   page_nr,
   gpointer   user_data) {
  if(page_nr==0){
g_print("printing page 0");
  //gtk_print_operation_set_use_full_page() and gtk_print_operation_set_unit()
  cairo_t * cr = gtk_print_context_get_cairo_context (context);
  cairo_surface_t *surface = cairo_image_surface_create_from_png 
("denemoprint_.png");
  cairo_status_t  status = cairo_surface_status(surface);
  if(status != CAIRO_STATUS_SUCCESS)
g_print("An error %d\n", status);
  cairo_set_source_surface (cr, surface, 0, 0);
  cairo_paint (cr);
  cairo_surface_destroy (surface);
  } else
gtk_print_operation_cancel (operation);
  g_print("returning from draw\n");
}

Which has been assembled from the gtk docs and the cairo samples at
http://www.cairographics.org/samples/
The draw_page function is being called for page_nr 0 and the png load is
ok but as I say, nothing more transpires.

The bits of code that I have invented here are the calls to
cairo_surface_destroy (surface); 
and 
gtk_print_operation_cancel (operation);

The first of these can be left out, but the second prevents draw_page
being called ad infinitum.

Anyone have a working example? I am using Debian Lenny standard standard
packages.

Richard Shann


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Printing vs Logging

2009-01-16 Thread dhk
Can someone explain the difference between when to use 1) Message
Logging, 2) the Message Output and Debugging Functions, and 3) the
printing in the String Utility Functions?  It seems that for logging
purposes either of the three can be used.  Is there any advantage of one
over the other?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: printing gtktextview and text layout

2008-04-18 Thread Behdad Esfahbod
On Fri, 2008-04-18 at 17:30 +0200, Philippe Rouquier wrote:
> 
> Le mardi 15 avril 2008 à 15:05 -0400, Behdad Esfahbod a écrit : 
> > On Sat, 2008-04-12 at 11:08 +0200, Philippe Rouquier wrote:
> > > 
> > > Could someone help me with that please?
> > 
> > Just reorder your code to use pango_cairo_show_layout() for both display
> > and print, then make sure you set font options on your PangoContext
> > attached to the layout using pango_cairo_context_set_font_options() to
> > turn metrics hinting off (cairo_font_options_set_hint_metrics()).
> > 
> Hi,
> 
> Thanks for your answer.
> I tried and indeed it works: I used a pangolayout (with hinting turned
> off) for display in a widget to reflect what was written in the
> GtkTextView. I noticed the same discrepancies of text layout as when I
> printed. I then printed and the results matched the on screen
> pangolayout.
> 
> Now the problem is I want to use and print the GtkTextView. How do I
> turn off hinting in a GtkTextView?
> But maybe I didn't understand you well?

You understood me correctly.  I don't have answers to the rest of your
questions.

> Thanks again.
> 
-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
-- Benjamin Franklin, 1759

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: printing gtktextview and text layout

2008-04-18 Thread Philippe Rouquier

Le mardi 15 avril 2008 à 15:05 -0400, Behdad Esfahbod a écrit :

> On Sat, 2008-04-12 at 11:08 +0200, Philippe Rouquier wrote:
> > 
> > Could someone help me with that please?
> 
> Just reorder your code to use pango_cairo_show_layout() for both display
> and print, then make sure you set font options on your PangoContext
> attached to the layout using pango_cairo_context_set_font_options() to
> turn metrics hinting off (cairo_font_options_set_hint_metrics()).
> 

Hi,

Thanks for your answer.
I tried and indeed it works: I used a pangolayout (with hinting turned
off) for display in a widget to reflect what was written in the
GtkTextView. I noticed the same discrepancies of text layout as when I
printed. I then printed and the results matched the on screen
pangolayout.

Now the problem is I want to use and print the GtkTextView. How do I
turn off hinting in a GtkTextView?
But maybe I didn't understand you well?

Thanks again.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: printing gtktextview and text layout

2008-04-15 Thread Behdad Esfahbod
On Sat, 2008-04-12 at 11:08 +0200, Philippe Rouquier wrote:
> 
> Could someone help me with that please?

Just reorder your code to use pango_cairo_show_layout() for both display
and print, then make sure you set font options on your PangoContext
attached to the layout using pango_cairo_context_set_font_options() to
turn metrics hinting off (cairo_font_options_set_hint_metrics()).

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
-- Benjamin Franklin, 1759

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


printing gtktextview and text layout

2008-04-12 Thread Philippe Rouquier
Hi,

In brasero I recently started to work on a WYSIWYG cover editor. I ran
into a problem when I try to print something: the layout of the text is
not exactly similar to what is displayed on screen.
For example, if I make a line of "a" that goes from the left side to the
right side and if I try to print this line, then in the preview and on
the paper I have a shorter line of 'a' that starts at the right place
but that ends before the point it should reach.

On screen:
| < full line of x "a"  > |

On paper:
| < smaller line of x "a"   >  | 

For text editing I use a GtkTextView with WRAP_CHAR set. I allocate its
space by using the screen resolution (with gdk_screen_get_resolution ())
multiplied by the width and height (in inch) of a CD cover.
For printing, I use a PangoLayout (from
gtk_print_context_create_pango_layout ()) with WRAP_CHAR as well. I get
the sizes for the borders the same way (gtk_print_context_get_dpi_x *
cover_width, ...). These latter border sizes were correct when I
checked. 


Could someone help me with that please?

Regards,

Philippe Rouquier
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Gtkmm Printing in Ubuntu 7.10

2008-04-09 Thread Murray Cumming
On Wed, 2008-04-09 at 08:15 -0700, Garth's KidStuff wrote:
> Hi,
> 
> As covered in some earlier posts, Murry helped point me to the bug report on
> Ubuntu 7.10 that showed that gtk+ printing just didn't work there.

Specifically, there is a problem with the printing API when used from
gtkmm (not with GTK+ printing in general) and Ubuntu need to take the
upstream fix.

>   I've
> upgraded to Ubuntu 8.04 (beta), and Printing now works great for me (yay!).
> BUT I'd like to distribute this app to users who are still on Ubuntu 7.10.
> Is there a recommended way to solve this?  (Other than, of course, having
> the Ubuntu folks upgrade gtk+

gtkmm

>  so that it's just fixed).
> 
> BTW Using the Gtkmm::PrintOperation was an absolute pleasure once I upgraded
> to 8.04.  It's a nicely designed bunch of code *grin* .

You can always use the C API together with gtkmm, by using the gobj()
and Glib::wrap() functions.

-- 
[EMAIL PROTECTED]
www.murrayc.com
www.openismus.com

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Gtkmm Printing in Ubuntu 7.10

2008-04-09 Thread Garth's KidStuff
Hi,

As covered in some earlier posts, Murry helped point me to the bug report on
Ubuntu 7.10 that showed that gtk+ printing just didn't work there.  I've
upgraded to Ubuntu 8.04 (beta), and Printing now works great for me (yay!).
BUT I'd like to distribute this app to users who are still on Ubuntu 7.10.
Is there a recommended way to solve this?  (Other than, of course, having
the Ubuntu folks upgrade gtk+ so that it's just fixed).

BTW Using the Gtkmm::PrintOperation was an absolute pleasure once I upgraded
to 8.04.  It's a nicely designed bunch of code *grin* .
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


re: I'd like (working) printing sample code

2008-04-03 Thread Garth's KidStuff
>Unfortunately, Ubuntu are terrible at packaging bug-fix releases. You
>should subscribe yourself (and/or add a comment) to this Ubuntu bug:
>https://bugs.launchpad.net/ubuntu/+source/gtkmm2.4/+bug/197010

>If they don't provide the new version then you'll have to update to
>Ubuntu 8.04 Hardy (currently in beta).

>You might also try using jhbuild to create a completely up-to-date
>development environment from svn sources.


Thanks tons.  I upgraded to Ubuntu 8.04 beta, recompiled, and printed the
first time I tried.

-Garth
-- 
Garth Upshaw
Garth's KidStuff
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: I'd like (working) printing sample code

2008-04-01 Thread Murray Cumming
On Tue, 2008-04-01 at 10:05 -0700, Garth's KidStuff wrote:
> Hi Murray,
> 
> Thanks.  I'm running Ubuntu 7.10 Gutsy.  I'm not sure how to tell what
> version of Gtkmm I'm linking to, but I just used package manager to
> get the latest available and here's what's in my /usr/lib:
> -rw-r--r-- 1 root root1478 2007-09-17 13:42 libgtkmm-2.4.la
> lrwxrwxrwx 1 root root  22 2008-04-01 08:48 libgtkmm-2.4.so ->
> libgtkmm-2.4.so.1.0.30
> lrwxrwxrwx 1 root root  22 2008-04-01 08:48 libgtkmm-2.4.so.1 ->
> libgtkmm-2.4.so.1.0.30
> -rw-r--r-- 1 root root 3488400 2007-09-17 13:42 libgtkmm-2.4.so.1.0.30
> 
> You say there's been a bug fix that solves this -- how can I get that?

Unfortunately, Ubuntu are terrible at packaging bug-fix releases. You
should subscribe yourself (and/or add a comment) to this Ubuntu bug:
https://bugs.launchpad.net/ubuntu/+source/gtkmm2.4/+bug/197010

If they don't provide the new version then you'll have to update to
Ubuntu 8.04 Hardy (currently in beta).

You might also try using jhbuild to create a completely up-to-date
development environment from svn sources.
 
-- 
[EMAIL PROTECTED]
www.murrayc.com
www.openismus.com

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: I'd like (working) printing sample code

2008-04-01 Thread Murray Cumming
On Mon, 2008-03-31 at 07:34 -0700, Garth's KidStuff wrote:
> Hi,
> 
> Thanks in advance.  The sample code at:
> http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-printing-example.html
> 
> doesn't work for me.  I get the on_begin_print callback as expected, but
> never receive the on_draw_page callback.  Instead I get an endless series of
> error/warning messages as follows:
> 
> (Opus:7115): GLib-GObject-CRITICAL **: g_value_type_compatible: assertion
> `G_TYPE_IS_VALUE (src_type)' failed
> 
> (Opus:7115): GLib-GObject-WARNING **:
> /build/buildd/glib2.0-2.14.1/gobject/gsignal.c:2180:
> invalid object type `g-key-file-error-quark' for value type
> `GtkPrintContext'
> 
> repeat ad infinitum

It works for me.

What versions of GTK+ and gtkmm do you have? What version of what distro
is this? There have been some bugfixes.

> I'm writing a gtkmm app in C++ and have had great luck with the other
> examples in the tutorials I refer to above.

I'm CCing the gtkmm list.

-- 
[EMAIL PROTECTED]
www.murrayc.com
www.openismus.com

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


I'd like (working) printing sample code

2008-03-31 Thread Garth's KidStuff
Hi,

Thanks in advance.  The sample code at:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-printing-example.html

doesn't work for me.  I get the on_begin_print callback as expected, but
never receive the on_draw_page callback.  Instead I get an endless series of
error/warning messages as follows:

(Opus:7115): GLib-GObject-CRITICAL **: g_value_type_compatible: assertion
`G_TYPE_IS_VALUE (src_type)' failed

(Opus:7115): GLib-GObject-WARNING **:
/build/buildd/glib2.0-2.14.1/gobject/gsignal.c:2180:
invalid object type `g-key-file-error-quark' for value type
`GtkPrintContext'

repeat ad infinitum

I'm writing a gtkmm app in C++ and have had great luck with the other
examples in the tutorials I refer to above.

-Garth

-- 
Garth Upshaw
Garth's KidStuff
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Printing

2008-02-27 Thread Bastiaan Veelo
Bastiaan Veelo wrote:
> Enrico Tröger wrote:
>   
>>> 8) When exporting to PDF on Windows, trying to overwrite an existing 
>>> file, the program crashes (oops!). This works fine on Linux.
>>> 
>>>   
>> I can't reproduce this, on my Windows 2000 box I can overwrite existing
>> files as expected.
>>   
>> 
>
> Now I cannot reproduce either. I don't know what went wrong.
OK, now I know. The crash happens when writing to a file that is 
currently open for reading, and that is because I did not check the 
cairo status. Sorry, my mistake.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Printing

2008-02-22 Thread Bastiaan Veelo
Enrico Tröger wrote:
>
>> 8) When exporting to PDF on Windows, trying to overwrite an existing 
>> file, the program crashes (oops!). This works fine on Linux.
>> 
> I can't reproduce this, on my Windows 2000 box I can overwrite existing
> files as expected.
>   

Now I cannot reproduce either. I don't know what went wrong.


Bastiaan.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Printing

2008-02-22 Thread Bastiaan Veelo
Hi Enrico,

I reported a bug on this. You can leave a note that you are able to 
reproduce this, and maybe mention your printer model and Windows 
version. See http://bugzilla.gnome.org/show_bug.cgi?id=518052

Thanks,
Bastiaan.

Enrico Tröger wrote:
>  
>   
>> 7) When printing under Windows to a Canon inkjet, the bounding rectangle 
>> of graphics (not text) is filled black (auch!). The PDF is printed OK. 
>> 
> I have the same problem, it is also black when the document is printed
> to a PDF printer on Windows (e.g. PDFCreator from
> http://www.pdfforge.org/).
>   


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Printing

2008-02-20 Thread Enrico Tröger
On Wed, 20 Feb 2008 06:31:04 -0700, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:

> 
> >> Enrico Tr?ger wrote:
> > For examples see:
> > http://www.uvena.de/tmp/cairo/print_pango_linux.pdf (fine)
> > and
> > http://www.uvena.de/tmp/cairo/print_pango_win32.pdf (broken)
> 
> The link to the windows version is non-functional. I get the following 
> 403 permission error when I try to open it:
Sorry for this.
Links are working now.


Regards,
Enrico

-- 
Get my GPG key from http://www.uvena.de/pub.key
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Printing

2008-02-20 Thread [EMAIL PROTECTED]

>> Enrico Tr?ger wrote:
> For examples see:
> http://www.uvena.de/tmp/cairo/print_pango_linux.pdf (fine)
> and
> http://www.uvena.de/tmp/cairo/print_pango_win32.pdf (broken)

The link to the windows version is non-functional. I get the following 
403 permission error when I try to open it:
403:
You don't have permission to access the requested object. It is either 
read-protected or not readable by the server

(The Linux version works fine - what a surprise!)
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Printing

2008-02-19 Thread Enrico Tröger
On Sun, 17 Feb 2008 20:28:49 +0100, Bastiaan Veelo <[EMAIL PROTECTED]>
wrote:

> Enrico Tröger wrote:
> > On Wed, 13 Feb 2008 19:56:05 +0100, Bastiaan Veelo <[EMAIL PROTECTED]>
> > wrote:
> >
> > Hi,
> >
> >   
> >> 1) In order to get approximately correctly scaled text I had to specify 
> >> a resolution of around 27.2 on the pango context. This value was 
> >> determined by trial and error. I suspect I am doing something 
> >> fundamentally wrong, and I would like to know how to render text the way 
> >> the font designer inteded it. I have tried scaling only graphics and not 
> >> text, but even then text was much too big.
> >>
> >> 2) The printed font seems a little heavy. This may be due to the scaling 
> >> issue above.
> >> 
> > regarding the font issues in general: did you ever try to use Pango for
> > the fonts instead of Cairo?
> >   
> 
> Yes, my issues are with pango. The posted code also prints a cairo line 
> of text, for reference, but I prefer using a pango layout.
> 
> > In my app I'm using a PangoContext to place text into the page, but
> > this also causes problems, at least on Windows.
> >   
> 
> What kind of problems? Like I have described or others?
No, not really. One reported similar problems some months ago, see
http://www.mail-archive.com/gtk-app-devel-list@gnome.org/msg10029.html.
Behdad Esfahbod told him to change his code, I already did this but
still get the same results.

For examples see:
http://www.uvena.de/tmp/cairo/print_pango_linux.pdf (fine)
and
http://www.uvena.de/tmp/cairo/print_pango_win32.pdf (broken)

It's printed with the same code. Unfortunately, I didn't manage it yet
to write a small sample programm to show this. The above PDFs are
created by printing with Geany. The relevant code can be found in the
draw_page function in
http://geany.svn.sourceforge.net/viewvc/geany/trunk/src/printing.c?revision=2201&view=markup#l_466

Regards,
Enrico

-- 
Get my GPG key from http://www.uvena.de/pub.key
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Printing

2008-02-17 Thread Bastiaan Veelo
Enrico Tröger wrote:
> On Wed, 13 Feb 2008 19:56:05 +0100, Bastiaan Veelo <[EMAIL PROTECTED]>
> wrote:
>
> Hi,
>
>   
>> 1) In order to get approximately correctly scaled text I had to specify 
>> a resolution of around 27.2 on the pango context. This value was 
>> determined by trial and error. I suspect I am doing something 
>> fundamentally wrong, and I would like to know how to render text the way 
>> the font designer inteded it. I have tried scaling only graphics and not 
>> text, but even then text was much too big.
>>
>> 2) The printed font seems a little heavy. This may be due to the scaling 
>> issue above.
>> 
> regarding the font issues in general: did you ever try to use Pango for
> the fonts instead of Cairo?
>   

Yes, my issues are with pango. The posted code also prints a cairo line 
of text, for reference, but I prefer using a pango layout.

> In my app I'm using a PangoContext to place text into the page, but
> this also causes problems, at least on Windows.
>   

What kind of problems? Like I have described or others?

Regards,
Bastiaan.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Printing

2008-02-16 Thread Enrico Tröger
On Wed, 13 Feb 2008 19:56:05 +0100, Bastiaan Veelo <[EMAIL PROTECTED]>
wrote:

Hi,

> 1) In order to get approximately correctly scaled text I had to specify 
> a resolution of around 27.2 on the pango context. This value was 
> determined by trial and error. I suspect I am doing something 
> fundamentally wrong, and I would like to know how to render text the way 
> the font designer inteded it. I have tried scaling only graphics and not 
> text, but even then text was much too big.
> 
> 2) The printed font seems a little heavy. This may be due to the scaling 
> issue above.
regarding the font issues in general: did you ever try to use Pango for
the fonts instead of Cairo?
In my app I'm using a PangoContext to place text into the page, but
this also causes problems, at least on Windows.
 
> 7) When printing under Windows to a Canon inkjet, the bounding rectangle 
> of graphics (not text) is filled black (auch!). The PDF is printed OK. 
I have the same problem, it is also black when the document is printed
to a PDF printer on Windows (e.g. PDFCreator from
http://www.pdfforge.org/).
The attached little example code demonstrates the problem. Probably I'm
doing something wrong, if so, can anyone tell me what?
The code works fine on Linux, on Windows with GTK 2.12.1, Pango 1.18.3
and Cairo 1.4.10 the created rectangle is completely filled with black.
Is this a GTK/Pango problem, in Cairo or in my code?
See http://www.uvena.de/tmp/cairo/print_linux.pdf and
http://www.uvena.de/tmp/cairo/print_win.pdf to see what it looks like.

> 8) When exporting to PDF on Windows, trying to overwrite an existing 
> file, the program crashes (oops!). This works fine on Linux.
I can't reproduce this, on my Windows 2000 box I can overwrite existing
files as expected.


Regards,
Enrico

-- 
Get my GPG key from http://www.uvena.de/pub.key
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Printing

2008-02-13 Thread Bastiaan Veelo
Enrico Tröger wrote:
>> You will find the code attached, these are the issues:
>> 
> I don't ;-(.
>
>   

Let's try inline then:



/* February 2008, Bastiaan Veelo, [EMAIL PROTECTED] */

#include 
#include 
#ifdef CAIRO_HAS_PDF_SURFACE
#include 
#endif

static GtkWidget *window = NULL;
static GtkPrintSettings *settings = NULL;
static GtkPageSetup *page_setup = NULL;
static gdouble scale100 = -1;
static GtkWidget *font_button = NULL;

static void
begin_print (GtkPrintOperation *operation, GtkPrintContext *context, 
gpointer user_data)
{
  gtk_print_operation_set_n_pages (operation, 1);
}


/* We draw in mm, with (0,0) being the top left corner of the text area. */
static void
draw_page (cairo_t *cr)
{
  g_return_if_fail (page_setup != NULL);

  cairo_set_source_rgb (cr, 0, 0, 0);
  cairo_rectangle (cr,
   0,
   0,
   100,
   100);
  cairo_set_line_width (cr, .2);
  cairo_stroke (cr);

  /* Draw some lines */
  cairo_move_to (cr, 0, 0);
  cairo_line_to (cr,
 gtk_page_setup_get_page_width (page_setup, GTK_UNIT_MM),
 gtk_page_setup_get_page_height (page_setup, GTK_UNIT_MM));
  cairo_move_to (cr, 0, gtk_page_setup_get_page_height (page_setup, 
GTK_UNIT_MM));
  cairo_line_to (cr, gtk_page_setup_get_page_width (page_setup, 
GTK_UNIT_MM), 0);

  cairo_set_line_width (cr, 1);
  cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
  cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);

  cairo_stroke (cr);

  PangoFontDescription *desc =
  pango_font_description_from_string (gtk_font_button_get_font_name 
(GTK_FONT_BUTTON (font_button)));

  const gdouble dpi = 27.2; /*  Misterious empirical value. */
  PangoLayout *pango_cairo_layout = pango_cairo_create_layout (cr);
  pango_layout_set_font_description (pango_cairo_layout, desc);
  pango_cairo_context_set_resolution (pango_layout_get_context 
(pango_cairo_layout), dpi);
  cairo_font_options_t *options = cairo_font_options_create ();
  cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_OFF);
  cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE);
  pango_cairo_context_set_font_options (pango_layout_get_context 
(pango_cairo_layout), options);
  cairo_font_options_destroy (options);
  pango_layout_set_text (pango_cairo_layout,
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog "
 "the quick brown fox jumped over the lazy dog", 
-1);
  pango_layout_set_width (pango_cairo_layout, 100*PANGO_SCALE);
  cairo_move_to (cr, 0, 0);
  pango_cairo_show_layout (cr, pango_cairo_layout);
  g_object_unref (pango_cairo_layout);
  pango_font_description_free (desc);

  cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
  CAIRO_FONT_WEIGHT_NORMAL);
  cairo_set_font_size (cr, 12.0);   /* size em in mm */
  cairo_move_to(cr, 0., 120.);
  cairo_show_text(cr, "m Hello World! Printing...");
  cairo_move_to(cr, 0., 120.);
  cairo_line_to(cr, 12., 120.);
  cairo_set_line_width (cr, .2);
  cairo_stroke (cr);

  cairo_show_page (cr);
}

static void
print_page (GtkPrintOperation *operation, GtkPrintContext *context,
gint page_nr, gpointer user_data)
{
  g_debug("Print dpi = %f, scale = %f.", gtk_print_context_get_dpi_y 
(context), gtk_print_context_get_dpi_y (context)/25.4);
  cairo_t *cr = gtk_print_context_get_cairo_context (context);

  cairo_scale (cr,
   gtk_print_context_get_dpi_x (context)/25.4,
   gtk_print_context_get_dpi_y (context)/25.4);
  draw_page (cr);
}


void YGTK_page_setup()
{
  if (settings == NULL)
settings = gtk_print_settings_new ();

  GtkPageSetup *new_page_setup =
  gtk_print_run_page_setup_dialog (GTK_WINDOW (window), page_setup, 
settings);

  if (page_setup)
g_object_unref (page_setup);

  page_setup = new_page_setup;
  gtk_widget_queue_draw (window);
}


void YGTK_print_dialog()
{
  GtkPrintOperation *print;
  GtkPrintOperationResult result;
  GError *error;

  print = gtk_print_operation_new ();

  if (set

Re: Printing

2008-02-13 Thread Enrico Tröger
On Wed, 13 Feb 2008 19:56:05 +0100, Bastiaan Veelo <[EMAIL PROTECTED]>
wrote:

Hi,

> In lack of a complete printing tutorial,  I wrote one myself. There are 
cool. I missed a tutorial too when I was first working with the new
printing API.

> You will find the code attached, these are the issues:
I don't ;-(.

Regards,
Enrico

-- 
Get my GPG key from http://www.uvena.de/pub.key
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Printing

2008-02-13 Thread Bastiaan Veelo

Dear list,

In lack of a complete printing tutorial,  I wrote one myself. There are 
still some open questions though. My objective is to get consistent 
output of text and graphics on screen, in PDF and printed on paper, 
cross platform. All drawing code is in one function, which should not 
need to know the properties of the current device. I do that by scaling 
the cairo context so user space units are in millimeters.


You will find the code attached, these are the issues:

1) In order to get approximately correctly scaled text I had to specify 
a resolution of around 27.2 on the pango context. This value was 
determined by trial and error. I suspect I am doing something 
fundamentally wrong, and I would like to know how to render text the way 
the font designer inteded it. I have tried scaling only graphics and not 
text, but even then text was much too big.


2) The printed font seems a little heavy. This may be due to the scaling 
issue above.


3) Some letters seem to be placed too close to each other. On my Linux 
screen with the Sans font this is most notable between the r and o in 
"brown" and o and x in "fox". On Windows the problems are at other 
places. I have tried to rule out hinting problems by switching off all 
hinting.


4) When trying to print under Linux, nothing happens. No print job is 
spooled. No message on the console. I can produce a preview which looks 
OK. Not sure whether this is because GTK+ assumes some command line tool 
to be present, like lpr. CUPS is operational on my system.


5) When printing under Windows to an HP LaserJet (PCL and PS) there is a 
positive offset of a few millimeters both horizontally and vertically. 
Printing the PDF is OK.


6) When printing under Windows to an HP LaserJet, the cairo_rectangle is 
not printed. It is when printing the PDF.


7) When printing under Windows to a Canon inkjet, the bounding rectangle 
of graphics (not text) is filled black (auch!). The PDF is printed OK. 
On the laserjet the bounding box is first cleared to white, visible when 
the example on [1] is printed.


8) When exporting to PDF on Windows, trying to overwrite an existing 
file, the program crashes (oops!). This works fine on Linux.


9) The issue of margins. I know that the margins dealt with in the API 
are intended to be used as printer margins, not document margins. 
However, on Windows it is natural to use them as document margins, 
because the interface to modifying them appears on a high level, 
directly in the page setup dialog. These can be modified independently 
from the paper dimensions, and the graphical representation gives the 
user the impression of adjusting document margins, with dynamically 
updated lines printed inside a dashed rectangle. The label does not 
inform the user either that the margins presented are supposed to be 
printer margins, and why would a user be interested to adjust these 
indeed? In most cases the user is only interested in document margins, 
and these should be limited to the printer margins which should stay 
outside the user's control.
On Linux the interface is quite different, here using these margins as 
document margins makes no sense. The interface to adjusting these 
margins is nested on a deeper level, and is coupled to the definition of 
a custom paper size. So the user cannot define the margins without 
defining a custom paper size.
It is my feeling that there is confusion between "paper setup" and "page 
setup". Linux implements "paper setup" with printer margins that are 
dependent on the printer and paper size, and Windows implements "page 
setup" with a choice of paper size and document margins. I think the 
Linux implementation is more correct (although the name GtkPageSetup is 
misleading), and that the exposure of the margins on Windows is a 
mistake. As it is, I think the page setup dialog is unsuitable not be 
used in cross platform applications.
However, a widget for adjusting document margins like the current 
Windows presentation would be nice, but then consistent accross platforms.



I hope we can work out all these issues, so the community can have a 
working tutorial and I can get on with my project :-) Probably I should 
file a bug for some of these issues, but maybe the list can correct my 
errors first...


Thanks,
Bastiaan.

[1] http://library.gnome.org/devel/gtk/stable/GtkPrintContext.html
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: printing, cairo, & cups

2007-11-27 Thread Behdad Esfahbod
Hi Thomas,

On Unix, Gtk+ uses the PS backend, not the image.  The image backend
makes little sense for printing.

On Tue, 2007-11-27 at 06:58 -0600, Thomas Stover wrote:
> My main question is this. Somewhere the cairo 
> RGBA color space must be mapped into a printer's device dependent color 
> space such as CMYK. Is this mapping done inside Gtk using info
> resolved from cups, or is this done inside cups with filters?

That's all done in CUPS.

-- 
behdad
http://behdad.org/

"Those who would give up Essential Liberty to purchase a little
 Temporary Safety, deserve neither Liberty nor Safety."
-- Benjamin Franklin, 1759



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


printing, cairo, & cups

2007-11-27 Thread Thomas Stover
I've been trying to get myself up to speed with state of printing 
support in Gtk, and I'm down to just a few conceptual questions. It 
looks like the general idea is to setup a callback to render with cairo 
one page at a time using a GtkPrintContext. From this I would speculate 
that on win32, a cairo GDI surface is used with the GDI device being a 
windows printer. On the *nix side GtkPrintContext might be using cairo 
post script surface, but more likely an image (memory buffer) surface is 
used. If the GtkPrintContext is setup correctly, then the device 
dependent details width, height, and dpi get used to build such a cairo 
memory buffer surface. I'm also betting Gtk is pulling all this from 
CUPS. In that case, there is then the issue of cairo's lack of support 
for color space beyond RGBA, as in printing, arises. Although that is a 
completely separate topic, and definitely something I can live with for 
now if all else works out. My main question is this. Somewhere the cairo 
RGBA color space must be mapped into a printer's device dependent color 
space such as CMYK. Is this mapping done inside Gtk using info resolved 
from cups, or is this done inside cups with filters?

Any help with my understanding would be appreciated. Most of this I'm 
just wildly guessing about since I haven't found it documented. I really 
would like to spare me the time of learning CUPS, which is why I want to 
understand how much, and what, work Gtk is doing for me.


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


GTK 2.10 printing

2007-06-24 Thread Bo Lorentsen
Hi ...

I have been trying to use GTK+ printing system (with some success even), 
but I have a few problems regarding stopping a print in a prober way 
(works only when spooling to a file or preview).

Where can I find some detailed documentation about this (rather nice) 
system and some examples too ? And what is the right forum to ask this 
things in ?

/BL
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Printing a GtkImage

2007-03-13 Thread David Hampton
Is there an easy way to print a generic GtkImage to a cairo context?  I
currently have code that in essence does the following:

image = GTK_IMAGE(gtk_image_new_from_file(data->filename));
pixbuf = gtk_image_get_pixbuf(image);
cr = gtk_print_context_get_cairo_context(print_context);
gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y);

This works well for printing the images that are loaded from a file, but
fails when the file can't be read and gtk_image_new_from_file() returns
the stock "broken image" icon.  I know I can get the image type via
gtk_image_get_storage_type() and build a case statement to handle the
various image types, specifically the GTK_IMAGE_STOCK type, but I was
hoping there was an easier and more generic way to do this.  I know that
GtkImage renders to a cairo context in order to draw on the screen, I
was hoping to leverage the same for rendering to a print context.

Am I missing something totally obvious?  Thanks.

David


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Printing with Gtk

2007-01-27 Thread Jens Sauer
Hi,

I want to print from my Gtk Application but I could not find any
tutorial.
How can I calculate the necessary page number?
What is the correct use of the draw-page signal of GtkPrintOperation?

Can anybody help?
-- 
Jens Sauer <[EMAIL PROTECTED]>

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: capture window for printing

2007-01-24 Thread Fabian Förg
Fabian Förg wrote:
> Hello,
>
> as the topic suggests, I am trying to capture a window which should be 
> printed afterwards.
>
> This is my code:
>
> /* appl_t is a struct created by me which contains "GtkWidget 
> *print_win",
> * the window I want to print. Moreover, appl_t contains gints for the
> * width and height of the window */
>
> /* callback for my print button */
> static void print_cb(appl_t * appl)
> {
>values_t *val = &appl->values;
>GtkPrintOperation *op;
>GtkPrintOperationResult res;
>
>output_print(appl); /* This function creates the window which I 
> want to print */
>
>op = gtk_print_operation_new();
>
>gtk_print_operation_set_n_pages(op, 1);
>gtk_print_operation_set_unit(op, GTK_UNIT_MM);
>g_signal_connect(op, "draw_page", G_CALLBACK(draw_page), appl);
>res =
>gtk_print_operation_run(op, 
> GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
>NULL, NULL);
>}
> }
>
> static void draw_page(GtkPrintOperation * operation,
>  GtkPrintContext * print_context, gint page_nr,
>  appl_t * appl)
> {
>gdouble print_width, print_height, scale;
>cairo_t *cr, *cr_win;
>cairo_surface_t *surface;
>values_t *val = &appl->values;
>
>/* create a surface of the print window */
>cr_win = gdk_cairo_create(appl->print_win->window);
>
>/* get width and height of the print window */
>gdk_drawable_get_size(appl->print_win->window, &(val->width), 
> &(val->height));
>
>gtk_widget_hide_all(appl->print_win);
>
>/* create the cairo surface for cr_win */
>surface = cairo_get_target(cr_win);
>cairo_surface_reference(surface);
>cairo_destroy(cr_win);
>
>/* get width and heigth of print_context */
>print_width = gtk_print_context_get_width(print_context);
>print_height = gtk_print_context_get_height(print_context);
>
>/* transform the print_context into a cairo_context */
>cr = gtk_print_context_get_cairo_context(print_context);
>
>scale = (gdouble) print_width / val->width;
>
>/* scale, keep aspect ratio */
>cairo_scale(cr, scale, scale);
>
>cairo_set_source_surface(cr, surface, 0., 0.);
>cairo_surface_destroy(surface);
>
>cairo_paint(cr);
> }
>
> The problem is that the window is often captured with the print dialog.
This is most likely due to the fact that the window is captured when the 
draw_page signal is emitted. I. e. gdk_cairo_create creates a cairo_t * 
when the print button of the print dialog is pressed, and so the print 
dialog is also on the resulting paper. Is this correct?
When the gdk_cairo_create function is inserted after output print, but 
before gtk_print_operation_new, it is the same. Thus, the window is 
supposed to be captured BEFORE even creating the Gtk print dialog, but 
why doesn't it make any difference?
Moreover, the window is maximized, but the correct width and height of 
the window are only retrieved if gdk_drawable_get_size is called in the 
draw_page callback funtion draw_page. If it is called after output_win, 
gdk_drawable_get_size retrieves the width and height of the "shrinked" 
window. Why?
> [...]
>
> Questions:
> - Are there any better ways to achieve what I want?
> - Can I capture the window without showing it?
?
> Regards,
> Fabian
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


capture window for printing

2007-01-23 Thread Fabian Förg
Hello,

as the topic suggests, I am trying to capture a window which should be 
printed afterwards.

This is my code:

/* appl_t is a struct created by me which contains "GtkWidget *print_win",
 * the window I want to print. Moreover, appl_t contains gints for the
 * width and height of the window */

/* callback for my print button */
static void print_cb(appl_t * appl)
{
values_t *val = &appl->values;
GtkPrintOperation *op;
GtkPrintOperationResult res;

output_print(appl); /* This function creates the window which I want 
to print */

op = gtk_print_operation_new();

gtk_print_operation_set_n_pages(op, 1);
gtk_print_operation_set_unit(op, GTK_UNIT_MM);
g_signal_connect(op, "draw_page", G_CALLBACK(draw_page), appl);
res =
gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
NULL, NULL);
}
}

static void draw_page(GtkPrintOperation * operation,
  GtkPrintContext * print_context, gint page_nr,
  appl_t * appl)
{
gdouble print_width, print_height, scale;
cairo_t *cr, *cr_win;
cairo_surface_t *surface;
values_t *val = &appl->values;

/* create a surface of the print window */
cr_win = gdk_cairo_create(appl->print_win->window);

/* get width and height of the print window */
gdk_drawable_get_size(appl->print_win->window, &(val->width), 
&(val->height));

gtk_widget_hide_all(appl->print_win);

/* create the cairo surface for cr_win */
surface = cairo_get_target(cr_win);
cairo_surface_reference(surface);
cairo_destroy(cr_win);

/* get width and heigth of print_context */
print_width = gtk_print_context_get_width(print_context);
print_height = gtk_print_context_get_height(print_context);

/* transform the print_context into a cairo_context */
cr = gtk_print_context_get_cairo_context(print_context);

scale = (gdouble) print_width / val->width;

/* scale, keep aspect ratio */
cairo_scale(cr, scale, scale);

cairo_set_source_surface(cr, surface, 0., 0.);
cairo_surface_destroy(surface);

cairo_paint(cr);
}

The problem is that the window is often captured with the print dialog.
Furthermore, the window is sometimes "incomplete". The PDF/PS output 
shows just parts of the window - it seems that print_win is captured 
before it is completely rendered.

Questions:
- Are there any better ways to achieve what I want?
- Can I capture the window without showing it?

Regards,
Fabian
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Gtk Printing - Print Image with new Gtk API and Cairo

2006-10-25 Thread Alessandro Oliva
I have played with the new gtk+ printing support.
I use gtk+ 2.10.6 with MinGW on Windows.

I have a pixbuf and I want to print it in A4 format.

the problem is:
when beginning the print process, the "Dimension" of the printing file 
(to printer) is 126 MB !!,
the process is slow and heavy


this is the function that is performed when I press the button "print":

void   print_pixbuf()
{
GtkPrintOperation *op;
GtkPrintOperationResult res;
GtkPrintSettings *settings;

op = gtk_print_operation_new ();

gtk_print_operation_set_n_pages (op, 1);
gtk_print_operation_set_unit (op, GTK_UNIT_MM);
g_signal_connect (op, "draw_page", G_CALLBACK (draw_page), NULL);
res = gtk_print_operation_run (op, 
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL);
}

the callback function connected is:

static void
draw_page (GtkPrintOperation *operation,
GtkPrintContext *context,
int page_nr)
{
cairo_t *cr = gtk_print_context_get_cairo_context (context);

cairo_surface_t *image;
   

gdk_cairo_set_source_pixbuf(cr, rotated_pixbuf, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (image);

}

in alternative I have tried (with same result):

static void
draw_page (GtkPrintOperation *operation,
GtkPrintContext *context,
int page_nr)
{
cairo_surface_t *image;


cairo_t *cr = gtk_print_context_get_cairo_context (context);

gdk_pixbuf_save (rotated_pixbuf, "tmp.png", "png", 0L,  NULL);

image = cairo_image_surface_create_from_png ("tmp.png");

cairo_set_source_surface (cr, image, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (image);

}

thanks
 Alessandro


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Problem with gtk printing

2006-08-12 Thread Chris Vine
On Saturday 12 August 2006 16:45, Sebastian Filippini wrote:
> Hi.
>
> My name is Sebastian, I'm new in gtk programming. I'm having a problem when
> I try to use the new print support:
>
> When I invoke gtk_print_operation_run() print dialog is opened. Then, when
> the CUPS printer is being loaded, application ends with:
>
> symbol lookup error: /usr/lib/gtk-2.0/2.10.0/printbackends/libprintbackend-
> cups.so: undefined symbol: create_pickone_option_custom
>
> I'm using Linux from Scratch 6.1.1 with CUPS. CUPS works fine. Version is (
> 1.1.23).
> Gtk+ version is 2.10.1.
>
> I only need orientation. Thanks in advance!

It's a bug, no. 350329 at bugzilla - a patch is also posted which you can use, 
but there are a number of other problems with the gtk printing implementation 
and I suggest you wait a bit before using it.

Chris

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Problem with gtk printing

2006-08-12 Thread Sebastian Filippini
Hi.

My name is Sebastian, I'm new in gtk programming. I'm having a problem when
I try to use the new print support:

When I invoke gtk_print_operation_run() print dialog is opened. Then, when
the CUPS printer is being loaded, application ends with:

symbol lookup error: /usr/lib/gtk-2.0/2.10.0/printbackends/libprintbackend-
cups.so: undefined symbol: create_pickone_option_custom

I'm using Linux from Scratch 6.1.1 with CUPS. CUPS works fine. Version is (
1.1.23).
Gtk+ version is 2.10.1.

I only need orientation. Thanks in advance!
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Cross-Platform text edit with printing

2006-01-23 Thread Arne Caspari
Hi, 

I want to write an application that presents a form which could be
edited by the user and which should then be printed. 

The text editing functionality of a multiline  edit would suffice but I
do not know how to print the text buffer. Using gnome-print is not an
option since the application should run on Win32 and on Linux. 

Can anybody give me a hint on what might be the easiest way to do this? 

Thanks, 

 /Arne

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Printing contents of GtkTextBuffer

2005-11-18 Thread dnr
Can anyone provide guidance on using Gnome Print to print the contents of a
GtkTextBuffer, or the GtkTextView that the buffer is associated with?

The buffer may contain images, and rtl text as well as ltr text.


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Printing with gtk on windows

2005-07-21 Thread Razvan Gavril
I need to do some printing in a gtk application that runs on windows os and 
i can't find any starting point to look for documentation. Can anyone help 
me ? 
-- 
Razvan Gavril
[EMAIL PROTECTED]
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: printing problem

2005-05-12 Thread stian
> hi
>
> I was wanting to divide my page in two columns. One
> column with images and the other with text. Could
> someone give me an idea of how to do this. I have been
> trying libgnomeprint library.
>
> Printing a char * in multiline and restricted to a
> certain column of the page is my main problem. Any
> suggestions.

Since you use gnomeprint, I understand that you want to print this stuff out.

pango_layout_set_width() is what you want to use. Something like this
perhaps:

(width, margin_left and margin_right comes from gnome_print_config)

pango_layout_set_width (pango_layout, (width - margin_left - margin_right)
* PANGO_SCALE / 2);



Stian Skjelstad
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


printing problem

2005-05-12 Thread abhi rocks
hi

I was wanting to divide my page in two columns. One
column with images and the other with text. Could
someone give me an idea of how to do this. I have been
trying libgnomeprint library. 

Printing a char * in multiline and restricted to a
certain column of the page is my main problem. Any
suggestions.

Thank You
Abhishek Samuel



___ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: printing HtmlView (from libgtkhtml)

2005-04-20 Thread Peter Bloomfield
On 04/20/2005 08:18:55 AM, Hubert Sokolowski wrote:
Hi!
How to easily print the content of HtmlView created with  
html_view_new () ? Or some way to save it to a postscript file?
The HtmlView api (libgtkhtml/view/htmlview.h) is quite  
sparse--nothing about printing, saving, or otherwise exporting  
the graphic.  If you have the option, try gtkhtml3.

Peter
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


printing HtmlView (from libgtkhtml)

2005-04-20 Thread Hubert Sokolowski

Hi!

How to easily print the content of HtmlView created with html_view_new () ?
Or some way to save it to a postscript file?

regards
hs
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list