Text.cpp
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:5k
源码类别:

GIS编程

开发平台:

Visual C++

  1. // Text.cpp: implementation of the CText class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Draw.h"
  6. #include "Text.h"
  7. #include "math.h"
  8. #include "DrawDoc.h"
  9. //#include "DrawDoc.cpp"
  10. #define pi 3.1415926
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char THIS_FILE[]=__FILE__;
  14. #define new DEBUG_NEW
  15. #endif
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. extern  IsRectCross(float minx,float miny,float maxx,float maxy);
  20. CText::CText();
  21. //CGraphPara* p_GraphPara;
  22. //float xMinScreen,yMinScreen,xMaxScreen,yMaxScreen;
  23. /*BOOL CText::IsRectCross(float minx,float miny,float maxx,float maxy)
  24. {
  25. if(minx>xMaxScreen||maxx<xMinScreen||miny>yMaxScreen||maxy<yMinScreen)
  26. return FALSE;  //如两个矩形不相交
  27. else
  28. return TRUE;
  29. }*/
  30. void CText::Draw(CDC* pDC,int m_DrawMode,int m_DrawModel,short BackColor)
  31. {
  32. if(b_Delete)
  33. return ;
  34. float minx,miny,maxx,maxy;
  35. GetRect(&minx,&miny,&maxx,&maxy);//得到边界矩形
  36. if(!IsRectCross(minx,miny,maxx,maxy))//如果边界矩形不与屏幕窗口相交
  37. return;
  38. short ColorPen=m_ColorPen;
  39. if(m_DrawModel==2)
  40. ColorPen=BackColor;
  41. CFont cjcf;
  42. int hight,wide,cc1,cc2,cd,angg;
  43. unsigned char c1,c2;
  44. float x1,y1,angl;
  45. char bz[4];
  46. const char *ls1;
  47. if(m_DrawMode==0)
  48. pDC->SetROP2(R2_COPYPEN);
  49. else if(m_DrawMode==1)
  50. pDC->SetROP2(R2_NOT);
  51. pDC->SetBkMode(TRANSPARENT);
  52. hight=DLtoVL(m_TextHeight);
  53. angl=(float)(m_Angle1*pi/180);
  54. if(hight<3||hight>200)
  55. return;
  56. x1=m_StartX-m_TextHeight*(float)sin(angl);
  57. y1=m_StartY+m_TextHeight*(float)cos(angl);
  58. angg=(int)(m_Angle2*10);
  59. wide=DLtoVL(m_TextWide);
  60. DPtoVP(x1,y1,&cc1,&cc2);
  61. cjcf.CreateFont(hight,wide,angg,0,50,0,0,0,255,OUT_TT_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY,FIXED_PITCH,"cjc");
  62. CFont* cjcbakf=pDC->SelectObject(&cjcf);
  63. pDC->SetBkMode(TRANSPARENT);
  64. CGraphPara m_GraphPara;
  65.     CGraphPara *p_GraphPara;
  66. p_GraphPara=&m_GraphPara;
  67. pDC->SetTextColor(p_GraphPara->GetColor(ColorPen));
  68. ls1=(const char *)c_Text;
  69. cd=strlen(ls1);
  70. while(cd>0)
  71. {
  72. c1=*ls1;
  73. c2=*(ls1+1);
  74. if(c1>c2&&c2>127)
  75. {
  76. strncpy(bz,ls1,2);
  77. bz[2]=0;
  78. ls1=ls1+2;
  79. pDC->TextOut(cc1,cc2,bz);
  80. cd=cd-2;
  81.             x1=x1+(m_TextWide*2+m_OffWide)*(float)cos(angl);
  82.             y1=y1+(m_TextWide*2+m_OffWide)*(float)sin(angl);
  83. DPtoVP(x1,y1,&cc1,&cc2);
  84. }
  85. else
  86. {
  87. strncpy(bz,ls1,1);
  88. bz[1]=0;
  89. ls1++;
  90. pDC->TextOut(cc1,cc2,bz);
  91.             cd=cd-1;
  92.             x1=x1+(m_TextWide*2+m_OffWide/2)*(float)cos(angl);
  93.             y1=y1+(m_TextWide*2+m_OffWide/2)*(float)sin(angl);
  94. DPtoVP(x1,y1,&cc1,&cc2);
  95. }
  96. }
  97. pDC->SelectObject(cjcbakf);
  98. }
  99. void CText::GetRect(float *minX,float *minY,float* maxX,float* maxY )
  100. {
  101. float x[4],y[4];
  102. double ang=pi*m_Angle1/180;
  103. x[0]=m_StartX;
  104. y[0]=m_StartY;
  105. x[1]=m_StartX+(float)((m_TextWide+m_OffWide)*m_TextLong*cos(ang));
  106. y[1]=m_StartY+(float)((m_TextWide+m_OffWide)*m_TextLong*sin(ang));
  107. x[2]=x[1]-(float)(sin(ang)*m_TextHeight);
  108. y[2]=y[1]+(float)(cos(ang)*m_TextHeight);
  109. x[3]=m_StartX-(float)(sin(ang)*m_TextHeight);
  110. y[3]=m_StartY-(float)(cos(ang)*m_TextHeight);
  111. *minX=m_StartX;
  112. *minY=m_StartY;
  113. *maxX=m_StartX;
  114. *maxY=m_StartY;
  115. for(int i=1;i<4;i++)  //比较得到最小和最大坐标值
  116. {
  117. if(*minX>x[i]) *minX=x[i];
  118. if(*minY>y[i]) *minY=y[i];
  119. if(*maxX<x[i]) *maxX=x[i];
  120. if(*maxY<y[i]) *maxY=y[i];
  121. }
  122. }
  123. BOOL CText::IsPoint(float x,float y,float j1,float blc)
  124. {
  125. PointStruct XY[4];
  126. float x1,y1,x2,y2;
  127. if(b_Delete)
  128. return FALSE;
  129. GetRect(&x1,&y1,&x2,&y2);
  130. if(!(x>=x1&&x<=x2&&y>=y1&&y<=y2))
  131. return FALSE;
  132. float ang=(float)pi*m_Angle1/180;
  133. XY[0].x=m_StartX;
  134. XY[0].y=m_StartY;
  135. XY[1].x=m_StartX+(float)((m_TextWide+m_OffWide)*m_TextLong*cos(ang));
  136. XY[1].y=m_StartY+(float)((m_TextWide+m_OffWide)*m_TextLong*sin(ang));
  137. XY[2].x=XY[1].x-(float)(sin(ang)*m_TextHeight);
  138. XY[2].y=XY[1].y+(float)(cos(ang)*m_TextHeight);
  139. XY[3].x=m_StartX-(float)(sin(ang)*m_TextHeight);
  140. XY[3].y=m_StartY+(float)(cos(ang)*m_TextHeight);
  141. if(PointRgn(x,y,4,XY,blc))
  142. return TRUE;
  143. return FALSE;
  144. }
  145. void CText::Move(float x_Move,float y_Move)
  146. {
  147. m_StartX+=x_Move;
  148. m_StartY+=y_Move;
  149. }
  150. void CText::Rotate(float baseX,float baseY,float angle)
  151. {
  152. RotatePoint(baseX,baseY,angle,&this->m_StartX,&this->m_StartY);
  153. RotatePoint(baseX,baseY,angle,&this->m_EndX,&this->m_EndY);
  154. m_Angle1+=(float)(angle*180/pi);
  155. m_Angle2+=(float)(angle*180/pi);
  156. }
  157. void CText::Init(short ColorPen,short ColorBrush,float LineWide,short LineType,short Layer,
  158.  float StartX,float StartY,float Angle1,float Angle2,float TextHeight,
  159.  float TextWide,float OffWide,int TextLong,CString Text)
  160. {
  161. m_ColorPen=ColorPen;
  162. m_ColorBrush=ColorBrush;
  163. m_LineWide=LineWide;
  164. m_LineType=LineType;
  165. m_Layer=Layer;
  166. m_StartX=StartX;
  167. m_StartY=StartY;
  168. m_Angle1=Angle1;
  169. m_Angle2=Angle2;
  170. m_TextHeight=TextHeight;
  171. m_TextWide=TextWide;
  172. m_OffWide=OffWide;
  173. m_TextLong=TextLong;
  174. c_Text=Text;
  175. }
  176. CText::~CText()
  177. {
  178. }