6883: non-Western fonts broken in PS reports
Replace PSDrawDoc with an almost identical twin of PdfDoc. runtest.sh now aware that the new backend produces text reports. svn: r22803
This commit is contained in:
parent
91a9126876
commit
2acb205ed0
@ -1,10 +1,9 @@
|
|||||||
#
|
#
|
||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
# Copyright (C) 2007 Zsolt Foldvari
|
||||||
# Copyright (C) 2007-2009 Brian G. Matherly
|
# Copyright (C) 2008 Brian G. Matherly
|
||||||
# Copyright (C) 2010 Jakim Friant
|
# Copyright (C) 2013 Vassilii Khachaturov
|
||||||
# Copyright (C) 2011 Adam Stein <adam@csh.rit.edu>
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -23,371 +22,266 @@
|
|||||||
|
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
"""
|
"""PS output generator based on Cairo.
|
||||||
PostScript document generator.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# python modules
|
# Python modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
from gen.ggettext import gettext as _
|
from gen.ggettext import gettext as _
|
||||||
|
import sys
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#Gramps modules
|
#
|
||||||
#-------------------------------------------------------------------------
|
# Gramps modules
|
||||||
from gen.plug.report import utils as ReportUtils
|
#
|
||||||
from gen.plug.docgen import BaseDoc, DrawDoc, FONT_SERIF, PAPER_PORTRAIT, SOLID
|
#------------------------------------------------------------------------
|
||||||
from gen.plug.utils import gformat
|
import libcairodoc
|
||||||
|
from gen.plug.docgen import INDEX_TYPE_ALP, INDEX_TYPE_TOC
|
||||||
import Errors
|
import Errors
|
||||||
|
|
||||||
def lrgb(grp):
|
#------------------------------------------------------------------------
|
||||||
grp = ReportUtils.rgb_color(grp)
|
#
|
||||||
return (gformat(grp[0]), gformat(grp[1]), gformat(grp[2]))
|
# Set up logging
|
||||||
|
#
|
||||||
def coords(grp):
|
#------------------------------------------------------------------------
|
||||||
return (gformat(grp[0]), gformat(grp[1]))
|
import logging
|
||||||
|
LOG = logging.getLogger(".PSDrawDoc")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# PSDrawDoc
|
# GTK modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class PSDrawDoc(BaseDoc, DrawDoc):
|
import pango
|
||||||
|
import cairo
|
||||||
|
import pangocairo
|
||||||
|
|
||||||
def __init__(self, styles, type):
|
#------------------------------------------------------------------------
|
||||||
BaseDoc.__init__(self, styles, type)
|
#
|
||||||
self.file = None
|
# Constants
|
||||||
self.filename = None
|
#
|
||||||
self.level = 0
|
#------------------------------------------------------------------------
|
||||||
self.page = 0
|
|
||||||
|
|
||||||
def fontdef(self, para):
|
# resolution
|
||||||
font = para.get_font()
|
DPI = 72.0
|
||||||
if font.get_type_face() == FONT_SERIF:
|
|
||||||
font_name = "/Times"
|
|
||||||
if font.get_bold():
|
|
||||||
font_name += "-Bold"
|
|
||||||
if font.get_italic():
|
|
||||||
font_name += "Italic"
|
|
||||||
elif font.get_italic():
|
|
||||||
font_name += "-Italic"
|
|
||||||
else:
|
|
||||||
font_name += "-Roman"
|
|
||||||
|
|
||||||
else: # Use a font without serifs
|
#------------------------------------------------------------------------
|
||||||
font_name = "/Helvetica"
|
#
|
||||||
if font.get_bold():
|
# PSDrawDoc class
|
||||||
font_name += "-Bold"
|
#
|
||||||
if font.get_italic():
|
#------------------------------------------------------------------------
|
||||||
font_name += "Oblique"
|
class PSDrawDoc(libcairodoc.CairoDoc):
|
||||||
elif font.get_italic():
|
"""Render the document into PS file using Cairo.
|
||||||
font_name += "-Oblique"
|
|
||||||
|
|
||||||
return "%s find-latin-font %d scalefont setfont\n" % \
|
|
||||||
(font_name, font.get_size())
|
|
||||||
|
|
||||||
def translate(self, x, y):
|
|
||||||
return (x, self.paper.get_size().get_height() - y)
|
|
||||||
|
|
||||||
def open(self, filename):
|
|
||||||
"""
|
"""
|
||||||
Opens the file so that it can be generated.
|
EXT = 'ps'
|
||||||
|
|
||||||
@param filename: path name of the file to create
|
def run(self):
|
||||||
|
"""Create the PS output.
|
||||||
"""
|
"""
|
||||||
self.filename = filename
|
# get paper dimensions
|
||||||
if not filename.endswith(".ps"):
|
paper_width = self.paper.get_size().get_width() * DPI / 2.54
|
||||||
self.filename += ".ps"
|
paper_height = self.paper.get_size().get_height() * DPI / 2.54
|
||||||
|
page_width = round(self.paper.get_usable_width() * DPI / 2.54)
|
||||||
|
page_height = round(self.paper.get_usable_height() * DPI / 2.54)
|
||||||
|
left_margin = self.paper.get_left_margin() * DPI / 2.54
|
||||||
|
top_margin = self.paper.get_top_margin() * DPI / 2.54
|
||||||
|
|
||||||
|
# create cairo context and pango layout
|
||||||
|
filename = self._backend.filename.encode(sys.getfilesystemencoding())
|
||||||
try:
|
try:
|
||||||
self.file = open(self.filename,"w")
|
surface = cairo.PSSurface(filename, paper_width, paper_height)
|
||||||
except IOError,msg:
|
except IOError,msg:
|
||||||
errmsg = "%s\n%s" % (_("Could not create %s") % self.filename, msg)
|
errmsg = "%s\n%s" % (_("Could not create %s") % filename, msg)
|
||||||
raise Errors.ReportError(errmsg)
|
raise Errors.ReportError(errmsg)
|
||||||
except:
|
except:
|
||||||
raise Errors.ReportError(_("Could not create %s") % self.filename)
|
raise Errors.ReportError(_("Could not create %s") % filename)
|
||||||
|
surface.set_fallback_resolution(300, 300)
|
||||||
|
cr = pangocairo.CairoContext(cairo.Context(surface))
|
||||||
|
|
||||||
self.file.write(
|
fontmap = pangocairo.cairo_font_map_get_default()
|
||||||
'%!PS-Adobe-3.0\n'
|
saved_resolution = fontmap.get_resolution()
|
||||||
'%%LanguageLevel: 2\n'
|
fontmap.set_resolution(DPI)
|
||||||
'%%Pages: (atend)\n'
|
|
||||||
'%%PageOrder: Ascend\n'
|
pango_context = fontmap.create_context()
|
||||||
'%%Orientation: '
|
options = cairo.FontOptions()
|
||||||
)
|
options.set_hint_metrics(cairo.HINT_METRICS_OFF)
|
||||||
if self.paper.get_orientation() != PAPER_PORTRAIT:
|
pangocairo.context_set_font_options(pango_context, options)
|
||||||
self.file.write('Landscape\n')
|
layout = pango.Layout(pango_context)
|
||||||
|
cr.update_context(pango_context)
|
||||||
|
|
||||||
|
# paginate the document
|
||||||
|
self.paginate_document(layout, page_width, page_height, DPI, DPI)
|
||||||
|
body_pages = self._pages
|
||||||
|
|
||||||
|
# build the table of contents and alphabetical index
|
||||||
|
toc_page = None
|
||||||
|
index_page = None
|
||||||
|
toc = []
|
||||||
|
index = {}
|
||||||
|
for page_nr, page in enumerate(body_pages):
|
||||||
|
if page.has_toc():
|
||||||
|
toc_page = page_nr
|
||||||
|
if page.has_index():
|
||||||
|
index_page = page_nr
|
||||||
|
for mark in page.get_marks():
|
||||||
|
if mark.type == INDEX_TYPE_ALP:
|
||||||
|
if mark.key in index:
|
||||||
|
if page_nr + 1 not in index[mark.key]:
|
||||||
|
index[mark.key].append(page_nr + 1)
|
||||||
else:
|
else:
|
||||||
self.file.write('Portrait\n')
|
index[mark.key] = [page_nr + 1]
|
||||||
self.file.write(
|
elif mark.type == INDEX_TYPE_TOC:
|
||||||
'%%EndComments\n'
|
toc.append([mark, page_nr + 1])
|
||||||
'/cm { 28.34 mul } def\n'
|
|
||||||
'% build iso-latin-1 version of a font\n'
|
|
||||||
'/font-to-iso-latin-1 { % <font> font-to-iso-latin-1 <font>\n'
|
|
||||||
'%% reencode for iso latin1; from the 2nd edition red book, sec 5.6.1\n'
|
|
||||||
'dup length dict begin {1 index /FID ne {def} {pop pop} ifelse} forall\n'
|
|
||||||
'/Encoding ISOLatin1Encoding def currentdict end\n'
|
|
||||||
'dup /FontName get 80 string cvs (-ISOLatin1) concatstrings cvn \n'
|
|
||||||
'exch definefont\n'
|
|
||||||
'} def\n'
|
|
||||||
'\n'
|
|
||||||
'/find-latin-font { % <name> find-latin-font <font>\n'
|
|
||||||
'findfont font-to-iso-latin-1\n'
|
|
||||||
'} def\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
self.filename = filename
|
# paginate the table of contents
|
||||||
|
rebuild_required = False
|
||||||
def close(self):
|
if toc_page is not None:
|
||||||
self.file.write(
|
toc_pages = self.__generate_toc(layout, page_width, page_height,
|
||||||
'%%Trailer\n'
|
toc)
|
||||||
'%%Pages: ' +
|
offset = len(toc_pages) - 1
|
||||||
'%d\n' % self.page +
|
if offset > 0:
|
||||||
'%%EOF\n'
|
self.__increment_pages(toc, index, toc_page, offset)
|
||||||
)
|
rebuild_required = True
|
||||||
self.file.close()
|
|
||||||
|
|
||||||
def write_text(self, text, mark=None, links=False):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def start_page(self):
|
|
||||||
self.page += 1
|
|
||||||
self.file.write(
|
|
||||||
"%%Page:" +
|
|
||||||
"%d %d\n" % (self.page, self.page)
|
|
||||||
)
|
|
||||||
if self.paper.get_orientation() != PAPER_PORTRAIT:
|
|
||||||
self.file.write('90 rotate %s cm %s cm translate\n' % (
|
|
||||||
gformat(0),gformat(-1*self.paper.get_size().get_height())))
|
|
||||||
|
|
||||||
def end_page(self):
|
|
||||||
self.file.write(
|
|
||||||
'showpage\n'
|
|
||||||
'%%PageTrailer\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
def encode(self, text):
|
|
||||||
try:
|
|
||||||
orig = unicode(text)
|
|
||||||
new_text = orig.encode('iso-8859-1')
|
|
||||||
except:
|
|
||||||
new_text = "?" * len(text)
|
|
||||||
return new_text
|
|
||||||
|
|
||||||
def encode_text(self, p, text):
|
|
||||||
fdef = self.fontdef(p)
|
|
||||||
new_text = self.encode(text)
|
|
||||||
return (new_text, fdef)
|
|
||||||
|
|
||||||
def center_text(self, style, text, x, y):
|
|
||||||
style_sheet = self.get_style_sheet()
|
|
||||||
stype = style_sheet.get_draw_style(style)
|
|
||||||
pname = stype.get_paragraph_style()
|
|
||||||
p = style_sheet.get_paragraph_style(pname)
|
|
||||||
|
|
||||||
x += self.paper.get_left_margin()
|
|
||||||
y += self.paper.get_top_margin() + ReportUtils.pt2cm(p.get_font().get_size())
|
|
||||||
|
|
||||||
(text, fdef) = self.encode_text(p, text)
|
|
||||||
|
|
||||||
self.file.write(
|
|
||||||
'gsave\n'
|
|
||||||
'%s %s %s setrgbcolor\n' % lrgb(stype.get_color()) +
|
|
||||||
fdef +
|
|
||||||
'(%s) dup stringwidth pop -2 div ' % text +
|
|
||||||
'%s cm add %s cm moveto ' % coords(self.translate(x, y)) +
|
|
||||||
'show\n'
|
|
||||||
'grestore\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
def draw_text(self, style, text, x1, y1):
|
|
||||||
style_sheet = self.get_style_sheet()
|
|
||||||
stype = style_sheet.get_draw_style(style)
|
|
||||||
pname = stype.get_paragraph_style()
|
|
||||||
p = style_sheet.get_paragraph_style(pname)
|
|
||||||
|
|
||||||
x1 += self.paper.get_left_margin()
|
|
||||||
y1 += self.paper.get_top_margin() + ReportUtils.pt2cm(p.get_font().get_size())
|
|
||||||
|
|
||||||
(text, fdef) = self.encode_text(p, text)
|
|
||||||
|
|
||||||
self.file.write(
|
|
||||||
'gsave\n'
|
|
||||||
'%s cm %s cm moveto\n' % coords(self.translate(x1, y1)) +
|
|
||||||
fdef +
|
|
||||||
'(%s) show grestore\n' % text
|
|
||||||
)
|
|
||||||
|
|
||||||
def rotate_text(self, style, text, x, y, angle):
|
|
||||||
|
|
||||||
x += self.paper.get_left_margin()
|
|
||||||
y += self.paper.get_top_margin()
|
|
||||||
|
|
||||||
style_sheet = self.get_style_sheet()
|
|
||||||
stype = style_sheet.get_draw_style(style)
|
|
||||||
pname = stype.get_paragraph_style()
|
|
||||||
p = style_sheet.get_paragraph_style(pname)
|
|
||||||
font = p.get_font()
|
|
||||||
|
|
||||||
size = font.get_size()
|
|
||||||
|
|
||||||
(new_text, fdef) = self.encode_text(p, text[0])
|
|
||||||
|
|
||||||
coords = self.translate(x, y)
|
|
||||||
self.file.write(
|
|
||||||
'gsave\n' +
|
|
||||||
fdef +
|
|
||||||
'%s cm %s cm translate\n' % (
|
|
||||||
gformat(coords[0]), gformat(coords[1])) +
|
|
||||||
'%s rotate\n' % gformat(-angle) +
|
|
||||||
'%s %s %s setrgbcolor\n' % lrgb(stype.get_color())
|
|
||||||
)
|
|
||||||
|
|
||||||
y = ((size * len(text)) / 2.0) - size
|
|
||||||
|
|
||||||
for line in text:
|
|
||||||
self.file.write(
|
|
||||||
'(%s) dup stringwidth pop -2 div '
|
|
||||||
% self.encode(line) +
|
|
||||||
"%s moveto show\n" % gformat(y)
|
|
||||||
)
|
|
||||||
y -= size
|
|
||||||
|
|
||||||
self.file.write('grestore\n')
|
|
||||||
|
|
||||||
def draw_path(self, style, path):
|
|
||||||
style_sheet = self.get_style_sheet()
|
|
||||||
stype = style_sheet.get_draw_style(style)
|
|
||||||
self.file.write(
|
|
||||||
'gsave\n'
|
|
||||||
'newpath\n'
|
|
||||||
'%s setlinewidth\n' % gformat(stype.get_line_width())
|
|
||||||
)
|
|
||||||
if stype.get_line_style() == SOLID:
|
|
||||||
self.file.write('[] 0 setdash\n')
|
|
||||||
else:
|
else:
|
||||||
dash_style = stype.get_dash_style(stype.get_line_style())
|
toc_pages = []
|
||||||
self.file.write('[%s] 0 setdash\n' % (
|
|
||||||
" ".join(map(str, dash_style)))
|
|
||||||
)
|
|
||||||
|
|
||||||
point = path[0]
|
# paginate the index
|
||||||
x1 = point[0] + self.paper.get_left_margin()
|
if index_page is not None:
|
||||||
y1 = point[1] + self.paper.get_top_margin()
|
index_pages = self.__generate_index(layout, page_width, page_height,
|
||||||
self.file.write(
|
index)
|
||||||
'%s cm %s cm moveto\n' % coords(self.translate(x1, y1))
|
offset = len(index_pages) - 1
|
||||||
)
|
if offset > 0:
|
||||||
|
self.__increment_pages(toc, index, index_page, offset)
|
||||||
for point in path[1:]:
|
rebuild_required = True
|
||||||
x1 = point[0] + self.paper.get_left_margin()
|
|
||||||
y1 = point[1] + self.paper.get_top_margin()
|
|
||||||
self.file.write(
|
|
||||||
'%s cm %s cm lineto\n' % coords(self.translate(x1, y1))
|
|
||||||
)
|
|
||||||
self.file.write('closepath\n')
|
|
||||||
|
|
||||||
color = stype.get_fill_color()
|
|
||||||
self.file.write(
|
|
||||||
'gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(color) +
|
|
||||||
'%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()) +
|
|
||||||
'grestore\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
def draw_line(self, style, x1, y1, x2, y2):
|
|
||||||
x1 += self.paper.get_left_margin()
|
|
||||||
x2 += self.paper.get_left_margin()
|
|
||||||
y1 += self.paper.get_top_margin()
|
|
||||||
y2 += self.paper.get_top_margin()
|
|
||||||
style_sheet = self.get_style_sheet()
|
|
||||||
stype = style_sheet.get_draw_style(style)
|
|
||||||
self.file.write(
|
|
||||||
'gsave newpath\n'
|
|
||||||
'%s cm %s cm moveto\n' % coords(self.translate(x1, y1)) +
|
|
||||||
'%s cm %s cm lineto\n' % coords(self.translate(x2, y2)) +
|
|
||||||
'%s setlinewidth\n' % gformat(stype.get_line_width())
|
|
||||||
)
|
|
||||||
if stype.get_line_style() == SOLID:
|
|
||||||
self.file.write('[] 0 setdash\n')
|
|
||||||
else:
|
else:
|
||||||
dash_style = stype.get_dash_style(stype.get_line_style())
|
index_pages = []
|
||||||
self.file.write('[%s] 0 setdash\n' % (
|
|
||||||
" ".join(map(str, dash_style)))
|
|
||||||
)
|
|
||||||
|
|
||||||
self.file.write(
|
# rebuild the table of contents and index if required
|
||||||
'2 setlinecap\n' +
|
if rebuild_required:
|
||||||
'%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()) +
|
if toc_page is not None:
|
||||||
'grestore\n'
|
toc_pages = self.__generate_toc(layout, page_width, page_height,
|
||||||
)
|
toc)
|
||||||
|
if index_page is not None:
|
||||||
|
index_pages = self.__generate_index(layout, page_width,
|
||||||
|
page_height, index)
|
||||||
|
|
||||||
def draw_box(self, style, text, x, y, w, h):
|
# render the pages
|
||||||
x += self.paper.get_left_margin()
|
if toc_page is not None:
|
||||||
y += self.paper.get_top_margin()
|
body_pages = body_pages[:toc_page] + toc_pages + \
|
||||||
|
body_pages[toc_page+1:]
|
||||||
|
if index_page is not None:
|
||||||
|
body_pages = body_pages[:index_page] + index_pages + \
|
||||||
|
body_pages[index_page+1:]
|
||||||
|
self._pages = body_pages
|
||||||
|
for page_nr in range(len(self._pages)):
|
||||||
|
cr.save()
|
||||||
|
cr.translate(left_margin, top_margin)
|
||||||
|
self.draw_page(page_nr, cr, layout,
|
||||||
|
page_width, page_height,
|
||||||
|
DPI, DPI)
|
||||||
|
cr.show_page()
|
||||||
|
cr.restore()
|
||||||
|
|
||||||
style_sheet = self.get_style_sheet()
|
# close the surface (file)
|
||||||
box_style = style_sheet.get_draw_style(style)
|
surface.finish()
|
||||||
|
|
||||||
self.file.write('gsave\n')
|
# Restore the resolution. On windows, Gramps UI fonts will be smaller
|
||||||
|
# if we don't restore the resolution.
|
||||||
|
fontmap.set_resolution(saved_resolution)
|
||||||
|
|
||||||
shadsize = box_style.get_shadow_space()
|
def __increment_pages(self, toc, index, start_page, offset):
|
||||||
if box_style.get_shadow():
|
"""
|
||||||
self.file.write(
|
Increment the page numbers in the table of contents and index.
|
||||||
'newpath\n'
|
"""
|
||||||
'%s cm %s cm moveto\n'
|
for n, value in enumerate(toc):
|
||||||
% coords(self.translate(x+shadsize, y+shadsize)) +
|
page_nr = toc[n][1]
|
||||||
'0 -%s cm rlineto\n' % gformat(h) +
|
toc[n][1] = page_nr + (offset if page_nr > start_page else 0)
|
||||||
'%s cm 0 rlineto\n' % gformat(w) +
|
for key, value in index.iteritems():
|
||||||
'0 %s cm rlineto\n' % gformat(h) +
|
index[key] = [page_nr + (offset if page_nr > start_page else 0)
|
||||||
'closepath\n'
|
for page_nr in value]
|
||||||
'.5 setgray\n'
|
|
||||||
'fill\n'
|
|
||||||
)
|
|
||||||
self.file.write(
|
|
||||||
'newpath\n'
|
|
||||||
'%s cm %s cm moveto\n' % coords(self.translate(x, y)) +
|
|
||||||
'0 -%s cm rlineto\n' % gformat(h) +
|
|
||||||
'%s cm 0 rlineto\n' % gformat(w) +
|
|
||||||
'0 %s cm rlineto\n' % gformat(h) +
|
|
||||||
'closepath\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
fill_color = box_style.get_fill_color()
|
def __generate_toc(self, layout, page_width, page_height, toc):
|
||||||
color = box_style.get_color()
|
"""
|
||||||
self.file.write(
|
Generate the table of contents.
|
||||||
'gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(fill_color) +
|
"""
|
||||||
'%s %s %s setrgbcolor stroke\n' % lrgb(color)
|
self._doc = libcairodoc.GtkDocDocument()
|
||||||
)
|
self._active_element = self._doc
|
||||||
|
self._pages = []
|
||||||
|
write_toc(toc, self)
|
||||||
|
self.paginate_document(layout, page_width, page_height, DPI, DPI)
|
||||||
|
return self._pages
|
||||||
|
|
||||||
self.file.write('newpath\n')
|
def __generate_index(self, layout, page_width, page_height, index):
|
||||||
if box_style.get_line_width():
|
"""
|
||||||
self.file.write(
|
Generate the index.
|
||||||
'%s cm %s cm moveto\n' % coords(self.translate(x, y)) +
|
"""
|
||||||
'0 -%s cm rlineto\n' % gformat(h) +
|
self._doc = libcairodoc.GtkDocDocument()
|
||||||
'%s cm 0 rlineto\n' % gformat(w) +
|
self._active_element = self._doc
|
||||||
'0 %s cm rlineto\n' % gformat(h) +
|
self._pages = []
|
||||||
'closepath\n' +
|
write_index(index, self)
|
||||||
'%s setlinewidth\n' % gformat(box_style.get_line_width()) +
|
self.paginate_document(layout, page_width, page_height, DPI, DPI)
|
||||||
'%s %s %s setrgbcolor stroke\n' % lrgb(box_style.get_color())
|
return self._pages
|
||||||
)
|
|
||||||
if text:
|
|
||||||
para_name = box_style.get_paragraph_style()
|
|
||||||
assert( para_name != '' )
|
|
||||||
p = style_sheet.get_paragraph_style(para_name)
|
|
||||||
(text, fdef) = self.encode_text(p, text)
|
|
||||||
self.file.write(fdef)
|
|
||||||
lines = text.split('\n')
|
|
||||||
|
|
||||||
mar = 10/28.35
|
def write_toc(toc, doc):
|
||||||
f_in_cm = p.get_font().get_size()/28.35
|
"""
|
||||||
fs = f_in_cm * 1.2
|
Write the table of contents.
|
||||||
center = y + (h + fs)/2.0 + (fs*shadsize)
|
"""
|
||||||
ystart = center - (fs/2.0) * len(lines)
|
if not toc:
|
||||||
for i, line in enumerate(lines):
|
return
|
||||||
ypos = ystart + (i * fs)
|
|
||||||
self.file.write(
|
doc.start_paragraph('TOC-Title')
|
||||||
'%s cm %s cm moveto\n'
|
doc.write_text(_('Contents'))
|
||||||
% coords(self.translate(x+mar, ypos)) +
|
doc.end_paragraph()
|
||||||
"(%s) show\n" % lines[i]
|
|
||||||
)
|
doc.start_table('toc', 'TOC-Table')
|
||||||
self.file.write('grestore\n')
|
for mark, page_nr in toc:
|
||||||
|
doc.start_row()
|
||||||
|
doc.start_cell('TOC-Cell')
|
||||||
|
if mark.level == 1:
|
||||||
|
style_name = "TOC-Heading1"
|
||||||
|
elif mark.level == 2:
|
||||||
|
style_name = "TOC-Heading2"
|
||||||
|
else:
|
||||||
|
style_name = "TOC-Heading3"
|
||||||
|
doc.start_paragraph(style_name)
|
||||||
|
doc.write_text(mark.key)
|
||||||
|
doc.end_paragraph()
|
||||||
|
doc.end_cell()
|
||||||
|
doc.start_cell('TOC-Cell')
|
||||||
|
doc.start_paragraph(style_name)
|
||||||
|
doc.write_text(str(page_nr))
|
||||||
|
doc.end_paragraph()
|
||||||
|
doc.end_cell()
|
||||||
|
doc.end_row()
|
||||||
|
doc.end_table()
|
||||||
|
|
||||||
|
def write_index(index, doc):
|
||||||
|
"""
|
||||||
|
Write the alphabetical index.
|
||||||
|
"""
|
||||||
|
if not index:
|
||||||
|
return
|
||||||
|
|
||||||
|
doc.start_paragraph('IDX-Title')
|
||||||
|
doc.write_text(_('Index'))
|
||||||
|
doc.end_paragraph()
|
||||||
|
|
||||||
|
doc.start_table('index', 'IDX-Table')
|
||||||
|
for key in sorted(index.iterkeys()):
|
||||||
|
doc.start_row()
|
||||||
|
doc.start_cell('IDX-Cell')
|
||||||
|
doc.start_paragraph('IDX-Entry')
|
||||||
|
doc.write_text(key)
|
||||||
|
doc.end_paragraph()
|
||||||
|
doc.end_cell()
|
||||||
|
doc.start_cell('IDX-Cell')
|
||||||
|
doc.start_paragraph('IDX-Entry')
|
||||||
|
pages = [str(page_nr) for page_nr in index[key]]
|
||||||
|
doc.write_text(', '.join(pages))
|
||||||
|
doc.end_paragraph()
|
||||||
|
doc.end_cell()
|
||||||
|
doc.end_row()
|
||||||
|
doc.end_table()
|
||||||
|
@ -151,7 +151,7 @@ plg = newplugin()
|
|||||||
plg.id = 'psdrawdoc'
|
plg.id = 'psdrawdoc'
|
||||||
plg.name = _('PostScript')
|
plg.name = _('PostScript')
|
||||||
plg.description = _("Generates documents in PostScript format (.ps).")
|
plg.description = _("Generates documents in PostScript format (.ps).")
|
||||||
plg.version = '1.0'
|
plg.version = '2.0'
|
||||||
plg.gramps_target_version = '3.4'
|
plg.gramps_target_version = '3.4'
|
||||||
plg.status = STABLE
|
plg.status = STABLE
|
||||||
plg.fname = 'PSDrawDoc.py'
|
plg.fname = 'PSDrawDoc.py'
|
||||||
|
@ -1336,10 +1336,21 @@ class CairoDoc(BaseDoc, TextDoc, DrawDoc):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# BaseDoc implementation
|
# BaseDoc implementation
|
||||||
|
EXT = 'pdf'
|
||||||
|
|
||||||
def open(self, filename):
|
def open(self, filename):
|
||||||
if filename[-4:] != '.pdf':
|
fe = filename.split('.')
|
||||||
filename = filename + '.pdf'
|
if len(fe) == 1:
|
||||||
|
filename = filename + '.' + self.EXT
|
||||||
|
elif fe[-1] != self.EXT:
|
||||||
|
# NOTE: the warning will be bogus
|
||||||
|
# if the EXT isn't properly overridden by derived class
|
||||||
|
log.warn(_(
|
||||||
|
"""Mismatch between selected extension %(ext)s and actual format.
|
||||||
|
Writing to %(filename)s in format %(impliedext)s.""") %
|
||||||
|
{'ext' : fe[-1],
|
||||||
|
'filename' : filename,
|
||||||
|
'impliedext' : self.EXT} )
|
||||||
self._backend = CairoBackend(filename)
|
self._backend = CairoBackend(filename)
|
||||||
self._doc = GtkDocDocument()
|
self._doc = GtkDocDocument()
|
||||||
self._active_element = self._doc
|
self._active_element = self._doc
|
||||||
|
@ -21,7 +21,7 @@ mkdir -p $REP_DIR
|
|||||||
OPTS="-i $EXAMPLE_XML"
|
OPTS="-i $EXAMPLE_XML"
|
||||||
|
|
||||||
GRPH_FMT="sxw ps pdf svg"
|
GRPH_FMT="sxw ps pdf svg"
|
||||||
TEXT_FMT="sxw pdf kwd abw rtf txt html tex"
|
TEXT_FMT="sxw ps pdf kwd abw rtf txt html tex"
|
||||||
|
|
||||||
GRPH_REP="ancestor_chart descend_chart fan_chart statistics_chart timeline calendar"
|
GRPH_REP="ancestor_chart descend_chart fan_chart statistics_chart timeline calendar"
|
||||||
TEXT_REP="ancestor_report descend_report det_ancestor_report det_descendant_report family_group"
|
TEXT_REP="ancestor_report descend_report det_ancestor_report det_descendant_report family_group"
|
||||||
|
Loading…
Reference in New Issue
Block a user