tkinter canvas postscript fontmap

Discussion in 'Python' started by Marcel Achim, Jan 13, 2004.

  1. Marcel Achim

    Marcel Achim Guest

    Hi,

    I want to set the fontmap to be used when saving the file. I write to
    the canvas using Arial and would like to get either Arial or Courier in
    the resulting .ps instead of MsSansSerif... I haven't found any sample
    on the net. Has anyone done this before with success ? What is the
    format of the "fontmap" option ?

    thanks
    Marcel
     
    Marcel Achim, Jan 13, 2004
    #1
    1. Advertisements

  2. > I want to set the fontmap to be used when saving the file. I write to
    > the canvas using Arial and would like to get either Arial or Courier in
    > the resulting .ps instead of MsSansSerif... I haven't found any sample
    > on the net. Has anyone done this before with success ? What is the
    > format of the "fontmap" option ?
    >


    I needed to do something similar some time ago and also found no examples.

    I'm not sure if it is the correct way to do it, but the code below appears
    to work.

    When you press the 'Print' button it creates a fontmap array which
    substitutes 'Arial 12' for all occurences of 'Courier 12' and 'Arial-Bold
    14' for 'Courier 14'. It then dumps the postscript to a file.

    Hope that helps,
    Richard Townsend

    ----------------------------------------------------------------------------
    ------------------------------------
    from Tkinter import *

    font1 = "Courier 12"
    font2 = "Courier 14"

    class Demo:

    def __init__(self):
    self.root = Tk()

    self.canvas = Canvas(self.root, height=300, width=300, bg="white")
    self.canvas.pack()

    frame = Frame(self.root)
    frame.pack()

    print_pb = Button(frame, text="Print", command=self.genPostscript)
    print_pb.pack(side=LEFT)

    quit_pb = Button(frame, text="Quit", command=self.quit)
    quit_pb.pack(side=LEFT)

    text = 'This is in %s' % font1
    self.canvas.create_text(10, 10, text=text, anchor=NW, font=font1)

    text = 'This is in %s' % font2
    self.canvas.create_text(10, 40, text=text, anchor=NW, font=font2)

    self.canvas.update_idletasks()
    self.root.mainloop()


    def genPostscript(self):
    # Create fontmap array
    self.root.tk.call('set', 'fontmap(%s)' % font1, 'Arial 12')
    self.root.tk.call('set', 'fontmap(%s)' % font2, 'Arial-Bold 14')

    #res = self.root.tk.call('array', 'get', 'fontmap')
    #print res

    # Generate the postscript data using the fontmap
    postscript = self.canvas.postscript(fontmap='fontmap')

    filename = 'dump.ps'
    fd = open(filename, 'w')
    fd.write(postscript)
    fd.close()


    def quit(self):
    self.root.quit()


    if __name__ == "__main__":

    Demo()
     
    Richard Townsend, Jan 13, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=

    Placing entry widgets on a canvas in Tkinter

    =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    599
    =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=
    Jun 30, 2003
  2. Suresh  Kumar
    Replies:
    0
    Views:
    727
    Suresh Kumar
    Jul 4, 2003
  3. Gary Richardson

    Tkinter Canvas/Grid question

    Gary Richardson, Sep 11, 2003, in forum: Python
    Replies:
    6
    Views:
    3,762
    Jeff Epler
    Sep 12, 2003
  4. Askari
    Replies:
    2
    Views:
    1,019
    Askari
    Aug 30, 2004
  5. PhilC
    Replies:
    2
    Views:
    1,144
    PhilC
    Oct 25, 2004
  6. Len Lawrence
    Replies:
    3
    Views:
    222
    Joel VanderWerf
    Apr 15, 2008
  7. Len Lawrence
    Replies:
    0
    Views:
    226
    Len Lawrence
    Jun 14, 2008
  8. Replies:
    10
    Views:
    571
    Rick Johnson
    Mar 15, 2013
Loading...