def __init__(self): RichTextBaseFont.__init__(self) # TODO: remove hard-coding self.mods = {} self.justify = "left" self.family = "Sans" self.size = 10 self.fg_color = "" self.bg_color = "" self.indent = 0 self.par_type = "none" self.link = None
def set_font(self, attr, tags, current_tags, tag_table): # set basic font attr RichTextBaseFont.set_font(self, attr, tags, current_tags, tag_table) font = attr.font if font: # get font family self.family = font.get_family() # get size in points (get_size() returns pango units) PIXELS_PER_PANGO_UNIT = 1024 self.size = font.get_size() // PIXELS_PER_PANGO_UNIT weight = font.get_weight() style = font.get_style() else: # TODO: replace this hard-coding self.family = "Sans" self.size = 10 weight = pango.WEIGHT_NORMAL style = pango.STYLE_NORMAL # get colors self.fg_color = color_to_string(attr.fg_color) self.bg_color = color_to_string(attr.bg_color) mod_class = tag_table.get_tag_class("mod") #bold = tag_table.lookup("bold") #italic = tag_table.lookup("italic") #underline = tag_table.lookup("underline") #strike = tag_table.lookup("strike") #tt = tag_table.lookup("tt") #nowrap = tag_table.lookup("nowrap") tag_set = set(tags) # set modifications (current tags override) self.mods = {} for tag in mod_class.tags: self.mods[tag.get_property("name")] = (tag in current_tags or tag in tag_set) self.mods["tt"] = (self.mods["tt"] or self.family == "Monospace") ''' "bold": bold in current_tags or bold in tag_set, "italic": italic in current_tags or italic in tag_set, "underline": underline in current_tags or underline in tag_set, "strike": strike in current_tags or strike in tag_set, "tt": tt in current_tags or tt in tag_set or self.family == "Monospace", "nowrap": nowrap in current_tags or nowrap in tag_set} ''' # set justification self.justify = RichTextJustifyTag.justify2name[attr.justification] # current tags override for family and size for tag in current_tags: if isinstance(tag, RichTextJustifyTag): self.justify = tag.get_justify() elif isinstance(tag, RichTextFamilyTag): self.family = tag.get_family() elif isinstance(tag, RichTextSizeTag): self.size = tag.get_size() elif isinstance(tag, RichTextFGColorTag): self.fg_color = tag.get_color() elif isinstance(tag, RichTextBGColorTag): self.bg_color = tag.get_color() # set indentation info for tag in chain(tags, current_tags): if isinstance(tag, RichTextIndentTag): self.indent = tag.get_indent() self.par_type = tag.get_par_indent() elif isinstance(tag, RichTextLinkTag): self.link = tag