def draw_mathtext(self, gc, x, y, s, prop, angle): # TODO: fix positioning and encoding fontsize = prop.get_size_in_points() width, height, pswriter = math_parse_s_pdf(s, self.file.dpi, fontsize) self.check_gc(gc, gc._rgb) self.file.output(Op.begin_text) prev_font = None, None oldx, oldy = 0, 0 for ox, oy, fontname, fontsize, glyph in pswriter: #print ox, oy, glyph fontname = fontname.lower() a = angle / 180.0 * pi newx = x + cos(a) * ox - sin(a) * oy newy = y + sin(a) * ox + cos(a) * oy self._setup_textpos(newx, newy, angle, oldx, oldy) oldx, oldy = newx, newy if (fontname, fontsize) != prev_font: self.file.output(self.file.fontName(fontname), fontsize, Op.selectfont) prev_font = fontname, fontsize #if fontname.endswith('cmsy10.ttf') or \ #fontname.endswith('cmmi10.ttf') or \ #fontname.endswith('cmex10.ttf'): # string = '\0' + chr(glyph) string = chr(glyph) self.file.output(string, Op.show) self.file.output(Op.end_text)
def draw_mathtext(self, gc, x, y, s, prop, angle): # TODO: fix positioning and encoding fontsize = prop.get_size_in_points() width, height, pswriter = math_parse_s_pdf(s, self.file.dpi, fontsize) self.check_gc(gc, gc._rgb) self.file.output(Op.begin_text) prev_font = None, None oldx, oldy = 0, 0 for ox, oy, fontname, fontsize, glyph in pswriter: #print ox, oy, glyph fontname = fontname.lower() a = angle / 180.0 * pi newx = x + cos(a)*ox - sin(a)*oy newy = y + sin(a)*ox + cos(a)*oy self._setup_textpos(newx, newy, angle, oldx, oldy) oldx, oldy = newx, newy if (fontname, fontsize) != prev_font: self.file.output(self.file.fontName(fontname), fontsize, Op.selectfont) prev_font = fontname, fontsize #if fontname.endswith('cmsy10.ttf') or \ #fontname.endswith('cmmi10.ttf') or \ #fontname.endswith('cmex10.ttf'): # string = '\0' + chr(glyph) string = chr(glyph) self.file.output(string, Op.show) self.file.output(Op.end_text)
def get_text_width_height(self, s, prop, ismath): if ismath: fontsize = prop.get_size_in_points() w, h, pswriter = math_parse_s_pdf(s, self.file.dpi, fontsize) else: font = self._get_font_ttf(prop) font.set_text(s, 0.0) w, h = font.get_width_height() factor = 1.0 / (self.dpi_factor * 64.0) w *= factor h *= factor return w, h
def get_text_width_height(self, s, prop, ismath): if ismath: fontsize = prop.get_size_in_points() w, h, pswriter = math_parse_s_pdf(s, self.file.dpi, fontsize) else: font = self._get_font_ttf(prop) font.set_text(s, 0.0) w, h = font.get_width_height() factor = 1.0/(self.dpi_factor*64.0) w *= factor h *= factor return w, h