Text.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:5k
源码类别:
GIS编程
开发平台:
Visual C++
- // Text.cpp: implementation of the CText class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Draw.h"
- #include "Text.h"
- #include "math.h"
- #include "DrawDoc.h"
- //#include "DrawDoc.cpp"
- #define pi 3.1415926
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- extern IsRectCross(float minx,float miny,float maxx,float maxy);
- CText::CText();
- //CGraphPara* p_GraphPara;
- //float xMinScreen,yMinScreen,xMaxScreen,yMaxScreen;
- /*BOOL CText::IsRectCross(float minx,float miny,float maxx,float maxy)
- {
- if(minx>xMaxScreen||maxx<xMinScreen||miny>yMaxScreen||maxy<yMinScreen)
- return FALSE; //如两个矩形不相交
- else
- return TRUE;
- }*/
- void CText::Draw(CDC* pDC,int m_DrawMode,int m_DrawModel,short BackColor)
- {
- if(b_Delete)
- return ;
- float minx,miny,maxx,maxy;
- GetRect(&minx,&miny,&maxx,&maxy);//得到边界矩形
- if(!IsRectCross(minx,miny,maxx,maxy))//如果边界矩形不与屏幕窗口相交
- return;
- short ColorPen=m_ColorPen;
- if(m_DrawModel==2)
- ColorPen=BackColor;
- CFont cjcf;
- int hight,wide,cc1,cc2,cd,angg;
- unsigned char c1,c2;
- float x1,y1,angl;
- char bz[4];
- const char *ls1;
- if(m_DrawMode==0)
- pDC->SetROP2(R2_COPYPEN);
- else if(m_DrawMode==1)
- pDC->SetROP2(R2_NOT);
- pDC->SetBkMode(TRANSPARENT);
- hight=DLtoVL(m_TextHeight);
- angl=(float)(m_Angle1*pi/180);
- if(hight<3||hight>200)
- return;
- x1=m_StartX-m_TextHeight*(float)sin(angl);
- y1=m_StartY+m_TextHeight*(float)cos(angl);
- angg=(int)(m_Angle2*10);
- wide=DLtoVL(m_TextWide);
- DPtoVP(x1,y1,&cc1,&cc2);
- cjcf.CreateFont(hight,wide,angg,0,50,0,0,0,255,OUT_TT_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,FIXED_PITCH,"cjc");
- CFont* cjcbakf=pDC->SelectObject(&cjcf);
- pDC->SetBkMode(TRANSPARENT);
- CGraphPara m_GraphPara;
- CGraphPara *p_GraphPara;
- p_GraphPara=&m_GraphPara;
- pDC->SetTextColor(p_GraphPara->GetColor(ColorPen));
- ls1=(const char *)c_Text;
- cd=strlen(ls1);
- while(cd>0)
- {
- c1=*ls1;
- c2=*(ls1+1);
- if(c1>c2&&c2>127)
- {
- strncpy(bz,ls1,2);
- bz[2]=0;
- ls1=ls1+2;
- pDC->TextOut(cc1,cc2,bz);
- cd=cd-2;
- x1=x1+(m_TextWide*2+m_OffWide)*(float)cos(angl);
- y1=y1+(m_TextWide*2+m_OffWide)*(float)sin(angl);
- DPtoVP(x1,y1,&cc1,&cc2);
- }
- else
- {
- strncpy(bz,ls1,1);
- bz[1]=0;
- ls1++;
- pDC->TextOut(cc1,cc2,bz);
- cd=cd-1;
- x1=x1+(m_TextWide*2+m_OffWide/2)*(float)cos(angl);
- y1=y1+(m_TextWide*2+m_OffWide/2)*(float)sin(angl);
- DPtoVP(x1,y1,&cc1,&cc2);
- }
- }
- pDC->SelectObject(cjcbakf);
- }
- void CText::GetRect(float *minX,float *minY,float* maxX,float* maxY )
- {
- float x[4],y[4];
- double ang=pi*m_Angle1/180;
- x[0]=m_StartX;
- y[0]=m_StartY;
- x[1]=m_StartX+(float)((m_TextWide+m_OffWide)*m_TextLong*cos(ang));
- y[1]=m_StartY+(float)((m_TextWide+m_OffWide)*m_TextLong*sin(ang));
- x[2]=x[1]-(float)(sin(ang)*m_TextHeight);
- y[2]=y[1]+(float)(cos(ang)*m_TextHeight);
- x[3]=m_StartX-(float)(sin(ang)*m_TextHeight);
- y[3]=m_StartY-(float)(cos(ang)*m_TextHeight);
- *minX=m_StartX;
- *minY=m_StartY;
- *maxX=m_StartX;
- *maxY=m_StartY;
- for(int i=1;i<4;i++) //比较得到最小和最大坐标值
- {
- if(*minX>x[i]) *minX=x[i];
- if(*minY>y[i]) *minY=y[i];
- if(*maxX<x[i]) *maxX=x[i];
- if(*maxY<y[i]) *maxY=y[i];
- }
- }
- BOOL CText::IsPoint(float x,float y,float j1,float blc)
- {
- PointStruct XY[4];
- float x1,y1,x2,y2;
- if(b_Delete)
- return FALSE;
- GetRect(&x1,&y1,&x2,&y2);
- if(!(x>=x1&&x<=x2&&y>=y1&&y<=y2))
- return FALSE;
- float ang=(float)pi*m_Angle1/180;
- XY[0].x=m_StartX;
- XY[0].y=m_StartY;
- XY[1].x=m_StartX+(float)((m_TextWide+m_OffWide)*m_TextLong*cos(ang));
- XY[1].y=m_StartY+(float)((m_TextWide+m_OffWide)*m_TextLong*sin(ang));
- XY[2].x=XY[1].x-(float)(sin(ang)*m_TextHeight);
- XY[2].y=XY[1].y+(float)(cos(ang)*m_TextHeight);
- XY[3].x=m_StartX-(float)(sin(ang)*m_TextHeight);
- XY[3].y=m_StartY+(float)(cos(ang)*m_TextHeight);
- if(PointRgn(x,y,4,XY,blc))
- return TRUE;
- return FALSE;
- }
- void CText::Move(float x_Move,float y_Move)
- {
- m_StartX+=x_Move;
- m_StartY+=y_Move;
- }
- void CText::Rotate(float baseX,float baseY,float angle)
- {
- RotatePoint(baseX,baseY,angle,&this->m_StartX,&this->m_StartY);
- RotatePoint(baseX,baseY,angle,&this->m_EndX,&this->m_EndY);
- m_Angle1+=(float)(angle*180/pi);
- m_Angle2+=(float)(angle*180/pi);
- }
- void CText::Init(short ColorPen,short ColorBrush,float LineWide,short LineType,short Layer,
- float StartX,float StartY,float Angle1,float Angle2,float TextHeight,
- float TextWide,float OffWide,int TextLong,CString Text)
- {
- m_ColorPen=ColorPen;
- m_ColorBrush=ColorBrush;
- m_LineWide=LineWide;
- m_LineType=LineType;
- m_Layer=Layer;
- m_StartX=StartX;
- m_StartY=StartY;
- m_Angle1=Angle1;
- m_Angle2=Angle2;
- m_TextHeight=TextHeight;
- m_TextWide=TextWide;
- m_OffWide=OffWide;
- m_TextLong=TextLong;
- c_Text=Text;
- }
- CText::~CText()
- {
- }