Drawing improvements
svn: r1290
This commit is contained in:
parent
9acab799cb
commit
1c18c6a3f0
@ -41,6 +41,7 @@ class GraphicsStyle:
|
||||
self.para_name = obj.para_name
|
||||
self.shadow = obj.shadow
|
||||
self.color = obj.color
|
||||
self.fill_color = obj.fill_color
|
||||
self.lwidth = obj.lwidth
|
||||
self.lstyle = obj.lstyle
|
||||
else:
|
||||
@ -49,7 +50,8 @@ class GraphicsStyle:
|
||||
self.para_name = ""
|
||||
self.shadow = 0
|
||||
self.lwidth = 0.5
|
||||
self.color = (255,255,255)
|
||||
self.color = (0,0,0)
|
||||
self.fill_color = (255,255,255)
|
||||
self.lstyle = SOLID
|
||||
|
||||
def set_line_width(self,val):
|
||||
@ -79,6 +81,9 @@ class GraphicsStyle:
|
||||
def set_color(self,val):
|
||||
self.color = val
|
||||
|
||||
def set_fill_color(self,val):
|
||||
self.fill_color = val
|
||||
|
||||
def get_height(self):
|
||||
return self.height
|
||||
|
||||
@ -94,6 +99,9 @@ class GraphicsStyle:
|
||||
def get_color(self):
|
||||
return self.color
|
||||
|
||||
def get_fill_color(self):
|
||||
return self.fill_color
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# DrawDoc
|
||||
|
@ -38,6 +38,7 @@ import Errors
|
||||
import TextDoc
|
||||
import DrawDoc
|
||||
import const
|
||||
import FontScale
|
||||
|
||||
from intl import gettext as _
|
||||
|
||||
@ -244,13 +245,18 @@ class OpenDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.write('" style:family="graphics" ')
|
||||
self.f.write('style:parent-style-name="standard">\n')
|
||||
self.f.write('<style:properties ')
|
||||
if style.color[0] == 0 and style.color[1] == 0 and style.color[2] == 0:
|
||||
self.f.write('draw:fill="solid" ')
|
||||
else:
|
||||
if style.color[0] == 255 and style.color[1] == 255 and style.color[2] == 255:
|
||||
self.f.write('draw:fill="none" ')
|
||||
else:
|
||||
self.f.write('draw:fill="solid" ')
|
||||
|
||||
self.f.write('draw:fill-color="#%02x%02x%02x" ' % style.get_fill_color())
|
||||
|
||||
if style.get_line_style() == DrawDoc.DASHED:
|
||||
self.f.write('draw:color="#cccccc" ')
|
||||
else:
|
||||
self.f.write('draw:color="#%02x%02x%02x" ' % style.get_color())
|
||||
|
||||
|
||||
if style.get_line_width():
|
||||
self.f.write('draw:stroke="solid" ')
|
||||
@ -484,12 +490,16 @@ class OpenDrawDoc(DrawDoc.DrawDoc):
|
||||
box_style = self.draw_styles[style]
|
||||
para_name = box_style.get_paragraph_style()
|
||||
|
||||
pstyle = self.style_list[para_name]
|
||||
font = pstyle.get_font()
|
||||
sw = FontScale.string_width(font,text)*1.3
|
||||
|
||||
self.f.write('<draw:text-box draw:style-name="')
|
||||
self.f.write(style)
|
||||
self.f.write('" draw:layer="layout" ')
|
||||
# fix this
|
||||
self.f.write('svg:width="%.3fcm" ' % 5.0)
|
||||
self.f.write('svg:height="%.3fcm" ' % 1.0)
|
||||
self.f.write('svg:width="%.3fcm" ' % sw)
|
||||
self.f.write('svg:height="%.4fpt" ' % (font.get_size()*1.4))
|
||||
|
||||
self.f.write('svg:x="%.3fcm" ' % float(x))
|
||||
self.f.write('svg:y="%.3fcm">' % float(y))
|
||||
|
@ -123,14 +123,13 @@ class PSDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.write('gsave\n')
|
||||
self.f.write('%f cm %f cm moveto\n' % self.translate(x1,y1))
|
||||
self.f.write(self.fontdef(p))
|
||||
self.f.write('(%s) show\n' % text)
|
||||
self.f.write('grestore\n')
|
||||
self.f.write('(%s) show grestore\n' % text)
|
||||
|
||||
def draw_path(self,style,path):
|
||||
stype = self.draw_styles[style]
|
||||
self.f.write('gsave\n')
|
||||
self.f.write('newpath\n')
|
||||
self.f.write('%d setlinewidth\n' % stype.get_line_width())
|
||||
self.f.write('%.4f setlinewidth\n' % stype.get_line_width())
|
||||
if stype.get_line_style() == DrawDoc.SOLID:
|
||||
self.f.write('[] 0 setdash\n')
|
||||
else:
|
||||
@ -146,10 +145,11 @@ class PSDrawDoc(DrawDoc.DrawDoc):
|
||||
y1 = point[1]+self.tmargin
|
||||
self.f.write('%f cm %f cm lineto\n' % self.translate(x1,y1))
|
||||
self.f.write('closepath\n')
|
||||
if self.color[0] == 0:
|
||||
self.f.write('fill\n')
|
||||
else:
|
||||
self.f.write('stroke\n')
|
||||
|
||||
color = stype.get_fill_color()
|
||||
if (color[0] != 255 or color[1] != 255 or color[2] != 255) :
|
||||
self.f.write('%.4f %.4f %.4f setrgbcolor fill\n' % rgb_color(color))
|
||||
self.f.write('%.4f %.4f %.4f setrgbcolor stroke\n' % rgb_color(stype.get_color()))
|
||||
self.f.write('grestore\n')
|
||||
|
||||
def draw_line(self,style,x1,y1,x2,y2):
|
||||
@ -158,18 +158,17 @@ class PSDrawDoc(DrawDoc.DrawDoc):
|
||||
y1 = y1 + self.tmargin
|
||||
y2 = y2 + self.tmargin
|
||||
stype = self.draw_styles[style]
|
||||
self.f.write('gsave\n')
|
||||
self.f.write('newpath\n')
|
||||
self.f.write('gsave newpath\n')
|
||||
self.f.write('%f cm %f cm moveto\n' % self.translate(x1,y1))
|
||||
self.f.write('%f cm %f cm lineto\n' % self.translate(x2,y2))
|
||||
self.f.write('%d setlinewidth\n' % stype.get_line_width())
|
||||
self.f.write('%.4f setlinewidth\n' % stype.get_line_width())
|
||||
if stype.get_line_style() == DrawDoc.SOLID:
|
||||
self.f.write('[] 0 setdash\n')
|
||||
else:
|
||||
self.f.write('[2 4] 0 setdash\n')
|
||||
|
||||
self.f.write('2 setlinecap\n')
|
||||
self.f.write('stroke\n')
|
||||
self.f.write('%.4f %.4f %.4f setrgbcolor stroke\n' % rgb_color(stype.get_color()))
|
||||
self.f.write('grestore\n')
|
||||
|
||||
def patch_text(self,text):
|
||||
@ -188,8 +187,8 @@ class PSDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.write("%f cm 0 rlineto\n" % (x2-x1))
|
||||
self.f.write("0 %f cm rlineto\n" % (y1-y2))
|
||||
self.f.write('closepath\n')
|
||||
self.f.write("%d setlinewidth\n" % box_type.get_line_width())
|
||||
self.f.write("stroke\n")
|
||||
self.f.write("%.4f setlinewidth\n" % box_type.get_line_width())
|
||||
self.f.write('%.4f %.4f %.4f setrgbcolor stroke\n' % rgb_color(box_type.get_color()))
|
||||
self.f.write('grestore\n')
|
||||
|
||||
def draw_box(self,style,text,x,y):
|
||||
@ -227,9 +226,8 @@ class PSDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.write('%f cm 0 rlineto\n' % bw)
|
||||
self.f.write('0 %f cm rlineto\n' % bh)
|
||||
self.f.write('closepath\n')
|
||||
self.f.write('0 setgray\n')
|
||||
self.f.write('1 setlinewidth\n')
|
||||
self.f.write('stroke\n')
|
||||
self.f.write('%.4f setlinewidth\n' % box_style.get_line_width())
|
||||
self.f.write('%.4f %.4f %.4f setrgbcolor stroke\n' % rgb_color(box_style.get_color()))
|
||||
if text != "":
|
||||
self.f.write(self.fontdef(p))
|
||||
lines = string.split(text,'\n')
|
||||
@ -245,4 +243,10 @@ class PSDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.write("(%s) show\n" % lines[i])
|
||||
self.f.write('grestore\n')
|
||||
|
||||
def rgb_color(color):
|
||||
r = float(color[0])/255.0
|
||||
g = float(color[1])/255.0
|
||||
b = float(color[2])/255.0
|
||||
return (r,g,b)
|
||||
|
||||
Plugins.register_draw_doc(_("PostScript"),PSDrawDoc);
|
||||
|
@ -111,6 +111,10 @@ class PdfDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.setDash([2,4],0)
|
||||
self.f.setLineWidth(stype.get_line_width())
|
||||
|
||||
color = stype.get_fill_color()
|
||||
|
||||
self.f.setFillColor((float(color[0])/255.0,float(color[1])/255.0,float(color[2])/255.0))
|
||||
|
||||
p = self.f.beginPath()
|
||||
point = path[0]
|
||||
p.moveTo((point[0]+self.lmargin)*cm,(point[1]+self.tmargin)*cm)
|
||||
|
@ -97,9 +97,25 @@ class SvgDrawDoc(DrawDoc.DrawDoc):
|
||||
y1 = y1 + self.tmargin
|
||||
y2 = y2 + self.tmargin
|
||||
|
||||
self.f.write('<line x1="%4.2fcm" y1="%4.2fcm" ' % (x1*28.35,y1*28.35))
|
||||
self.f.write('x2="%4.2fcm" y2="%4.2fcm" ' % (x2*28.35,y2*28.35))
|
||||
self.f.write(' style="stroke:#000000;stroke-width=1"/>\n')
|
||||
s = self.draw_styles[style]
|
||||
|
||||
self.f.write('<line x1="%4.2fcm" y1="%4.2fcm" ' % (x1,y1))
|
||||
self.f.write('x2="%4.2fcm" y2="%4.2fcm" ' % (x2,y2))
|
||||
color = s.get_color()
|
||||
self.f.write(' style="stroke:#%02x%02x%02x; stroke-width:%.2fpt;"/>\n' %
|
||||
(color[0],color[1],color[2],s.get_line_width()))
|
||||
|
||||
def draw_path(self,style,path):
|
||||
stype = self.draw_styles[style]
|
||||
|
||||
point = path[0]
|
||||
self.f.write('<polygon fill="#%02x%02x%02x"' % stype.get_fill_color())
|
||||
self.f.write(' style="stroke:#%02x%02x%02x; ' % stype.get_color())
|
||||
self.f.write(' stroke-width=%.2fpt;"' % stype.get_line_width())
|
||||
self.f.write(' points="%.2f,%.2f' % units((point[0]+self.lmargin,point[1]+self.tmargin)))
|
||||
for point in path[1:]:
|
||||
self.f.write(' %.2f,%.2f' % units((point[0]+self.lmargin,point[1]+self.tmargin)))
|
||||
self.f.write('"/>\n')
|
||||
|
||||
def draw_bar(self,style,x1,y1,x2,y2):
|
||||
x1 = x1 + self.lmargin
|
||||
@ -113,8 +129,8 @@ class SvgDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.write('y="%4.2fcm" ' % y1)
|
||||
self.f.write('width="%4.2fcm" ' % (x2-x1))
|
||||
self.f.write('height="%4.2fcm" ' % (y2-y1))
|
||||
self.f.write('style="fill:#ffffff;stroke:#000000;')
|
||||
self.f.write('stroke-width:%.2f"/>\n' % s.get_line_width())
|
||||
self.f.write('style="fill:#ffffff; stroke:#000000; ')
|
||||
self.f.write('stroke-width:%.2f;"/>\n' % s.get_line_width())
|
||||
|
||||
def draw_box(self,style,text,x,y):
|
||||
x = x + self.lmargin
|
||||
@ -131,13 +147,13 @@ class SvgDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.write('y="%4.2fcm" ' % (y+0.15))
|
||||
self.f.write('width="%4.2fcm" ' % bw)
|
||||
self.f.write('height="%4.2fcm" ' % bh)
|
||||
self.f.write('style="fill:#808080;stroke:#808080;stroke-width:1"/>\n')
|
||||
self.f.write('style="fill:#808080; stroke:#808080; stroke-width:1;"/>\n')
|
||||
self.f.write('<rect ')
|
||||
self.f.write('x="%4.2fcm" ' % x)
|
||||
self.f.write('y="%4.2fcm" ' % y)
|
||||
self.f.write('width="%4.2fcm" ' % bw)
|
||||
self.f.write('height="%4.2fcm" ' % bh)
|
||||
self.f.write('style="fill:#%02x%02x%02x;stroke:#000000;stroke-width:1"/>\n' % box_style.get_color())
|
||||
self.f.write('style="fill:#%02x%02x%02x; stroke:#000000; stroke-width:1;"/>\n' % box_style.get_color())
|
||||
if text != "":
|
||||
font = p.get_font()
|
||||
font_size = font.get_size()
|
||||
@ -154,14 +170,14 @@ class SvgDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.write('y="%4.2fcm" ' % ypos)
|
||||
self.f.write('style="fill:#%02x%02x%02x; '% font.get_color())
|
||||
if font.get_bold():
|
||||
self.f.write('font-weight="bold";')
|
||||
self.f.write(' font-weight:"bold";')
|
||||
if font.get_italic():
|
||||
self.f.write('font-style="italic";')
|
||||
self.f.write('font-size:%d;' % font_size)
|
||||
self.f.write(' font-style:"italic";')
|
||||
self.f.write(' font-size:%d;' % font_size)
|
||||
if font.get_type_face() == TextDoc.FONT_SANS_SERIF:
|
||||
self.f.write('font-family=sans-serif;')
|
||||
self.f.write(' font-family:sans-serif;')
|
||||
else:
|
||||
self.f.write('font-family=serif;')
|
||||
self.f.write(' font-family:serif;')
|
||||
self.f.write('">')
|
||||
self.f.write(lines[i])
|
||||
self.f.write('</text>\n')
|
||||
@ -182,18 +198,21 @@ class SvgDrawDoc(DrawDoc.DrawDoc):
|
||||
self.f.write('y="%4.2fcm" ' % (y+fs))
|
||||
self.f.write('style="fill:#%02x%02x%02x; '% font.get_color())
|
||||
if font.get_bold():
|
||||
self.f.write('font-weight="bold";')
|
||||
self.f.write('font-weight:"bold";')
|
||||
if font.get_italic():
|
||||
self.f.write('font-style="italic";')
|
||||
self.f.write('font-size:%d;' % font_size)
|
||||
self.f.write('font-style:"italic";')
|
||||
self.f.write('font-size:%d; ' % font_size)
|
||||
if font.get_type_face() == TextDoc.FONT_SANS_SERIF:
|
||||
self.f.write('font-family=sans-serif;')
|
||||
self.f.write('font-family:sans-serif;')
|
||||
else:
|
||||
self.f.write('font-family=serif;')
|
||||
self.f.write('font-family:serif;')
|
||||
self.f.write('">')
|
||||
self.f.write(text)
|
||||
self.f.write('</text>\n')
|
||||
|
||||
def units(val):
|
||||
return (val[0]*35.433, val[1]*35.433)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Register document generator
|
||||
|
9403
src/po/es.po
9403
src/po/es.po
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user