X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=ps%2Fggvutils.c;h=bea0412f0c2059f1d1024af807b8992a85f5c70f;hb=ca09e13c4411410140f24c9a0de61527685c9719;hp=c79ec041183e78f6caa230e701069d523345ccd9;hpb=fb1055dd92e9aa1173de92add6f4a6f5e4a62d2d;p=evince.git diff --git a/ps/ggvutils.c b/ps/ggvutils.c index c79ec041..bea0412f 100644 --- a/ps/ggvutils.c +++ b/ps/ggvutils.c @@ -21,23 +21,12 @@ */ #include "config.h" -#include -#include -#include - -#include -#include -#include +#include #include #include "ggvutils.h" -typedef struct { - char *stock_id; - char *name; -} GgvStockIcon; - GtkGSPaperSize ggv_paper_sizes[] = { {N_("BBox"), 0, 0}, {N_("Letter"), 612, 792,}, @@ -60,13 +49,6 @@ GtkGSPaperSize ggv_paper_sizes[] = { {NULL, 0, 0} }; -const gfloat ggv_unit_factors[] = { - 1.0, - 25.4, - 2.54, - 72.0 -}; - const gchar *ggv_orientation_labels[] = { N_("Portrait"), N_("Landscape"), @@ -75,20 +57,6 @@ const gchar *ggv_orientation_labels[] = { NULL, }; -const gint ggv_max_orientation_labels = - (sizeof(ggv_orientation_labels) / sizeof(gchar *)) - 2; - -const gchar *ggv_unit_labels[] = { - N_("inch"), - N_("mm"), - N_("cm"), - N_("point"), - NULL -}; - -const gint ggv_max_unit_labels = - (sizeof(ggv_unit_labels) / sizeof(gchar *)) - 2; - gfloat ggv_zoom_levels[] = { 1.0 / 6.0, 1.0 / 5.0, 1.0 / 4.0, 1.0 / 3.0, 1.0 / 2.0, 3.0 / 4.0, 1.0, 3.0 / 2.0, 2.0, 3.0, 4.0, 5.0, 6.0 @@ -103,136 +71,6 @@ const gchar *ggv_zoom_level_names[] = { const gint ggv_max_zoom_levels = (sizeof(ggv_zoom_levels) / sizeof(gfloat)) - 1; -const gchar *ggv_auto_fit_modes[] = { - N_("None"), N_("Fit to page width"), N_("Fit to page size") -}; - -const gint ggv_max_auto_fit_modes = - (sizeof(ggv_auto_fit_modes) / sizeof(gchar *)) - 1; - -gint -ggv_zoom_index_from_float(gfloat zoom_level) -{ - int i; - - for(i = 0; i <= ggv_max_zoom_levels; i++) { - float this, epsilon; - - /* if we're close to a zoom level */ - this = ggv_zoom_levels[i]; - epsilon = this * 0.01; - - if(zoom_level < this + epsilon) - return i; - } - - return ggv_max_zoom_levels; -} - -gfloat -ggv_zoom_level_from_index(gint index) -{ - if(index > ggv_max_zoom_levels) - index = ggv_max_zoom_levels; - - return ggv_zoom_levels[index]; -} - -GSList * -ggv_split_string(const gchar * string, const gchar * delimiter) -{ - const gchar *ptr = string; - int pos = 0, escape = 0; - char buffer[BUFSIZ]; - GSList *list = NULL; - - g_return_val_if_fail(string != NULL, NULL); - g_return_val_if_fail(delimiter != NULL, NULL); - - while(*ptr) { - char c = *ptr++; - const gchar *d; - int found = 0; - - if(pos >= BUFSIZ) { - g_warning("string too long, aborting"); - return list; - } - - if(escape) { - buffer[pos++] = c; - escape = 0; - continue; - } - - if(c == '\\') { - escape = 1; - continue; - } - - for(d = delimiter; *d; d++) { - if(c == *d) { - buffer[pos++] = 0; - list = g_slist_prepend(list, g_strdup(buffer)); - pos = 0; - found = 1; - break; - } - } - - if(!found) - buffer[pos++] = c; - } - - buffer[pos++] = 0; - list = g_slist_prepend(list, g_strdup(buffer)); - - return list; -} - -gint -ggv_get_index_of_string(gchar * string, gchar ** strings) -{ - guint idx = 0; - - while(strings[idx] != NULL) { - if(strcmp(strings[idx], string) == 0) - return idx; - idx++; - } - - return -1; -} - -/* Quote filename for system call */ -gchar * -ggv_quote_filename(const gchar * str) -{ - return g_shell_quote(str); -} - -/* escapes filename to form a proper URI: works conservatively - anything - except [a-zA-Z0-9_] will be escaped with a %XX escape sequence where - XX is the hex value of the char. */ -gchar * -ggv_filename_to_uri(const gchar * fname) -{ - gchar *full_path, *ret_val; - - if(*fname != '/') { - gchar *cwd; - /* relative file name - we will have to absolutize it */ - cwd = g_get_current_dir(); - full_path = g_strconcat(cwd, "/", fname, NULL); - } - else - full_path = NULL; - ret_val = gnome_vfs_get_uri_from_local_path(full_path ? full_path : fname); - if(full_path) - g_free(full_path); - return ret_val; -} - /* If file exists and is a regular file then return its length, else -1 */ gint ggv_file_length(const gchar * filename) @@ -252,97 +90,3 @@ ggv_file_readable(const char *filename) { return (ggv_file_length(filename) > 0); } - -/* Set a tooltip for a widget */ -void -ggv_set_tooltip(GtkWidget * w, const gchar * tip) -{ - GtkTooltips *t = gtk_tooltips_new(); - - gtk_tooltips_set_tip(t, w, tip, NULL); -} - -gfloat -ggv_compute_zoom(gint zoom_spec) -{ - return pow(1.2, zoom_spec); /* The Knuth magstep formula rules */ -} - -gint -ggv_compute_spec(gfloat zoom) -{ - zoom = MAX(0.02, zoom); - zoom = MIN(10.0, zoom); - - zoom = log(zoom) / log(1.2); - return (gint) rint(zoom); -} - -void -ggv_raise_and_focus_widget(GtkWidget * widget) -{ - g_assert(GTK_WIDGET_REALIZED(widget)); - gdk_window_raise(widget->window); - gtk_widget_grab_focus(widget); -} - -void -ggv_get_window_size(GtkWidget * widget, gint * width, gint * height) -{ - *width = widget->allocation.width; - *height = widget->allocation.height; -} - -static GgvStockIcon items[] = { - {GGV_CLEAR_ALL, GNOMEICONDIR "/ggv/clearall.xpm"}, - {GGV_TOGGLE_ALL, GNOMEICONDIR "/ggv/toggleall.xpm"}, - {GGV_TOGGLE_EVEN, GNOMEICONDIR "/ggv/toggleeven.xpm"}, - {GGV_TOGGLE_ODD, GNOMEICONDIR "/ggv/toggleodd.xpm"}, - {GGV_FIT_WIDTH, GNOMEICONDIR "/ggv/fitwidth.png"}, - {GGV_ZOOM, GNOMEICONDIR "/ggv/zoom.xpm"} -}; - -static void -ggv_register_stock_icons(GtkIconFactory * factory) -{ - gint i; - GtkIconSource *source; - - source = gtk_icon_source_new(); - - for(i = 0; i < G_N_ELEMENTS(items); ++i) { - GtkIconSet *icon_set; - - if(!g_file_test(items[i].name, G_FILE_TEST_EXISTS)) { - g_warning(_("Unable to load ggv stock icon '%s'\n"), items[i].name); - icon_set = gtk_icon_factory_lookup_default(GTK_STOCK_MISSING_IMAGE); - gtk_icon_factory_add(factory, items[i].stock_id, icon_set); - continue; - } - - gtk_icon_source_set_filename(source, items[i].name); - - icon_set = gtk_icon_set_new(); - gtk_icon_set_add_source(icon_set, source); - gtk_icon_factory_add(factory, items[i].stock_id, icon_set); - gtk_icon_set_unref(icon_set); - } - gtk_icon_source_free(source); -} - -void -ggv_init_stock_icons(void) -{ - GtkIconFactory *factory; - static gboolean initialized = FALSE; - - if(initialized) - return; - initialized = TRUE; - - factory = gtk_icon_factory_new(); - gtk_icon_factory_add_default(factory); - ggv_register_stock_icons(factory); - - g_object_unref(factory); -}