Ejemplo n.º 1
0
    def draw(self, page, x, y):
        fillColor = self.style.get('fill')
        if fillColor is not None:
            setFillColor(fillColor)
            setStrokColor(None)

        stroke(0.8)
        strokeWidth(0.5)
        fill(None)
        rect(x, y, self.w, self.h)
        if len(self.dimensions) == 1:
            raise ValueError('Not supporting 1 axis now')
        if len(self.dimensions) > 2:
            raise ValueError('Not supporting >2 axis now')

        axisNames = sorted(self.dimensions.keys())
        axisX = axisNames[0]
        sizeX = self.dimensions[axisX]
        axisY = axisNames[1]
        sizeY = self.dimensions[axisY]
        stepX = self.w / (sizeX + 1)
        stepY = self.h / (sizeY + 1)
        """Add more parametric layout behavior here."""
        RANGE = 1000
        for indexX in range(sizeX + 1):
            for indexY in range(sizeY + 1):
                ox = 30
                oy = 25
                px = ox + x + indexX * stepX
                py = oy + y + indexY * stepY
                self.location[axisX] = indexX * RANGE / sizeX
                self.location[axisY] = indexY * RANGE / sizeY
                glyphPathScale = self.fontSize / self.font.info.unitsPerEm

                drawGlyphPath(self.font.ttFont,
                              self.glyphNames[0],
                              px,
                              py,
                              self.location,
                              s=glyphPathScale,
                              fillColor=(0, 0, 0))

                fs = FormattedString('%s %d\n%s %d' %
                                     (axisX, indexX * RANGE / sizeX, axisY,
                                      indexY * RANGE / sizeY),
                                     fontSize=6,
                                     fill=0)
                w, h = fs.size()
                page.text(
                    fs, px - stepX / 4, py -
                    16)  # Bit of hack, we need the width of the glyph here.
        fs = FormattedString('Other axes: %s' % self.location,
                             fontSize=6,
                             fill=0)
        w, h = fs.size()
        page.text(fs, x, y - 16)
Ejemplo n.º 2
0
    def draw(self, page, x, y):

        if self.drawBefore is not None:  # Call if defined
            self.drawBefore(self, p, view)

        fillColor = self.style.get('fill')
        if fillColor is not None:
            setFillColor(fillColor)
            setStrokColor(None)

        #stroke(0.8)
        #strokeWidth(0.5)
        #fill(None)
        #rect(x, y, self.w, self.h)

        stroke(None)

        stepX = self.w / (self.sizeX + 1)
        stepY = self.h / (self.sizeY + 1)
        """Add more parametric layout behavior here."""
        for indexX in range(self.sizeX + 1):
            for indexY in range(self.sizeY + 1):
                ox = 30
                oy = 25
                px = ox + x + indexX * stepX
                py = oy + y + indexY * stepY
                if self.locations is not None:
                    location = choice(self.locations)
                else:
                    location = self.getRandomLocation()
                glyphPathScale = self.fontSize / self.font.info.unitsPerEm
                fillColor = self.style.get('textFill') or (0, 0, 0)
                drawGlyphPath(self.font.ttFont,
                              self.glyphNames[0],
                              px,
                              py,
                              location,
                              s=glyphPathScale,
                              fillColor=fillColor)
                if self.recipeAxes:
                    recipe = self.location2Recipe(location)
                    fs = FormattedString(recipe, fontSize=4, fill=0)
                    w, h = fs.size()
                    page.text(
                        fs, px - stepX / 4, py - 24
                    )  # Bit of hack, we need the width of the glyph here.
                    if len(self.recipeAxes) > 3:
                        recipe = self.location2Recipe(location, 3, 6)
                        fs = FormattedString(recipe, fontSize=4, fill=0)
                        w, h = fs.size()
                        page.text(
                            fs, point(px - stepX / 4 + 30, py - 24)
                        )  # Bit of hack, we need the width of the glyph here.

        if self.drawAfter is not None:  # Call if defined
            self.drawAfter(self, p, view)