From: <ai...@us...> - 2009-09-23 14:14:03
|
Revision: 10461 http://plplot.svn.sourceforge.net/plplot/?rev=10461&view=rev Author: airwin Date: 2009-09-23 14:13:53 +0000 (Wed, 23 Sep 2009) Log Message: ----------- Massive commit to delete old, unused code from svn trunk as discussed on list. All these legacy files are preserved in tags/v_5_9_5 and many previous releases. Removed Paths: ------------- trunk/drivers/gnome.c trunk/drivers/next.c trunk/drivers/xwinttf.c trunk/old/ trunk/sys/dos/bcc/ trunk/sys/dos/emx/ trunk/sys/dos/msc/ trunk/sys/mac/ trunk/sys/os2/ trunk/sys/unix/ trunk/sys/win32/ Deleted: trunk/drivers/gnome.c =================================================================== --- trunk/drivers/gnome.c 2009-09-23 13:16:55 UTC (rev 10460) +++ trunk/drivers/gnome.c 2009-09-23 14:13:53 UTC (rev 10461) @@ -1,1441 +0,0 @@ -/* $Id$ - - PLplot GnomeCanvas device driver. - - Copyright (C) 2004 Rafael Laboissiere - - This file is part of PLplot. - - PLplot is free software; you can redistribute it and/or modify - it under the terms of the GNU General Library Public License as published - by the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - PLplot is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with PLplot; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include "plDevs.h" - -#ifdef PLD_gnome - -#include "plplotP.h" -#include "drivers.h" - -#include <gtk/gtk.h> -#include <glib.h> -#include <pthread.h> -#include <math.h> - -#include <gnome.h> - -#include <unistd.h> - -/* Device info */ -PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_gnome = "gnome:Gnome Canvas:1:gnome:6:gnome\n"; - -/*#undef DEBUG*/ -#define DEBUG - -#undef ANTIALISED_CANVAS - -/* Physical dimensions */ - -/* Unit of drawing (1/360 in). Corresponds to the pen widht = 1 */ -#define DRAWING_UNIT (0.0027777778) - -/* How many pixels in a drawing unit (defualt value) */ -#define PIXELS_PER_DU (0.2) - -/* mm per inch */ -#define MM_PER_IN (25.4) - -/* pixels per mm */ -#define PIXELS_PER_MM (PIXELS_PER_DU / DRAWING_UNIT / MM_PER_IN) - -/* Default dimensions of the canvas (in inches) */ -#define WIDTH (9) -#define HEIGHT (6.5) - -/* Magnification factor for the PLplot physical dimensions */ -#define MAG_FACTOR 10 - -#define BUFFER_LEN 128 - -#ifndef ABS -#define ABS(x) ((x < 0) ? (-(x)) : (x)) -#endif - -void -debug (char* msg) -{ -#ifdef DEBUG - printf (msg); - fflush (stdout); -#endif -} - -G_LOCK_DEFINE_STATIC (canvas); - -static pthread_t tid; - -static guint gnome_is_initialized = FALSE; - -/*// FIXME : Terrible global variable hack*/ -static GtkStatusbar* sb; - -typedef enum { - GNOME_PLDEV_LOCATE_MODE, - GNOME_PLDEV_ZOOM_MODE, - GNOME_PLDEV_NONE_MODE -} GnomePLdevCanvasMode; - -typedef struct { - guint cmap; - gdouble color; -} ItemColor; - -typedef struct { - GtkScrolledWindow* sw; - GnomeCanvas* canvas; - GnomePLdevCanvasMode mode; - GnomeCanvasItem* hlocline; - double hpos; - GnomeCanvasItem* vlocline; - double vpos; - GnomeCanvasItem* zoomrect; - PLGraphicsIn gin; - guint context; - GtkAdjustment* hadj; - GtkAdjustment* vadj; - double width; - double height; - double ppu; - short bufx[1024]; - short bufy[1024]; - guint bufc; - PLINT curcolor; - PLINT curwidth; -} GnomePLdevPage; - -typedef struct { - GtkWidget* parent; - GtkWidget* root; - GtkNotebook* notebook; - GtkStatusbar* statusbar; - guint npages; - GnomePLdevPage** page; - guint parent_is_from_driver; - PLINT pattern; - GdkBitmap* pattern_stipple[2]; -} GnomePLdev; - -void -gnome_pldev_adopt (PLStream* pls, GtkContainer* parent) -{ - GnomePLdev* dev = pls->dev; - GtkWidget* root; - - if (dev->parent_is_from_driver) { - root = dev->root; - gtk_object_ref (GTK_OBJECT (root)); - gtk_container_remove (GTK_CONTAINER (dev->parent), root); - gtk_widget_destroy (dev->parent); - dev->parent_is_from_driver = FALSE; - } - gtk_container_add (parent, root); - dev->parent = GTK_WIDGET (parent); - gtk_object_unref (GTK_OBJECT (root)); -} - -static guint timeout_id; - -static gint -canvas_timeout (gpointer dev) -{ - guint i; - - for (i = 0; i < ((GnomePLdev*) dev)->npages ; i++) - ((GnomePLdev*) dev)->page[i]->canvas->need_update = TRUE; - - return FALSE; -} - -static void -timeout_register (GnomeCanvas* canvas, GnomePLdev* dev) -{ - /*// gtk_timeout_remove (timeout_id);*/ - /*// canvas->need_update = FALSE;*/ - /*// timeout_id = gtk_timeout_add (100, canvas_timeout, dev);*/ -} - -static -void change_mode (GnomePLdevPage* page, GnomePLdevCanvasMode mode) -{ - guint context = page->context; - - page->mode = mode; - - switch (mode) { - case GNOME_PLDEV_LOCATE_MODE: - /*// FIXME : Terrible global variable hack*/ - gtk_statusbar_pop (sb, context); - /*// FIXME : Terrible global variable hack*/ - gtk_statusbar_push (sb, context, "Locate Mode"); - break; - case GNOME_PLDEV_ZOOM_MODE: - /*// FIXME : Terrible global variable hack*/ - gtk_statusbar_pop (sb, context); - /*// FIXME : Terrible global variable hack*/ - gtk_statusbar_push (sb, context, "Zoom Mode"); - break; - default: - break; - } -} - -static -void *init(void *args) -{ - gdk_threads_enter(); - gtk_main(); - gdk_threads_leave (); - pthread_exit(NULL); -} - -static gboolean -quit_dialog (void) -{ - GtkWidget* dialog; - gint answer; - - fflush (stderr); - - dialog = gnome_dialog_new ("PLplot Gnome driver", - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, - NULL); - - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), - gtk_label_new ("Quit PLplot?"), - TRUE, - TRUE, - 0); - - gtk_widget_show_all (GTK_WIDGET (GNOME_DIALOG (dialog)->vbox)); - - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - gnome_dialog_set_default (GNOME_DIALOG (dialog), 0); - - answer = gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); - - if (answer == 0) { - return TRUE; - } - else - return FALSE; -} - -static gint -canvas_pressed_cb(GnomeCanvasItem *item, GdkEvent *event, - GnomePLdevPage* page) -{ - static guint dragging; - guint move; - GdkCursor *cursor; - char buffer[BUFFER_LEN]; - PLGraphicsIn* gin = &(page->gin); - ItemColor* color; - GnomeCanvasItem* item_at_cursor; - - move = FALSE; - - switch (event->type) { - - case GDK_2BUTTON_PRESS: - - case GDK_3BUTTON_PRESS: - - case GDK_BUTTON_PRESS: - - if (event->button.button == 1) { - - gnome_canvas_item_raise_to_top (page->hlocline); - gnome_canvas_item_raise_to_top (page->vlocline); - - move = TRUE; - - cursor = gdk_cursor_new (GDK_CROSSHAIR); - gnome_canvas_item_grab(item, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, - cursor, - event->button.time); - gdk_cursor_destroy(cursor); - - /*// FIXME : Terrible global variable hack*/ - gtk_statusbar_push (sb, page->context, ""); - - dragging = TRUE; - } - break; - - case GDK_MOTION_NOTIFY: - if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) - move = TRUE; - break; - - case GDK_BUTTON_RELEASE: - if (dragging && (event->motion.state & GDK_BUTTON1_MASK)) { - gnome_canvas_item_ungrab(item, event->button.time); - dragging = FALSE; - gnome_canvas_item_hide (page->hlocline); - gnome_canvas_item_hide (page->vlocline); - /*// FIXME : Terrible global variable hack*/ - gtk_statusbar_pop (sb, page->context); - /*// printf ("Button release\n");*/ - /*// fflush (stdout);*/ - } - break; - - default: - /*// printf ("Other event\n");*/ - /*// fflush (stdout);*/ - break; - - } - - if (move) { - - gnome_canvas_item_hide (page->hlocline); - gnome_canvas_item_hide (page->vlocline); - - item_at_cursor = gnome_canvas_get_item_at (page->canvas, - event->button.x, - event->button.y); - - if (item_at_cursor != NULL) - color = (ItemColor *) gtk_object_get_data (GTK_OBJECT (item_at_cursor), - "color"); - else - color = NULL; - - gnome_canvas_item_show (page->hlocline); - gnome_canvas_item_show (page->vlocline); - - gnome_canvas_item_move (page->hlocline, - 0.0, event->button.y - page->vpos); - page->vpos = event->button.y; - - gnome_canvas_item_move (page->vlocline, - event->button.x - page->hpos, 0.0); - page->hpos = event->button.x; - - gin->dX = page->hpos / page->width; - gin->dY = page->vpos / (- page->height); - - plTranslateCursor (gin); - - if (color == NULL) - buffer[0] = '\0'; - else - if (color->cmap == 0) - snprintf (buffer, BUFFER_LEN, " x = %f y = %f color = %d (cmap0)", - gin->wX, gin->wY, (int) color->color); - else - snprintf (buffer, BUFFER_LEN, " x = %f y = %f color = %f (cmap1)", - gin->wX, gin->wY, color->color); - - /*// FIXME : Terrible global variable hack*/ - gtk_statusbar_pop (sb, page->context); - /*// FIXME : Terrible global variable hack*/ - gtk_statusbar_push (sb, page->context, buffer); - - } - - return TRUE; -} - - -static gint -delete_event_cb (GtkWidget* widget, GdkEventAny* e, gpointer data) -{ - if (quit_dialog () == TRUE) { - gtk_widget_destroy (widget); - gtk_main_quit (); - } - return TRUE; -} - - -static gint -item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - switch (event->type) { - case GDK_BUTTON_PRESS: - break; - } - - return TRUE; -} - -static void -setup_item(GnomeCanvasItem *item) -{ - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) canvas_pressed_cb, - NULL); -} - -static void -add_to_adj (GtkAdjustment* adj, gfloat add) -{ - gfloat value; - - value = adj->value + add; - gtk_adjustment_set_value (adj, value); -} - -static gint -key_cb (GtkWidget* widget, GdkEventKey* event, PLStream* pls) -{ - GnomePLdev* dev = pls->dev; - GnomePLdevPage* page; - GtkNotebook* notebook = dev->notebook; - GtkStatusbar* statusbar = dev->statusbar; - guint curpage; - - if (notebook != NULL) - curpage = gtk_notebook_get_current_page (notebook); - else - curpage = 0; - - page = dev->page[curpage]; - - switch (event->keyval) { - case GDK_minus: - case GDK_plus: - case GDK_equal: - switch (event->keyval) { - case GDK_minus: - page->ppu /= 1.4142; - break; - case GDK_plus: - case GDK_equal: - page->ppu *= 1.4142; - break; - } - gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (widget), page->ppu); - break; - case GDK_Q: - case GDK_Return: - if (quit_dialog () == TRUE) - gtk_main_quit (); - break; - case GDK_l: - /*//gdk_threads_enter ();*/ - change_mode (page, GNOME_PLDEV_LOCATE_MODE); - /*//gdk_threads_leave ();*/ - break; - case GDK_z: - /*//gdk_threads_enter ();*/ - change_mode (page, GNOME_PLDEV_ZOOM_MODE); - /*//gdk_threads_leave ();*/ - break; - case GDK_Page_Up: - if (curpage != 0) - gtk_notebook_set_page (notebook, curpage - 1); - break; - case GDK_Page_Down: - gtk_notebook_set_page (notebook, curpage + 1); - break; - case GDK_Right: - case GDK_Left: - case GDK_Up: - case GDK_Down: - switch (event->keyval) { - case GDK_Right: - add_to_adj (page->hadj, page->ppu); - break; - case GDK_Left: - add_to_adj (page->hadj, -page->ppu); - break; - case GDK_Up: - add_to_adj (page->vadj, page->ppu); - break; - case GDK_Down: - add_to_adj (page->vadj, -page->ppu); - break; - } - page->hadj->step_increment = page->ppu; - page->hadj->step_increment = page->ppu; - gtk_adjustment_changed (page->hadj); - gtk_adjustment_changed (page->vadj); - break; - default: - break; - } - - return TRUE; -} - -static void -page_switch (GtkNotebook *notebook, GtkNotebookPage *page, gint page_num, - gpointer dev) -{ - guint curpage; - GnomeCanvas* canvas; - - canvas = ((GnomePLdev*)(dev))->page[page_num]->canvas; - if (canvas != NULL) - gtk_widget_grab_focus (GTK_WIDGET (canvas)); -} - -static guint32 -plcolor_to_rgba (PLColor color, guchar alpha) -{ - return - ((int)(color.r) << 24) - + ((int)(color.g) << 16) - + ((int)(color.b) << 8) - + alpha; -} - -static guint32 -plcolor_to_rgba_inv (PLColor color, guchar alpha) -{ - return - ((int)(255 - color.r) << 24) - + ((int)(255 - color.g) << 16) - + ((int)(255 - color.b) << 8) - + alpha; -} - -static void -set_color (GnomeCanvasItem* item, guint cmap, gdouble color) -{ - ItemColor* colorp; - - colorp = g_malloc (sizeof (ItemColor)); - colorp->cmap = cmap; - colorp->color = color; - - gtk_object_set_data (GTK_OBJECT (item), "color", colorp); -} - -static void -new_page (PLStream* pls) -{ - GtkAdjustment* adj; - GnomeCanvasGroup* group; - GnomeCanvasItem* background; - GnomeCanvas* canvas; - GnomePLdev* dev; - GnomePLdevPage* page; - GnomeCanvasPoints* points; - guint np; - guint32 loclinecolor; - char buffer[BUFFER_LEN]; - - dev = pls->dev; - page = g_malloc (sizeof (GnomePLdevPage)); - page->mode = GNOME_PLDEV_LOCATE_MODE; - page->ppu = 1.0; - - page->bufc = 0; - - np = dev->npages; - - /*// gdk_threads_enter ();*/ - -#ifdef ANTIALISED_CANVAS - - gtk_widget_push_visual(gdk_rgb_get_visual()); - gtk_widget_push_colormap(gdk_rgb_get_cmap()); - canvas = GNOME_CANVAS (gnome_canvas_new_aa ()); - -#else - - gtk_widget_push_visual(gdk_imlib_get_visual()); - gtk_widget_push_colormap(gdk_imlib_get_colormap()); - canvas = GNOME_CANVAS (gnome_canvas_new ()); - -#endif - - timeout_id = gtk_timeout_add (1000, canvas_timeout, dev); - - page->canvas = canvas; - - page->width = PIXELS_PER_DU * WIDTH / DRAWING_UNIT; - page->height = PIXELS_PER_DU * HEIGHT / DRAWING_UNIT; - - gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), - 0, -page->height, page->width, 0); - - gtk_widget_pop_visual(); - gtk_widget_pop_colormap(); - - group = gnome_canvas_root (GNOME_CANVAS (canvas)); - - background = gnome_canvas_item_new (group, - gnome_canvas_rect_get_type(), - "x1", 0.0, - "y1", -page->height, - "x2", page->width, - "y2", 0.0, - "fill_color", (pls->cmap0[0]).name, - "width_units", 0.0, - NULL); - - timeout_register (canvas, dev); - - set_color (background, 0, 0.0); - - points = gnome_canvas_points_new (2); - - points->coords[0] = 0.0; - points->coords[1] = 0.0; - points->coords[2] = page->width; - points->coords[3] = 0.0; - - loclinecolor = plcolor_to_rgba_inv (pls->cmap0[0], 0xF0), - page->hlocline = - gnome_canvas_item_new (group, - gnome_canvas_line_get_type(), - "points", points, - "fill_color_rgba", loclinecolor, - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (page->hlocline); - - timeout_register (canvas, dev); - - page->hpos = 0.0; - - points->coords[0] = 0.0; - points->coords[1] = -page->height; - points->coords[2] = 0.0; - points->coords[3] = 0.0; - - page->vlocline = - gnome_canvas_item_new (group, - gnome_canvas_line_get_type(), - "points", points, - "fill_color_rgba", loclinecolor, - "width_pixels", 1, - NULL); - gnome_canvas_item_hide (page->vlocline); - - timeout_register (canvas, dev); - - page->vpos = 0.0; - - gnome_canvas_points_unref (points); - points = gnome_canvas_points_new (5); - - points->coords[0] = 0.0; - points->coords[1] = 0.0; - points->coords[2] = 0.0; - points->coords[3] = 0.0; - points->coords[4] = 0.0; - points->coords[5] = 0.0; - points->coords[6] = 0.0; - points->coords[7] = 0.0; - points->coords[8] = 0.0; - points->coords[9] = 0.0; - - page->zoomrect = - gnome_canvas_item_new (group, - gnome_canvas_line_get_type(), - "points", points, - "fill_color_rgba", - plcolor_to_rgba_inv (pls->cmap0[0], 0xF0), - "width_units", 1.0, - NULL); - - gnome_canvas_item_hide (page->zoomrect); - - timeout_register (canvas, dev); - - page->hpos = 0.0; - - gnome_canvas_points_unref (points); - - page->context = np+1; - - change_mode (page, GNOME_PLDEV_LOCATE_MODE); - - gtk_signal_connect (GTK_OBJECT (background), "event", - (GtkSignalFunc) canvas_pressed_cb, - page); - - gtk_signal_connect (GTK_OBJECT (canvas), "key_press_event", - GTK_SIGNAL_FUNC (key_cb), pls); - - page->hadj = GTK_ADJUSTMENT (GTK_LAYOUT (canvas)->hadjustment); - page->vadj = GTK_ADJUSTMENT (GTK_LAYOUT (canvas)->vadjustment); - - page->sw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (page->hadj, - page->vadj)); - - gtk_scrolled_window_set_policy (page->sw, - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - - gtk_container_add (GTK_CONTAINER (page->sw), GTK_WIDGET (canvas)); - - if (np == 0) - dev->page = g_malloc (sizeof (GnomePLdevPage*)); - else - dev->page = g_realloc (dev->page, - (np+1) * sizeof (GnomePLdevPage*)); - - - dev->page[np] = page; - - gtk_notebook_set_show_tabs (dev->notebook, (np > 0)); - - snprintf (buffer, BUFFER_LEN, "Page %d", np+1); - gtk_notebook_append_page (dev->notebook, GTK_WIDGET (page->sw), - gtk_label_new (buffer)); - - /*// adj = gtk_scrolled_window_get_vadjustment (page->hadj);*/ - /*// page->hadj->value = 0.0;*/ - /*//page->hadj->step_increment = 1.0;*/ - /*// page->vadj = adj;*/ - /*//gtk_scrolled_window_set_vadjustment (page->sw, adj);*/ - - /*//adj = gtk_scrolled_window_get_hadjustment (page->sw);*/ - /*//page->vadj->value = 0.0;*/ - /*//page->vadj->step_increment = 1.0;*/ - /*// page->hadj = adj;*/ - /*//gtk_scrolled_window_set_hadjustment (page->sw, adj);*/ - - gtk_widget_show_all (dev->parent); - - gtk_notebook_set_page (dev->notebook, -1); - - /*// gdk_threads_leave ();*/ - - dev->npages++; - -} - -void -gnome_pldev_create (PLStream* pls) -{ - GnomePLdev* dev; - GtkWidget* vbox; - - dev = g_malloc (sizeof (GnomePLdev)); - pls->dev = dev; - dev->npages = 0; - dev->pattern = 0; - dev->pattern_stipple[0] = NULL; - dev->pattern_stipple[1] = NULL; - vbox = gtk_vbox_new (FALSE, 0); - dev->root = vbox; - - dev->statusbar = GTK_STATUSBAR (gtk_statusbar_new ()); - sb = dev->statusbar; - - gtk_box_pack_end (GTK_BOX (dev->root), GTK_WIDGET (dev->statusbar), - FALSE, FALSE, 0); - - dev->notebook = GTK_NOTEBOOK (gtk_notebook_new ()); - - gtk_signal_connect (GTK_OBJECT (dev->notebook), "switch_page", - GTK_SIGNAL_FUNC (page_switch), dev); - - gtk_notebook_set_scrollable (dev->notebook, TRUE); - - gtk_box_pack_start (GTK_BOX (dev->root), GTK_WIDGET (dev->notebook), - TRUE, TRUE, 0); - - gtk_widget_show_all (GTK_WIDGET (dev->notebook)); - - dev->parent_is_from_driver = FALSE; -} - -void plD_open_gnome(PLStream *pls); - -void plD_init_gnome (PLStream *); -void plD_line_gnome (PLStream *, short, short, short, short); -void plD_polyline_gnome (PLStream *, short *, short *, PLINT); -void plD_eop_gnome (PLStream *); -void plD_bop_gnome (PLStream *); -void plD_tidy_gnome (PLStream *); -void plD_state_gnome (PLStream *, PLINT); -void plD_esc_gnome (PLStream *, PLINT, void *); - -void plD_dispatch_init_gnome( PLDispatchTable *pdt ) -{ -#ifndef ENABLE_DYNDRIVERS - pdt->pl_MenuStr = "Gnome Canvas"; - pdt->pl_DevName = "gnome"; -#endif - pdt->pl_type = plDevType_Interactive; - pdt->pl_seq = 1; - pdt->pl_init = (plD_init_fp) plD_init_gnome; - pdt->pl_line = (plD_line_fp) plD_line_gnome; - pdt->pl_polyline = (plD_polyline_fp) plD_polyline_gnome; - pdt->pl_eop = (plD_eop_fp) plD_eop_gnome; - pdt->pl_bop = (plD_bop_fp) plD_bop_gnome; - pdt->pl_tidy = (plD_tidy_fp) plD_tidy_gnome; - pdt->pl_state = (plD_state_fp) plD_state_gnome; - pdt->pl_esc = (plD_esc_fp) plD_esc_gnome; -} - -/*--------------------------------------------------------------------------*\ - * plD_init_gnome() - * - * Initialize device. - * X-dependent stuff done in plD_open_gnome() and Init(). -\*--------------------------------------------------------------------------*/ - -void -plD_init_gnome (PLStream *pls) -{ - char* argv[] = { "" }; - GnomePLdev* dev; - GtkWidget* window; - double phys2canvas = MAG_FACTOR * PIXELS_PER_MM; - - pls->termin = 1; /* Is an interactive terminal */ - pls->dev_flush = 1; /* Handle our own flushes */ - pls->dev_fill0 = 1; /* Handle solid fills */ - pls->dev_fill1 = 1; /* Driver handles pattern fills */ - pls->dev_dash = 1; /* Handle dashed lines */ - pls->plbuf_write = 1; /* Use plot buffer to replot to another device */ - pls->width = 1; - pls->dev_clear = 1; /* Handle plclear() */ - - - /* The real meat of the initialization done here */ - - /*// atexit (do_quit);*/ - - /* init threads */ - g_thread_init (NULL); - - if (pls->dev == NULL) { - - if (! gnome_is_initialized ) { - - gnome_init ("GnomePLplotDriver", "0.0.1", 1, argv); - gnome_sound_shutdown (); - - } - - gdk_rgb_init (); - - gnome_pldev_create (pls); - - dev = pls->dev; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - dev->parent = window; - - gtk_signal_connect (GTK_OBJECT (window), - "delete_event", - GTK_SIGNAL_FUNC (delete_event_cb), - NULL); - - gtk_window_set_title (GTK_WINDOW (window), "Gnome PLplot Driver"); - - gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, TRUE); - - gtk_window_set_default_size (GTK_WINDOW (window), 700, 565); - - gtk_container_add (GTK_CONTAINER (window), dev->root); - - gtk_widget_show_all (window); - - } - - plP_setpxl ((PLFLT) phys2canvas, (PLFLT) phys2canvas); - plP_setphy ((PLINT) 0, (PLINT) MAG_FACTOR * WIDTH/DRAWING_UNIT, - (PLINT) 0, (PLINT) MAG_FACTOR * HEIGHT/DRAWING_UNIT); - - gnome_is_initialized = TRUE; - -#ifdef HAVE_PTHREADS - - pthread_create (&tid, NULL, init, NULL); - -#endif - -} - - -/*--------------------------------------------------------------------------*\ - * plD_polyline_gnome() - * - * Draw a polyline in the current color from (x1,y1) to (x2,y2). -\*--------------------------------------------------------------------------*/ -static -int count[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - -void -plD_polyline_gnome(PLStream *pls, short *x, short *y, PLINT npts) -{ - GnomePLdev* dev; - GnomePLdevPage* page; - GnomeCanvasPoints* points; - GnomeCanvasGroup* group; - GnomeCanvasItem* item; - GnomeCanvas* canvas; - guint i; - short* xp; - short* yp; - - /*// gdk_threads_enter ();*/ - - dev = pls->dev; - - page = dev->page[dev->npages-1]; - - /*// debug ("Before if\n");*/ - - if ( page->bufc > 0 - && ((npts == 0) - || (page->curcolor != pls->icol0) - || (page->curwidth != pls->width) - || (*x != page->bufx[page->bufc - 1]) - || (*y != page->bufy[page->bufc - 1])) ) { - - /*// printf("bufc = %d\tnpts = %d\n", page->bufc, npts);*/ - /*//q fflush(stdout);*/ - - canvas = page->canvas; - - group = gnome_canvas_root (canvas); - - points = gnome_canvas_points_new (page->bufc); - - for ( i = 0; i < page->bufc; i++ ) { - points->coords[2*i] = ((double) page->bufx[i]/MAG_FACTOR) * PIXELS_PER_DU; - points->coords[2*i + 1] = ((double) -page->bufy[i]/MAG_FACTOR) * PIXELS_PER_DU;; - } - - item = gnome_canvas_item_new (group, - gnome_canvas_line_get_type (), - "cap_style", GDK_CAP_ROUND, - "join_style", GDK_JOIN_ROUND, - "points", points, - "fill_color_rgba", - plcolor_to_rgba (pls->cmap0[page->curcolor], 0xFF), - "width_units", - MAX ((double) page->curwidth, 3.0) * PIXELS_PER_DU, - NULL); - - timeout_register (canvas, dev); - - set_color (item, 0, page->curcolor); - - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) canvas_pressed_cb, - page); - - gnome_canvas_points_unref (points); - - count[pls->icol0]++; - - page->bufc = 0; - - } - - /*// debug ("Got here\n");*/ - - xp = &(page->bufx[page->bufc]); - yp = &(page->bufy[page->bufc]); - - page->bufc += npts; - - while (npts--) { - *(xp++) = *(x++); - *(yp++) = *(y++); - } - - page->curcolor = pls->icol0; - page->curwidth = pls->width; - - /*// gdk_threads_leave ();*/ - -} - -/*--------------------------------------------------------------------------*\ - * plD_line_gnome() - * - * Draw a line in the current color from (x1,y1) to (x2,y2). -\*--------------------------------------------------------------------------*/ - -void -plD_line_gnome(PLStream *pls, short x1, short y1, short x2, short y2) -{ - short x[2]; - short y[2]; - - x[0] = x1; - x[1] = x2; - y[0] = y1; - y[1] = y2; - - plD_polyline_gnome(pls, x, y, (PLINT) 2); - -} - -/*--------------------------------------------------------------------------*\ - * plD_eop_gnome() - * - * End of page. User must hit return (or third mouse button) to continue. -\*--------------------------------------------------------------------------*/ - -void -plD_eop_gnome(PLStream *pls) -{ - GnomePLdev* dev; - GnomePLdevPage* page; - GnomeCanvas* canvas; - int i; - short x, y; - - /*// static int i;*/ - - dev = pls->dev; - - plD_polyline_gnome(pls, NULL, NULL, 0); - - /*// gdk_threads_enter ();*/ - - page = dev->page[dev->npages-1]; - canvas = page->canvas; - - canvas->need_update = 1; - gnome_canvas_update_now (canvas); - - gdk_threads_leave (); - - /*// for (i=0;i<16;i++)*/ - /*// printf("count[%d] = %d\n", i, count[i]);*/ - /*// fflush (stdout);*/ - - /*// printf("eop #%d\n", i++);*/ - /*// fflush (stdout);*/ - - /*// getchar();*/ -} - -/*--------------------------------------------------------------------------*\ - * plD_bop_gnome() - * - * Set up for the next page. -\*--------------------------------------------------------------------------*/ - -void -plD_bop_gnome(PLStream *pls) -{ - GnomePLdev* dev; - GnomePLdevPage* page; - GnomeCanvas* canvas; - - gdk_threads_enter (); - - new_page (pls); - - dev = pls->dev; - - /*// printf("npages = %d\n", dev->npages);*/ - /*// fflush (stdout);*/ - - page = dev->page[dev->npages-1]; - canvas = page->canvas; - - canvas->need_update = 1; - gnome_canvas_update_now (canvas); - - /*// gdk_threads_leave ();*/ - - pls->page++; -} - -/*--------------------------------------------------------------------------*\ - * plD_tidy_gnome() - * - * Close graphics file -\*--------------------------------------------------------------------------*/ - -void -plD_tidy_gnome(PLStream *pls) -{ - -#ifdef HAVE_PTHREADS - - pthread_join (tid, NULL); - -#else - - if (pls->nopause) { - gtk_main_quit(); - } else - gtk_main(); - -#endif - -} - -/*--------------------------------------------------------------------------*\ - * plD_state_gnome() - * - * Handle change in PLStream state (color, pen width, fill attribute, etc). -\*--------------------------------------------------------------------------*/ - -void -plD_state_gnome(PLStream *pls, PLINT op) -{ - switch (op) { - - case PLSTATE_WIDTH: - break; - - case PLSTATE_COLOR0: - break; - - case PLSTATE_COLOR1: - break; - - case PLSTATE_CMAP0: - break; - - case PLSTATE_CMAP1: - break; - } -} - -static void -generate_pattern_fill (PLStream* pls) -{ - GnomePLdev* dev = pls->dev; - int i; - - if (dev->pattern == pls->patt) - return; - - dev->pattern = pls->patt; - - for (i = 0; i < pls->nps; i++) { - int j; - PLINT incl; - double tani; - double dist; /* in pixels */ - int width; - int height; - int cols; - double inclr; - double sini; - double cosi; - GdkGC* gc; - GdkColor black; - GdkColor white; - GdkColormap* colormap; - - dist = (pls->delta[i]/1e3) * PIXELS_PER_MM; - - incl = pls->inclin[i] % 3600; - if (incl > 900) - incl = incl - 900; - else if (incl < -900) - incl = incl + 900; - - inclr = PI * incl / 1800.0; - sini = sin (inclr); - cosi = cos (inclr); - - if (ABS (sini) < cosi) { - if (sini == 0.0) { - width = 1; - height = (int) dist;; - } - else { - width = MIN (ABS (dist / sini), 64); - height = MAX (dist / cosi, 2); - } - } - else { - if (ABS(incl) == 900) { - width = (int) dist; - height = 1; - } - else { - width = MAX (ABS (dist / sini), 2); - height = MIN (dist / cosi, 64); - } - } - - colormap = gtk_widget_get_colormap (GTK_WIDGET (dev->page[0]->canvas)); - - gdk_color_parse ("white", &white); - gdk_color_alloc (colormap, &white); - gdk_color_parse ("black", &black); - gdk_color_alloc (colormap, &black); - - if (dev->pattern_stipple[i] != NULL) - gdk_pixmap_unref (dev->pattern_stipple[i]); - - dev->pattern_stipple[i] = gdk_pixmap_new (NULL, width, height, 1); - - gc = gdk_gc_new (dev->pattern_stipple[i]); - - gdk_gc_set_foreground (gc, &black); - - gdk_draw_rectangle (dev->pattern_stipple[i], gc, TRUE, - 0, 0, width, height); - - gdk_gc_set_foreground (gc, &white); - gdk_gc_set_line_attributes (gc, 1, GDK_LINE_SOLID, 0, 0); - - if (incl == 0 || ABS (incl) == 900) - gdk_draw_point (dev->pattern_stipple[i], gc, 0, 0); - else if (sini < 0.0) { - gdk_draw_line (dev->pattern_stipple[i], gc, 0, 0, width, height); - gdk_draw_line (dev->pattern_stipple[i], gc, 0, -height, - 2*width, height); - gdk_draw_line (dev->pattern_stipple[i], gc, -width, 0, - width, 2*height); - } - else { - gdk_draw_line (dev->pattern_stipple[i], gc, width, 0, 0, height); - gdk_draw_line (dev->pattern_stipple[i], gc, 2*width, 0, 0, 2*height); - gdk_draw_line (dev->pattern_stipple[i], gc, - width, -height, -width, height); - } - - gdk_gc_unref (gc); - - } -} - - -static void -fill_polygon (PLStream* pls) -{ - GnomePLdev* dev; - GnomePLdevPage* page; - GnomeCanvasPoints* points; - GnomeCanvasGroup* group; - GnomeCanvasItem* item; - GnomeCanvas* canvas; - guint i; - - dev = pls->dev; - - /*// gdk_threads_enter ();*/ - - page = dev->page[dev->npages-1]; - - canvas = page->canvas; - - group = gnome_canvas_root (canvas); - - points = gnome_canvas_points_new (pls->dev_npts); - - for ( i = 0; i < pls->dev_npts; i++ ) { - points->coords[2*i] = - ((double) pls->dev_x[i]/MAG_FACTOR) * PIXELS_PER_DU; - points->coords[2*i + 1] = - ((double) -pls->dev_y[i]/MAG_FACTOR) * PIXELS_PER_DU; - } - - /* Experimental stuff for pattern fill */ - if (pls->patt < 0) { - int i; - - generate_pattern_fill (pls); - - for (i = 0; i < pls->nps; i++) - item = gnome_canvas_item_new (group, - gnome_canvas_polygon_get_type (), - "points", points, - "fill_stipple", dev->pattern_stipple[i], - "fill_color_rgba", - plcolor_to_rgba (pls->curcolor, 0xFF), - "width_units", 0.0, - NULL); - } - else - item = gnome_canvas_item_new (group, - gnome_canvas_polygon_get_type (), - "points", points, - "fill_color_rgba", - plcolor_to_rgba (pls->curcolor, 0xFF), - "width_units", 0.0, - NULL); - - timeout_register (canvas, dev); - - set_color (item, 1, (double) pls->icol1); - - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) canvas_pressed_cb, - page); - - gnome_canvas_points_unref (points); - - /*// gdk_threads_leave ();*/ - -} - -static void -dashed_line (PLStream* pls) -{ - GnomePLdev* dev; - GnomePLdevPage* page; - GnomeCanvasPoints* points; - GnomeCanvasGroup* group; - GnomeCanvasItem* item; - GnomeCanvas* canvas; - guint i; - gchar* dash_list; - - dev = pls->dev; - - /*// gdk_threads_enter ();*/ - - page = dev->page[dev->npages-1]; - - canvas = page->canvas; - - group = gnome_canvas_root (canvas); - - points = gnome_canvas_points_new (pls->dev_npts); - - for (i = 0; i < pls->dev_npts; i++) { - points->coords[2*i] = - ((double) pls->dev_x[i]/MAG_FACTOR) * PIXELS_PER_DU; - points->coords[2*i + 1] = - ((double) -pls->dev_y[i]/MAG_FACTOR) * PIXELS_PER_DU; - } - - dash_list = g_malloc (sizeof (gchar) * 2 * pls->nms); - for (i = 0; i < pls->nms; i++) { - dash_list[2*i] = (gchar) ceil ((pls->mark[i]/1e3) * PIXELS_PER_MM); - dash_list[2*i+1] = (gchar) floor ((pls->space[i]/1e3) * PIXELS_PER_MM); - fflush(stdout); - } - - gdk_gc_set_dashes (canvas->pixmap_gc, 0, dash_list, 2*pls->nms); - - g_free (dash_list); - - item = gnome_canvas_item_new (group, - gnome_canvas_line_get_type (), - "cap_style", GDK_CAP_BUTT, - "join_style", GDK_JOIN_ROUND, - "line_style", GDK_LINE_ON_OFF_DASH, - "points", points, - "fill_color_rgba", - plcolor_to_rgba (pls->curcolor, 0xFF), - "width_units", - MAX ((double) pls->width, 3.0) * PIXELS_PER_DU, - NULL); - - timeout_register (canvas, dev); - - set_color (item, 0, (double) pls->icol0); - - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) canvas_pressed_cb, - page); - - gnome_canvas_points_unref (points); - - /*// gdk_threads_leave ();*/ - -} - -/*--------------------------------------------------------------------------*\ - * plD_esc_gnome() - * - * Escape function. - * - * Functions: - * - * PLESC_EH Handle pending events - * PLESC_EXPOSE Force an expose - * PLESC_FILL Fill polygon - * PLESC_FLUSH Flush X event buffer - * PLESC_GETC Get coordinates upon mouse click - * PLESC_REDRAW Force a redraw - * PLESC_RESIZE Force a resize - * PLESC_XORMOD set/reset xor mode -\*--------------------------------------------------------------------------*/ - -static void -clear (PLStream* pls) -{ - GnomePLdev* dev = pls->dev; - GnomePLdevPage* page; - GnomeCanvas* canvas; - GnomeCanvasGroup* group; - GnomeCanvasItem* rect; - - fflush(stdout); - - page = dev->page[pls->page-1]; - canvas = page->canvas; - group = gnome_canvas_root (canvas); - - rect = gnome_canvas_item_new (group, - gnome_canvas_rect_get_type(), - "x1", (double) (pls->sppxmi) * PIXELS_PER_DU, - "y1", (double) -(pls->sppyma) * PIXELS_PER_DU, - "x2", (double) (pls->sppxma) * PIXELS_PER_DU, - "y2", (double) -(pls->sppymi) * PIXELS_PER_DU, - "fill_color", (pls->cmap0[0]).name, - "width_units", 0.0, - NULL); - gnome_canvas_item_raise_to_top (rect); - - gtk_signal_connect (GTK_OBJECT (rect), "event", - (GtkSignalFunc) canvas_pressed_cb, - page); - -} - -void -plD_esc_gnome(PLStream *pls, PLINT op, void *ptr) -{ - dbug_enter("plD_esc_gnome"); - - switch (op) { - - case PLESC_CLEAR: - clear (pls); - break; - - case PLESC_DASH: - dashed_line (pls); - break; - - case PLESC_FILL: - fill_polygon(pls); - break; - - } -} - -#else -int -pldummy_gnome() -{ - return 0; -} - -#endif /* PLD_gnome */ Deleted: trunk/drivers/next.c =================================================================== --- trunk/drivers/next.c 2009-09-23 13:16:55 UTC (rev 10460) +++ trunk/drivers/next.c 2009-09-23 14:13:53 UTC (rev 10461) @@ -1,309 +0,0 @@ -/* $Id$ - - PLplot NeXT display driver. - - Attention: this driver needs a supporter. It may not even work - any more. Also, there have been many improvements to ps.c that - were not incorporated here. If you use this please consider - becoming the official maintainer. Email mj...@di... - for more info. -*/ -#include "plDevs.h" - -#ifdef PLD_next - -#include "plplotP.h" -#include "drivers.h" - -/* top level declarations */ - -#define LINELENGTH 70 -#define COPIES 1 -#define XSIZE 540 /* 7.5" x 7.5" (72 points equal 1 inch) */ -#define YSIZE 540 -#define ENLARGE 5 -#define XPSSIZE ENLARGE*XSIZE -#define YPSSIZE ENLARGE*YSIZE -#define XOFFSET 18 -#define YOFFSET 18 -#define XSCALE 100 -#define YSCALE 100 -#define LINESCALE 100 -#define ANGLE 90 -#define PSX XPSSIZE-1 -#define PSY YPSSIZE-1 -#define OF pls->OutFile -#define MIN_WIDTH 1 /* Minimum pen width */ -#define MAX_WIDTH 10 /* Maximum pen width */ -#define DEF_WIDTH 3 /* Default pen width */ - -static char outbuf[128]; -static int llx = XPSSIZE, lly = YPSSIZE, urx = 0, ury = 0, ptcnt; - -/*------------------------------------------------------------------------*\ - * plD_init_nx() - * - * Initialize device. -\*------------------------------------------------------------------------*/ - -void -plD_init_nx(PLStream *pls) -{ - PLDev *dev; - -/* Allocate and initialize device-specific data */ - - dev = plAllocDev(pls); - - dev->xold = PL_UNDEFINED; - dev->yold = PL_UNDEFINED; - dev->xmin = 0; - dev->xmax = PSX; - dev->ymin = 0; - dev->ymax = PSY; - - plP_setpxl((PLFLT) 11.81, (PLFLT) 11.81); /* 300 dpi */ - - plP_setphy(0, PSX, 0, PSY); -} - -/*------------------------------------------------------------------------*\ - * plD_line_nx() - * - * Draw a line in the current color from (x1,y1) to (x2,y2). -\*------------------------------------------------------------------------*/ - -void -plD_line_nx(PLStream *pls, short x1a, short y1a, short x2a, short y2a) -{ - PLDev *dev = (PLDev *) pls->dev; - int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a; - int ori; - - if (pls->linepos + 21 > LINELENGTH) { - putc('\n', OF); - pls->linepos = 0; - } - else - putc(' ', OF); - - pls->bytecnt++; - - if (x1 == dev->xold && y1 == dev->yold && ptcnt < 40) { - sprintf(outbuf, "%d %d D", x2, y2); - ptcnt++; - } - else { - sprintf(outbuf, "Z %d %d M %d %d D", x1, y1, x2, y2); - llx = MIN(llx, x1); - lly = MIN(lly, y1); - urx = MAX(urx, x1); - ury = MAX(ury, y1); - ptcnt = 1; - } - llx = MIN(llx, x2); - lly = MIN(lly, y2); - urx = MAX(urx, x2); - ury = MAX(ury, y2); - - fprintf(OF, "%s", outbuf); - pls->bytecnt += strlen(outbuf); - dev->xold = x2; - dev->yold = y2; - pls->linepos += 21; -} - -/*------------------------------------------------------------------------*\ - * plD_polyline_nx() - * - * Draw a polyline in the current color. -\*------------------------------------------------------------------------*/ - -void -plD_polyline_nx(PLStream *pls, short *xa, short *ya, PLINT npts) -{ - PLINT i; - - for (i = 0; i < npts - 1; i++) - plD_line_nx(pls, xa[i], ya[i], xa[i + 1], ya[i + 1]); -} - -/*------------------------------------------------------------------------*\ - * plD_eop_nx() - * - * End of page. -\*------------------------------------------------------------------------*/ - -void -plD_eop_nx(PLStream *pls) -{ - fprintf(OF, " S\neop\n"); - - pclose(OF); -} - -/*------------------------------------------------------------------------*\ - * plD_bop_nx() - * - * Set up for the next page. -\*------------------------------------------------------------------------*/ - -void -plD_bop_nx(PLStream *pls) -{ - PLDev *dev = (PLDev *) pls->dev; - - dev->xold = PL_UNDEFINED; - dev->yold = PL_UNDEFINED; - -/* Pipe output to Preview */ - - OF = popen("open", "w"); - -/* Header comments */ - - fprintf(OF, "%%!PS-Adobe-2.0 EPSF-2.0\n"); - fprintf(OF, "%%%%Title: PLplot Graph\n"); - fprintf(OF, "%%%%Creator: PLplot Version %s\n", PLPLOT_VERSION); - fprintf(OF, "%%%%BoundingBox: 0 0 576 576\n"); - fprintf(OF, "%%%%EndComments\n\n"); - -/* Definitions */ - -/* - eop - -- end a page */ - - fprintf(OF, "/eop\n"); - fprintf(OF, " {\n"); - fprintf(OF, " showpage\n"); - fprintf(OF, " } def\n"); - -/* Set line parameters */ - - fprintf(OF, "/@line\n"); - fprintf(OF, " {0 setlinecap\n"); - fprintf(OF, " 0 setlinejoin\n"); - fprintf(OF, " 1 setmiterlimit\n"); - fprintf(OF, " } def\n"); - -/* d @hsize - horizontal clipping dimension */ - - fprintf(OF, "/@hsize {/hs exch def} def\n"); - fprintf(OF, "/@vsize {/vs exch def} def\n"); - -/* d @hoffset - shift for the plots */ - - fprintf(OF, "/@hoffset {/ho exch def} def\n"); - fprintf(OF, "/@voffset {/vo exch def} def\n"); - -/* s @hscale - scale factors */ - - fprintf(OF, "/@hscale {100 div /hsc exch def} def\n"); - fprintf(OF, "/@vscale {100 div /vsc exch def} def\n"); - -/* Set line width */ - - fprintf(OF, "/lw %d def\n", (int) ( - (pls->width < MIN_WIDTH) ? DEF_WIDTH : - (pls->width > MAX_WIDTH) ? MAX_WIDTH : pls->width)); - -/* Setup user specified offsets, scales, sizes for clipping */ - - fprintf(OF, "/@SetPlot\n"); - fprintf(OF, " {\n"); - fprintf(OF, " ho vo translate\n"); - fprintf(OF, " XScale YScale scale\n"); - fprintf(OF, " lw setlinewidth\n"); - fprintf(OF, " } def\n"); - -/* Setup x & y scales */ - - fprintf(OF, "/XScale\n"); - fprintf(OF, " {hsc hs mul %d div} def\n", YPSSIZE); - fprintf(OF, "/YScale\n"); - fprintf(OF, " {vsc vs mul %d div} def\n", XPSSIZE); - -/* Macro definitions of common instructions, to keep output small */ - - fprintf(OF, "/M {moveto} def\n"); - fprintf(OF, "/D {lineto} def\n"); - fprintf(OF, "/S {stroke} def\n"); - fprintf(OF, "/Z {stroke newpath} def\n"); - fprintf(OF, "/F {fill} def\n"); - fprintf(OF, "/C {setrgbcolor} def\n"); - fprintf(OF, "/G {setgray} def\n"); - fprintf(OF, "/W {setlinewidth} def\n"); - -/* Set up the plots */ - - fprintf(OF, "@line\n"); - fprintf(OF, "%d @hsize\n", YSIZE); - fprintf(OF, "%d @vsize\n", XSIZE); - fprintf(OF, "%d @hoffset\n", YOFFSET); - fprintf(OF, "%d @voffset\n", XOFFSET); - fprintf(OF, "%d @hscale\n", YSCALE); - fprintf(OF, "%d @vscale\n", XSCALE); - fprintf(OF, "@SetPlot\n\n"); - pls->page++; - pls->linepos = 0; -} - -/*------------------------------------------------------------------------*\ - * plD_tidy_nx() - * - * Close graphics file or otherwise clean up. -\*------------------------------------------------------------------------*/ - -void -plD_tidy_nx(PLStream *pls) -{ -} - -/*------------------------------------------------------------------------*\ - * plD_state_nx() - * - * Handle change in PLStream state (color, pen width, fill attribute, etc). -\*------------------------------------------------------------------------*/ - -void -plD_state_nx(PLStream *pls, PLINT op) -{ - switch (op) { - - case PLSTATE_WIDTH:{ - int width = - (pls->width < MIN_WIDTH) ? DEF_WIDTH : - (pls->width > MAX_WIDTH) ? MAX_WIDTH : pls->width; - - fprintf(OF, " S\n%d W", width); - - dev->xold = PL_UNDEFINED; - dev->yold = PL_UNDEFINED; - break; - } - case PLSTATE_COLOR0: - break; - - case PLSTATE_COLOR1: - break; - } -} - -/*------------------------------------------------------------------------*\ - * plD_esc_nx() - * - * Escape function. -\*------------------------------------------------------------------------*/ - -void -plD_esc_nx(PLStream *pls, PLINT op, void *ptr) -{ -} - -#else -int -pldummy_next() -{ - return 0; -} - -#endif /* PLD_next */ Deleted: trunk/drivers/xwinttf.c =================================================================== --- trunk/drivers/xwinttf.c 2009-09-23 13:16:55 UTC (rev 10460) +++ trunk/drivers/xwinttf.c 2009-09-23 14:13:53 UTC (rev 10461) @@ -1,701 +0,0 @@ -/* March 13, 2007 - - PLplot driver for X Windows that uses the Cairo graphics library for - rendering graphics and Pango for rendering text. - - Copyright (C) 2007 Hazen Babcock - - This file is part of PLplot. - - PLplot is free software; you can redistribute it and/or modify - it under the terms of the GNU General Library Public License as published - by the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - PLplot is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with PLplot; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -//--------------------------------------------- -// Header files, defines and local variables -//--------------------------------------------- - -#include <stdio.h> -#include <string.h> -#include <math.h> - -#include <X11/X.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/cursorfont.h> - -#include <cairo.h> -#include <cairo-xlib.h> - -#include <pango/pangocairo.h> - -/* PLplot header files */ - -#include "plplotP.h" -#include "drivers.h" - -/* constants */ - -#define MAXPAGES 50 -#define DPI 72 -#define XWINTTF_DEFAULT_X 720 -#define XWINTTF_DEFAULT_Y 540 -#define MAX_STRING_LEN 500 -#define MAX_MARKUP_LEN MAX_STRING_LEN * 10 - -/* local variables */ - -PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_xwinttf = "xwinttf:TrueType X Windows Driver:1:xwinttf:59:xwinttf\n"; - -static int currentPage = -1; -static int XScreen; -static Display *XDisplay = NULL; -static Window rootWindow ; -static Window XWindow[MAXPAGES]; - -static int windowXSize = XWINTTF_DEFAULT_X; -static int windowYSize = XWINTTF_DEFAULT_Y; - -static cairo_surface_t *cairoSurface[MAXPAGES]; -static cairo_t *cairoContext[MAXPAGES]; - -//----------------------------------------------- -// Font style and weight lookup tables (copied -// from the psttf driver). -//----------------------------------------------- - -#define NPANGOLOOKUP 5 - -const char *defaultFamilyLookup[NPANGOLOOKUP] = { - "Sans", - "Serif", - "Monospace", - "Sans", - "Sans" -}; - -const char *envFamilyLookup[NPANGOLOOKUP] = { - "PLPLOT_FREETYPE_SANS_FAMILY", - "PLPLOT_FREETYPE_SERIF_FAMILY", - "PLPLOT_FREETYPE_MONO_FAMILY", - "PLPLOT_FREETYPE_SCRIPT_FAMILY", - "PLPLOT_FREETYPE_SYMBOL_FAMILY" -}; - -char familyLookup[NPANGOLOOKUP][1024]; - -const char *weightLookup[2] = { - "normal", - "bold" -}; - -const char *styleLookup[3] = { - "normal", - "italic", - "oblique" -}; - -//----------------------------------------------- -// function declarations -//----------------------------------------------- - -/* String processing */ - -static void proc_str(PLStream *, EscText *); -static char *ucs4_to_pango_markup_format(PLUNICODE *, int, float); -static void open_span_tag(char *, PLUNICODE, float, int); -static void close_span_tag(char *, int); - -/* Graphics */ - -static void get_cursor(PLStream *, PLGraphicsIn *); -static void set_current_context(PLStream *); -static void poly_line(PLStream *, short *, short *, PLINT); - -/* PLplot interface functions */ - -void plD_dispatch_init_xwinttf (PLDispatchTable *pdt); -void plD_init_xwinttf (PLStream *); -void plD_line_xwinttf (PLStream *, short, short, short, short); -void plD_polyline_xwinttf (PLStream *, short *, short *, PLINT); -void plD_eop_xwinttf (PLStream *); -void plD_bop_xwinttf (PLStream *); -void plD_tidy_xwinttf (PLStream *); -void plD_state_xwinttf (PLStream *, PLINT); -void plD_esc_xwinttf (PLStream *, PLINT, void *); - -//--------------------------------------------------------------------- -// dispatch_init_init() -// -// Initialize device dispatch table -//---------------------------------------------------------------------- - -void plD_dispatch_init_xwinttf(PLDispatchTable *pdt) -{ -#ifndef ENABLE_DYNDRIVERS - pdt->pl_MenuStr = "TrueType X Windows Driver"; - pdt->pl_DevName = "xwinttf"; -#endif - pdt->pl_type = plDevType_Interactive; - pdt->pl_seq = 59; - pdt->pl_init = (plD_init_fp) plD_init_xwinttf; - pdt->pl_line = (plD_line_fp) plD_line_xwinttf; - pdt->pl_polyline = (plD_polyline_fp) plD_polyline_xwinttf; - pdt->pl_eop = (plD_eop_fp) plD_eop_xwinttf; - pdt->pl_bop = (plD_bop_fp) plD_bop_xwinttf; - pdt->pl_tidy = (plD_tidy_fp) plD_tidy_xwinttf; - pdt->pl_state = (plD_state_fp) plD_state_xwinttf; - pdt->pl_esc = (plD_esc_fp) plD_esc_xwinttf; -} - -//--------------------------------------------------------------------- -// xwinttf_init() -// -// Initialize device -//---------------------------------------------------------------------- - -void plD_init_xwinttf(PLStream *pls) -{ - int i; - char *a; - - pls->termin = 1; /* Interactive device */ - pls->dev_flush = 1; /* Handles flushes */ - pls->color = 1; /* Supports color */ - pls->dev_text = 1; /* Handles text */ - pls->dev_unicode = 1; /* Wants unicode text */ - pls->page = 0; - pls->dev_fill0 = 1; /* Supports hardware solid fills */ - - plP_setpxl(DPI/25.4, DPI/25.4); - - if (pls->xlength <= 0 || pls->ylength <= 0){ - plP_setphy((PLINT) 0, (PLINT) XWINTTF_DEFAULT_X, (PLINT) 0, XWINTTF_DEFAULT_Y); - } else { - windowXSize = pls->xlength; - windowYSize = pls->ylength; - plP_setphy((PLINT) 0, (PLINT) pls->xlength, (PLINT) 0, (PLINT) pls->ylength); - } - - XDisplay = XOpenDisplay(NULL); - if(XDisplay == NULL){ - printf("Failed to open X Windows display\n"); - // some sort of error here - } - XScreen = DefaultScreen(XDisplay); - rootWindow = RootWindow(XDisplay, XScreen); - - // Initialize font table with either enviroment variables or defaults. - // This was copied from the psttf driver. - for(i=0;i<NPANGOLOOKUP;i++){ - if((a = getenv(envFamilyLookup[i])) != NULL){ - strcpy(familyLookup[i],a); - } - else { - strcpy(familyLookup[i],defaultFamilyLookup[i]); - } - } - - // Set all cairo pointers to NULL - for(i=0;i<MAXPAGES;i++){ - cairoSurface[i] = NULL; - cairoContext[i] = NULL; - } -} - -//---------------------------------------------------------------------- -// xwinttf_bop() -// -// Set up for the next page. -//---------------------------------------------------------------------- - -void plD_bop_xwinttf(PLStream *pls) -{ - char plotTitle[40]; - cairo_matrix_t *flipVertical; - Visual *defaultVisual; - XGCValues values; - - // Increment the page number. - currentPage++; - if(currentPage > MAXPAGES){ - currentPage = 0; - } - pls->page++; - - // Initialize plot title - sprintf(plotTitle, "PLplot (%d)", currentPage); - - // Create a X Window. - XWindow[currentPage] = XCreateSimpleWindow(XDisplay, rootWindow, 0, 0, windowXSize, windowYSize, - 1, BlackPixel(XDisplay, XScreen), BlackPixel(XDisplay, XScreen)); - XStoreName(XDisplay, XWindow[currentPage], plotTitle); - XSelectInput(XDisplay, XWindow[currentPage], NoEventMask); - XMapWindow(XDisplay, XWindow[currentPage]); - - // Create an cairo surface & context that are associated with the window. - defaultVisual = DefaultVisual(XDisplay, 0); - cairoSurface[currentPage] = cairo_xlib_surface_create(XDisplay, XWindow[currentPage], defaultVisual, windowXSize, windowYSize); - cairoContext[currentPage] = cairo_create(cairoSurface[currentPage]); - - // Fill in the window with the background color. - cairo_rectangle(cairoContext[currentPage], 0.0, 0.0, windowXSize, windowYSize); - cairo_set_source_rgb(cairoContext[currentPage], - (double)pls->cmap0[0].r/255.0, - (double)pls->cmap0[0].g/255.0, - (double)pls->cmap0[0].b/255.0); - cairo_fill(cairoContext[currentPage]); - - // Invert the coordinate system so the graphs are drawn right side up. - flipVertical = (cairo_matrix_t *) malloc (sizeof(cairo_matrix_t)); - cairo_matrix_init(flipVertical, 1.0, 0.0, 0.0, -1.0, 0.0, windowYSize); - cairo_set_matrix(cairoContext[currentPage], flipVertical); - free(flipVertical); -} - -//--------------------------------------------------------------------- -// xwinttf_line() -// -// Draw a line in the current color from (x1,y1) to (x2,y2). -//---------------------------------------------------------------------- - -void plD_line_xwinttf(PLStream *pls, short x1a, short y1a, short x2a, short y2a) -{ - set_current_context(pls); - - cairo_move_to(cairoContext[currentPage], (double) x1a, (double) y1a); - cairo_line_to(cairoContext[currentPage], (double) x2a, (double) y2a); - cairo_stroke(cairoContext[currentPage]); -} - -//--------------------------------------------------------------------- -// xwinttf_polyline() -// -// Draw a polyline in the current color. -//--------------------------------------------------------------------- - -void plD_polyline_xwinttf(PLStream *pls, short *xa, short *ya, PLINT npts) -{ - poly_line(pls, xa, ya, npts); - cairo_stroke(cairoContext[currentPage]); -} - -//--------------------------------------------------------------------- -// xwinttf_eop() -// -// End of page -//--------------------------------------------------------------------- - -void plD_eop_xwinttf(PLStream *pls) -{ - XFlush(XDisplay); -} - -//--------------------------------------------------------------------- -// xwinttf_tidy() -// -// Close graphics file or otherwise clean up. -//--------------------------------------------------------------------- - -void plD_tidy_xwinttf(PLStream *pls) -{ - int i; - - printf("Key <Return> to finish\n"); - getc(stdin); - - for(i=0;i<MAXPAGES;i++){ - if(cairoContext[i] != NULL){ - cairo_destroy(cairoContext[i]); - cairo_surface_destroy(cairoSurface[i]); - } - } - - XCloseDisplay(XDisplay); - free(XDisplay); -} - -//--------------------------------------------------------------------- -// plD_state_xwinttf() -// -// Handle change in PLStream state (color, pen width, fill attribute, etc). -// -// Nothing is done here because these attributes are acquired from -// PLStream for each element that is drawn. -//--------------------------------------------------------------------- - -void plD_state_xwinttf(PLStream *pls, PLINT op) -{ -} - -//--------------------------------------------------------------------- -// xwinttf_esc() -// -// Escape function. -//--------------------------------------------------------------------- - -void plD_esc_xwinttf(PLStream *pls, PLINT op, void *ptr) -{ - switch(op) - { - case PLESC_FILL: // filled polygon - poly_line(pls, pls->dev_x, pls->dev_y, pls->dev_npts); - cairo_fill(cairoContext[currentPage]); - break; - case PLESC_HAS_TEXT: // render rext - proc_str(pls, (EscText *) ptr); - break; - case PLESC_FLUSH: // forced update of the window - XFlush(XDisplay); - break; - case PLESC_GETC: // get cursor position - XFlush(XDisplay); - get_cursor(pls, (PLGraphicsIn*)ptr); - break; - } -} - -//--------------------------------------------------------------------- -// proc_str() -// -// Processes strings for display. -//--------------------------------------------------------------------- - -void proc_str(PLStream *pls, EscText *args) -{ - int i; - float fontSize; - int textXExtent, textYExtent; - char *textWithPangoMarkup; - PLFLT rotation, shear, cos_rot, sin_rot, sin_shear; - cairo_matrix_t *cairoTransformMatrix; - PangoLayout *layout; - PangoFontDescription *fontDescription; - - set_current_context(pls); - - // Check that we got unicode, warning message and return if not - if(args->unicode_array_len == 0){ - printf("Non unicode string passed to xwinttf driver, ignoring\n"); - return; - } - - // Check that unicode string isn't longer then the max we allow - if(args->unicode_array_len >= MAX_STRING_LEN){ - printf("Sorry, the xwinttf driver only handles strings of length < %d\n", MAX_STRING_LEN); - return; - } - - // Calculate the font size (in pixels) - fontSize = pls->chrht * DPI/25.4; - - // Convert the escape characters into the appropriate Pango markup - textWithPangoMarkup = ucs4_to_pango_markup_format(args->unicode_array, args->unicode_array_len, fontSize); - - // Create the Pango text layout so we can figure out how big it is - layout = pango_cairo_create_layout(cairoContext[currentPage]); - pango_layout_set_markup(layout, textWithPangoMarkup, -1); - // fontDescription = pango_font_description_from_string(fontString); - // pango_layout_set_font_description(layout, fontDescription); - pango_layout_get_pixel_size(layout, &textXExtent, &textYExtent); - - // Move to the string reference point - cairo_move_to(cairoContext[currentPage], (double) args->x, (double) args->y); - - // Save current transform matrix - cairo_save(cairoContext[currentPage]); - - // Invert the coordinate system so that the text is drawn right side up - cairoTransformMatrix = (cairo_matrix_t *) malloc (sizeof(cairo_matrix_t)); - cairo_matrix_init(cairoTransformMatrix, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0); - cairo_transform(cairoContext[currentPage], cairoTransformMatrix); - - // Extract rotation angle and shear from the PLplot tranformation matrix. - // Compute sines and cosines of the angles as an optimization. - plRotationShear(args->xform, &rotation, &shear); - cos_rot = cos(rotation); - sin_rot = sin(rotation); - sin_shear = sin(shear); - - // Apply the transform matrix - cairo_matrix_init(cairoTransformMatrix, - cos_rot, - -sin_rot, - cos_rot * sin_shear + sin_rot, - -sin_rot * sin_shear + cos_rot, - 0,0); - cairo_transform(cairoContext[currentPage], cairoTransformMatrix); - free(cairoTransformMatrix); - - // Move to the text starting point - cairo_rel_move_to(cairoContext[currentPage], - (double)(-1.0 * args->just * (double)textXExtent), - (double)(-0.5 * textYExtent)); - - // Render the text - pango_cairo_show_layout(cairoContext[currentPage], layout); - - // Restore the transform matrix to its state prior to the text transform. - cairo_restore(cairoContext[currentPage]); - - // Free the layout object and the markup string. - g_object_unref(layout); - free(textWithPangoMarkup); -} - -//--------------------------------------------------------------------- -// ucs4_to_pango_markup_format() -// -// Converts the plplot string (in ucs4) to a utf8 string that includes -// pango markup. -// -// http://developer.gnome.org/doc/API/2.0/pango/PangoMarkupFormat.html -//--------------------------------------------------------------------- - -char *ucs4_to_pango_markup_format(PLUNICODE *ucs4, int ucs4Len, float fontSize) -{ - char plplotEsc; - int i; - int upDown = 0; - PLUNICODE fci; - char utf8[5]; - char *pangoMarkupString; - - // Will this be big enough? We might have lots of markup. - pangoMarkupString = (char *) malloc (sizeof(char) * MAX_MARKUP_LEN); - for(i = 0; i < MAX_MARKUP_LEN; i++){ - pangoMarkupString[i] = 0; - } - - // Get PLplot escape character - plgesc(&plplotEsc); - - // Get the curent font and open the first span tag - plgfci(&fci); - open_span_tag(pangoMarkupString, fci, fontSize, 0); - - // Parse the string to generate the tags - i = 0; - while (i < ucs4Len){ - // Try to avoid going off the end of the string - if(strlen(pangoMarkupString) > (MAX_MARKUP_LEN - 50)){ - continue; - } - if (ucs4[i] < PL_FCI_MARK){ // not a font change - if (ucs4[i] != (PLUNICODE)plplotEsc) { // a character to display - // we have to handle "<", ">" and "&" separately since they throw off the XML - switch(ucs4[i]) - { - case 38: - strcat(pangoMarkupString, "&"); - break; - case 60: - strcat(pangoMarkupString, "<"); - break; - case 62: - strcat(pangoMarkupString, ">"); - break; - default: - ucs4_to_utf8(ucs4[i],utf8); - strcat(pangoMarkupString, utf8); - break; - } - i++; - continue; - } - i++; - if (ucs4[i] == (PLUNICODE)plplotEsc){ // a escape character to display - strcat(pangoMarkupString, utf8); - i++; - continue; - } - else { - if(ucs4[i] == (PLUNICODE)'u'){ // Superscript - if(upDown < 0){ - strcat(pangoMarkupString, "</sub>"); - } else { - strcat(pangoMarkupString, "<sup>"); - } - upDown++; - } - if(ucs4[i] == (PLUNICODE)'d'){ // Subscript - if(upDown > 0){ - strcat(pangoMarkupString, "</sup>"); - } else {... [truncated message content] |