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 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) 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 translate_text(self, dest_parent, source_text): text = source_text.text.encode('utf-8') trafo = list(source_text.trafo) if len(source_text.trafo) == 2: trafo = [1.0, 0.0, 0.0, 1.0] + trafo trafo[4] += self.dx trafo[5] += self.dy size = source_text.properties.font_size * 1.16 dest_text = sk2_model.Text(dest_parent.config, dest_parent, [0.0, -size], text, trafo=trafo) dest_text.style = get_sk2_txt_style(source_text) return dest_text
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 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