/ATF2/control-software/epics-3.14.10/extensions/src/edm/pvFactory/SciPlot.c
C | 2143 lines | 1831 code | 234 blank | 78 comment | 238 complexity | 90323d5e806635f00d9f428b1389fdbf MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- /*----------------------------------------------------------------------------
- * SciPlot A generalized plotting widget
- *
- * Copyright (c) 1996 Robert W. McMullen
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library 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 this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- * Author: Rob McMullen <rwmcm@mail.ae.utexas.edu>
- * http://www.ae.utexas.edu/~rwmcm
- *
- * Modifications (KUK): Double-buffering, seperate Text color
- */
- #include <X11/IntrinsicP.h>
- #include <X11/StringDefs.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "SciPlotP.h"
- #define offset(field) XtOffsetOf(SciPlotRec, plot.field)
- static XtResource resources[] =
- {
- {XtNchartType, XtCMargin, XtRInt, sizeof(int),
- offset(ChartType), XtRImmediate, (XtPointer) XtCARTESIAN},
- {XtNdegrees, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(Degrees), XtRImmediate, (XtPointer) True},
- {XtNdrawMajor, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DrawMajor), XtRImmediate, (XtPointer) True},
- {XtNdrawMajorTics, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DrawMajorTics), XtRImmediate, (XtPointer) True},
- {XtNdrawMinor, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DrawMinor), XtRImmediate, (XtPointer) True},
- {XtNdrawMinorTics, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(DrawMinorTics), XtRImmediate, (XtPointer) True},
- {XtNmonochrome, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(Monochrome), XtRImmediate, (XtPointer) False},
- {XtNshowLegend, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(ShowLegend), XtRImmediate, (XtPointer) True},
- {XtNshowTitle, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(ShowTitle), XtRImmediate, (XtPointer) True},
- {XtNshowXLabel, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(ShowXLabel), XtRImmediate, (XtPointer) True},
- {XtNshowYLabel, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(ShowYLabel), XtRImmediate, (XtPointer) True},
- {XtNxLabel, XtCString, XtRString, sizeof(String),
- offset(TransientXLabel), XtRString, "X Axis"},
- {XtNyLabel, XtCString, XtRString, sizeof(String),
- offset(TransientYLabel), XtRString, "Y Axis"},
- {XtNplotTitle, XtCString, XtRString, sizeof(String),
- offset(TransientPlotTitle), XtRString, "Plot"},
- {XtNmargin, XtCMargin, XtRInt, sizeof(int),
- offset(Margin), XtRImmediate, (XtPointer) 5},
- {XtNtitleMargin, XtCMargin, XtRInt, sizeof(int),
- offset(TitleMargin), XtRImmediate, (XtPointer) 16},
- {XtNlegendLineSize, XtCMargin, XtRInt, sizeof(int),
- offset(LegendLineSize), XtRImmediate, (XtPointer) 16},
- {XtNdefaultMarkerSize, XtCMargin, XtRInt, sizeof(int),
- offset(DefaultMarkerSize), XtRImmediate, (XtPointer) 3},
- {XtNlegendMargin, XtCMargin, XtRInt, sizeof(int),
- offset(LegendMargin), XtRImmediate, (XtPointer) 3},
- {XtNlegendThroughPlot, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(LegendThroughPlot), XtRImmediate, (XtPointer) False},
- {XtNtitleFont, XtCMargin, XtRInt, sizeof(int),
- offset(TitleFont), XtRImmediate, (XtPointer) (XtFONT_HELVETICA | 24)},
- {XtNlabelFont, XtCMargin, XtRInt, sizeof(int),
- offset(LabelFont), XtRImmediate, (XtPointer) (XtFONT_TIMES | 18)},
- {XtNaxisFont, XtCMargin, XtRInt, sizeof(int),
- offset(AxisFont), XtRImmediate, (XtPointer) (XtFONT_TIMES | 10)},
- {XtNxAutoScale, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XAutoScale), XtRImmediate, (XtPointer) True},
- {XtNyAutoScale, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YAutoScale), XtRImmediate, (XtPointer) True},
- {XtNxAxisNumbers, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XAxisNumbers), XtRImmediate, (XtPointer) True},
- {XtNyAxisNumbers, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YAxisNumbers), XtRImmediate, (XtPointer) True},
- {XtNxLog, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XLog), XtRImmediate, (XtPointer) False},
- {XtNyLog, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YLog), XtRImmediate, (XtPointer) False},
- {XtNxOrigin, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(XOrigin), XtRImmediate, (XtPointer) False},
- {XtNyOrigin, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YOrigin), XtRImmediate, (XtPointer) False},
- {XtNyNumbersHorizontal, XtCBoolean, XtRBoolean, sizeof(Boolean),
- offset(YNumHorz), XtRImmediate, (XtPointer) True},
- };
- static SciPlotFontDesc font_desc_table[] =
- {
- {XtFONT_TIMES, "Times", "times", False, True},
- {XtFONT_COURIER, "Courier", "courier", True, False},
- {XtFONT_HELVETICA, "Helvetica", "helvetica", True, False},
- {XtFONT_LUCIDA, "Lucida", "lucidabright", False, False},
- {XtFONT_LUCIDASANS, "LucidaSans", "lucida", False, False},
- {XtFONT_NCSCHOOLBOOK, "NewCenturySchlbk",
- "new century schoolbook", False, True},
- {-1, NULL, NULL, False, False},
- };
- /*
- * Private function declarations
- */
- static void Redisplay();
- static void Resize();
- static Boolean SetValues();
- static void GetValuesHook();
- static void Initialize();
- static void Realize();
- static void Destroy();
- static void ComputeAll();
- static void ComputeAllDimensions();
- static void DrawAll();
- static void ItemDrawAll();
- static void ItemDraw();
- static void EraseAll();
- static void FontInit();
- static int ColorStore(SciPlotWidget w, Pixel color);
- static int FontStore();
- static int FontnumReplace();
- SciPlotClassRec sciplotClassRec =
- {
- {
- /* core_class fields */
- #ifdef MOTIF
- /* superclass */ (WidgetClass) & xmPrimitiveClassRec,
- #else
- /* superclass */ (WidgetClass) & widgetClassRec,
- #endif
- /* class_name */ "SciPlot",
- /* widget_size */ sizeof(SciPlotRec),
- /* class_initialize */ NULL,
- /* class_part_initialize */ NULL,
- /* class_inited */ False,
- /* initialize */ Initialize,
- /* initialize_hook */ NULL,
- /* realize */ Realize,
- /* actions */ NULL,
- /* num_actions */ 0,
- /* resources */ resources,
- /* num_resources */ XtNumber(resources),
- /* xrm_class */ NULLQUARK,
- /* compress_motion */ True,
- /* compress_exposure */ XtExposeCompressMultiple,
- /* compress_enterleave */ True,
- /* visible_interest */ True,
- /* destroy */ Destroy,
- /* resize */ Resize,
- /* expose */ Redisplay,
- /* set_values */ SetValues,
- /* set_values_hook */ NULL,
- /* set_values_almost */ XtInheritSetValuesAlmost,
- /* get_values_hook */ GetValuesHook,
- /* accept_focus */ NULL,
- /* version */ XtVersion,
- /* callback_private */ NULL,
- /* tm_table */ NULL,
- /* query_geometry */ NULL,
- /* display_accelerator */ XtInheritDisplayAccelerator,
- /* extension */ NULL
- },
- #ifdef MOTIF
- {
- /* primitive_class fields */
- /* border_highlight */ (XtWidgetProc) _XtInherit,
- /* border_unhighligh */ (XtWidgetProc) _XtInherit,
- /* translations */ XtInheritTranslations,
- /* arm_and_activate */ (XtActionProc)_XtInherit,
- /* syn_resources */ NULL,
- /* num_syn_resources */ 0,
- /* extension */ NULL
- },
- #endif
- {
- /* plot_class fields */
- /* dummy */ 0
- /* (some stupid compilers barf on empty structures) */
- }
- };
- WidgetClass sciplotWidgetClass = (WidgetClass) & sciplotClassRec;
- static void
- Initialize(Widget treq, Widget tnew, ArgList args, Cardinal *num)
- {
- SciPlotWidget new;
- new = (SciPlotWidget) tnew;
- new->plot.plotlist = NULL;
- new->plot.alloc_plotlist = 0;
- new->plot.num_plotlist = 0;
- new->plot.alloc_drawlist = NUMPLOTITEMALLOC;
- new->plot.drawlist = (SciPlotItem *) XtCalloc(new->plot.alloc_drawlist,
- sizeof(SciPlotItem));
- new->plot.num_drawlist = 0;
- new->plot.cmap = DefaultColormap(XtDisplay(new),
- DefaultScreen(XtDisplay(new)));
- new->plot.xlabel = (char *) XtMalloc(strlen(new->plot.TransientXLabel) + 1);
- strcpy(new->plot.xlabel, new->plot.TransientXLabel);
- new->plot.ylabel = (char *) XtMalloc(strlen(new->plot.TransientYLabel) + 1);
- strcpy(new->plot.ylabel, new->plot.TransientYLabel);
- new->plot.plotTitle = (char *) XtMalloc(strlen(new->plot.TransientPlotTitle) + 1);
- strcpy(new->plot.plotTitle, new->plot.TransientPlotTitle);
- new->plot.TransientXLabel=NULL;
- new->plot.TransientYLabel=NULL;
- new->plot.TransientPlotTitle=NULL;
- new->plot.colors = NULL;
- new->plot.num_colors = 0;
- new->plot.fonts = NULL;
- new->plot.num_fonts = 0;
- new->plot.update = FALSE;
- new->plot.UserMin.x = new->plot.UserMin.y = 0.0;
- new->plot.UserMax.x = new->plot.UserMax.y = 10.0;
- new->plot.titleFont = FontStore(new, new->plot.TitleFont);
- new->plot.labelFont = FontStore(new, new->plot.LabelFont);
- new->plot.axisFont = FontStore(new, new->plot.AxisFont);
- }
- static void
- GCInitialize(SciPlotWidget new)
- {
- XGCValues values;
- XtGCMask mask;
- long colorsave;
- values.line_style = LineSolid;
- values.line_width = 0;
- values.fill_style = FillSolid;
- values.background = WhitePixelOfScreen(XtScreen(new));
- values.background = new->core.background_pixel;
- new->plot.BackgroundColor = ColorStore(new, values.background);
- #ifdef MOTIF
- new->core.background_pixel = values.background;
- #endif
- values.foreground = colorsave = BlackPixelOfScreen(XtScreen(new));
- new->plot.TextColor = ColorStore(new, values.foreground);
- new->plot.ForegroundColor = ColorStore(new, values.foreground);
- mask = GCLineStyle | GCLineWidth | GCFillStyle | GCForeground | GCBackground;
- #ifdef DOUBLE_BUF
- new->plot.screenGC = XCreateGC(XtDisplay(new), XtWindow(new),
- mask, &values);
- new->plot.double_buf =
- XCreatePixmap(XtDisplay(new),
- XtWindow(new),
- new->core.width,
- new->core.height,
- DefaultDepth(XtDisplay(new),
- DefaultScreen(XtDisplay(new))));
- new->plot.defaultGC = XCreateGC(XtDisplay(new), new->plot.double_buf,
- mask, &values);
- values.foreground = colorsave;
- values.line_style = LineOnOffDash;
- new->plot.dashGC = XCreateGC(XtDisplay(new), new->plot.double_buf,
- mask, &values);
- #else
- new->plot.defaultGC = XCreateGC(XtDisplay(new), XtWindow(new),
- mask, &values);
-
- values.foreground = colorsave;
- values.line_style = LineOnOffDash;
- new->plot.dashGC = XCreateGC(XtDisplay(new),XtWindow(new), mask, &values);
- #endif
- }
- static void
- Realize(Widget aw, XtValueMask * value_mask, XSetWindowAttributes * attributes)
- {
- SciPlotWidget w = (SciPlotWidget) aw;
- #define superclass (&widgetClassRec)
- (*superclass->core_class.realize) (aw, value_mask, attributes);
- #undef superclass
- GCInitialize(w);
- }
- static void
- Destroy(SciPlotWidget w)
- {
- int i;
- SciPlotFont *pf;
- SciPlotList *p;
- EraseAll(w);
- XFreeGC(XtDisplay(w), w->plot.defaultGC);
- w->plot.defaultGC = 0;
- #ifdef DOUBLE_BUF
- XFreeGC(XtDisplay(w), w->plot.screenGC);
- XFreePixmap(XtDisplay(w), w->plot.double_buf);
- w->plot.screenGC = 0;
- w->plot.double_buf = 0;
- #endif
- XFreeGC(XtDisplay(w), w->plot.dashGC);
- XtFree((char *) w->plot.xlabel);
- XtFree((char *) w->plot.ylabel);
- XtFree((char *) w->plot.plotTitle);
- for (i = 0; i < w->plot.num_fonts; i++) {
- pf = &w->plot.fonts[i];
- XFreeFont(XtDisplay((Widget) w), pf->font);
- }
- XtFree((char *) w->plot.fonts);
- XtFree((char *) w->plot.colors);
- for (i = 0; i < w->plot.alloc_plotlist; i++) {
- p = w->plot.plotlist + i;
- if (p->allocated > 0)
- XtFree((char *) p->data);
- if (p->legend)
- XtFree(p->legend);
- }
- if (w->plot.alloc_plotlist > 0)
- XtFree((char *) w->plot.plotlist);
- XtFree((char *) w->plot.drawlist);
- }
- static Boolean
- SetValues(SciPlotWidget current, SciPlotWidget request, SciPlotWidget new,
- ArgList args, Cardinal nargs)
- {
- Boolean redisplay = FALSE;
- if (current->plot.XLog != new->plot.XLog)
- redisplay = TRUE;
- else if (current->plot.YLog != new->plot.YLog)
- redisplay = TRUE;
- else if (current->plot.XOrigin != new->plot.XOrigin)
- redisplay = TRUE;
- else if (current->plot.YOrigin != new->plot.YOrigin)
- redisplay = TRUE;
- else if (current->plot.XAxisNumbers != new->plot.XAxisNumbers)
- redisplay = TRUE;
- else if (current->plot.YAxisNumbers != new->plot.YAxisNumbers)
- redisplay = TRUE;
- else if (current->plot.DrawMajor != new->plot.DrawMajor)
- redisplay = TRUE;
- else if (current->plot.DrawMajorTics != new->plot.DrawMajorTics)
- redisplay = TRUE;
- else if (current->plot.DrawMinor != new->plot.DrawMinor)
- redisplay = TRUE;
- else if (current->plot.DrawMinorTics != new->plot.DrawMinorTics)
- redisplay = TRUE;
- else if (current->plot.ChartType != new->plot.ChartType)
- redisplay = TRUE;
- else if (current->plot.Degrees != new->plot.Degrees)
- redisplay = TRUE;
- else if (current->plot.ShowLegend != new->plot.ShowLegend)
- redisplay = TRUE;
- else if (current->plot.ShowTitle != new->plot.ShowTitle)
- redisplay = TRUE;
- else if (current->plot.ShowXLabel != new->plot.ShowXLabel)
- redisplay = TRUE;
- else if (current->plot.ShowYLabel != new->plot.ShowYLabel)
- redisplay = TRUE;
- else if (current->plot.ShowTitle != new->plot.ShowTitle)
- redisplay = TRUE;
- else if (current->plot.Monochrome != new->plot.Monochrome)
- redisplay = TRUE;
-
- if (new->plot.TransientXLabel) {
- if (current->plot.TransientXLabel != new->plot.TransientXLabel ||
- strcmp(new->plot.TransientXLabel,current->plot.xlabel)!=0) {
- redisplay = TRUE;
- XtFree(current->plot.xlabel);
- new->plot.xlabel = (char *) XtMalloc(strlen(new->plot.TransientXLabel) + 1);
- strcpy(new->plot.xlabel, new->plot.TransientXLabel);
- new->plot.TransientXLabel=NULL;
- }
- }
- if (new->plot.TransientYLabel) {
- if (current->plot.TransientYLabel != new->plot.TransientYLabel ||
- strcmp(new->plot.TransientYLabel,current->plot.ylabel)!=0) {
- redisplay = TRUE;
- XtFree(current->plot.ylabel);
- new->plot.ylabel = (char *) XtMalloc(strlen(new->plot.TransientYLabel) + 1);
- strcpy(new->plot.ylabel, new->plot.TransientYLabel);
- new->plot.TransientYLabel=NULL;
- }
- }
- if (new->plot.TransientPlotTitle) {
- if (current->plot.TransientPlotTitle != new->plot.TransientPlotTitle ||
- strcmp(new->plot.TransientPlotTitle,current->plot.plotTitle)!=0) {
- redisplay = TRUE;
- XtFree(current->plot.plotTitle);
- new->plot.plotTitle = (char *) XtMalloc(strlen(new->plot.TransientPlotTitle) + 1);
- strcpy(new->plot.plotTitle, new->plot.TransientPlotTitle);
- new->plot.TransientPlotTitle=NULL;
- }
- }
-
- if (current->plot.AxisFont != new->plot.AxisFont) {
- redisplay = TRUE;
- FontnumReplace(new, new->plot.axisFont, new->plot.AxisFont);
- }
- if (current->plot.TitleFont != new->plot.TitleFont) {
- redisplay = TRUE;
- FontnumReplace(new, new->plot.titleFont, new->plot.TitleFont);
- }
- if (current->plot.LabelFont != new->plot.LabelFont) {
- redisplay = TRUE;
- FontnumReplace(new, new->plot.labelFont, new->plot.LabelFont);
- }
- new->plot.update = redisplay;
- return redisplay;
- }
- static void
- GetValuesHook(SciPlotWidget w, ArgList args, Cardinal *num_args)
- {
- int i;
- char **loc;
- for (i=0; i<*num_args; i++) {
- loc=(char **)args[i].value;
- if (strcmp(args[i].name,XtNplotTitle)==0)
- *loc=w->plot.plotTitle;
- else if (strcmp(args[i].name,XtNxLabel)==0)
- *loc=w->plot.xlabel;
- else if (strcmp(args[i].name,XtNyLabel)==0)
- *loc=w->plot.ylabel;
-
- }
- }
- static void
- Redisplay(SciPlotWidget w)
- {
- if (!XtIsRealized((Widget)w))
- return;
-
- if (w->plot.update) {
- Resize(w);
- w->plot.update = FALSE;
- }
- else {
- ItemDrawAll(w);
- }
- }
- static void
- Resize(SciPlotWidget w)
- {
- if (!XtIsRealized((Widget)w))
- return;
-
- EraseAll(w);
- ComputeAll(w);
- DrawAll(w);
- }
- /*
- * Private SciPlot utility functions
- */
- static int ColorStore(SciPlotWidget w, Pixel color)
- {
- w->plot.num_colors++;
- w->plot.colors = (Pixel *) XtRealloc((char *) w->plot.colors,
- sizeof(Pixel) * w->plot.num_colors);
- w->plot.colors[w->plot.num_colors - 1] = color;
- return w->plot.num_colors - 1;
- }
- static void
- FontnumStore (SciPlotWidget w, int fontnum, int flag)
- {
- SciPlotFont *pf;
- int fontflag, sizeflag, attrflag;
- pf = &w->plot.fonts[fontnum];
- fontflag = flag & XtFONT_NAME_MASK;
- sizeflag = flag & XtFONT_SIZE_MASK;
- attrflag = flag & XtFONT_ATTRIBUTE_MASK;
- switch (fontflag) {
- case XtFONT_TIMES:
- case XtFONT_COURIER:
- case XtFONT_HELVETICA:
- case XtFONT_LUCIDA:
- case XtFONT_LUCIDASANS:
- case XtFONT_NCSCHOOLBOOK:
- break;
- default:
- fontflag = XtFONT_NAME_DEFAULT;
- break;
- }
- if (sizeflag < 1)
- sizeflag = XtFONT_SIZE_DEFAULT;
- switch (attrflag) {
- case XtFONT_BOLD:
- case XtFONT_ITALIC:
- case XtFONT_BOLD_ITALIC:
- break;
- default:
- attrflag = XtFONT_ATTRIBUTE_DEFAULT;
- break;
- }
- pf->id = flag;
- FontInit(w, pf);
- }
- static int
- FontnumReplace (SciPlotWidget w, int fontnum, int flag)
- {
- SciPlotFont *pf;
- pf = &w->plot.fonts[fontnum];
- XFreeFont(XtDisplay(w), pf->font);
- FontnumStore(w, fontnum, flag);
- return fontnum;
- }
- static int
- FontStore (SciPlotWidget w, int flag)
- {
- int fontnum;
- w->plot.num_fonts++;
- w->plot.fonts = (SciPlotFont *) XtRealloc((char *) w->plot.fonts,
- sizeof(SciPlotFont) * w->plot.num_fonts);
- fontnum = w->plot.num_fonts - 1;
- FontnumStore(w, fontnum, flag);
- return fontnum;
- }
- static SciPlotFontDesc *
- FontDescLookup (int flag)
- {
- SciPlotFontDesc *pfd;
- pfd = font_desc_table;
- while (pfd->flag >= 0) {
- #ifdef DEBUG_SCIPLOT
- printf("checking if %d == %d (font %s)\n",
- flag & XtFONT_NAME_MASK, pfd->flag, pfd->PostScript);
- #endif
- if ((flag & XtFONT_NAME_MASK) == pfd->flag)
- return pfd;
- pfd++;
- }
- return NULL;
- }
- static void
- FontnumPostScriptString (SciPlotWidget w, int fontnum, char *str)
- {
- char temp[128];
- int flag, bold, italic;
- SciPlotFontDesc *pfd;
- flag = w->plot.fonts[fontnum].id;
- pfd = FontDescLookup(flag);
- if (pfd) {
- strcpy(temp, pfd->PostScript);
- bold = False;
- italic = False;
- if (flag & XtFONT_BOLD) {
- bold = True;
- strcat(temp, "-Bold");
- }
- if (flag & XtFONT_ITALIC) {
- italic = True;
- if (!bold)
- strcat(temp, "-");
- if (pfd->PSUsesOblique)
- strcat(temp, "Oblique");
- else
- strcat(temp, "Italic");
- }
- if (!bold && !italic && pfd->PSUsesRoman) {
- strcat(temp, "-Roman");
- }
- sprintf(str, "/%s findfont %d scalefont",
- temp,
- (flag & XtFONT_SIZE_MASK));
- }
- else
- sprintf(str, "/Courier findfond 10 scalefont");
- }
- static void
- FontX11String (int flag, char *str)
- {
- SciPlotFontDesc *pfd;
- pfd = FontDescLookup(flag);
- if (pfd) {
- sprintf(str, "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-*-*",
- pfd->X11,
- (flag & XtFONT_BOLD ? "bold" : "medium"),
- (flag & XtFONT_ITALIC ? (pfd->PSUsesOblique ? "o" : "i") : "r"),
- (flag & XtFONT_SIZE_MASK));
- }
- else
- sprintf(str, "fixed");
- #ifdef DEBUG_SCIPLOT
- printf("font string=%s\n", str);
- #endif
- }
- static void
- FontInit (SciPlotWidget w, SciPlotFont *pf)
- {
- char str[256], **list;
- int num;
- FontX11String(pf->id, str);
- list = XListFonts(XtDisplay(w), str, 100, &num);
- #ifdef DEBUG_SCIPLOT
- if (1) {
- int i;
- i = 0;
- while (i < num) {
- printf("Found font: %s\n", list[i]);
- i++;
- }
- }
- #endif
- if (num <= 0) {
- pf->id &= ~XtFONT_ATTRIBUTE_MASK;
- pf->id |= XtFONT_ATTRIBUTE_DEFAULT;
- FontX11String(pf->id, str);
- list = XListFonts(XtDisplay(w), str, 100, &num);
- #ifdef DEBUG_SCIPLOT
- if (1) {
- int i;
- i = 0;
- while (i < num) {
- printf("Attr reset: found: %s\n", list[i]);
- i++;
- }
- }
- #endif
- }
- if (num <= 0) {
- pf->id &= ~XtFONT_NAME_MASK;
- pf->id |= XtFONT_NAME_DEFAULT;
- FontX11String(pf->id, str);
- list = XListFonts(XtDisplay(w), str, 100, &num);
- #ifdef DEBUG_SCIPLOT
- if (1) {
- int i;
- i = 0;
- while (i < num) {
- printf("Name reset: found: %s\n", list[i]);
- i++;
- }
- }
- #endif
- }
- if (num <= 0) {
- pf->id &= ~XtFONT_SIZE_MASK;
- pf->id |= XtFONT_SIZE_DEFAULT;
- FontX11String(pf->id, str);
- list = XListFonts(XtDisplay(w), str, 100, &num);
- #ifdef DEBUG_SCIPLOT
- if (1) {
- int i;
- i = 0;
- while (i < num) {
- printf("Size reset: found: %s\n", list[i]);
- i++;
- }
- }
- #endif
- }
- if (num <= 0)
- strcpy(str, "fixed");
- else
- XFreeFontNames(list);
- pf->font = XLoadQueryFont(XtDisplay(w), str);
- }
- static XFontStruct *
- FontFromFontnum (SciPlotWidget w, int fontnum)
- {
- XFontStruct *f;
- if (fontnum >= w->plot.num_fonts)
- fontnum = 0;
- f = w->plot.fonts[fontnum].font;
- return f;
- }
- static real
- FontHeight(XFontStruct *f)
- {
- return (real) (f->max_bounds.ascent + f->max_bounds.descent);
- }
- static real
- FontnumHeight(SciPlotWidget w, int fontnum)
- {
- XFontStruct *f;
- f = FontFromFontnum(w, fontnum);
- return FontHeight(f);
- }
- static real
- FontDescent(XFontStruct *f)
- {
- return (real) (f->max_bounds.descent);
- }
- static real
- FontnumDescent(SciPlotWidget w, int fontnum)
- {
- XFontStruct *f;
- f = FontFromFontnum(w, fontnum);
- return FontDescent(f);
- }
- static real
- FontAscent(XFontStruct *f)
- {
- return (real) (f->max_bounds.ascent);
- }
- static real
- FontnumAscent(SciPlotWidget w, int fontnum)
- {
- XFontStruct *f;
- f = FontFromFontnum(w, fontnum);
- return FontAscent(f);
- }
- static real
- FontTextWidth(XFontStruct *f, char *c)
- {
- return (real) XTextWidth(f, c, strlen(c));
- }
- static real
- FontnumTextWidth(SciPlotWidget w, int fontnum, char *c)
- {
- XFontStruct *f;
- f = FontFromFontnum(w, fontnum);
- return FontTextWidth(f, c);
- }
- /*
- * Private List functions
- */
- static int
- _ListNew (SciPlotWidget w)
- {
- int index;
- SciPlotList *p;
- Boolean found;
- /* First check to see if there is any free space in the index */
- found = FALSE;
- for (index = 0; index < w->plot.num_plotlist; index++) {
- p = w->plot.plotlist + index;
- if (!p->used) {
- found = TRUE;
- break;
- }
- }
- /* If no space is found, increase the size of the index */
- if (!found) {
- w->plot.num_plotlist++;
- if (w->plot.alloc_plotlist == 0) {
- w->plot.alloc_plotlist = NUMPLOTLINEALLOC;
- w->plot.plotlist = (SciPlotList *) XtCalloc(w->plot.alloc_plotlist, sizeof(SciPlotList));
- if (!w->plot.plotlist) {
- printf("Can't calloc memory for SciPlotList\n");
- exit(1);
- }
- w->plot.alloc_plotlist = NUMPLOTLINEALLOC;
- }
- else if (w->plot.num_plotlist > w->plot.alloc_plotlist) {
- w->plot.alloc_plotlist += NUMPLOTLINEALLOC;
- w->plot.plotlist = (SciPlotList *) XtRealloc((char *) w->plot.plotlist,
- w->plot.alloc_plotlist * sizeof(SciPlotList));
- if (!w->plot.plotlist) {
- printf("Can't realloc memory for SciPlotList\n");
- exit(1);
- }
- }
- index = w->plot.num_plotlist - 1;
- p = w->plot.plotlist + index;
- }
- p->LineStyle = p->LineColor = p->PointStyle = p->PointColor = 0;
- p->number = p->allocated = 0;
- p->data = NULL;
- p->legend = NULL;
- p->draw = p->used = TRUE;
- p->markersize = (real) w->plot.DefaultMarkerSize;
- return index;
- }
- static void
- _ListDelete (SciPlotList *p)
- {
- p->draw = p->used = FALSE;
- p->number = p->allocated = 0;
- if (p->data)
- XtFree((char *) p->data);
- p->data = NULL;
- if (p->legend)
- XtFree((char *) p->legend);
- p->legend = NULL;
- }
- static SciPlotList *
- _ListFind (SciPlotWidget w, int id)
- {
- SciPlotList *p;
- if ((id >= 0) && (id < w->plot.num_plotlist)) {
- p = w->plot.plotlist + id;
- if (p->used)
- return p;
- }
- return NULL;
- }
- static void
- _ListSetStyle (SciPlotList *p, int pcolor, int pstyle, int lcolor, int lstyle)
- {
- /* Note! Do checks in here later on... */
- if (lstyle >= 0)
- p->LineStyle = lstyle;
- if (lcolor >= 0)
- p->LineColor = lcolor;
- if (pstyle >= 0)
- p->PointStyle = pstyle;
- if (pcolor >= 0)
- p->PointColor = pcolor;
- }
- static void
- _ListSetLegend (SciPlotList *p, char *legend)
- {
- /* Note! Do checks in here later on... */
- p->legend = (char *) XtMalloc(strlen(legend) + 1);
- strcpy(p->legend, legend);
- }
- static void
- _ListAllocData (SciPlotList *p, int num)
- {
- if (p->data) {
- XtFree((char *) p->data);
- p->allocated = 0;
- }
- p->allocated = num + NUMPLOTDATAEXTRA;
- p->data = (realpair *) XtCalloc(p->allocated, sizeof(realpair));
- if (!p->data) {
- p->number = p->allocated = 0;
- }
- }
- static void
- _ListReallocData (SciPlotList *p, int more)
- {
- if (!p->data) {
- _ListAllocData(p, more);
- }
- else if (p->number + more > p->allocated) {
- p->allocated += more + NUMPLOTDATAEXTRA;
- p->data = (realpair *) XtRealloc((char *) p->data, p->allocated * sizeof(realpair));
- if (!p->data) {
- p->number = p->allocated = 0;
- }
- }
- }
- static void
- _ListAddReal (SciPlotList *p, int num, real *xlist, real *ylist)
- {
- int i;
- _ListReallocData(p, num);
- if (p->data) {
- for (i = 0; i < num; i++) {
- p->data[i + p->number].x = xlist[i];
- p->data[i + p->number].y = ylist[i];
- }
- p->number += num;
- }
- }
- static void
- _ListAddFloat (SciPlotList *p, int num, float *xlist, float *ylist)
- {
- int i;
- _ListReallocData(p, num);
- if (p->data) {
- for (i = 0; i < num; i++) {
- p->data[i + p->number].x = xlist[i];
- p->data[i + p->number].y = ylist[i];
- }
- p->number += num;
- }
- }
- static void
- _ListAddDouble (SciPlotList *p, int num, double *xlist, double *ylist)
- {
- int i;
- _ListReallocData(p, num);
- if (p->data) {
- for (i = 0; i < num; i++) {
- p->data[i + p->number].x = xlist[i];
- p->data[i + p->number].y = ylist[i];
- }
- p->number += num;
- }
- }
- static void
- _ListSetReal(SciPlotList *p, int num, real *xlist, real *ylist)
- {
- if ((!p->data) || (p->allocated < num))
- _ListAllocData(p, num);
- p->number = 0;
- _ListAddReal(p, num, xlist, ylist);
- }
- static void
- _ListSetFloat (SciPlotList *p, int num, float *xlist, float *ylist)
- {
- if ((!p->data) || (p->allocated < num))
- _ListAllocData(p, num);
- p->number = 0;
- _ListAddFloat(p, num, xlist, ylist);
- }
- static void
- _ListSetDouble (SciPlotList *p, int num, double *xlist, double *ylist)
- {
- if ((!p->data) || (p->allocated < num))
- _ListAllocData(p, num);
- p->number = 0;
- _ListAddDouble(p, num, xlist, ylist);
- }
- /*
- * Private SciPlot functions
- */
- /*
- * The following vertical text drawing routine uses the "Fill Stippled" idea
- * found in xvertext-5.0, by Alan Richardson (mppa3@syma.sussex.ac.uk).
- *
- * The following code is my interpretation of his idea, including some
- * hacked together excerpts from his source. The credit for the clever bits
- * belongs to him.
- *
- * To be complete, portions of the subroutine XDrawVString are
- * Copyright (c) 1993 Alan Richardson (mppa3@syma.sussex.ac.uk)
- */
- static void
- XDrawVString (Display *display, Drawable win, GC gc, int x, int y, char *str, int len, XFontStruct *f)
- {
- XImage *before, *after;
- char *dest, *source;
- int xloop, yloop, xdest, ydest;
- Pixmap pix, rotpix;
- int width, height;
- GC drawGC;
- width = (int) FontTextWidth(f, str);
- height = (int) FontHeight(f);
- pix = XCreatePixmap(display, win, width, height, 1);
- rotpix = XCreatePixmap(display, win, height, width, 1);
- drawGC = XCreateGC(display, pix, 0L, NULL);
- XSetBackground(display, drawGC, 0);
- XSetFont(display, drawGC, f->fid);
- XSetForeground(display, drawGC, 0);
- XFillRectangle(display, pix, drawGC, 0, 0, width, height);
- XFillRectangle(display, rotpix, drawGC, 0, 0, height, width);
- XSetForeground(display, drawGC, 1);
- XDrawImageString(display, pix, drawGC, 0, (int) FontAscent(f),
- str, strlen(str));
- source = (char *) XtCalloc((((width + 7) / 8) * height), 1);
- before = XCreateImage(display, DefaultVisual(display, DefaultScreen(display)),
- 1, XYPixmap, 0, source, width, height, 8, 0);
- before->byte_order = before->bitmap_bit_order = MSBFirst;
- XGetSubImage(display, pix, 0, 0, width, height, 1L, XYPixmap, before, 0, 0);
- source = (char *) XtCalloc((((height + 7) / 8) * width), 1);
- after = XCreateImage(display, DefaultVisual(display, DefaultScreen(display)),
- 1, XYPixmap, 0, source, height, width, 8, 0);
- after->byte_order = after->bitmap_bit_order = MSBFirst;
- for (yloop = 0; yloop < height; yloop++) {
- for (xloop = 0; xloop < width; xloop++) {
- source = before->data + (xloop / 8) +
- (yloop * before->bytes_per_line);
- if (*source & (128 >> (xloop % 8))) {
- dest = after->data + (yloop / 8) +
- ((width - 1 - xloop) * after->bytes_per_line);
- *dest |= (128 >> (yloop % 8));
- }
- }
- }
- #ifdef DEBUG_SCIPLOT_VTEXT
- if (1) {
- char sourcebit;
- for (yloop = 0; yloop < before->height; yloop++) {
- for (xloop = 0; xloop < before->width; xloop++) {
- source = before->data + (xloop / 8) +
- (yloop * before->bytes_per_line);
- sourcebit = *source & (128 >> (xloop % 8));
- if (sourcebit)
- putchar('X');
- else
- putchar('.');
- }
- putchar('\n');
- }
- for (yloop = 0; yloop < after->height; yloop++) {
- for (xloop = 0; xloop < after->width; xloop++) {
- source = after->data + (xloop / 8) +
- (yloop * after->bytes_per_line);
- sourcebit = *source & (128 >> (xloop % 8));
- if (sourcebit)
- putchar('X');
- else
- putchar('.');
- }
- putchar('\n');
- }
- }
- #endif
- xdest = x - (int) FontAscent(f);
- if (xdest < 0)
- xdest = 0;
- ydest = y - width;
- XPutImage(display, rotpix, drawGC, after, 0, 0, 0, 0,
- after->width, after->height);
- XSetFillStyle(display, gc, FillStippled);
- XSetStipple(display, gc, rotpix);
- XSetTSOrigin(display, gc, xdest, ydest);
- XFillRectangle(display, win, gc, xdest, ydest, after->width, after->height);
- XSetFillStyle(display, gc, FillSolid);
- XFreeGC(display, drawGC);
- XDestroyImage(before);
- XDestroyImage(after);
- XFreePixmap(display, pix);
- XFreePixmap(display, rotpix);
- /* Note that it appears that there is a memory leak here, but XDestroyImage
- * frees the image data that is XtCalloc'ed
- */
- }
- static char dots[] =
- {2, 1, 1};
- static char widedots[] =
- {2, 1, 4};
- static GC
- ItemGetGC (SciPlotWidget w, SciPlotItem *item)
- {
- GC gc;
- short color;
-
- switch (item->kind.any.style) {
- case XtLINE_SOLID:
- gc = w->plot.defaultGC;
- break;
- case XtLINE_DOTTED:
- XSetDashes(XtDisplay(w), w->plot.dashGC, 0, &dots[1],
- (int) dots[0]);
- gc = w->plot.dashGC;
- break;
- case XtLINE_WIDEDOT:
- XSetDashes(XtDisplay(w), w->plot.dashGC, 0, &widedots[1],
- (int) widedots[0]);
- gc = w->plot.dashGC;
- break;
- default:
- return NULL;
- break;
- }
- if (w->plot.Monochrome)
- if (item->kind.any.color > 0)
- color = w->plot.ForegroundColor;
- else
- color = w->plot.BackgroundColor;
- else if (item->kind.any.color >= w->plot.num_colors)
- color = w->plot.ForegroundColor;
- else if (item->kind.any.color <= 0)
- color = w->plot.BackgroundColor;
- else
- color = item->kind.any.color;
- XSetForeground(XtDisplay(w), gc, w->plot.colors[color]);
- return gc;
- }
- static GC
- ItemGetFontGC (SciPlotWidget w, SciPlotItem *item)
- {
- GC gc;
- short color, fontnum;
- gc = w->plot.dashGC;
- if (w->plot.Monochrome)
- if (item->kind.any.color > 0)
- color = w->plot.TextColor;
- else
- color = w->plot.BackgroundColor;
- else if (item->kind.any.color >= w->plot.num_colors)
- color = w->plot.TextColor;
- else if (item->kind.any.color <= 0)
- color = w->plot.BackgroundColor;
- else
- color = item->kind.any.color;
- XSetForeground(XtDisplay(w), gc, w->plot.colors[color]);
- if (item->kind.text.font >= w->plot.num_fonts)
- fontnum = 0;
- else
- fontnum = item->kind.text.font;
- /*
- * fontnum==0 hack: 0 is supposed to be the default font, but the program
- * can't seem to get the default font ID from the GC for some reason. So,
- * use a different GC where the default font still exists.
- */
- XSetFont(XtDisplay(w), gc, w->plot.fonts[fontnum].font->fid);
- return gc;
- }
- static void
- ItemDraw (SciPlotWidget w, SciPlotItem *item)
- {
- XPoint point[8];
- XSegment seg;
- XRectangle rect;
- int i;
- GC gc;
- Drawable win;
- if (!XtIsRealized((Widget) w))
- return;
-
- #ifdef DOUBLE_BUF
- win = w->plot.double_buf;
- #else
- win = XtWindow(w);
- #endif
-
- if ((item->type > SciPlotStartTextTypes) && (item->type < SciPlotEndTextTypes))
- gc = ItemGetFontGC(w, item);
- else
- gc = ItemGetGC(w, item);
- if (!gc)
- return;
- switch (item->type) {
- case SciPlotLine:
- seg.x1 = (short) item->kind.line.x1;
- seg.y1 = (short) item->kind.line.y1;
- seg.x2 = (short) item->kind.line.x2;
- seg.y2 = (short) item->kind.line.y2;
- XDrawSegments(XtDisplay(w), win, gc,
- &seg, 1);
- break;
- case SciPlotRect:
- XDrawRectangle(XtDisplay(w), win, gc,
- (int) (item->kind.rect.x),
- (int) (item->kind.rect.y),
- (unsigned int) (item->kind.rect.w),
- (unsigned int) (item->kind.rect.h));
- break;
- case SciPlotFRect:
- XFillRectangle(XtDisplay(w), win, gc,
- (int) (item->kind.rect.x),
- (int) (item->kind.rect.y),
- (unsigned int) (item->kind.rect.w),
- (unsigned int) (item->kind.rect.h));
- XDrawRectangle(XtDisplay(w), win, gc,
- (int) (item->kind.rect.x),
- (int) (item->kind.rect.y),
- (unsigned int) (item->kind.rect.w),
- (unsigned int) (item->kind.rect.h));
- break;
- case SciPlotPoly:
- i = 0;
- while (i < item->kind.poly.count) {
- point[i].x = (int) item->kind.poly.x[i];
- point[i].y = (int) item->kind.poly.y[i];
- i++;
- }
- point[i].x = (int) item->kind.poly.x[0];
- point[i].y = (int) item->kind.poly.y[0];
- XDrawLines(XtDisplay(w), win, gc,
- point, i + 1, CoordModeOrigin);
- break;
- case SciPlotFPoly:
- i = 0;
- while (i < item->kind.poly.count) {
- point[i].x = (int) item->kind.poly.x[i];
- point[i].y = (int) item->kind.poly.y[i];
- i++;
- }
- point[i].x = (int) item->kind.poly.x[0];
- point[i].y = (int) item->kind.poly.y[0];
- XFillPolygon(XtDisplay(w), win, gc,
- point, i + 1, Complex, CoordModeOrigin);
- XDrawLines(XtDisplay(w), win, gc,
- point, i + 1, CoordModeOrigin);
- break;
- case SciPlotCircle:
- XDrawArc(XtDisplay(w), win, gc,
- (int) (item->kind.circ.x - item->kind.circ.r),
- (int) (item->kind.circ.y - item->kind.circ.r),
- (unsigned int) (item->kind.circ.r * 2),
- (unsigned int) (item->kind.circ.r * 2),
- 0 * 64, 360 * 64);
- break;
- case SciPlotFCircle:
- XFillArc(XtDisplay(w), win, gc,
- (int) (item->kind.circ.x - item->kind.circ.r),
- (int) (item->kind.circ.y - item->kind.circ.r),
- (unsigned int) (item->kind.circ.r * 2),
- (unsigned int) (item->kind.circ.r * 2),
- 0 * 64, 360 * 64);
- break;
- case SciPlotText:
- XDrawString(XtDisplay(w), win, gc,
- (int) (item->kind.text.x), (int) (item->kind.text.y),
- item->kind.text.text,
- (int) item->kind.text.length);
- break;
- case SciPlotVText:
- XDrawVString(XtDisplay(w), win, gc,
- (int) (item->kind.text.x), (int) (item->kind.text.y),
- item->kind.text.text,
- (int) item->kind.text.length,
- FontFromFontnum(w, item->kind.text.font));
- break;
- case SciPlotClipRegion:
- rect.x = (short) item->kind.line.x1;
- rect.y = (short) item->kind.line.y1;
- rect.width = (short) item->kind.line.x2;
- rect.height = (short) item->kind.line.y2;
- XSetClipRectangles(XtDisplay(w), w->plot.dashGC, 0, 0, &rect, 1, Unsorted);
- XSetClipRectangles(XtDisplay(w), w->plot.defaultGC, 0, 0, &rect, 1, Unsorted);
- break;
- case SciPlotClipClear:
- XSetClipMask(XtDisplay(w), w->plot.dashGC, None);
- XSetClipMask(XtDisplay(w), w->plot.defaultGC, None);
- break;
- default:
- break;
- }
- }
- static void
- ItemDrawAll (SciPlotWidget w)
- {
- SciPlotItem *item;
- int i;
- if (!XtIsRealized((Widget) w))
- return;
- item = w->plot.drawlist;
- i = 0;
- while (i < w->plot.num_drawlist) {
- ItemDraw(w, item);
- i++;
- item++;
- }
- }
- /*
- * PostScript (r) functions ------------------------------------------------
- *
- */
- typedef struct {
- char *command;
- char *prolog;
- } PScommands;
- static PScommands psc[] =
- {
- {"ma", "moveto"},
- {"da", "lineto stroke newpath"},
- {"la", "lineto"},
- {"poly", "closepath stroke newpath"},
- {"fpoly", "closepath fill newpath"},
- {"box", "1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath stroke newpath"},
- {"fbox", "1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath fill newpath"},
- {"clipbox", "gsave 1 index 0 rlineto 0 exch rlineto neg 0 rlineto closepath clip newpath"},
- {"unclip", "grestore newpath"},
- {"cr", "0 360 arc stroke newpath"},
- {"fcr", "0 360 arc fill newpath"},
- {"vma", "gsave moveto 90 rotate"},
- {"norm", "grestore"},
- {"solid", "[] 0 setdash"},
- {"dot", "[.25 2] 0 setdash"},
- {"widedot", "[.25 8] 0 setdash"},
- {"rgb", "setrgbcolor"},
- {NULL, NULL}
- };
- enum PSenums {
- PSmoveto, PSlineto,
- PSpolyline, PSendpoly, PSendfill,
- PSbox, PSfbox,
- PSclipbox, PSunclip,
- PScircle, PSfcircle,
- PSvmoveto, PSnormal,
- PSsolid, PSdot, PSwidedot,
- PSrgb
- };
- static void
- ItemPSDrawAll (SciPlotWidget w, FILE *fd, double yflip, Boolean usecolor)
- {
- int i, loopcount;
- SciPlotItem *item;
- XcmsColor currentcolor;
- int previousfont, previousline, currentfont, currentline, previouscolor;
- item = w->plot.drawlist;
- loopcount = 0;
- previousfont = 0;
- previouscolor = -1;
- previousline = XtLINE_SOLID;
- while (loopcount < w->plot.num_drawlist) {
- /* 2 switch blocks: 1st sets up defaults, 2nd actually draws things. */
- currentline = previousline;
- currentfont = previousfont;
- switch (item->type) {
- case SciPlotLine:
- case SciPlotCircle:
- currentline = item->kind.any.style;
- break;
- default:
- break;
- }
- if (currentline != XtLINE_NONE) {
- if (currentline != previousline) {
- switch (item->kind.any.style) {
- case XtLINE_SOLID:
- fprintf(fd, "%s ", psc[PSsolid].command);
- break;
- case XtLINE_DOTTED:
- fprintf(fd, "%s ", psc[PSdot].command);
- break;
- case XtLINE_WIDEDOT:
- fprintf(fd, "%s ", psc[PSwidedot].command);
- break;
- }
- previousline = currentline;
- }
- if (usecolor && item->kind.any.color != previouscolor) {
-
- /* Get Pixel index */
- currentcolor.pixel = w->plot.colors[item->kind.any.color];
- /* Get RGBi components [0.0,1.0] */
- XcmsQueryColor( XtDisplay(w), w->plot.cmap, ¤tcolor,
- XcmsRGBiFormat );
- /* output PostScript command */
- fprintf(fd, "%f %f %f %s ", currentcolor.spec.RGBi.red,
- currentcolor.spec.RGBi.green, currentcolor.spec.RGBi.blue,
- psc[PSrgb].command);
- previouscolor=item->kind.any.color;
-
- }
- switch (item->type) {
- case SciPlotLine:
- fprintf(fd, "%.2f %.2f %s %.2f %.2f %s\n",
- item->kind.line.x1, yflip - item->kind.line.y1,
- psc[PSmoveto].command,
- item->kind.line.x2, yflip - item->kind.line.y2,
- psc[PSlineto].command);
- break;
- case SciPlotRect:
- fprintf(fd, "%.2f %.2f %s %.2f %.2f %s\n",
- item->kind.rect.x,
- yflip - item->kind.rect.y - (item->kind.rect.h - 1.0),
- psc[PSmoveto].command,
- item->kind.rect.w - 1.0, item->kind.rect.h - 1.0,
- psc[PSbox].command);
- break;
- case SciPlotFRect:
- fprintf(fd, "%.2f %.2f %s %.2f %.2f %s\n",
- item->kind.rect.x,
- yflip - item->kind.rect.y - (item->kind.rect.h - 1.0),
- psc[PSmoveto].command,
- item->kind.rect.w - 1.0, item->kind.rect.h - 1.0,
- psc[PSfbox].command);
- break;
- case SciPlotPoly:
- fprintf(fd, "%.2f %.2f %s ",
- item->kind.poly.x[0], yflip - item->kind.poly.y[0],
- psc[PSmoveto].command);
- for (i = 1; i < item->kind.poly.count; i++) {
- fprintf(fd, "%.2f %.2f %s ",
- item->kind.poly.x[i],
- yflip - item->kind.poly.y[i],
- psc[PSpolyline].command);
- }
- fprintf(fd, "%s\n", psc[PSendpoly].command);
- break;
- case SciPlotFPoly:
- fprintf(fd, "%.2f %.2f %s ",
- item->kind.poly.x[0], yflip - item->kind.poly.y[0],
- psc[PSmoveto].command);
- for (i = 1; i < item->kind.poly.count; i++) {
- fprintf(fd, "%.2f %.2f %s ",
- item->kind.poly.x[i],
- yflip - item->kind.poly.y[i],
- psc[PSpolyline].command);
- }
- fprintf(fd, "%s\n", psc[PSendfill].command);
- break;
- case SciPlotCircle:
- fprintf(fd, "%.2f %.2f %.2f %s\n",
- item->kind.circ.x, yflip - item->kind.circ.y,
- item->kind.circ.r,
- psc[PScircle].command);
- break;
- case SciPlotFCircle:
- fprintf(fd, "%.2f %.2f %.2f %s\n",
- item->kind.circ.x, yflip - item->kind.circ.y,
- item->kind.circ.r,
- psc[PSfcircle].command);
- break;
- case SciPlotText:
- fprintf(fd, "font-%d %.2f %.2f %s (%s) show\n",
- item->kind.text.font,
- item->kind.text.x, yflip - item->kind.text.y,
- psc[PSmoveto].command,
- item->kind.text.text);
- break;
- case SciPlotVText:
- fprintf(fd, "font-%d %.2f %.2f %s (%s) show %s\n",
- item->kind.text.font,
- item->kind.text.x, yflip - item->kind.text.y,
- psc[PSvmoveto].command,
- item->kind.text.text,
- psc[PSnormal].command);
- break;
- case SciPlotClipRegion:
- fprintf(fd, "%.2f %.2f %s %.2f %.2f %s\n",
- item->kind.line.x1,
- yflip - item->kind.line.y1 - item->kind.line.y2,
- psc[PSmoveto].command,
- item->kind.line.x2, item->kind.line.y2,
- psc[PSclipbox].command);
- break;
- case SciPlotClipClear:
- fprintf(fd, "%s\n", psc[PSunclip].command);
- break;
- default:
- break;
- }
- }
- loopcount++;
- item++;
- }
- }
- Boolean
- SciPlotPSCreateFancy (SciPlotWidget w, char *filename, int drawborder, char *titles, Boolean usecolor)
- {
- FILE *fd;
- float scale, xoff, yoff, xmax, ymax, yflip, aspect, border, titlefontsize;
- int i;
- PScommands *p;
- char fontname[128];
- if (!(fd = fopen(filename, "w"))) {
- XtWarning("SciPlotPSCreate: Unable to open postscript file.");
- return False;
- }
- DrawAll(w);
- aspect = (float) w->core.width / (float) w->core.height;
- border = 36.0;
- if (aspect > (612.0 / 792.0)) {
- scale = (612.0 - (2 * border)) / (float) w->core.width;
- xoff = border;
- yoff = (792.0 - (2 * border) - scale * (float) w->core.height) / 2.0;
- xmax = xoff + scale * (float) w->core.width;
- ymax = yoff + scale * (float) w->core.height;
- }
- else {
- scale = (792.0 - (2 * border)) / (float) w->core.height;
- yoff = border;
- xoff = (612.0 - (2 * border) - scale * (float) w->core.width) / 2.0;
- xmax = xoff + s…
Large files files are truncated, but you can click here to view the full file