Ejemplo n.º 1
0
 def demo(self):
     D = shapes.Drawing(200, 100)
     yn = YesNo()
     yn.x = 15
     yn.y = 25
     yn.size = 70
     yn.testValue = 0
     yn.draw()
     D.add(yn)
     yn2 = YesNo()
     yn2.x = 120
     yn2.y = 25
     yn2.size = 70
     yn2.testValue = 1
     yn2.draw()
     D.add(yn2)
     labelFontSize = 8
     D.add(shapes.String(yn.x+(yn.size/2),(yn.y-(1.2*labelFontSize)),
                         'testValue=0', fillColor=colors.black, textAnchor='middle',
                         fontSize=labelFontSize))
     D.add(shapes.String(yn2.x+(yn2.size/2),(yn2.y-(1.2*labelFontSize)),
                         'testValue=1', fillColor=colors.black, textAnchor='middle',
                         fontSize=labelFontSize))
     labelFontSize = 10
     D.add(shapes.String(yn.x+85,(yn.y-20),
                         self.__class__.__name__, fillColor=colors.black, textAnchor='middle',
                         fontSize=labelFontSize))
     return D
Ejemplo n.º 2
0
    def draw_label(label, width, height, vara):

        textastaerd = 32
        nafnbreidd = stringWidth(vara.fulltnafn, "Helvetica", textastaerd)
        while nafnbreidd > width - 4:
            textastaerd *= 0.95
            nafnbreidd = stringWidth(vara.fulltnafn, "Helvetica", textastaerd)

        nafnbreidd = stringWidth(vara.fulltnafn, "Helvetica", textastaerd)
        label.add(
            shapes.String((width - nafnbreidd) / 2,
                          height - 32 - 16,
                          str(vara.fulltnafn),
                          fontName="Helvetica",
                          fontSize=textastaerd))

        label.add(
            shapes.String(2,
                          2,
                          str(vara.verd().smasoluverd) + ' kr.',
                          fontName="Helvetica",
                          fontSize=16))
        label.add(
            shapes.String(width - 2,
                          2,
                          str(vara.vorunumer()),
                          fontName="Helvetica",
                          fontSize=16,
                          textAnchor="end"))
Ejemplo n.º 3
0
 def draw_label_top_bc(label, width, height, obj):
     # Just convert the object to a string and print this at the bottom left of
     # the label.
     label.add(
         shapes.String(2, 2, str(obj[0]), fontName="Helvetica",
                       fontSize=12))
     label.add(
         shapes.String(2,
                       13,
                       str(obj[1]),
                       fontName="Helvetica",
                       fontSize=12))
     label.add(
         shapes.String(2,
                       24,
                       str(obj[2]),
                       fontName="Helvetica",
                       fontSize=12))
     label.add(shapes.Image(2, 46, 180, 40, make_barcode(obj[3])))
     # label.add(shapes.String(38, 30, str(obj[3]), fontName="3of9", fontSize=30))
     label.add(
         shapes.String(2,
                       35,
                       str(obj[4]),
                       fontName="Helvetica",
                       fontSize=12))
Ejemplo n.º 4
0
def draw_label(label, width, height, obj):
    #  + ' <img src="images/air.png" valign="middle"/>',
    i = 90
    for t in obj[0]:
        for r in t:
            label.add(shapes.String(10, i, str(r), fontName="Helvetica", fontSize=9))
            p = Paragraph("lol", normalStyle)
            i = i - 10
        i = i - 20

    # i = 50
    # for t in obj[1]:
    #    label.add(shapes.String(10, i, str(t), fontName="Helvetica", fontSize=9))
    #    i = i - 10

    i = 10
    # for t in obj[2]:
    for t in obj[1]:
        label.add(shapes.String(10, i, '<b>' + str(t) + '</b>', fontName="Helvetica", fontSize=9))
        # label.add(drawing)
        i = i - 10

    s = shapes.Rect(5, 8, 150, 11, fill = True)
    s.fillColor = transparent
    label.add(s)
