void wxMemoryDCImpl::Init() { if ( m_ok ) { SetBrush(*wxWHITE_BRUSH); SetPen(*wxBLACK_PEN); // the background mode is only used for text background and is set in // DrawText() to OPAQUE as required, otherwise always TRANSPARENT ::SetBkMode( GetHdc(), TRANSPARENT ); } }
void wxPrinterDC::DoDrawBitmap(const wxBitmap& bmp, wxCoord x, wxCoord y, bool useMask) { wxCHECK_RET( bmp.Ok(), _T("invalid bitmap in wxPrinterDC::DrawBitmap") ); int width = bmp.GetWidth(), height = bmp.GetHeight(); if ( !(::GetDeviceCaps(GetHdc(), RASTERCAPS) & RC_STRETCHDIB) || !DrawBitmapUsingStretchDIBits(GetHdc(), bmp, x, y) ) { // no support for StretchDIBits() or an error occurred if we got here wxMemoryDC memDC; memDC.SelectObject(bmp); Blit(x, y, width, height, &memDC, 0, 0, wxCOPY, useMask); memDC.SelectObject(wxNullBitmap); } }
void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap ) { // select old bitmap out of the device context if ( m_oldBitmap ) { ::SelectObject(GetHdc(), (HBITMAP) m_oldBitmap); if ( m_selectedBitmap.Ok() ) { m_selectedBitmap.SetSelectedInto(NULL); m_selectedBitmap = wxNullBitmap; } } // check for whether the bitmap is already selected into a device context wxASSERT_MSG( !bitmap.GetSelectedInto() || (bitmap.GetSelectedInto() == GetOwner()), wxT("Bitmap is selected in another wxMemoryDC, delete the first wxMemoryDC or use SelectObject(NULL)") ); m_selectedBitmap = bitmap; WXHBITMAP hBmp = m_selectedBitmap.GetHBITMAP(); if ( !hBmp ) return; m_selectedBitmap.SetSelectedInto(GetOwner()); hBmp = (WXHBITMAP)::SelectObject(GetHdc(), (HBITMAP)hBmp); if ( !hBmp ) { wxLogLastError(wxT("SelectObject(memDC, bitmap)")); wxFAIL_MSG(wxT("Couldn't select a bitmap into wxMemoryDC")); } else if ( !m_oldBitmap ) { m_oldBitmap = hBmp; } }
wxEnhMetaFile *wxEnhMetaFileDCImpl::Close() { wxCHECK_MSG( IsOk(), NULL, _T("invalid wxEnhMetaFileDC") ); HENHMETAFILE hMF = ::CloseEnhMetaFile(GetHdc()); if ( !hMF ) { wxLogLastError(_T("CloseEnhMetaFile")); return NULL; } wxEnhMetaFile *mf = new wxEnhMetaFile; mf->SetHENHMETAFILE((WXHANDLE)hMF); return mf; }
void FastDC::SetFontStyles(int fontStyles, std::map<int,wxFont>& fontMap) { const int fontStyle = (fontStyles & wxFONTFLAG_ITALIC) ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL; const int fontWeight = (fontStyles & wxFONTFLAG_BOLD) ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL; const bool fontUnderline = (fontStyles & wxFONTFLAG_UNDERLINED) ? true : false; // Check if we need to change font style // (changing the font can be expensive, so we want to avoid it if possible) const bool styleChanged = (m_font.GetStyle() != fontStyle); const bool widthChanged = (m_font.GetWeight() != fontWeight); const bool underlineChanged = (m_font.GetUnderlined() != fontUnderline); if (!styleChanged && !widthChanged && !underlineChanged) return; // Check if we have font in cache std::map<int,wxFont>::const_iterator p = fontMap.find(fontStyles); if (p == fontMap.end()) { m_font.SetStyle(fontStyle); m_font.SetWeight(fontWeight); m_font.SetUnderlined(fontUnderline); fontMap[fontStyles] = m_font; } else m_font = p->second; /*m_font.SetStyle(fontStyle); m_font.SetWeight(fontWeight); m_font.SetUnderlined(fontUnderline);*/ #ifdef __WXMSW__ HGDIOBJ hfont = ::SelectObject(GetHdc(), GetHfontOf(m_font)); if ( hfont == HGDI_ERROR ) { wxLogLastError(_T("SelectObject(font)")); } else // selected ok { if ( !m_oldFont ) m_oldFont = (WXHPEN)hfont; } #else SetFont(m_font); #endif }
bool wxPrinterDCImpl::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord WXUNUSED(xsrc), wxCoord WXUNUSED(ysrc), wxRasterOperationMode WXUNUSED(rop), bool useMask, wxCoord WXUNUSED(xsrcMask), wxCoord WXUNUSED(ysrcMask)) { wxDCImpl *impl = source->GetImpl(); wxMSWDCImpl *msw_impl = wxDynamicCast(impl, wxMSWDCImpl); if (!msw_impl) return false; wxBitmap& bmp = msw_impl->GetSelectedBitmap(); wxMask *mask = useMask ? bmp.GetMask() : NULL; if ( mask ) { // If we are printing source colours are screen colours not printer // colours and so we need copy the bitmap pixel by pixel. RECT rect; HDC dcSrc = GetHdcOf(*msw_impl); MemoryHDC dcMask(dcSrc); SelectInHDC selectMask(dcMask, (HBITMAP)mask->GetMaskBitmap()); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { COLORREF cref = ::GetPixel(dcMask, x, y); if (cref) { HBRUSH brush = ::CreateSolidBrush(::GetPixel(dcSrc, x, y)); rect.left = xdest + x; rect.right = rect.left + 1; rect.top = ydest + y; rect.bottom = rect.top + 1; ::FillRect(GetHdc(), &rect, brush); ::DeleteObject(brush); } } } } else // no mask { if ( !(::GetDeviceCaps(GetHdc(), RASTERCAPS) & RC_STRETCHDIB) || !DrawBitmapUsingStretchDIBits(GetHdc(), bmp, xdest, ydest) ) { // no support for StretchDIBits // as we are printing, source colours are screen colours not // printer colours and so we need copy the bitmap pixel by pixel. HDC dcSrc = GetHdcOf(*msw_impl); RECT rect; for (int y = 0; y < height; y++) { // optimization: draw identical adjacent pixels together. for (int x = 0; x < width; x++) { COLORREF col = ::GetPixel(dcSrc, x, y); HBRUSH brush = ::CreateSolidBrush( col ); rect.left = xdest + x; rect.top = ydest + y; while( (x + 1 < width) && (::GetPixel(dcSrc, x + 1, y) == col ) ) { ++x; } rect.right = xdest + x + 1; rect.bottom = rect.top + 1; ::FillRect((HDC) m_hDC, &rect, brush); ::DeleteObject(brush); } } } } return true; }