From ff2cca4aca8aca2ee001970f1028ea0e82abf470 Mon Sep 17 00:00:00 2001 From: "Aurelio A. Heckert (a)" Date: Fri, 19 Mar 2010 13:14:05 -0300 Subject: [PATCH] extension printing-marks: "Set crop marks to selection" is workin now! --- share/extensions/printing-marks.inx | 3 +- share/extensions/printing-marks.py | 157 ++++++++++++++-------------- 2 files changed, 82 insertions(+), 78 deletions(-) diff --git a/share/extensions/printing-marks.inx b/share/extensions/printing-marks.inx index 40954380f..e652945d8 100644 --- a/share/extensions/printing-marks.inx +++ b/share/extensions/printing-marks.inx @@ -17,6 +17,7 @@ <_item value="canvas">Canvas + <_item value="selection">Selection @@ -34,7 +35,7 @@ - + all diff --git a/share/extensions/printing-marks.py b/share/extensions/printing-marks.py index 3cebd665b..6e12167f4 100644 --- a/share/extensions/printing-marks.py +++ b/share/extensions/printing-marks.py @@ -220,7 +220,7 @@ class Printing_Marks (inkex.Effect): self.area_x1 = min_x self.area_y1 = min_y self.area_x2 = max_x - self.area_xy = max_y + self.area_y2 = max_y self.area_w = max_x - min_x self.area_h = max_y - min_y @@ -228,8 +228,8 @@ class Printing_Marks (inkex.Effect): if self.options.where_to_crop == 'selection' : self.get_selection_area() - inkex.errormsg('Sory, the crop to selection is a TODO feature') - exit(1) + #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')) @@ -237,13 +237,13 @@ class Printing_Marks (inkex.Effect): self.area_x1 = 0 self.area_y1 = 0 self.area_x2 = self.area_w - self.area_xy = self.area_h + 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']) + #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) + \ @@ -263,15 +263,18 @@ class Printing_Marks (inkex.Effect): else : bmr = br - offset # Define the new document limits - left = - offset - right = width + offset - top = - offset - bottom = height + offset + 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"]', + '//*[@id="printing-marks" and @inkscape:groupmode="layer"]', namespaces=inkex.NSS) if layer: svg.remove(layer[0]) # remove if it existis # Create a new layer @@ -289,35 +292,35 @@ class Printing_Marks (inkex.Effect): g_crops = inkex.etree.SubElement(layer, 'g', g_attribs) # Top left Mark - self.draw_crop_line(0, top, - 0, top - self.mark_size, + self.draw_crop_line(self.area_x1, offset_top, + self.area_x1, offset_top - self.mark_size, 'cropTL1', g_crops) - self.draw_crop_line(left, 0, - left - self.mark_size, 0, + 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(width, top, - width , top - self.mark_size, + self.draw_crop_line(self.area_x2, offset_top, + self.area_x2, offset_top - self.mark_size, 'cropTR1', g_crops) - self.draw_crop_line(right, 0, - right + self.mark_size, 0, + 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(0, bottom, - 0, bottom + self.mark_size, + self.draw_crop_line(self.area_x1, offset_bottom, + self.area_x1, offset_bottom + self.mark_size, 'cropBL1', g_crops) - self.draw_crop_line(left, height, - left - self.mark_size, height, + 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(width, bottom, - width, bottom + self.mark_size, + self.draw_crop_line(self.area_x2, offset_bottom, + self.area_x2, offset_bottom + self.mark_size, 'cropBR1', g_crops) - self.draw_crop_line(right, height, - right + self.mark_size, height, + self.draw_crop_line(offset_right, self.area_y2, + offset_right + self.mark_size, self.area_y2, 'cropBR2', g_crops) # Bleed Mark @@ -328,35 +331,35 @@ class Printing_Marks (inkex.Effect): 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, + 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(left - bml, -bt, - left - bml - self.mark_size, -bt, + 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(width + br, top - bmt, - width + br, top - bmt - self.mark_size, + 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(right + bmr, -bt, - right + bmr + self.mark_size, -bt, + 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(-bl, bottom + bmb, - -bl, bottom + bmb + self.mark_size, + 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(left - bml, height + bb, - left - bml - self.mark_size, height + bb, + 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(width + br, bottom + bmb, - width + br, bottom + bmb + self.mark_size, + 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(right + bmr, height + bb, - right + bmr + self.mark_size, height + bb, + 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 @@ -368,26 +371,26 @@ class Printing_Marks (inkex.Effect): # 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, + 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(width + cx + (self.mark_size/2), - (height/2) - self.mark_size*1.5, + 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((width/2), - -cy - (self.mark_size/2), + 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((width/2), - height + cy + (self.mark_size/2), + self.draw_reg_marks(middle_horizontal, + self.area_y2 + cy + (self.mark_size/2), '-90', 'regMarkB', g_center) # Star Target @@ -397,27 +400,27 @@ class Printing_Marks (inkex.Effect): 'id':'StarTarget'} g_center = inkex.etree.SubElement(layer, 'g', g_attribs) - if height < width : + if self.area_h < self.area_w : # Left Star cx = max( bml + offset, self.min_mark_margin ) - self.draw_star_target(-cx - (self.mark_size/2), - (height/2), + 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(width + cx + (self.mark_size/2), - (height/2), + 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((width/2) - self.mark_size*1.5, - -cy - (self.mark_size/2), + 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((width/2) - self.mark_size*1.5, - height + cy + (self.mark_size/2), + self.draw_star_target(middle_horizontal - self.mark_size*1.5, + self.area_y2 + cy + (self.mark_size/2), 'starTargetB', g_center) @@ -428,30 +431,30 @@ class Printing_Marks (inkex.Effect): 'id':'PrintingColourBars'} g_center = inkex.etree.SubElement(layer, 'g', g_attribs) - if height > width : + if self.area_h > self.area_w : # Left Bars cx = max( bml + offset, self.min_mark_margin ) - self.draw_coluor_bars(-cx - (self.mark_size/2), - height/2 + self.mark_size, + 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(width + cx + (self.mark_size/2), - height/2 + self.mark_size, + 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(width/2 + self.mark_size, - -cy - (self.mark_size/2), + 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(width/2 + self.mark_size, - height + cy + (self.mark_size/2), + self.draw_coluor_bars(middle_horizontal + self.mark_size, + self.area_y2 + cy + (self.mark_size/2), 0, 'PrintingColourBarsB', g_center) @@ -463,16 +466,16 @@ class Printing_Marks (inkex.Effect): '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_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(width,self.options.unit),2)) +\ + str(round(inkex.uutounit(self.area_w,self.options.unit),2)) +\ 'x' +\ - str(round(inkex.uutounit(height,self.options.unit),2)) +\ + str(round(inkex.uutounit(self.area_h,self.options.unit),2)) +\ ' ' + self.options.unit -- 2.30.2