Ejemplo n.º 5
0
def draw_label(label, width, height, obj):

	font_size = 28
	f_size = 20
	text_width = width - 5
	name_width = stringWidth(obj, "Helvetica", font_size)


	while name_width > text_width: # compresses the label to fit within its boundaries 
	  	font_size *= 0.9
		name_width = stringWidth(obj, "Helvetica", font_size)



	firstpart, secondpart = obj[:len(obj)/2], obj[len(obj)/2:]

	t = shapes.String(width/2.0, 30, obj, textAnchor="middle")
	s = shapes.String(width/2.0, 35, firstpart, textAnchor="middle")
	e = shapes.String(width/2.0, 19, secondpart, textAnchor="middle")


	e.fontSize = f_size
	s.fontSize = f_size
	t.fontSize = font_size

 ####need to figure a test for str lenght to format it##########
	if len(obj) <= 23:
		label.add(t)
	elif len(obj) <= 33:
		label.add(s)
		label.add(e)
Ejemplo n.º 6
0
def draw_label(label, width, height, obj):
    # converts each part to a string and adds separately so that everything is done on separate lines
    text = str(obj).split('\n')
    label.add(shapes.String(20, 50, text[0], fontName="Helvetica",
                            fontSize=10))
    label.add(shapes.String(20, 35, text[1], fontName="Helvetica",
                            fontSize=10))
    label.add(shapes.String(20, 20, text[2], fontName="Helvetica",
                            fontSize=10))
Ejemplo n.º 7
0
def draw_athlete_label(label, width, height, obj):
    label.add(
        shapes.String(10,
                      53,
                      obj['id'],
                      fontName="Helvetica-Bold",
                      fontSize=16))
    label.add(
        shapes.String(10, 38, obj['name'], fontName="Helvetica", fontSize=12))
    label.add(
        shapes.String(10, 24, obj['team'], fontName="Helvetica", fontSize=11))
    label.add(
        shapes.String(10, 10, obj['info'], fontName="Helvetica", fontSize=10))
Ejemplo n.º 8
0
def draw_label(label, width, height, part):
    # The coordinate begins on lower left, use width and height together
    # with fontsize (although in points and not mm) to align the shapes.

    # In partkeepr I'm using a hierarchy exactly similar to
    # http://octopart.com/search, the lines here represent a part with
    # the longest (end node) in that hierarchy. You can use  these as a
    # static test to see if the label is correct

    # label.add(shapes.String(5, height-5, "Clock Generators, PLLs, Frequency Synthesizers", fontName="Consolas Bold", fontSize=10))
    # label.add(shapes.String(10, height-15, "MOSFETs", fontName="Consolas Bold", fontSize=10))
    # label.add(shapes.String(10, height-45, "Lattice Semiconductor", fontName="Consolas Bold", fontSize=13))
    # label.add(shapes.String(10, height-60, "LC4064V-75TN100C", fontName="Consolas Bold", fontSize=13))
    # label.add(shapes.Rect(width-50, height-55, 40, 20, strokeWidth=1, fillColor=None))
    # label.add(shapes.String(width-45, height-48, "#4444", fontName="Consolas Bold", fontSize=11))
    # label.add(shapes.Line(10, height-75, width-10,height-75, strokeWidth=1))

    label.add(
        shapes.String(10,
                      height - 15,
                      part["category"],
                      fontName="Consolas Bold",
                      fontSize=10))
    label.add(
        shapes.String(10,
                      height - 45,
                      part["name"],
                      fontName="Consolas Bold",
                      fontSize=13))
    label.add(
        shapes.String(10,
                      height - 60,
                      part["description"],
                      fontName="Consolas Bold",
                      fontSize=10))
    label.add(
        shapes.Line(10, height - 75, width - 10, height - 75, strokeWidth=1))
    label.add(
        shapes.Rect(width - 50,
                    height - 43,
                    40,
                    20,
                    strokeWidth=1,
                    fillColor=None))
    label.add(
        shapes.String(width - 46,
                      height - 36,
                      part["id36"],
                      fontName="Consolas Bold",
                      fontSize=10))
Ejemplo n.º 9
0
def draw_team_label(label, width, height, obj):
    label.add(
        shapes.String(10,
                      53,
                      obj['team'],
                      fontName="Helvetica-Bold",
                      fontSize=16))
    label.add(
        shapes.String(10,
                      38,
                      obj['session'],
                      fontName="Helvetica",
                      fontSize=12))
    label.add(
        shapes.String(10, 10, obj['level'], fontName="Helvetica", fontSize=10))
