From 37d47c916dd0d8d53f277862a297aa23feb8ff13 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Mon, 18 Sep 2000 03:43:20 +0000 Subject: Added check for gnome-app-lib. Removed directories that have been moved to 2000-09-18 Christopher James Lahey * configure.in: Added check for gnome-app-lib. Removed directories that have been moved to gal. From addressbook/ChangeLog: 2000-09-18 Christopher James Lahey * backend/ebook/Makefile.am, contact-editor/Makefile.am, ename/Makefile.am, gui/component/Makefile.am, gui/widgets/Makefile.am: Added $(EXTRA_GNOME_CFLAGS) and $(EXTRA_GNOME_LIBS). Removed unneeded libraries. * backend/ebook/e-card.c, backend/pas/pas-backend-file.c, contact-editor/e-contact-editor-address.c, contact-editor/e-contact-editor-categories.c, contact-editor/e-contact-editor-categories.h, contact-editor/e-contact-editor-fullname.c, contact-editor/e-contact-editor.c, contact-editor/e-contact-save-as.c, ename/e-address-western.c, ename/test-ename-western-gtk.c, gui/component/addressbook-factory.c, gui/component/addressbook.c, gui/component/e-cardlist-model.h, gui/component/e-ldap-storage.c, gui/component/select-names/e-select-names-bonobo.c, gui/component/select-names/e-select-names-manager.c, gui/component/select-names/e-select-names-model.c, gui/component/select-names/e-select-names-table-model.c, gui/component/select-names/e-select-names-table-model.h, gui/component/select-names/e-select-names-text-model.h, gui/component/select-names/e-select-names.c, gui/component/select-names/e-select-names.h, gui/search/e-addressbook-search-dialog.c, gui/widgets/e-addressbook-model.h, gui/widgets/e-addressbook-view.c, gui/widgets/e-minicard-label.c, gui/widgets/e-minicard-view-widget.c, gui/widgets/e-minicard-view-widget.h, gui/widgets/e-minicard-view.c, gui/widgets/e-minicard-view.h, gui/widgets/e-minicard-widget.h, gui/widgets/e-minicard.c, gui/widgets/test-minicard-label.c, gui/widgets/test-reflow.c, printing/e-contact-print.c: Fixed the #include lines to deal properly with gal. From calendar/ChangeLog: 2000-09-18 Christopher James Lahey * gui/Makefile.am: Added $(EXTRA_GNOME_CFLAGS) and $(EXTRA_GNOME_LIBS). Removed unneeded libraries. * gui/calendar-model.h, gui/e-calendar-table.c, gui/e-day-view.c, gui/e-week-view-event-item.c, gui/e-week-view.c, gui/event-editor.c, gui/gncal-todo.c, gui/gnome-cal.c, gui/main.c, gui/print.c, gui/dialogs/task-editor.c: Fixed the #include lines to deal properly with gal. * gui/check-filled.xpm: New file since we can't include it from e-table anymore. From camel/ChangeLog: 2000-09-18 Christopher James Lahey * camel-folder-search.c, camel-folder-search.h, camel-remote-store.c, providers/imap/camel-imap-folder.c, providers/imap/camel-imap-store.c: Fixed the #include lines to deal properly with gal. From composer/ChangeLog: 2000-09-18 Christopher James Lahey * Makefile.am: Added $(EXTRA_GNOME_CFLAGS) and $(EXTRA_GNOME_LIBS). Removed unneeded libraries. * e-msg-composer-address-dialog.c, e-msg-composer-address-entry.c, e-msg-composer-attachment.c, e-msg-composer-hdrs.c, e-msg-composer.c: Fixed the #include lines to deal properly with gal. From e-util/ChangeLog: 2000-09-18 Christopher James Lahey * Makefile.am: Removed all the files moved to gal. * e-dialog-widgets.c: Fixed the #include lines to deal properly with gal. * e-gui-utils.c, e-gui-utils.h: Removed all of the functionality that was moved to gal. * e-canvas-utils.c, e-canvas-utils.h, e-canvas-vbox.c, e-canvas-vbox.h, e-canvas.c, e-canvas.h, e-cursors.c, e-cursors.h, e-font.c, e-font.h, e-popup-menu.c, e-popup-menu.h, e-printable.c, e-printable.h, e-unicode.c, e-unicode.h, e-util.c, e-util.h, e-xml-utils.c, e-xml-utils.h: Moved to gal. From filter/ChangeLog: 2000-09-18 Christopher James Lahey * filter-editor.c, filter-filter.c, filter-folder.c, filter-input.c, filter-message-search.c, filter-option.c, filter-rule.c, score-editor.c, vfolder-editor.c, vfolder-rule.c: Fixed the #include lines to deal properly with gal. From mail/ChangeLog: 2000-09-18 Christopher James Lahey * Makefile.am: Added $(EXTRA_GNOME_CFLAGS) and $(EXTRA_GNOME_LIBS). Removed unneeded libraries. * component-factory.c, folder-browser-factory.c, folder-browser.c, mail-callbacks.c, mail-config-gui.c, mail-display.c, mail-display.h, main.c, message-list.c, message-list.h: Fixed the #include lines to deal properly with gal. From po/ChangeLog: 2000-09-18 Christopher James Lahey * POTFILES.in: Removed files that have been moved to gal. From shell/ChangeLog: 2000-09-18 Christopher James Lahey * Makefile.am: Added $(EXTRA_GNOME_CFLAGS) and $(EXTRA_GNOME_LIBS). Removed unneeded libraries. * e-component-registry.c, e-corba-storage-registry.c, e-corba-storage.c, e-folder-type-registry.c, e-folder.c, e-local-folder.c, e-local-storage.c, e-shell-folder-creation-dialog.c, e-shell-folder-selection-dialog.c, e-shell-folder-title-bar.c, e-shell-view.c, e-shell.c, e-shortcuts-view.c, e-shortcuts.c, e-storage-set-view.c, e-storage-set-view.h, e-storage-set.c, e-storage.c, evolution-local-storage.c, evolution-session.c, evolution-shell-client.c, evolution-shell-component-client.c, evolution-shell-component.c, evolution-shell-view.c, evolution-storage-listener.c, evolution-storage.c, main.c: Fixed the #include lines to deal properly with gal. From widgets/meeting-time-sel/ChangeLog: 2000-09-18 Christopher James Lahey * Makefile.am: Added $(EXTRA_GNOME_CFLAGS) and $(EXTRA_GNOME_LIBS). Removed unneeded libraries. * e-meeting-time-sel-list-item.c, e-meeting-time-sel.c, e-meeting-time-sel.h: Fixed the #include lines to deal properly with gal. If you've read this far, you deserve a prize. The first email in my mailbox with the subject "What a commit message!" (and your physical mailing address somewhere in the message) will receive a free Helix Code T-shirt mailed to anywhere within the continental United States. I cannot be held responsible for problems with email systems anywhere. This is supposed to be for fun, so please don't make a fuss if something goes wrong and your mail doesn't reach me. Find my email elsewhere in this message, and if it's been more than a few days, you're probably too late. From widgets/misc/ChangeLog: 2000-09-18 Christopher James Lahey * Makefile.am: Added $(EXTRA_GNOME_CFLAGS) and $(EXTRA_GNOME_LIBS). Removed unneeded libraries. * e-calendar-item.c, e-calendar.c, e-calendar.h, e-title-bar.c: Fixed the #include lines to deal properly with gal. * e-scroll-frame.c, e-scroll-frame.h: Moved to gal. From widgets/shortcut-bar/ChangeLog: 2000-09-18 Christopher James Lahey * Makefile.am: Added $(EXTRA_GNOME_CFLAGS) and $(EXTRA_GNOME_LIBS). Removed unneeded libraries. * e-icon-bar.c, e-icon-bar.h, e-shortcut-bar.c, e-shortcut-model.c, test-shortcut-bar.c: Fixed the #include lines to deal properly with gal. From widgets/ChangeLog: 2000-09-18 Christopher James Lahey * Makefile.am: Removed directories that have been moved to gal. * e-paned/.cvsignore, e-paned/Makefile.am, e-paned/e-hpaned.c, e-paned/e-hpaned.h, e-paned/e-paned.c, e-paned/e-paned.h, e-paned/e-vpaned.c, e-paned/e-vpaned.h: Moved to gal. * e-reflow/.cvsignore, e-reflow/Makefile.am, e-reflow/e-reflow-sorted.c, e-reflow/e-reflow-sorted.h, e-reflow/e-reflow.c, e-reflow/e-reflow.h: Moved to gal. * e-table/.cvsignore, e-table/ChangeLog, e-table/LICENSE, e-table/Makefile.am, e-table/ROADMAP.e-table, e-table/TODO, e-table/add-col.xpm, e-table/arrow-down.xpm, e-table/arrow-up.xpm, e-table/check-empty.xpm, e-table/check-filled.xpm, e-table/clip.png, e-table/e-cell-checkbox.c, e-table/e-cell-checkbox.h, e-table/e-cell-string.c, e-table/e-cell-text.c, e-table/e-cell-text.h, e-table/e-cell-toggle.c, e-table/e-cell-toggle.h, e-table/e-cell-tree.c, e-table/e-cell-tree.h, e-table/e-cell.c, e-table/e-cell.h, e-table/e-table-click-to-add.c, e-table/e-table-click-to-add.h, e-table/e-table-col-dnd.h, e-table/e-table-col.c, e-table/e-table-col.h, e-table/e-table-column-model.h, e-table/e-table-column.c, e-table/e-table-config.c, e-table/e-table-config.glade, e-table/e-table-config.glade.h, e-table/e-table-config.h, e-table/e-table-defines.h, e-table/e-table-example-1.c, e-table/e-table-example-2.c, e-table/e-table-field-chooser-dialog.c, e-table/e-table-field-chooser-dialog.h, e-table/e-table-field-chooser-item.c, e-table/e-table-field-chooser-item.h, e-table/e-table-field-chooser.c, e-table/e-table-field-chooser.glade, e-table/e-table-field-chooser.glade.h, e-table/e-table-field-chooser.h, e-table/e-table-group-container.c, e-table/e-table-group-container.h, e-table/e-table-group-leaf.c, e-table/e-table-group-leaf.h, e-table/e-table-group.c, e-table/e-table-group.glade, e-table/e-table-group.glade.h, e-table/e-table-group.h, e-table/e-table-header-item.c, e-table/e-table-header-item.h, e-table/e-table-header.c, e-table/e-table-header.h, e-table/e-table-item.c, e-table/e-table-item.h, e-table/e-table-model.c, e-table/e-table-model.h, e-table/e-table-one.c, e-table/e-table-one.h, e-table/e-table-scrolled.c, e-table/e-table-scrolled.h, e-table/e-table-selection-model.c, e-table/e-table-selection-model.h, e-table/e-table-simple.c, e-table/e-table-simple.h, e-table/e-table-size-test.c, e-table/e-table-sort-info.c, e-table/e-table-sort-info.h, e-table/e-table-sorted-variable.c, e-table/e-table-sorted-variable.h, e-table/e-table-sorted.c, e-table/e-table-sorted.h, e-table/e-table-sorter.c, e-table/e-table-sorter.h, e-table/e-table-subset-variable.c, e-table/e-table-subset-variable.h, e-table/e-table-subset.c, e-table/e-table-subset.h, e-table/e-table-text-model.c, e-table/e-table-text-model.h, e-table/e-table-tooltip.h, e-table/e-table-tree.h, e-table/e-table.c, e-table/e-table.h, e-table/e-tree-example-1.c, e-table/e-tree-example-2.c, e-table/e-tree-model.c, e-table/e-tree-model.h, e-table/e-tree-simple.c, e-table/e-tree-simple.h, e-table/image1.png, e-table/image2.png, e-table/image3.png, e-table/remove-col.xpm, e-table/sample.table, e-table/table-test.c, e-table/table-test.h, e-table/test-check.c, e-table/test-cols.c, e-table/test-table.c: Moved to gal. * e-text/.cvsignore, e-text/Makefile.am, e-text/e-entry-test.c, e-text/e-entry.c, e-text/e-entry.h, e-text/e-text-event-processor-emacs-like.c, e-text/e-text-event-processor-emacs-like.h, e-text/e-text-event-processor-types.h, e-text/e-text-event-processor.c, e-text/e-text-event-processor.h, e-text/e-text-model.c, e-text/e-text-model.h, e-text/e-text-test.c, e-text/e-text.c, e-text/e-text.h: Moved to gal. i.e., ... changed evolution to work with gal. svn path=/trunk/; revision=5490 --- e-util/e-font.c | 532 -------------------------------------------------------- 1 file changed, 532 deletions(-) delete mode 100644 e-util/e-font.c (limited to 'e-util/e-font.c') diff --git a/e-util/e-font.c b/e-util/e-font.c deleted file mode 100644 index b33a3bc08d..0000000000 --- a/e-util/e-font.c +++ /dev/null @@ -1,532 +0,0 @@ -#define _E_FONT_C_ - -/* - * e-font - * - * Temporary wrappers around GdkFonts to get unicode displaying - * - * Author: Lauris Kaplinski - * - * Copyright (C) 2000 Helix Code, Inc. - * - * TODO: LRU Cache - * - */ - -#include -#include -#include -#include "e-font.h" - -#define FONT_TESTING - -struct _EFont { - gint refcount; - GdkFont *font; - GdkFont *bold; - gboolean twobyte; - unicode_iconv_t to; - unicode_iconv_t from; -}; - -static gboolean find_variants (gchar **namelist, gint length, - gchar *base_weight, gchar **light, - gchar **bold); - -EFont * -e_font_from_gdk_name (const gchar *name) -{ - EFont * font; - GdkFont *gdkfont; - - gdkfont = gdk_font_load (name); - font = e_font_from_gdk_font (gdkfont); - gdk_font_unref (gdkfont); - - return font; -} - -EFont * -e_font_from_gdk_font (GdkFont *gdkfont) -{ - EFont *font; - XFontStruct *xfs; - Atom font_atom, atom; - Bool status; - GdkFont *boldfont, *lightfont; - - boldfont = lightfont = NULL; - - gdk_font_ref (gdkfont); - - /* Try to find iso-10646-1 encoded font with same name */ - - font_atom = gdk_atom_intern ("FONT", FALSE); - if (gdkfont->type == GDK_FONT_FONTSET) { - XFontStruct **font_structs; - gint num_fonts; - gchar **font_names; - num_fonts = XFontsOfFontSet (GDK_FONT_XFONT (gdkfont), - &font_structs, - &font_names); - status = XGetFontProperty (font_structs[0], - font_atom, - &atom); - } else { - status = XGetFontProperty (GDK_FONT_XFONT (gdkfont), - font_atom, - &atom); - } - if (status) { - gchar *c[14]; - gchar *name, *p; - gchar *enc, *boldname, *lightname; - gchar **namelist; - GdkFont *newfont; - gint numfonts, len, i; - - name = gdk_atom_name (atom); - len = strlen (name) + 64; /* Hope that's sufficent */ - p = name; - - for (i = 0; i < 13; i++) { - c[i] = p; - /* Skip text */ - while (*p && (*p != '-')) p++; - /* Replace hyphen with '\0' */ - if (*p) *p++ = '\0'; - } - c[i] = p; - - p = alloca (len); - - /* Compose name for unicode encoding */ - enc = "iso10646-1"; - g_snprintf (p, len, "%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s", - c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], - c[8], c[9], c[10], c[11], c[12], enc); - /* Try to load unicode font */ - newfont = gdk_font_load (p); - if (newfont) { - /* OK, use that */ - gdk_font_unref (gdkfont); - gdkfont = newfont; - } else { - /* Nope, use original encoding */ - enc = c[13]; - } - /* Try to find bolder variant */ - g_snprintf (p, len, "%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s", - c[0], c[1], c[2], "*", c[4], c[5], "*", "*", - c[8], c[9], c[10], c[11], "*", enc); - namelist = XListFonts (GDK_FONT_XDISPLAY (gdkfont), - p, 32, &numfonts); - if (find_variants (namelist, numfonts, c[3], - &lightname, &boldname)) { - if (!g_strcasecmp (c[3], lightname)) - lightfont = gdkfont; - else if (!g_strcasecmp (c[3], boldname)) - boldfont = gdkfont; - else - gdk_font_unref (gdkfont); - - if (!lightfont) { - g_snprintf (p, len, "%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s", - c[0], c[1], c[2], lightname, c[4], - c[5], "*", "*", c[8], c[9], c[10], - c[11], "*", enc); - lightfont = gdk_font_load (p); - } - if (!boldfont) { - g_snprintf (p, len, "%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s", - c[0], c[1], c[2], boldname, c[4], - c[5], "*", "*", c[8], c[9], c[10], - c[11], "*", enc); - boldfont = gdk_font_load (p); - } - } else - lightfont = gdkfont; - XFreeFontNames (namelist); - - g_free (name); - } - - font = g_new (EFont, 1); - - xfs = GDK_FONT_XFONT (gdkfont); - - font->refcount = 1; - font->font = lightfont; - font->bold = boldfont; - font->twobyte = ((xfs->min_byte1 != 0) || (xfs->max_byte1 != 0)); - font->to = e_uiconv_to_gdk_font (font->font); - font->from = e_uiconv_from_gdk_font (font->font); - - return font; - -} - -void -e_font_ref (EFont *font) -{ - font->refcount++; -} - -void -e_font_unref (EFont *font) -{ - font->refcount--; - - if (font->refcount < 1) { - gdk_font_unref (font->font); - if (font->bold) gdk_font_unref (font->bold); - g_free (font); - } -} - -gint -e_font_ascent (EFont * font) -{ - return font->font->ascent; -} - -gint -e_font_descent (EFont * font) -{ - return font->font->descent; -} - -static gint -e_font_to_native (EFont *font, gchar *native, gchar *utf, gint bytes) -{ - char *ib, *ob; - size_t ibl, obl; - - ib = utf; - ibl = bytes; - ob = native; - obl = bytes * 4; - - while (ibl > 0) { - unicode_iconv (font->to, (const char **) &ib, &ibl, &ob, &obl); - if (ibl > 0) { - gint len; - if ((*ib & 0x80) == 0x00) len = 1; - else if ((*ib &0xe0) == 0xc0) len = 2; - else if ((*ib &0xf0) == 0xe0) len = 3; - else if ((*ib &0xf80) == 0xf0) len = 4; - else { - g_warning ("Invalid UTF-8 sequence"); - return ob - native; - } - ib += len; - ibl = bytes - (ib - utf); - if (ibl > bytes) ibl = 0; - if (!font->twobyte) { - *ob++ = '_'; - obl--; - } else { - *((guint16 *) ob) = '_'; - ob += 2; - obl -= 2; - } - } - } - - return ob - native; -} - -void -e_font_draw_utf8_text (GdkDrawable *drawable, EFont *font, EFontStyle style, GdkGC *gc, gint x, gint y, gchar *text, gint numbytes) -{ - gchar *native; - gint native_bytes; - - g_return_if_fail (drawable != NULL); - g_return_if_fail (font != NULL); - g_return_if_fail (gc != NULL); - g_return_if_fail (text != NULL); - - if (numbytes < 1) return; - - native = alloca (numbytes * 4); - - native_bytes = e_font_to_native (font, native, text, numbytes); - - if ((style & E_FONT_BOLD) && (font->bold)) { - gdk_draw_text (drawable, font->bold, gc, x, y, native, native_bytes); - } else { - gdk_draw_text (drawable, font->font, gc, x, y, native, native_bytes); - if (style & E_FONT_BOLD) - gdk_draw_text (drawable, font->font, gc, x + 1, y, native, native_bytes); - } -} - -gint -e_font_utf8_text_width (EFont *font, EFontStyle style, char *text, int numbytes) -{ - gchar *native; - gint native_bytes; - gint width; - - g_return_val_if_fail (font != NULL, 0); - g_return_val_if_fail (text != NULL, 0); - - if (numbytes < 1) return 0; - - native = alloca (numbytes * 4); - - native_bytes = e_font_to_native (font, native, text, numbytes); - - if ((style & E_FONT_BOLD) && (font->bold)) { - width = gdk_text_width (font->bold, native, native_bytes); - } else { - width = gdk_text_width (font->font, native, native_bytes); - } - - return width; -} - -gint -e_font_utf8_char_width (EFont *font, EFontStyle style, char *text) -{ - gint len; - - g_return_val_if_fail (font != NULL, 0); - g_return_val_if_fail (text != NULL, 0); - - if ((*text & 0x80) == 0x00) len = 1; - else if ((*text &0xe0) == 0xc0) len = 2; - else if ((*text &0xf0) == 0xe0) len = 3; - else if ((*text &0xf80) == 0xf0) len = 4; - else { - g_warning ("Invalid UTF-8 sequence"); - return 0; - } - - return e_font_utf8_text_width (font, style, text, len); -} - -static const gchar * -translate_encoding (const gchar *encoding) -{ - static GHashTable *eh = NULL; - gchar e[64]; - - if (!eh) { - eh = g_hash_table_new (g_str_hash, g_str_equal); - - g_hash_table_insert (eh, "iso8859-1", "iso-8859-1"); - g_hash_table_insert (eh, "iso8859-2", "iso-8859-2"); - g_hash_table_insert (eh, "iso8859-3", "iso-8859-3"); - g_hash_table_insert (eh, "iso8859-4", "iso-8859-4"); - g_hash_table_insert (eh, "iso8859-5", "iso-8859-5"); - g_hash_table_insert (eh, "iso8859-6", "iso-8859-6"); - g_hash_table_insert (eh, "iso8859-7", "iso-8859-7"); - g_hash_table_insert (eh, "iso8859-8", "iso-8859-8"); - g_hash_table_insert (eh, "iso8859-9", "iso-8859-9"); - g_hash_table_insert (eh, "iso8859-10", "iso-8859-10"); - g_hash_table_insert (eh, "iso8859-13", "iso-8859-13"); - g_hash_table_insert (eh, "iso8859-14", "iso-8859-14"); - g_hash_table_insert (eh, "iso8859-15", "iso-8859-15"); - g_hash_table_insert (eh, "iso10646-1", "UTF-16"); - g_hash_table_insert (eh, "koi8-r", "koi8-r"); - } - - strncpy (e, encoding, 64); - g_strdown (e); - - return g_hash_table_lookup (eh, e); -} - -const gchar * -e_gdk_font_encoding (GdkFont *font) -{ - Atom font_atom, atom; - Bool status; - char *name, *p; - const gchar *encoding; - gint i; - - if (!font) return NULL; - - font_atom = gdk_atom_intern ("FONT", FALSE); - - if (font->type == GDK_FONT_FONTSET) { - XFontStruct **font_structs; - gint num_fonts; - gchar **font_names; - - num_fonts = XFontsOfFontSet (GDK_FONT_XFONT (font), - &font_structs, - &font_names); - status = XGetFontProperty (font_structs[0], - font_atom, - &atom); - } else { - status = XGetFontProperty (GDK_FONT_XFONT (font), - font_atom, - &atom); - } - - if (!status) return NULL; - - name = p = gdk_atom_name (atom); - - for (i = 0; i < 13; i++) { - /* Skip hyphen */ - while (*p && (*p != '-')) p++; - if (*p) p++; - } - - if (!*p) return NULL; - - encoding = translate_encoding (p); - - g_free (name); - - return encoding; -} - -unicode_iconv_t -e_uiconv_from_gdk_font (GdkFont *font) -{ - static GHashTable *uh = NULL; - const gchar *enc; - unicode_iconv_t uiconv; - - if (!font) return (unicode_iconv_t) -1; - - enc = e_gdk_font_encoding (font); - - if (!enc) return (unicode_iconv_t) -1; - - if (!uh) uh = g_hash_table_new (g_str_hash, g_str_equal); - - uiconv = g_hash_table_lookup (uh, enc); - - if (!uiconv) { - uiconv = unicode_iconv_open ("UTF-8", enc); - if (uiconv == (unicode_iconv_t) -1) return uiconv; - g_hash_table_insert (uh, (gpointer) enc, uiconv); - } - - return uiconv; -} - -unicode_iconv_t -e_uiconv_to_gdk_font (GdkFont *font) -{ - static GHashTable *uh = NULL; - const gchar *enc; - unicode_iconv_t uiconv; - - if (!font) return (unicode_iconv_t) -1; - - enc = e_gdk_font_encoding (font); - - if (!enc) return (unicode_iconv_t) -1; - - if (!uh) uh = g_hash_table_new (g_str_hash, g_str_equal); - - uiconv = g_hash_table_lookup (uh, enc); - - if (!uiconv) { - uiconv = unicode_iconv_open (enc, "UTF-8"); - if (uiconv == (unicode_iconv_t) -1) return uiconv; - g_hash_table_insert (uh, (gpointer) enc, uiconv); - } - - return uiconv; -} - -/* Find light and bold variants of a font, ideally using the provided - * weight for the light variant, and a weight 2 shades darker than it - * for the bold variant. If there isn't something 2 shades darker, use - * something 3 or more shades darker if it exists, or 1 shade darker - * if that's all there is. If there is nothing darker than the provided - * weight, but there are lighter fonts, then use the darker one for - * bold and a lighter one for light. - */ -static gboolean -find_variants (gchar **namelist, gint length, gchar *weight, - gchar **lightname, gchar **boldname) -{ - static GHashTable *wh = NULL; - /* Standard, Found, Bold, Light */ - gint sw, fw, bw, lw; - gchar *s, *f, *b, *l; - gchar *p; - gint i; - - if (!wh) { - wh = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_insert (wh, "light", GINT_TO_POINTER (1)); - g_hash_table_insert (wh, "book", GINT_TO_POINTER (2)); - g_hash_table_insert (wh, "regular", GINT_TO_POINTER (2)); - g_hash_table_insert (wh, "medium", GINT_TO_POINTER (3)); - g_hash_table_insert (wh, "demibold", GINT_TO_POINTER (5)); - g_hash_table_insert (wh, "bold", GINT_TO_POINTER (6)); - g_hash_table_insert (wh, "black", GINT_TO_POINTER (8)); - } - - s = alloca (strlen (weight) + 1); - strcpy (s, weight); - g_strdown (s); - sw = GPOINTER_TO_INT (g_hash_table_lookup (wh, s)); - if (sw == 0) return FALSE; - - fw = 0; lw = 0; bw = 32; - f = NULL; l = NULL; b = NULL; - *lightname = NULL; *boldname = NULL; - - for (i = 0; i < length; i++) { - p = namelist[i]; - if (*p) p++; - while (*p && (*p != '-')) p++; - if (*p) p++; - while (*p && (*p != '-')) p++; - if (*p) p++; - f = p; - while (*p && (*p != '-')) p++; - if (*p) *p = '\0'; - g_strdown (f); - fw = GPOINTER_TO_INT (g_hash_table_lookup (wh, f)); - if (fw) { - if (fw > sw) { - if ((fw - 2 == sw) || - ((fw > bw) && (bw == sw + 1)) || - ((fw < bw) && (fw - 2 > sw))) { - bw = fw; - b = f; - } - } else if (fw < sw) { - if ((fw + 2 == sw) || - ((fw < lw) && (lw == sw - 1)) || - ((fw > lw) && (fw + 2 < sw))) { - lw = fw; - l = f; - } - } - } - } - - if (b) { - *lightname = weight; - *boldname = b; - return TRUE; - } else if (l) { - *lightname = l; - *boldname = weight; - return TRUE; - } - return FALSE; -} - - - - - - - - -- cgit v1.2.3