示例#1
0
//
/// Maps the points of the printer DC to the screen DC. Sets the screen window
/// extent equal to the maximum logical pointer of the printer DC.
///
/// It is assumed that the viewport extents of the screen DC
/// are already set and represent the full previewed page. 
/// The window extents are set to the page size in logical units
/// as defined by the printer DC.
//
void
TPrintPreviewDC::ReScale()
{
  // Get the extents of the screen viewport in device units (pixels).
  // This should represent the whole previewed page on the screen.

  TSize ve; ::GetViewportExtEx(GetHDC(), &ve);

  // Calculate the size of the previewed page in logical units.

  TSize page = GetPageSizeInPixels(PrnDC);
  TSize pve = PrnDC.GetViewportExt();
  TSize pwe = PrnDC.GetWindowExt();
  TSize we(MulDiv(page.cx, pwe.cx, pve.cx), MulDiv(page.cy, pwe.cy, pve.cy));

  // Set the mapping mode and scale.

  ::SetMapMode(GetHDC(), MM_ANISOTROPIC);
  ::SetWindowExtEx(GetHDC(), we.cx, we.cy, 0);
  ::SetViewportExtEx(GetHDC(), ve.cx, ve.cy, 0);

  // Set the origin for logical units.

  ReOrg();
}
示例#2
0
//
// Set the color table of the currently selected bitmap.
//
uint
TDibDC::SetDIBColorTable(uint start, uint count, const RGBQUAD * colors)
{
# if defined(__GNUC__)
  return ::SetDIBColorTable(GetHDC(), start, count, (RGBQUAD*)colors);
# else
  return ::SetDIBColorTable(GetHDC(), start, count, colors);
# endif //WINELIB
}
示例#3
0
//************************************************************************
// CLCDGfx::DrawBitmap
//************************************************************************
void CLCDGfx::DrawBitmap(int nX, int nY,int nWidth, int nHeight, HBITMAP hBitmap)
{
	HDC hCompatibleDC = CreateCompatibleDC(GetHDC());
	HBITMAP hOldBitmap = (HBITMAP)SelectObject(hCompatibleDC, hBitmap);

	BitBlt(GetHDC(), nX, nY, nWidth, nHeight, hCompatibleDC, 0, 0, SRCCOPY);

	// restores
	SelectObject(hCompatibleDC, hOldBitmap);
	DeleteDC(hCompatibleDC);
}
示例#4
0
void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent& event)
{
  /* realize palette if this is *not* the current window */
  if ( GetPalette() &&
       GetPalette()->Ok() && (this != event.GetChangedWindow()) )
  {
    ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE());
    ::SelectPalette(GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
    ::RealizePalette(GetHDC());
    Refresh();
  }
}
示例#5
0
void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent& event)
{
  /* realize palette if this is the current window */
  if ( GetPalette()->Ok() ) {
    ::UnrealizeObject((HPALETTE) GetPalette()->GetHPALETTE());
    ::SelectPalette(GetHDC(), (HPALETTE) GetPalette()->GetHPALETTE(), FALSE);
    ::RealizePalette(GetHDC());
    Refresh();
    event.SetPaletteRealized(true);
  }
  else
    event.SetPaletteRealized(false);
}
示例#6
0
文件: XFont.cpp 项目: g200kg/SkinMan
void XGraphics::MeasureString(wchar_t *str,int n,XFont *font,PointF ptf,RectF *rcf) {
	rcf->X=ptf.X;
	rcf->Y=ptf.Y;
	rcf->Width=0;
	rcf->Height=0;
	if(font->dwFontType&TRUETYPE_FONTTYPE)
		Graphics::MeasureString(str,n,font->font,ptf,rcf);
	else {
		HDC hdc=GetHDC();
		SIZE sz;
		wchar_t strTemp[1024];
		HFONT hfontOld=(HFONT)SelectObject(hdc,font->hfont);
		if(n<0)
			n=wcslen(str);
		wcsncpy_s(strTemp,1024,str,n);
		strTemp[n]=0;
		while(n>0 && strTemp[n-1]==' ')
			--n,strTemp[n]=0;
		++n;
		wcscat_s(strTemp,1024,L" ");
		GetTextExtentPoint32(hdc,strTemp,n,&sz);
		SelectObject(hdc,hfontOld);
		ReleaseHDC(hdc);
		rcf->X=ptf.X;
		rcf->Y=ptf.Y;
		rcf->Width=(float)sz.cx;
		rcf->Height=(float)sz.cy;
	}
}
示例#7
0
//
/// Sets the current text color of this DC to the given color value. The text color
/// determines the color displayed by TDC::TextOut and TDC::ExtTextOut.
//
TColor
TPrintPreviewDC::SetTextColor(const TColor& color)
{
  TColor result = PrnDC.SetTextColor(color);
  ::SetTextColor(GetHDC(), PrnDC.GetTextColor());
  return result;
}
示例#8
0
文件: WPGDI.CPP 项目: 1000copy/Piero
//////////////////
// Create memory DC from bitmap
// 
WPMemDC::WPMemDC(WPDevContext *dc, WPBitmap *bm)
{
	hdc = CreateCompatibleDC(GetHDC(dc));
	assert(hdc);
	if (bm)
		setBitmap(bm);
	if (dc)
		mapMode(dc->mapMode());
}
示例#9
0
/// Sets the screen font equal to the current printer font.
//
/// SyncFont performs a simple font match attempt, with a retry option if
/// the GDI selected match is too different from the selected printer font.
/// In print preview, matching the size of the characters is more important
/// than matching their appearance.  In most cases, the print preview will
/// barely be legible anyway.  Size is most important because you don't
/// want character size differences to change the line breaks or page
/// breaks of the on-screen document from what they would be on the
/// printed page.  This effect is minimized in this TPrintPreviewDC object,
/// since info reports such as GetTextMetrics and GetTextExtent are always
/// reported from the printer dc using the real font.  Internal calculations
/// should be the same for preview as for printing, but the output accuracy
/// will depend upon the accuracy of font selection.
///
/// It is also possible to take over control of the text output functions
/// through this DC object - the TextOut and other text methods are virtual.
/// You can place each character on the preview screen yourself, if you
/// desire more precision in character placement than GDI's font matching
/// can provide.  That's a lot of work, and a lot of code, and isn't
/// necessary to meet the needs of most applications.
///
/// SyncFont is virtual so that you may substitute your own font matching
/// algorythm with more font matching heuristics.
//
void
TPrintPreviewDC::SyncFont()
{
  //
  // set screen font to match current printer font.
  //
  LOGFONT lf;
  ::GetObject(PrnFont, sizeof(lf), &lf);

  TEXTMETRIC tm;
  PrnDC.GetTextMetrics(tm);

  lf.lfHeight         = GlyphHeight(tm);
  lf.lfWidth          = tm.tmAveCharWidth;
  lf.lfWeight         = tm.tmWeight;
  lf.lfItalic         = tm.tmItalic;
  lf.lfUnderline      = tm.tmUnderlined;
  lf.lfStrikeOut      = tm.tmStruckOut;
  lf.lfCharSet        = tm.tmCharSet;
  lf.lfOutPrecision   = OUT_TT_PRECIS;
  lf.lfClipPrecision  = CLIP_DEFAULT_PRECIS;
  lf.lfQuality        = DRAFT_QUALITY;

  // Keep just the pitch (low 2 bits). Ignore the family
  //
  lf.lfPitchAndFamily = uint8((tm.tmPitchAndFamily & 0x0003) | FF_DONTCARE);
  PrnDC.GetTextFace(sizeof(lf.lfFaceName)/sizeof(lf.lfFaceName[0]), lf.lfFaceName);

  ::DeleteObject(::SelectObject(GetHDC(), ::CreateFontIndirect(&lf)));

  //
  // if height isn't right, relax the font pitch and facename requirements
  //
  GetTextMetrics(tm);
  if (abs(abs(static_cast<int>(lf.lfHeight)) - abs(GlyphHeight(tm))) > 2) {
    if (lf.lfPitchAndFamily & FF_DECORATIVE)
      lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DECORATIVE;
    else
      lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
    lf.lfFaceName[0] = 0;
    ::DeleteObject(::SelectObject(GetHDC(), CreateFontIndirect(&lf)));
  }
}
示例#10
0
//
/// Gets the x- and y- extents of the viewport, equalizes the logical and screen
/// points, and resets the x- and y- extents of the viewport.
//
void
TPrintPreviewDC::ReOrg()
{
  // Get the viewport origin of the printer DC and transform it into 
  // screen device units. It is assumed that the viewport extents of
  // the screen DC represent the whole previewed page.

  TPoint pvo = PrnDC.GetViewportOrg();
  TSize page = GetPageSizeInPixels(PrnDC);
  TSize ve; ::GetViewportExtEx(GetHDC(), &ve); // screen extents
  TPoint vo(MulDiv(pvo.x, ve.cx, page.cx), MulDiv(pvo.y, ve.cy, page.cy));

  // Use the same logical origin as the printout. 

  TPoint wo = PrnDC.GetWindowOrg();

  // Set the origins.

  ::SetWindowOrgEx(GetHDC(), wo.x, wo.y, 0);
  ::SetViewportOrgEx(GetHDC(), vo.x, vo.y, 0);
}
示例#11
0
//////////////////////////////////////////////////////////
// TMapDC
// ------
//
TMapDC::~TMapDC()
{
	// Restore first pen of DC
	OrgPen = hOldPen;
	RestoreObjects();

	// If DC created with GetDC, call ReleseDC
	if ( FromWindow )
	{
		::ReleaseDC (pEditor->Handle, GetHDC());
		Handle = 0;		// DC destroyed
	}
}
示例#12
0
//************************************************************************
// CLCDGfx::DrawText
//************************************************************************
void CLCDGfx::DrawText(int nX,int nY,int nWidth,tstring strText)
{
	SIZE sizeLine =  {0, 0};
	SIZE sizeCutOff = {0, 0};

	GetTextExtentPoint(GetHDC(),_T("..."),3,&sizeCutOff);

	int *piWidths = new int[strText.length()];
	int iMaxChars = 0;

	GetTextExtentExPoint(GetHDC(), strText.c_str(), (int)strText.length(), nWidth, &iMaxChars, piWidths, &sizeLine);

	if(iMaxChars < strText.length()) {
		for(iMaxChars--;iMaxChars>0;iMaxChars--)
			if(piWidths[iMaxChars] + sizeCutOff.cx <= nWidth)
				break;

		DrawText(nX,nY,(strText.substr(0,iMaxChars) + _T("...")).c_str());
	}
	else DrawText(nX,nY,strText.c_str());
	delete[] piWidths;
}
示例#13
0
//************************************************************************
// CLCDGfx::SetClipRegion
//************************************************************************
void CLCDGfx::SetClipRegion(int iX,int iY,int iWidth,int iHeight)
{
	ASSERT(NULL != m_hPrevBitmap);

	m_rClipRegion.left = iX;
	m_rClipRegion.right = iX+iWidth;
	m_rClipRegion.top = iY;
	m_rClipRegion.bottom = iY+iHeight;

	HRGN hRgn = CreateRectRgn(iX,iY,iX+iWidth,iY+iHeight);
	SelectClipRgn(GetHDC(), hRgn);
	DeleteObject(hRgn);
}
示例#14
0
/**
 *\fn           HDC SelectImageDC(int id)
 *\brief        ѡȡͼÏñID
 *\param[in]    int id ͼÏñDCÐòºÅ
 *\return       ͼÏñDC¾ä±ú
 */
HDC CXTDC::SelectImageDC(int id)
{
    int cx = 0;
    int cy = 0;

    if (GetBmpRect(id, cx, cy))
    {
        curImageDC_ = GetHDC(IMAGEDC, id);
        ::BitBlt(curCompDC_, 0, 0, cx, cy, curImageDC_, 0, 0, SRCCOPY);		
        return curImageDC_;
    }

    return NULL;
}
示例#15
0
文件: WPGDI.CPP 项目: 1000copy/Piero
//////////////////
// Create memory DC compatible w/existing DC.
// Rectangle says which window in primary DC to map; 
// "mono" flags creates monochrome bitmap.
//
WPMemDC::WPMemDC(WPDevContext *dc, WPRect& winRect, BOOL mono)
{
	hdc = CreateCompatibleDC(GetHDC(dc));
	assert(hdc);

	// Get bitmap dimensions: convert window rect to device coords.
	WPPoint p(winRect.width(), winRect.height());
	if (dc) {
		dc->LP2DP(&p, 1);
		mapMode(dc->mapMode());
	}
	HBITMAP h = 
		CreateCompatibleBitmap((dc && !mono) ? (*dc)() : hdc, p.x, p.y);
	assert(h);
	select(SELBITMAP, h, TRUE);
	windowOrg(winRect.origin()); // window origin = top left corner of rect
}
示例#16
0
wxPaintDCImpl::wxPaintDCImpl( wxDC *owner, wxWindow *window ) :
   wxClientDCImpl( owner )
{
    wxCHECK_RET( window, wxT("NULL canvas in wxPaintDCImpl ctor") );

#ifdef wxHAS_PAINT_DEBUG
    if ( g_isPainting <= 0 )
    {
        wxFAIL_MSG( wxT("wxPaintDCImpl may be created only in EVT_PAINT handler!") );

        return;
    }
#endif // wxHAS_PAINT_DEBUG

    // see comments in src/msw/window.cpp where this is defined
    extern bool wxDidCreatePaintDC;

    wxDidCreatePaintDC = true;


    m_window = window;

    // do we have a DC for this window in the cache?
    m_hDC = FindDCInCache(m_window);
    if ( !m_hDC )
    {
        // not in cache, create a new one
        wxPaintDCInfoOur* const info = new wxPaintDCInfoOur(m_window);
        gs_PaintDCInfos[m_window] = info;
        m_hDC = info->GetHDC();
    }

    // Note: at this point m_hDC can be NULL under MicroWindows, when dragging.
    if (!GetHDC())
        return;

    // (re)set the DC parameters.
    InitDC();

    // the HDC can have a clipping box (which we didn't set), make sure our
    // DoGetClippingBox() checks for it
    m_clipping = true;
}
示例#17
0
文件: XFont.cpp 项目: g200kg/SkinMan
Status XGraphics::DrawString(const WCHAR *str,INT len,const XFont *font,const RectF &rcf,const StringFormat *form,const Brush *br) {
	if(font->dwFontType&TRUETYPE_FONTTYPE)
		return Graphics::DrawString(str,len,font->font,rcf,form,br);
	else {
		HDC hdc=GetHDC();
		HFONT hfontOld=(HFONT)SelectObject(hdc,font->hfont);
		RECT rc;
		Color col;
		COLORREF cref;
		SolidBrush *sbr=(SolidBrush*)br;
		sbr->GetColor(&col);
		cref=RGB(col.GetR(),col.GetG(),col.GetB());
		rc.left=(LONG)rcf.X;
		rc.top=(LONG)rcf.Y;
		rc.right=rc.left+(LONG)rcf.Width;
		rc.bottom=rc.top+(LONG)rcf.Height;
		SetTextColor(hdc,cref);
		DrawText(hdc,str,len,&rc,DT_LEFT|DT_TOP);
		SelectObject(hdc,hfontOld);
		ReleaseHDC(hdc);
	}
	return Ok;
}
示例#18
0
//
// Get the color table of the currently selected bitmap.
//
uint
TDibDC::GetDIBColorTable(uint start, uint count, RGBQUAD * colors)
{
  return ::GetDIBColorTable(GetHDC(), start, count, colors);
}