Re: [Tkinter-discuss] Text to postscript

2019-06-24 Thread Vasilis Vlachoudis
Hi all,

last weekend I started working on an initial version of the Text() -> 
postscript exporter.
Still is very primitive but some basic functionality is there.
Who ever is interested (or propose changes), can find it on 

https://github.com/vlachoudis/pstext 

run with "python3 pstext.py" (Sorry it executes the "gv" command to visualize 
the postscript
in linux.  I don't know how to do it in windows or on mac)
(After 1s it opens the gv viewer, or you can trigger it with the "v" keyboard 
command, "q" to quit)

Needless to say I am completely newbie in postscript, so maybe a few things 
might be done in a wrong way.

The program is using the "Text.dump()" command to go through all the Text() 
content and convert it
to postscript.

However I have a list of problems some related to tk and some with postscript

Tk related:
1. I could not find a way to get the "image" data from an embeded image in the 
Text() widget
2. When word wrap is enabled how I can find where is the "word break" on each 
line?

Tk-Postscript related:
1. How to make a proper "font" mapping from x11 to postscript
2. Unicode text: I have no idea how to do it in postscript.
3. How to get from postscript the font information (height, ascending, 
descending etc...) when
   running in python? 

I was thinking that the best way will be to "subclass" the Text and add a 
"postscript" method
maybe like in the Canvas that returns a text object, but for starting I 
preferred to make it external.

Any comments, suggestions are more than welcome
Vasilis


From: Tkinter-discuss 
[tkinter-discuss-bounces+vasilis.vlachoudis=cern...@python.org] on behalf of 
Cameron Laird [came...@phaseit.net]
Sent: Wednesday, June 19, 2019 15:52
To: tkinter-discuss@python.org
Subject: Re: [Tkinter-discuss] Text to postscript

On Tue, Jun 18, 2019 at 11:21:29PM +0200, Michael Lange wrote:
.
.
.
> On Tue, 18 Jun 2019 10:09:08 +
> Vasilis Vlachoudis  wrote:
>
> > Thanks Michael,
> >
> > not exactly what I was looking for.
>
> oh yes, I thought so :)
>
> > I am investigating how difficult is to write my own ps exporter,
> > based on the Canvas postscript source code.
>
> This would surely be awesome! In case you succeed please make sure to let
> us know :)
.
.
.
I've written such before.

More precisely, I composed several PostScript utilities and
programs, including one exporter from a custom Tk Canvas.  I
remember it as being fun and rewarding.  While I'm overbooked
at the present, I can at least say that a similar project
for Tkinter certainly *sounds* feasible.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Text to postscript

2019-06-19 Thread Cameron Laird
On Tue, Jun 18, 2019 at 11:21:29PM +0200, Michael Lange wrote:
.
.
.
> On Tue, 18 Jun 2019 10:09:08 +
> Vasilis Vlachoudis  wrote:
> 
> > Thanks Michael,
> >
> > not exactly what I was looking for.
> 
> oh yes, I thought so :)
> 
> > I am investigating how difficult is to write my own ps exporter,
> > based on the Canvas postscript source code.
> 
> This would surely be awesome! In case you succeed please make sure to let
> us know :)
.
.
.
I've written such before.

More precisely, I composed several PostScript utilities and
programs, including one exporter from a custom Tk Canvas.  I
remember it as being fun and rewarding.  While I'm overbooked
at the present, I can at least say that a similar project
for Tkinter certainly *sounds* feasible.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Text to postscript

2019-06-18 Thread Michael Lange
Hi,

On Tue, 18 Jun 2019 10:09:08 +
Vasilis Vlachoudis  wrote:

> Thanks Michael,
>
> not exactly what I was looking for.

oh yes, I thought so :)

> I am investigating how difficult is to write my own ps exporter,
> based on the Canvas postscript source code.

This would surely be awesome! In case you succeed please make sure to let
us know :)

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

