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

📄 gpcanvas.c

📁 Graphviz - Graph Drawing Programs from AT&T Research and Lucent Bell Labs See doc/build.html for
💻 C
📖 第 1 页 / 共 3 页
字号:
        CloseClipboard ();        DeleteMetaFile (mfile);    } else {        EndPage (GC);        EndDoc (GC);    }    return 0;}int GPcanvasclear (Gwidget_t *widget) {    HBRUSH brush, pbrush;    /* FIXME: drain repaint messages */    brush = CreateSolidBrush (PALETTEINDEX (0));    pbrush = SelectObject (GC, brush);    Rectangle (GC, 0, 0, (int) WPU->vsize.x, (int) WPU->vsize.y);    SelectObject (GC, pbrush);    return 0;}int GPsetgfxattr (Gwidget_t *widget, Ggattr_t *ap) {    setgattr (widget, ap);    WPU->defgattr = WPU->gattr;    return 0;}int GPgetgfxattr (Gwidget_t *widget, Ggattr_t *ap) {    if ((ap->flags & G_GATTRCOLOR))        ap->color = WPU->gattr.color;    if ((ap->flags & G_GATTRWIDTH))        ap->width = WPU->gattr.width;    if ((ap->flags & G_GATTRMODE))        ap->mode = WPU->gattr.mode;    if ((ap->flags & G_GATTRFILL))        ap->fill = WPU->gattr.fill;    if ((ap->flags & G_GATTRSTYLE))        ap->style = WPU->gattr.style;    return 0;}int GParrow (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) {    PIXpoint_t pp1, pp2, pa, pb, pd;    double tangent, l;    pp1 = pdrawtopix (widget, gp1), pp2 = pdrawtopix (widget, gp2);    pd.x = pp1.x - pp2.x, pd.y = pp1.y - pp2.y;    if (pd.x == 0 && pd.y == 0)        return 0;    tangent = atan2 ((double) pd.y, (double) pd.x);    if ((l = sqrt ((double) (pd.x * pd.x + pd.y * pd.y))) > 30)        l = 30;    pa.x = l * cos (tangent + M_PI / 7) + pp2.x;    pa.y = l * sin (tangent + M_PI / 7) + pp2.y;    pb.x = l * cos (tangent - M_PI / 7) + pp2.x;    pb.y = l * sin (tangent - M_PI / 7) + pp2.y;    setgattr (widget, ap);    MoveToEx (GC, pp1.x, pp1.y, NULL), LineTo (GC, pp2.x, pp2.y);    MoveToEx (GC, pa.x, pa.y, NULL), LineTo (GC, pp2.x, pp2.y);    MoveToEx (GC, pb.x, pb.y, NULL), LineTo (GC, pp2.x, pp2.y);    return 0;}int GPline (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) {    PIXpoint_t pp1, pp2;    pp1 = pdrawtopix (widget, gp1), pp2 = pdrawtopix (widget, gp2);    setgattr (widget, ap);    MoveToEx (GC, pp1.x, pp1.y, NULL);    LineTo (GC, pp2.x, pp2.y);    return 0;}int GPbox (Gwidget_t *widget, Grect_t gr, Ggattr_t *ap) {    PIXrect_t pr;    Grect_t gr2;    if (gr.o.x <= gr.c.x)        gr2.o.x = gr.o.x, gr2.c.x = gr.c.x;    else        gr2.o.x = gr.c.x, gr2.c.x = gr.o.x;    if (gr.o.y <= gr.c.y)        gr2.o.y = gr.o.y, gr2.c.y = gr.c.y;    else        gr2.o.y = gr.c.y, gr2.c.y = gr.o.y;    pr = rdrawtopix (widget, gr);    setgattr (widget, ap);    if (WPU->gattr.fill)        Rectangle (GC, pr.o.x, pr.o.y, pr.c.x, pr.c.y);    else {        Gppp[0].x = pr.o.x, Gppp[0].y = pr.o.y;        Gppp[1].x = pr.c.x, Gppp[1].y = pr.o.y;        Gppp[2].x = pr.c.x, Gppp[2].y = pr.c.y;        Gppp[3].x = pr.o.x, Gppp[3].y = pr.c.y;        Gppp[4].x = pr.o.x, Gppp[4].y = pr.o.y;        Polyline (GC, Gppp, 5);    }    return 0;}int GPpolygon (Gwidget_t *widget, int gpn, Gpoint_t *gpp, Ggattr_t *ap) {    int n, i;    if (gpn == 0)        return 0;    if (gpn + 1 > Gppn) {        n = (((gpn + 1) + PPINCR - 1) / PPINCR) * PPINCR;        Gppp = Marraygrow (Gppp, (long) n * PPSIZE);        Gppn = n;    }    for (i = 0; i < gpn; i++)        Gppp[i] = pdrawtopix (widget, gpp[i]);    setgattr (widget, ap);    if (WPU->gattr.fill) {        if (Gppp[gpn - 1].x != Gppp[0].x || Gppp[gpn - 1].y != Gppp[0].y)            Gppp[gpn] = Gppp[0], gpn++;        Polygon (GC, Gppp, (int) gpn);    } else        Polyline (GC, Gppp, (int) gpn);    return 0;}int GPsplinegon (Gwidget_t *widget, int gpn, Gpoint_t *gpp, Ggattr_t *ap) {    PIXpoint_t p0, p1, p2, p3;    int n, i;    if (gpn == 0)        return 0;    Gppi = 1;    if (Gppi >= Gppn) {        n = (((Gppi + 1) + PPINCR - 1) / PPINCR) * PPINCR;        Gppp = Marraygrow (Gppp, (long) n * PPSIZE);        Gppn = n;    }    Gppp[0] = p3 = pdrawtopix (widget, gpp[0]);    for (i = 1; i < gpn; i += 3) {        p0 = p3;        p1 = pdrawtopix (widget, gpp[i]);        p2 = pdrawtopix (widget, gpp[i + 1]);        p3 = pdrawtopix (widget, gpp[i + 2]);        bezier (p0, p1, p2, p3);    }    setgattr (widget, ap);    if (WPU->gattr.fill) {        if (Gppp[Gppi - 1].x != Gppp[0].x || Gppp[Gppi - 1].y != Gppp[0].y)            Gppp[Gppi] = Gppp[0], Gppi++;        Polygon (GC, Gppp, (int) Gppi);    } else        Polyline (GC, Gppp, (int) Gppi);    return 0;}static void bezier (    PIXpoint_t p0, PIXpoint_t p1, PIXpoint_t p2, PIXpoint_t p3) {    Gpoint_t gp0, gp1, gp2;    Gsize_t s;    PIXpoint_t p;    double t;    int n, i, steps;    if ((s.x = p3.x - p0.x) < 0)        s.x = - s.x;    if ((s.y = p3.y - p0.y) < 0)        s.y = - s.y;    if (s.x > s.y)        steps = s.x / 5 + 1;    else        steps = s.y / 5 + 1;    for (i = 0; i <= steps; i++) {        t = i / (double) steps;        gp0.x = p0.x + t * (p1.x - p0.x);        gp0.y = p0.y + t * (p1.y - p0.y);        gp1.x = p1.x + t * (p2.x - p1.x);        gp1.y = p1.y + t * (p2.y - p1.y);        gp2.x = p2.x + t * (p3.x - p2.x);        gp2.y = p2.y + t * (p3.y - p2.y);        gp0.x = gp0.x + t * (gp1.x - gp0.x);        gp0.y = gp0.y + t * (gp1.y - gp0.y);        gp1.x = gp1.x + t * (gp2.x - gp1.x);        gp1.y = gp1.y + t * (gp2.y - gp1.y);        p.x = gp0.x + t * (gp1.x - gp0.x) + 0.5;        p.y = gp0.y + t * (gp1.y - gp0.y) + 0.5;        if (Gppi >= Gppn) {            n = (((Gppi + 1) + PPINCR - 1) / PPINCR) * PPINCR;            Gppp = Marraygrow (Gppp, (long) n * PPSIZE);            Gppn = n;        }        Gppp[Gppi++] = p;    }}int GParc (    Gwidget_t *widget, Gpoint_t gc, Gsize_t gs,    double ang1, double ang2, Ggattr_t *ap) {    PIXpoint_t pc;    PIXsize_t ps;    double a1, a2;    pc = pdrawtopix (widget, gc), ps = sdrawtopix (widget, gs);    setgattr (widget, ap);    a1 = ang1 * M_PI / 180, a2 = ang2 * M_PI / 180;    if (WPU->gattr.fill)        Chord (            GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y,            (int) (cos (a1) * ps.x), (int) (sin (a1) * ps.x),            (int) (cos (a2) * ps.x), (int) (sin (a2) * ps.x)        );    else        Arc (            GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y,            (int) (cos (a1) * ps.x), (int) (sin (a1) * ps.x),            (int) (cos (a2) * ps.x), (int) (sin (a2) * ps.x)        );    return 0;}int GPtext (    Gwidget_t *widget, Gtextline_t *tlp, int n, Gpoint_t go, char *fn,    double fs, char *justs, Ggattr_t *ap) {    Gsize_t gs;    PIXpoint_t po;    PIXsize_t ps;    PIXrect_t pr;    HFONT font;    SIZE size;    RECT r;    int x, y, w, h, i;    po = pdrawtopix (widget, go);    gs.x = 0, gs.y = fs;    ps = sdrawtopix (widget, gs);    if (!(font = findfont (fn, ps.y))) {        Rectangle (GC, po.x, po.y, po.x + 1, po.y + 1);        return 0;    }    setgattr (widget, ap);    if (font != WPU->font) {        WPU->font = font;        SelectObject (GC, font);    }    for (w = h = 0, i = 0; i < n; i++) {        if (tlp[i].n)            GetTextExtentPoint32 (GC, tlp[i].p, (int) tlp[i].n, &size);        else            GetTextExtentPoint32 (GC, "M", (int) 1, &size);        tlp[i].w = size.cx, tlp[i].h = size.cy;        w = max (w, size.cx), h += size.cy;    }    switch (justs[0]) {    case 'l': po.x += w / 2; break;    case 'r': po.x -= w / 2; break;    }    switch (justs[1]) {    case 'd': po.y -= h; break;    case 'c': po.y -= h / 2; break;    }    pr.o.x = po.x - w / 2, pr.o.y = po.y;    pr.c.x = po.x + w / 2, pr.c.y = po.y + h;    for (i = 0; i < n; i++) {        switch (tlp[i].j) {        case 'l': x = po.x - w / 2; break;        case 'n': x = po.x - tlp[i].w / 2; break;        case 'r': x = po.x - (tlp[i].w - w / 2); break;        }        y = po.y + i * tlp[i].h;        r.left = x, r.top = y;        r.right = x + tlp[i].w, r.bottom = y + tlp[i].h;        DrawText (GC, tlp[i].p, (int) tlp[i].n, &r, DT_LEFT | DT_TOP);    }    return 0;}static HFONT findfont (char *name, int size) {    HFONT font;    int fi;    if (name[0] == '\000')        return Gfontp[0].font;    sprintf (&Gbufp[0], name, size);    for (fi = 0; fi < Gfontn; fi++)        if (strcmp (&Gbufp[0], Gfontp[fi].name) == 0 && Gfontp[fi].size == size)            return Gfontp[fi].font;    font = CreateFont (        (int) size, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &Gbufp[0]    );    if (!font)        font = Gfontp[0].font;    Gfontp = Marraygrow (Gfontp, (long) (Gfontn + 1) * FONTSIZE);    Gfontp[Gfontn].name = strdup (&Gbufp[0]);    Gfontp[Gfontn].size = size;    Gfontp[Gfontn].font = font;    Gfontn++;    return font;}int GPcreatebitmap (Gwidget_t *widget, Gbitmap_t *bitmap, Gsize_t s) {    if (!widget) {        Gerr (POS, G_ERRNOPARENTWIDGET);        return -1;    }    if (!bitmap) {        Gerr (POS, G_ERRNOBITMAP);        return -1;    }    if (!(bitmap->u.bmap.orig = CreateBitmap (        (int) s.x, (int) s.y, 1, Gdepth, NULL    ))) {        Gerr (POS, G_ERRCANNOTCREATEBITMAP);        return -1;    }    bitmap->u.bmap.scaled = 0;    bitmap->scale.x = bitmap->scale.y = 1;    bitmap->ctype = widget->type;    bitmap->canvas = widget - &Gwidgets[0];    bitmap->size = s;    return 0;}int GPdestroybitmap (Gbitmap_t *bitmap) {    if (!bitmap) {        Gerr (POS, G_ERRNOBITMAP);        return -1;    }    DeleteObject (bitmap->u.bmap.orig);    return 0;}int GPreadbitmap (Gwidget_t *widget, Gbitmap_t *bitmap, FILE *fp) {    Gsize_t s;    HDC gc;    char bufp[2048];    unsigned int rgb[3];    char *s1, *s2;    char c;    int bufn, bufi, step, x, y, k;    if (!widget) {        Gerr (POS, G_ERRNOPARENTWIDGET);        return -1;    }    if (!bitmap) {        Gerr (POS, G_ERRNOBITMAP);        return -1;    }    step = 0;    while (step < 3) {l1:        if (!fgets (bufp, 2048, fp)) {            Gerr (POS, G_ERRCANNOTREADBITMAP);            return -1;        }        s1 = &bufp[0];l2:        for (; *s1 && isspace (*s1); s1++)            ;        if (!*s1 || *s1 == '#')            goto l1;        switch (step) {        case 0:            if (strncmp (s1, "P6", 2) != 0) {                Gerr (POS, G_ERRCANNOTREADBITMAP);                return -1;            }            step++, s1 += 2;            goto l2;        case 1:            for (s2 = s1; *s2 && *s2 >= '0' && *s2 <= '9'; s2++)                ;            c = *s2, *s2 = 0;            if (s2 == s1 || (s.x = atoi (s1)) <= 0) {                *s2 = c, Gerr (POS, G_ERRCANNOTREADBITMAP);                return -1;            }            *s2 = c, step++, s1 = s2;            goto l2;        case 2:            for (s2 = s1; *s2 && *s2 >= '0' && *s2 <= '9'; s2++)                ;            c = *s2, *s2 = 0;            if (s2 == s1 || (s.y = atoi (s1)) <= 0) {                *s2 = c, Gerr (POS, G_ERRCANNOTREADBITMAP);                return -1;            }            *s2 = c, step++, s1 = s2;            goto l2;        }    }    if (!(bitmap->u.bmap.orig = CreateBitmap (        (int) s.x, (int) s.y, 1, Gdepth, NULL    ))) {        Gerr (POS, G_ERRCANNOTCREATEBITMAP);        return -1;    }    gc = CreateCompatibleDC (GC);    SelectObject (gc, bitmap->u.bmap.orig);    bitmap->u.bmap.scaled = 0;    bitmap->scale.x = bitmap->scale.y = 1;    bitmap->ctype = widget->type;    bitmap->canvas = widget - &Gwidgets[0];    bitmap->size = s;

⌨️ 快捷键说明

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