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

📄 text.cpp

📁 串口 操作 源码 打标机的控制程序
💻 CPP
字号:
#include "stdafx.h"
#include "math.h"
#include "dabiao.h"
#include "dabiaoDoc.h"
#include "dabiaoView.h"
#include "Text.h"
#include <afxdlgs.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern class CDabiaoView*	g_pView;
extern class CDabiaoDoc*	g_pDoc;
extern int viewx,viewscale,viewy,viewwidth,sviewx,sviewy;
///////////////////////////////////////
IMPLEMENT_SERIAL(CText,CObject,1)
CText::CText(const CPoint& begin,UINT high,UINT width,UINT far,CString text,int type,LOGFONT lf)
{

	m_begin =begin;
	m_high  =high;
	m_text  =text;
	m_width =width;
	m_type  =type;
    m_far   =0;
	memcpy(&m_lf,&lf, sizeof(LOGFONT));

}

CText::CText()
{
	m_begin =0;
	m_high  =0;
	m_text  ="";
	m_width =0;
	m_type  =0;
    m_far   =0;
}

CPoint CText::GetBeginPos()
{
	CPoint point;
	point.x=m_begin.x*viewscale+viewx;
	point.y=m_begin.y*viewscale+viewy;
	return point;
}


CPoint CText::GetEndPos()
{
	CPoint end;
	end.y=GetBeginPos().y+m_high*viewscale;
	end.x=GetBeginPos().x+m_text.GetLength()*(m_width*viewscale);
	if(end.y < viewy)
		end.y = viewy;
	if(end.x > viewx+viewwidth)
		end.x=viewx+viewwidth;
	return end;
}

int CText::GetHigh()
{
	
	return m_high*viewscale;

}

int CText::GetWidth()
{
	return m_width*viewscale;
}
CString CText::GetText()
{
	return m_text;
}

CText::~CText()
{
}

void CText::Init()
{
	m_color = RGB(0,0,0);
    m_linetype = PS_SOLID;
	m_linewidth = 1 ;
	m_begin.x=0;
	m_begin.y=10;
	m_high=10;
}

int CText::GetType()
{
	return m_type;
}
int CText::GetFar()
{
	return m_far*viewscale;
}
 void CText::Serialize(CArchive& ar)
{

	if(ar.IsStoring())
	{
		ar << m_begin.x;
		ar << m_begin.y;
		ar << m_text;
		ar << m_color;
		ar << m_linetype;
		ar << m_linewidth;
		ar << m_far;
		ar << m_high;
		ar << m_width;
		ar << m_type;
		/////////////////////
		///////////////////////////////
//		ar<<viewwidth;
//		ar<<viewhigh;

		////////////////
        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;
	
		ar<<m_datatype;
		ar<<m_timetype;
		ar<<viewscale;
	}
	else
	{
        ar >> m_begin.x;
		ar >>m_begin.y;
		ar >> m_text;
		ar >> m_color;
		ar >> m_linetype;
		ar >> m_linewidth;
		ar >> m_far;
		ar >> m_high;
		ar >> m_width;
		ar >> m_type;
		/////////////////////////
//		ar>>viewwidth;
//		ar>>viewhigh;
		///////////////////////
		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);
         ar>>m_datatype;
		 ar>>m_timetype;
		 ar>>viewscale;
		 
	}
}

void CText::Draw(CDC* pDC,int drawMode)
{

	int n=GetROP2(pDC->GetSafeHdc());
	CFont font0;
	m_lf.lfHeight=m_high;
	m_lf.lfWidth=m_width;
	font0.CreateFontIndirect(&m_lf);
	CFont* pOldFont0=pDC->SelectObject(&font0);
	pDC->TextOut(m_begin.x+sviewx,m_begin.y+sviewy,m_text);
	pDC->SelectObject(pOldFont0);


	CFont font1;
	m_lf.lfHeight=m_high*viewscale;
	m_lf.lfWidth=m_width*viewscale;
	font1.CreateFontIndirect(&m_lf);
    CPen pen;//修改画笔宽度
	pen.CreatePen(PS_SOLID,viewscale,RGB(0,0,0));
    CPen* pOldPen=pDC->SelectObject(&pen);
    CFont* pOldFont=pDC->SelectObject(&font1);
	if(drawMode!=0)
	{
		COLORREF color = RGB(255,0,0);
		pDC->SetTextColor(color);
	}
	else
	{
        COLORREF color = RGB(0,0,0);
		pDC->SetTextColor(color);
	}
	pDC->TextOut(m_begin.x*viewscale+viewx,m_begin.y*viewscale+viewy,m_text);
	pDC->SelectObject(pOldFont);
	pDC->SelectObject(pOldPen);
	pDC->SetROP2(n);

}

void CText::GetBox(BOX2D *pBox)
{
    pBox->min[0] = min( m_begin.x, GetEndPos().x );
	pBox->min[1] = min( m_begin.y, GetEndPos().y );
	pBox->max[0] = max( m_begin.x, GetEndPos().x );
	pBox->max[1] = max( m_begin.y, GetEndPos().y );
}

BOOL CText::Pick(const CPoint &pos)
{

	CPoint end,pos0;
	end=GetEndPos();
	if((pos.x > GetBeginPos().x)
		&&(pos.x < end.x)
		&&(pos.y > GetBeginPos().y)
		&&(pos.y < end.y)
		)
	{
		return TRUE;
	}
	return FALSE;
	
}

⌨️ 快捷键说明

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