def uu_to_unit(self, val, unit): """ Wrapper for uutounit() accounting for different implementation in Inkscape versions""" try: # Inkscape > 0.48 return self.uutounit(val, unit) except AttributeError: # Inkscape <= 0.48 return inkex.uutounit(val, unit)
def calc_unit_factor(self): """ return the scale factor for all dimension conversions. - The document units are always irrelevant as everything in inkscape is expected to be in 90dpi pixel units """ # namedView = self.document.getroot().find(inkex.addNS('namedview', 'sodipodi')) # doc_units = inkex.uutounit(1.0, namedView.get(inkex.addNS('document-units', 'inkscape'))) dialog_units = inkex.uutounit(1.0, self.options.units) unit_factor = 1.0 / dialog_units return unit_factor
def calc_circular_pitch(self): """ We use math based on circular pitch. Expressed in inkscape units which is 90dpi 'pixel' units. """ dimension = self.options.dimension # print >> self.tty, "unit_factor=%s, doc_units=%s, dialog_units=%s (%s), system=%s" % (unit_factor, doc_units, dialog_units, self.options.units, self.options.system) if self.options.system == 'CP': # circular pitch circular_pitch = dimension elif self.options.system == 'DP': # diametral pitch circular_pitch = pi / dimension elif self.options.system == 'MM': # module (metric) circular_pitch = dimension * pi / 25.4 else: inkex.debug("unknown system '%s', try CP, DP, MM" % self.options.system) # circular_pitch defines the size in inches. # We divide the internal inch factor (px = 90dpi), to remove the inch # unit. # The internal inkscape unit is always px, # it is independent of the doc_units! return circular_pitch / inkex.uutounit(1.0, 'in')
def uutounit(self,nn,uu): try: return self.uutounit(nn,uu) # inkscape 0.91 except: return inkex.uutounit(nn,uu) # inkscape 0.48
def uutounit(self, nn, uu): try: return self.uutounit(nn, uu) # inkscape 0.91 except: return inkex.uutounit(nn, uu) # inkscape 0.48
def effect(self): if self.options.where_to_crop == 'selection': self.get_selection_area() #inkex.errormsg('Sory, the crop to selection is a TODO feature') #exit(1) else: svg = self.document.getroot() self.area_w = inkex.unittouu(svg.get('width')) self.area_h = inkex.unittouu(svg.attrib['height']) self.area_x1 = 0 self.area_y1 = 0 self.area_x2 = self.area_w self.area_y2 = self.area_h # Get SVG document dimensions # self.width must be replaced by self.area_x2. same to others. svg = self.document.getroot() #self.width = width = inkex.unittouu(svg.get('width')) #self.height = height = inkex.unittouu(svg.attrib['height']) # Convert parameters to user unit offset = inkex.unittouu(str(self.options.crop_offset) + \ self.options.unit) bt = inkex.unittouu(str(self.options.bleed_top) + self.options.unit) bb = inkex.unittouu(str(self.options.bleed_bottom) + self.options.unit) bl = inkex.unittouu(str(self.options.bleed_left) + self.options.unit) br = inkex.unittouu(str(self.options.bleed_right) + self.options.unit) # Bleed margin if bt < offset: bmt = 0 else: bmt = bt - offset if bb < offset: bmb = 0 else: bmb = bb - offset if bl < offset: bml = 0 else: bml = bl - offset if br < offset: bmr = 0 else: bmr = br - offset # Define the new document limits offset_left = self.area_x1 - offset offset_right = self.area_x2 + offset offset_top = self.area_y1 - offset offset_bottom = self.area_y2 + offset # Get middle positions middle_vertical = self.area_y1 + (self.area_h / 2) middle_horizontal = self.area_x1 + (self.area_w / 2) # Test if printing-marks layer existis layer = self.document.xpath( '//*[@id="printing-marks" and @inkscape:groupmode="layer"]', namespaces=inkex.NSS) if layer: svg.remove(layer[0]) # remove if it existis # Create a new layer layer = inkex.etree.SubElement(svg, 'g') layer.set('id', 'printing-marks') layer.set(inkex.addNS('label', 'inkscape'), 'Printing Marks') layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer') layer.set(inkex.addNS('insensitive', 'sodipodi'), 'true') # Crop Mark if self.options.crop_marks == True: # Create a group for Crop Mark g_attribs = { inkex.addNS('label', 'inkscape'): 'CropMarks', 'id': 'CropMarks' } g_crops = inkex.etree.SubElement(layer, 'g', g_attribs) # Top left Mark self.draw_crop_line(self.area_x1, offset_top, self.area_x1, offset_top - self.mark_size, 'cropTL1', g_crops) self.draw_crop_line(offset_left, self.area_y1, offset_left - self.mark_size, self.area_y1, 'cropTL2', g_crops) # Top right Mark self.draw_crop_line(self.area_x2, offset_top, self.area_x2, offset_top - self.mark_size, 'cropTR1', g_crops) self.draw_crop_line(offset_right, self.area_y1, offset_right + self.mark_size, self.area_y1, 'cropTR2', g_crops) # Bottom left Mark self.draw_crop_line(self.area_x1, offset_bottom, self.area_x1, offset_bottom + self.mark_size, 'cropBL1', g_crops) self.draw_crop_line(offset_left, self.area_y2, offset_left - self.mark_size, self.area_y2, 'cropBL2', g_crops) # Bottom right Mark self.draw_crop_line(self.area_x2, offset_bottom, self.area_x2, offset_bottom + self.mark_size, 'cropBR1', g_crops) self.draw_crop_line(offset_right, self.area_y2, offset_right + self.mark_size, self.area_y2, 'cropBR2', g_crops) # Bleed Mark if self.options.bleed_marks == True: # Create a group for Bleed Mark g_attribs = { inkex.addNS('label', 'inkscape'): 'BleedMarks', 'id': 'BleedMarks' } g_bleed = inkex.etree.SubElement(layer, 'g', g_attribs) # Top left Mark self.draw_bleed_line(self.area_x1 - bl, offset_top - bmt, self.area_x1 - bl, offset_top - bmt - self.mark_size, 'bleedTL1', g_bleed) self.draw_bleed_line(offset_left - bml, self.area_y1 - bt, offset_left - bml - self.mark_size, self.area_y1 - bt, 'bleedTL2', g_bleed) # Top right Mark self.draw_bleed_line(self.area_x2 + br, offset_top - bmt, self.area_x2 + br, offset_top - bmt - self.mark_size, 'bleedTR1', g_bleed) self.draw_bleed_line(offset_right + bmr, self.area_y1 - bt, offset_right + bmr + self.mark_size, self.area_y1 - bt, 'bleedTR2', g_bleed) # Bottom left Mark self.draw_bleed_line(self.area_x1 - bl, offset_bottom + bmb, self.area_x1 - bl, offset_bottom + bmb + self.mark_size, 'bleedBL1', g_bleed) self.draw_bleed_line(offset_left - bml, self.area_y2 + bb, offset_left - bml - self.mark_size, self.area_y2 + bb, 'bleedBL2', g_bleed) # Bottom right Mark self.draw_bleed_line(self.area_x2 + br, offset_bottom + bmb, self.area_x2 + br, offset_bottom + bmb + self.mark_size, 'bleedBR1', g_bleed) self.draw_bleed_line(offset_right + bmr, self.area_y2 + bb, offset_right + bmr + self.mark_size, self.area_y2 + bb, 'bleedBR2', g_bleed) # Registration Mark if self.options.reg_marks == True: # Create a group for Registration Mark g_attribs = { inkex.addNS('label', 'inkscape'): 'RegistrationMarks', 'id': 'RegistrationMarks' } g_center = inkex.etree.SubElement(layer, 'g', g_attribs) # Left Mark cx = max(bml + offset, self.min_mark_margin) self.draw_reg_marks(self.area_x1 - cx - (self.mark_size / 2), middle_vertical - self.mark_size * 1.5, '0', 'regMarkL', g_center) # Right Mark cx = max(bmr + offset, self.min_mark_margin) self.draw_reg_marks(self.area_x2 + cx + (self.mark_size / 2), middle_vertical - self.mark_size * 1.5, '180', 'regMarkR', g_center) # Top Mark cy = max(bmt + offset, self.min_mark_margin) self.draw_reg_marks(middle_horizontal, self.area_y1 - cy - (self.mark_size / 2), '90', 'regMarkT', g_center) # Bottom Mark cy = max(bmb + offset, self.min_mark_margin) self.draw_reg_marks(middle_horizontal, self.area_y2 + cy + (self.mark_size / 2), '-90', 'regMarkB', g_center) # Star Target if self.options.star_target == True: # Create a group for Star Target g_attribs = { inkex.addNS('label', 'inkscape'): 'StarTarget', 'id': 'StarTarget' } g_center = inkex.etree.SubElement(layer, 'g', g_attribs) if self.area_h < self.area_w: # Left Star cx = max(bml + offset, self.min_mark_margin) self.draw_star_target(self.area_x1 - cx - (self.mark_size / 2), middle_vertical, 'starTargetL', g_center) # Right Star cx = max(bmr + offset, self.min_mark_margin) self.draw_star_target(self.area_x2 + cx + (self.mark_size / 2), middle_vertical, 'starTargetR', g_center) else: # Top Star cy = max(bmt + offset, self.min_mark_margin) self.draw_star_target(middle_horizontal - self.mark_size * 1.5, self.area_y1 - cy - (self.mark_size / 2), 'starTargetT', g_center) # Bottom Star cy = max(bmb + offset, self.min_mark_margin) self.draw_star_target(middle_horizontal - self.mark_size * 1.5, self.area_y2 + cy + (self.mark_size / 2), 'starTargetB', g_center) # Colour Bars if self.options.colour_bars == True: # Create a group for Colour Bars g_attribs = { inkex.addNS('label', 'inkscape'): 'ColourBars', 'id': 'PrintingColourBars' } g_center = inkex.etree.SubElement(layer, 'g', g_attribs) if self.area_h > self.area_w: # Left Bars cx = max(bml + offset, self.min_mark_margin) self.draw_coluor_bars(self.area_x1 - cx - (self.mark_size / 2), middle_vertical + self.mark_size, 90, 'PrintingColourBarsL', g_center) # Right Bars cx = max(bmr + offset, self.min_mark_margin) self.draw_coluor_bars(self.area_x2 + cx + (self.mark_size / 2), middle_vertical + self.mark_size, 90, 'PrintingColourBarsR', g_center) else: # Top Bars cy = max(bmt + offset, self.min_mark_margin) self.draw_coluor_bars(middle_horizontal + self.mark_size, self.area_y1 - cy - (self.mark_size / 2), 0, 'PrintingColourBarsT', g_center) # Bottom Bars cy = max(bmb + offset, self.min_mark_margin) self.draw_coluor_bars(middle_horizontal + self.mark_size, self.area_y2 + cy + (self.mark_size / 2), 0, 'PrintingColourBarsB', g_center) # Page Information if self.options.page_info == True: # Create a group for Page Information g_attribs = { inkex.addNS('label', 'inkscape'): 'PageInformation', 'id': 'PageInformation' } g_pag_info = inkex.etree.SubElement(layer, 'g', g_attribs) y_margin = max(bmb + offset, self.min_mark_margin) txt_attribs = { 'style': 'font-size:12px;font-style:normal;font-weight:normal;fill:#000000;font-family:Bitstream Vera Sans,sans-serif;text-anchor:middle;text-align:center', 'x': str(middle_horizontal), 'y': str(self.area_y2 + y_margin + self.mark_size + 20) } txt = inkex.etree.SubElement(g_pag_info, 'text', txt_attribs) txt.text = 'Page size: ' +\ str(round(inkex.uutounit(self.area_w,self.options.unit),2)) +\ 'x' +\ str(round(inkex.uutounit(self.area_h,self.options.unit),2)) +\ ' ' + self.options.unit
def effect(self): if self.options.where_to_crop == 'selection' : inkex.errormsg('Sory, the crop to selection is a TODO feature') # Get SVG document dimensions svg = self.document.getroot() self.width = width = inkex.unittouu(svg.get('width')) self.height = height = inkex.unittouu(svg.attrib['height']) # Convert parameters to user unit offset = inkex.unittouu(str(self.options.crop_offset) + self.options.unit) bt = inkex.unittouu(str(self.options.bleed_top) + self.options.unit) bb = inkex.unittouu(str(self.options.bleed_bottom) + self.options.unit) bl = inkex.unittouu(str(self.options.bleed_left) + self.options.unit) br = inkex.unittouu(str(self.options.bleed_right) + self.options.unit) # Bleed margin if bt < offset : bmt = 0 else : bmt = bt - offset if bb < offset : bmb = 0 else : bmb = bb - offset if bl < offset : bml = 0 else : bml = bl - offset if br < offset : bmr = 0 else : bmr = br - offset # Define the new document limits left = - offset right = width + offset top = - offset bottom = height + offset # Test if printing-marks layer existis layer = self.document.xpath( '//*[@id="printing-marks" and @inkscape:groupmode="layer"]', namespaces=inkex.NSS) if layer: svg.remove(layer[0]) # remove if it existis # Create a new layer layer = inkex.etree.SubElement(svg, 'g') layer.set('id', 'printing-marks') layer.set(inkex.addNS('label', 'inkscape'), 'Printing Marks') layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer') layer.set(inkex.addNS('insensitive', 'sodipodi'), 'true') # Crop Mark if self.options.crop_marks == True: # Create a group for Crop Mark g_attribs = {inkex.addNS('label','inkscape'):'CropMarks', 'id':'CropMarks'} g_crops = inkex.etree.SubElement(layer, 'g', g_attribs) # Top left Mark self.draw_crop_line(0, top, 0, top - self.mark_size, 'cropTL1', g_crops) self.draw_crop_line(left, 0, left - self.mark_size, 0, 'cropTL2', g_crops) # Top right Mark self.draw_crop_line(width, top, width , top - self.mark_size, 'cropTR1', g_crops) self.draw_crop_line(right, 0, right + self.mark_size, 0, 'cropTR2', g_crops) # Bottom left Mark self.draw_crop_line(0, bottom, 0, bottom + self.mark_size, 'cropBL1', g_crops) self.draw_crop_line(left, height, left - self.mark_size, height, 'cropBL2', g_crops) # Bottom right Mark self.draw_crop_line(width, bottom, width, bottom + self.mark_size, 'cropBR1', g_crops) self.draw_crop_line(right, height, right + self.mark_size, height, 'cropBR2', g_crops) # Bleed Mark if self.options.bleed_marks == True: # Create a group for Bleed Mark g_attribs = {inkex.addNS('label','inkscape'):'BleedMarks', 'id':'BleedMarks'} g_bleed = inkex.etree.SubElement(layer, 'g', g_attribs) # Top left Mark self.draw_bleed_line(-bl, top - bmt, -bl, top - bmt - self.mark_size, 'bleedTL1', g_bleed) self.draw_bleed_line(left - bml, -bt, left - bml - self.mark_size, -bt, 'bleedTL2', g_bleed) # Top right Mark self.draw_bleed_line(width + br, top - bmt, width + br, top - bmt - self.mark_size, 'bleedTR1', g_bleed) self.draw_bleed_line(right + bmr, -bt, right + bmr + self.mark_size, -bt, 'bleedTR2', g_bleed) # Bottom left Mark self.draw_bleed_line(-bl, bottom + bmb, -bl, bottom + bmb + self.mark_size, 'bleedBL1', g_bleed) self.draw_bleed_line(left - bml, height + bb, left - bml - self.mark_size, height + bb, 'bleedBL2', g_bleed) # Bottom right Mark self.draw_bleed_line(width + br, bottom + bmb, width + br, bottom + bmb + self.mark_size, 'bleedBR1', g_bleed) self.draw_bleed_line(right + bmr, height + bb, right + bmr + self.mark_size, height + bb, 'bleedBR2', g_bleed) # Registration Mark if self.options.reg_marks == True: # Create a group for Registration Mark g_attribs = {inkex.addNS('label','inkscape'):'RegistrationMarks', 'id':'RegistrationMarks'} g_center = inkex.etree.SubElement(layer, 'g', g_attribs) # Left Mark cx = max( bml + offset, self.min_mark_margin ) self.draw_reg_marks(-cx - (self.mark_size/2), (height/2) - self.mark_size*1.5, '0', 'regMarkL', g_center) # Right Mark cx = max( bmr + offset, self.min_mark_margin ) self.draw_reg_marks(width + cx + (self.mark_size/2), (height/2) - self.mark_size*1.5, '180', 'regMarkR', g_center) # Top Mark cy = max( bmt + offset, self.min_mark_margin ) self.draw_reg_marks((width/2) - self.mark_size*1.5, -cy - (self.mark_size/2), '90', 'regMarkT', g_center) # Bottom Mark cy = max( bmb + offset, self.min_mark_margin ) self.draw_reg_marks((width/2) - self.mark_size*1.5, height + cy + (self.mark_size/2), '-90', 'regMarkB', g_center) # Star Target if self.options.star_target == True: # Create a group for Star Target g_attribs = {inkex.addNS('label','inkscape'):'StarTarget', 'id':'StarTarget'} g_center = inkex.etree.SubElement(layer, 'g', g_attribs) if height < width : # Left Star cx = max( bml + offset, self.min_mark_margin ) self.draw_star_target(-cx - (self.mark_size/2), (height/2), 'starTargetL', g_center) # Right Star cx = max( bmr + offset, self.min_mark_margin ) self.draw_star_target(width + cx + (self.mark_size/2), (height/2), 'starTargetR', g_center) else : # Top Star cy = max( bmt + offset, self.min_mark_margin ) self.draw_star_target((width/2), -cy - (self.mark_size/2), 'starTargetT', g_center) # Bottom Star cy = max( bmb + offset, self.min_mark_margin ) self.draw_star_target((width/2), height + cy + (self.mark_size/2), 'starTargetB', g_center) # Colour Bars if self.options.colour_bars == True: # Create a group for Colour Bars g_attribs = {inkex.addNS('label','inkscape'):'ColourBars', 'id':'PrintingColourBars'} g_center = inkex.etree.SubElement(layer, 'g', g_attribs) if height > width : # Left Bars cx = max( bml + offset, self.min_mark_margin ) self.draw_coluor_bars(-cx - (self.mark_size/2), height/2, 90, 'PrintingColourBarsL', g_center) # Right Bars cx = max( bmr + offset, self.min_mark_margin ) self.draw_coluor_bars(width + cx + (self.mark_size/2), height/2, 90, 'PrintingColourBarsR', g_center) else : # Top Bars cy = max( bmt + offset, self.min_mark_margin ) self.draw_coluor_bars(width/2, -cy - (self.mark_size/2), 0, 'PrintingColourBarsT', g_center) # Bottom Bars cy = max( bmb + offset, self.min_mark_margin ) self.draw_coluor_bars(width/2, height + cy + (self.mark_size/2), 0, 'PrintingColourBarsB', g_center) # Page Information if self.options.page_info == True: # Create a group for Page Information g_attribs = {inkex.addNS('label','inkscape'):'PageInformation', 'id':'PageInformation'} g_pag_info = inkex.etree.SubElement(layer, 'g', g_attribs) y_margin = max( bmb + offset, self.min_mark_margin ) txt_attribs = {'style':'font-size:12px;font-style:normal;font-weight:normal;fill:#000000;font-family:Bitstream Vera Sans,sans-serif;text-anchor:middle;text-align:center', 'x':str(width/2), 'y':str(height+y_margin+self.mark_size+20)} txt = inkex.etree.SubElement(g_pag_info, 'text', txt_attribs) txt.text = 'Page size: ' +\ str(round(inkex.uutounit(width,self.options.unit),2)) +\ 'x' +\ str(round(inkex.uutounit(height,self.options.unit),2)) +\ ' ' + self.options.unit
def effect(self): # a short hand so = self.options o = self.options seamInner = so.seamInner seamOuter = so.seamOuter seamEnd = so.seamEnd cx, cy = self.view_center # Put in in the centre of the current view #center = self.view_center domedata, thickness = make_dome_data(o.radius, o.segments) #segData = data_dict # change radius(cm) into pixels #r_px = inkex.unittouu(str(o.radius) + 'cm') thicknessPx = inkex.unittouu(str(thickness) + "cm") # change seams from cm to pixels seamInner = inkex.unittouu(str(o.seamInner) + "cm") seamOuter = inkex.unittouu(str(o.seamOuter) + "cm") seamEnd = inkex.unittouu(str(o.seamEnd) + "cm") seamOther = inkex.unittouu(str(so.seamOther) + 'cm') SubElement = inkex.etree.SubElement #inkex.debug(type(seamOther)) # line styles and node attributes line_style = { 'stroke': '#000000', 'stroke-width': '1.0px', 'fill': 'none' } #lineStyle = line_style #defaultStyle = lineStyle attr = {'style': formatStyle(line_style)} #defaultAttr = attr self.add_info_lines( ("$Pattern Info", "Total segments: %i" % o.segments, "Radius of dome: %.1fcm" % (o.radius), "Segment thickness: %.3fcm" % (thickness), "rendering line thickness: %.3f" % (inkex.uutounit(0.5, 'cm')), " ") ) if o.addSeams: self.add_info_lines( ("$Seam Allowences", "inner seam: %.1fcm" % (o.seamInner), "Outer seam: %.1fcm" % (o.seamOuter), "End seam: %.1fcm" % (o.seamEnd), "Other seams: %.1fcm" % (o.seamOther), " ") ) # zipper and body strip zipdata = make_zipper_data(o.radius, thickness, o.zipperStrapJoin, o.zipperHeight, o.zipperTop, o.zipperBottom) regex = re.compile("([a-z])([A-Z])") for key, val in zipdata.iteritems(): w, h = val['d'] x1, y1 = (200, 200) wpx = inkex.unittouu(str(w) + 'cm') hpx = inkex.unittouu(str(h) + 'cm') label = val['label'] name = regex.sub('\g<1> \g<2>', key) rect = RectPattern(wpx, hpx, label, name) rect.set_start_loc(x1, y1) grp = SubElement(self.current_layer, 'g', {inkex.addNS('label', 'inkscape'): key}) attr['d'] = formatPath(rect.path) SubElement(grp, inkex.addNS('path', 'svg'), attr) if o.addSeams: seam = RectSeamPattern.from_rect(rect) seam.set_seams(seamOther) if seam.label.startswith('Z1'): seam.bottom = 0 elif seam.label.startswith('Z2'): seam.top = 0 attr['d'] = formatPath(seam.path) SubElement(grp, inkex.addNS('path', 'svg'), attr) # add labels to rendered piece svg_add_text(grp, 212, y1 + (rect.height / 4), "%s (%s)" % (rect.name, rect.label)) self.add_info_lines( ("$" + rect.name + " (" + rect.label + ")", "Width: %.3fcm" % (w), "Height: %.3fcm" % (h)) ) #return # loop through the data_dict making each segment in turn using the data # OPTIMIZE: Should use enumerate here for i in xrange(1, len(domedata) + 1): # create a group to put this pattern in grp = SubElement(self.current_layer, 'g', {inkex.addNS('label', 'inkscape'): "Segment " + str(i)}) #get the data we need from the dictionary angle, radius = domedata[i] angle = angle / o.seams r = inkex.unittouu(str(radius) + "cm") if i == 1: # adjust top cone to be a flat circle using pixel units r = (r * angle) / (2 * pi) angle = 2 * pi circle(r, cx, cy, grp, line_style) if o.addSeams: circle(r + seamOuter, cx, cy, grp, line_style) else: piece = DomePiece(i, angle, r, thicknessPx) piece.set_start_loc(cx, cy) attr['d'] = formatPath(piece.path) SubElement(grp, inkex.addNS('path', 'svg'), attr) if o.addSeams: # set all the seams seam = DomeSeamPiece.from_dome_piece(piece) seam.set_seams({ 'outer': seamOuter, 'inner': seamInner, 'end': seamEnd }) attr['d'] = formatPath(seam.path) SubElement(grp, inkex.addNS('path', 'svg'), attr) if o.showSegLabel: self.write_dome_piece_label(r, thicknessPx, grp, i) self.add_info_lines( ('$S %i data:' % i, 'Outer radius: %.3fcm' % radius, 'Inner radius: %.3fcm' % (radius - thickness), 'Angle: %.4f' % degrees(angle)) ) #self.addInfoLines(lines) if so.showSegData: self.writeInfoLines()