Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--toolbar.py35
2 files changed, 33 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 0a6674f..7e85890 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+* Also (temporary) add fonts used by loaded documents that are not available
+ on the system to the font dropdown list (uwog)
* Set a tooltip on various menu items (#821) (uwog)
* Hook up the abiword canvas 'style-name' signal to the Format toolbar (uwog)
* Hook up the abiword canvas 'font-family' signal to the Text toolbar (uwog)
diff --git a/toolbar.py b/toolbar.py
index d21e1ce..835584a 100644
--- a/toolbar.py
+++ b/toolbar.py
@@ -102,6 +102,8 @@ class TextToolbar(gtk.Toolbar):
self.insert(tool_item, -1);
tool_item.show()
+ self._has_custom_fonts = False
+
self._font_combo = ComboBox()
self._fonts = sorted(self._abiword_canvas.get_font_names())
self._fonts_changed_id = self._font_combo.connect('changed', self._font_changed_cb)
@@ -199,13 +201,38 @@ class TextToolbar(gtk.Toolbar):
self._abiword_canvas.set_font_size(self._font_sizes[self._font_size_combo.get_active()])
def _font_family_cb(self, abi, font_family):
+ font_index = -1
+
+ # search for the font name in our font list
for i, f in enumerate(self._fonts):
if f == font_family:
- self._font_combo.handler_block(self._fonts_changed_id)
- self._font_combo.set_active(i)
- self._font_combo.handler_unblock(self._fonts_changed_id)
+ font_index = i
break;
- # TODO: if no match is found, then add the font to the font family dropdown
+
+ # if we don't know this font yet, then add it (temporary) to the list
+ if font_index == -1:
+ logger.debug('Font not found in font list: %s', font_family)
+ if not self._has_custom_fonts:
+ # add a separator to seperate the non-available fonts from
+ # the available ones
+ self._fonts.append('') # ugly
+ self._font_combo.append_separator()
+ self._has_custom_fonts = True
+ font_index = 1
+ # add the new font
+ self._fonts.append(font_family)
+ self._font_combo.append_item(0, font_family, None)
+ # see how many fonts we have now, so we can select the last one
+ model = self._font_combo.get_model()
+ num_children = model.iter_n_children(None)
+ logger.debug('Number of fonts in the list: %d', num_children)
+ font_index = num_children-1
+
+ # activate the found font
+ if (font_index > -1):
+ self._font_combo.handler_block(self._fonts_changed_id)
+ self._font_combo.set_active(font_index)
+ self._font_combo.handler_unblock(self._fonts_changed_id)
def _font_changed_cb(self, combobox):
if self._font_combo.get_active() != -1: