0000876: Calendar would print beyond a day's borders if too many, or too long
svn: r7992
This commit is contained in:
parent
70d9579340
commit
c95ebb4282
@ -1,6 +1,9 @@
|
||||
2007-01-26 Douglas Blank <dblank@cs.brynmawr.edu>
|
||||
* src/ReportBase/ReportUtils.py: 0000875: _ReportUtils.py has incorrect
|
||||
conversion cm2pt
|
||||
* src/FontScale.py: add string_trim()
|
||||
* src/plugins/Calendar.py: 0000876: Calendar would print beyond a day's
|
||||
borders if too many, or too long
|
||||
|
||||
2007-01-26 Don Allingham <don@gramps-project.org>
|
||||
* src/DataViews/_MediaView.py: fix accelerator entries
|
||||
|
@ -261,3 +261,63 @@ def string_width(font,text):
|
||||
except:
|
||||
r = r + l[ord('n')]
|
||||
return (r+1)*s
|
||||
|
||||
def string_trim(font, text, width, ellipses = "..."):
|
||||
"""
|
||||
Like string_width, but this makes sure the length of the
|
||||
string is <= width. Optionally, add ellipses (...).
|
||||
"""
|
||||
i = font.get_type_face()
|
||||
j = font.get_bold() + font.get_italic()*2
|
||||
s = font.get_size()
|
||||
l = _font_array[i][j]
|
||||
ellipses_length = 0
|
||||
# get length of each letter
|
||||
for c in ellipses:
|
||||
try:
|
||||
ellipses_length += l[ord(c)]
|
||||
except:
|
||||
ellipses_length += l[ord('n')]
|
||||
# find the part that is < width
|
||||
retval = ""
|
||||
sumlen = 0
|
||||
length = 0
|
||||
for i in range(len(text)):
|
||||
c = text[i]
|
||||
try:
|
||||
length = l[ord(c)]
|
||||
except:
|
||||
length = l[ord('n')]
|
||||
# too long:
|
||||
if (sumlen + length + 1) * s > width:
|
||||
if ellipses_length > 0:
|
||||
# try again with ellipses
|
||||
retval += c
|
||||
sumlen += length
|
||||
break
|
||||
else:
|
||||
# return just this so far
|
||||
return retval
|
||||
retval += c
|
||||
sumlen += length
|
||||
# if exited out the bottom:
|
||||
if (sumlen + 1) * s <= width:
|
||||
return text
|
||||
# too long; try again with ellipses
|
||||
retval = ""
|
||||
sumlen = 0
|
||||
length = 0
|
||||
for i in range(len(text)):
|
||||
c = text[i]
|
||||
try:
|
||||
length = l[ord(c)]
|
||||
except:
|
||||
length = l[ord('n')]
|
||||
if (sumlen + length + 1) * s > width:
|
||||
return retval
|
||||
if (sumlen + length + ellipses_length + 1) * s > width:
|
||||
return retval + ellipses
|
||||
retval += c
|
||||
sumlen += length
|
||||
# should not exit out the bottom!
|
||||
return text
|
||||
|
@ -41,10 +41,12 @@ from PluginUtils import register_report
|
||||
from ReportBase import Report, ReportUtils, ReportOptions, \
|
||||
CATEGORY_DRAW, CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI
|
||||
pt2cm = ReportUtils.pt2cm
|
||||
cm2pt = ReportUtils.cm2pt
|
||||
from Filters import GenericFilter, ParamFilter, Rules
|
||||
import GrampsLocale
|
||||
import RelLib
|
||||
from Utils import probably_alive
|
||||
from FontScale import string_trim, string_width
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -238,6 +240,12 @@ class Calendar(Report):
|
||||
position += (lines * spacing)
|
||||
current = 0
|
||||
for line in p.split("\n"):
|
||||
# make sure text will fit:
|
||||
numpos = pt2cm(self["CAL-Numbers"].get_size())
|
||||
if position + (current * spacing) - 0.1 >= cell_height - numpos: # font daynums
|
||||
continue
|
||||
font = self["CAL-Text"]
|
||||
line = string_trim(font, line, cm2pt(cell_width + 0.2))
|
||||
self.doc.draw_text("CAL-Text", line,
|
||||
day_col * cell_width + 0.1,
|
||||
header + (week_row + 1) * cell_height - position + (current * spacing) - 0.1)
|
||||
|
Loading…
Reference in New Issue
Block a user