def text_on_path(text, shape, font_name, font_size, alignment, margin, baseline_offset): if shape is None or shape.length <= 0: return None if text is None: return None text = unicode(text) if isinstance(shape, Path): shape = shape.asGeometry() p = Path() fm = get_font_metrics(font_name, font_size) string_width = textwidth(text, fm) dw = string_width / shape.length if alignment == "trailing": first = True for char in text: char_width = textwidth(char, fm) if first: t = (99.9 - margin) / 100.0 first = False else: t -= char_width / string_width * dw t = t % 1.0 margin = t * 100 first = True for char in text: char_width = textwidth(char, fm) if first: t = margin / 100.0 first = False else: t += char_width / string_width * dw # Always loop (the other behavior is weird) t = t % 1.0 pt1 = shape.pointAt(t) pt2 = shape.pointAt(t + 0.0000001) a = angle(pt2.x, pt2.y, pt1.x, pt1.y) tp = Text(char, -char_width, -baseline_offset) tp.align = Text.Align.LEFT tp.fontName = font_name tp.fontSize = font_size tp.translate(pt1.x, pt1.y) tp.rotate(a - 180) for contour in tp.path.contours: p.add(contour) return p
def delete_points(path, bounding, delete_selected=True): if path is None or bounding is None: return None new_path = Path(path, False) # cloneContours = False for old_contour in path.contours: new_contour = Contour() for point in old_contour.points: if bounding.contains(point) == delete_selected: new_contour.addPoint(Point(point.x, point.y, point.type)) new_contour.closed = old_contour.closed new_path.add(new_contour) return new_path
def _function(shape, *args, **kwargs): from java.util import List if isinstance(shape, (list, tuple, List)): return fn(shape, *args, **kwargs) elif isinstance(shape, Path): new_path = Path(shape, False) for c in shape.contours: new_path.add(Contour(fn(c.points, *args, **kwargs), c.closed)) return new_path elif isinstance(shape, Geometry): new_geo = Geometry() for path in shape.paths: new_geo.add(_map_geo_to_points(fn)(path, *args, **kwargs)) return new_geo return None