* src/docgen/PSDrawDoc.py: locale independent floating point

* src/DateDisplay.py: Better french republican date handling
* src/DateParser.py: Better french republican date handling


svn: r5242
This commit is contained in:
Don Allingham 2005-09-27 03:45:19 +00:00
parent 56038d9b63
commit f517351802
5 changed files with 87 additions and 65 deletions

View File

@ -1,3 +1,8 @@
2005-09-26 Don Allingham <don@gramps-project.org>
* src/docgen/PSDrawDoc.py: locale independent floating point
* src/DateDisplay.py: Better french republican date handling
* src/DateParser.py: Better french republican date handling
2005-09-26 Alex Roitman <shura@gramps-project.org>
* src/plugins/ChangeNames.py: Convert to the new scheme.
* src/plugins/Checkpoint.py: Convert to new scheme, improve.

View File

@ -290,9 +290,22 @@ class DateDisplay:
else:
return value
def _display_french(self,date_val):
return self._display_calendar(date_val,self._french)
year = abs(date_val[2])
if self.format == 0 or self.format == 1:
return self.display_iso(date_val)
else:
if date_val[0] == 0:
if date_val[1] == 0:
value = year
else:
value = u"%s %d" % (self._french[date_val[1]],year)
else:
value = u"%d %s %s" % (date_val[0],self._french[date_val[1]],year)
if date_val[2] < 0:
return self._bce_str % value
else:
return value
def _display_hebrew(self,date_val):
return self._display_calendar(date_val,self._hebrew)

View File

@ -209,6 +209,7 @@ class DateParser:
self.parser = {
Date.CAL_GREGORIAN : self._parse_greg_julian,
Date.CAL_JULIAN : self._parse_greg_julian,
Date.CAL_FRENCH : self._parse_french,
Date.CAL_PERSIAN : self._parse_persian,
Date.CAL_HEBREW : self._parse_hebrew,
Date.CAL_ISLAMIC : self._parse_islamic,
@ -541,6 +542,8 @@ class DateParser:
"""
Parses the text and sets the date according to the parsing.
"""
date.set_text_value(text)
qual = Date.QUAL_NONE
cal = Date.CAL_GREGORIAN
@ -555,27 +558,13 @@ class DateParser:
(text,bc) = self.match_bce(text)
if self.match_modifier(text,cal,qual,bc,date):
return
subdate = self._parse_subdate(text)
if subdate == Date.EMPTY:
subdate = self._parse_hebrew(text)
if subdate == Date.EMPTY:
subdate = self._parse_persian(text)
if subdate == Date.EMPTY:
subdate = self._parse_islamic(text)
if subdate == Date.EMPTY:
subdate = self._parse_french(text)
if subdate == Date.EMPTY:
date.set_as_text(text)
return
else:
cal = Date.CAL_FRENCH
else:
cal = Date.CAL_ISLAMIC
else:
cal = Date.CAL_PERSIAN
else:
cal = Date.CAL_HEBREW
try:
subdate = self._parse_subdate(text,self.parser[cal])
except:
date.set_as_text(text)
return
if bc:
date.set(qual,Date.MOD_NONE,cal,self.invert_year(subdate))

View File

@ -377,7 +377,7 @@ def gfloat(val):
return 0.0
def gformat(val):
"""Performs ("%.3f" % val) formatting with the resulting string always
"""Performs ('%.3f' % val) formatting with the resulting string always
using dot ('.') as a decimal point.
Useful for writing float values into XML when under non-English locale.

View File

@ -38,6 +38,14 @@ import Errors
import BaseDoc
from Report import run_print_dialog
from ReportUtils import pt2cm, rgb_color
from Utils import gformat
def lrgb(grp):
grp = rgb_color(grp)
return (gformat(grp[0]),gformat(grp[1]),gformat(grp[2]))
def coords(grp):
return (gformat(grp[0]),gformat(grp[1]))
#-------------------------------------------------------------------------
#
@ -139,7 +147,8 @@ class PSDrawDoc(BaseDoc.BaseDoc):
self.f.write("%%Page:")
self.f.write("%d %d\n" % (self.page,self.page))
if self.orientation != BaseDoc.PAPER_PORTRAIT:
self.f.write('90 rotate %5.2f cm %5.2f cm translate\n' % (0,-1*self.height))
self.f.write('90 rotate %s cm %s cm translate\n' % (
gformat(0),gformat(-1*self.height)))
def end_page(self):
self.f.write('showpage\n')
@ -165,10 +174,10 @@ class PSDrawDoc(BaseDoc.BaseDoc):
(text,fdef) = self.encode_text(p,text)
self.f.write('gsave\n')
self.f.write('%.4f %.4f %.4f setrgbcolor\n' % rgb_color(stype.get_color()))
self.f.write('%s %s %s setrgbcolor\n' % lrgb(stype.get_color()))
self.f.write(fdef)
self.f.write('(%s) dup stringwidth pop -2 div ' % text)
self.f.write('%.4f cm add %.4f cm moveto ' % self.translate(x,y))
self.f.write('%s cm add %s cm moveto ' % coords(self.translate(x,y)))
self.f.write('show\n')
self.f.write('grestore\n')
@ -183,7 +192,7 @@ class PSDrawDoc(BaseDoc.BaseDoc):
(text,fdef) = self.encode_text(p,text)
self.f.write('gsave\n')
self.f.write('%f cm %f cm moveto\n' % self.translate(x1,y1))
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x1,y1)))
self.f.write(fdef)
self.f.write('(%s) show grestore\n' % text)
@ -254,17 +263,19 @@ class PSDrawDoc(BaseDoc.BaseDoc):
self.f.write('gsave\n')
self.f.write(fdef)
self.f.write('%4.2f cm %4.2f cm translate\n' % self.translate(x,y))
self.f.write('%4.2f rotate\n' % -angle)
coords = self.translate(x,y)
self.f.write('%s cm %s cm translate\n' % (
gformat(coords[0]),gformat(coords[1])))
self.f.write('%s rotate\n' % gformat(-angle))
self.f.write('%.4f %.4f %.4f setrgbcolor\n' % rgb_color(stype.get_color()))
self.f.write('%s %s %s setrgbcolor\n' % lrgb(stype.get_color()))
val = len(text)
y = ((size * val)/2.0) - size
for line in text:
self.f.write('(%s) dup stringwidth pop -2 div '% line.encode('iso-8859-1'))
self.f.write("%.4f moveto show\n" % y)
self.f.write("%s moveto show\n" % gformat(y))
y -= size
self.f.write('grestore\n')
@ -273,7 +284,7 @@ class PSDrawDoc(BaseDoc.BaseDoc):
stype = self.draw_styles[style]
self.f.write('gsave\n')
self.f.write('newpath\n')
self.f.write('%.4f setlinewidth\n' % stype.get_line_width())
self.f.write('%s setlinewidth\n' % gformat(stype.get_line_width()))
if stype.get_line_style() == BaseDoc.SOLID:
self.f.write('[] 0 setdash\n')
else:
@ -282,17 +293,17 @@ class PSDrawDoc(BaseDoc.BaseDoc):
point = path[0]
x1 = point[0]+self.lmargin
y1 = point[1]+self.tmargin
self.f.write('%f cm %f cm moveto\n' % self.translate(x1,y1))
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x1,y1)))
for point in path[1:]:
x1 = point[0]+self.lmargin
y1 = point[1]+self.tmargin
self.f.write('%f cm %f cm lineto\n' % self.translate(x1,y1))
self.f.write('%s cm %s cm lineto\n' % coords(self.translate(x1,y1)))
self.f.write('closepath\n')
color = stype.get_fill_color()
self.f.write('gsave %.4f %.4f %.4f setrgbcolor fill grestore\n' % rgb_color(color))
self.f.write('%.4f %.4f %.4f setrgbcolor stroke\n' % rgb_color(stype.get_color()))
self.f.write('gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(color))
self.f.write('%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()))
self.f.write('grestore\n')
def draw_line(self,style,x1,y1,x2,y2):
@ -302,16 +313,16 @@ class PSDrawDoc(BaseDoc.BaseDoc):
y2 = y2 + self.tmargin
stype = self.draw_styles[style]
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('%.4f setlinewidth\n' % stype.get_line_width())
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x1,y1)))
self.f.write('%s cm %s cm lineto\n' % coords(self.translate(x2,y2)))
self.f.write('%s setlinewidth\n' % gformat(stype.get_line_width()))
if stype.get_line_style() == BaseDoc.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('%.4f %.4f %.4f setrgbcolor stroke\n' % rgb_color(stype.get_color()))
self.f.write('%s %s %s setrgbcolor stroke\n' % lrgb(stype.get_color()))
self.f.write('grestore\n')
def patch_text(self,text):
@ -326,7 +337,7 @@ class PSDrawDoc(BaseDoc.BaseDoc):
(text,fdef) = self.encode_text(para_style,text)
self.f.write('gsave\n')
self.f.write('%f cm %f cm moveto\n' % self.translate(x,y))
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x,y)))
self.f.write(fdef)
self.f.write('(%s) show grestore\n' % text)
@ -341,14 +352,14 @@ class PSDrawDoc(BaseDoc.BaseDoc):
color = rgb_color(box_type.get_color())
self.f.write('gsave\n')
self.f.write("%f cm %f cm moveto\n" % self.translate(x1,y1))
self.f.write("0 %f cm rlineto\n" % (y2-y1))
self.f.write("%f cm 0 rlineto\n" % (x2-x1))
self.f.write("0 %f cm rlineto\n" % (y1-y2))
self.f.write("%s cm %s cm moveto\n" % coords(self.translate(x1,y1)))
self.f.write("0 %s cm rlineto\n" % gformat(y2-y1))
self.f.write("%s cm 0 rlineto\n" % gformat(x2-x1))
self.f.write("0 %s cm rlineto\n" % gformat(y1-y2))
self.f.write('closepath\n')
self.f.write("%.4f setlinewidth\n" % box_type.get_line_width())
self.f.write('gsave %.4f %.4f %.4f setrgbcolor fill grestore\n' % fill_color)
self.f.write('%.4f %.4f %.4f setrgbcolor stroke\n' % color)
self.f.write("%s setlinewidth\n" % gformat(box_type.get_line_width()))
self.f.write('gsave %s %s %s setrgbcolor fill grestore\n' % lrgb(fill_color))
self.f.write('%s %s %s setrgbcolor stroke\n' % lrgb(color))
self.f.write('grestore\n')
def draw_box(self,style,text,x,y):
@ -366,34 +377,38 @@ class PSDrawDoc(BaseDoc.BaseDoc):
shadsize = box_style.get_shadow_space()
if box_style.get_shadow():
self.f.write('newpath\n')
self.f.write('%f cm %f cm moveto\n' % self.translate(x+shadsize,y+shadsize))
self.f.write('0 -%f cm rlineto\n' % bh)
self.f.write('%f cm 0 rlineto\n' % bw)
self.f.write('0 %f cm rlineto\n' % bh)
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x+shadsize,y+shadsize)))
self.f.write('0 -%s cm rlineto\n' % gformat(bh))
self.f.write('%s cm 0 rlineto\n' % gformat(bw))
self.f.write('0 %s cm rlineto\n' % gformat(bh))
self.f.write('closepath\n')
self.f.write('.5 setgray\n')
self.f.write('fill\n')
self.f.write('newpath\n')
self.f.write('%f cm %f cm moveto\n' % self.translate(x,y))
self.f.write('0 -%f cm rlineto\n' % bh)
self.f.write('%f cm 0 rlineto\n' % bw)
self.f.write('0 %f cm rlineto\n' % bh)
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x,y)))
self.f.write('0 -%s cm rlineto\n' % gformat(bh))
self.f.write('%s cm 0 rlineto\n' % gformat(bw))
self.f.write('0 %s cm rlineto\n' % gformat(bh))
self.f.write('closepath\n')
self.f.write('1 setgray\n')
self.f.write('fill\n')
self.f.write('newpath\n')
if box_style.get_line_width():
self.f.write('%f cm %f cm moveto\n' % self.translate(x,y))
self.f.write('0 -%f cm rlineto\n' % bh)
self.f.write('%f cm 0 rlineto\n' % bw)
self.f.write('0 %f cm rlineto\n' % bh)
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x,y)))
self.f.write('0 -%s cm rlineto\n' % gformat(bh))
self.f.write('%s cm 0 rlineto\n' % gformat(bw))
self.f.write('0 %s cm rlineto\n' % gformat(bh))
self.f.write('closepath\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()))
self.f.write('%s setlinewidth\n' % gformat(box_style.get_line_width()))
self.f.write('%s %s %s setrgbcolor stroke\n' % lrgb(box_style.get_color()))
if text != "":
(text,fdef) = self.encode_text(p,text)
self.f.write(fdef)
lines = '\n'.split(text)
lines = text.split('\n')
print text
print lines
nlines = len(lines)
mar = 10/28.35
f_in_cm = p.get_font().get_size()/28.35
@ -402,7 +417,7 @@ class PSDrawDoc(BaseDoc.BaseDoc):
ystart = center - (fs/2.0) * nlines
for i in range(nlines):
ypos = ystart + (i * fs)
self.f.write('%f cm %f cm moveto\n' % self.translate(x+mar,ypos))
self.f.write('%s cm %s cm moveto\n' % coords(self.translate(x+mar,ypos)))
self.f.write("(%s) show\n" % lines[i])
self.f.write('grestore\n')