0001957: Orientation switch doesn't work for Graphviz reports.

0001940: GS PDF output is broken for Graphiz graphs. Page size depends on dpi

svn: r10347
This commit is contained in:
Brian Matherly 2008-03-20 03:22:45 +00:00
parent 33e19a643c
commit 334fed79ae

View File

@ -110,8 +110,8 @@ class GVDocBase(BaseDoc.BaseDoc,BaseDoc.GVDoc):
inherit from this class will only need to implement the close function. inherit from this class will only need to implement the close function.
The close function will generate the actual file of the appropriate type. The close function will generate the actual file of the appropriate type.
""" """
def __init__(self, options,paper_style): def __init__(self, options, paper_style):
BaseDoc.BaseDoc.__init__(self,None,paper_style,None) BaseDoc.BaseDoc.__init__(self, None, paper_style, None)
self.options = options.handler.options_dict self.options = options.handler.options_dict
self.dot = StringIO() self.dot = StringIO()
@ -132,27 +132,19 @@ class GVDocBase(BaseDoc.BaseDoc,BaseDoc.GVDoc):
self.vpages = self.options['v_pages' ] self.vpages = self.options['v_pages' ]
paper_size = paper_style.get_size() paper_size = paper_style.get_size()
pheight = paper_size.get_height_inches()
pwidth = paper_size.get_width_inches()
# graph size sizew = ( paper_size.get_width() -
if self.paper.get_orientation() == BaseDoc.PAPER_LANDSCAPE: self.paper.get_left_margin() -
rotate = 90 self.paper.get_right_margin() ) / 2.54
sizew = ( paper_size.get_height() - sizeh = ( paper_size.get_height() -
self.paper.get_top_margin() - self.paper.get_top_margin() -
self.paper.get_bottom_margin() ) / 2.54 self.paper.get_bottom_margin() ) / 2.54
sizeh = ( paper_size.get_width() -
self.paper.get_left_margin() -
self.paper.get_right_margin() ) / 2.54
else: pheight = paper_size.get_height_inches()
rotate = 0 pwidth = paper_size.get_width_inches()
sizew = ( paper_size.get_width() -
self.paper.get_left_margin() - xmargin = self.paper.get_left_margin() / 2.54
self.paper.get_right_margin() ) / 2.54 ymargin = self.paper.get_top_margin() / 2.54
sizeh = ( paper_size.get_height() -
self.paper.get_top_margin() -
self.paper.get_bottom_margin() ) / 2.54
sizew = sizew * self.hpages sizew = sizew * self.hpages
sizeh = sizeh * self.vpages sizeh = sizeh * self.vpages
@ -173,9 +165,9 @@ class GVDocBase(BaseDoc.BaseDoc,BaseDoc.GVDoc):
self.write( ' rankdir="%s";\n' % self.rankdir ) self.write( ' rankdir="%s";\n' % self.rankdir )
self.write( ' ranksep="%.2f";\n' % self.ranksep ) self.write( ' ranksep="%.2f";\n' % self.ranksep )
self.write( ' ratio="%s";\n' % self.ratio ) self.write( ' ratio="%s";\n' % self.ratio )
self.write( ' rotate="%d";\n' % rotate )
self.write( ' searchsize="100";\n' ) self.write( ' searchsize="100";\n' )
self.write( ' size="%3.2f,%3.2f"; \n' % (sizew, sizeh) ) self.write( ' size="%3.2f,%3.2f"; \n' % (sizew, sizeh) )
self.write( ' margin="%3.2f,%3.2f"; \n' % (xmargin, ymargin))
self.write( ' splines="true";\n' ) self.write( ' splines="true";\n' )
self.write( '\n' ) self.write( '\n' )
self.write( ' edge [len=0.5 style=solid arrowhead=none ' self.write( ' edge [len=0.5 style=solid arrowhead=none '
@ -322,6 +314,13 @@ class GVDotDoc(GVDocBase):
# #
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class GVPsDoc(GVDocBase): class GVPsDoc(GVDocBase):
def __init__(self, options, paper_style):
# DPI must always be 72 for PDF.
# GV documentation says dpi is only for image formats.
options.handler.options_dict['dpi'] = 72
GVDocBase.__init__(self, options, paper_style)
def close(self): def close(self):
GVDocBase.close(self) GVDocBase.close(self)
@ -496,6 +495,13 @@ class GVGifDoc(GVDocBase):
# #
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class GVPdfGvDoc(GVDocBase): class GVPdfGvDoc(GVDocBase):
def __init__(self, options, paper_style):
# DPI must always be 72 for PDF.
# GV documentation says dpi is only for image formats.
options.handler.options_dict['dpi'] = 72
GVDocBase.__init__(self, options, paper_style)
def close(self): def close(self):
GVDocBase.close(self) GVDocBase.close(self)
@ -519,13 +525,19 @@ class GVPdfGvDoc(GVDocBase):
app = Mime.get_application("application/pdf") app = Mime.get_application("application/pdf")
Utils.launch(app[0], self.filename) Utils.launch(app[0], self.filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
# GVPdfGsDoc # GVPdfGsDoc
# #
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
class GVPdfGsDoc(GVDocBase): class GVPdfGsDoc(GVDocBase):
def __init__(self, options, paper_style):
# DPI must always be 72 for PDF.
# GV documentation says dpi is only for image formats.
options.handler.options_dict['dpi'] = 72
GVDocBase.__init__(self, options, paper_style)
def close(self): def close(self):
GVDocBase.close(self) GVDocBase.close(self)
@ -547,12 +559,10 @@ class GVPdfGsDoc(GVDocBase):
command = 'dot -Tps -o"%s" "%s"' % ( tmp_ps, tmp_dot ) command = 'dot -Tps -o"%s" "%s"' % ( tmp_ps, tmp_dot )
os.system(command) os.system(command)
# dot creates ps with a ceratin dpi; the paper size, in points, has to be # Add .5 to remove rounding errors.
# adjusted according to what the user has defined. The paper will be large,
# but pdf-printers adjust to actual printer paper size.
paper_size = self.paper.get_size() paper_size = self.paper.get_size()
width_pt = int( (paper_size.get_width_inches() * self.dpi)) width_pt = int( (paper_size.get_width_inches() * 72) + 0.5 )
height_pt = int( (paper_size.get_height_inches() * self.dpi)) height_pt = int( (paper_size.get_height_inches() * 72) + 0.5 )
# Convert to PDF using ghostscript # Convert to PDF using ghostscript
command = '%s -q -sDEVICE=pdfwrite -dNOPAUSE -dDEVICEWIDTHPOINTS=%d' \ command = '%s -q -sDEVICE=pdfwrite -dNOPAUSE -dDEVICEWIDTHPOINTS=%d' \
@ -797,8 +807,8 @@ class GraphvizReportDialog(ReportDialog):
self.dpi = dpi self.dpi = dpi
dpi.set_help(_( "Dots per inch. When creating images such as " dpi.set_help(_( "Dots per inch. When creating images such as "
".gif or .png files for the web, try numbers " ".gif or .png files for the web, try numbers "
"such as 75 or 100 DPI. When printing, try" "such as 100 or 300 DPI. When creating postscript or "
"300 or 600 DPI.")) "pdf files, use 72 DPI."))
self.options.add_menu_option(category, "dpi", dpi) self.options.add_menu_option(category, "dpi", dpi)
nodesep = NumberOption(_("Node spacing"), 0.20, 0.01, 5.00, 0.01) nodesep = NumberOption(_("Node spacing"), 0.20, 0.01, 5.00, 0.01)