def draw(self, rtl, ctx, pc, layout, fascent, fheight, baseline_x, baseline_y): """Draw this category header. Args: rtl (boolean): whether to draw right-to-left or not. ctx (cairo.Context): the Cairo context to draw to. pc (pangocairo.CairoContext): the PangoCairo context. layout (pango.layout): the Pango layout to draw text into. fascent (int): font ascent. fheight (int): font height. baseline_x (int): base X axis position. baseline_y (int): base Y axis position. """ ctx.save() ctx.set_source_rgb(0.9, 0.9, 0.9) ctx.rectangle(baseline_x, baseline_y - fascent, layout.get_width() / Pango.SCALE, fheight) ctx.fill() ctx.set_source_rgb(0.0, 0.0, 0.0) draw_utils.draw_text_center(ctx, pc, layout, fascent, fheight, baseline_x, baseline_y, self.name) ctx.restore()
def draw(self, rtl, ctx, pc, layout, fascent, fheight, baseline_x, baseline_y): """Draw this category header. Args: rtl (boolean): whether to draw right-to-left or not. ctx (cairo.Context): the Cairo context to draw to. pc (pangocairo.CairoContext): the PangoCairo context. layout (pango.layout): the Pango layout to draw text into. fascent (int): font ascent. fheight (int): font height. baseline_x (int): base X axis position. baseline_y (int): base Y axis position. """ # Bugfix: use real height (rect_height) of heading (could be multiple rows) # instead of fheight rect_height = self.label_drawing_height(layout) ctx.save() ctx.set_source_rgb(0.9, 0.9, 0.9) ctx.rectangle(baseline_x, baseline_y - fascent, layout.get_width() / Pango.SCALE, rect_height) ctx.fill() ctx.set_source_rgb(0.0, 0.0, 0.0) draw_utils.draw_text_center(ctx, pc, layout, fascent, rect_height, baseline_x, baseline_y, self.name) # print("cat-head %d %d %d %d %s" % (fascent, rect_height, # baseline_x, baseline_y, self.name)) ctx.restore()
def _draw_page_header(self, rtl, ctx, pc, layout, fascent, fheight, baseline_x, baseline_y, margin_top, text): content_width = self.rendering_area_w - 2 * self.print_bleed_pt - self.margin_inside_pt - self.margin_outside_pt margin_left = self.print_bleed_pt + ( self.margin_inside_pt if (self.index_page_num + self.page_offset) % 2 else self.margin_outside_pt) # calculate height -> fill background first. layout.set_text(text, -1) ext = layout.get_extents() textblock_height = float(ext.ink_rect.height) / Pango.SCALE * 1.8 self.ctx.save() if Renderer.DEBUG: # gray background: show heading area LOG.debug( "page_header (gray background): %f left, %f top, %f width, %f textblock_height" % (margin_left, margin_top, content_width, textblock_height)) self.ctx.set_source_rgba(.7, .7, .7, .75) self.ctx.rectangle(margin_left, margin_top, content_width, textblock_height) self.ctx.fill() # text self.ctx.set_source_rgb(0.72, 0.055, 0.047) self.ctx.translate(0, self.print_bleed_pt) draw_utils.draw_text_center(self.ctx, pc, layout, fascent, textblock_height, margin_left, baseline_y + (textblock_height / 2 * 1.1), text) #baseline_y self.ctx.restore() return textblock_height
def draw(self, rtl, ctx, pc, layout, fascent, fheight, baseline_x, baseline_y): """Draw this category header. Args: rtl (boolean): whether to draw right-to-left or not. ctx (cairo.Context): the Cairo context to draw to. pc (pangocairo.CairoContext): the PangoCairo context. layout (pango.layout): the Pango layout to draw text into. fascent (int): font ascent. fheight (int): font height. baseline_x (int): base X axis position. baseline_y (int): base Y axis position. """ ctx.save() ctx.set_source_rgb(0.9, 0.9, 0.9) ctx.rectangle(baseline_x, baseline_y - fascent, layout.get_width() / pango.SCALE, fheight) ctx.fill() ctx.set_source_rgb(0.0, 0.0, 0.0) draw_utils.draw_text_center(ctx, pc, layout, fascent, fheight, baseline_x, baseline_y, self.name) ctx.restore()
def draw(self, rtl, ctx, pc, layout, fascent, fheight, baseline_x, baseline_y): """Draw this category header. Parameters ---------- rtl : boolean Whether to draw right-to-left or not. ctx : cairo.Context The Cairo context to draw to. pc : pangocairo.CairoContext The PangoCairo context to use. layout : pango.layout The Pango layout to draw text into. fascent : int Font ascent. fheight : int Font height. baseline_x : int Base X axis position. baseline_y : int Base Y axis position. Returns ------- int Actual rendering height used """ # calculate header dimensions based on layout layout.set_auto_dir(False) layout.set_alignment(Pango.Alignment.CENTER) layout.set_text(self.name, -1) width, height = [x / Pango.SCALE for x in layout.get_size()] wrap_width = layout.get_width() / Pango.SCALE # draw the category header background bar ctx.save() ctx.set_source_rgb(0.9, 0.9, 0.9) ctx.rectangle(baseline_x, baseline_y - fascent, wrap_width, height) ctx.fill() # draw the actual category title text ctx.set_source_rgb(0.0, 0.0, 0.0) draw_utils.draw_text_center(ctx, layout, fascent, baseline_x, baseline_y, self.name) ctx.restore() # return total document height used return height
def draw(self, rtl, ctx, pc, layout, fascent, fheight, baseline_x, baseline_y): """Draw this category header. Args: rtl (boolean): whether to draw right-to-left or not. ctx (cairo.Context): the Cairo context to draw to. pc (pangocairo.CairoContext): the PangoCairo context. layout (pango.layout): the Pango layout to draw text into. fascent (int): font ascent. fheight (int): font height. baseline_x (int): base X axis position. baseline_y (int): base Y axis position. """ ctx.save() ctx.set_source_rgb(0.9, 0.9, 0.9) ctx.rectangle(baseline_x, baseline_y - fascent, layout.get_width() / pango.SCALE, fheight) ctx.fill() ctx.set_source_rgb(0.0, 0.0, 0.0) lx, _, rx, _ = draw_utils.draw_text_center(ctx, pc, layout, fascent, fheight, baseline_x, baseline_y, self.name) if self.icon: ctx.save() grp, w, h = self.draw_icon(ctx, fheight) if grp: ctx.translate(lx - (w * 1.1), baseline_y - fascent + (fheight-h)/2.0) ctx.set_source(grp) ctx.paint_with_alpha(1.0) ctx.restore() ctx.restore()