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