kopia lustrzana https://github.com/inkstitch/inkstitch
				
				
				
			fix split text (#2057)
							rodzic
							
								
									025c464ace
								
							
						
					
					
						commit
						920a3e267c
					
				|  | @ -11,32 +11,38 @@ from .base import InkstitchExtension | ||||||
| 
 | 
 | ||||||
| class PaletteSplitText(InkstitchExtension): | class PaletteSplitText(InkstitchExtension): | ||||||
|     # Splits sublines of text into it's own text elements in order to color them with the color picker |     # Splits sublines of text into it's own text elements in order to color them with the color picker | ||||||
|     def __init__(self, *args, **kwargs): |  | ||||||
|         InkstitchExtension.__init__(self, *args, **kwargs) |  | ||||||
|         self.arg_parser.add_argument("-l", "--line-height", type=int, default=6, dest="line_height") |  | ||||||
| 
 |  | ||||||
|     def effect(self): |     def effect(self): | ||||||
|         if not self.svg.selection: |         if not self.svg.selection: | ||||||
|             inkex.errormsg(_("Please select one or more text elements to split lines.")) |             inkex.errormsg(_("Please select one or more text elements to split lines.")) | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         line_height = self.options.line_height |  | ||||||
| 
 |  | ||||||
|         for text in self.svg.selection.get(inkex.elements.TextElement): |         for text in self.svg.selection.get(inkex.elements.TextElement): | ||||||
|             parent = text.getparent() |             parent = text.getparent() | ||||||
|             content = text.get_text() |             content = text.get_text() | ||||||
|             lines = content.split('\n') |             lines = content.split('\n') | ||||||
|             lines.reverse() |             lines.reverse() | ||||||
|             style = text.get('style') |             lines = [line for line in lines if not len(line) == 0] | ||||||
|             x = text.get('x') | 
 | ||||||
|             y = text.get('y') |             style = text.style | ||||||
|             y = float(y) + (len(lines) - 1) * line_height |             # If shape-inside style is used, it will lead to bad placement | ||||||
|  |             style.pop('shape-inside', None) | ||||||
|  | 
 | ||||||
|  |             transform = text.transform | ||||||
|  |             text.pop('transform') | ||||||
|  | 
 | ||||||
|  |             bbox = text.get_inkscape_bbox() | ||||||
|  |             x = bbox.left | ||||||
|  |             y = bbox.bottom | ||||||
|  |             height = bbox.height / (len(lines)) | ||||||
|  | 
 | ||||||
|             for line in lines: |             for line in lines: | ||||||
|                 element = inkex.TextElement() |                 element = inkex.TextElement() | ||||||
|                 element.text = line |                 element.text = line | ||||||
|                 element.set('style', style) |                 element.set('style', str(style)) | ||||||
|                 element.set('x', x) |                 element.set('x', str(x)) | ||||||
|                 element.set('y', str(y)) |                 element.set('y', str(y)) | ||||||
|                 y = float(y) - line_height |                 element.set('transform', str(transform)) | ||||||
|  | 
 | ||||||
|  |                 y -= height | ||||||
|                 parent.insert(0, element) |                 parent.insert(0, element) | ||||||
|             parent.remove(text) |             parent.remove(text) | ||||||
|  |  | ||||||
|  | @ -13,7 +13,6 @@ | ||||||
|           </submenu> |           </submenu> | ||||||
|         </effects-menu> |         </effects-menu> | ||||||
|     </effect> |     </effect> | ||||||
|     <param name="line-height" type="int" min="1" max="100" gui-text="Line Height">6</param> |  | ||||||
|     <script> |     <script> | ||||||
|         {{ command_tag | safe }} |         {{ command_tag | safe }} | ||||||
|     </script> |     </script> | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Kaalleen
						Kaalleen