diff --git a/plugins/textsize/textsize/documenthelper.py b/plugins/textsize/textsize/documenthelper.py index bd355fb..572115f 100644 --- a/plugins/textsize/textsize/documenthelper.py +++ b/plugins/textsize/textsize/documenthelper.py @@ -40,28 +40,15 @@ class DocumentHelper(Signals): self._default_font = None self._last_font = None - self._font_tags = {} def stop(self): if self._default_font: self._view.override_font(self._default_font) - self.remove_font_tags() self.disconnect_signals(self._view) self._view.textsize_document_helper = None - def remove_font_tags(self): - buf = self._view.get_buffer() - table = buf.get_tag_table() - - # Remove all the font tags - for size in self._font_tags: - tag = self._font_tags[size] - table.remove(tag) - - self._font_tags = {} - def update_default_font(self): context = self._view.get_style_context() description = context.get_font(context.get_state()).copy() @@ -69,23 +56,6 @@ class DocumentHelper(Signals): if not self._last_font or description.hash() != self._last_font.hash(): self._default_font = description - def get_font_tags(self, start, end): - tags = set() - - # Check all the know font tags - for size in self._font_tags: - tag = self._font_tags[size] - - if start.has_tag(tag): - tags.add(tag) - else: - cp = start.copy() - - if cp.forward_to_tag_toggle(tag) and cp.compare(end) < 0: - tags.add(tag) - - return list(tags) - def set_font_size(self, amount): self.update_default_font() @@ -93,61 +63,17 @@ class DocumentHelper(Signals): description = context.get_font(context.get_state()).copy() buf = self._view.get_buffer() - bounds = buf.get_selection_bounds() size = description.get_size() / Pango.SCALE - if not bounds: - if size >= MAX_FONT_SIZE and amount == 1: - return; - if size <= MIN_FONT_SIZE and amount == -1: - return; + if size >= MAX_FONT_SIZE and amount == 1: + return; + if size <= MIN_FONT_SIZE and amount == -1: + return; - description.set_size(max(1, (size + amount)) * Pango.SCALE) + description.set_size(max(1, (size + amount)) * Pango.SCALE) - self._view.override_font(description) - self._last_font = description - else: - start = bounds[0] - end = bounds[1] - - tags = self.get_font_tags(start, end) - - if not tags: - # Simply use the overall font size as the base - newsize = size + amount - elif len(tags) == 1: - newsize = tags[0].props.font_desc.get_size() / Pango.SCALE + amount - else: - newsize = 0 - - for tag in tags: - newsize += tag.props.font_desc.get_size() / Pango.SCALE - - newsize = round(newsize / len(tags)) - - if newsize >= MAX_FONT_SIZE and amount == 1: - return; - if newsize <= MIN_FONT_SIZE and amount == -1: - return; - - newsize = int(max(1, newsize)) - - if not newsize in self._font_tags: - newtag = buf.create_tag(None) - - desc = description - desc.set_size(newsize * Pango.SCALE) - - newtag.props.font_desc = desc - self._font_tags[newsize] = newtag - else: - newtag = self._font_tags[newsize] - - # Remove all the previous mix of tags - for tag in tags: - buf.remove_tag(tag, start, end) - - buf.apply_tag(newtag, start, end) + self._view.override_font(description) + self._last_font = description def larger_text(self): self.set_font_size(1) @@ -159,18 +85,9 @@ class DocumentHelper(Signals): self.update_default_font() buf = self._view.get_buffer() - bounds = buf.get_selection_bounds() - if not bounds: - self.remove_font_tags() - - self._view.override_font(self._default_font) - self._last_font = self._default_font - else: - tags = self.get_font_tags(bounds[0], bounds[1]) - - for tag in tags: - buf.remove_tag(tag, bounds[0], bounds[1]) + self._view.override_font(self._default_font) + self._last_font = self._default_font def on_scroll_event(self, view, event): state = event.state & Gtk.accelerator_get_default_mod_mask()