Ejemplo n.º 1
0
void CPreviewDC::MirrorFont()
/***************************/
{
    if( m_hPrinterFont == NULL ) {
        SelectStockObject( DEVICE_DEFAULT_FONT );

        // SelectStockObject() calls MirrorFont(), so there's no need to do anything
        // else here.
    } else {
        LOGFONT     lf;
        TEXTMETRIC  tm;
        ::GetObject( m_hPrinterFont, sizeof( LOGFONT ), &lf );
        ::GetTextFace( m_hAttribDC, LF_FACESIZE, lf.lfFaceName );
        ::GetTextMetrics( m_hAttribDC, &tm );
        lf.lfHeight = tm.tmHeight;
        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.lfPitchAndFamily = tm.tmPitchAndFamily;

        HFONT hFont = ::CreateFontIndirect( &lf );
        ::SelectObject( m_hDC, hFont );
        if( m_hFont != NULL ) {
            ::DeleteObject( m_hFont );
        }
        m_hFont = hFont;
    }
}
Ejemplo n.º 2
0
PaintCanvas::~PaintCanvas()
{
  /* Select stock objects into the DC, to unreference the custom
     brushes and pens.  Older Windows CE versions (specifically
     PPC2000/2002) are known to be leaky when the DC is not cleaned
     up.  We don't need to change the bitmap selection, because a
     PaintCanvas should never have a selected bitmap. */
  SelectWhiteBrush();
  SelectBlackPen();
  SelectStockObject(SYSTEM_FONT);

  window.EndPaint(&ps);
}
Ejemplo n.º 3
0
//////////////////////////////////////////////////////////
// TMapDC
// ------
//
void
TMapDC::Init (TEditorClient *_pEditor)
{
#ifdef USE_PEN_CACHE
	if ( LastPens == NULL )		InitCacheData();
#endif

	// Pointer to editor client window
	pEditor = _pEditor;

	DoDelete = FALSE;
	CurPenColor = -1;
	CurPenWidth = 0;
	CurPenStyle = 0;

	hOldPen = 0;

	// Don't fill figures
	SelectStockObject (NULL_BRUSH);

	// Setup clipping region and Window and DC origins
	// SetupClipping();
	SetupOrg();
}
Ejemplo n.º 4
0
 void SelectBlackBrush() {
   SelectStockObject(BLACK_BRUSH);
 }
Ejemplo n.º 5
0
 void SelectWhiteBrush() {
   SelectStockObject(WHITE_BRUSH);
 }
Ejemplo n.º 6
0
 void SelectHollowBrush() {
   SelectStockObject(HOLLOW_BRUSH);
 }
Ejemplo n.º 7
0
 void SelectBlackPen() {
   SelectStockObject(BLACK_PEN);
 }
Ejemplo n.º 8
0
 void SelectWhitePen() {
   SelectStockObject(WHITE_PEN);
 }
Ejemplo n.º 9
0
 void SelectNullPen() {
   SelectStockObject(NULL_PEN);
 }
Ejemplo n.º 10
0
void CPreviewDC::MirrorFont()
{
	if (m_hAttribDC == NULL)
		return;         // Can't do anything without Attrib DC

	if (m_hPrinterFont == NULL)
	{
		SelectStockObject(DEVICE_DEFAULT_FONT); // will recurse
		return;
	}

	if (m_hDC == NULL)
		return;         // can't mirror font without a screen DC

	LOGFONT logFont;
	// Fill the logFont structure with the original info
	::GetObject(m_hPrinterFont, sizeof(LOGFONT), (LPVOID)&logFont);

	TEXTMETRIC tm;

	GetTextFace(LF_FACESIZE, (LPTSTR)&logFont.lfFaceName[0]);
	GetTextMetrics(&tm);

	// Set real values based on the Printer's text metrics.

	if (tm.tmHeight < 0)
		logFont.lfHeight = tm.tmHeight;
	else
		logFont.lfHeight = -(tm.tmHeight - tm.tmInternalLeading);

	logFont.lfWidth = 0;
	logFont.lfWeight = tm.tmWeight;
	logFont.lfItalic = tm.tmItalic;
	logFont.lfUnderline = tm.tmUnderlined;
	logFont.lfStrikeOut = tm.tmStruckOut;
	logFont.lfCharSet = tm.tmCharSet;
	logFont.lfPitchAndFamily = tm.tmPitchAndFamily;

	HFONT hNewFont = ::CreateFontIndirect(&logFont);
	::SelectObject(m_hDC, hNewFont);

	::GetTextMetrics(m_hDC, &tm);

	// Is the displayed font too large?

	int cyDesired = -logFont.lfHeight;
	int cyActual;
	if (tm.tmHeight < 0)
		cyActual = -tm.tmHeight;
	else
		cyActual = tm.tmHeight - tm.tmInternalLeading;

	CSize sizeWinExt;
	VERIFY(::GetWindowExtEx(m_hDC, &sizeWinExt));
	CSize sizeVpExt;
	VERIFY(::GetViewportExtEx(m_hDC, &sizeVpExt));

	// Only interested in Extent Magnitudes, not direction
	if (sizeWinExt.cy < 0)
		sizeWinExt.cy = -sizeWinExt.cy;
	if (sizeVpExt.cy < 0)
		sizeVpExt.cy = -sizeVpExt.cy;

	// Convert to screen device coordinates to eliminate rounding
	// errors as a source of SmallFont aliasing

	cyDesired = MulDiv(cyDesired, sizeVpExt.cy, sizeWinExt.cy);
	cyActual = MulDiv(cyActual, sizeVpExt.cy, sizeWinExt.cy);

	ASSERT(cyDesired >= 0 && cyActual >= 0);

	if (cyDesired < cyActual)
	{
		logFont.lfFaceName[0] = 0;      // let the mapper find a good fit

		if ((logFont.lfPitchAndFamily & 0xf0) == FF_DECORATIVE)
			logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DECORATIVE;
		else
			logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;

		HFONT hTempFont = ::CreateFontIndirect(&logFont);
		::SelectObject(m_hDC, hTempFont);           // Select it in.
		::DeleteObject(hNewFont);
		hNewFont = hTempFont;
	}

	AfxDeleteObject((HGDIOBJ*)&m_hFont);  // delete the old logical font
	m_hFont = hNewFont;         // save the new one

#ifdef _MAC
	VERIFY(::GetCharWidth(m_hDC, 0, 255, m_aCharWidthsDraw));
	VERIFY(::GetCharWidth(m_hAttribDC, 0, 255, m_aCharWidthsAttrib));
#endif
}