summaryrefslogtreecommitdiff
path: root/pango-view
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2009-03-14 21:33:07 -0400
committerBehdad Esfahbod <behdad@behdad.org>2009-03-14 21:33:07 -0400
commitdf05d117a5c168fb90138d7d6bae760c1b2851af (patch)
tree128d53734e16723adbdee38762f9f5d57c9c5c1c /pango-view
parent3310b979c486e38182d89132d6b6b3e3d7ffb728 (diff)
downloadpango-df05d117a5c168fb90138d7d6bae760c1b2851af.tar.gz
Bug 523166 – pango-view opens display even when invoked with -q
Works now.
Diffstat (limited to 'pango-view')
-rw-r--r--pango-view/viewer-cairo.c85
-rw-r--r--pango-view/viewer-cairo.h2
-rw-r--r--pango-view/viewer-main.c12
-rw-r--r--pango-view/viewer-pangocairo.c6
-rw-r--r--pango-view/viewer-x.c4
-rw-r--r--pango-view/viewer.h1
6 files changed, 93 insertions, 17 deletions
diff --git a/pango-view/viewer-cairo.c b/pango-view/viewer-cairo.c
index eb56d455..0f3cd5ca 100644
--- a/pango-view/viewer-cairo.c
+++ b/pango-view/viewer-cairo.c
@@ -21,16 +21,21 @@
#include "config.h"
#include "viewer-cairo.h"
+#include "viewer-render.h"
+
+#include <cairo.h>
+
+
#ifdef HAVE_CAIRO_XLIB
#include "viewer-x.h"
#include <cairo-xlib.h>
static cairo_surface_t *
-cairo_x_view_create_surface (gpointer instance,
- gpointer surface,
- int width,
- int height)
+cairo_x_view_iface_create_surface (gpointer instance,
+ gpointer surface,
+ int width,
+ int height)
{
XViewer *x = (XViewer *)instance;
Drawable drawable = (Drawable) surface;
@@ -42,12 +47,76 @@ cairo_x_view_create_surface (gpointer instance,
static CairoViewerIface cairo_x_viewer_iface = {
&x_viewer,
- cairo_x_view_create_surface
+ cairo_x_view_iface_create_surface
};
+#endif /* HAVE_CAIRO_XLIB */
-const CairoViewerIface *
-get_default_cairo_viewer_iface (void)
+
+
+static gpointer
+cairo_image_view_create (const PangoViewer *klass G_GNUC_UNUSED)
+{
+ return NULL;
+}
+
+static void
+cairo_image_view_destroy (gpointer instance G_GNUC_UNUSED)
+{
+}
+
+static gpointer
+cairo_image_view_create_surface (gpointer instance,
+ int width,
+ int height)
+{
+ /* TODO: Be smarter about format? */
+ return cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+}
+
+static void
+cairo_image_view_destroy_surface (gpointer instance,
+ gpointer surface)
+{
+ cairo_surface_destroy (surface);
+}
+
+const PangoViewer cairo_image_viewer = {
+ "CairoImage",
+ NULL,
+ NULL,
+ cairo_image_view_create,
+ cairo_image_view_destroy,
+ NULL,
+ cairo_image_view_create_surface,
+ cairo_image_view_destroy_surface,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+static cairo_surface_t *
+cairo_image_view_iface_create_surface (gpointer instance,
+ gpointer surface,
+ int width,
+ int height)
{
- return &cairo_x_viewer_iface;
+ return surface;
}
+
+static CairoViewerIface cairo_image_viewer_iface = {
+ &cairo_image_viewer,
+ cairo_image_view_iface_create_surface
+};
+
+const CairoViewerIface *
+get_cairo_viewer_iface (void)
+{
+#ifdef HAVE_CAIRO_XLIB
+ if (opt_display)
+ return &cairo_x_viewer_iface;
#endif /* HAVE_CAIRO_XLIB */
+
+ return &cairo_image_viewer_iface;
+}
diff --git a/pango-view/viewer-cairo.h b/pango-view/viewer-cairo.h
index ba5a5d7c..7e6d9ae3 100644
--- a/pango-view/viewer-cairo.h
+++ b/pango-view/viewer-cairo.h
@@ -37,6 +37,6 @@ struct _CairoViewerIface
int height);
};
-const CairoViewerIface *get_default_cairo_viewer_iface (void);
+const CairoViewerIface *get_cairo_viewer_iface (void);
#endif /* VIEWER_CAIRO_H */
diff --git a/pango-view/viewer-main.c b/pango-view/viewer-main.c
index 2b664682..611a4fb8 100644
--- a/pango-view/viewer-main.c
+++ b/pango-view/viewer-main.c
@@ -118,8 +118,13 @@ main (int argc,
gpointer state = NULL;
if (view->create_window)
- window = view->create_window (instance, title, width, height);
+ {
+ window = view->create_window (instance, title, width, height);
+ if (!window)
+ goto no_display;
+ }
+ opt_display = FALSE;
while (1)
{
state = view->display (instance, surface, window, width, height, state);
@@ -132,7 +137,10 @@ main (int argc,
if (view->destroy_window)
view->destroy_window (instance, window);
}
- else
+no_display:
+
+ /* If failed to display natively, call ImageMagick */
+ if (opt_display)
{
int fd;
FILE *stream;
diff --git a/pango-view/viewer-pangocairo.c b/pango-view/viewer-pangocairo.c
index 45c03df0..84756279 100644
--- a/pango-view/viewer-pangocairo.c
+++ b/pango-view/viewer-pangocairo.c
@@ -36,7 +36,6 @@ typedef struct
cairo_font_options_t *font_options;
} CairoViewer;
-/* TODO: hinting */
static gpointer
pangocairo_view_create (const PangoViewer *klass G_GNUC_UNUSED)
{
@@ -44,7 +43,7 @@ pangocairo_view_create (const PangoViewer *klass G_GNUC_UNUSED)
instance = g_slice_new (CairoViewer);
- instance->iface = get_default_cairo_viewer_iface ();
+ instance->iface = get_cairo_viewer_iface ();
instance->backend = instance->iface->backend_class->create (instance->iface->backend_class);
instance->fontmap = pango_cairo_font_map_new ();
@@ -364,6 +363,9 @@ pangocairo_view_create_window (gpointer instance,
{
CairoViewer *c = (CairoViewer *) instance;
+ if (!c->iface->backend_class->create_window)
+ return NULL;
+
return c->iface->backend_class->create_window (c->backend,
title,
width, height);
diff --git a/pango-view/viewer-x.c b/pango-view/viewer-x.c
index 58f1c592..25492f33 100644
--- a/pango-view/viewer-x.c
+++ b/pango-view/viewer-x.c
@@ -32,7 +32,7 @@ x_view_init (gpointer instance,
x->display = XOpenDisplay (NULL);
if (!x->display)
- fail ("Cannot open display %s\n", XDisplayName (NULL));
+ fail ("Cannot open display %s", XDisplayName (NULL));
x->screen = DefaultScreen (x->display);
}
@@ -237,5 +237,3 @@ const PangoViewer x_viewer = {
x_view_destroy_window,
x_view_display
};
-
-const PangoViewer *fallback_viewer = &x_viewer;
diff --git a/pango-view/viewer.h b/pango-view/viewer.h
index 20fbdbe0..055ca58f 100644
--- a/pango-view/viewer.h
+++ b/pango-view/viewer.h
@@ -93,7 +93,6 @@ struct _PangoViewer {
};
-extern const PangoViewer *fallback_viewer;
extern const PangoViewer *viewers[];
#endif /* VIEWER_H */