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

📄 gprint.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                                    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_SPLINESvoid 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_SPLINESbool 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 )        return;    const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );#endif    size_t datalen = strlen((const char*)data);    pango_layout_set_text( m_layout, (const char*) data, datalen);    if (underlined)    {        PangoAttrList *attrs = pango_attr_list_new();        PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);        a->start_index = 0;        a->end_index = datalen;        pango_attr_list_insert(attrs, a);        pango_layout_set_attributes(m_layout, attrs);        pango_attr_list_unref(attrs);    }    if (m_textForegroundColour.Ok())    {        unsigned char red = m_textForegroundColour.Red();        unsigned char blue = m_textForegroundColour.Blue();        unsigned char green = m_textForegroundColour.Green();        if (!(red == m_currentRed && green == m_currentGreen && blue == m_currentBlue))        {            double redPS = (double)(red) / 255.0;            double bluePS = (double)(blue) / 255.0;            double greenPS = (double)(green) / 255.0;            gs_lgp->gnome_print_setrgbcolor( m_gpc, redPS, greenPS, bluePS );            m_currentRed = red;            m_currentBlue = blue;            m_currentGreen = green;        }    }    int w,h;    if (fabs(m_scaleY - 1.0) > 0.00001)    {        // If there is a user or actually any scale applied to        // the device context, scale the font.        // scale font description        gint oldSize = pango_font_description_get_size( m_fontdesc );        double size = oldSize;        size = size * m_scaleY;        pango_font_description_set_size( m_fontdesc, (gint)size );        // actually apply scaled font        pango_layout_set_font_description( m_layout, m_fontdesc );        pango_layout_get_pixel_size( m_layout, &w, &h );#if 0        if ( m_backgroundMode == wxSOLID )        {            gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());            gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);            gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());        }#endif        // Draw layout.        gs_lgp->gnome_print_moveto (m_gpc, x, y);        if (fabs(angle) > 0.00001)        {            gs_lgp->gnome_print_gsave( m_gpc );            gs_lgp->gnome_print_rotate( m_gpc, angle );            gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );            gs_lgp->gnome_print_grestore( m_gpc );        }        else        {            gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );        }        // reset unscaled size        pango_font_description_set_size( m_fontdesc, oldSize );        // actually apply unscaled font        pango_layout_set_font_description( m_layout, m_fontdesc );    }    else    {        pango_layout_get_pixel_size( m_layout, &w, &h );#if 0        if ( m_backgroundMode == wxSOLID )        {            gdk_gc_set_foreground(m_textGC, m_textBackgroundColour.GetColor());            gdk_draw_rectangle(m_window, m_textGC, TRUE, x, y, w, h);            gdk_gc_set_foreground(m_textGC, m_textForegroundColour.GetColor());        }#endif        // Draw layout.        gs_lgp->gnome_print_moveto (m_gpc, x, y);        if (fabs(angle) > 0.00001)        {            gs_lgp->gnome_print_gsave( m_gpc );            gs_lgp->gnome_print_rotate( m_gpc, angle );            gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );            gs_lgp->gnome_print_grestore( m_gpc );        }        else        {            gs_lgp->gnome_print_pango_layout( m_gpc, m_layout );        }    }    if (underlined)    {        // undo underline attributes setting:        pango_layout_set_attributes(m_layout, NULL);    }    CalcBoundingBox (x + w, y + h);}void wxGnomePrintDC::Clear(){}void wxGnomePrintDC::SetFont( const wxFont& font ){    m_font = font;    if (m_font.Ok())    {        if (m_fontdesc)            pango_font_description_free( m_fontdesc );        m_fontdesc = pango_font_description_copy( m_font.GetNativeFontInfo()->description );        pango_layout_set_font_description( m_layout, m_fontdesc );    }}void wxGnomePrintDC::SetPen( const wxPen& pen ){    if (!pen.Ok()) return;    m_pen = pen;    gs_lgp->gnome_print_setlinewidth( m_gpc, XLOG2DEVREL( 1000 * m_pen.GetWidth() ) / 1000.0f );    static const double dotted[] =  {2.0, 5.0};    static const double short_dashed[] = {4.0, 4.0};    static const double wxCoord_dashed[] = {4.0, 8.0};    static const double dotted_dashed[] = {6.0, 6.0, 2.0, 6.0};    switch (m_pen.GetStyle())    {        case wxDOT:           gs_lgp->gnome_print_setdash( m_gpc, 2, dotted, 0 ); break;        case wxSHORT_DASH:    gs_lgp->gnome_print_setdash( m_gpc, 2, short_dashed, 0 ); break;        case wxLONG_DASH:     gs_lgp->gnome_print_setdash( m_gpc, 2, wxCoord_dashed, 0 ); break;

⌨️ 快捷键说明

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