copyright Jakim Friant, ticket 4237: Line Styles in Report not Fully Supported
svn: r15911
This commit is contained in:
parent
7efc0f77cf
commit
f89bfe0796
@ -2,6 +2,7 @@
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2009 B. Malengier
|
||||
# Copyright (C) 2010 Jakim Friant
|
||||
#
|
||||
# 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
|
||||
@ -32,7 +33,7 @@ from paragraphstyle import ParagraphStyle, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,\
|
||||
PARA_ALIGN_RIGHT, PARA_ALIGN_JUSTIFY
|
||||
from tablestyle import TableStyle, TableCellStyle
|
||||
from stylesheet import StyleSheetList, StyleSheet, SheetParser
|
||||
from graphicstyle import GraphicsStyle, SOLID, DASHED
|
||||
from graphicstyle import GraphicsStyle, SOLID, DASHED, DOTTED
|
||||
from textdoc import TextDoc, IndexMark,INDEX_TYPE_ALP, INDEX_TYPE_TOC
|
||||
from drawdoc import DrawDoc
|
||||
from graphdoc import GVDoc
|
||||
|
@ -6,6 +6,7 @@
|
||||
# Copyright (C) 2007 Brian G. Matherly
|
||||
# Copyright (C) 2009 Benny Malengier
|
||||
# Copyright (C) 2009 Gary Burton
|
||||
# Copyright (C) 2010 Jakim Friant
|
||||
#
|
||||
# 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
|
||||
@ -54,6 +55,23 @@ log = logging.getLogger(".graphicstyle")
|
||||
#-------------------------------------------------------------------------
|
||||
SOLID = 0
|
||||
DASHED = 1
|
||||
DOTTED = 2
|
||||
|
||||
# Notes about adding new line styles:
|
||||
# 1) the first style is used when an invalid style is specified by the report
|
||||
# 2) the style names are used by the ODF generator and should be unique
|
||||
# 3) the line style constants above need to be imported in the
|
||||
# gen.plug.docgen.__init__ file so they can be used in a report add-on
|
||||
line_style_names = ('solid', 'dashed', 'dotted')
|
||||
_DASH_ARRAY = [ [1, 0], [2, 4], [1, 2] ]
|
||||
|
||||
def get_line_style_by_name(style_name):
|
||||
which = 0
|
||||
for (idx, sn) in enumerate(line_style_names):
|
||||
if sn == style_name:
|
||||
which = idx
|
||||
break
|
||||
return _DASH_ARRAY[which]
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -106,6 +124,22 @@ class GraphicsStyle(object):
|
||||
def set_line_style(self, val):
|
||||
self.lstyle = val
|
||||
|
||||
def get_dash_style(self, val = None):
|
||||
if val is None:
|
||||
val = self.lstyle
|
||||
if val >= 0 and val < len(_DASH_ARRAY):
|
||||
return _DASH_ARRAY[val]
|
||||
else:
|
||||
return _DASH_ARRAY[0]
|
||||
|
||||
def get_dash_style_name(self, val=None):
|
||||
if val is None:
|
||||
val = self.lstyle
|
||||
if val >= 0 and val < len(line_style_names):
|
||||
return line_style_names[val]
|
||||
else:
|
||||
return line_style_names[0]
|
||||
|
||||
def set_paragraph_style(self, val):
|
||||
self.para_name = val
|
||||
|
||||
|
@ -79,8 +79,8 @@ from xml.sax.saxutils import escape
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gui.utils import open_file_with_default_application
|
||||
from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc,
|
||||
FONT_SANS_SERIF, DASHED, PAPER_PORTRAIT,
|
||||
from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, graphicstyle,
|
||||
FONT_SANS_SERIF, SOLID, PAPER_PORTRAIT,
|
||||
INDEX_TYPE_TOC, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,
|
||||
INDEX_TYPE_ALP, PARA_ALIGN_RIGHT)
|
||||
from gen.plug.docgen.fontscale import string_width
|
||||
@ -500,7 +500,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
||||
'<office:automatic-styles>\n' +
|
||||
_AUTOMATIC_STYLES
|
||||
)
|
||||
|
||||
|
||||
styles = self.get_style_sheet()
|
||||
|
||||
for style_name in styles.get_draw_style_names():
|
||||
@ -519,23 +519,23 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
||||
'draw:marker-start="" '
|
||||
'draw:marker-start-width="0.0" '
|
||||
'draw:marker-end-width="0.0" '
|
||||
'draw:stroke="solid" '
|
||||
'draw:textarea-horizontal-align="center" '
|
||||
'draw:textarea-vertical-align="middle" '
|
||||
)
|
||||
if style.get_line_style() != SOLID:
|
||||
#wrt('svg:fill-color="#ff0000" ')
|
||||
wrt('draw:stroke="dash" draw:stroke-dash="gramps_%s" ' % style.get_dash_style_name())
|
||||
else:
|
||||
wrt('draw:stroke="solid" ')
|
||||
else:
|
||||
wrt(
|
||||
'draw:stroke="none" '
|
||||
'draw:stroke-color="#000000" '
|
||||
)
|
||||
|
||||
if style.get_line_style() == DASHED:
|
||||
wrt('svg:fill-color="#cccccc" ')
|
||||
else:
|
||||
wrt('svg:fill-color="#%02x%02x%02x" '
|
||||
% style.get_color())
|
||||
|
||||
wrt(
|
||||
'svg:fill-color="#%02x%02x%02x" '
|
||||
% style.get_color() +
|
||||
'draw:fill-color="#%02x%02x%02x" '
|
||||
% style.get_fill_color() +
|
||||
'draw:shadow="hidden" '
|
||||
@ -1161,6 +1161,15 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
||||
'</style:style>\n'
|
||||
)
|
||||
|
||||
# Dash lengths are based on the OpenOffice Ultrafine Dashed line style.
|
||||
for line_style in graphicstyle.line_style_names:
|
||||
dash_array = graphicstyle.get_line_style_by_name(line_style)
|
||||
wrtf('<draw:stroke-dash draw:name="gramps_%s" draw:style="rect" '
|
||||
'draw:dots1="%d" draw:dots1-length="0.102cm" '
|
||||
'draw:dots2="%d" draw:dots2-length="0.102cm" '
|
||||
'draw:distance="%5.3fcm" />\n' % (line_style, dash_array[0], dash_array[0], dash_array[1] * 0.051))
|
||||
|
||||
|
||||
# Current no leading number format for headers
|
||||
|
||||
#wrtf('<text:outline-style>\n')
|
||||
@ -1580,7 +1589,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
||||
self.cntnt.write(
|
||||
'<draw:line text:anchor-type="paragraph" ' +
|
||||
'draw:z-index="3" ' +
|
||||
'draw:text-style-name="%s" ' % style +
|
||||
'draw:style-name="%s" ' % style +
|
||||
'svg:x1="%.2fcm" ' % x1 +
|
||||
'svg:y1="%.2fcm" ' % y1 +
|
||||
'svg:x2="%.2fcm" ' % x2 +
|
||||
|
@ -269,7 +269,8 @@ class PSDrawDoc(BaseDoc, DrawDoc):
|
||||
if stype.get_line_style() == SOLID:
|
||||
self.file.write('[] 0 setdash\n')
|
||||
else:
|
||||
self.file.write('[2 4] 0 setdash\n')
|
||||
dash_style = stype.get_dash_style(stype.get_line_style())
|
||||
self.file.write('[%s] 0 setdash\n' % (" ".join([str(d) for d in dash_style])))
|
||||
|
||||
point = path[0]
|
||||
x1 = point[0] + self.paper.get_left_margin()
|
||||
@ -309,7 +310,8 @@ class PSDrawDoc(BaseDoc, DrawDoc):
|
||||
if stype.get_line_style() == SOLID:
|
||||
self.file.write('[] 0 setdash\n')
|
||||
else:
|
||||
self.file.write('[2 4] 0 setdash\n')
|
||||
dash_style = stype.get_dash_style(stype.get_line_style())
|
||||
self.file.write('[%s] 0 setdash\n' % (" ".join([str(d) for d in dash_style])))
|
||||
|
||||
self.file.write(
|
||||
'2 setlinecap\n' +
|
||||
|
@ -3,6 +3,7 @@
|
||||
#
|
||||
# Copyright (C) 2000-2006 Donald N. Allingham
|
||||
# Copyright (C) 2007-2009 Brian G. Matherly
|
||||
# Copyright (C) 2010 Jakim Friant
|
||||
#
|
||||
# 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
|
||||
@ -38,7 +39,7 @@ import StringIO
|
||||
# Gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gen.plug.docgen import BaseDoc, DrawDoc, FONT_SANS_SERIF
|
||||
from gen.plug.docgen import BaseDoc, DrawDoc, SOLID, FONT_SANS_SERIF
|
||||
import Errors
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -153,26 +154,27 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
|
||||
style_sheet = self.get_style_sheet()
|
||||
s = style_sheet.get_draw_style(style)
|
||||
|
||||
self.f.write(
|
||||
'<line x1="%4.2fcm" y1="%4.2fcm" ' % (x1, y1) +
|
||||
'x2="%4.2fcm" y2="%4.2fcm" ' % (x2, y2) +
|
||||
'style="stroke:#%02x%02x%02x; ' % s.get_color() +
|
||||
'stroke-width:%.2fpt;"/>\n' % s.get_line_width()
|
||||
)
|
||||
line_out = '<line x1="%4.2fcm" y1="%4.2fcm" ' % (x1, y1)
|
||||
line_out += 'x2="%4.2fcm" y2="%4.2fcm" ' % (x2, y2)
|
||||
line_out += 'style="stroke:#%02x%02x%02x; ' % s.get_color()
|
||||
if s.get_line_style() != SOLID:
|
||||
line_out += 'stroke-dasharray: %s; ' % (",".join([str(d) for d in s.get_dash_style()]))
|
||||
line_out += 'stroke-width:%.2fpt;"/>\n' % s.get_line_width()
|
||||
self.f.write(line_out)
|
||||
|
||||
def draw_path(self, style, path):
|
||||
style_sheet = self.get_style_sheet()
|
||||
stype = style_sheet.get_draw_style(style)
|
||||
|
||||
point = path[0]
|
||||
self.f.write(
|
||||
'<polygon fill="#%02x%02x%02x"' % stype.get_fill_color() +
|
||||
' style="stroke:#%02x%02x%02x; ' % stype.get_color() +
|
||||
' stroke-width:%.2fpt;"' % stype.get_line_width() +
|
||||
' points="%.2f,%.2f'
|
||||
% units((point[0]+self.paper.get_left_margin(),
|
||||
point[1]+self.paper.get_top_margin()))
|
||||
)
|
||||
line_out = '<polygon fill="#%02x%02x%02x"' % stype.get_fill_color()
|
||||
line_out += ' style="stroke:#%02x%02x%02x; ' % stype.get_color()
|
||||
if stype.get_line_style() != SOLID:
|
||||
line_out += 'stroke-dasharray: %s; ' % (",".join([str(d) for d in stype.get_dash_style()]))
|
||||
line_out += ' stroke-width:%.2fpt;"' % stype.get_line_width()
|
||||
line_out += ' points="%.2f,%.2f' % units((point[0]+self.paper.get_left_margin(),
|
||||
point[1]+self.paper.get_top_margin()))
|
||||
self.f.write(line_out)
|
||||
for point in path[1:]:
|
||||
self.f.write(
|
||||
' %.2f,%.2f'
|
||||
@ -198,16 +200,17 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
|
||||
'style="fill:#808080; stroke:#808080; stroke-width:1;"/>\n'
|
||||
)
|
||||
|
||||
self.f.write(
|
||||
'<rect '
|
||||
'x="%4.2fcm" ' % x +
|
||||
'y="%4.2fcm" ' % y +
|
||||
'width="%4.2fcm" ' % w +
|
||||
'height="%4.2fcm" ' % h +
|
||||
'style="fill:#%02x%02x%02x; ' % box_style.get_fill_color() +
|
||||
'stroke:#%02x%02x%02x; ' % box_style.get_color() +
|
||||
'stroke-width:%f;"/>\n' % box_style.get_line_width()
|
||||
)
|
||||
line_out = '<rect '
|
||||
line_out += 'x="%4.2fcm" ' % x
|
||||
line_out += 'y="%4.2fcm" ' % y
|
||||
line_out += 'width="%4.2fcm" ' % w
|
||||
line_out += 'height="%4.2fcm" ' % h
|
||||
line_out += 'style="fill:#%02x%02x%02x; ' % box_style.get_fill_color()
|
||||
line_out += 'stroke:#%02x%02x%02x; ' % box_style.get_color()
|
||||
if box_style.get_line_style() != SOLID:
|
||||
line_out += 'stroke-dasharray: %s; ' % (",".join([str(d) for d in box_style.get_dash_style()]))
|
||||
line_out += 'stroke-width:%f;"/>\n' % box_style.get_line_width()
|
||||
self.f.write(line_out)
|
||||
|
||||
if text:
|
||||
para_name = box_style.get_paragraph_style()
|
||||
|
@ -41,7 +41,7 @@ from math import radians
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, ParagraphStyle,
|
||||
TableCellStyle, FONT_SANS_SERIF, FONT_SERIF,
|
||||
TableCellStyle, SOLID, FONT_SANS_SERIF, FONT_SERIF,
|
||||
FONT_MONOSPACE, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT)
|
||||
from gen.plug.report import utils as ReportUtils
|
||||
from Errors import PluginError
|
||||
@ -1032,6 +1032,9 @@ class GtkDocLine(GtkDocBaseElement):
|
||||
cr.set_source_rgb(*line_color)
|
||||
cr.set_line_width(self._style.get_line_width())
|
||||
# TODO line style
|
||||
line_style = self._style.get_line_style()
|
||||
if line_style != SOLID:
|
||||
cr.set_dash(self._style.get_dash_style(line_style), 0)
|
||||
cr.move_to(*start)
|
||||
cr.line_to(*end)
|
||||
cr.stroke()
|
||||
@ -1065,6 +1068,9 @@ class GtkDocPolygon(GtkDocBaseElement):
|
||||
cr.set_source_rgb(*path_stroke_color)
|
||||
cr.set_line_width(self._style.get_line_width())
|
||||
# TODO line style
|
||||
line_style = self._style.get_line_style()
|
||||
if line_style != SOLID:
|
||||
cr.set_dash(self._style.get_dash_style(line_style), 0)
|
||||
cr.stroke()
|
||||
cr.restore()
|
||||
|
||||
@ -1097,6 +1103,9 @@ class GtkDocBox(GtkDocBaseElement):
|
||||
|
||||
cr.set_line_width(self._style.get_line_width())
|
||||
# TODO line style
|
||||
line_style = self._style.get_line_style()
|
||||
if line_style != SOLID:
|
||||
cr.set_dash(self._style.get_dash_style(line_style), 0)
|
||||
|
||||
if self._style.get_shadow():
|
||||
shadow_x = box_x + self._style.get_shadow_space() * dpi_x / 2.54
|
||||
|
Loading…
Reference in New Issue
Block a user