示例#1
0
 def _drawGrid(self):
     label_every = 1
     if self.units > 24:
         label_every = 2
     drawing.save()
     drawing.strokeWidth(0)
     drawing.stroke(None)
     drawing.fill(0.88, 0.92, 0.98)
     if self.system is not None:
         if self.system.min_units is not None:
             drawing.rect(0, 0, 10 + self.system.min_units * self.histogram_width / (self.units * self.ems_horizontal), self.histogram_height)
         if self.system.max_units is not None:
             drawing.rect(10 + self.system.max_units * self.histogram_width / (self.units * self.ems_horizontal), 0, self.histogram_width, self.histogram_height)
     
     drawing.strokeWidth(1.0)
     drawing.stroke(0.8, 0.8, 0.8)
     drawing.fill(0.6, 0.6, 0.6)
     for u in range(0, int(ceil(self.units * self.ems_horizontal))):
         x = 10 + u * self.histogram_width / (self.units * self.ems_horizontal)
         if u == self.units:
             # mark the full em
             drawing.stroke(0, 0, 0)
             drawing.line(x, 20, x, self.histogram_height-10)
             drawing.strokeWidth(0)
             drawing.text("1 em", x + 4, self.histogram_height - 21)
             drawing.strokeWidth(1.0)
         elif u % 10 == 0:
             # make every 10th line darker
             drawing.stroke(0.5, 0.5, 0.5)
             drawing.line(x, 20, x, self.histogram_height - 20)
         else:
             drawing.stroke(0.8, 0.8, 0.8)
             drawing.line(x, 20, x, self.histogram_height - 30)
         if u % label_every == 0:
             drawing.strokeWidth(0)
             drawing.text("%s" % (u), x - 3 * len(str(u)), 5)
     drawing.restore()
示例#2
0
 def draw_histogram(self, font, upm, color, show_glyphs=False, histogram=None):
     if histogram is None:
         try:
             histogram = self.histogram
         except Exception, err:
             self.calculate_histogram
     drawing.save()
     if histogram is None:
         try:
             histogram = self.histogram
         except:
             pass
     if histogram is None:
         print "__no Histogram"
         return
     drawing.fill(1, 0.5, 0.2, 1.0)
     drawing.stroke(color[0], color[1], color[2], color[3])
     try:
         for width in sorted(histogram.keys()):
             num = len(histogram[width])
             x = 10 + width * self.histogram_width / (upm * self.ems_horizontal)
             drawing.save()
             if show_glyphs:
                 drawing.save()
                 drawing.fill(color[0], color[1], color[2], 0.2)
                 drawing.fontsize(self.scale_vertical)
                 for i in range(len(histogram[width])):
                     glyph_name = histogram[width][i]
                     if glyph_name in font:
                         u = font[glyph_name].unicode
                         if u: