⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpcanvas.c

📁 Graphviz - Graph Drawing Programs from AT&T Research and Lucent Bell Labs See doc/build.html for
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $Id: gpcanvas.c,v 1.2 2005/04/08 20:45:34 erg Exp $ $Revision: 1.2 $ *//* vim:set shiftwidth=4 ts=8: *//***********************************************************      This software is part of the graphviz package      **                http://www.graphviz.org/                 **                                                         **            Copyright (c) 1994-2004 AT&T Corp.           **                and is licensed under the                **            Common Public License, Version 1.0           **                      by AT&T Corp.                      **                                                         **        Information and Software Systems Research        **              AT&T Research, Florham Park NJ             ***********************************************************//* Lefteris Koutsofios - AT&T Labs Research */#include "common.h"#include "g.h"#include "gcommon.h"#include "mem.h"#define WPU widget->u.p#define WINDOW widget->u.p->window#define GC widget->u.p->gcstatic long gstyles[5] = {    /* G_SOLID */       PS_SOLID,    /* G_DASHED */      PS_DASH,    /* G_DOTTED */      PS_DOT,    /* G_LONGDASHED */  PS_DASH,    /* G_SHORTDASHED */ PS_DASH,};static char grays[][4] = {    { 0x00, 0x00, 0x00, 0x00 },    { 0x08, 0x00, 0x00, 0x00 },    { 0x08, 0x00, 0x02, 0x00 },    { 0x0A, 0x00, 0x02, 0x00 },    { 0x0A, 0x00, 0x0A, 0x00 },    { 0x0A, 0x04, 0x0A, 0x00 },    { 0x0A, 0x04, 0x0A, 0x01 },    { 0x0A, 0x05, 0x0A, 0x01 },    { 0x0A, 0x05, 0x0A, 0x05 },    { 0x0E, 0x05, 0x0A, 0x05 },    { 0x0E, 0x05, 0x0B, 0x05 },    { 0x0F, 0x05, 0x0B, 0x05 },    { 0x0F, 0x05, 0x0F, 0x05 },    { 0x0F, 0x0D, 0x0F, 0x05 },    { 0x0F, 0x0D, 0x0F, 0x07 },    { 0x0F, 0x0F, 0x0F, 0x07 },    { 0x0F, 0x0F, 0x0F, 0x0F }};char *Gpscanvasname = "out.emf";static void bezier (PIXpoint_t, PIXpoint_t, PIXpoint_t, PIXpoint_t);static HFONT findfont (char *, int);static int scalebitmap (Gwidget_t *, Gbitmap_t *, Gsize_t, int, int);static void setgattr (Gwidget_t *, Ggattr_t *);static PIXrect_t  rdrawtopix (Gwidget_t *, Grect_t);static PIXpoint_t pdrawtopix (Gwidget_t *, Gpoint_t);static PIXsize_t  sdrawtopix (Gwidget_t *, Gsize_t);static PIXrect_t  rdrawtobpix (Gbitmap_t *, Grect_t);static PIXpoint_t pdrawtobpix (Gbitmap_t *, Gpoint_t);int GPcreatewidget (    Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp) {    PIXpoint_t po;    PIXsize_t ps;    PRINTDLG pd;    DOCINFO di;    DEVMODE *dmp;    /* the 2 here is to provide enough space for palPalEntry[0] and [1] */    LOGPALETTE pal[2];    HBRUSH brush;    HPEN pen;    HBITMAP bmap;    char *s, *s1;    int color, lflag, ai, dpix, dpiy, i;    s = Gpscanvasname;    lflag = FALSE;    po.x = po.y = 0;    ps.x = ps.y = MINPWSIZE;    for (ai = 0; ai < attrn; ai++) {        switch (attrp[ai].id) {        case G_ATTRORIGIN:            GETORIGIN (attrp[ai].u.p, po);            break;        case G_ATTRSIZE:            GETSIZE (attrp[ai].u.s, ps, MINPWSIZE);            break;        case G_ATTRNAME:            if (attrp[ai].u.t && attrp[ai].u.t[0])                s = attrp[ai].u.t;            break;        case G_ATTRMODE:            if (strcmp ("landscape", attrp[ai].u.t) == 0)                lflag = TRUE;            else if (strcmp ("portrait", attrp[ai].u.t) == 0)                lflag = FALSE;            else {                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);                return -1;            }            break;        case G_ATTRCOLOR:            /* will do it after the widget is created */            break;        case G_ATTRVIEWPORT:            /* will do it after the widget is created */            break;        case G_ATTRWINDOW:            /* will do it after the widget is created */            break;        case G_ATTRWINDOWID:            Gerr (POS, G_ERRCANNOTSETATTR1, "windowid");            return -1;        case G_ATTRUSERDATA:            widget->udata = attrp[ai].u.u;            break;        default:            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);            return -1;        }    }    s1 = s + strlen (s) - 3;    if (s1 > s && strncmp (s1, "emf", 3) == 0) {        WPU->mode = 1;        ps.x *= 8.235, ps.y *= 8.235;        if (!(GC = CreateEnhMetaFile (NULL, s, NULL, "LEFTY\\0GRAPH\\0\\0"))) {            Gerr (POS, G_ERRCANNOTCREATEWIDGET);            return -1;        }    } else { /* open the printer device */        WPU->mode = 2;        di.cbSize = sizeof (DOCINFO);        di.lpszDocName = NULL;        di.lpszOutput = NULL;        di.lpszDatatype = "LEFTY";        di.fwType = 0;        pd.lStructSize = sizeof (pd);        pd.hwndOwner = NULL;        pd.hDevMode = NULL;        pd.hDevNames = NULL;        pd.hDC = NULL;        pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;        pd.nFromPage = 0;        pd.nToPage = 0;        pd.nMinPage = 0;        pd.nMaxPage = 0;        pd.nCopies = 1;        pd.hInstance = NULL;        pd.lCustData = NULL;        pd.lpfnPrintHook = NULL;        pd.lpfnSetupHook = NULL;        pd.lpPrintTemplateName = NULL;        pd.lpSetupTemplateName = NULL;        pd.hPrintTemplate = NULL;        pd.hSetupTemplate = NULL;        if (!PrintDlg (&pd)) {            Gerr (POS, G_ERRCANNOTCREATEWIDGET);            return -1;        }        if (lflag && pd.hDevMode) {            dmp = (DEVMODE *) GlobalLock (pd.hDevMode);            dmp->dmOrientation = DMORIENT_LANDSCAPE;            GlobalUnlock (pd.hDevMode);            pd.Flags = PD_RETURNDC;            if (!PrintDlg (&pd)) {                Gerr (POS, G_ERRCANNOTCREATEWIDGET);                return -1;            }        }        GC = pd.hDC;        dpix = GetDeviceCaps (GC, LOGPIXELSX);        if (dpix != 300)            ps.x = ps.x * (double) dpix / 300.0;        dpiy = GetDeviceCaps (GC, LOGPIXELSY);        if (dpiy != 300)            ps.y = ps.y * (double) dpiy / 300.0;        if (StartDoc (GC, &di) <= 0 || StartPage (GC) <= 0) {            Gerr (POS, G_ERRCANNOTCREATEWIDGET);            return -1;        }    }    WPU->wrect.o.x = 0.0, WPU->wrect.o.y = 0.0;    WPU->wrect.c.x = 1.0, WPU->wrect.c.y = 1.0;    WPU->vsize.x = ps.x, WPU->vsize.y = ps.y;    WPU->ncolor = 2;    pal[0].palVersion = 0x300; /* HA HA HA */    pal[0].palNumEntries = 2;    pal[0].palPalEntry[0].peRed = 255;    pal[0].palPalEntry[0].peGreen = 255;    pal[0].palPalEntry[0].peBlue = 255;    pal[0].palPalEntry[0].peFlags = 0;    pal[0].palPalEntry[1].peRed = 0;    pal[0].palPalEntry[1].peGreen = 0;    pal[0].palPalEntry[1].peBlue = 0;    pal[0].palPalEntry[1].peFlags = 0;    WPU->cmap = CreatePalette (&pal[0]);    WPU->colors[0].color = pal[0].palPalEntry[0];    for (i = 1; i < G_MAXCOLORS; i++)        WPU->colors[i].color = pal[0].palPalEntry[1];    SelectPalette (GC, WPU->cmap, FALSE);    RealizePalette (GC);    WPU->colors[0].inuse = TRUE;    WPU->colors[1].inuse = TRUE;    for (i = 2; i < G_MAXCOLORS; i++)        WPU->colors[i].inuse = FALSE;    WPU->gattr.color = 1;    brush = CreateSolidBrush (PALETTEINDEX (1));    SelectObject (GC, brush);    pen = CreatePen (PS_SOLID, 1, PALETTEINDEX (1));    SelectObject (GC, pen);    SetTextColor (GC, PALETTEINDEX (1));    SetBkMode (GC, TRANSPARENT);    WPU->gattr.width = 0;    WPU->gattr.mode = G_SRC;    WPU->gattr.fill = 0;    WPU->gattr.style = 0;    WPU->defgattr = WPU->gattr;    WPU->font = NULL;    if (Gdepth == 1) {        for (i = 0; i < 17; i++) {            if (!(bmap = CreateBitmap (4, 4, 1, 1, &grays[i][0])))                continue;            WPU->grays[i] = CreatePatternBrush (bmap);        }    }    for (ai = 0; ai < attrn; ai++) {        switch (attrp[ai].id) {        case G_ATTRCOLOR:            color = attrp[ai].u.c.index;            if (color < 0 || color > G_MAXCOLORS) {                Gerr (POS, G_ERRBADCOLORINDEX, color);                return -1;            }            WPU->colors[color].color.peRed = attrp[ai].u.c.r;            WPU->colors[color].color.peGreen = attrp[ai].u.c.g;            WPU->colors[color].color.peBlue = attrp[ai].u.c.b;            WPU->colors[color].color.peFlags = 0;            if (color >= WPU->ncolor)                ResizePalette (WPU->cmap, color + 1), WPU->ncolor = color + 1;            SetPaletteEntries (                WPU->cmap, (int) color, 1, &WPU->colors[color].color            );            RealizePalette (GC);            WPU->colors[color].inuse = TRUE;            if (color == WPU->gattr.color)                WPU->gattr.color = -1;            break;        case G_ATTRVIEWPORT:            if (attrp[ai].u.s.x == 0)                attrp[ai].u.s.x = 1;            if (attrp[ai].u.s.y == 0)                attrp[ai].u.s.y = 1;            WPU->vsize.x = attrp[ai].u.s.x + 0.5;            WPU->vsize.y = attrp[ai].u.s.y + 0.5;            SetWindowPos (                widget->w, (HWND) NULL, 0, 0, WPU->vsize.x,                WPU->vsize.y, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE            );            break;        case G_ATTRWINDOW:            if (attrp[ai].u.r.o.x == attrp[ai].u.r.c.x)                attrp[ai].u.r.c.x = attrp[ai].u.r.o.x + 1;            if (attrp[ai].u.r.o.y == attrp[ai].u.r.c.y)                attrp[ai].u.r.c.y = attrp[ai].u.r.o.y + 1;            WPU->wrect = attrp[ai].u.r;            break;        }    }    return 0;}int GPsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {    PIXsize_t ps;    int color, ai;    for (ai = 0; ai < attrn; ai++) {        switch (attrp[ai].id) {        case G_ATTRORIGIN:            break;        case G_ATTRSIZE:            break;        case G_ATTRNAME:            break;        case G_ATTRMODE:            break;        case G_ATTRCOLOR:            color = attrp[ai].u.c.index;            if (color < 0 || color > G_MAXCOLORS) {                Gerr (POS, G_ERRBADCOLORINDEX, color);                return -1;            }            WPU->colors[color].color.peRed = attrp[ai].u.c.r;            WPU->colors[color].color.peGreen = attrp[ai].u.c.g;            WPU->colors[color].color.peBlue = attrp[ai].u.c.b;            WPU->colors[color].color.peFlags = 0;            if (color >= WPU->ncolor)                ResizePalette (WPU->cmap, color + 1), WPU->ncolor = color + 1;            SetPaletteEntries (                WPU->cmap, (int) color, 1, &WPU->colors[color].color            );            RealizePalette (GC);            WPU->colors[color].inuse = TRUE;            if (color == WPU->gattr.color)                WPU->gattr.color = -1;            break;        case G_ATTRVIEWPORT:            if (attrp[ai].u.s.x == 0)                attrp[ai].u.s.x = 1;            if (attrp[ai].u.s.y == 0)                attrp[ai].u.s.y = 1;            WPU->vsize.x = attrp[ai].u.s.x + 0.5;            WPU->vsize.y = attrp[ai].u.s.y + 0.5;            ps.x = WPU->vsize.x, ps.y = WPU->vsize.y;            break;        case G_ATTRWINDOW:            if (attrp[ai].u.r.o.x == attrp[ai].u.r.c.x)                attrp[ai].u.r.c.x = attrp[ai].u.r.o.x + 1;            if (attrp[ai].u.r.o.y == attrp[ai].u.r.c.y)                attrp[ai].u.r.c.y = attrp[ai].u.r.o.y + 1;            WPU->wrect = attrp[ai].u.r;            break;        case G_ATTRWINDOWID:            Gerr (POS, G_ERRCANNOTSETATTR2, "windowid");            return -1;        case G_ATTRUSERDATA:            widget->udata = attrp[ai].u.u;            break;        default:            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);            return -1;        }    }    return 0;}int GPgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) {    PALETTEENTRY *cp;    int color, ai;    for (ai = 0; ai < attrn; ai++) {        switch (attrp[ai].id) {        case G_ATTRORIGIN:            break;        case G_ATTRSIZE:            break;        case G_ATTRNAME:            break;        case G_ATTRMODE:            break;        case G_ATTRCOLOR:            color = attrp[ai].u.c.index;            if (color < 0 || color > G_MAXCOLORS) {                Gerr (POS, G_ERRBADCOLORINDEX, color);                return -1;            }            if (WPU->colors[color].inuse) {                cp = &WPU->colors[color].color;                attrp[ai].u.c.r = cp->peRed;                attrp[ai].u.c.g = cp->peGreen;                attrp[ai].u.c.b = cp->peBlue;            } else {                attrp[ai].u.c.r = -1;                attrp[ai].u.c.g = -1;                attrp[ai].u.c.b = -1;            }            break;        case G_ATTRVIEWPORT:            attrp[ai].u.s = WPU->vsize;            break;        case G_ATTRWINDOW:            attrp[ai].u.r = WPU->wrect;            break;        case G_ATTRWINDOWID:            Gerr (POS, G_ERRCANNOTGETATTR, "windowid");            break;        case G_ATTRUSERDATA:            widget->udata = attrp[ai].u.u;            break;        default:            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);            return -1;        }    }    return 0;}int GPdestroywidget (Gwidget_t *widget) {    HENHMETAFILE mfile;    if (WPU->mode == 1) {        mfile = CloseEnhMetaFile (GC);        OpenClipboard (NULL);        EmptyClipboard ();        SetClipboardData (CF_ENHMETAFILE, mfile);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -