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

📄 gprint.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            gs_lgp->gnome_print_fill( m_gpc );
        }

        if (m_pen.GetStyle() != wxTRANSPARENT)
        {
            SetPen (m_pen);
            gs_lgp->gnome_print_newpath( m_gpc );
            gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc) );
            gs_lgp->gnome_print_arcto( m_gpc, XLOG2DEV(xc), YLOG2DEV(yc), XLOG2DEVREL((int)radius), alpha1, alpha2, 0 );
            gs_lgp->gnome_print_closepath( m_gpc );

            gs_lgp->gnome_print_stroke( m_gpc );
        }

    CalcBoundingBox (x1, y1);
    CalcBoundingBox (x2, y2);
    CalcBoundingBox (xc, yc);
}

void wxGnomePrintDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
{
    x += w/2;
    y += h/2;

    int xx = XLOG2DEV(x);
    int yy = YLOG2DEV(y);

    gs_lgp->gnome_print_gsave( m_gpc );

    gs_lgp->gnome_print_translate( m_gpc, xx, yy );
    double scale = (double)YLOG2DEVREL(h) / (double) XLOG2DEVREL(w);
    gs_lgp->gnome_print_scale( m_gpc, 1.0, scale );

    xx = 0;
    yy = 0;

    if (m_brush.GetStyle () != wxTRANSPARENT)
    {
        SetBrush( m_brush );

        gs_lgp->gnome_print_moveto ( m_gpc, xx, yy );
        gs_lgp->gnome_print_arcto( m_gpc, xx, yy,
            XLOG2DEVREL(w)/2, sa, ea, 0 );
        gs_lgp->gnome_print_moveto ( m_gpc, xx, yy );

        gs_lgp->gnome_print_fill( m_gpc );
    }

    if (m_pen.GetStyle () != wxTRANSPARENT)
    {
        SetPen (m_pen);

        gs_lgp->gnome_print_arcto( m_gpc, xx, yy,
            XLOG2DEVREL(w)/2, sa, ea, 0 );

        gs_lgp->gnome_print_stroke( m_gpc );
    }

    gs_lgp->gnome_print_grestore( m_gpc );

    CalcBoundingBox( x, y );
    CalcBoundingBox( x+w, y+h );
}

void wxGnomePrintDC::DoDrawPoint(wxCoord x, wxCoord y)
{
}

void wxGnomePrintDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
{
    if (m_pen.GetStyle() == wxTRANSPARENT) return;

    if (n <= 0) return;

    SetPen (m_pen);

    int i;
    for ( i =0; i<n ; i++ )
        CalcBoundingBox( points[i].x+xoffset, points[i].y+yoffset);

    gs_lgp->gnome_print_moveto ( m_gpc, XLOG2DEV(points[0].x+xoffset), YLOG2DEV(points[0].y+yoffset) );

    for (i = 1; i < n; i++)
        gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV(points[i].x+xoffset), YLOG2DEV(points[i].y+yoffset) );

    gs_lgp->gnome_print_stroke ( m_gpc);
}

void wxGnomePrintDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
{
    if (n==0) return;

    if (m_brush.GetStyle () != wxTRANSPARENT)
    {
        SetBrush( m_brush );

        int x = points[0].x + xoffset;
        int y = points[0].y + yoffset;
        CalcBoundingBox( x, y );
        gs_lgp->gnome_print_newpath( m_gpc );
        gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
        int i;
        for (i = 1; i < n; i++)
        {
            int x = points[i].x + xoffset;
            int y = points[i].y + yoffset;
            gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
            CalcBoundingBox( x, y );
        }
        gs_lgp->gnome_print_closepath( m_gpc );
        gs_lgp->gnome_print_fill( m_gpc );
    }

    if (m_pen.GetStyle () != wxTRANSPARENT)
    {
        SetPen (m_pen);

        int x = points[0].x + xoffset;
        int y = points[0].y + yoffset;
        gs_lgp->gnome_print_newpath( m_gpc );
        gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
        int i;
        for (i = 1; i < n; i++)
        {
            int x = points[i].x + xoffset;
            int y = points[i].y + yoffset;
            gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
            CalcBoundingBox( x, y );
        }
        gs_lgp->gnome_print_closepath( m_gpc );
        gs_lgp->gnome_print_stroke( m_gpc );
    }
}

void wxGnomePrintDC::DoDrawPolyPolygon(int n, int count[], wxPoint points[], wxCoord xoffset, wxCoord yoffset, int fillStyle)
{
    wxDC::DoDrawPolyPolygon( n, count, points, xoffset, yoffset, fillStyle );
}

void wxGnomePrintDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
    if (m_brush.GetStyle () != wxTRANSPARENT)
    {
        SetBrush( m_brush );

        gs_lgp->gnome_print_newpath( m_gpc );
        gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
        gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
        gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
        gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
        gs_lgp->gnome_print_closepath( m_gpc );
        gs_lgp->gnome_print_fill( m_gpc );

        CalcBoundingBox( x, y );
        CalcBoundingBox( x + width, y + height );
    }

    if (m_pen.GetStyle () != wxTRANSPARENT)
    {
        SetPen (m_pen);

        gs_lgp->gnome_print_newpath( m_gpc );
        gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV(x), YLOG2DEV(y) );
        gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y) );
        gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x + width), YLOG2DEV(y + height) );
        gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV(x), YLOG2DEV(y + height) );
        gs_lgp->gnome_print_closepath( m_gpc );
        gs_lgp->gnome_print_stroke( m_gpc );

        CalcBoundingBox( x, y );
        CalcBoundingBox( x + width, y + height );
    }
}

void wxGnomePrintDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
{
    wxCoord rad = (wxCoord) radius;

    if (m_brush.GetStyle() != wxTRANSPARENT)
    {
        SetBrush(m_brush);
        gs_lgp->gnome_print_newpath(m_gpc);
        gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
        gs_lgp->gnome_print_curveto(m_gpc,
                                    XLOG2DEV(x + rad),YLOG2DEV(y),
                                    XLOG2DEV(x),YLOG2DEV(y),
                                    XLOG2DEV(x),YLOG2DEV(y + rad));
        gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad));
        gs_lgp->gnome_print_curveto(m_gpc,
                                    XLOG2DEV(x),YLOG2DEV(y + height - rad),
                                    XLOG2DEV(x),YLOG2DEV(y + height),
                                    XLOG2DEV(x + rad),YLOG2DEV(y + height));
        gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
        gs_lgp->gnome_print_curveto(m_gpc,
                                    XLOG2DEV(x + width - rad),YLOG2DEV(y + height),
                                    XLOG2DEV(x + width),YLOG2DEV(y + height),
                                    XLOG2DEV(x + width),YLOG2DEV(y + height - rad));
        gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad));
        gs_lgp->gnome_print_curveto(m_gpc,
                                    XLOG2DEV(x + width),YLOG2DEV(y + rad),
                                    XLOG2DEV(x + width),YLOG2DEV(y),
                                    XLOG2DEV(x + width - rad),YLOG2DEV(y));
        gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
        gs_lgp->gnome_print_closepath(m_gpc);
        gs_lgp->gnome_print_fill(m_gpc);

        CalcBoundingBox(x,y);
        CalcBoundingBox(x+width,y+height);
    }

    if (m_pen.GetStyle() != wxTRANSPARENT)
    {
        SetPen(m_pen);
        gs_lgp->gnome_print_newpath(m_gpc);
        gs_lgp->gnome_print_moveto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
        gs_lgp->gnome_print_curveto(m_gpc,
                                    XLOG2DEV(x + rad),YLOG2DEV(y),
                                    XLOG2DEV(x),YLOG2DEV(y),
                                    XLOG2DEV(x),YLOG2DEV(y + rad));
        gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x),YLOG2DEV(y + height - rad));
        gs_lgp->gnome_print_curveto(m_gpc,
                                    XLOG2DEV(x),YLOG2DEV(y + height - rad),
                                    XLOG2DEV(x),YLOG2DEV(y + height),
                                    XLOG2DEV(x + rad),YLOG2DEV(y + height));
        gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width - rad),YLOG2DEV(y + height));
        gs_lgp->gnome_print_curveto(m_gpc,
                                    XLOG2DEV(x + width - rad),YLOG2DEV(y + height),
                                    XLOG2DEV(x + width),YLOG2DEV(y + height),
                                    XLOG2DEV(x + width),YLOG2DEV(y + height - rad));
        gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + width),YLOG2DEV(y + rad));
        gs_lgp->gnome_print_curveto(m_gpc,
                                    XLOG2DEV(x + width),YLOG2DEV(y + rad),
                                    XLOG2DEV(x + width),YLOG2DEV(y),
                                    XLOG2DEV(x + width - rad),YLOG2DEV(y));
        gs_lgp->gnome_print_lineto(m_gpc,XLOG2DEV(x + rad),YLOG2DEV(y));
        gs_lgp->gnome_print_closepath(m_gpc);
        gs_lgp->gnome_print_stroke(m_gpc);

        CalcBoundingBox(x,y);
        CalcBoundingBox(x+width,y+height);
    }
}

void wxGnomePrintDC::makeEllipticalPath(wxCoord x, wxCoord y,
                                        wxCoord width, wxCoord height)
{
    double r = 4 * (sqrt (2) - 1) / 3;
    double  halfW = 0.5 * width,
            halfH = 0.5 * height,
            halfWR = r * halfW,
            halfHR = r * halfH;
    wxCoord halfWI = (wxCoord) halfW,
            halfHI = (wxCoord) halfH;

    gs_lgp->gnome_print_newpath( m_gpc );

    // Approximate an ellipse using four cubic splines, clockwise from 0 deg */
    gs_lgp->gnome_print_moveto( m_gpc,
                XLOG2DEV(x + width),
                YLOG2DEV(y + halfHI) );
    gs_lgp->gnome_print_curveto( m_gpc,
                XLOG2DEV(x + width),
                YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)),
                XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)),
                YLOG2DEV(y + height),
                XLOG2DEV(x + halfWI),
                YLOG2DEV(y + height) );
    gs_lgp->gnome_print_curveto( m_gpc,
                XLOG2DEV(x + (wxCoord) rint(halfW - halfWR)),
                YLOG2DEV(y + height),
                XLOG2DEV(x),
                YLOG2DEV(y + (wxCoord) rint (halfH + halfHR)),
                XLOG2DEV(x), YLOG2DEV(y+halfHI) );
    gs_lgp->gnome_print_curveto( m_gpc,
                XLOG2DEV(x),
                YLOG2DEV(y + (wxCoord) rint (halfH - halfHR)),
                XLOG2DEV(x + (wxCoord) rint (halfW - halfWR)),
                YLOG2DEV(y),
                XLOG2DEV(x+halfWI), YLOG2DEV(y) );
    gs_lgp->gnome_print_curveto( m_gpc,
                XLOG2DEV(x + (wxCoord) rint(halfW + halfWR)),
                YLOG2DEV(y),
                XLOG2DEV(x + width),
                YLOG2DEV(y + (wxCoord) rint(halfH - halfHR)),
                XLOG2DEV(x + width), YLOG2DEV(y + halfHI) );

    gs_lgp->gnome_print_closepath(m_gpc);
}

void wxGnomePrintDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{
    if (m_brush.GetStyle () != wxTRANSPARENT)
    {
        SetBrush( m_brush );
        makeEllipticalPath( x, y, width, height );
        gs_lgp->gnome_print_fill( m_gpc );
        CalcBoundingBox( x, y );
        CalcBoundingBox( x + width, y + height );
    }

    if (m_pen.GetStyle () != wxTRANSPARENT)
    {
        SetPen (m_pen);
        makeEllipticalPath( x, y, width, height );
        gs_lgp->gnome_print_stroke( m_gpc );
        CalcBoundingBox( x, y );
        CalcBoundingBox( x + width, y + height );
    }
}

#if wxUSE_SPLINES
void wxGnomePrintDC::DoDrawSpline(wxList *points)
{
    SetPen (m_pen);

    double c, d, x1, y1, x2, y2, x3, y3;
    wxPoint *p, *q;

    wxList::compatibility_iterator node = points->GetFirst();
    p = (wxPoint *)node->GetData();
    x1 = p->x;
    y1 = p->y;

    node = node->GetNext();
    p = (wxPoint *)node->GetData();
    c = p->x;
    d = p->y;
    x3 =
         (double)(x1 + c) / 2;
    y3 =
         (double)(y1 + d) / 2;

    gs_lgp->gnome_print_newpath( m_gpc );
    gs_lgp->gnome_print_moveto( m_gpc, XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1) );
    gs_lgp->gnome_print_lineto( m_gpc, XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );

    CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
    CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );

    node = node->GetNext();
    while (node)
    {
        q = (wxPoint *)node->GetData();

        x1 = x3;
        y1 = y3;
        x2 = c;
        y2 = d;
        c = q->x;
        d = q->y;
        x3 = (double)(x2 + c) / 2;
        y3 = (double)(y2 + d) / 2;

        gs_lgp->gnome_print_curveto(m_gpc,
            XLOG2DEV((wxCoord)x1), YLOG2DEV((wxCoord)y1),
            XLOG2DEV((wxCoord)x2), YLOG2DEV((wxCoord)y2),
            XLOG2DEV((wxCoord)x3), YLOG2DEV((wxCoord)y3) );

        CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 );
        CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 );

        node = node->GetNext();
    }

    gs_lgp->gnome_print_lineto ( m_gpc, XLOG2DEV((wxCoord)c), YLOG2DEV((wxCoord)d) );

    gs_lgp->gnome_print_stroke( m_gpc );
}
#endif // wxUSE_SPLINES

