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

📄 stack.cpp

📁 mtext,编辑器,支持潜入对象
💻 CPP
字号:
// Stack.cpp: implementation of the CMTextStack class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ZWStack.h"
#include "Stack.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CMTextStack,CObject,1)
CMTextStack::CMTextStack()
{
	m_pFont=new CFont;
	m_pFont->CreatePointFont (100,_T("Arial"));
	m_pFont->GetLogFont(&m_lf);
	m_dwPenColor=RGB(255,0,255);
	m_strDownString=_T("m_strDownString");
	m_strUpString=_T("m_strUpString");
	m_StackStyle=StackS_Lean;
	m_fSizeScale=1.0; 
	m_iAlign=Align_Top;
}

CMTextStack::~CMTextStack()
{
	m_pFont->DeleteObject();
	delete m_pFont;
	m_pFont=NULL;
}

void CMTextStack::Serialize(CArchive &ar)
{	
	if(ar.IsStoring())
	{
	
		ar<<m_strDownString<<m_strUpString<<m_dwPenColor<<m_StackStyle;
		ar<<m_fSizeScale;//比例
		ar<<m_lf.lfCharSet;
		ar<<m_lf.lfClipPrecision;
		ar<<m_lf.lfEscapement;
		ar<<m_lf.lfHeight;
		ar<<m_lf.lfItalic;
		ar<<m_lf.lfOrientation;
		ar<<m_lf.lfOutPrecision;
		ar<<m_lf.lfPitchAndFamily;
		ar<<m_lf.lfQuality;	
		ar<<m_lf.lfWidth;
		ar<<m_lf.lfWeight;
		ar<<m_lf.lfUnderline;
		ar<<m_lf.lfStrikeOut;

		CString str=m_lf.lfFaceName;
		ar<<str;
	
	}
	else
	{
		ar>>m_strDownString>>m_strUpString>>m_dwPenColor>>m_StackStyle;
			ar>>m_fSizeScale;//比例
			ar>>m_lf.lfCharSet;
			ar>>m_lf.lfClipPrecision;
			ar>>m_lf.lfEscapement;
			ar>>m_lf.lfHeight;
			ar>>m_lf.lfItalic;
			ar>>m_lf.lfOrientation;
			ar>>m_lf.lfOutPrecision;
			ar>>m_lf.lfPitchAndFamily;
			ar>>m_lf.lfQuality;	
			ar>>m_lf.lfWidth;
			ar>>m_lf.lfWeight;
			ar>>m_lf.lfUnderline;
			ar>>m_lf.lfStrikeOut;
			CString str;
			ar>>str;
			::lstrcpy(m_lf.lfFaceName,str);
			m_pFont->DeleteObject();
			m_pFont->CreateFontIndirect(&m_lf);
	
	}	
}


void CMTextStack::OnDraw(CDC *pDC)
{
	switch(m_StackStyle) 
	{
	case StackS_Horizontal:
		DrawHorizontal(pDC);
		break;
	case StackS_Tolerance:
		DrawTolerance(pDC);
		break;
	case StackS_Lean:
		DrawLean(pDC);
		break;
	}
}

void CMTextStack::CalcNodeSize(CDC *pDC, CSize &sizeNode)
{
	
	ASSERT(pDC != NULL);
	CString strMax;
	switch(m_StackStyle) 
	{
	case StackS_Horizontal:
	case StackS_Tolerance:
		strMax=m_strDownString.GetLength()>m_strUpString.GetLength()?m_strDownString:m_strUpString;
		break;
	case StackS_Lean:
		strMax=m_strDownString+m_strUpString;
		break;
	}
	sizeNode = pDC->GetTextExtent(strMax,strMax.GetLength());
	sizeNode.cy*=2;
	sizeNode += CSize(CX_INSET * 2, CY_INSET * 2);
}

void CMTextStack::DrawTolerance(CDC *pDC)
{
	CPoint ptStartPoint(CX_MARGIN, CY_MARGIN);
	CSize  sizeNode;
	
	m_pFont->DeleteObject();
	m_lf.lfHeight=LONG(m_lf.lfHeight*m_fSizeScale);
	m_pFont->CreateFontIndirect(&m_lf);
	m_lf.lfHeight=LONG(m_lf.lfHeight/m_fSizeScale);
	CFont *pOldFond=pDC->SelectObject(m_pFont);

	
	CalcNodeSize(pDC,sizeNode);
	CRect rect(ptStartPoint, sizeNode);
	if (!pDC->RectVisible(&rect))
		return ;
	BOOL bOK = TRUE;
	
	CPen* pOldPen = NULL;
	CPen penNewPen;
	int nPenStyle =PS_SOLID;
	if (penNewPen.CreatePen(nPenStyle, 1, m_dwPenColor))
		pOldPen = pDC->SelectObject(&penNewPen);
	
	rect.InflateRect(-CX_INSET, -CY_INSET);
	pDC->SetTextColor(m_dwPenColor);
	if (!pDC->ExtTextOut(rect.left, rect.top, ETO_CLIPPED, rect,
		m_strUpString,m_strUpString.GetLength(), NULL))
		return ;
	
	if (!pDC->ExtTextOut(rect.left, rect.CenterPoint().y+2*Y_OFFSET, ETO_CLIPPED, rect,
		m_strDownString,m_strDownString.GetLength(), NULL))
		return ;
	
	pDC->SelectObject(pOldPen);
	pDC->SelectObject(pOldFond);
}
void CMTextStack::DrawLean(CDC *pDC)
 {
 	CPoint ptStartPoint(CX_MARGIN, CY_MARGIN);
 	CSize  sizeNode;
 	
	m_pFont->DeleteObject();
	m_lf.lfHeight=LONG(m_lf.lfHeight*m_fSizeScale);
	m_pFont->CreateFontIndirect(&m_lf);
	m_lf.lfHeight=LONG(m_lf.lfHeight/m_fSizeScale);
	CFont *pOldFond=pDC->SelectObject(m_pFont);
	
 	CalcNodeSize(pDC,sizeNode);
 	CRect rect(ptStartPoint, sizeNode);
 	if (!pDC->RectVisible(&rect))
 		return ;
 	BOOL bOK = TRUE;
 	
 	CPen* pOldPen = NULL;
 	CPen penNewPen;
 	int nPenStyle =PS_SOLID;
 	if (penNewPen.CreatePen(nPenStyle, 1, m_dwPenColor))
 		pOldPen = pDC->SelectObject(&penNewPen);
 	
 	///////////////画斜分数线////////////////
 
 	CSize upSize;

 	CalcStringSize(pDC,m_strUpString,upSize);
 	CRect upRect(ptStartPoint,upSize);
	
 	pDC->MoveTo(upRect.right-upSize.cy,upRect.bottom+upSize.cy);
 	pDC->LineTo(upRect.right+upSize.cy,upRect.bottom-upSize.cy);
 
 	rect.InflateRect(-CX_INSET, -CY_INSET);
 	pDC->SetTextColor(m_dwPenColor); 
 	if (!pDC->ExtTextOut(rect.left, rect.top, ETO_CLIPPED, rect,
 		m_strUpString,m_strUpString.GetLength(), NULL))
 		return ;
 	
 	if (!pDC->ExtTextOut(upRect.right+2*X_OFFSET,rect.CenterPoint().y+2*Y_OFFSET, ETO_CLIPPED, rect,
 		m_strDownString,m_strDownString.GetLength(), NULL))
 		return ;
 	
 	pDC->SelectObject(pOldPen);
 	pDC->SelectObject(pOldFond);
 }
void CMTextStack::DrawHorizontal(CDC *pDC)
{
	CPoint ptStartPoint(CX_MARGIN, CY_MARGIN);
	CSize  sizeNode;
	
	m_pFont->DeleteObject();
	m_lf.lfHeight=LONG(m_lf.lfHeight*m_fSizeScale);
	m_pFont->CreateFontIndirect(&m_lf);
	m_lf.lfHeight=LONG(m_lf.lfHeight/m_fSizeScale);
	CFont *pOldFond=pDC->SelectObject(m_pFont);

	CalcNodeSize(pDC,sizeNode);
	CRect rect(ptStartPoint, sizeNode);
	if (!pDC->RectVisible(&rect))
		return ;
	BOOL bOK = TRUE;
	
	CPen* pOldPen = NULL;
	CPen penNewPen;
	int nPenStyle =PS_SOLID;
	if (penNewPen.CreatePen(nPenStyle, 1, m_dwPenColor))
		pOldPen = pDC->SelectObject(&penNewPen);
	
	pDC->MoveTo(rect.left,rect.CenterPoint().y+Y_OFFSET);
	pDC->LineTo(rect.right,rect.CenterPoint().y+Y_OFFSET);
	rect.InflateRect(-CX_INSET, -CY_INSET);
	pDC->SetTextColor(m_dwPenColor);
	if (!pDC->ExtTextOut(rect.left, rect.top, ETO_CLIPPED, rect,
		m_strUpString,m_strUpString.GetLength(), NULL))
		return ;
	
	if (!pDC->ExtTextOut(rect.left, rect.CenterPoint().y+2*Y_OFFSET, ETO_CLIPPED, rect,
		m_strDownString,m_strDownString.GetLength(), NULL))
		return ;
	
	pDC->SelectObject(pOldPen);
	pDC->SelectObject(pOldFond);
}
void CMTextStack::CalcStringSize(CDC *pDC, CString strCalc, CSize &sizeNode)
{
	ASSERT(pDC != NULL);
	sizeNode = pDC->GetTextExtent(strCalc,
		strCalc.GetLength());
//	sizeNode += CSize(CX_INSET * 2, CY_INSET * 2);
}

⌨️ 快捷键说明

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