Ejemplo n.º 10
0
    def mailing_label(label, width, height, data):
        font = "Helvetica"
        lines = []
        num_lines = 0
        lines.append(data.name + ", " + data.prisoner_id_raw)
        num_lines += 1
        if len(data.address.address_1) > 0:
            lines.append(data.address.address_1)
            num_lines += 1
        if len(data.address.address_2) > 0:
            lines.append(data.address.address_2)
            num_lines += 1
        if len(data.address.address_3) > 0:
            lines.append(data.address.address_3)
            num_lines += 1
        lines.append(data.address.city + ', ' + data.address.state + ', ' +
                     data.address.postal_code)
        num_lines += 1
        fontsize = 20
        maxIndex = 0
        for i in range(1, num_lines):
            # calculate size of font
            if len(lines[i]) > len(lines[maxIndex]):
                maxIndex = i
        fontsize = 15
        add_width = stringWidth(lines[maxIndex], font, fontsize)
        text_width = width - 10
        font_height = 15
        while add_width > text_width:
            fontsize *= 0.9
            add_width = stringWidth(lines[maxIndex], font, fontsize)

        for i in range(0, num_lines):
            label.add(
                shapes.String(5,
                              height - 15 - fontsize * i,
                              lines[i],
                              fontName=font,
                              fontSize=fontsize))
        if program.print_rule:
            label.add(
                shapes.String(187,
                              3,
                              data.rules,
                              fontName=font,
                              fontSize=fontsize,
                              textAnchor='end'))
Ejemplo n.º 11
0
 def __call__(self, legend, g, thisx, y, i, colName, swatch):
     g.add(
         shapes.String(swatch.x - 2,
                       y,
                       self._texts[i],
                       textAnchor='end',
                       fontName=self._fontName,
                       fontSize=self._fontSize))
Ejemplo n.º 12
0
def draw_label(label, width, height, obj):
    # To demonstrate that this is only called once for each label, no matter
    # how many times it is repeated on the sheet.
    print('Drawing "{0:s}".'.format(str(obj)))

    # Just convert the object to a string and print this at the bottom left of
    # the label.
    label.add(shapes.String(2, 2, str(obj), fontName="Helvetica", fontSize=40))
def draw_label_plate(label, width, height, obj):
    # Generate QR Code for labels
    qr_barcode = mktemp(suffix='.png')

    qrcode.make(str(obj['ID'])).save(qr_barcode, "png")
    label.add(shapes.Image(3, 0, 44, 44, qr_barcode))
    label.add(
        shapes.String(45, 16, str(obj['ID']), fontName="Courier", fontSize=16))
Ejemplo n.º 14
0
    def draw(self):
        """ returns a group of shapes
        """
        g = shapes.Group()

        #overall border and fill
        if self.borderStrokeColor or self.fillColor: # adds border and filling color
            rect = shapes.Rect(self.x, self.y, self.width, self.height)
            rect.fillColor = self.fillColor
            rect.strokeColor = self.borderStrokeColor
            rect.strokeWidth = self.borderStrokeWidth
            g.add(rect)

        #special case - for an empty table we want to avoid divide-by-zero
        data = self.preProcessData(self.data)
        rows = len(self.data)
        cols = len(self.data[0])
        #print "(rows,cols)=(%s, %s)"%(rows,cols)
        row_step = self.height / float(rows)
        col_step = self.width / float(cols)
        #print "(row_step,col_step)=(%s, %s)"%(row_step,col_step)
        # draw the grid
        if self.horizontalDividerStrokeColor:
            for i in range(rows): # make horizontal lines
                x1 = self.x
                x2 = self.x + self.width
                y = self.y + row_step*i
                #print 'line (%s, %s), (%s, %s)'%(x1, y, x2, y)
                line = shapes.Line(x1, y, x2, y)
                line.strokeDashArray = self.dividerDashArray
                line.strokeWidth = self.horizontalDividerStrokeWidth
                line.strokeColor = self.horizontalDividerStrokeColor
                g.add(line)
        if self.verticalDividerStrokeColor:
            for i in range(cols): # make vertical lines
                x = self.x+col_step*i
                y1 = self.y
                y2 = self.y + self.height
                #print 'line (%s, %s), (%s, %s)'%(x, y1, x, y2)
                line = shapes.Line(x, y1, x, y2)
                line.strokeDashArray = self.dividerDashArray
                line.strokeWidth = self.verticalDividerStrokeWidth
                line.strokeColor = self.verticalDividerStrokeColor
                g.add(line)

        # since we plot data from down up, we reverse the list
        self.data.reverse()
        for (j, row) in enumerate(self.data):
            y = self.y + j*row_step + 0.5*row_step - 0.5 * self.fontSize
            for (i, datum) in enumerate(row):
                if datum:
                    x = self.x + i*col_step + 0.5*col_step
                    s = shapes.String(x, y, str(datum), textAnchor=self.textAnchor)
                    s.fontName = self.fontName
                    s.fontSize = self.fontSize
                    s.fillColor = self.fontColor
                    g.add(s)
        return g