bool wxGnomePrintDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
            wxDC *source, wxCoord xsrc, wxCoord ysrc, int rop, bool useMask,
            wxCoord xsrcMask, wxCoord ysrcMask)
{
    wxCHECK_MSG( source, false, wxT("invalid source dc") );

    // blit into a bitmap
    wxBitmap bitmap( width, height );
    wxMemoryDC memDC;
    memDC.SelectObject(bitmap);
    memDC.Blit(0, 0, width, height, source, xsrc, ysrc, rop); /* TODO: Blit transparently? */
    memDC.SelectObject(wxNullBitmap);

    // draw bitmap. scaling and positioning is done there
    DrawBitmap( bitmap, xdest, ydest );

    return true;
}

void wxGnomePrintDC::DoDrawIcon( const wxIcon& icon, wxCoord x, wxCoord y )
{
    DoDrawBitmap( icon, x, y, true );
}

void wxGnomePrintDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
{
    if (!bitmap.Ok()) return;

    if (bitmap.HasPixbuf())
    {
        GdkPixbuf *pixbuf = bitmap.GetPixbuf();
        guchar *raw_image = gdk_pixbuf_get_pixels( pixbuf );
        bool has_alpha = gdk_pixbuf_get_has_alpha( pixbuf );
        int rowstride = gdk_pixbuf_get_rowstride( pixbuf );
        int height = gdk_pixbuf_get_height( pixbuf );
        int width = gdk_pixbuf_get_width( pixbuf );

        gs_lgp->gnome_print_gsave( m_gpc );
        double matrix[6];
        matrix[0] = XLOG2DEVREL(width);
        matrix[1] = 0;
        matrix[2] = 0;
        matrix[3] = YLOG2DEVREL(height);
        matrix[4] = XLOG2DEV(x);
        matrix[5] = YLOG2DEV(y+height);
        gs_lgp->gnome_print_concat( m_gpc, matrix );
        gs_lgp->gnome_print_moveto(  m_gpc, 0, 0 );
        if (has_alpha)
            gs_lgp->gnome_print_rgbaimage( m_gpc, (guchar *)raw_image, width, height, rowstride );
        else
            gs_lgp->gnome_print_rgbimage( m_gpc, (guchar *)raw_image, width, height, rowstride );
        gs_lgp->gnome_print_grestore( m_gpc );
    }
    else
    {
        wxImage image = bitmap.ConvertToImage();

        if (!image.Ok()) return;

        gs_lgp->gnome_print_gsave( m_gpc );
        double matrix[6];
        matrix[0] = XLOG2DEVREL(image.GetWidth());
        matrix[1] = 0;
        matrix[2] = 0;
        matrix[3] = YLOG2DEVREL(image.GetHeight());
        matrix[4] = XLOG2DEV(x);
        matrix[5] = YLOG2DEV(y+image.GetHeight());
        gs_lgp->gnome_print_concat( m_gpc, matrix );
        gs_lgp->gnome_print_moveto(  m_gpc, 0, 0 );
        gs_lgp->gnome_print_rgbimage( m_gpc, (guchar*) image.GetData(), image.GetWidth(), image.GetHeight(), image.GetWidth()*3 );
        gs_lgp->gnome_print_grestore( m_gpc );
    }
}

void wxGnomePrintDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y )
{
    DoDrawRotatedText( text, x, y, 0.0 );
}

void wxGnomePrintDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
{
    x = XLOG2DEV(x);
    y = YLOG2DEV(y);

    bool underlined = m_font.Ok() && m_font.GetUnderlined();

#if wxUSE_UNICODE
    const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
#else
    const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text );
    if ( !wdata )

⌨️ 快捷键说明

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