Reader.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:38k
源码类别:

CAD

开发平台:

Visual C++

  1. // Reader.cpp: implementation of the CReader class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "FileSwitch.h"
  6. #include "Reader.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CStdioFile g_CensorialFile; //监察转换进度的文件
  16. int g_mode;
  17. CTypedPtrMap<CMapStringToPtr, CString, void*> g_afont;
  18. CReader::CReader()
  19. {
  20. g_mode=0;
  21. _CONV_OPEN;
  22. }
  23. CReader::~CReader()
  24. {
  25. _CONV_CLOSE;
  26. g_afont.RemoveAll();
  27. }
  28. BOOL CReader::calculate_findfontname(CString strfontfile2,CString strfontfile,CString &strfontname)
  29. {
  30. //为防止破坏系统的字体文件,将文件拷贝到临时目录.
  31. CString strPath;
  32. {
  33. TCHAR szFileName[MAX_PATH]; 
  34. ::GetModuleFileName(::GetModuleHandle(_T("FileSwitch.dll")),szFileName,MAX_PATH); 
  35. (*_tcsrchr(szFileName,'\'))=''; 
  36. strPath=szFileName;
  37. strPath+="\";
  38. strPath+=strfontfile2;
  39. }
  40. try
  41. {
  42. if(! ::CopyFile(strfontfile,strPath,FALSE) )
  43. {
  44. int i=::GetLastError();
  45. return FALSE;
  46. }
  47. strfontfile=strPath;
  48. }
  49. catch(...)
  50. {
  51. return FALSE;
  52. }
  53. CFile file;
  54. if(!file.Open(strfontfile,CFile::modeRead))
  55. {
  56. try{::DeleteFile(strfontfile);}catch(...){}
  57. return FALSE;
  58. }
  59. unsigned int inumTables;
  60. unsigned int isearchRange;
  61. unsigned int ientrySelector;
  62. unsigned int irangeShift;
  63. {
  64. __int16 data;
  65. //1.Fixed sfnt version 0x00010000 for version 1.0.
  66. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  67. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  68. //2.USHORT  numTables Number of tables.  USHORT 16-bit unsigned integer.
  69. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  70. inumTables=calculate_findint16(data);
  71. //3.USHORT  searchRange (Maximum power of 2 £ numTables) x 16.
  72. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  73. isearchRange=calculate_findint16(data);
  74. //4.USHORT  entrySelector Log2(maximum power of 2 £ numTables).
  75. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  76. ientrySelector=calculate_findint16(data);
  77. //5.USHORT  rangeShift NumTables x 16-searchRange.
  78. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  79. irangeShift=calculate_findint16(data);
  80. }
  81. unsigned long lcheckSum;
  82. unsigned long loffset;
  83. unsigned long llength;
  84. for(unsigned int index=0;index<inumTables;index++)
  85. {
  86. BOOL bName=FALSE;
  87. __int32 data;
  88. //ULONG tag 4 -byte identifier.  ULONG 32-bit unsigned integer.
  89. if(file.Read(&data,4)!=4){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  90. if(calculate_findname(data))
  91. {
  92. bName=TRUE;
  93. }
  94. //ULONG checkSum CheckSum for this table.
  95. if(file.Read(&data,4)!=4){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  96. if(bName)
  97. {
  98. lcheckSum=calculate_findint32(data);
  99. }
  100. //ULONG offset Offset from beginning of TrueType font file.
  101. if(file.Read(&data,4)!=4){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  102. if(bName)
  103. {
  104. loffset=calculate_findint32(data);
  105. }
  106. //ULONG length Length of this table.
  107. if(file.Read(&data,4)!=4){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  108. if(bName)
  109. {
  110. llength=calculate_findint32(data);
  111. break;
  112. }
  113. if((index+1)==inumTables)//最后一个数据.
  114. {
  115. {try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  116. }
  117. }
  118. try
  119. {
  120. file.Seek(loffset,CFile::begin);
  121. }
  122. catch(CFileException e)
  123. {
  124. {try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  125. }
  126. unsigned int istrStoOffset;
  127. CArray<unsigned int,unsigned int>istrLength;
  128. CArray<unsigned int,unsigned int>istrOffset;
  129. {
  130. __int16 data;
  131. unsigned int inumNameRecord;
  132. //USHORT Format selector (=0). 
  133. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  134. //USHORT Number of NameRecords that follow n.
  135. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  136. inumNameRecord=calculate_findint16(data);
  137. //USHORT Offset to start of string storage (from start of table).
  138. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  139. istrStoOffset=calculate_findint16(data);
  140. //n  NameRecords The NameRecords.
  141. for(unsigned index=0;index<inumNameRecord;index++)
  142. {
  143. BOOL bName=FALSE;
  144. //USHORT Platform ID.
  145. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  146. {
  147. unsigned int iPlatID=calculate_findint16(data);
  148. if(iPlatID!=3)//3.表示microsoft操作系统
  149. {
  150. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  151. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  152. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  153. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  154. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  155. continue;
  156. }
  157. }
  158. //USHORT Platform-specific encoding ID.
  159. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  160. //USHORT Language ID.
  161. BOOL bEng=TRUE;
  162. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  163. {
  164. unsigned int iLangID=calculate_findint16(data);
  165. //对于不是英语表示的信息,涉及到内码转换的问题,均不予处理.
  166. if((iLangID!=0x409)&&(iLangID!=0x809)&&(iLangID!=0xC09)&&(iLangID!=0x1009)&&(iLangID!=0x1409)&&(iLangID!=0x1809))//0x409表示English (6): American (0409; ENU) 1252 437
  167. {
  168. bEng=FALSE;
  169. }
  170. }
  171. //USHORT Name ID.
  172. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  173. if(calculate_findint16(data)==((unsigned int)1))
  174. {
  175. //1 Font Family name
  176. bName=TRUE;
  177. }
  178. //USHORT String length (in bytes).
  179. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  180. if(bName)
  181. {
  182. if(bEng)
  183. {
  184. istrLength.Add(calculate_findint16(data));
  185. }
  186. else
  187. {
  188. istrLength.InsertAt(0,calculate_findint16(data));
  189. }
  190. }
  191. //USHORT String offset from start of storage area (in bytes).
  192. if(file.Read(&data,2)!=2){try{file.Close();::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  193. if(bName)
  194. {
  195. if(bEng)
  196. {
  197. istrOffset.Add(calculate_findint16(data));
  198. }
  199. else
  200. {
  201. istrOffset.InsertAt(0,calculate_findint16(data));
  202. }
  203. }
  204. }
  205. }
  206. PBYTE pSourceData = NULL;
  207. {
  208. for(int index=0;index<istrLength.GetSize();index++)
  209. {
  210. try
  211. {
  212. file.Seek(loffset+istrStoOffset+istrOffset[index],CFile::begin);
  213. }
  214. catch(CFileException e)
  215. {
  216. {try{file.Close();::DeleteFile(strfontfile);}catch(...){};return FALSE;}
  217. }
  218. if(istrLength[index]%2)//如果不是偶数就退出
  219. {
  220. continue;
  221. }
  222. {
  223. pSourceData=(PBYTE)(LPVOID)GlobalAlloc(GPTR,istrLength[index]+2);
  224. pSourceData[istrLength[index]]=0;
  225. pSourceData[istrLength[index]+1]=0;
  226. __int8 data1;
  227. __int8 data2;
  228. CString strFontName;
  229. for(unsigned int index2=0;index2<istrLength[index];index2+=2)//index2和istrLength[index]是偶数
  230. {
  231. if(file.Read(&data1,1)!=1){try{file.Close();::DeleteFile(strfontfile);}catch(...){};GlobalFree(GlobalHandle(pSourceData));return FALSE;}
  232. if(file.Read(&data2,1)!=1){try{file.Close();::DeleteFile(strfontfile);}catch(...){};GlobalFree(GlobalHandle(pSourceData));return FALSE;}
  233. pSourceData[index2]=data2;
  234. pSourceData[index2+1]=data1;
  235. }
  236. strfontname=(LPCWSTR)pSourceData;
  237. for(int index3=0;index3<strfontname.GetLength();index3++)
  238. {
  239. strfontname.SetAt(index3,'');
  240. }
  241. strfontname=(LPCWSTR)pSourceData;
  242. if(strfontname.GetLength()>0)
  243. {
  244. GlobalFree(GlobalHandle(pSourceData));
  245. try{file.Close();::DeleteFile(strfontfile);}catch(...){}
  246. return TRUE;
  247. }
  248. GlobalFree(GlobalHandle(pSourceData));
  249. pSourceData=NULL;
  250. }
  251. }
  252. }
  253. try{file.Close();::DeleteFile(strfontfile);}catch(...){}
  254. return FALSE;
  255. }
  256. unsigned int CReader::calculate_findint16(__int16 data)
  257. {
  258. __int16 data2;
  259. __int8* byte=(__int8*)&data;
  260. __int8* byte2=(__int8*)&data2;
  261. (*byte2)=(*(byte+1));
  262. (*(byte2+1))=(*byte);
  263. return data2;
  264. }
  265. unsigned long CReader::calculate_findint32(__int32 data)
  266. {
  267. __int32 data2;
  268. __int8* byte=(__int8*)&data;
  269. __int8* byte2=(__int8*)&data2;
  270. (*byte2)=(*(byte+3));
  271. (*(byte2+1))=(*(byte+2));
  272. (*(byte2+2))=(*(byte+1));
  273. (*(byte2+3))=(*byte);
  274. return data2;
  275. }
  276. BOOL CReader::calculate_findname(__int32 data)
  277. {
  278. __int8* byte=(__int8*)&data;
  279. if((*byte)==0x6E)//'n'
  280. if((*(byte+1))==0x61)//'a'
  281. if((*(byte+2))==0x6D)//'m'
  282. if((*(byte+3))==0x65)//'e'
  283. return TRUE;
  284. return FALSE;
  285. }
  286. void CReader::CreateShape(AD_DB_HANDLE dwghandle,AD_OBJHANDLE shapefileobjhandle,char *str,int len, double* px, double* py, double dAng, int bound_high,
  287. double text_h, double text_w, KmBuffer* pBuffer)
  288. {
  289. BOOL bDown;
  290. int i,byte_num1,byte_num2,byte_num3,byte_num4,nPosStackDepth;
  291. int nVar1,nVar2,nVar3,nVar4,nVar5;
  292. double x0,y0,x1,y1,xStack[4],yStack[4];
  293. double endX,endY,cenX,cenY;
  294. double PointX1,PointY1,PointX2,PointY2,x,y,r,xCen,yCen;
  295. double dAmplify=1;
  296. BYTE uScale;
  297. x0=y0=0;
  298. x=*px;
  299. y=*py;
  300. nPosStackDepth=0;//位置栈的深度
  301. for(i=0; i<len; i++)
  302. {
  303. byte_num1 = (int)str[i];
  304. switch(byte_num1)
  305. {
  306. case 1://落笔
  307. {
  308. bDown=TRUE;
  309. while(bDown && (++i)<len)
  310. {
  311. byte_num2 = (int)str[i];
  312. byte_num3 = byte_num2&0xf;
  313. byte_num4 = byte_num2&0xf0;
  314. if(byte_num4==0)
  315. {//非矢量表达,该字符是控制符
  316. switch(byte_num2)
  317. {
  318. case 0:
  319. return;
  320. case 1:
  321. continue;
  322. case 2:
  323. {
  324. i--;
  325. bDown=FALSE;
  326. break;
  327. }
  328. case 3://控制文字矢量长度,除以下一字节
  329. {
  330. uScale=str[++i];
  331. //text_h/=x2;
  332. dAmplify/=uScale;
  333. break;
  334. }
  335. case 4://控制文字矢量长度,乘以下一字节
  336. {
  337. uScale=str[++i];
  338. //text_h*=x2;
  339. dAmplify*=uScale;
  340. break;
  341. }
  342. case 5://将当前位置压入位置栈
  343. {
  344. xStack[nPosStackDepth]=x0;
  345. yStack[nPosStackDepth]=y0;
  346. nPosStackDepth++;
  347. ASSERT(nPosStackDepth<=4);//位置栈的深度最多只能为4
  348. break;
  349. }
  350. case 6://从位置栈中弹出当前位置
  351. {
  352. nPosStackDepth--;
  353. ASSERT(nPosStackDepth>=0);
  354. x0=xStack[nPosStackDepth];
  355. y0=yStack[nPosStackDepth];
  356. TransRotate(x0*text_h*text_w/bound_high,
  357. y0*text_h/bound_high,dAng,
  358. PointX2,PointY2);
  359. *px=x+PointX2;
  360. *py=y+PointY2;
  361. break;
  362. }
  363. case 7://子形
  364. {
  365. uScale=str[++i];
  366. calculate_findshape(dwghandle,shapefileobjhandle,uScale,px,py,dAng,bound_high,text_h,text_w,pBuffer);
  367. TRACE("子形");
  368. break;
  369. }
  370. case 8://单个坐标点
  371. {
  372. x1 = ((int)str[++i])*dAmplify;
  373. y1 = ((int)str[++i])*dAmplify;
  374. TransRotate(x0*text_h*text_w/bound_high,
  375. y0*text_h/bound_high,dAng,
  376. PointX1,PointY1);
  377. TransRotate((x0+x1)*text_h*text_w/bound_high,
  378. (y0+y1)*text_h/bound_high,dAng,
  379. PointX2,PointY2);
  380. //if(DRAWPRESENT!=DRAWTOCALC)
  381. DrawLine(x+PointX1,y+PointY1,x+PointX2,y+PointY2,pBuffer);
  382. x0 += x1;
  383. y0 += y1;
  384. *px=x+PointX2;
  385. *py=y+PointY2;
  386. break;
  387. }
  388. case 9://连续坐标点
  389. for(;i<len;)
  390. {
  391. x1 = ((int)str[++i])*dAmplify;
  392. y1 = ((int)str[++i])*dAmplify;
  393. if(x1==0 && y1==0)
  394. break;
  395. TransRotate(x0*text_h*text_w/bound_high,
  396. y0*text_h/bound_high,dAng,
  397. PointX1,PointY1);
  398. TransRotate((x0+x1)*text_h*text_w/bound_high,
  399. (y0+y1)*text_h/bound_high,dAng,
  400. PointX2,PointY2);
  401. //if(DRAWPRESENT!=DRAWTOCALC)
  402. DrawLine(x+PointX1,y+PointY1,x+PointX2,y+PointY2,pBuffer);
  403. x0 += x1;
  404. y0 += y1;
  405. *px=x+PointX2;
  406. *py=y+PointY2;
  407. }
  408. break;
  409. case 10://Octant弧
  410. {
  411. x1 = ((int)str[++i])*dAmplify;
  412. nVar1 = (int)str[++i];
  413. OctantArc(x0,y0,x1,nVar1,endX,endY,cenX,cenY);
  414. r=sqrt((endX-cenX)*(endX-cenX)+(endY-cenY)*(endY-cenY));
  415. //if(DRAWPRESENT!=DRAWTOCALC)
  416. {
  417. DrawEllipse(x,y,cenX*text_h*text_w/bound_high,
  418. cenY*text_h/bound_high,
  419. r*text_h*text_w/bound_high,
  420. r*text_h/bound_high,
  421. dAng,
  422. x0*text_h*text_w/bound_high,
  423. y0*text_h/bound_high,
  424. endX*text_h*text_w/bound_high,
  425. endY*text_h/bound_high,
  426. nVar1>0 ? 1 : 0,
  427. pBuffer);
  428. }
  429. TransRotate(x0*text_h*text_w/bound_high,
  430. y0*text_h/bound_high,dAng,
  431. PointX1,PointY1);
  432. TransRotate(endX*text_h*text_w/bound_high,
  433. endY*text_h/bound_high,dAng,
  434. PointX2,PointY2);
  435. x0 = endX;
  436. y0 = endY;
  437. *px=x+PointX2;
  438. *py=y+PointY2;
  439. }
  440. break;
  441. case 11://Fractional弧
  442. {
  443. nVar1 = (int)str[++i];
  444. nVar2 = (int)str[++i];
  445. nVar3 = (int)str[++i];
  446. nVar4 = (int)str[++i];
  447. nVar5 = (int)str[++i];
  448. FractionalArc(x0,y0,nVar1,nVar2,nVar3,nVar4,nVar5,dAmplify,endX,endY,cenX,cenY);
  449. r=sqrt((endX-cenX)*(endX-cenX)+(endY-cenY)*(endY-cenY));
  450. //if(DRAWPRESENT!=DRAWTOCALC)
  451. {
  452. DrawEllipse(x,y,cenX*text_h*text_w/bound_high,
  453. cenY*text_h/bound_high,
  454. r*text_h*text_w/bound_high,
  455. r*text_h/bound_high,
  456. dAng,
  457. x0*text_h*text_w/bound_high,
  458. y0*text_h/bound_high,
  459. endX*text_h*text_w/bound_high,
  460. endY*text_h/bound_high,
  461. nVar5>0 ? 1 : 0,
  462. pBuffer);
  463. }
  464. TransRotate(x0*text_h*text_w/bound_high,
  465. y0*text_h/bound_high,dAng,
  466. PointX1,PointY1);
  467. TransRotate(endX*text_h*text_w/bound_high,
  468. endY*text_h/bound_high,dAng,
  469. PointX2,PointY2);
  470. TransRotate(cenX*text_h*text_w/bound_high,
  471. cenY*text_h/bound_high,dAng,
  472. xCen,yCen);
  473. x0 = endX;
  474. y0 = endY;
  475. *px=x+PointX2;
  476. *py=y+PointY2;
  477. }
  478. break;
  479. case 12://Bulge弧
  480. {
  481. x1 = ((int)str[++i])*dAmplify;
  482. y1 = ((int)str[++i])*dAmplify;
  483. nVar1 = (int)str[++i];
  484. BulgeArc(x0,y0,x0+x1,y0+y1,nVar1,r,xCen,yCen);
  485. TransRotate(x0*text_h*text_w/bound_high,
  486. y0*text_h/bound_high,dAng,
  487. PointX1,PointY1);
  488. TransRotate((x0+x1)*text_h*text_w/bound_high,
  489. (y0+y1)*text_h/bound_high,dAng,
  490. PointX2,PointY2);
  491. if(fabs(r)<PRECISION)//直接画线
  492. {
  493. DrawLine(x+PointX1,y+PointY1,x+PointX2,y+PointY2,pBuffer);
  494. }
  495. else//画椭圆
  496. {
  497. DrawEllipse(x,y,xCen*text_h*text_w/bound_high,
  498. yCen*text_h/bound_high,
  499. r*text_h*text_w/bound_high,
  500. r*text_h/bound_high,
  501. dAng,
  502. x0*text_h*text_w/bound_high,
  503. y0*text_h/bound_high,
  504. (x0+x1)*text_h*text_w/bound_high,
  505. (y0+y1)*text_h/bound_high,
  506. nVar1>0 ? 1 : 0 ,
  507. pBuffer);
  508. }
  509. x0 += x1;
  510. y0 += y1;
  511. *px=x+PointX2;
  512. *py=y+PointY2;
  513. }
  514. break;
  515. case 13://Bulge弧
  516. for(;i<len;)
  517. {
  518. if((int)str[i+1]==0 && (int)str[i+2]==0)
  519. break;
  520. x1 = ((int)str[++i])*dAmplify;
  521. y1 = ((int)str[++i])*dAmplify;
  522. nVar1 = (int)str[++i];
  523. BulgeArc(x0,y0,x0+x1,y0+y1,nVar1,r,xCen,yCen);
  524. TransRotate(x0*text_h*text_w/bound_high,
  525. y0*text_h/bound_high,dAng,
  526. PointX1,PointY1);
  527. TransRotate((x0+x1)*text_h*text_w/bound_high,
  528. (y0+y1)*text_h/bound_high,dAng,
  529. PointX2,PointY2);
  530. if(fabs(r)<PRECISION)//直接画线
  531. {
  532. DrawLine(x+PointX1,y+PointY1,x+PointX2,y+PointY2,pBuffer);
  533. }
  534. else//画椭圆
  535. {
  536. DrawEllipse(x,y,xCen*text_h*text_w/bound_high,
  537. yCen*text_h/bound_high,
  538. r*text_h*text_w/bound_high,
  539. r*text_h/bound_high,
  540. dAng,
  541. x0*text_h*text_w/bound_high,
  542. y0*text_h/bound_high,
  543. (x0+x1)*text_h*text_w/bound_high,
  544. (y0+y1)*text_h/bound_high,
  545. nVar1>0 ? 1 : 0 ,
  546. pBuffer);
  547. }
  548. x0 += x1;
  549. y0 += y1;
  550. *px=x+PointX2;
  551. *py=y+PointY2;
  552. }
  553. break;
  554. case 14://暂不处理铅垂排列的字
  555. {
  556. //后移一位
  557. byte_num2 = (int)str[++i];
  558. if(byte_num2==8) i+=2;//如果是点坐标,再后移两位
  559. else if(byte_num2&0xf0) i++;//如果是及坐标仅后移一位
  560. break;
  561. }
  562. }//switch(byte_num2)
  563. }//if(byte_num4==0)
  564. else
  565. {
  566. //矢量表达的点
  567. TranXY(byte_num3,byte_num4/16*dAmplify,x1,y1);
  568. TransRotate(x0*text_h*text_w/bound_high,
  569. y0*text_h/bound_high,dAng,
  570. PointX1,PointY1);
  571. TransRotate((x0+x1)*text_h*text_w/bound_high,
  572. (y0+y1)*text_h/bound_high,dAng,
  573. PointX2,PointY2);
  574. //if(DRAWPRESENT!=DRAWTOCALC)
  575. DrawLine(x+PointX1,y+PointY1,x+PointX2,y+PointY2,pBuffer);
  576. x0 += x1;
  577. y0 += y1;
  578. *px=x+PointX2;
  579. *py=y+PointY2;
  580. }
  581. }//while(bDown && (++i)<len)
  582. break;
  583. }//case 1
  584. case 2://抬笔
  585. {
  586. bDown=FALSE;
  587. while(!bDown && (++i)<len )
  588. {
  589. byte_num2 = (int)str[i];
  590. switch(byte_num2)
  591. {
  592. case 0:
  593. return;
  594. case 1:
  595. {
  596. i--;
  597. bDown=TRUE;
  598. break;
  599. }
  600. case 2:
  601. {
  602. continue;
  603. }
  604. case 3://控制文字矢量长度,除以下一字节
  605. {
  606. uScale=str[++i];
  607. //text_h/=x2;
  608. dAmplify/=uScale;
  609. break;
  610. }
  611. case 4://控制文字矢量长度,乘以下一字节
  612. {
  613. uScale=str[++i];
  614. //text_h*=x2;
  615. dAmplify*=uScale;
  616. break;
  617. }
  618. case 5://将当前位置压入位置栈
  619. {
  620. xStack[nPosStackDepth]=x0;
  621. yStack[nPosStackDepth]=y0;
  622. nPosStackDepth++;
  623. ASSERT(nPosStackDepth<=4);//位置栈的深度最多只能为4
  624. break;
  625. }
  626. case 6://从位置栈中弹出当前位置
  627. {
  628. nPosStackDepth--;
  629. ASSERT(nPosStackDepth>=0);
  630. x0=xStack[nPosStackDepth];
  631. y0=yStack[nPosStackDepth];
  632. TransRotate(x0*text_h*text_w/bound_high,
  633. y0*text_h/bound_high,dAng,
  634. PointX2,PointY2);
  635. *px=x+PointX2;
  636. *py=y+PointY2;
  637. break;
  638. }
  639. case 7://子形
  640. {
  641. uScale=str[++i];
  642. calculate_findshape(dwghandle,shapefileobjhandle,uScale,px,py,dAng,bound_high,text_h,text_w,pBuffer);
  643. TRACE("子形");
  644. break;
  645. }
  646. case 8://位置移动
  647. {
  648. x1 = ((int)str[++i])*dAmplify;
  649. y1 = ((int)str[++i])*dAmplify;
  650. TransRotate((x0+x1)*text_h*text_w/bound_high,
  651. (y0+y1)*text_h/bound_high,dAng,
  652. PointX2,PointY2);
  653. x0 += x1;
  654. y0 += y1;
  655. *px=x+PointX2;
  656. *py=y+PointY2;
  657. break;
  658. }
  659. case 9://连续坐标点
  660. for(;i<len;)
  661. {
  662. x1 = ((int)str[++i])*dAmplify;
  663. y1 = ((int)str[++i])*dAmplify;
  664. if(x1==0 && y1==0)
  665. break;
  666. TransRotate(x0*text_h*text_w/bound_high,
  667. y0*text_h/bound_high,dAng,
  668. PointX1,PointY1);
  669. TransRotate((x0+x1)*text_h*text_w/bound_high,
  670. (y0+y1)*text_h/bound_high,dAng,
  671. PointX2,PointY2);
  672. x0 += x1;
  673. y0 += y1;
  674. *px=x+PointX2;
  675. *py=y+PointY2;
  676. }
  677. break;
  678. case 10://Octant弧
  679. {
  680. x1 = ((int)str[++i])*dAmplify;
  681. nVar1 = (int)str[++i];
  682. OctantArc(x0,y0,x1,nVar1,endX,endY,cenX,cenY);
  683. r=sqrt((endX-cenX)*(endX-cenX)+(endY-cenY)*(endY-cenY));
  684. TransRotate(x0*text_h*text_w/bound_high,
  685. y0*text_h/bound_high,dAng,
  686. PointX1,PointY1);
  687. TransRotate(endX*text_h*text_w/bound_high,
  688. endY*text_h/bound_high,dAng,
  689. PointX2,PointY2);
  690. x0 = endX;
  691. y0 = endY;
  692. *px=x+PointX2;
  693. *py=y+PointY2;
  694. }
  695. break;
  696. case 11://Fractional弧
  697. {
  698. nVar1 = (int)str[++i];
  699. nVar2 = (int)str[++i];
  700. nVar3 = (int)str[++i];
  701. nVar4 = (int)str[++i];
  702. nVar5 = (int)str[++i];
  703. FractionalArc(x0,y0,nVar1,nVar2,nVar3,nVar4,nVar5,dAmplify,endX,endY,cenX,cenY);
  704. r=sqrt((endX-cenX)*(endX-cenX)+(endY-cenY)*(endY-cenY));
  705. TransRotate(x0*text_h*text_w/bound_high,
  706. y0*text_h/bound_high,dAng,
  707. PointX1,PointY1);
  708. TransRotate(endX*text_h*text_w/bound_high,
  709. endY*text_h/bound_high,dAng,
  710. PointX2,PointY2);
  711. TransRotate(cenX*text_h*text_w/bound_high,
  712. cenY*text_h/bound_high,dAng,
  713. xCen,yCen);
  714. x0 = endX;
  715. y0 = endY;
  716. *px=x+PointX2;
  717. *py=y+PointY2;
  718. }
  719. break;
  720. case 12://Bulge弧
  721. {
  722. x1 = ((int)str[++i])*dAmplify;
  723. y1 = ((int)str[++i])*dAmplify;
  724. nVar1 = (int)str[++i];
  725. BulgeArc(x0,y0,x0+x1,y0+y1,nVar1,r,xCen,yCen);
  726. TransRotate(x0*text_h*text_w/bound_high,
  727. y0*text_h/bound_high,dAng,
  728. PointX1,PointY1);
  729. TransRotate((x0+x1)*text_h*text_w/bound_high,
  730. (y0+y1)*text_h/bound_high,dAng,
  731. PointX2,PointY2);
  732. x0 += x1;
  733. y0 += y1;
  734. *px=x+PointX2;
  735. *py=y+PointY2;
  736. }
  737. break;
  738. case 13://Bulge弧
  739. for(;i<len;)
  740. {
  741. if((int)str[i+1]==0 && (int)str[i+2]==0)
  742. break;
  743. x1 = ((int)str[++i])*dAmplify;
  744. y1 = ((int)str[++i])*dAmplify;
  745. nVar1 = (int)str[++i];
  746. BulgeArc(x0,y0,x0+x1,y0+y1,nVar1,r,xCen,yCen);
  747. TransRotate(x0*text_h*text_w/bound_high,
  748. y0*text_h/bound_high,dAng,
  749. PointX1,PointY1);
  750. TransRotate((x0+x1)*text_h*text_w/bound_high,
  751. (y0+y1)*text_h/bound_high,dAng,
  752. PointX2,PointY2);
  753. x0 += x1;
  754. y0 += y1;
  755. *px=x+PointX2;
  756. *py=y+PointY2;
  757. }
  758. break;
  759. case 14://暂不处理铅垂排列的字
  760. {
  761. //后移一位
  762. byte_num2 = (int)str[++i];
  763. if(byte_num2==8) i+=2;//如果是点坐标,再后移两位
  764. break;
  765. }
  766. default://极坐标的位置移动 
  767. {
  768. byte_num2 = (int)str[i];
  769. byte_num3 = byte_num2&0xf;
  770. byte_num4 = byte_num2&0xf0;
  771. if(byte_num4)
  772. {
  773. //极坐标转换为坐标点
  774. TranXY(byte_num3,byte_num4/16*dAmplify,x1,y1);
  775. TransRotate((x0+x1)*text_h*text_w/bound_high,
  776. (y0+y1)*text_h/bound_high,dAng,
  777. PointX2,PointY2);
  778. x0 += x1;
  779. y0 += y1;
  780. *px=x+PointX2;
  781. *py=y+PointY2;
  782. }
  783. else
  784. {
  785. ASSERT(FALSE);
  786. }
  787. break;
  788. }
  789. }//switch(byte_num2)
  790. }//while(!bDown)
  791. break;
  792. }//case 2
  793. case 3://控制文字矢量长度,除以下一字节
  794. {
  795. uScale=str[++i];
  796. //text_h/=x2;
  797. dAmplify/=uScale;
  798. break;
  799. }
  800. case 4://控制文字矢量长度,乘以下一字节
  801. {
  802. uScale=str[++i];
  803. //text_h*=x2;
  804. dAmplify*=uScale;
  805. break;
  806. }
  807. case 5://将当前位置压入位置栈
  808. {
  809. xStack[nPosStackDepth]=x0;
  810. yStack[nPosStackDepth]=y0;
  811. nPosStackDepth++;
  812. ASSERT(nPosStackDepth<=4);//位置栈的深度最多只能为4
  813. break;
  814. }
  815. case 6://从位置栈中弹出当前位置
  816. {
  817. nPosStackDepth--;
  818. ASSERT(nPosStackDepth>=0);
  819. x0=xStack[nPosStackDepth];
  820. y0=yStack[nPosStackDepth];
  821. TransRotate(x0*text_h*text_w/bound_high,
  822. y0*text_h/bound_high,dAng,
  823. PointX2,PointY2);
  824. *px=x+PointX2;
  825. *py=y+PointY2;
  826. break;
  827. }
  828. case 7://子形
  829. {
  830. uScale=str[++i];
  831. calculate_findshape(dwghandle,shapefileobjhandle,uScale,px,py,dAng,bound_high,text_h,text_w,pBuffer);
  832. TRACE("子形");
  833. break;
  834. }
  835. }//switch(byte_num1)
  836. }//for
  837. }
  838. int CReader::calculate_findstringlength(CString& strEnter)
  839. {
  840. int imax=0;
  841. int icurmax=0;
  842. for(int i=0;i<strEnter.GetLength();i++)
  843. {
  844. if(strEnter[i]=='\n')
  845. {
  846. if(icurmax>imax)
  847. {
  848. imax=icurmax;
  849. }
  850. icurmax=0;
  851. }
  852. else
  853. {
  854. if(strEnter[i]=='\')
  855. {
  856. if(i+1<strEnter.GetLength())
  857. {
  858. if(strEnter[i+1]=='\')
  859. {
  860. icurmax++;
  861. i++;
  862. continue;
  863. }
  864. else if(strEnter[i+1]=='U')
  865. {
  866. icurmax+=2;
  867. i+=6;
  868. continue;
  869. }
  870. else if(strEnter[i+1]=='u')
  871. {
  872. icurmax+=2;
  873. i+=6;
  874. continue;
  875. }
  876. else if(strEnter[i+1]=='M')
  877. {
  878. icurmax+=2;
  879. i+=7;
  880. continue;
  881. }
  882. else if(strEnter[i+1]=='m')
  883. {
  884. icurmax+=2;
  885. i+=7;
  886. continue;
  887. }
  888. }
  889. {
  890. for(int j=i+1;j<strEnter.GetLength();j++)
  891. {
  892. if(strEnter[j]==';')
  893. {
  894. i=j;
  895. break;
  896. }
  897. }
  898. }
  899. }
  900. else
  901. {
  902. icurmax++;
  903. }
  904. }
  905. }
  906. if(icurmax>imax)
  907. {
  908. imax=icurmax;
  909. }
  910. return imax;
  911. }
  912. void CReader::BulgeArc(double x0, double y0, double x1, double y1, 
  913.   int hArc, double& r ,double& xCen, double& yCen)
  914. {
  915. double x,y,w;
  916. double dx=x1-x0;
  917. double dy=y1-y0;
  918. double dis=sqrt(dx*dx+dy*dy);
  919. if(fabs(dis)<PRECISION)
  920. {
  921. TRACE("在拱弧计算中两点距离为0n");
  922. r=0;
  923. return;
  924. }
  925. dx/=dis;
  926. dy/=dis;
  927. //计算两线中点
  928. x=x0+dx*dis/2;
  929. y=y0+dy*dis/2;
  930. //计算半径
  931. w=fabs(hArc)*dis/254;
  932. if(fabs(w)<PRECISION)
  933. {
  934. //是直线
  935. TRACE("拱弧拱高为0n");
  936. r=0;
  937. return;
  938. }
  939. //勾股弦定理计算
  940. dis/=2;
  941. r=(dis*dis)/(2*w)+w/2;
  942. if(fabs(r)<PRECISION)
  943. return;
  944. //求圆心
  945. if(hArc>0)
  946. {
  947. xCen=x-dy*(r-w);
  948. yCen=y+dx*(r-w);
  949. }
  950. else
  951. {
  952. xCen=x+dy*(r-w);
  953. yCen=y-dx*(r-w);
  954. }
  955. /* //求起始角和终止角
  956. if(w>0)//逆弧
  957. {
  958. ASSERT(fabs((x0-cenX)/r)<=1);
  959. dBAng=acos((x0-cenX)/r);
  960. if((y0-cenY)<0)
  961. dBAng=2*PI-dBAng;
  962. ASSERT(fabs((x1-cenX)/r)<=1);
  963. dEAng=acos((x1-cenX)/r);
  964. if((y1-cenY)<0)
  965. dEAng=2*PI-dEAng;
  966. }
  967. else//顺弧
  968. {
  969. ASSERT(fabs((x1-cenX)/r)<=1);
  970. dBAng=acos((x1-cenX)/r);
  971. if((y1-cenY)<0)
  972. dBAng=2*PI-dBAng;
  973. ASSERT(fabs((x0-cenX)/r)<=1);
  974. dEAng=acos((x0-cenX)/r);
  975. if((y0-cenY)<0)
  976. dEAng=360-dEAng;
  977. }*/
  978. }
  979. void CReader::OctantArc(double begX,double begY,double Rad,int OSC,
  980.   double& endX,double& endY,double& cenX,double& cenY)
  981. {
  982. int osc;
  983. int i;
  984. int begin_ang,end_ang;
  985. double tempX,tempY;
  986. if(OSC<0)
  987. osc = 256 + OSC;
  988. else
  989. osc = OSC;
  990. i = osc>>4;
  991. i = i&15;
  992. if(i>7) 
  993. i = i - 8;
  994. switch(i)
  995. {//根据第二位判断开始角度.角度知道后可求出坐标系中心(圆心)
  996. case 0:
  997. begin_ang = 0;
  998. cenX = begX - Rad;
  999. cenY = begY;
  1000. break;
  1001. case 1:
  1002. begin_ang = 45;
  1003. cenX = begX - Rad;
  1004. cenY = begY - Rad;
  1005. break;
  1006. case 2:
  1007. begin_ang = 90;
  1008. cenX = begX;
  1009. cenY = begY - Rad;
  1010. break;
  1011. case 3:
  1012. begin_ang = 135;
  1013. cenX = begX + Rad;
  1014. cenY = begY - Rad;
  1015. break;
  1016. case 4:
  1017. begin_ang = 180;
  1018. cenX = begX + Rad;
  1019. cenY = begY;
  1020. break;
  1021. case 5:
  1022. begin_ang = 225;
  1023. cenX = begX + Rad;
  1024. cenY = begY + Rad;
  1025. break;
  1026. case 6:
  1027. begin_ang = 270;
  1028. cenX = begX;
  1029. cenY = begY + Rad;
  1030. break;
  1031. case 7:
  1032. begin_ang = 315;
  1033. cenX = begX - Rad;
  1034. cenY = begY + Rad;
  1035. break;
  1036. }
  1037. i = osc&15;
  1038. if(i==0)
  1039. end_ang = 360;
  1040. else
  1041. end_ang = i*45;
  1042. if(OSC<0)//顺时针
  1043. TransRotate((double)(begX - cenX),(double)(begY - cenY),
  1044. (float)(-end_ang*PI/180),tempX,tempY);
  1045. else//逆时针
  1046. TransRotate((double)(begX - cenX),(double)(begY - cenY),
  1047. (float)(end_ang*PI/180),tempX,tempY);
  1048. endX = cenX + tempX;//+0.499); 
  1049. endY = cenY + tempY;//+0.49999);
  1050. }
  1051. void CReader::FractionalArc(double begX,double begY, int s_off,int e_off,
  1052. int h_rad,int l_rad,int OSC,double dAmplify,
  1053.   double& endX,double& endY,double& cenX,double& cenY)
  1054. {
  1055. double Rad;
  1056. int osc;
  1057. int i;
  1058. int begin_ang,end_ang;
  1059. double tempX,tempY;
  1060. Rad = (h_rad*255 + l_rad)*dAmplify;
  1061. if(OSC<0) osc = 256 + OSC;
  1062. else osc = OSC;
  1063. i = osc>>4;
  1064. i = i&15;
  1065. if(i>7) i = i - 8;
  1066. switch(i)
  1067. {//根据第二位判断开始角度.角度知道后可求出坐标系中心(圆心)
  1068. case 0:
  1069. begin_ang = (45*s_off/256)+0;
  1070. cenX = begX - Rad;
  1071. cenY = begY;
  1072. break;
  1073. case 1:
  1074. begin_ang = (45*s_off/256)+45;
  1075. cenX = begX - Rad;
  1076. cenY = begY - Rad;
  1077. break;
  1078. case 2:
  1079. begin_ang = (45*s_off/256)+90;
  1080. cenX = begX;
  1081. cenY = begY - Rad;
  1082. break;
  1083. case 3:
  1084. begin_ang = (45*s_off/256)+135;
  1085. cenX = begX + Rad;
  1086. cenY = begY - Rad;
  1087. break;
  1088. case 4:
  1089. begin_ang = (45*s_off/256)+180;
  1090. cenX = begX + Rad;
  1091. cenY = begY;
  1092. break;
  1093. case 5:
  1094. begin_ang = (45*s_off/256)+225;
  1095. cenX = begX + Rad;
  1096. cenY = begY + Rad;
  1097. break;
  1098. case 6:
  1099. begin_ang = (45*s_off/256)+270;
  1100. cenX = begX;
  1101. cenY = begY + Rad;
  1102. break;
  1103. case 7:
  1104. begin_ang = (45*s_off/256)+315;
  1105. cenX = begX - Rad;
  1106. cenY = begY + Rad;
  1107. break;
  1108. }
  1109. i = osc&15;
  1110. switch(i)
  1111. {//根据第二位判断开始角度.角度知道后可求出坐标系中心(圆心)
  1112. case 0:
  1113. end_ang = (45*e_off/256)+0;
  1114. cenX = begX - Rad;
  1115. cenY = begY;
  1116. break;
  1117. case 1:
  1118. end_ang = (45*e_off/256)+45;
  1119. cenX = begX - Rad;
  1120. cenY = begY - Rad;
  1121. break;
  1122. case 2:
  1123. end_ang = (45*e_off/256)+90;
  1124. cenX = begX;
  1125. cenY = begY - Rad;
  1126. break;
  1127. case 3:
  1128. end_ang = (45*e_off/256)+135;
  1129. cenX = begX + Rad;
  1130. cenY = begY - Rad;
  1131. break;
  1132. case 4:
  1133. end_ang = (45*e_off/256)+180;
  1134. cenX = begX + Rad;
  1135. cenY = begY;
  1136. break;
  1137. case 5:
  1138. end_ang = (45*e_off/256)+225;
  1139. cenX = begX + Rad;
  1140. cenY = begY + Rad;
  1141. break;
  1142. case 6:
  1143. end_ang = (45*e_off/256)+270;
  1144. cenX = begX;
  1145. cenY = begY + Rad;
  1146. break;
  1147. case 7:
  1148. end_ang = (45*e_off/256)+315;
  1149. cenX = begX - Rad;
  1150. cenY = begY + Rad;
  1151. break;
  1152. }
  1153. end_ang = end_ang - begin_ang;
  1154. if(OSC<0)//顺时针
  1155. TransRotate((double)(begX - cenX),(double)(begY - cenY),
  1156. (double)(-end_ang*PI/180),tempX,tempY);
  1157. else//逆时针
  1158. TransRotate((double)(begX - cenX),(double)(begY - cenY),
  1159. (double)(end_ang*PI/180),tempX,tempY);
  1160. endX = cenX + tempX;//+0.499);
  1161. endY = cenY + tempY;//+0.49999);
  1162. }
  1163. void CReader::TranXY(int direct,double len,double&  x1,double&  y1)
  1164. {
  1165. switch(direct)
  1166. {
  1167. case 0:
  1168. x1 = len; y1 = 0;
  1169. break;
  1170. case 1:
  1171. x1 = len; y1 = len/2;
  1172. break;
  1173. case 2:
  1174. x1 = len; y1 = len;
  1175. break;
  1176. case 3:
  1177. x1 = len/2; y1 = len;
  1178. break;
  1179. case 4:
  1180. x1 = 0; y1 = len;
  1181. break;
  1182. case 5:
  1183. x1 = -len/2; y1 = len;
  1184. break;
  1185. case 6:
  1186. x1 = -len; y1 = len;
  1187. break;
  1188. case 7:
  1189. x1 = -len; y1 = len/2;
  1190. break;
  1191. case 8:
  1192. x1 = -len; y1 = 0;
  1193. break;
  1194. case 9:
  1195. x1 = -len; y1 = -len/2;
  1196. break;
  1197. case 10:
  1198. x1 = -len; y1 = -len;
  1199. break;
  1200. case 11:
  1201. x1 = -len/2; y1 = -len;
  1202. break;
  1203. case 12:
  1204. x1 = 0; y1 = -len;
  1205. break;
  1206. case 13:
  1207. x1 = len/2; y1 = -len;
  1208. break;
  1209. case 14:
  1210. x1 = len; y1 = -len;
  1211. break;
  1212. case 15:
  1213. x1 = len; y1 = -len/2;
  1214. break;
  1215. }
  1216. }
  1217. void CReader::DrawLine(double x1,double y1,double x2, double y2, KmBuffer* pBuffer)
  1218. {
  1219. if(pBuffer!=NULL)
  1220. {
  1221. S_LINE_BUFFER* pLineBuf= new S_LINE_BUFFER;
  1222. pLineBuf->Color=RGB(0,0,0);
  1223. pLineBuf->LineScale=1;
  1224. pLineBuf->LineType=SOLID_LINE;
  1225. pLineBuf->Mode=DRAWPRESENT;
  1226. pLineBuf->P1.x=x1;
  1227. pLineBuf->P1.y=y1;
  1228. pLineBuf->P2.x=x2;
  1229. pLineBuf->P2.y=y2;
  1230. pLineBuf->Width=1;
  1231. pBuffer->AddLine(pLineBuf);
  1232. }
  1233. }
  1234. void CReader::DrawArc(double x1, double y1, double x2, double y2,
  1235.  double xCen, double yCen, int nWise, KmBuffer* pBuffer)
  1236. {
  1237. double r,dBAng,dEAng,dDivAng;
  1238. r=sqrt((x1-xCen)*(x1-xCen)+(y1-yCen)*(y1-yCen));
  1239. if(r<PRECISION) r=PRECISION;
  1240. if(nWise>0)//逆弧
  1241. {
  1242. ASSERT(fabs((x1-xCen)/r)<=1);
  1243. dBAng=acos((x1-xCen)/r);
  1244. if((y1-yCen)<0)
  1245. dBAng=2*PI-dBAng;
  1246. ASSERT(fabs((x2-xCen)/r)<=1);
  1247. dEAng=acos((x2-xCen)/r);
  1248. if((y2-yCen)<0)
  1249. dEAng=2*PI-dEAng;
  1250. }
  1251. else
  1252. {
  1253. ASSERT(fabs((x1-xCen)/r)<=1);
  1254. dEAng=acos((x1-xCen)/r);
  1255. if((y1-yCen)<0)
  1256. dEAng=2*PI-dEAng;
  1257. ASSERT(fabs((x2-xCen)/r)<=1);
  1258. dBAng=acos((x2-xCen)/r);
  1259. if((y2-yCen)<0)
  1260. dBAng=2*PI-dBAng;
  1261. }
  1262. if(r < PRECISION_SHOW)
  1263. {
  1264. r = PRECISION_SHOW;
  1265. }
  1266. dDivAng = sqrt(0.50 / r);
  1267. if (dDivAng > 1)
  1268. dDivAng = 1;
  1269. dDivAng = fabs(2 * asin(dDivAng));
  1270. if(fabs(dDivAng) < PRECISION_SHOW)
  1271. {
  1272. dDivAng = PRECISION_SHOW;
  1273. }
  1274. if(dDivAng>PI/16)
  1275. dDivAng=PI/16;
  1276. //将圆分段,用直线绘制
  1277. if(dEAng<dBAng)
  1278. dEAng+=2*PI;
  1279. //if(m_pShow->show_scale>1)
  1280. // a/=m_pShow->show_scale;
  1281. //画线
  1282. if(pBuffer)
  1283. {
  1284. x1=xCen+r*cos(dBAng);
  1285. y1=yCen+r*sin(dBAng);
  1286. while(dBAng<dEAng-PRECISION_SHOW_ANG)
  1287. {
  1288. dBAng+=dDivAng;
  1289. if(dBAng>dEAng-PRECISION_SHOW_ANG)
  1290. dBAng=dEAng;
  1291. x2=xCen+r*cos(dBAng);
  1292. y2=yCen+r*sin(dBAng);
  1293. {
  1294. S_LINE_BUFFER* pLineBuf= new S_LINE_BUFFER;
  1295. pLineBuf->Color=RGB(0,0,0);
  1296. pLineBuf->LineScale=1;
  1297. pLineBuf->LineType=SOLID_LINE;
  1298. pLineBuf->Mode=DRAWPRESENT;
  1299. pLineBuf->P1.x=x1;
  1300. pLineBuf->P1.y=y1;
  1301. pLineBuf->P2.x=x2;
  1302. pLineBuf->P2.y=y2;
  1303. pLineBuf->Width=1;
  1304. pBuffer->AddLine(pLineBuf);
  1305. x1=x2;
  1306. y1=y2;
  1307. }
  1308. };
  1309. }
  1310. }
  1311. //画椭圆
  1312. //dBaseX,dBaseY为基点坐标
  1313. //xCen,yCen为圆心坐标
  1314. //xr,yr为两方向轴长
  1315. //dAng为椭圆x轴与坐标x轴的夹角
  1316. //bx,by为椭圆弧的起点
  1317. //ex,ey为椭圆弧的终点
  1318. //bCounterClockWise为椭圆弧的旋转方向是否为逆时针方向
  1319. //pBuffer为KmBuffer缓存
  1320. void CReader::DrawEllipse(double dBaseX, double dBaseY, double xCen, double yCen,
  1321.  double xr, double yr, double dAng, double bx, double by,
  1322.  double ex, double ey, BOOL bCounterClockWise, KmBuffer* pBuffer)
  1323. {
  1324. //若近似为圆则画圆弧
  1325. if(fabs(xr-yr)<PRECISION)
  1326. {
  1327. TransRotate(xCen,yCen,dAng,xCen,yCen);
  1328. TransRotate(bx,by,dAng,bx,by);
  1329. TransRotate(ex,ey,dAng,ex,ey);
  1330. DrawArc(dBaseX+bx,dBaseY+by,dBaseX+ex,dBaseY+ey,
  1331. dBaseX+xCen,dBaseY+yCen, bCounterClockWise ? 1: -1,pBuffer);
  1332. return;
  1333. }
  1334. //画椭圆弧
  1335. //1. 先计算起始角和终止角
  1336. double dBAng,dEAng,dDivAng,x1,y1,x2,y2,xend,yend;
  1337. dBAng=atan2((by-yCen)/yr,(bx-xCen)/xr);
  1338. dEAng=atan2((ey-yCen)/yr,(ex-xCen)/xr);
  1339. if(dBAng<0)
  1340. dBAng+=2*PI;
  1341. if(dEAng<0)
  1342. dEAng+=2*PI; 
  1343. //2. 再计算弧度步长
  1344. if(xr<0 || yr<0)
  1345. return;
  1346. dDivAng = sqrt(1 / (xr+yr));
  1347. if (dDivAng > 1)
  1348. dDivAng = 1;
  1349. dDivAng = fabs(2 * asin(dDivAng));
  1350. if(fabs(dDivAng) < PRECISION_SHOW)
  1351. {
  1352. dDivAng = PRECISION_SHOW;
  1353. }
  1354. if(dDivAng>PI/4)
  1355. dDivAng=PI/4;
  1356. //3.计算每步画线的两点坐标,旋转dAng并加基点坐标偏移后画线
  1357. if(!bCounterClockWise)//统一为逆弧 
  1358. {
  1359. double dAng=dBAng;
  1360. dBAng=dEAng;
  1361. dEAng=dAng;
  1362. xend=bx;
  1363. yend=by;
  1364. bx=ex;
  1365. by=ey;
  1366. }
  1367. else
  1368. {
  1369. xend=ex;
  1370. yend=ey;
  1371. }
  1372. if(dEAng<dBAng)
  1373. dEAng+=2*PI;
  1374. TransRotate(bx,by,dAng,x1,y1);
  1375. x1+=dBaseX;
  1376. y1+=dBaseY;
  1377. if(pBuffer)
  1378. {
  1379. while(dBAng<dEAng-PRECISION_SHOW_ANG)
  1380. {
  1381. dBAng+=dDivAng;
  1382. if(dBAng>dEAng-PRECISION_SHOW_ANG)
  1383. {
  1384. //dBAng=dEAng;
  1385. ex=xend;
  1386. ey=yend;
  1387. }
  1388. else
  1389. {
  1390. ex=xCen+xr*cos(dBAng);
  1391. ey=yCen+yr*sin(dBAng);
  1392. }
  1393. TransRotate(ex,ey,dAng,x2,y2);
  1394. x2+=dBaseX;
  1395. y2+=dBaseY;
  1396. {
  1397. S_LINE_BUFFER* pLineBuf= new S_LINE_BUFFER;
  1398. pLineBuf->Color=RGB(0,0,0);
  1399. pLineBuf->LineScale=1;
  1400. pLineBuf->LineType=SOLID_LINE;
  1401. pLineBuf->Mode=DRAWPRESENT;
  1402. pLineBuf->P1.x=x1;
  1403. pLineBuf->P1.y=y1;
  1404. pLineBuf->P2.x=x2;
  1405. pLineBuf->P2.y=y2;
  1406. pLineBuf->Width=1;
  1407. pBuffer->AddLine(pLineBuf);
  1408. x1=x2;
  1409. y1=y2;
  1410. }
  1411. };
  1412. }
  1413. }
  1414. void CReader::TransRotate(double x, double y, double dAng, double& x1, double& y1)
  1415. {
  1416. if(fabs(dAng)<PRECISION)
  1417. {
  1418. x1=x;
  1419. y1=y;
  1420. return;
  1421. }
  1422. double dRotAng=atan2(y,x);
  1423. if(dRotAng<0)
  1424. dRotAng+=2*PI;
  1425. x1 = sqrt(x*x+y*y)*cos(dRotAng+dAng);
  1426. y1 = sqrt(x*x+y*y)*sin(dRotAng+dAng);
  1427. }