viewmeta
Description
viewmeta.c provides an X-windows based viewer for plotlib metafiles. It reads plotlib commands (generated by applications using plotlib.c) and renders them graphically on a screen. This module allows users to interactively preview plots, zoom into sub-areas, and capture screenshots.
It acts as a graphical device driver for plotlib, translating generic plotting instructions into X-windows drawing calls.
Global Variables
no_sub_windows: Counter for opened sub-windows.visual,screen,ddepth: X-windows display information.basefont: Default font for text.sub_name: Name for sub-windows.MAXWINDOW,MAX_SUB_WINDOW: Maximum dimensions for windows.SUN_flag: Flag for SUN workstations (for colormap handling).
Functions (Implementing plotlib Driver Interface)
plot_start(float dx, float dy): Initializes the X-windows display and creates the main plotting window. Calculates window dimensions, initializes X-windows connection, creates and maps the main window and a graphic window. Sets up the colormap and initial graphics context.plot_end(): Finalizes the X-windows display. Enters an event loop (process_x_events) to handle user interaction (e.g., zooming, closing). Ifjust_dumpis set, it dumps the window content to a PPM file. Closes the X-windows connection.plot_rotate(): (Empty function) Not directly implemented for screen display; rotation would typically be handled by transforming coordinates.plot_move(float x, float y): Moves the logical pen position. Updateslast_Xcoordandlast_Ycoord(global variables used by drawing functions).plot_line(float x, float y): Draws a line on the X-windows display. Callsjhc_line()(an X-windows drawing function) to draw a line from(last_Xcoord, last_Ycoord)to(x, y)in both the main window and any sub-windows.plot_text(char *text): Draws a text string on the X-windows display. Callsjhc_text()(an X-windows drawing function) to draw the text at the last pen position in both the main window and any sub-windows.plot_textrot(float angle): Sets the orientation for text drawing. Calculates a normalized angle for text path setting.plot_pen(int pen): Selects the drawing pen (color). Maps theplotlibpen number to an X-windows color and updatespennum.plot_textsize(float x, float y): Sets the size of the text characters. Callsjhc_select_font()(an X-windows font selection function) based on the Y-scaling.plot_clip(float x0, float y0, float x1, float y1): (Empty function) Clipping is not directly implemented by this module.
Event Handling Functions
refresh_window(Window window): Refreshes the content of a given window (main or sub-window) by copying its pixmap buffer to the screen.view_subarea(int window_idx, int anchor_x, int anchor_y, int toe_x, int toe_y): Creates a new sub-window to display a zoomed-in view of a selected rectangular area. Re-parses the metafile, redrawing all commands constrained to the new sub-window’s coordinate system and clipping area.process_x_events(int go): The main X-windows event loop. HandlesConfigureNotify,Expose,KeyPress,MotionNotify,ButtonRelease, andButtonPressevents. Supports rubber-band selection for zooming, printing coordinates, and exiting.dump_the_window(Window window, int the_width, int the_height, char *filename): Captures the content of an X-window and saves it as a PPM (Portable Pixmap) image file.
How It Works
viewmeta.c implements a plotlib device driver that renders generic plotlib commands onto an X-windows graphical display. It initializes an X-windows connection, creates a main window, and sets up a graphics context. When plotdriver processes a plotlib metafile and dispatches commands to viewmeta.c, these commands are translated into X-windows drawing primitives (lines, text, colors). The module uses double-buffering (drawing to an off-screen pixmap and then copying to the visible window) to prevent flickering. An event loop (process_x_events) handles user interactions, enabling interactive features like zooming (by re-parsing and re-drawing within a new coordinate system) and screenshot capture.
Output Files
- The primary output is a graphical display in an X-windows window.
viewmeta.dump.ppm: A PPM image file ifjust_dumpis set (for screenshots).
Dependencies
plotdriver.h: Defines the interface forplotlibdevice drivers.plotlib.h: Defines generalplotlibconstants and global variables.viewmeta.h: Definesviewmeta-specific constants and global variables, includingMAXWINDOW,MAX_SUB_WINDOW.X_extra.h: Provides custom X-windows drawing functions (start_x,terminate_x,jhc_line,jhc_text, etc.).- X11 and GLX libraries.
Notes
viewmeta is a crucial tool for interactively previewing and debugging plotlib generated output, offering a dynamic alternative to static file formats like HPGL. Its ability to zoom into specific areas and capture screenshots enhances its utility for analysis and documentation. The SUN_flag is a legacy option for specific workstation types.