def insertBarcodeAPI(self, codetype, value, addChecksum, posX, posY): value = getattr(self, 'validate_%s' % codetype)(value, addChecksum) if value is None: raise RuntimeException('Error validating codetype ' + codetype, self.ctx) group = getattr(self, 'draw_%s' % codetype)(value, addChecksum) draw.setpos(group, posX, posY)
def add_text_above(self, code, text, offset=0): offset = int(offset / 4 + int(offset / 2) * int(self.barlengthmodify) / 100) doc = self.getcomponent() page = self.getDrawPage() group = self.ctx.ServiceManager.createInstance( 'com.sun.star.drawing.ShapeCollection') group.add(code) shape = draw.createShape(doc, page, 'Text') shape.String = text shape.TextAutoGrowWidth = True shape.TextAutoGrowHeight = True shape.CharFontName = "Liberation Mono" shape.CharHeight = int(20 * int(self.barwidthmodify) / 100) shape.TextHorizontalAdjust = com_sun_star_drawing_TextHorizontalAdjust_CENTER if (self.isWriter()): shape.AnchorType = AT_PARAGRAPH draw.setpos(shape, (code.Size.Width - shape.Size.Width) / 2, 0 - 1000 + offset) group.add(shape) return page.group(group)
def insert(self): dlg = self.createdialog('Barcode') getattr(dlg, self.config.LastBarcodeType).State = True dlg.WithChecksum.State = self.config.LastChecksum dlg.HeightModify.Text = self.config.HeightModify dlg.WidthModify.Text = self.config.WidthModify dlg.PositionX.Text = self.config.PositionX dlg.PositionY.Text = self.config.PositionY while True: ok = dlg.execute() if not ok: return for codetype in self.CODETYPES: if getattr(dlg, codetype).State: break value = dlg.CodeField.Text value = getattr(self, 'validate_%s' % codetype)(value, dlg.WithChecksum.State) # empty field somehow appears as "&652.Barcode.CodeField.Text" if value is not None and value != "" and value != "&652.Barcode.CodeField.Text": self.config.LastBarcodeType = codetype self.config.LastChecksum = dlg.WithChecksum.State self.config.HeightModify = dlg.HeightModify.Text self.config.WidthModify = dlg.WidthModify.Text self.config.PositionX = dlg.PositionX.Text self.config.PositionY = dlg.PositionY.Text self.config.commitChanges() self.barlengthmodify = dlg.HeightModify.Text self.barwidthmodify = dlg.WidthModify.Text group = getattr(self, 'draw_%s' % codetype)(value, dlg.WithChecksum.State) draw.setpos(group, self.config.PositionX, self.config.PositionY) return
def drawcode(self, code, barlength=None, barwidth=None): ''' Draws the code described in the code parameter. code is a list of pairs of the form (binary, meta) where binary is a string made up of 1's and 0's (1's representing black bars) and meta is a string that is either '' (empty string), signifying that there is nothing to be done 'long', signifying that the bars should be drawn longer than usual or a single character string that will be printed under the bars. drawcode returns a Draw object that is a group of the bars and the text. ''' if barlength is None: barlength = self.BARLENGTH if barwidth is None: barwidth = self.BARWIDTH barwidth = int(int(barwidth) * int(self.barwidthmodify) / 100) normalbarlength = int(int(barlength) * int(self.barlengthmodify) / 100) longbarlength = int((barlength + self.LONGBAREXTRALENGTH) * int(self.barlengthmodify) / 100) doc = self.getcomponent() page = self.getDrawPage() group = self.ctx.ServiceManager.createInstance( 'com.sun.star.drawing.ShapeCollection') bars = [] x = 0 for binary, meta in code: if meta == 'long': barlength = longbarlength else: barlength = normalbarlength bars.extend(self.drawbars(binary, x, barlength, barwidth)) w = barwidth * len(binary) if len(meta) == 1: shape = draw.createShape(doc, page, 'Text') shape.String = meta shape.TextAutoGrowWidth = True shape.TextAutoGrowHeight = True shape.CharFontName = "Liberation Mono" shape.CharHeight = int(20 * int(self.barwidthmodify) / 100) shape.TextHorizontalAdjust = com_sun_star_drawing_TextHorizontalAdjust_CENTER if (self.isWriter()): shape.AnchorType = AT_PARAGRAPH if self.isWriter() or self.isDraw() or self.isImpress(): pos_x = x - 200 else: # Calc pos_x = x draw.setpos(shape, pos_x, normalbarlength, w, shape.Size.Height) group.add(shape) x += w shape = draw.createPolygon(doc, page, bars, color=draw.RGB(0, 0, 0)) shape.LineStyle = 0 if (self.isWriter()): shape.AnchorType = AT_PARAGRAPH # Writer needs some positioning hack due to DrawPage differences last = self.config.LastBarcodeType if last == 'EAN13' or last == 'ISBN13' or last == 'Bookland' or last == 'UPCA' \ or last == 'JAN' or last == 'UPCE': draw.setpos(shape, 300, 0) elif last == 'EAN8' or last == 'STANDARD2OF5': draw.setpos(shape, -200, 0) else: # INTERLEAVED2OF5, CODE128 draw.setpos(shape, 0, 0) group.add(shape) return page.group(group)