def translate_header(self, header): self.sk2_mt.doc_units = uc2const.UNIT_PT center = [0.0, 0.0] p = [self.wwidth, self.wheight] x0, y0 = apply_trafo_to_point(center, self.get_trafo()) x1, y1 = apply_trafo_to_point(p, self.get_trafo()) width = abs(x1 - x0) height = abs(y1 - y0) ornt = uc2const.PORTRAIT if width > height: ornt = uc2const.LANDSCAPE page_fmt = ['Custom', (width, height), ornt] pages_obj = self.sk2_mtds.get_pages_obj() pages_obj.page_format = page_fmt self.page = sk2_model.Page(pages_obj.config, pages_obj, 'WMF page') self.page.page_format = deepcopy(page_fmt) pages_obj.childs = [self.page, ] pages_obj.page_counter = 1 self.layer = sk2_model.Layer(self.page.config, self.page) self.page.childs = [self.layer, ] for record in header.childs: try: self.translate_record(record) except: print wmfconst.WMF_RECORD_NAMES[record.func] for item in sys.exc_info(): print item
def render_image(self, ctx, obj): if not obj.cache_cdata: libimg.update_image(self.cms, obj) canvas_matrix = ctx.get_matrix() canvas_trafo = libcairo.get_trafo_from_matrix(canvas_matrix) zoom = canvas_trafo[0] h = obj.size[1] lu_corner = libgeom.apply_trafo_to_point([0.0, float(h)], obj.trafo) x0, y0 = libgeom.apply_trafo_to_point(lu_corner, canvas_trafo) m11, m12, m21, m22 = obj.trafo[:4] matrix = cairo.Matrix(zoom * m11, -zoom * m12, - zoom * m21, zoom * m22, x0, y0) ctx.set_matrix(matrix) if self.contour_flag: if not obj.cache_gray_cdata: libimg.update_gray_image(self.cms, obj) ctx.set_source_surface(obj.cache_gray_cdata) if zoom * abs(m11) > .98: ctx.get_source().set_filter(cairo.FILTER_NEAREST) ctx.paint_with_alpha(0.3) else: ctx.set_source_surface(obj.cache_cdata) if zoom * abs(m11) > .98: ctx.get_source().set_filter(cairo.FILTER_NEAREST) ctx.paint() ctx.set_matrix(canvas_matrix)
def get_path(self): ret = [[], [], self.closed] inv_trafo = libgeom.invert_trafo(self.trafo) ret[0] = libgeom.apply_trafo_to_point(self.start_point.point, inv_trafo) for item in self.points: ret[1].append(libgeom.apply_trafo_to_point(item.point, inv_trafo)) return ret
def apply_trafo(self, trafo): if len(self.point) == 2: self.point = libgeom.apply_trafo_to_point(self.point, trafo) else: p0, p1, p2, marker = deepcopy(self.point) p1 = libgeom.apply_trafo_to_point(p1, trafo) p2 = libgeom.apply_trafo_to_point(p2, trafo) self.point = [p0, p1, p2, marker]
def tr_rectangle(self, chunk): bottom, right, top, left = get_data('<hhhh', chunk) left, top = apply_trafo_to_point([left, top], self.get_trafo()) right, bottom = apply_trafo_to_point([right, bottom], self.get_trafo()) cfg = self.layer.config sk2_style = self.get_style() rect = [left, top, right - left, bottom - top] rect = sk2_model.Rectangle(cfg, self.layer, rect, style=sk2_style) self.layer.childs.append(rect)
def tr_round_rectangle(self, chunk): eh, ew, bottom, right, top, left = get_data('<hhhhhh', chunk) corners = 4 * [0.0, ] if eh and ew: coef = max(ew / abs(right - left), eh / abs(bottom - top)) corners = 4 * [coef, ] left, top = apply_trafo_to_point([left, top], self.get_trafo()) right, bottom = apply_trafo_to_point([right, bottom], self.get_trafo()) cfg = self.layer.config sk2_style = self.get_style() rect = [left, top, right - left, bottom - top] rect = sk2_model.Rectangle(cfg, self.layer, rect, style=sk2_style, corners=corners) self.layer.childs.append(rect)
def tr_textout(self, chunk): length = get_data('<h', chunk[:2])[0] encoding = self.get_encoding() txt = chunk[8:8 + length].decode(encoding) txt_length = len(txt) txt = txt.encode('utf-8') y, x, = get_data('<hhhh', chunk[8 + length:16 + length]) p = apply_trafo_to_point([x, y], self.get_trafo()) cfg = self.layer.config sk2_style, tags = self.get_text_style() markup = [[tags, (0, txt_length)]] tr = [] + libgeom.NORMAL_TRAFO text = sk2_model.Text(cfg, self.layer, p, txt, -1, tr, sk2_style) text.markup = markup if self.dc.opacity: bg_style = [[], [], [], []] clr = [] + self.dc.bgcolor clr = [uc2const.COLOR_RGB, clr, 1.0, '', ''] bg_style[0] = [sk2_const.FILL_EVENODD, sk2_const.FILL_SOLID, clr] text.update() bbox = [] + text.cache_bbox rect = bbox[:2] + [bbox[2] - bbox[0], bbox[3] - bbox[1]] rect = sk2_model.Rectangle(cfg, self.layer, rect, style=bg_style) self.layer.childs.append(rect) if self.dc.font[-2]: tr = libgeom.trafo_rotate_grad(self.dc.font[-2], p[0], p[1]) text.trafo = libgeom.multiply_trafo(text.trafo, tr) if self.dc.opacity: rect.trafo = libgeom.multiply_trafo(rect.trafo, tr) self.layer.childs.append(text)
def apply_trafo(self, trafo): p = libgeom.apply_trafo_to_point(self.get_point(), trafo) if self.point == self.base_point: self.point.point[1] = p else: self.point.point[0] = p self.point.update_connection()
def update_bbox(self): bp = libgeom.apply_trafo_to_point([0.0, 0.0], self.trafo) self.cache_bbox = 2 * bp index = 0 for item in self.cache_cpath: if not item: data = self.cache_layout_data[index] bp = [data[0], data[4]] bbox = 2 * libgeom.apply_trafo_to_point(bp, self.trafo) else: bbox = libgeom.get_cpath_bbox(item) if not self.cache_bbox: self.cache_bbox = bbox else: self.cache_bbox = libgeom.sum_bbox(self.cache_bbox, bbox) index += 1
def tr_stretch_dib(self, chunk): src_h, src_w, = get_data('<hh', chunk[6:10]) dst_h, dst_w, dst_y, dst_x = get_data('<hhhh', chunk[14:22]) imagestr = wmflib.dib_to_imagestr(chunk[22:]) tr = self.get_trafo() p0 = apply_trafo_to_point([dst_x, dst_y], tr) p1 = apply_trafo_to_point([dst_w + dst_x, dst_h + dst_y], tr) w = abs(p1[0] - p0[0]) h = abs(p1[1] - p0[1]) trafo = [w / src_w, 0.0, 0.0, h / src_h, p0[0], p0[1] - h] pixmap = sk2_model.Pixmap(self.layer.config) libimg.set_image_data(self.sk2_doc.cms, pixmap, imagestr) pixmap.trafo = trafo self.layer.childs.append(pixmap)
def tr_arc(self, chunk, arc_type=sk2_const.ARC_ARC): ye, xe, ys, xs, bottom, right, top, left = get_data('<hhhhhhhh', chunk) left, top = apply_trafo_to_point([left, top], self.get_trafo()) right, bottom = apply_trafo_to_point([right, bottom], self.get_trafo()) xs, ys = apply_trafo_to_point([xs, ys], self.get_trafo()) xe, ye = apply_trafo_to_point([xe, ye], self.get_trafo()) if left != right and top != bottom: t = [(right - left) / 2, 0, 0, (bottom - top) / 2, (right + left) / 2, (top + bottom) / 2] t = libgeom.invert_trafo(t) xs, ys = apply_trafo_to_point([xs, ys], t) xe, ye = apply_trafo_to_point([xe, ye], t) end_angle = libgeom.get_point_angle([xs, ys], [0.0, 0.0]) start_angle = libgeom.get_point_angle([xe, ye], [0.0, 0.0]) else: start_angle = end_angle = 0.0 cfg = self.layer.config sk2_style = self.get_style() if arc_type == sk2_const.ARC_ARC: sk2_style[0] = [] rect = [left, top, right - left, bottom - top] ellipse = sk2_model.Circle(cfg, self.layer, rect, start_angle, end_angle, arc_type, sk2_style) self.layer.childs.append(ellipse)
def tr_round_rectangle(self, chunk): eh, ew, bottom, right, top, left = get_data('<hhhhhh', chunk) corners = 4 * [ 0.0, ] if eh and ew: coef = max(ew / abs(right - left), eh / abs(bottom - top)) corners = 4 * [ coef, ] left, top = apply_trafo_to_point([left, top], self.get_trafo()) right, bottom = apply_trafo_to_point([right, bottom], self.get_trafo()) cfg = self.layer.config sk2_style = self.get_style() rect = [left, top, right - left, bottom - top] rect = sk2_model.Rectangle(cfg, self.layer, rect, style=sk2_style, corners=corners) self.layer.childs.append(rect)
def apply_moving(self, event, start=False, final=False): point = event.get_point() wpoint = self.canvas.point_win_to_doc(point) invtrafo = libgeom.invert_trafo(self.target.trafo) x, y = libgeom.apply_trafo_to_point(wpoint, invtrafo) x -= 0.5 y -= 0.5 angle = 0.0 if x > 0 and y > 0: angle = math.atan(y / x) elif x == 0 and y > 0: angle = math.pi / 2.0 elif x < 0 and y > 0: angle = math.atan(-x / y) + math.pi / 2.0 elif x < 0 and y == 0: angle = math.pi elif x < 0 and y < 0: angle = math.atan(y / x) + math.pi elif x == 0 and y < 0: angle = 1.5 * math.pi elif x > 0 and y < 0: angle = math.atan(x / -y) + 1.5 * math.pi elif x > 0 and y == 0: angle = 0.0 elif x == 0 and y == 0: return if event.is_ctrl(): fixed_angle = math.pi * config.ellipse_fixed_angle / 180.0 angle //= fixed_angle angle *= fixed_angle else: contra_point = self.start_point if start:contra_point = self.end_point if contra_point.is_pressed(point): angle = contra_point.get_angle() circle_type = self.orig_type if event.is_alt() and not circle_type == sk2_const.ARC_ARC: circle_type = sk2_const.ARC_CHORD if libgeom.distance([x, y]) < 0.5: circle_type = sk2_const.ARC_PIE_SLICE angle1 = self.orig_angle1 angle2 = self.orig_angle2 if start: angle1 = angle else: angle2 = angle if final: self.api.set_circle_properties_final(circle_type, angle1, angle2, self.orig_type, self.orig_angle1, self.orig_angle2, self.target) else: self.api.set_circle_properties(circle_type, angle1, angle2, self.target) self.update_points()
def translate_header(self, header): self.sk2_mt.doc_units = uc2const.UNIT_PT center = [0.0, 0.0] p = [self.wwidth, self.wheight] x0, y0 = apply_trafo_to_point(center, self.get_trafo()) x1, y1 = apply_trafo_to_point(p, self.get_trafo()) width = abs(x1 - x0) height = abs(y1 - y0) ornt = uc2const.PORTRAIT if width > height: ornt = uc2const.LANDSCAPE page_fmt = ['Custom', (width, height), ornt] pages_obj = self.sk2_mtds.get_pages_obj() pages_obj.page_format = page_fmt self.page = sk2_model.Page(pages_obj.config, pages_obj, 'WMF page') self.page.page_format = deepcopy(page_fmt) pages_obj.childs = [ self.page, ] pages_obj.page_counter = 1 self.layer = sk2_model.Layer(self.page.config, self.page) self.page.childs = [ self.layer, ] for record in header.childs: try: self.translate_record(record) except Exception as e: LOG.error('ERREC-->%s', wmf_const.WMF_RECORD_NAMES[record.func]) LOG.error('Record index %s', str(header.childs.index(record))) LOG.error('Error: %s', e)
def _text(self, element): (x, y), chunk = self.read_point(element.params) flg, chunk = self.read_enum(chunk) txt, chunk = self.read_str(chunk) p0 = libgeom.apply_trafo_to_point([x, y], self.get_trafo()) py, px = self.cgm['text.orientation'] py = libgeom.normalize_point(py) px = libgeom.normalize_point(px) tr = libgeom.sub_points(px, p0) + libgeom.sub_points(py, p0) + p0 text = sk2_model.Text(self.layer.config, self.layer, p0, txt, -1, style=self.get_style(text=True)) self.layer.childs.append(text)
def get_vector(path, trafo): p0 = p1 = path[0] is_cp = libgeom.is_curve_point t = 0.001 for point in path[1]: p0 = point[0] if is_cp(point) else point if not p0 == p1: break elif is_cp(point) and p1 != point[2]: p0 = libgeom.split_bezier_curve(p1, point, t)[0][2] break return [ libgeom.apply_trafo_to_point(p, trafo) for p in (p0, p1) ]
def apply_rounding(self, point, final=False, inplace=False): wpoint = self.canvas.point_win_to_doc(point) invtrafo = libgeom.invert_trafo(self.target.trafo) wpoint = libgeom.apply_trafo_to_point(wpoint, invtrafo) corners = [] + self.target.corners name = str(self.rnd_index) + str(self.rnd_subindex) if self.stop2: val = abs(wpoint[0] - self.start[0]) val2 = abs(wpoint[1] - self.start[1]) start = self.start if val > val2: if self.rnd_index in (0, 2): stop = self.stop2 res = (wpoint[0] - start[0]) / (stop[0] - start[0]) else: stop = self.stop res = (wpoint[0] - start[0]) / (stop[0] - start[0]) else: if self.rnd_index in (0, 2): stop = self.stop res = (wpoint[1] - start[1]) / (stop[1] - start[1]) else: stop = self.stop2 res = (wpoint[1] - start[1]) / (stop[1] - start[1]) else: start = self.start stop = self.stop if name in H_ORIENT: res = (wpoint[0] - start[0]) / (stop[0] - start[0]) else: res = (wpoint[1] - start[1]) / (stop[1] - start[1]) if res < 0.0: res = 0.0 if res > 1.0: res = 1.0 if inplace: corners[self.rnd_index] = res else: corners = [res, res, res, res] if final: self.api.set_rect_corners_final(corners, self.orig_corners, self.target) else: self.api.set_rect_corners(corners, self.target) self.update_points()
def get_trafo(self): trafo = [] + sk2_const.NORMAL_TRAFO bbox = self.get_selection_bbox() w, h = self.get_selection_size() new_w = self.h_spin.get_point_value() new_h = self.v_spin.get_point_value() trafo[0] = new_w / w trafo[3] = new_h / h bp = [bbox[0] + w * (1.0 + self.orientation[0]) / 2.0, bbox[1] + h * (1.0 + self.orientation[1]) / 2.0] new_bp = libgeom.apply_trafo_to_point(bp, trafo) trafo[4] = bp[0] - new_bp[0] trafo[5] = bp[1] - new_bp[1] return trafo
def translate_text(self, obj, cfg): trafo_rotate = libgeom.trafo_rotate(obj.angle) base_point = libgeom.apply_trafo_to_point([obj.x, obj.y], self.trafo) base_point[1] -= obj.font_size trafo = [72.0 / 90.0, 0.0, 0.0, 72.0 / 90.0] + base_point trafo = libgeom.multiply_trafo(trafo_rotate, trafo) text_style = self.get_text_style(obj) props = dict(point=[0.0, obj.font_size], style=text_style, text=obj.string, trafo=trafo) new_obj = sk2_model.Text(cfg, **props) txt_length = len(obj.string) tags = [] new_obj.markup = [[tags, (0, txt_length)]] return new_obj
def get_index_by_point(self, point): doc_point = self.canvas.win_to_doc(point) inv_trafo = libgeom.invert_trafo(self.target.trafo) doc_point = libgeom.apply_trafo_to_point(doc_point, inv_trafo) line = -1 for item in self.target.cache_line_points: line += 1 if doc_point[1] >= item[1]: break index = self.lines[line][0] for item in range(*self.lines[line]): layout = self.target.cache_layout_data pos = layout[index][0] + layout[index][2] / 2.0 if doc_point[0] <= pos: break index += 1 return index
def apply_resizing(self, point, final=False): wpoint = self.canvas.point_win_to_doc(point) invtrafo = libgeom.invert_trafo(self.target.trafo) wpoint = libgeom.apply_trafo_to_point(wpoint, invtrafo) rect = self.target.get_rect() corners = [] + self.target.corners if self.res_index == 0: rect[2] -= wpoint[0] - rect[0] rect[0] = wpoint[0] if rect[2] < 0: self.res_index = 2 c0, c1, c2, c3 = corners corners = [c3, c2, c1, c0] elif self.res_index == 1: rect[3] = wpoint[1] - rect[1] if rect[3] < 0: self.res_index = 3 c0, c1, c2, c3 = corners corners = [c1, c0, c3, c2] elif self.res_index == 2: rect[2] = wpoint[0] - rect[0] if rect[2] < 0: self.res_index = 0 c0, c1, c2, c3 = corners corners = [c3, c2, c1, c0] elif self.res_index == 3: rect[3] -= wpoint[1] - rect[1] rect[1] = wpoint[1] if rect[3] < 0: self.res_index = 1 c0, c1, c2, c3 = corners corners = [c1, c0, c3, c2] rect = libgeom.normalize_rect(rect) if final: self.api.set_rect_final(self.target, rect, self.orig_rect) if not corners == self.orig_corners: self.api.set_rect_corners_final(corners, self.orig_corners, self.target) self.orig_corners = [] + self.target.corners self.orig_rect = self.target.get_rect() else: self.api.set_rect(self.target, rect) if not corners == self.target.corners: self.api.set_rect_corners(corners, self.target) self.update_points()
def apply_rounding(self, point, final=False, inplace=False): wpoint = self.canvas.point_win_to_doc(point) invtrafo = libgeom.invert_trafo(self.target.trafo) wpoint = libgeom.apply_trafo_to_point(wpoint, invtrafo) corners = [] + self.target.corners name = str(self.rnd_index) + str(self.rnd_subindex) res = 0.0 if self.stop2: val = abs(wpoint[0] - self.start[0]) val2 = abs(wpoint[1] - self.start[1]) start = self.start if val > val2: if self.rnd_index in (0, 2): stop = self.stop2 res = (wpoint[0] - start[0]) / (stop[0] - start[0]) else: stop = self.stop res = (wpoint[0] - start[0]) / (stop[0] - start[0]) else: if self.rnd_index in (0, 2): stop = self.stop res = (wpoint[1] - start[1]) / (stop[1] - start[1]) else: stop = self.stop2 res = (wpoint[1] - start[1]) / (stop[1] - start[1]) else: start = self.start stop = self.stop if name in H_ORIENT: res = (wpoint[0] - start[0]) / (stop[0] - start[0]) else: res = (wpoint[1] - start[1]) / (stop[1] - start[1]) if res < 0.0: res = 0.0 if res > 1.0: res = 1.0 if inplace: corners[self.rnd_index] = res else: corners = [res, res, res, res] if final: self.api.set_rect_corners_final(corners, self.orig_corners, self.target) else: self.api.set_rect_corners(corners, self.target) self.update_points()
def _calc_bottom_scale_trafo(self, event): is_centering = event.is_shift() is_constraining = event.is_ctrl() is_snapping = not is_constraining m11, m21, m12, m22, dx, dy = sk2const.NORMAL_TRAFO start_point = self.canvas.win_to_doc(self.start) end_point = self.canvas.win_to_doc(self.end) bbox = self.presenter.selection.bbox middle_points = libgeom.bbox_middle_points(bbox) point = middle_points[3] base_y = bbox[3] h = libgeom.bbox_size(bbox)[1] if is_centering: shift_y = h / 2.0 + self.selection.center_offset[1] ratio_y = h / shift_y if shift_y else 1.0 ratio_y = ratio_y if abs(ratio_y) < MAX_RATIO_TRAFO else 1.0 shift_y = h - shift_y else: shift_y, ratio_y = 0.0, 1.0 change_y = h + (start_point[1] - end_point[1]) * ratio_y if is_constraining and h and change_y: if -h < change_y < h: change_y = 1.0 / (h // change_y) * h else: change_y = h + (change_y - h / 2) // h * h m22 = change_y / h if h and change_y else 1.0 dy = base_y - base_y * m22 + shift_y * (m22 - 1.0) if is_snapping: trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) flag, _wp, end_point = self.snap.snap_point(p, False) start_point = point if flag: change_y = h + (start_point[1] - end_point[1]) * ratio_y m22 = change_y / h if h else 1.0 dy = base_y - base_y * m22 + shift_y * (m22 - 1.0) return [m11 or EPSILON, m21, m12, m22 or EPSILON, dx, dy]
def _calc_left_scale_trafo(self, event): is_centering = event.is_shift() is_constraining = event.is_ctrl() is_snapping = not is_constraining m11, m21, m12, m22, dx, dy = sk2const.NORMAL_TRAFO start_point = self.canvas.win_to_doc(self.start) end_point = self.canvas.win_to_doc(self.end) bbox = self.presenter.selection.bbox middle_points = libgeom.bbox_middle_points(bbox) point = middle_points[0] base_x = bbox[2] w = libgeom.bbox_size(bbox)[0] if is_centering: shift_x = w / 2.0 + self.selection.center_offset[0] ratio_x = w / shift_x if shift_x else 1.0 ratio_x = ratio_x if abs(ratio_x) < MAX_RATIO_TRAFO else 1.0 shift_x = w - shift_x else: shift_x, ratio_x = 0.0, 1.0 change_x = w + (start_point[0] - end_point[0]) * ratio_x if is_constraining and w and change_x: if -w < change_x < w: change_x = 1.0 / (w // change_x) * w else: change_x = w + (change_x - w / 2) // w * w m11 = change_x / w if w and change_x else 1.0 dx = base_x - base_x * m11 + shift_x * (m11 - 1.0) if is_snapping: trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) flag, _wp, end_point = self.snap.snap_point(p, False) start_point = point if flag: change_x = w + (start_point[0] - end_point[0]) * ratio_x m11 = change_x / w if w else 1.0 dx = base_x - base_x * m11 + shift_x * (m11 - 1.0) return [m11 or EPSILON, m21, m12, m22 or EPSILON, dx, dy]
def get_trafo(self): angle1 = self.h_shear.get_angle_value() angle2 = self.v_shear.get_angle_value() m12 = math.tan(angle1) m21 = math.tan(angle2) m11 = 1.0 m22 = 1.0 - (m12 * m21) trafo = [m11, m21, -m12, m22, 0, 0] bbox = self.get_selection_bbox() w, h = self.get_selection_size() bp = [bbox[0] + w * (1.0 + self.orientation[0]) / 2.0, bbox[1] + h * (1.0 + self.orientation[1]) / 2.0] new_bp = libgeom.apply_trafo_to_point(bp, trafo) trafo[4] = bp[0] - new_bp[0] trafo[5] = bp[1] - new_bp[1] return trafo
def get_trafo(self): trafo = [] + sk2const.NORMAL_TRAFO bbox = self.get_selection_bbox() w, h = self.get_selection_size() trafo[0] = self.h_spin.get_value() / 100.0 trafo[3] = self.v_spin.get_value() / 100.0 if self.h_mirror.get_value(): trafo[0] *= -1.0 if self.v_mirror.get_value(): trafo[3] *= -1.0 bp = [ bbox[0] + w * (1.0 + self.orientation[0]) / 2.0, bbox[1] + h * (1.0 + self.orientation[1]) / 2.0 ] new_bp = libgeom.apply_trafo_to_point(bp, trafo) trafo[4] = bp[0] - new_bp[0] trafo[5] = bp[1] - new_bp[1] return trafo
def apply_midpoint_change(self, point, index, control=False, final=False): wpoint = self.canvas.point_win_to_doc(point) invtrafo = libgeom.invert_trafo(self.target.trafo) x, y = libgeom.apply_trafo_to_point(wpoint, invtrafo) radius = self.target.get_midpoint_radius() angle = self.target.get_midpoint_angle(index) coef2 = libgeom.get_point_radius([x, y]) / radius if control: props = [self.orig_angle1, self.orig_angle2, self.orig_coef1, coef2] else: angle2 = libgeom.get_point_angle([x, y]) - angle props = [self.orig_angle1, angle2, self.orig_coef1, coef2] if final: props_before = [self.orig_angle1, self.orig_angle2, self.orig_coef1, self.orig_coef2] self.api.set_polygon_properties_final(props, props_before, self.target) else: self.api.set_polygon_properties(props, self.target) self.update_points()
def tr_exttextout(self, chunk): y, x, length = get_data('<hhh', chunk[:6]) dl = 0 if length % 2: length += 1 dl += 1 p = apply_trafo_to_point([x, y], self.get_trafo()) encoding = self.get_encoding() pos = 16 if not len(chunk) - 8 == length else 8 txt = chunk[pos:pos + length - dl].decode(encoding) txt_length = len(txt) txt = txt.encode('utf-8') cfg = self.layer.config sk2_style, tags = self.get_text_style() markup = [[tags, (0, txt_length)]] tr = [] + libgeom.NORMAL_TRAFO text = sk2_model.Text(cfg, self.layer, p, txt, -1, tr, sk2_style) text.markup = markup rect = None if self.dc.opacity: bg_style = [[], [], [], []] clr = [] + self.dc.bgcolor clr = [uc2const.COLOR_RGB, clr, 1.0, '', ''] bg_style[0] = [sk2const.FILL_EVENODD, sk2const.FILL_SOLID, clr] text.update() bbox = [] + text.cache_bbox rect = bbox[:2] + [bbox[2] - bbox[0], bbox[3] - bbox[1]] rect = sk2_model.Rectangle(cfg, self.layer, rect, style=bg_style) rect.trafo = tr self.layer.childs.append(rect) if self.dc.font[-2]: tr = libgeom.trafo_rotate_grad(self.dc.font[-2], p[0], p[1]) text.trafo = libgeom.multiply_trafo(text.trafo, tr) if self.dc.opacity: rect.trafo = libgeom.multiply_trafo(rect.trafo, tr) self.layer.childs.append(text)
def apply_trafo_before(self, trafo): if not len(self.point) == 2: p0, p1, p2, marker = deepcopy(self.point) p0 = libgeom.apply_trafo_to_point(p0, trafo) self.point = [p0, p1, p2, marker]
def _calc_bottom_right_scale_trafo(self, event): is_centering = event.is_shift() is_constraining = event.is_ctrl() is_snapping = True m11, m21, m12, m22, dx, dy = sk2const.NORMAL_TRAFO start_point = self.canvas.win_to_doc(self.start) end_point = self.canvas.win_to_doc(self.end) bbox = self.presenter.selection.bbox bbox_points = libgeom.bbox_points(bbox) point = bbox_points[2] base_x, base_y = bbox_points[1] w, h = libgeom.bbox_size(bbox) if is_centering: shift_x = w / 2.0 - self.selection.center_offset[0] shift_y = h / 2.0 + self.selection.center_offset[1] ratio_x = w / shift_x if shift_x else 1.0 ratio_y = h / shift_y if shift_y else 1.0 ratio_x = ratio_x if abs(ratio_x) < MAX_RATIO_TRAFO else 1.0 ratio_y = ratio_y if abs(ratio_y) < MAX_RATIO_TRAFO else 1.0 shift_x = shift_x - w shift_y = h - shift_y else: shift_x, ratio_x = 0.0, 1.0 shift_y, ratio_y = 0.0, 1.0 change_x = w + (end_point[0] - start_point[0]) * ratio_x change_y = h + (start_point[1] - end_point[1]) * ratio_y if is_constraining: if w < h: m11 = m22 = change_x / w if w and change_x else 1.0 else: m11 = m22 = change_y / h if h and change_y else 1.0 else: m11 = change_x / w if w and change_x else 1.0 m22 = change_y / h if h and change_y else 1.0 dx = base_x - base_x * m11 + shift_x * (m11 - 1.0) dy = base_y - base_y * m22 + shift_y * (m22 - 1.0) if is_snapping: trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) flag, _wp, end_point = self.snap.snap_point(p, False) start_point = point if flag: change_x = w + (end_point[0] - start_point[0]) * ratio_x change_y = h + (start_point[1] - end_point[1]) * ratio_y if is_constraining: if self.snap.active_snap[0] is not None: m11 = m22 = change_x / w if w and change_x else 1.0 else: m11 = m22 = change_y / h if h and change_y else 1.0 else: m11 = change_x / w if w and change_x else 1.0 m22 = change_y / h if h and change_y else 1.0 dx = base_x - base_x * m11 + shift_x * (m11 - 1.0) dy = base_y - base_y * m22 + shift_y * (m22 - 1.0) return [m11 or EPSILON, m21, m12, m22 or EPSILON, dx, dy]
def get_point(self): return libgeom.apply_trafo_to_point(self.point, self.target.trafo)
def _calc_trafo(self, event): control = shift = False if event.state & gtk.gdk.CONTROL_MASK: control = True if event.state & gtk.gdk.SHIFT_MASK: shift = True mark = self.canvas.resize_marker start_point = self.canvas.win_to_doc(self.start) end_point = self.canvas.win_to_doc(self.end) bbox = self.presenter.selection.bbox middle_points = libgeom.bbox_middle_points(bbox) w = bbox[2] - bbox[0] h = bbox[3] - bbox[1] m11 = m22 = 1.0 m12 = m21 = 0.0 dx = dy = 0.0 snap = [None, None] if mark == 0: dx = start_point[0] - end_point[0] dy = end_point[1] - start_point[1] if shift: if control: m11 = (w + 2.0 * dx) / w m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + 2.0 * dx) / w else: m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = m22 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] else: point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if control: m11 = (w + dx) / w m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[1] * m22 - bbox[1]) #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) snap[0] = self.snap.active_snap[0] point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m22 = (h + dy) / h dy = -(bbox[1] * m22 - bbox[1]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + dx) / w else: m11 = m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[1] * m22 - bbox[1]) #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = m22 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[1] * m22 - bbox[1]) snap[0] = self.snap.active_snap[0] else: point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m11 = m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[1] * m22 - bbox[1]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping if mark == 1: dy = end_point[1] - start_point[1] if shift: m22 = (h + 2.0 * dy) / h dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dy = p_doc[1] - point[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 #---- snapping else: m22 = (h + dy) / h dy = -(bbox[1] * m22 - bbox[1]) #---- snapping point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dy = p_doc[1] - point[1] m22 = (h + dy) / h dy = -(bbox[1] * m22 - bbox[1]) #---- snapping if mark == 2: dx = end_point[0] - start_point[0] dy = end_point[1] - start_point[1] if shift: if control: m11 = (w + 2.0 * dx) / w m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + 2.0 * dx) / w else: m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = m22 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] else: point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if control: m11 = (w + dx) / w m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[1] * m22 - bbox[1]) #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) snap[0] = self.snap.active_snap[0] point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m22 = (h + dy) / h dy = -(bbox[1] * m22 - bbox[1]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + dx) / w else: m11 = m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[1] * m22 - bbox[1]) #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = m22 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[1] * m22 - bbox[1]) snap[0] = self.snap.active_snap[0] else: point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m11 = m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[1] * m22 - bbox[1]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping if mark == 3: dx = start_point[0] - end_point[0] if shift: m11 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dx = point[0] - p_doc[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 #---- snapping else: m11 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dx = point[0] - p_doc[0] m11 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) #---- snapping if mark == 5: dx = end_point[0] - start_point[0] if shift: m11 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dx = p_doc[0] - point[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 #---- snapping else: m11 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dx = p_doc[0] - point[0] m11 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) #---- snapping if mark == 6: dx = start_point[0] - end_point[0] dy = start_point[1] - end_point[1] if shift: if control: m11 = (w + 2.0 * dx) / w m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + 2.0 * dx) / w else: m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = m22 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] else: point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if control: m11 = (w + dx) / w m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[3] * m22 - bbox[3]) #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) snap[0] = self.snap.active_snap[0] point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m22 = (h + dy) / h dy = -(bbox[3] * m22 - bbox[3]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + dx) / w else: m11 = m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[3] * m22 - bbox[3]) #---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = m22 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[3] * m22 - bbox[3]) snap[0] = self.snap.active_snap[0] else: point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m11 = m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[3] * m22 - bbox[3]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping if mark == 7: dy = start_point[1] - end_point[1] if shift: m22 = (h + 2.0 * dy) / h dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dy = point[1] - p_doc[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 #---- snapping else: m22 = (h + dy) / h dy = -(bbox[3] * m22 - bbox[3]) #---- snapping point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dy = point[1] - p_doc[1] m22 = (h + dy) / h dy = -(bbox[3] * m22 - bbox[3]) #---- snapping if mark == 8: dx = end_point[0] - start_point[0] dy = start_point[1] - end_point[1] if shift: if control: m11 = (w + 2.0 * dx) / w m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + 2.0 * dx) / w else: m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = m22 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] else: point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if control: m11 = (w + dx) / w m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[3] * m22 - bbox[3]) #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) snap[0] = self.snap.active_snap[0] point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m22 = (h + dy) / h dy = -(bbox[3] * m22 - bbox[3]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + dx) / w else: m11 = m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[3] * m22 - bbox[3]) #---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = m22 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[3] * m22 - bbox[3]) snap[0] = self.snap.active_snap[0] else: point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m11 = m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[3] * m22 - bbox[3]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap #---- snapping if mark == 11: change_x = end_point[0] - start_point[0] m12 = change_x / h dx = -bbox[1] * m12 if mark == 16: change_x = start_point[0] - end_point[0] m12 = change_x / h dx = -bbox[3] * m12 if mark == 13: change_y = start_point[1] - end_point[1] m21 = change_y / w dy = -bbox[2] * m21 if mark == 14: change_y = end_point[1] - start_point[1] m21 = change_y / w dy = -bbox[0] * m21 if mark in (10, 12, 15, 17): x0, y0 = bbox[:2] shift_x, shift_y = self.selection.center_offset center_x = x0 + w / 2.0 + shift_x center_y = y0 + h / 2.0 + shift_y a1 = math.atan2(start_point[1] - center_y, start_point[0] - center_x) a2 = math.atan2(end_point[1] - center_y, end_point[0] - center_x) angle = a2 - a1 if control: step = config.rotation_step * math.pi / 180.0 angle = round(angle / step) * step m21 = math.sin(angle) m11 = m22 = math.cos(angle) m12 = -m21 dx = center_x - m11 * center_x + m21 * center_y; dy = center_y - m21 * center_x - m11 * center_y; if not m11: m11 = .0000000001 if not m22: m22 = .0000000001 return [m11, m21, m12, m22, dx, dy]
def point4wmf(self, point): return rndpoint(apply_trafo_to_point(point, self.trafo))
def get_point(self): p = libgeom.midpoint(self.start, self.stop, self.coef) return libgeom.apply_trafo_to_point(p, self.target.trafo)
def is_point_in_layout_bbox(self, point): bbox = self.target.cache_layout_bbox doc_point = self.canvas.win_to_doc(point) inv_trafo = libgeom.invert_trafo(self.target.trafo) doc_point = libgeom.apply_trafo_to_point(doc_point, inv_trafo) return libgeom.is_point_in_bbox(doc_point, bbox)
def get_point(self): angle = self.get_angle() x = 0.5 * math.cos(angle) + 0.5 y = 0.5 * math.sin(angle) + 0.5 return libgeom.apply_trafo_to_point([x, y], self.target.trafo)
def _calc_trafo(self, event): control = event.is_ctrl() shift = event.is_shift() mark = self.canvas.resize_marker start_point = self.canvas.win_to_doc(self.start) end_point = self.canvas.win_to_doc(self.end) bbox = self.presenter.selection.bbox middle_points = libgeom.bbox_middle_points(bbox) w = bbox[2] - bbox[0] h = bbox[3] - bbox[1] m11 = m22 = 1.0 m12 = m21 = 0.0 dx = dy = 0.0 snap = [None, None] if mark == 0: dx = start_point[0] - end_point[0] dy = end_point[1] - start_point[1] if shift: if control: m11 = (w + 2.0 * dx) / w m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + 2.0 * dx) / w else: m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = m22 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] else: point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if control: m11 = (w + dx) / w m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[1] * m22 - bbox[1]) # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) snap[0] = self.snap.active_snap[0] point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m22 = (h + dy) / h dy = -(bbox[1] * m22 - bbox[1]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + dx) / w else: m11 = m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[1] * m22 - bbox[1]) # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = m22 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[1] * m22 - bbox[1]) snap[0] = self.snap.active_snap[0] else: point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m11 = m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[1] * m22 - bbox[1]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping if mark == 1: dy = end_point[1] - start_point[1] if shift: m22 = (h + 2.0 * dy) / h dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dy = p_doc[1] - point[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 # ---- snapping else: m22 = (h + dy) / h dy = -(bbox[1] * m22 - bbox[1]) # ---- snapping point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dy = p_doc[1] - point[1] m22 = (h + dy) / h dy = -(bbox[1] * m22 - bbox[1]) # ---- snapping if mark == 2: dx = end_point[0] - start_point[0] dy = end_point[1] - start_point[1] if shift: if control: m11 = (w + 2.0 * dx) / w m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + 2.0 * dx) / w else: m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = m22 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] else: point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[1] * m22 - bbox[1]) - h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if control: m11 = (w + dx) / w m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[1] * m22 - bbox[1]) # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) snap[0] = self.snap.active_snap[0] point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m22 = (h + dy) / h dy = -(bbox[1] * m22 - bbox[1]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + dx) / w else: m11 = m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[1] * m22 - bbox[1]) # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = m22 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[1] * m22 - bbox[1]) snap[0] = self.snap.active_snap[0] else: point = middle_points[1] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = p_doc[1] - point[1] m11 = m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[1] * m22 - bbox[1]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping if mark == 3: dx = start_point[0] - end_point[0] if shift: m11 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dx = point[0] - p_doc[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 # ---- snapping else: m11 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dx = point[0] - p_doc[0] m11 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) # ---- snapping if mark == 5: dx = end_point[0] - start_point[0] if shift: m11 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dx = p_doc[0] - point[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 # ---- snapping else: m11 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dx = p_doc[0] - point[0] m11 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) # ---- snapping if mark == 6: dx = start_point[0] - end_point[0] dy = start_point[1] - end_point[1] if shift: if control: m11 = (w + 2.0 * dx) / w m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + 2.0 * dx) / w else: m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = m22 = (w + 2.0 * dx) / w dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] else: point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[2] * m11 - bbox[2]) + w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if control: m11 = (w + dx) / w m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[3] * m22 - bbox[3]) # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) snap[0] = self.snap.active_snap[0] point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m22 = (h + dy) / h dy = -(bbox[3] * m22 - bbox[3]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + dx) / w else: m11 = m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[3] * m22 - bbox[3]) # ---- snapping point = middle_points[0] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = point[0] - p_doc[0] m11 = m22 = (w + dx) / w dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[3] * m22 - bbox[3]) snap[0] = self.snap.active_snap[0] else: point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m11 = m22 = (h + dy) / h dx = -(bbox[2] * m11 - bbox[2]) dy = -(bbox[3] * m22 - bbox[3]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping if mark == 7: dy = start_point[1] - end_point[1] if shift: m22 = (h + 2.0 * dy) / h dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dy = point[1] - p_doc[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 # ---- snapping else: m22 = (h + dy) / h dy = -(bbox[3] * m22 - bbox[3]) # ---- snapping point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False) dy = point[1] - p_doc[1] m22 = (h + dy) / h dy = -(bbox[3] * m22 - bbox[3]) # ---- snapping if mark == 8: dx = end_point[0] - start_point[0] dy = start_point[1] - end_point[1] if shift: if control: m11 = (w + 2.0 * dx) / w m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m22 = (h + 2.0 * dy) / h dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + 2.0 * dx) / w else: m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = m22 = (w + 2.0 * dx) / w dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[0] = self.snap.active_snap[0] else: point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m11 = m22 = (h + 2.0 * dy) / h dx = -(bbox[0] * m11 - bbox[0]) - w * (m11 - 1.0) / 2.0 dy = -(bbox[3] * m22 - bbox[3]) + h * (m22 - 1.0) / 2.0 snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if control: m11 = (w + dx) / w m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[3] * m22 - bbox[3]) # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) snap[0] = self.snap.active_snap[0] point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m22 = (h + dy) / h dy = -(bbox[3] * m22 - bbox[3]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping else: if abs(dx) < abs(dy): m11 = m22 = (w + dx) / w else: m11 = m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[3] * m22 - bbox[3]) # ---- snapping point = middle_points[2] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_y=False) if f: dx = p_doc[0] - point[0] m11 = m22 = (w + dx) / w dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[3] * m22 - bbox[3]) snap[0] = self.snap.active_snap[0] else: point = middle_points[3] trafo = [m11, m21, m12, m22, dx, dy] p = libgeom.apply_trafo_to_point(point, trafo) f, p, p_doc = self.snap.snap_point(p, False, snap_x=False) if f: dy = point[1] - p_doc[1] m11 = m22 = (h + dy) / h dx = -(bbox[0] * m11 - bbox[0]) dy = -(bbox[3] * m22 - bbox[3]) snap[1] = self.snap.active_snap[1] self.snap.active_snap = snap # ---- snapping if mark == 11: change_x = end_point[0] - start_point[0] m12 = change_x / h dx = -bbox[1] * m12 if mark == 16: change_x = start_point[0] - end_point[0] m12 = change_x / h dx = -bbox[3] * m12 if mark == 13: change_y = start_point[1] - end_point[1] m21 = change_y / w dy = -bbox[2] * m21 if mark == 14: change_y = end_point[1] - start_point[1] m21 = change_y / w dy = -bbox[0] * m21 if mark in (10, 12, 15, 17): x0, y0 = bbox[:2] shift_x, shift_y = self.selection.center_offset center_x = x0 + w / 2.0 + shift_x center_y = y0 + h / 2.0 + shift_y a1 = math.atan2(start_point[1] - center_y, start_point[0] - center_x) a2 = math.atan2(end_point[1] - center_y, end_point[0] - center_x) angle = a2 - a1 if control: step = config.rotation_step * math.pi / 180.0 angle = round(angle / step) * step m21 = math.sin(angle) m11 = m22 = math.cos(angle) m12 = -m21 dx = center_x - m11 * center_x + m21 * center_y dy = center_y - m21 * center_x - m11 * center_y m11 = m11 or .000001 m22 = m22 or .000001 return [m11, m21, m12, m22, dx, dy]