def write_content(label, width, height, filepath):

    # Create a shape for the QR code image and position it
    im = Image.open(filepath)
    imwidth, imheight = im.size
    a = shapes.Image(((width / 2.0) - (imwidth / 2.0)), 45, imwidth, imheight,
                     filepath)

    # Create a human-readable label and position it
    human_readable = os.path.splitext(os.path.split(filepath)[1])[0]
    b = shapes.String(width / 2.0, 15, human_readable, textAnchor="middle")

    # Create a space to write in a donor name
    c = shapes.String(30, (height - 30), "Donor name: ")

    label.add(a)
    label.add(b)
    label.add(c)
Ejemplo n.º 16
0
def draw_label(label, width, height, obj):
    # Just convert the object to a string and print this at the bottom left of
    # the label.
    Prenom = obj[0]
    Nom = obj[1]
    Entreprise = obj[2]
    Email = obj[3]
    Tel = obj[4]

    # Measure the width of the first name and shrink the font size until it fits.
    prenom_font_size = 14
    text_width = width - 90
    prenom_width = stringWidth(Prenom, "Helvetica", prenom_font_size)
    while prenom_width > text_width:
        prenom_font_size *= 0.8
        prenom_width = stringWidth(Prenom, "Helvetica", prenom_font_size)

    label.add(shapes.String(10, 90, Prenom.decode('utf-8').title(), fontName="Helvetica-Bold", fontSize=prenom_font_size))

    # Measure the width of the last name and shrink the font size until it fits.
    nom_font_size = 14
    text_width = width - 90
    nom_width = stringWidth(Nom, "Helvetica", nom_font_size)
    while nom_width > text_width:
        nom_font_size *= 0.8
        nom_width = stringWidth(Nom, "Helvetica", nom_font_size)

    label.add(shapes.String(10, 60, Nom.decode('utf-8').upper(), fontName="Helvetica-Bold", fontSize=nom_font_size))

    # Measure the width of the entreprise and shrink the font size until it fits.
    entreprise_font_size = 14
    text_width = width - 5
    Entreprise_width = stringWidth(Entreprise, "Helvetica", entreprise_font_size)
    while Entreprise_width > text_width:
        entreprise_font_size *= 0.8
        Entreprise_width = stringWidth(Entreprise, "Helvetica", entreprise_font_size)

    label.add(shapes.String(10, 20, Entreprise, fontName="Helvetica", fontSize=entreprise_font_size))

    # Insertion du QRCode
    NomComplet= Prenom + " " + Nom
    vcard="BEGIN:VCARD\nN:" + NomComplet + "\nORG:" + Entreprise + "\nEMAIL:" + Email + "\nTEL;TYPE=WORK:" + Tel + "\nEND:VCARD"
    img = qrcode.make(vcard)
    label.add(shapes.Image(190,35,80,80,img))
Ejemplo n.º 17
0
def writeLabelInfo(label, width, height, info):
    # (0, 0) is bottom left, (width, height) is top right

    startingFontSize = 12

    x = 5  # starting x coord
    numOfLines = 5  # lines on labels
    verticalSpacing = height / (numOfLines + 2)
    y = height - 20  # starting y coord

    # name
    s = shapes.String(x, y, info[0], fontName="Times-Roman", fontSize=startingFontSize)
    label.add(s)

    # address, shrink font to fit label
    font_size = startingFontSize
    while stringWidth(info[1], "Times-Roman", font_size) > width - 10:
        font_size *= 0.9
    y -= verticalSpacing
    s = shapes.String(x, y, info[1], fontName="Times-Roman", fontSize=font_size)
    label.add(s)

    # city, state, , shrink font to fit label
    tmpStr = info[2] + ", " + info[3]
    # font_size = startingFontSize
    while stringWidth(tmpStr, "Times-Roman", font_size) > width - 10:
        font_size *= 0.9
    y -= verticalSpacing
    s = shapes.String(x, y, tmpStr, fontName="Times-Roman", fontSize=font_size)
    label.add(s)

    # country poscode
    tmpStr = str(info[4]) + " " + str(info[5])
    y -= verticalSpacing
    s = shapes.String(x, y, tmpStr, fontName="Times-Roman", fontSize=font_size)
    label.add(s)

    # orders, shrink font to fit label
    # font_size = startingFontSize
    while stringWidth(info[6], "Times-Roman", font_size) > width - 10:
        font_size *= 0.9
    y -= verticalSpacing
    s = shapes.String(x, y, info[6], fontName="Times-Roman", fontSize=font_size)
    label.add(s)
Ejemplo n.º 18
0
def write_name(label, width, height, name):
    # Write the title.
    label.add(shapes.String(5, height-20, "Hello, my name is",
                            fontName="Judson Bold", fontSize=20))

    # Measure the width of the name and shrink the font size until it fits.
    font_size = 50
    text_width = width - 10
    name_width = stringWidth(name, "KatamotzIkasi", font_size)
    while name_width > text_width:
        font_size *= 0.8
        name_width = stringWidth(name, "KatamotzIkasi", font_size)

    # Write out the name in the centre of the label with a random colour.
    s = shapes.String(width/2.0, 15, name, textAnchor="middle")
    s.fontName = "KatamotzIkasi"
    s.fontSize = font_size
    s.fillColor = random.choice((colors.black, colors.blue, colors.red, colors.green))
    label.add(s)
Ejemplo n.º 19
0
 def process(self):
     attrs = dict(self.getAttributeValues())
     string = shapes.String(attrs.pop('x'), attrs.pop('y'),
                            attrs.pop('text'))
     angle = attrs.pop('angle', 0)
     for name, value in attrs.items():
         setattr(string, name, value)
     group = shapes.Group(string)
     group.translate(0, 0)
     group.rotate(angle)
     self.parent.parent.drawing.add(group)
Ejemplo n.º 20
0
 def demo(self):
     D = shapes.Drawing(200, 100)
     s = float(self.size)
     ob = self.__class__()
     ob.x=50
     ob.y=0
     ob.draw()
     D.add(ob)
     D.add(shapes.String(ob.x+(s/2),(ob.y-12),
                         ob.__class__.__name__, fillColor=colors.black, textAnchor='middle',
                         fontSize=10))
     return D
Ejemplo n.º 21
0
    def draw(self):
        g = shapes.Group()

        for attr, info in filter(lambda x: x[1]["visible"],
                                 self.render_info.items()):
            if hasattr(self, attr):
                val = getattr(self, attr)
                if val is not None:
                    fs = info["font_size"] * self.baseheight
                    rel = info["offset_relative"]
                    y = self.y
                    if rel == "self":
                        x = self.x
                    elif rel == "edge" and self.parent:
                        x = self.x - (self.x - self.parent.x) * 0.5
                    dx = info["x_offset"] * fs
                    dy = info["y_offset"] * fs
                    label = shapes.String(x + dx,
                                          y + dy,
                                          info["format"] % val,
                                          fontName=info["font"],
                                          fontSize=fs,
                                          fillColor=info["font_color"],
                                          textAnchor=info["text_anchor"])
                    g.add(label)

        if self.parent:
            pl = shapes.PolyLine([
                self.x, self.y, self.parent.x, self.y, self.parent.x,
                self.parent.y
            ],
                                 strokeWidth=max(self.calc_strokewidth(), 1.0),
                                 strokeColor=self.stroke_color,
                                 fillColor=None)
            g.add(pl)

            ## thicken strongly supported branches
            if self.thicken:
                pl = shapes.PolyLine(
                    [
                        self.x, self.y, self.parent.x -
                        self.parent.calc_strokewidth() / 2.0, self.y
                    ],
                    strokeWidth=max(self.calc_strokewidth(), 1.0) * 4,
                    strokeColor=self.stroke_color,
                    fillColor=None)
                g.add(pl)

        for d in self.drawables:
            g.add(d)
        return g
Ejemplo n.º 22
0
def draw_label(label, width, height, obj):
    # Just convert the object to a string and print this at the bottom left of
    # the label.
    label.add(
        shapes.String(5,
                      260,
                      "MK Makerspace Project",
                      fontName="Helvetica",
                      fontSize=20))
    label.add(
        shapes.String(5,
                      240,
                      "Inventory & Storage System",
                      fontName="Helvetica",
                      fontSize=20))
    label.add(
        shapes.String(5,
                      215,
                      "Owner: Alan Hacker",
                      fontName="Helvetica",
                      fontSize=15))
    label.add(
        shapes.String(5,
                      200,
                      "Removal date: 31/12/2099",
                      fontName="Helvetica",
                      fontSize=15))
    label.add(
        shapes.String(5,
                      185,
                      "Approved By: Hackerman Jones",
                      fontName="Helvetica",
                      fontSize=15))
    qr_code = qr.QrCodeWidget("https://data.mkmakerspace.co.uk",
                              barLevel='H',
                              barHeight=200,
                              barWidth=200)
    label.add(qr_code)
Ejemplo n.º 23
0
def drawLabel(label, width, height, obj):
    str_obj = str(obj)
    font_size = 50
    text_width = width - 10
    while stringWidth(str_obj, 'Helvetica', font_size) > text_width:
        font_size = font_size * .9

    label.add(
        shapes.String(width / 2,
                      height / 2,
                      str_obj,
                      fontName='Helvetica',
                      fontSize=font_size,
                      textAnchor='middle'))
Ejemplo n.º 24
0
def draw_medal_label(label, width, height, obj):
    label.add(
        shapes.String(width / 2.0,
                      80,
                      obj['meet'],
                      fontName="Helvetica",
                      fontSize=7,
                      textAnchor="middle"))
    label.add(
        shapes.String(width / 2.0,
                      60,
                      obj['place'],
                      fontName="Helvetica-Bold",
                      fontSize=10,
                      textAnchor="middle"))
    label.add(
        shapes.String(width / 2.0,
                      48,
                      obj['event'],
                      fontName="Helvetica-Bold",
                      fontSize=10,
                      textAnchor="middle"))
    label.add(
        shapes.String(width / 2.0,
                      35,
                      obj['level'],
                      fontName="Helvetica",
                      fontSize=8,
                      textAnchor="middle"))
    label.add(
        shapes.String(width / 2.0,
                      25,
                      obj['age_div'],
                      fontName="Helvetica",
                      fontSize=8,
                      textAnchor="middle"))
Ejemplo n.º 25
0
    def write_line(self, text):
        """Write a line of text.

        Each call to this will place a new line base_font_size + pad_extra
        points further down the label.
        """
        font_size = squeeze_in(text, self.width, self.font_name,
                               self.base_font_size)
        self.y -= self.base_font_size
        self.label.add(
            shapes.String(self.x,
                          self.y,
                          text,
                          fontName=self.font_name,
                          fontSize=font_size))
        self.y -= self.pad_extra
Ejemplo n.º 26
0
 def draw_aux_label(self, label, width, height, obj):
     """
     just fill the label with the text
     """
     fontSize = 22
     if width > 127:
         fontSize = 40
     textWidth = stringWidth(obj, self.font, fontSize)
     while textWidth > (width - 10):
         fontSize *= 0.5
         textWidth = stringWidth(obj, self.font, fontSize)
     label.add(
         shapes.String(width / 2.0,
                       height - (fontSize + fontSize / 5.0),
                       obj,
                       textAnchor="middle",
                       fontSize=fontSize))
Ejemplo n.º 27
0
    def draw(self):
        # general widget bits
        s = float(self.size)  # abbreviate as we will use this a lot
        g = shapes.Group()

        # stop-sign specific bits
        athird = s / 3

        outerOctagon = shapes.Polygon(points=[
            self.x + athird, self.y, self.x, self.y + athird, self.x,
            self.y + (athird * 2), self.x + athird, self.y + s,
            self.x + (athird * 2), self.y + s, self.x + s,
            self.y + (athird * 2), self.x + s, self.y + athird,
            self.x + (athird * 2), self.y
        ],
                                      strokeColor=self.strokeColor,
                                      fillColor=None,
                                      strokeWidth=1)
        g.add(outerOctagon)

        innerOctagon = shapes.Polygon(points=[
            self.x + athird + (s / 75), self.y + (s / 75), self.x + (s / 75),
            self.y + athird + (s / 75), self.x + (s / 75),
            self.y + (athird * 2) - (s / 75), self.x + athird + (s / 75),
            self.y + s - (s / 75), self.x + (athird * 2) - (s / 75),
            (self.y + s) - (s / 75),
            (self.x + s) - (s / 75), self.y + (athird * 2) - (s / 75),
            (self.x + s) - (s / 75), self.y + athird + (s / 75),
            self.x + (athird * 2) - (s / 75), self.y + (s / 75)
        ],
                                      strokeColor=None,
                                      fillColor=self.fillColor,
                                      strokeWidth=0)
        g.add(innerOctagon)

        if self.stopColor:
            g.add(
                shapes.String(self.x + (s * 0.5),
                              self.y + (s * 0.4),
                              'STOP',
                              fillColor=self.stopColor,
                              textAnchor='middle',
                              fontSize=s / 3,
                              fontName="Helvetica-Bold"))

        return g
def fit_text_in_area(the_text, font_name, text_width_limit, text_height_limit):
    font_size = text_height_limit
    text_width = stringWidth(the_text, font_name, font_size)
    while ((text_width > text_width_limit) or (font_size > text_height_limit)):
        font_size *= 0.95
        text_width = stringWidth(the_text, font_name, font_size)

    s = shapes.String(0,
                      0,
                      the_text,
                      fontName=font_name,
                      fontSize=font_size,
                      textAnchor="start")
    #pprint("text_height_limit = " + str(text_height_limit))
    #pprint(s.dumpProperties())
    #pprint(s)
    return s
Ejemplo n.º 29
0
def draw_label(label, width, height, obj):
    # Pick a background colour.
    colour = random.choice(colours)

    # And a style.
    style = random.choice(('solid', 'stripes', 'hatch'))

    # Draw a solid background.
    if style == 'solid':
        r = shapes.Rect(0, 0, width, height)
        r.fillColor = colour
        r.strokeColor = None
        label.add(r)

    # Both stripes and hatches need vertical stripes.
    if style in ('stripes', 'hatch'):
        g = Grid()
        g.width = width
        g.height = height
        g.delta = width / 14.0  # The width of the stripes.
        g.delta0 = random.random() * (width / 14.0
                                      )  # Offset of the start of the stripe.
        g.fillColor = None
        g.strokeColor = None
        g.orientation = 'vertical'
        g.stripeColors = (colors.HexColor(0xFFFFFF), colour)
        label.add(g)

    # Draw the horizontal stripes of any hatching.
    # Note the empty parts need to be 'coloured' transparent to avoid
    # hiding the vertical stripes.
    if style == 'hatch':
        g2 = Grid()
        g2.width = width
        g2.height = height
        g2.delta = height / 4.0
        g2.delta0 = random.random() * (height / 4.0)
        g2.fillColor = None
        g2.strokeColor = None
        g2.orientation = 'horizontal'
        g2.stripeColors = (colors.transparent, colour)
        label.add(g2)

    # Print the label value as a string.
    label.add(shapes.String(2, 2, str(obj), fontName="Helvetica", fontSize=40))
Ejemplo n.º 30
0
def write_name(label, width, height, row):
    # Write the item code.
    label.add(shapes.String(width/2.0, height-13, str(row[4].value), fontName='Calibrib', fontSize=11, textAnchor="middle"))
    # Write the invoice number and quantity.
    label.add(shapes.String(5, height/2.0 + 2, 'Invoice #: ' + str(row[0].value), fontName='Calibri', fontSize=11))
    qty_width = stringWidth('Quantity: ' + str(row[3].value), "Calibri", 11) + 5
    label.add(shapes.String(width - qty_width, height/2.0 + 2, 'Quantity: ' + str(row[3].value), fontName='Calibri', fontSize=11))
    # Write certification level.
    label.add(shapes.String(5, height/2.0 - 14, str(row[5].value), fontName='Calibri', fontSize=10))
    # Write website and location.
    label.add(shapes.String(5, 7, 'RasaCreekFarm.com', fontName='Calibri', fontSize=10))
    loc_width = stringWidth('Lumby, BC', "Calibri", 10) + 5
    label.add(shapes.String(width - loc_width, 7, 'Lumby, BC', fontName='Calibri', fontSize=10))