"What terrible way to die."
"There are no good ways."
-- Sulu and Kirk, "That Which Survives", stardate unknown
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Text to postscript

2019-06-18 Thread Paul Malherbe
Title: signature

  
  
Hi
You could use fpdf to convert text to pdf as per:


import fpdf
    
  text = """The earliest known appearance of the phrase is from The
  Boston Journal. In an article titled "Current Notes" in the
  February 10, 1885, morning edition, the phrase is mentioned as a
  good practice sentence for writing students: "A favorite copy set
  by writing teachers for their pupils is the following, because it
  contains every letter of the alphabet: 'A quick brown fox jumps
  over the lazy dog.'"[1] Dozens of other newspapers published the
  phrase over the next few months, all using the version of the
  sentence starting with "A" rather than "The".[2] The earliest
  known use of the phrase in its modern form (starting with "The")
  is from the 1888 book Illustrative Shorthand by Linda Bronson.[3]
  The modern form (starting with "The") became more common despite
  the fact that it is slightly longer than the original (starting
  with "A")."""
  pdf = fpdf.FPDF(orientation="P", unit="mm", format="A4")
  pdf.set_font("courier", "", 10)
  pdf.set_auto_page_break(True, margin=5)
  pdf.add_page()
  pdf.multi_cell(180, 5, txt=text)
  pdf.output("test.pdf", "F")
--


  
  
  Regards
  
  Paul Malherbe
  
  

On 18/06/2019 12:09, Vasilis Vlachoudis
  wrote:


  Thanks Michael,

not exactly what I was looking for.
I am investigating how difficult is to write my own ps exporter,
based on the Canvas postscript source code.

Vasilis



From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern...@python.org] on behalf of Michael Lange [klappn...@web.de]
Sent: Tuesday, June 18, 2019 11:16
To: tkinter-discuss@python.org
Subject: Re: [Tkinter-discuss] Text to postscript

Hi,

On Mon, 17 Jun 2019 12:16:49 +
Vasilis Vlachoudis  wrote:


  
Hi all,

Canvas has this nice method to convert it to postscript, which is
perfect for printing. Is there something similar for Text(), I could
not find anything internal but if there is something external to
convert to html, ps, pdf it would be nice.

  
  
maybe you could use tkimg to create a "screenshot" of the widget in
postscript format.
To enable tkimg's "window" handler once it's installed you just need to do
something like

root.tk.call('package', 'require', 'img::window')

early in your code.

IIRC by default tkimg's "window" handler will include only the visible
part of the widget, but here:

https://wiki.tcl-lang.org/page/Img

George Petasis posted a recipe that seems to be able to capture the whole
contents of a canvas widget. I don't know how well this actually works
though and if it can be done with a Text widget in the same fashion.


Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

History tends to exaggerate.
-- Col. Green, "The Savage Curtain", stardate 5906.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss



  

___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] Text to postscript

2019-06-18 Thread Michael Lange
Hi,

On Mon, 17 Jun 2019 12:16:49 +
Vasilis Vlachoudis  wrote:

> Hi all,
>
> Canvas has this nice method to convert it to postscript, which is
> perfect for printing. Is there something similar for Text(), I could
> not find anything internal but if there is something external to
> convert to html, ps, pdf it would be nice.

maybe you could use tkimg to create a "screenshot" of the widget in
postscript format.
To enable tkimg's "window" handler once it's installed you just need to do
something like

root.tk.call('package', 'require', 'img::window')

early in your code.

IIRC by default tkimg's "window" handler will include only the visible
part of the widget, but here:

https://wiki.tcl-lang.org/page/Img

George Petasis posted a recipe that seems to be able to capture the whole
contents of a canvas widget. I don't know how well this actually works
though and if it can be done with a Text widget in the same fashion.


Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

History tends to exaggerate.
-- Col. Green, "The Savage Curtain", stardate 5906.4
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss