2004-02-29 21:05:44 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000-2004 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# Modifications and feature additions:
|
|
|
|
# 2002 Donald A. Peterson
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2004-02-29 23:12:38 +05:30
|
|
|
# Written by Billy C. Earney, 2003-2004
|
|
|
|
# Modified by Alex Roitman, 2004
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
"""LPR document generator"""
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import string
|
2004-03-06 05:38:09 +05:30
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME/GTK Modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2004-03-07 11:58:00 +05:30
|
|
|
import gtk.gdk
|
2004-03-06 05:38:09 +05:30
|
|
|
import gnomeprint, gnomeprint.ui
|
2004-03-09 04:02:13 +05:30
|
|
|
|
|
|
|
### FIXME ###
|
2004-03-08 07:52:41 +05:30
|
|
|
if gnomeprint.Context.__dict__.has_key('grestore'):
|
|
|
|
support_photos = 1
|
|
|
|
else:
|
|
|
|
support_photos = 0
|
|
|
|
print "LPRDoc: Photos and rotated text (used in TimeChart)"
|
2004-03-17 07:14:10 +05:30
|
|
|
print " are not supported for direct printing."
|
2004-03-10 07:40:34 +05:30
|
|
|
print " Get gnome-python from CVS"
|
|
|
|
print " or wait for the next gnome-python release."
|
2004-03-09 04:02:13 +05:30
|
|
|
### end FIXME ###
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import BaseDoc
|
|
|
|
import Plugins
|
|
|
|
import ImgManip
|
|
|
|
|
2004-03-03 11:24:26 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Spacing in points (distance between the bottoms of two adjacent lines)
|
|
|
|
_LINE_SPACING = 20
|
|
|
|
|
2004-03-06 05:30:39 +05:30
|
|
|
# Elevation of superscripts: a fraction of it's size
|
|
|
|
_SUPER_ELEVATION_FRACTION = 0.3
|
|
|
|
|
|
|
|
# Number of points to subtract to get the superscrip size
|
|
|
|
_SUPER_SIZE_REDUCTION = 2
|
|
|
|
|
2004-03-10 07:40:34 +05:30
|
|
|
# Factor which multiplies the font size to get line spacing for the font
|
|
|
|
_EXTRA_SPACING_FACTOR = 1.1
|
|
|
|
|
2004-03-03 11:24:26 +05:30
|
|
|
# Font constants -- specific for gnome-print
|
2004-03-10 07:40:34 +05:30
|
|
|
_TTF_FREEFONT = (
|
|
|
|
('FreeSerif Medium','FreeSerif Bold','FreeSerif Italic','FreeSerif BoldItalic' ),
|
|
|
|
('FreeSans Medium','FreeSans Bold','FreeSans Oblique','FreeSans BoldOblique'),
|
|
|
|
('FreeMono Medium','FreeMono Bold','FreeMono Oblique','FreeMono BoldOblique')
|
2004-03-09 04:02:13 +05:30
|
|
|
)
|
2004-03-10 07:40:34 +05:30
|
|
|
_MS_TTFONT = (
|
|
|
|
('Times New Roman Regular','Times New Roman Bold','Times New Roman Italic','Times New Roman Bold Italic' ),
|
|
|
|
('Arial Regular','Arial Bold','Arial Italic','Arial Bold Italic'),
|
|
|
|
('Courier New Regular','Courier New Bold','Courier New Italic','Courier New Bold Italic')
|
2004-03-09 04:02:13 +05:30
|
|
|
)
|
2004-03-10 07:40:34 +05:30
|
|
|
_GNOME_FONT = (
|
|
|
|
('Serif Regular','Serif Bold','Serif Italic','Serif Bold Italic' ),
|
|
|
|
('Sans Regular','Sans Bold','Sans Italic','Sans Bold Italic'),
|
|
|
|
('Monospace Regular','Monospace New Bold','Monospace New Italic','Monospace New Bold Italic')
|
2004-03-09 04:02:13 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
# Search for ttf-freefont first
|
|
|
|
ttf_not_found = 0
|
|
|
|
for family in _TTF_FREEFONT:
|
|
|
|
for font in family:
|
|
|
|
if font not in gnomeprint.font_list():
|
|
|
|
ttf_not_found = 1
|
|
|
|
break
|
|
|
|
|
|
|
|
if ttf_not_found:
|
2004-03-10 07:40:34 +05:30
|
|
|
print "LPRDoc: Free true type fonts not found."
|
2004-03-09 04:02:13 +05:30
|
|
|
# Search for MS ttfs
|
|
|
|
ms_not_found = 0
|
|
|
|
for family in _MS_TTFONT:
|
|
|
|
for font in family:
|
|
|
|
if font not in gnomeprint.font_list():
|
|
|
|
ms_not_found = 1
|
|
|
|
break
|
|
|
|
if ms_not_found:
|
2004-03-10 07:40:34 +05:30
|
|
|
print " Microsoft true type fonts not found."
|
|
|
|
print " Using Gnome standard fonts."
|
|
|
|
print " Non-ascii characters will appear garbled in the output."
|
|
|
|
print " INSTALL Free true type fonts"
|
|
|
|
print " from http://www.nongnu.org/freefont/"
|
2004-03-09 04:02:13 +05:30
|
|
|
_FONT_SET = _GNOME_FONT
|
|
|
|
else:
|
2004-03-10 07:40:34 +05:30
|
|
|
print " Found Microsoft true type fonts. Will use them for now."
|
|
|
|
print " These fonts are not free. "
|
|
|
|
print " You are advised to switch to Free true type fonts"
|
|
|
|
print " INSTALL Free true type fonts"
|
|
|
|
print " from http://www.nongnu.org/freefont/"
|
2004-03-09 04:02:13 +05:30
|
|
|
_FONT_SET = _MS_TTFONT
|
|
|
|
else:
|
|
|
|
_FONT_SET = _TTF_FREEFONT
|
2004-03-03 11:24:26 +05:30
|
|
|
|
|
|
|
# Formatting directive constants
|
2004-03-04 02:20:06 +05:30
|
|
|
_LINE_BREAK = "Break"
|
|
|
|
_BOLD = "Bold"
|
|
|
|
_SUPER = "Super"
|
2004-03-05 10:41:07 +05:30
|
|
|
_MONO = "Mono"
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Units conversion
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2004-03-01 22:20:23 +05:30
|
|
|
def cm2u(cm):
|
2004-02-29 21:05:44 +05:30
|
|
|
"""
|
2004-03-10 07:40:34 +05:30
|
|
|
Convert cm to gnome-print units.
|
2004-02-29 21:05:44 +05:30
|
|
|
"""
|
2004-03-01 22:20:23 +05:30
|
|
|
return cm * 72.0 / 2.54
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2004-03-03 11:24:26 +05:30
|
|
|
# font lookup function
|
2004-03-01 22:20:23 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2004-03-03 11:24:26 +05:30
|
|
|
def find_font_from_fontstyle(fontstyle):
|
|
|
|
"""
|
|
|
|
This function returns the gnomeprint.Font() object instance
|
2004-03-04 02:20:06 +05:30
|
|
|
corresponding to the parameters of BaseDoc.FontStyle() object.
|
2004-03-03 11:24:26 +05:30
|
|
|
|
|
|
|
fontstyle - a BaseDoc.FontStyle() instance
|
|
|
|
"""
|
2004-03-01 22:20:23 +05:30
|
|
|
|
2004-03-09 04:02:13 +05:30
|
|
|
if fontstyle.get_type_face() == BaseDoc.FONT_SERIF:
|
|
|
|
family = _FONT_SET[0]
|
|
|
|
elif fontstyle.get_type_face() == BaseDoc.FONT_SANS_SERIF:
|
|
|
|
family = _FONT_SET[1]
|
2004-03-03 11:24:26 +05:30
|
|
|
elif fontstyle.get_type_face() == BaseDoc.FONT_MONOSPACE:
|
2004-03-09 04:02:13 +05:30
|
|
|
family = _FONT_SET[2]
|
2004-03-03 11:24:26 +05:30
|
|
|
|
|
|
|
if fontstyle.get_bold():
|
|
|
|
if fontstyle.get_italic():
|
2004-03-09 04:02:13 +05:30
|
|
|
font = family[3]
|
|
|
|
else:
|
|
|
|
font = family[1]
|
2004-03-03 11:24:26 +05:30
|
|
|
elif fontstyle.get_italic():
|
2004-03-09 04:02:13 +05:30
|
|
|
font = family[2]
|
2004-03-03 11:24:26 +05:30
|
|
|
else:
|
2004-03-09 04:02:13 +05:30
|
|
|
font = family[0]
|
2004-03-03 11:24:26 +05:30
|
|
|
|
|
|
|
size = fontstyle.get_size()
|
2004-03-09 04:02:13 +05:30
|
|
|
return gnomeprint.font_find_closest(font,size)
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-04 02:20:06 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# basic font-specific text formatting functions
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2004-03-03 11:24:26 +05:30
|
|
|
def get_text_width(text,fontstyle):
|
2004-03-04 02:20:06 +05:30
|
|
|
"""
|
|
|
|
This function returns the width of text using given fontstyle
|
|
|
|
when not formatted.
|
|
|
|
|
|
|
|
text - a text whose width to find
|
|
|
|
fontstyle - a BaseDoc.FontStyle() instance
|
|
|
|
"""
|
2004-03-03 11:24:26 +05:30
|
|
|
font = find_font_from_fontstyle(fontstyle)
|
|
|
|
return font.get_width_utf8(text)
|
|
|
|
|
2004-03-04 02:20:06 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# add to paragraph taking care of the newline characters
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
def append_to_paragraph(paragraph,directive,text):
|
|
|
|
"""
|
|
|
|
Add a piece to the paragraph while
|
|
|
|
taking care of the newline characters.
|
|
|
|
|
|
|
|
paragraph - a GnomePrintParagraph() instance
|
|
|
|
directive - what to do with this piece
|
|
|
|
text - the text of the corresponding piece
|
|
|
|
"""
|
2004-03-05 06:06:04 +05:30
|
|
|
if not directive and not text:
|
|
|
|
return
|
2004-03-04 02:20:06 +05:30
|
|
|
text_list = text.split('\n')
|
|
|
|
for the_text in text_list[:-1]:
|
|
|
|
paragraph.add_piece(directive,the_text)
|
|
|
|
paragraph.add_piece(_LINE_BREAK,"")
|
|
|
|
paragraph.add_piece(directive,text_list[-1:][0])
|
|
|
|
|
2004-03-03 11:24:26 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Paragraph class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class GnomePrintParagraph:
|
|
|
|
"""
|
|
|
|
A paragraph abstraction which provides the means for in-paragraph
|
|
|
|
formatting.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,paragraph_style):
|
|
|
|
"""
|
|
|
|
Creates a GnomePrintParapgrah instance.
|
|
|
|
|
|
|
|
paragraph_style - an instance of BaseDoc paragraph style object
|
|
|
|
"""
|
|
|
|
self.style = paragraph_style
|
|
|
|
self.fontstyle = self.style.get_font()
|
|
|
|
self.piece_list = []
|
2004-03-05 06:06:04 +05:30
|
|
|
self.lines = []
|
|
|
|
self.height = None
|
2004-03-03 11:24:26 +05:30
|
|
|
|
|
|
|
def add_piece(self,directive,text):
|
|
|
|
"""
|
|
|
|
Add a piece to the paragraph.
|
|
|
|
|
|
|
|
directive - what to do with this piece
|
2004-03-04 02:20:06 +05:30
|
|
|
text - the text of the corresponding piece
|
2004-03-03 11:24:26 +05:30
|
|
|
"""
|
|
|
|
self.piece_list.append((directive,text))
|
|
|
|
|
|
|
|
def get_piece_list(self):
|
|
|
|
"""
|
|
|
|
Return a list of pieces for the paragraph.
|
|
|
|
"""
|
|
|
|
return self.piece_list
|
|
|
|
|
|
|
|
def get_fontstyle(self):
|
|
|
|
"""
|
2004-03-10 07:40:34 +05:30
|
|
|
Return fontstyle for the paragraph.
|
2004-03-03 11:24:26 +05:30
|
|
|
"""
|
|
|
|
return self.fontstyle
|
|
|
|
|
2004-03-04 05:08:48 +05:30
|
|
|
def get_alignment(self):
|
|
|
|
"""
|
2004-03-10 07:40:34 +05:30
|
|
|
Return requested alignment of the paragraph.
|
2004-03-04 05:08:48 +05:30
|
|
|
"""
|
|
|
|
return self.style.get_alignment()
|
|
|
|
|
2004-03-03 11:24:26 +05:30
|
|
|
def get_min_width(self):
|
|
|
|
"""
|
2004-03-10 07:40:34 +05:30
|
|
|
Determine the minimal width of the paragraph (longest word).
|
2004-03-03 11:24:26 +05:30
|
|
|
"""
|
|
|
|
max_word_size = 0
|
|
|
|
|
|
|
|
for (directive,text) in self.piece_list:
|
|
|
|
fontstyle = BaseDoc.FontStyle(self.fontstyle)
|
2004-03-04 02:20:06 +05:30
|
|
|
if directive == _BOLD:
|
2004-03-03 11:24:26 +05:30
|
|
|
fontstyle.set_bold(1)
|
2004-03-04 02:20:06 +05:30
|
|
|
elif directive == _SUPER:
|
2004-03-03 21:42:26 +05:30
|
|
|
size = fontstyle.get_size()
|
2004-03-06 05:30:39 +05:30
|
|
|
fontstyle.set_size(size-_SUPER_SIZE_REDUCTION)
|
2004-03-05 10:41:07 +05:30
|
|
|
elif directive == _MONO:
|
|
|
|
fontstyle.set_type_face(BaseDoc.FONT_MONOSPACE)
|
2004-03-03 11:24:26 +05:30
|
|
|
|
|
|
|
for word in text.split():
|
|
|
|
length = get_text_width(word,fontstyle)
|
|
|
|
if length > max_word_size:
|
|
|
|
max_word_size = length
|
|
|
|
|
|
|
|
return max_word_size
|
|
|
|
|
|
|
|
def get_height(self,width):
|
2004-03-05 08:31:21 +05:30
|
|
|
"""
|
|
|
|
Determine the height the paragraph would have
|
|
|
|
if formatted for a given width.
|
|
|
|
|
|
|
|
width - required formatting width
|
|
|
|
"""
|
2004-03-05 06:06:04 +05:30
|
|
|
if not self.lines:
|
|
|
|
self.format(width)
|
|
|
|
return self.height
|
|
|
|
|
|
|
|
def format(self,width):
|
2004-03-03 11:24:26 +05:30
|
|
|
"""
|
2004-03-05 08:31:21 +05:30
|
|
|
Format the paragraph for a given width.
|
|
|
|
This is a complex procedure. It assembles lines from the paragraph's
|
|
|
|
pieces. It also sets the height of the whole paragraph and
|
|
|
|
the widths available after the lines are assembled.
|
2004-03-03 11:24:26 +05:30
|
|
|
|
|
|
|
width - required formatting width
|
|
|
|
"""
|
2004-03-05 06:06:04 +05:30
|
|
|
|
|
|
|
if self.lines:
|
|
|
|
return
|
|
|
|
|
2004-03-06 05:30:39 +05:30
|
|
|
width = width - cm2u(self.style.get_right_margin()) \
|
|
|
|
- cm2u(self.style.get_left_margin())
|
|
|
|
|
2004-03-05 06:06:04 +05:30
|
|
|
nlines = 1
|
2004-03-03 11:24:26 +05:30
|
|
|
avail_width = width
|
2004-03-05 06:06:04 +05:30
|
|
|
|
|
|
|
start_piece = end_piece = start_word = end_word = 0
|
2004-03-06 05:30:39 +05:30
|
|
|
first = 1
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-05 06:06:04 +05:30
|
|
|
for piece_num in range(len(self.piece_list)):
|
|
|
|
end_piece = piece_num
|
|
|
|
|
|
|
|
(directive,text) = self.piece_list[piece_num]
|
|
|
|
|
2004-03-03 11:24:26 +05:30
|
|
|
fontstyle = BaseDoc.FontStyle(self.fontstyle)
|
2004-03-04 02:20:06 +05:30
|
|
|
if directive == _BOLD:
|
2004-03-03 11:24:26 +05:30
|
|
|
fontstyle.set_bold(1)
|
2004-03-04 02:20:06 +05:30
|
|
|
elif directive == _SUPER:
|
2004-03-03 21:42:26 +05:30
|
|
|
size = fontstyle.get_size()
|
2004-03-06 05:30:39 +05:30
|
|
|
fontstyle.set_size(size-_SUPER_SIZE_REDUCTION)
|
2004-03-05 10:41:07 +05:30
|
|
|
elif directive == _MONO:
|
|
|
|
fontstyle.set_type_face(BaseDoc.FONT_MONOSPACE)
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-06 05:30:39 +05:30
|
|
|
if first:
|
|
|
|
first = 0
|
|
|
|
avail_width = avail_width - cm2u(self.style.get_first_indent())
|
|
|
|
|
2004-03-03 11:24:26 +05:30
|
|
|
if text and avail_width > get_text_width(text,fontstyle):
|
|
|
|
avail_width -= get_text_width(text,fontstyle)
|
2004-03-05 06:06:04 +05:30
|
|
|
end_word = len(text.split())
|
2004-03-03 11:24:26 +05:30
|
|
|
elif directive == _LINE_BREAK:
|
|
|
|
nlines += 1
|
2004-03-05 06:06:04 +05:30
|
|
|
end_word = 0
|
|
|
|
self.lines.append((start_piece,start_word,end_piece,end_word,avail_width))
|
2004-03-03 11:24:26 +05:30
|
|
|
avail_width = width
|
2004-03-05 06:06:04 +05:30
|
|
|
start_piece = end_piece
|
|
|
|
start_word = 0
|
2004-03-03 11:24:26 +05:30
|
|
|
elif text and avail_width <= get_text_width(text,fontstyle):
|
2004-03-05 06:06:04 +05:30
|
|
|
# divide up text
|
2004-03-03 11:24:26 +05:30
|
|
|
textlist = text.split()
|
|
|
|
the_text = ""
|
2004-03-05 06:06:04 +05:30
|
|
|
for word_num in range(len(textlist)):
|
|
|
|
word = textlist[word_num]
|
|
|
|
if get_text_width(the_text + word + " ",fontstyle) <= avail_width:
|
|
|
|
the_text = the_text + word + " "
|
2004-03-03 11:24:26 +05:30
|
|
|
else:
|
2004-03-04 21:17:00 +05:30
|
|
|
# the_text contains as much as avail_width allows
|
2004-03-03 11:24:26 +05:30
|
|
|
nlines += 1
|
2004-03-05 06:06:04 +05:30
|
|
|
end_word = word_num
|
|
|
|
avail_width -= get_text_width(the_text,fontstyle)
|
|
|
|
self.lines.append((start_piece,start_word,end_piece,end_word,avail_width))
|
2004-03-03 11:24:26 +05:30
|
|
|
avail_width = width
|
2004-03-05 06:06:04 +05:30
|
|
|
the_text = word + " "
|
|
|
|
start_piece = end_piece
|
|
|
|
start_word = word_num
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-04 21:17:00 +05:30
|
|
|
# if the_text still contains data, we will want to print it out
|
2004-03-03 11:24:26 +05:30
|
|
|
if the_text:
|
|
|
|
avail_width = width - get_text_width(the_text,fontstyle)
|
2004-03-05 06:06:04 +05:30
|
|
|
end_word = len(textlist)
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-05 06:06:04 +05:30
|
|
|
self.lines.append((start_piece,start_word,end_piece,end_word,avail_width))
|
2004-03-10 07:40:34 +05:30
|
|
|
self.height = nlines * self.fontstyle.get_size() * _EXTRA_SPACING_FACTOR \
|
2004-03-06 07:59:20 +05:30
|
|
|
+ 2 * cm2u(self.style.get_padding())
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-06 05:30:39 +05:30
|
|
|
def get_lines(self):
|
|
|
|
"""
|
2004-03-06 05:38:09 +05:30
|
|
|
Return a list of assemlbed lines for the paragraph.
|
2004-03-10 07:40:34 +05:30
|
|
|
|
2004-03-06 05:38:09 +05:30
|
|
|
Each element is a tuple corresponding to the line's contents:
|
|
|
|
(start_piece,start_word,end_piece,end_word,avail_width)
|
2004-03-06 05:30:39 +05:30
|
|
|
"""
|
|
|
|
return self.lines
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-07 11:58:00 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Photo class
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class GnomePrintPhoto:
|
|
|
|
"""
|
|
|
|
A photo abstraction which provides the means for correct photo placement.
|
|
|
|
Way less complex that paragraph, but still useful.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,name,pos,x_size,y_size):
|
|
|
|
"""
|
|
|
|
Creates a GnomePrintPhoto instance.
|
|
|
|
"""
|
|
|
|
self.name = name
|
|
|
|
self.alignment = pos
|
|
|
|
self.pixbuf = gtk.gdk.pixbuf_new_from_file(name)
|
|
|
|
self.height = self.pixbuf.get_height()
|
|
|
|
self.width = self.pixbuf.get_width()
|
|
|
|
max_size = cm2u(max(x_size,y_size))
|
|
|
|
self.scale_x = int( max_size * float(self.width)/max(self.height,self.width) )
|
|
|
|
self.scale_y = int( max_size * float(self.height)/max(self.height,self.width) )
|
|
|
|
|
|
|
|
def get_image(self):
|
|
|
|
"""
|
|
|
|
Return the raw image of the photo.
|
|
|
|
"""
|
|
|
|
return self.pixbuf.get_pixels()
|
|
|
|
|
|
|
|
def get_has_alpha(self):
|
|
|
|
"""
|
|
|
|
Return has_alpha of the photo.
|
|
|
|
"""
|
|
|
|
return self.pixbuf.get_has_alpha()
|
|
|
|
|
|
|
|
def get_rowstride(self):
|
|
|
|
"""
|
|
|
|
Return the rowstride of the photo.
|
|
|
|
"""
|
|
|
|
return self.pixbuf.get_rowstride()
|
|
|
|
|
|
|
|
def get_height(self,width=None):
|
|
|
|
"""
|
|
|
|
Return the real height of the photo as it should appear on the page.
|
|
|
|
"""
|
|
|
|
return self.scale_y
|
|
|
|
|
|
|
|
def get_width(self):
|
|
|
|
"""
|
|
|
|
Return the real width of the photo as it should appear on the page.
|
|
|
|
"""
|
|
|
|
return self.scale_x
|
|
|
|
|
|
|
|
def get_min_width(self):
|
|
|
|
"""
|
|
|
|
Return the minimum width of the photo as it should appear on the page.
|
|
|
|
"""
|
|
|
|
return self.scale_x
|
|
|
|
|
|
|
|
def get_image_height(self):
|
|
|
|
"""
|
|
|
|
Return the height of the photo in terms of image's pixels.
|
|
|
|
"""
|
|
|
|
return self.height
|
|
|
|
|
|
|
|
def get_image_width(self):
|
|
|
|
"""
|
|
|
|
Return the width of the photo in terms of image's pixels.
|
|
|
|
"""
|
|
|
|
return self.width
|
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2004-03-01 22:20:23 +05:30
|
|
|
# LPRDoc class
|
2004-02-29 21:05:44 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class LPRDoc(BaseDoc.BaseDoc):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Gnome-print document interface class. Derived from BaseDoc."""
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-08 07:52:41 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# General methods
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2004-02-29 21:05:44 +05:30
|
|
|
def open(self,filename):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Sets up initialization."""
|
2004-02-29 21:05:44 +05:30
|
|
|
#set up variables needed to keep track of which state we are in
|
2004-03-13 01:17:06 +05:30
|
|
|
self.in_table = 0
|
|
|
|
self.in_cell = 0
|
|
|
|
self.page_count = 0
|
|
|
|
self.page_open = 0
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-03 11:24:26 +05:30
|
|
|
self.paragraph = None
|
2004-03-13 01:17:06 +05:30
|
|
|
self.cell_data = []
|
|
|
|
self.table_data = []
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
#create main variables for this print job
|
2004-03-13 01:17:06 +05:30
|
|
|
self.job = gnomeprint.Job(gnomeprint.config_default())
|
|
|
|
self.gpc = self.job.get_context()
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
#find out what the width and height of the page is
|
2004-03-13 01:17:06 +05:30
|
|
|
width, height = gnomeprint.job_get_page_size_from_config(self.job.get_config())
|
2004-03-02 06:06:53 +05:30
|
|
|
|
2004-03-03 11:24:26 +05:30
|
|
|
self.left_margin = cm2u(self.get_left_margin())
|
|
|
|
self.right_margin = width - cm2u(self.get_right_margin())
|
|
|
|
self.top_margin = height - cm2u(self.get_top_margin())
|
|
|
|
self.bottom_margin = cm2u(self.get_bottom_margin())
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
self.start_page(self)
|
|
|
|
|
2004-03-02 07:05:53 +05:30
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
def close(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Clean up and close the document."""
|
2004-02-29 21:05:44 +05:30
|
|
|
#gracefully end page before we close the doc if a page is open
|
2004-03-13 01:17:06 +05:30
|
|
|
if self.page_open:
|
2004-02-29 21:05:44 +05:30
|
|
|
self.end_page()
|
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.job.close()
|
|
|
|
self.show_print_dialog()
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def start_page(self,orientation=None):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Create a new page."""
|
|
|
|
# Don't start new page if it is just started
|
|
|
|
if self.brand_new_page:
|
|
|
|
return
|
2004-02-29 21:05:44 +05:30
|
|
|
#reset variables dealing with opening a page
|
2004-03-13 01:17:06 +05:30
|
|
|
if (self.page_open):
|
2004-03-04 02:20:06 +05:30
|
|
|
self.end_page()
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.page_open = 1
|
|
|
|
self.page_count += 1
|
|
|
|
self.x = self.left_margin
|
|
|
|
self.y = self.top_margin
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.beginpage(str(self.page_count))
|
|
|
|
self.gpc.moveto(self.x, self.y)
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 1
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def end_page(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Close the current page."""
|
2004-03-13 01:17:06 +05:30
|
|
|
if (self.page_open):
|
|
|
|
self.page_open = 0
|
|
|
|
self.gpc.showpage()
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
def page_break(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"Forces a page break, creating a new page."
|
2004-03-08 07:52:41 +05:30
|
|
|
# If we're already at the very top, relax and do nothing
|
2004-03-10 07:40:34 +05:30
|
|
|
if not self.brand_new_page:
|
2004-03-08 07:52:41 +05:30
|
|
|
self.end_page()
|
|
|
|
self.start_page()
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Text methods
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def line_break(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"Forces a line break within a paragraph."
|
2004-03-08 07:52:41 +05:30
|
|
|
# Add previously held text to the paragraph,
|
|
|
|
# then add line break directive,
|
|
|
|
# then start accumulating further text
|
2004-03-13 01:17:06 +05:30
|
|
|
append_to_paragraph(self.paragraph,self.paragraph_directive,self.paragraph_text)
|
2004-03-08 07:52:41 +05:30
|
|
|
self.paragraph.add_piece(_LINE_BREAK,"")
|
2004-03-13 01:17:06 +05:30
|
|
|
self.paragraph_text = ""
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def start_paragraph(self,style_name,leader=None):
|
|
|
|
"""Paragraphs handling - A Gramps paragraph is any
|
|
|
|
single body of text, from a single word, to several sentences.
|
|
|
|
We assume a linebreak at the end of each paragraph."""
|
2004-03-04 02:20:06 +05:30
|
|
|
# Instantiate paragraph object and initialize buffers
|
2004-03-03 11:24:26 +05:30
|
|
|
self.paragraph = GnomePrintParagraph(self.style_list[style_name])
|
2004-03-13 01:17:06 +05:30
|
|
|
self.paragraph_directive = ""
|
|
|
|
self.paragraph_text = ""
|
2004-03-03 22:29:47 +05:30
|
|
|
if leader:
|
2004-03-13 01:17:06 +05:30
|
|
|
self.paragraph_text += leader + " "
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def end_paragraph(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""End the current paragraph."""
|
2004-03-04 02:20:06 +05:30
|
|
|
# Add current text/directive to paragraoh,
|
|
|
|
# then either add paragrah to the list of cell's paragraphs
|
|
|
|
# or print it right away if not in cell
|
2004-03-13 01:17:06 +05:30
|
|
|
append_to_paragraph(self.paragraph,self.paragraph_directive,self.paragraph_text)
|
|
|
|
if self.in_cell:
|
2004-03-03 11:24:26 +05:30
|
|
|
# We're inside cell. Add paragrah to celldata
|
2004-03-13 01:17:06 +05:30
|
|
|
self.cell_data.append(self.paragraph)
|
2004-03-03 11:24:26 +05:30
|
|
|
else:
|
|
|
|
# paragraph not in table: write it right away
|
2004-03-13 01:17:06 +05:30
|
|
|
self.x, self.y = self.write_paragraph(self.paragraph,
|
|
|
|
self.x, self.y,
|
2004-03-05 06:06:04 +05:30
|
|
|
self.right_margin - self.left_margin)
|
2004-03-03 11:24:26 +05:30
|
|
|
self.paragraph = None
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
def start_bold(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Bold face."""
|
2004-03-13 01:17:06 +05:30
|
|
|
append_to_paragraph(self.paragraph,self.paragraph_directive,self.paragraph_text)
|
|
|
|
self.paragraph_directive = _BOLD
|
|
|
|
self.paragraph_text = ""
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def end_bold(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""End bold face."""
|
2004-03-13 01:17:06 +05:30
|
|
|
append_to_paragraph(self.paragraph,self.paragraph_directive,self.paragraph_text)
|
|
|
|
self.paragraph_directive = ""
|
|
|
|
self.paragraph_text = ""
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def start_superscript(self):
|
2004-03-13 01:17:06 +05:30
|
|
|
append_to_paragraph(self.paragraph,self.paragraph_directive,self.paragraph_text)
|
|
|
|
self.paragraph_directive = _SUPER
|
|
|
|
self.paragraph_text = ""
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def end_superscript(self):
|
2004-03-13 01:17:06 +05:30
|
|
|
append_to_paragraph(self.paragraph,self.paragraph_directive,self.paragraph_text)
|
|
|
|
self.paragraph_directive = ""
|
|
|
|
self.paragraph_text = ""
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def start_table(self,name,style_name):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Begin new table."""
|
2004-03-04 02:20:06 +05:30
|
|
|
# initialize table, compute its width, find number of columns
|
2004-03-13 01:17:06 +05:30
|
|
|
self.table_data = []
|
|
|
|
self.in_table = 1
|
|
|
|
self.tbl_style = self.table_styles[style_name]
|
|
|
|
self.ncols = self.tbl_style.get_columns()
|
2004-03-02 06:06:53 +05:30
|
|
|
self.rownum = -1
|
2004-03-13 01:17:06 +05:30
|
|
|
self.table_width = (self.right_margin - self.left_margin) * \
|
|
|
|
self.tbl_style.get_width() / 100.0
|
|
|
|
self.cell_widths = []
|
|
|
|
self.cell_styles = []
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def end_table(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Close the table environment."""
|
2004-03-04 02:20:06 +05:30
|
|
|
# output table contents
|
2004-03-13 01:17:06 +05:30
|
|
|
self.output_table()
|
|
|
|
self.in_table = 0
|
|
|
|
self.y = self.advance_line(self.y)
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def start_row(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Begin a new row."""
|
2004-03-04 02:20:06 +05:30
|
|
|
# Initialize row, compute cell widths
|
2004-03-13 01:17:06 +05:30
|
|
|
self.row_data = []
|
2004-03-02 06:06:53 +05:30
|
|
|
self.rownum = self.rownum + 1
|
|
|
|
self.cellnum = -1
|
2004-03-13 01:17:06 +05:30
|
|
|
self.span = 1
|
|
|
|
self.cell_widths.append([0] * self.ncols)
|
|
|
|
self.cell_styles.append([None] * self.ncols)
|
|
|
|
for cell in range(self.ncols):
|
|
|
|
self.cell_widths[self.rownum][cell] = self.table_width * \
|
|
|
|
self.tbl_style.get_column_width(cell) / 100.0
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def end_row(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""End the row (new line)."""
|
2004-03-04 02:20:06 +05:30
|
|
|
# add row data to the data we have for the current table
|
2004-03-13 01:17:06 +05:30
|
|
|
self.table_data.append(self.row_data)
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
def start_cell(self,style_name,span=1):
|
2004-03-04 02:20:06 +05:30
|
|
|
"""Add an entry to the table."""
|
|
|
|
# Initialize a cell, take care of span>1 cases
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-13 01:17:06 +05:30
|
|
|
self.in_cell = 1
|
|
|
|
self.cell_data = []
|
|
|
|
self.cellnum = self.cellnum + self.span
|
|
|
|
self.span = span
|
|
|
|
self.cell_styles[self.rownum][self.cellnum] = \
|
2004-03-07 11:58:00 +05:30
|
|
|
self.cell_styles[style_name]
|
2004-03-13 01:17:06 +05:30
|
|
|
for extra_cell in range(1,span):
|
|
|
|
self.cell_widths[self.rownum][self.cellnum] += \
|
|
|
|
self.cell_widths[self.rownum][self.cellnum + extra_cell]
|
|
|
|
self.cell_widths[self.rownum][self.cellnum + extra_cell] = 0
|
2004-03-07 11:58:00 +05:30
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
def end_cell(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Prepares for next cell."""
|
2004-03-04 02:20:06 +05:30
|
|
|
# append the cell text to the row data
|
2004-03-13 01:17:06 +05:30
|
|
|
self.in_cell = 0
|
|
|
|
self.row_data.append(self.cell_data)
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-16 07:52:37 +05:30
|
|
|
def add_media_object(self,name,pos,x,y):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Add photo to report."""
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-07 11:58:00 +05:30
|
|
|
photo = GnomePrintPhoto(name,pos,x,y)
|
2004-03-13 01:17:06 +05:30
|
|
|
if self.in_cell:
|
2004-03-07 11:58:00 +05:30
|
|
|
# We're inside cell. Add photo to celldata
|
2004-03-13 01:17:06 +05:30
|
|
|
self.cell_data.append(photo)
|
2004-03-07 11:58:00 +05:30
|
|
|
else:
|
|
|
|
# photo not in table: write it right away
|
2004-03-13 01:17:06 +05:30
|
|
|
self.x, self.y = self.write_photo(photo,
|
|
|
|
self.x, self.y,
|
2004-03-07 11:58:00 +05:30
|
|
|
self.right_margin - self.left_margin)
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-07 11:58:00 +05:30
|
|
|
|
|
|
|
def write_photo(self,photo,x,y,width):
|
|
|
|
"""
|
|
|
|
Write the photo.
|
|
|
|
|
|
|
|
photo - GnomePrintPhoto instance
|
|
|
|
x,y - coordinates to start at
|
|
|
|
width - allocated width
|
|
|
|
"""
|
|
|
|
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-08 07:52:41 +05:30
|
|
|
# FIXME -- remove when gnome-python is released and hits every distro
|
|
|
|
if not support_photos:
|
|
|
|
return (x,y)
|
|
|
|
# end FIXME
|
|
|
|
|
2004-03-07 11:58:00 +05:30
|
|
|
width = photo.get_width()
|
|
|
|
height = photo.get_height()
|
|
|
|
|
|
|
|
if y - height < self.bottom_margin:
|
|
|
|
self.end_page()
|
|
|
|
self.start_page()
|
2004-03-13 01:17:06 +05:30
|
|
|
y = self.y
|
2004-03-07 11:58:00 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.gsave()
|
|
|
|
self.gpc.translate(x,y-height)
|
|
|
|
self.gpc.scale(width,height)
|
2004-03-07 11:58:00 +05:30
|
|
|
|
|
|
|
if photo.get_has_alpha():
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.rgbaimage(photo.get_image(),
|
2004-03-07 11:58:00 +05:30
|
|
|
photo.get_image_width(),
|
|
|
|
photo.get_image_height(),
|
|
|
|
photo.get_rowstride())
|
|
|
|
else:
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.rgbimage(photo.get_image(),
|
2004-03-07 11:58:00 +05:30
|
|
|
photo.get_image_width(),
|
|
|
|
photo.get_image_height(),
|
|
|
|
photo.get_rowstride())
|
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.grestore()
|
2004-03-07 11:58:00 +05:30
|
|
|
x = x
|
|
|
|
y = y - height
|
|
|
|
return (x,y)
|
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
def write_text(self,text):
|
2004-03-03 11:24:26 +05:30
|
|
|
"""Add the text to the paragraph"""
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-04 02:20:06 +05:30
|
|
|
# Take care of superscript tags
|
2004-03-03 21:42:26 +05:30
|
|
|
super_count = text.count('<super>')
|
|
|
|
for num in range(super_count):
|
|
|
|
start = text.find('<super>')
|
2004-03-13 01:17:06 +05:30
|
|
|
self.paragraph_text = self.paragraph_text + text[:start]
|
|
|
|
append_to_paragraph(self.paragraph,self.paragraph_directive,self.paragraph_text)
|
|
|
|
self.paragraph_text = ""
|
2004-03-03 21:42:26 +05:30
|
|
|
text = text[start+7:]
|
|
|
|
|
|
|
|
start = text.find('</super>')
|
2004-03-13 01:17:06 +05:30
|
|
|
self.paragraph_text = self.paragraph_text + text[:start]
|
|
|
|
append_to_paragraph(self.paragraph,_SUPER,self.paragraph_text)
|
|
|
|
self.paragraph_text = ""
|
2004-03-03 21:42:26 +05:30
|
|
|
text = text[start+8:]
|
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.paragraph_text = self.paragraph_text + text
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-02 10:27:00 +05:30
|
|
|
def write_note(self,text,format,style_name):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-02 10:27:00 +05:30
|
|
|
if format == 1:
|
|
|
|
for line in text.split('\n'):
|
|
|
|
self.start_paragraph(style_name)
|
2004-03-13 01:17:06 +05:30
|
|
|
self.paragraph_directive = _MONO
|
2004-03-02 10:27:00 +05:30
|
|
|
self.write_text(line)
|
|
|
|
self.end_paragraph()
|
|
|
|
elif format == 0:
|
|
|
|
for line in text.split('\n\n'):
|
|
|
|
self.start_paragraph(style_name)
|
|
|
|
line = line.replace('\n',' ')
|
|
|
|
line = string.join(string.split(line))
|
|
|
|
self.write_text(line)
|
|
|
|
self.end_paragraph()
|
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
#function to help us advance a line
|
2004-03-13 01:17:06 +05:30
|
|
|
def advance_line(self,y,paragraph=None):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-06 05:30:39 +05:30
|
|
|
if paragraph:
|
2004-03-10 07:40:34 +05:30
|
|
|
spacing = paragraph.fontstyle.get_size() * _EXTRA_SPACING_FACTOR
|
2004-03-06 05:30:39 +05:30
|
|
|
else:
|
|
|
|
spacing = _LINE_SPACING
|
|
|
|
new_y = y - spacing
|
2004-03-03 11:24:26 +05:30
|
|
|
if y < self.bottom_margin:
|
2004-03-13 01:17:06 +05:30
|
|
|
x = self.x
|
2004-03-03 11:24:26 +05:30
|
|
|
self.end_page()
|
|
|
|
self.start_page()
|
2004-03-13 01:17:06 +05:30
|
|
|
new_y = self.y
|
|
|
|
self.x = x
|
2004-03-03 11:24:26 +05:30
|
|
|
return new_y
|
2004-03-01 22:20:23 +05:30
|
|
|
|
2004-03-05 06:06:04 +05:30
|
|
|
def write_paragraph(self,paragraph,x,y,width):
|
2004-03-03 11:24:26 +05:30
|
|
|
"""
|
|
|
|
Write the contents of the paragraph, observing per-piece info.
|
|
|
|
|
|
|
|
paragraph - GnomePrintParagraph instance
|
|
|
|
x,y - coordinates to start at
|
2004-03-07 11:58:00 +05:30
|
|
|
width - allocated width
|
2004-03-03 11:24:26 +05:30
|
|
|
"""
|
2004-03-05 06:06:04 +05:30
|
|
|
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-05 08:31:21 +05:30
|
|
|
if not paragraph.get_piece_list():
|
|
|
|
return (x,y)
|
|
|
|
|
2004-03-06 05:30:39 +05:30
|
|
|
paragraph.format(width)
|
|
|
|
|
|
|
|
x = x + cm2u(paragraph.style.get_left_margin())
|
|
|
|
|
|
|
|
width = width - cm2u(paragraph.style.get_right_margin()) \
|
|
|
|
- cm2u(paragraph.style.get_left_margin())
|
|
|
|
|
2004-03-05 06:06:04 +05:30
|
|
|
left_margin = x
|
2004-03-05 08:31:21 +05:30
|
|
|
no_space = 0
|
2004-03-06 05:30:39 +05:30
|
|
|
first = 1
|
2004-03-02 07:05:53 +05:30
|
|
|
|
2004-03-10 07:40:34 +05:30
|
|
|
if y - paragraph.fontstyle.get_size() * _EXTRA_SPACING_FACTOR < self.bottom_margin:
|
2004-03-02 07:05:53 +05:30
|
|
|
self.end_page()
|
|
|
|
self.start_page()
|
2004-03-05 06:06:04 +05:30
|
|
|
x = left_margin
|
2004-03-13 01:17:06 +05:30
|
|
|
y = self.y
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-06 07:59:20 +05:30
|
|
|
if y != self.top_margin:
|
|
|
|
y = y - cm2u(paragraph.style.get_padding())
|
|
|
|
|
2004-03-05 08:31:21 +05:30
|
|
|
# Loop over lines which were assembled by paragraph.format()
|
2004-03-05 06:06:04 +05:30
|
|
|
for (start_piece,start_word,end_piece,end_word,avail_width) \
|
2004-03-06 05:30:39 +05:30
|
|
|
in paragraph.get_lines():
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-05 06:06:04 +05:30
|
|
|
if paragraph.get_alignment() == BaseDoc.PARA_ALIGN_CENTER:
|
|
|
|
x = x + 0.5 * avail_width
|
|
|
|
elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_RIGHT:
|
|
|
|
x = x + avail_width
|
|
|
|
elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_LEFT:
|
|
|
|
pass
|
|
|
|
elif paragraph.get_alignment() == BaseDoc.PARA_ALIGN_JUSTIFY:
|
2004-03-10 07:40:34 +05:30
|
|
|
print "LPRDoc: Paragraph justification not supported."
|
|
|
|
print " Falling back to left-justified mode."
|
2004-03-05 06:06:04 +05:30
|
|
|
|
2004-03-06 05:30:39 +05:30
|
|
|
if first:
|
|
|
|
first = 0
|
|
|
|
x = x + cm2u(paragraph.style.get_first_indent())
|
2004-03-10 07:40:34 +05:30
|
|
|
y = y - paragraph.fontstyle.get_size() * _EXTRA_SPACING_FACTOR
|
2004-03-06 05:30:39 +05:30
|
|
|
|
2004-03-05 08:31:21 +05:30
|
|
|
# Loop over pieces that constitute the line
|
2004-03-05 06:06:04 +05:30
|
|
|
for piece_num in range(start_piece,end_piece+1):
|
|
|
|
(directive,text) = paragraph.get_piece_list()[piece_num]
|
|
|
|
fontstyle = BaseDoc.FontStyle(paragraph.get_fontstyle())
|
|
|
|
if directive == _BOLD:
|
|
|
|
fontstyle.set_bold(1)
|
|
|
|
elif directive == _SUPER:
|
|
|
|
size = fontstyle.get_size()
|
2004-03-06 05:30:39 +05:30
|
|
|
fontstyle.set_size(size-_SUPER_SIZE_REDUCTION)
|
|
|
|
y = y + _SUPER_ELEVATION_FRACTION * fontstyle.get_size()
|
2004-03-05 10:41:07 +05:30
|
|
|
elif directive == _MONO:
|
|
|
|
fontstyle.set_type_face(BaseDoc.FONT_MONOSPACE)
|
2004-03-05 06:06:04 +05:30
|
|
|
|
|
|
|
textlist = text.split()
|
|
|
|
if start_piece == end_piece:
|
|
|
|
the_textlist = textlist[start_word:end_word]
|
|
|
|
elif piece_num > start_piece and piece_num < end_piece:
|
|
|
|
the_textlist = textlist[:]
|
|
|
|
elif piece_num == start_piece:
|
|
|
|
the_textlist = textlist[start_word:]
|
|
|
|
elif piece_num == end_piece:
|
|
|
|
the_textlist = textlist[:end_word]
|
|
|
|
|
|
|
|
the_text = string.join(the_textlist)
|
|
|
|
if piece_num == start_piece \
|
|
|
|
or directive == _SUPER \
|
2004-03-05 08:31:21 +05:30
|
|
|
or no_space \
|
|
|
|
or (the_text and the_text[0] in string.punctuation):
|
|
|
|
spacer = ""
|
2004-03-05 06:06:04 +05:30
|
|
|
else:
|
2004-03-05 08:31:21 +05:30
|
|
|
spacer = " "
|
|
|
|
the_text = spacer + the_text
|
2004-03-04 05:08:48 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.setfont(find_font_from_fontstyle(fontstyle))
|
|
|
|
self.gpc.moveto(x, y)
|
|
|
|
self.gpc.show(the_text)
|
2004-03-05 06:06:04 +05:30
|
|
|
x = x + get_text_width(the_text,fontstyle)
|
|
|
|
if directive == _SUPER:
|
2004-03-06 05:30:39 +05:30
|
|
|
y = y - _SUPER_ELEVATION_FRACTION * fontstyle.get_size()
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-05 08:31:21 +05:30
|
|
|
# If this was the linebreak, no space on the next line's start
|
|
|
|
if end_word:
|
|
|
|
no_space = 0
|
|
|
|
else:
|
|
|
|
no_space = 1
|
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
y = self.advance_line(y,paragraph)
|
2004-03-05 06:06:04 +05:30
|
|
|
x = left_margin
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-06 05:30:39 +05:30
|
|
|
x = x - cm2u(paragraph.style.get_left_margin())
|
2004-03-06 07:59:20 +05:30
|
|
|
y = y - cm2u(paragraph.style.get_padding())
|
2004-02-29 21:05:44 +05:30
|
|
|
return (x,y)
|
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
def output_table(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
"""Do calcs on data in table and output data in a formatted way."""
|
|
|
|
self.brand_new_page = 0
|
2004-03-13 01:17:06 +05:30
|
|
|
min_col_size = [0] * self.ncols
|
|
|
|
max_vspace = [0] * len(self.table_data)
|
|
|
|
|
|
|
|
for row_num in range(len(self.table_data)):
|
|
|
|
row = self.table_data[row_num][:]
|
|
|
|
#do calcs on each row and keep track on max length of each column
|
|
|
|
for col in range(self.ncols):
|
|
|
|
if not self.cell_widths[row_num][col]:
|
2004-03-02 10:27:00 +05:30
|
|
|
continue
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
padding = cm2u(self.cell_styles[row_num][col].get_padding())
|
|
|
|
the_max = 0
|
|
|
|
for paragraph in row[col]:
|
|
|
|
the_min = paragraph.get_min_width()
|
|
|
|
if the_min > min_col_size[col]:
|
|
|
|
min_col_size[col] = the_min
|
2004-03-03 11:24:26 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
the_max += paragraph.get_height(
|
|
|
|
self.cell_widths[row_num][col])
|
|
|
|
the_max += 2 * padding
|
|
|
|
if the_max > max_vspace[row_num]:
|
|
|
|
max_vspace[row_num] = the_max
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-04 05:08:48 +05:30
|
|
|
#is table width larger than the width of the paper?
|
2004-03-13 01:17:06 +05:30
|
|
|
min_table_width = 0
|
|
|
|
for size in min_col_size:
|
|
|
|
min_table_width = min_table_width + size
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
if min_table_width > (self.right_margin - self.left_margin):
|
2004-03-10 07:40:34 +05:30
|
|
|
print "LPRDoc: Table does not fit onto the page."
|
2004-03-03 22:29:47 +05:30
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
#for now we will assume left justification of tables
|
|
|
|
#output data in table
|
2004-03-13 01:17:06 +05:30
|
|
|
for row_num in range(len(self.table_data)):
|
|
|
|
row = self.table_data[row_num]
|
2004-03-01 22:20:23 +05:30
|
|
|
# If this row puts us below the bottom, start new page here
|
2004-03-13 01:17:06 +05:30
|
|
|
if self.y - max_vspace[row_num] < self.bottom_margin:
|
2004-03-03 11:24:26 +05:30
|
|
|
self.end_page()
|
|
|
|
self.start_page()
|
2004-03-05 06:06:04 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
x = self.left_margin #reset so that x is at margin
|
|
|
|
col_y = self.y # all columns start at the same height
|
|
|
|
for col in range(self.ncols):
|
|
|
|
if not self.cell_widths[row_num][col]:
|
2004-03-02 10:27:00 +05:30
|
|
|
continue
|
2004-03-13 01:17:06 +05:30
|
|
|
self.y = col_y
|
|
|
|
padding = cm2u(self.cell_styles [row_num][col].get_padding())
|
|
|
|
for paragraph in row[col]:
|
2004-03-07 11:58:00 +05:30
|
|
|
if paragraph.__class__.__name__ == 'GnomePrintPhoto':
|
|
|
|
write_item = self.write_photo
|
|
|
|
else:
|
|
|
|
write_item = self.write_paragraph
|
2004-03-13 01:17:06 +05:30
|
|
|
junk, self.y = write_item(paragraph,
|
|
|
|
x + padding, self.y - padding,
|
|
|
|
self.cell_widths[row_num][col] \
|
2004-03-07 11:58:00 +05:30
|
|
|
- 2 * padding)
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
x = x + self.cell_widths[row_num][col] # set up margin for this row
|
|
|
|
self.y = col_y - max_vspace[row_num]
|
2004-02-29 21:05:44 +05:30
|
|
|
|
2004-03-08 07:52:41 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Graphic methods
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def horizontal_line(self):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.moveto(self.left_margin, self.y)
|
|
|
|
self.gpc.lineto(self.right_margin, self.y)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
def draw_path(self,style,path):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-08 07:52:41 +05:30
|
|
|
stype = self.draw_styles[style]
|
|
|
|
color = [ val/255.0 for val in stype.get_fill_color()]
|
|
|
|
|
|
|
|
point = path[0]
|
|
|
|
x = cm2u(point[0]) + self.left_margin
|
|
|
|
y = self.top_margin - cm2u(point[1])
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.moveto(x,y)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
for point in path[1:]:
|
|
|
|
x = cm2u(point[0]) + self.left_margin
|
|
|
|
y = self.top_margin - cm2u(point[1])
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.lineto(x,y)
|
|
|
|
self.gpc.closepath()
|
|
|
|
self.gpc.stroke()
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
point = path[0]
|
|
|
|
x = cm2u(point[0]) + self.left_margin
|
|
|
|
y = self.top_margin - cm2u(point[1])
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.moveto(x,y)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
for point in path[1:]:
|
|
|
|
x = cm2u(point[0]) + self.left_margin
|
|
|
|
y = self.top_margin - cm2u(point[1])
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.lineto(x,y)
|
|
|
|
self.gpc.closepath()
|
2004-03-08 07:52:41 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.setrgbcolor(color[0],color[1],color[2])
|
|
|
|
self.gpc.fill()
|
|
|
|
self.gpc.setrgbcolor(0,0,0)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
def draw_box(self,style,text,x,y):
|
|
|
|
#assuming that we start drawing box from current position
|
|
|
|
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-08 07:52:41 +05:30
|
|
|
x = self.left_margin + cm2u(x)
|
|
|
|
y = self.top_margin - cm2u(y)
|
|
|
|
|
|
|
|
box_style = self.draw_styles[style]
|
|
|
|
para_name = box_style.get_paragraph_style()
|
|
|
|
para_style = self.style_list[para_name]
|
|
|
|
fontstyle = para_style.get_font()
|
|
|
|
bh = cm2u(box_style.get_height())
|
|
|
|
bw = cm2u(box_style.get_width())
|
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.rect_stroked(x,y,bw,-bh)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
if text:
|
|
|
|
lines = text.split('\n')
|
|
|
|
start_x = x + 0.5 * fontstyle.get_size()
|
2004-03-10 07:40:34 +05:30
|
|
|
start_y = y - fontstyle.get_size() * _EXTRA_SPACING_FACTOR
|
2004-03-08 07:52:41 +05:30
|
|
|
for line in lines:
|
|
|
|
if not line.split():
|
|
|
|
continue
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.setfont(find_font_from_fontstyle(fontstyle))
|
|
|
|
self.gpc.moveto(start_x,start_y)
|
|
|
|
self.gpc.show(line)
|
2004-03-10 07:40:34 +05:30
|
|
|
start_y -= fontstyle.get_size() * _EXTRA_SPACING_FACTOR
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
def write_at (self, style, text, x, y):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-08 07:52:41 +05:30
|
|
|
para_style = self.style_list[style]
|
|
|
|
fontstyle = para_style.get_font()
|
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.setfont(find_font_from_fontstyle(fontstyle))
|
|
|
|
self.gpc.moveto(cm2u(x), cm2u(y))
|
|
|
|
self.gpc.show(text)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
def draw_bar(self, style, x1, y1, x2, y2):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.moveto(x1, y1)
|
|
|
|
self.gpc.lineto(x2, y2)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
def draw_text(self,style,text,x,y):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-08 07:52:41 +05:30
|
|
|
box_style = self.draw_styles[style]
|
|
|
|
para_name = box_style.get_paragraph_style()
|
|
|
|
para_style = self.style_list[para_name]
|
|
|
|
fontstyle = para_style.get_font()
|
|
|
|
|
|
|
|
start_x = self.left_margin + cm2u(x)
|
2004-03-10 07:40:34 +05:30
|
|
|
start_y = self.top_margin - cm2u(y) - fontstyle.get_size() * _EXTRA_SPACING_FACTOR
|
2004-03-08 07:52:41 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.setfont(find_font_from_fontstyle(fontstyle))
|
|
|
|
self.gpc.moveto(start_x,start_y)
|
|
|
|
self.gpc.show(text)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
def center_text(self,style,text,x,y):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-08 07:52:41 +05:30
|
|
|
box_style = self.draw_styles[style]
|
|
|
|
para_name = box_style.get_paragraph_style()
|
|
|
|
para_style = self.style_list[para_name]
|
|
|
|
fontstyle = para_style.get_font()
|
|
|
|
|
|
|
|
width = get_text_width(text,fontstyle)
|
|
|
|
start_x = self.left_margin + cm2u(x) - 0.5 * width
|
2004-03-10 07:40:34 +05:30
|
|
|
start_y = self.top_margin - cm2u(y) \
|
|
|
|
- fontstyle.get_size() * _EXTRA_SPACING_FACTOR
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.setfont(find_font_from_fontstyle(fontstyle))
|
|
|
|
self.gpc.moveto(start_x, start_y)
|
|
|
|
self.gpc.show(text)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
def rotate_text(self,style,text,x,y,angle):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-08 07:52:41 +05:30
|
|
|
# FIXME - remove when new gnome-python is in all distros
|
|
|
|
if not support_photos:
|
|
|
|
return
|
|
|
|
# end FIXME
|
|
|
|
box_style = self.draw_styles[style]
|
|
|
|
para_name = box_style.get_paragraph_style()
|
|
|
|
para_style = self.style_list[para_name]
|
|
|
|
fontstyle = para_style.get_font()
|
|
|
|
|
|
|
|
y_start = self.top_margin - cm2u(y)
|
|
|
|
x_start = self.left_margin + cm2u(x)
|
|
|
|
size = fontstyle.get_size()
|
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.gsave()
|
|
|
|
self.gpc.translate(x_start,y_start)
|
|
|
|
self.gpc.rotate(-angle)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
this_y = 0
|
|
|
|
for line in text:
|
|
|
|
if not line.split():
|
|
|
|
continue
|
|
|
|
width = get_text_width(line,fontstyle)
|
|
|
|
this_x = -0.5 * width
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.setfont(find_font_from_fontstyle(fontstyle))
|
|
|
|
self.gpc.moveto(this_x,this_y)
|
|
|
|
self.gpc.show(line)
|
2004-03-10 07:40:34 +05:30
|
|
|
this_y -= size * _EXTRA_SPACING_FACTOR
|
2004-03-08 07:52:41 +05:30
|
|
|
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.grestore()
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
def draw_line(self,style,x1,y1,x2,y2):
|
2004-03-10 07:40:34 +05:30
|
|
|
self.brand_new_page = 0
|
2004-03-08 07:52:41 +05:30
|
|
|
x1 = cm2u(x1) + self.left_margin
|
|
|
|
x2 = cm2u(x2) + self.left_margin
|
|
|
|
y1 = self.top_margin - cm2u(y1)
|
|
|
|
y2 = self.top_margin - cm2u(y2)
|
2004-03-13 01:17:06 +05:30
|
|
|
self.gpc.line_stroked(x1,y1,x2,y2)
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Print job methods
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
2004-02-29 21:05:44 +05:30
|
|
|
#function to print text to a printer
|
2004-03-13 01:17:06 +05:30
|
|
|
def do_print(self,dialog,job):
|
2004-03-16 04:30:36 +05:30
|
|
|
self.gpc = gnomeprint.Context(dialog.get_config())
|
|
|
|
job.render(self.gpc)
|
|
|
|
self.gpc.close()
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
#I believe this is a print preview
|
2004-03-13 01:17:06 +05:30
|
|
|
def show_preview(self,dialog):
|
|
|
|
w = gnomeprint.ui.JobPreview(self.job, _("Print Preview"))
|
|
|
|
w.set_property('allow-grow', 1)
|
|
|
|
w.set_property('allow-shrink', 1)
|
|
|
|
w.set_transient_for(dialog)
|
|
|
|
w.show_all()
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
#function used to get users response and do a certain
|
|
|
|
#action depending on that response
|
2004-03-13 01:17:06 +05:30
|
|
|
def print_dialog_response(self, dialog, resp, job):
|
2004-02-29 21:05:44 +05:30
|
|
|
if resp == gnomeprint.ui.DIALOG_RESPONSE_PREVIEW:
|
2004-03-13 01:17:06 +05:30
|
|
|
self.show_preview(dialog)
|
2004-02-29 21:05:44 +05:30
|
|
|
elif resp == gnomeprint.ui.DIALOG_RESPONSE_CANCEL:
|
|
|
|
dialog.destroy()
|
|
|
|
elif resp == gnomeprint.ui.DIALOG_RESPONSE_PRINT:
|
2004-03-13 01:17:06 +05:30
|
|
|
self.do_print(dialog, self.job)
|
2004-02-29 21:05:44 +05:30
|
|
|
dialog.destroy()
|
|
|
|
|
|
|
|
#function displays a window that allows user to choose
|
|
|
|
#to print, show, etc
|
2004-03-13 01:17:06 +05:30
|
|
|
def show_print_dialog(self):
|
|
|
|
dialog = gnomeprint.ui.Dialog(self.job, _("Print..."),
|
|
|
|
gnomeprint.ui.DIALOG_RANGE|gnomeprint.ui.DIALOG_COPIES)
|
|
|
|
dialog.construct_range_page(
|
|
|
|
gnomeprint.ui.RANGE_ALL|gnomeprint.ui.RANGE_RANGE,
|
|
|
|
1, self.page_count, "A", "Pages: ")
|
|
|
|
dialog.connect('response', self.print_dialog_response, self.job)
|
|
|
|
dialog.show()
|
2004-02-29 21:05:44 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register the document generator with the system
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
Plugins.register_text_doc(
|
|
|
|
name=_("Print..."),
|
|
|
|
classref=LPRDoc,
|
|
|
|
table=1,
|
|
|
|
paper=1,
|
2004-03-02 06:06:53 +05:30
|
|
|
style=1,
|
2004-02-29 21:05:44 +05:30
|
|
|
ext=""
|
|
|
|
)
|
2004-03-07 11:58:00 +05:30
|
|
|
|
|
|
|
Plugins.register_book_doc(
|
|
|
|
_("Print..."),
|
|
|
|
LPRDoc,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
"")
|
2004-03-08 07:52:41 +05:30
|
|
|
|
|
|
|
Plugins.register_draw_doc(
|
|
|
|
_("Print..."),
|
|
|
|
LPRDoc,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
"");
|