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

CAD

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "FileSwitch.h"
  3. #include "Reader.h"
  4. #include "DwgReader.h"
  5. #include "KmSection.h"
  6. #include "CShow.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. CString CReader::m_strACADpath="";
  13. CString CReader::m_strAddPath="";
  14. double CReader::calculate_3d2pdistance(double x1,double y1,double z1,double x2,double y2,double z2)
  15. {
  16. return sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2) );
  17. }
  18. double CReader::calculate_3ddpdistance(double dx,double dy,double dz)
  19. {
  20. return sqrt( dx*dx+dy*dy+dz*dz );
  21. }
  22. double CReader::calculate_2dangle(double dx,double dy)
  23. {
  24. double r=sqrt(dx*dx+dy*dy);
  25. if(r<0.00000001)
  26. {
  27. return 0;
  28. }
  29. double cosv=dx/r;
  30. if(cosv>=1.0)
  31. {
  32. return 0;
  33. }
  34. if(cosv<=-1.0)
  35. {
  36. return PI;
  37. }
  38. double sinv=dy/r;
  39. if(sinv>=0)
  40. {
  41. return acos(cosv);
  42. }
  43. else
  44. {
  45. return (2*PI-acos(cosv));
  46. }
  47. }
  48. KmPoint CReader::calculate_2drotate(double xo,double yo,double dx,double dy,double ra)
  49. {
  50. KmMatrix matrix;//旋转矩阵
  51. matrix.r11 = cos(ra);
  52. matrix.r21 = sin(ra);
  53. matrix.r31 = 0.0;
  54. matrix.r12 = -sin(ra);   
  55. matrix.r22 = cos(ra);
  56. matrix.r32 = 0.0;
  57. matrix.r13 = xo*(1.0 - cos(ra)) + yo*sin(ra);
  58. matrix.r23 = yo*(1.0 - cos(ra)) - xo*sin(ra);
  59. matrix.r33 = 1.0;
  60. KmPoint pt(xo+dx,yo+dy);
  61.     pt = matrix * pt;
  62. return pt;
  63. }
  64. void CDwgReader::calculate_3dbulgelines(CArray<CVector*,CVector*>&avectors)
  65. {
  66. for(int i=1;i<avectors.GetSize();i++)
  67. {
  68. if(fabs(avectors[i-1]->m_bulge)<= 1e-6)
  69. {
  70. if(avectors[i-1]->m_bwidth&&avectors[i-1]->m_widthbegin<1.0e-6)
  71. {
  72. m_pConverter->ConverterEntiey_KmArrowHead(avectors[i-1]->m_x,avectors[i-1]->m_y,avectors[i]->m_x,avectors[i]->m_y,avectors[i-1]->m_widthend);
  73. }
  74. else if(avectors[i-1]->m_bwidth&&avectors[i-1]->m_widthend<1.0e-6)
  75. {
  76. m_pConverter->ConverterEntiey_KmArrowHead(avectors[i]->m_x,avectors[i]->m_y,avectors[i-1]->m_x,avectors[i-1]->m_y,avectors[i-1]->m_widthbegin);
  77. }
  78. else
  79. {
  80. m_pConverter->ConverterEntiey_KmLine(avectors[i-1]->m_x,avectors[i-1]->m_y,avectors[i-1]->m_z,avectors[i]->m_x,avectors[i]->m_y,avectors[i]->m_z);
  81. }
  82. }
  83. else
  84. {
  85. double b = sqrt( (avectors[i-1]->m_x-avectors[i]->m_x)*(avectors[i-1]->m_x-avectors[i]->m_x)+
  86. (avectors[i-1]->m_y-avectors[i]->m_y)*(avectors[i-1]->m_y-avectors[i]->m_y) );
  87. double d = fabs( b/2/(2*avectors[i-1]->m_bulge/(1-avectors[i-1]->m_bulge*avectors[i-1]->m_bulge) ) );
  88. double bert;
  89. if(avectors[i-1]->m_bulge<0)
  90. {
  91. if( (avectors[i-1]->m_bulge + 1) < 0 )
  92. {
  93. bert=atan2(avectors[i]->m_y-avectors[i-1]->m_y,avectors[i]->m_x-avectors[i-1]->m_x) - PI/2;
  94. }
  95. else 
  96. {
  97. bert=atan2(avectors[i]->m_y-avectors[i-1]->m_y,avectors[i]->m_x-avectors[i-1]->m_x) + PI/2;
  98. }
  99. }
  100. else
  101. {
  102. if( (avectors[i-1]->m_bulge - 1) > 0 )
  103. {
  104. bert=atan2(avectors[i]->m_y-avectors[i-1]->m_y,avectors[i]->m_x-avectors[i-1]->m_x) + PI/2;
  105. }
  106. else 
  107. {
  108. bert=atan2(avectors[i]->m_y-avectors[i-1]->m_y,avectors[i]->m_x-avectors[i-1]->m_x) - PI/2;
  109. }
  110. }
  111. double radius = sqrt((b/2)*(b/2) + d*d );
  112. double cir_x = (avectors[i-1]->m_x+avectors[i]->m_x)/2 - d*cos(bert);
  113. double cir_y = (avectors[i-1]->m_y+avectors[i]->m_y)/2 - d*sin(bert);
  114. double b_angle = atan2( avectors[i-1]->m_y-cir_y, avectors[i-1]->m_x-cir_x );
  115. double e_angle = atan2( avectors[i]->m_y-cir_y, avectors[i]->m_x-cir_x );
  116. if(avectors[i-1]->m_bulge<0)
  117. {
  118. m_pConverter->ConverterEntiey_KmArc(cir_x,cir_y,0,radius,e_angle,b_angle);
  119. }
  120. else
  121. {
  122. m_pConverter->ConverterEntiey_KmArc(cir_x,cir_y,0,radius,b_angle,e_angle);
  123. }
  124. }
  125. }
  126. }
  127. BOOL CDwgReader::calculate_BackView()
  128. {
  129. if(adenhd->entflags&AD_EXTRUSION_INFO_VALID)
  130. {
  131. if(fabs(adenhd->extrusion[0])<0.00000001)
  132. {
  133. if(fabs(adenhd->extrusion[1])<0.00000001)
  134. {
  135. if(fabs(adenhd->extrusion[2]+1.0)<0.00000001)
  136. {
  137. return TRUE;
  138. }
  139. }
  140. }
  141. }
  142. return FALSE;
  143. }
  144. //搜索dwg图纸所用的文件,并将它拷贝到kmcad的同名目录中.
  145. void CReader::calculate_DefaultExamineFile(CString& filename2,CString sondir,CString sonkmdir)
  146. {
  147. if(sonkmdir.IsEmpty())sonkmdir=sondir;
  148. CString temppath;
  149. CString tempname;
  150. for(int index=0;index<filename2.GetLength();index++)
  151. {
  152. if(filename2[index]=='\')
  153. {
  154. if(!tempname.IsEmpty())
  155. {
  156. temppath+=tempname;
  157. temppath+="\";
  158. tempname.Empty();
  159. }
  160. }
  161. else
  162. {
  163. tempname+=filename2[index];
  164. }
  165. }
  166. if(!temppath.IsEmpty())
  167. {
  168. CString filetemp=temppath+tempname;
  169. CFileFind filefind;
  170. if( filefind.FindFile(filetemp) )
  171. {
  172. calculate_CopyFile(filetemp,tempname,sonkmdir);
  173. filefind.Close();
  174. }
  175. }
  176. CString filename=filename2=tempname;
  177. for(int i=0;i<=1;i++)
  178. {
  179. if((i==1)&&(filename2!=filename))
  180. {
  181. filename2=filename;
  182. }
  183. else if(i==1)
  184. {
  185. //没有找到型文件
  186. break;
  187. }
  188. CFileFind filefind;
  189. //1.直接在kmcad的目录中寻找.
  190. {
  191. TCHAR szFileName[MAX_PATH]; 
  192. ::GetModuleFileName(::GetModuleHandle(_T("FileSwitch.dll")),szFileName,MAX_PATH); 
  193. (*_tcsrchr(szFileName,'\'))=''; 
  194. CString strPath=szFileName;
  195. strPath+="\";
  196. strPath+=sonkmdir;
  197. strPath+="\";
  198. strPath+=filename;
  199. if(filefind.FindFile(strPath))
  200. {
  201. filename=strPath;
  202. filefind.Close();
  203. return;
  204. }
  205. }
  206. //2.直接在硬盘上搜索该文件.
  207. if(filefind.FindFile(filename))
  208. {
  209. CString name;
  210. for(int i=filename.GetLength();i>0;i--)
  211. {
  212. if(filename.GetAt(i-1)=='\')
  213. {
  214. break;
  215. }
  216. if(filename.GetAt(i-1)=='/')
  217. {
  218. break;
  219. }
  220. name+=filename.GetAt(i-1);
  221. }
  222. filename=calculate_CopyFile(filename,name,sonkmdir);
  223. filefind.Close();
  224. return;
  225. }
  226. if(!m_strAddPath.IsEmpty())
  227. {
  228. CString filenametemp;
  229. filenametemp=m_strAddPath+tempname;
  230. if(filefind.FindFile(filenametemp))
  231. {
  232. CString name;
  233. for(int i=filenametemp.GetLength();i>0;i--)
  234. {
  235. if(filenametemp.GetAt(i-1)=='\')
  236. {
  237. break;
  238. }
  239. if(filenametemp.GetAt(i-1)=='/')
  240. {
  241. break;
  242. }
  243. name+=filenametemp.GetAt(i-1);
  244. }
  245. filenametemp=calculate_CopyFile(filenametemp,name,sonkmdir);
  246. filefind.Close();
  247. return;
  248. }
  249. }
  250. //3.在用户提供的acad路径中寻找该文件.
  251. CString strPath;
  252. for(int i=0;i<m_strACADpath.GetLength();i++)
  253. {
  254. if(m_strACADpath.GetAt(i)!=';')
  255. {
  256. strPath+=m_strACADpath.GetAt(i);
  257. }
  258. else
  259. {
  260. if(strPath.GetLength()>0)
  261. {
  262. if(strPath.GetAt(strPath.GetLength()-1)!='\')
  263. {
  264. strPath+="\";
  265. }
  266. if(sondir.GetLength()>0)
  267. {
  268. strPath+=sondir;
  269. strPath+='\';
  270. }
  271. strPath+=filename;
  272. if(filefind.FindFile(strPath))
  273. {
  274. filename=calculate_CopyFile(strPath,filename,sonkmdir);
  275. return;
  276. }
  277. }
  278. strPath.Empty();
  279. }
  280. }
  281. //3.在系统环境中寻找.
  282. char *envptr;
  283. if ((envptr=getenv("ACAD"))!=NULL)//在系统路径中寻找
  284. {
  285. CString strPaths=envptr;
  286. for(int i=0;i<strPaths.GetLength();i++)
  287. {
  288. if(strPaths.GetAt(i)!=';')
  289. {
  290. strPath+=strPaths.GetAt(i);
  291. }
  292. else
  293. {
  294. if(strPath.GetLength()>0)
  295. {
  296. if(strPath.GetAt(strPath.GetLength()-1)!='\')
  297. {
  298. strPath+="\";
  299. }
  300. CString strTemp=strPath;
  301. if(sondir.GetLength()>0)
  302. {
  303. strPath+=sondir;
  304. strPath+='\';
  305. }
  306. strTemp+=filename;
  307. if(filefind.FindFile(strTemp))
  308. {
  309. filename=calculate_CopyFile(strPath,filename,sonkmdir);
  310. filefind.Close();
  311. return;
  312. }
  313. strPath+=filename;
  314. if(filefind.FindFile(strPath))
  315. {
  316. filename=calculate_CopyFile(strPath,filename,sonkmdir);
  317. filefind.Close();
  318. return;
  319. }
  320. }
  321. strPath.Empty();
  322. }
  323. }
  324. }
  325. //5.在注册表中寻找.
  326. //○1通过RegOpenKey函数打开注册表.
  327. HKEY hKey;
  328. if(RegOpenKey(HKEY_LOCAL_MACHINE,"Software\Autodesk\AutoCAD",&hKey)==ERROR_SUCCESS)
  329. {
  330. //○2通过RegQueryValueEx进行键值查询.
  331. DWORD dwType=REG_SZ;
  332. BYTE szData[100];
  333. DWORD dwSize=sizeof(szData);
  334. if(RegQueryValueEx(hKey,"CurVer",0,&dwType,szData,&dwSize)==ERROR_SUCCESS)
  335. {
  336. CString strKey="Software\Autodesk\AutoCAD\";
  337. strKey+=(char*)szData;
  338. if(RegOpenKey(HKEY_LOCAL_MACHINE,strKey,&hKey)==ERROR_SUCCESS)
  339. {
  340. dwSize=sizeof(szData);
  341. if(RegQueryValueEx(hKey,"CurVer",0,&dwType,szData,&dwSize)==ERROR_SUCCESS)
  342. {
  343. strKey+='\';
  344. strKey+=(char*)szData;
  345. if(RegOpenKey(HKEY_LOCAL_MACHINE,strKey,&hKey)==ERROR_SUCCESS)
  346. {
  347. dwSize=sizeof(szData);
  348. if(RegQueryValueEx(hKey,"AcadLocation",0,&dwType,szData,&dwSize)==ERROR_SUCCESS)
  349. {
  350. strPath.Empty();
  351. strPath=(char*)szData;
  352. if(strPath.GetLength()>0)
  353. {
  354. if(strPath.GetAt(strPath.GetLength()-1)!='\')
  355. {
  356. strPath+="\";
  357. }
  358. if(sondir.GetLength()>0)
  359. {
  360. strPath+=sondir;
  361. strPath+='\';
  362. }
  363. strPath+=filename;
  364. if(filefind.FindFile(strPath))
  365. {
  366. filename=calculate_CopyFile(strPath,filename,sonkmdir);
  367. return;
  368. }
  369. }
  370. strPath.Empty();
  371. }
  372. }
  373. }
  374. }
  375. }
  376. }
  377. }
  378. //filefind.Close();
  379. //没有找到型文件
  380. }
  381. CString CReader::calculate_CopyFile(CString fullfilename,CString filename,CString sondir)
  382. {
  383. CFileFind filefind;
  384. CString strPath;
  385. {
  386. TCHAR szFileName[MAX_PATH]; 
  387. ::GetModuleFileName(::GetModuleHandle(_T("FileSwitch.dll")),szFileName,MAX_PATH); 
  388. (*_tcsrchr(szFileName,'\'))=''; 
  389. strPath=szFileName;
  390. strPath+="\";
  391. strPath+=sondir;
  392. strPath+="\";
  393. strPath+=filename;
  394. if(filefind.FindFile(strPath))
  395. {
  396. filefind.Close();
  397. return strPath;
  398. }
  399. }
  400. if(!filefind.FindFile(fullfilename))
  401. {
  402. //错误:没有找到指定的文件.
  403. filefind.Close();
  404. return fullfilename;
  405. }
  406. //copy file fullfilename to strpath
  407. {
  408. ::CopyFile(fullfilename,strPath,TRUE);
  409. }
  410. if(filefind.FindFile(strPath))
  411. {
  412. filefind.Close();
  413. return strPath;
  414. }
  415. filefind.Close();
  416. return fullfilename;
  417. }
  418. void CReader::calculate_path_line(PATH2* path,double x1,double y1,double x2,double y2)
  419. {
  420. path->points.Add(KmPoint(x1,y1));
  421. path->bugle.Add(1);
  422. path->Center.Add(KmPoint(x2,y2));
  423. path->Radius.Add(0);
  424. path->b_angle.Add(0);
  425. path->e_angle.Add(0);
  426. }
  427. void CReader::calculate_path_arc(PATH2* path,double x1,double y1,double r,double ba,double ea,short full)
  428. {
  429. double b_angle=ba;//作逆弧处理
  430. double e_angle=ea;
  431. if(full)
  432. {
  433. path->points.Add(KmPoint(0,0));
  434. path->bugle.Add(0);
  435. path->Center.Add(KmPoint(x1,y1));
  436. path->Radius.Add(r);
  437. path->b_angle.Add(0);
  438. path->e_angle.Add(360);
  439. }
  440. else
  441. {
  442. path->points.Add(KmPoint(0,0));
  443. path->bugle.Add(0);
  444. path->Center.Add(KmPoint(x1,y1));
  445. path->Radius.Add(r);
  446. path->b_angle.Add(ba);
  447. path->e_angle.Add(ea);
  448. }
  449. }
  450. void CReader::calculate_path_object(PATH2* path,KmObject* pObj)
  451. {
  452. KmBuffer aBuffer;
  453. S_LINE_BUFFER* pLineBuffer;
  454.     S_CIRCLE_BUFFER* pCircleBuffer;
  455. CShow* pShow = new CGDIShow((CWnd*)NULL);
  456. pObj->Draw(pShow,0,DRAWPRESENT,&aBuffer);
  457. for(int i=0;i<aBuffer.GetLineBuffSize();i++)
  458. {
  459. pLineBuffer=aBuffer.GetLineEnt(i);
  460. calculate_path_line(path,pLineBuffer->P1.x,pLineBuffer->P1.y,pLineBuffer->P2.x,pLineBuffer->P2.y);
  461. }
  462. for(i=0;i<aBuffer.GetCircleBuffSize();i++)
  463. {
  464. pCircleBuffer=aBuffer.GetCircleEnt(i);
  465. if(pCircleBuffer->message&MESSAGE_CIRCLE_FULL)
  466. {
  467. calculate_path_arc(path,pCircleBuffer->center.x,pCircleBuffer->center.y,pCircleBuffer->radius,0,0,1);
  468. }
  469. else if(pCircleBuffer->message&MESSAGE_CIRCLE_NEGATIVE)//顺弧
  470. {
  471. calculate_path_arc(path,pCircleBuffer->center.x,pCircleBuffer->center.y,pCircleBuffer->radius,pCircleBuffer->e_angle,pCircleBuffer->b_angle,0);
  472. }
  473. else
  474. {
  475. calculate_path_arc(path,pCircleBuffer->center.x,pCircleBuffer->center.y,pCircleBuffer->radius,pCircleBuffer->b_angle,pCircleBuffer->e_angle,0);
  476. }
  477. }
  478. aBuffer.ClearKmBuffer();
  479. delete pShow;
  480. }
  481. void CReader::calculate_path_bugleline(PATH2* path,double x1,double y1,double bugle,double x2,double y2)
  482. {
  483. if(fabs(bugle)<0.0000001)
  484. {
  485. calculate_path_line(path,x1,y1,x2,y2);
  486. return;
  487. }
  488. KmCircle* pCircle=new KmCircle; 
  489. /*
  490. KmPoint Point_X1;        //存放圆上的第三点
  491. KmPoint Point_X2;        //存放圆上的第三点
  492. KmPoint Point_X3;        //存放圆上的第三点
  493. Point_X1.x=x1;
  494. Point_X1.x=y1;
  495. Point_X2.x=x2;
  496. Point_X2.x=y2;
  497. KmPoint ChangPoint;
  498. KmPoint MidPoint;        //弦Point_X1Point_X2上的中点
  499. double   length  ;        //Point_X1,Point_X2之间线段长度
  500. double   hight;           //弦Point_X1Point_X2上的高
  501. double   borderlen;
  502. double   SaveAngle;       //与弧相关角的SIN或COS值
  503. double   X;
  504.  
  505. length=sqrt((Point_X1.x-Point_X2.x)*(Point_X1.x-Point_X2.x)+(Point_X1.y-Point_X2.y)*(Point_X1.y-Point_X2.y));
  506. hight=(length*bugle)/2;
  507.     MidPoint.x=(Point_X1.x+Point_X2.x)/2;
  508.     MidPoint.y=(Point_X1.y+Point_X2.y)/2;
  509. if((Point_X1.y==MidPoint.y)&&(Point_X1.x>MidPoint.x))//当弦与X轴平行
  510. {
  511. Point_X3.y=MidPoint.y+hight;
  512. Point_X3.x=MidPoint.x;
  513. }
  514. else if((Point_X1.y==MidPoint.y)&&(Point_X1.x<MidPoint.x))//当弦与Y轴平行
  515. {
  516. Point_X3.y=MidPoint.y-hight;
  517. Point_X3.x=MidPoint.x;
  518. }
  519. else
  520. {
  521. if(bugle>0)  //弧为逆时针方向
  522. {
  523. borderlen=fabs(MidPoint.x-Point_X2.x);
  524. SaveAngle=borderlen/length*2;             
  525. if((Point_X2.y>Point_X1.y)&&(Point_X2.x<Point_X1.x))
  526. {
  527. Point_X3.y=MidPoint.y+(hight*SaveAngle);
  528. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  529. Point_X3.x=MidPoint.x+X;
  530. }
  531. else if((Point_X2.y>Point_X1.y)&&(Point_X2.x>Point_X1.x))
  532. {
  533. Point_X3.y=MidPoint.y-(hight*SaveAngle);
  534. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  535. Point_X3.x=MidPoint.x+X;
  536. }
  537. else if((Point_X2.y<Point_X1.y)&&(Point_X2.x>Point_X1.x))
  538. {
  539. Point_X3.y=MidPoint.y-(hight*SaveAngle);
  540. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  541. Point_X3.x=MidPoint.x-X;
  542. }
  543. else if((Point_X2.y<Point_X1.y)&&(Point_X2.x<Point_X1.x))
  544. {
  545. Point_X3.y=(MidPoint.y+(hight*SaveAngle));
  546. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  547. Point_X3.x=MidPoint.x-X;
  548. }
  549. }
  550. else
  551. {
  552. borderlen=fabs(MidPoint.x-Point_X2.x);
  553. SaveAngle=borderlen/length*2;             
  554. if((Point_X2.y>Point_X1.y)&&(Point_X2.x<Point_X1.x))
  555. {
  556. Point_X3.y=MidPoint.y+(hight*SaveAngle);
  557. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  558. Point_X3.x=MidPoint.x-X;
  559. }
  560. else if((Point_X2.y>Point_X1.y)&&(Point_X2.x>Point_X1.x))
  561. {
  562. Point_X3.y=MidPoint.y-(hight*SaveAngle);
  563. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  564. Point_X3.x=MidPoint.x-X;
  565. }
  566. else if((Point_X2.y<Point_X1.y)&&(Point_X2.x>Point_X1.x))
  567. {
  568. Point_X3.y=MidPoint.y-(hight*SaveAngle);
  569. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  570. Point_X3.x=MidPoint.x+X;
  571. }
  572. else if((Point_X2.y<Point_X1.y)&&(Point_X2.x<Point_X1.x))
  573. {
  574. Point_X3.y=(MidPoint.y+(hight*SaveAngle));
  575. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  576. Point_X3.x=MidPoint.x+X;
  577. }
  578. }
  579. }
  580. calculate_path_line(path,Point_X1.x,Point_X1.y,Point_X3.x,Point_X3.y);
  581. calculate_path_line(path,Point_X2.x,Point_X2.y,Point_X3.x,Point_X3.y);
  582. calculate_path_line(path,Point_X1.x,Point_X1.y,Point_X2.x,Point_X2.y);
  583. */
  584. calculate_Get_CIRCLE(*pCircle,bugle,KmPoint(x1,y1),KmPoint(x2,y2));
  585. calculate_path_object(path,pCircle);
  586. delete pCircle;
  587. }
  588. void CReader::calculate_Get_CIRCLE(CIRCLE &rCircle,double bugle,KmPoint Point_X1,KmPoint Point_X2)
  589. {
  590. KmPoint Point_X3;        //存放圆上的第三点
  591. KmPoint ChangPoint;
  592. KmPoint MidPoint;        //弦Point_X1Point_X2上的中点
  593. double   length  ;        //Point_X1,Point_X2之间线段长度
  594. double   hight;           //弦Point_X1Point_X2上的高
  595. double   borderlen;
  596. double   SaveAngle;       //与弧相关角的SIN或COS值
  597. double   X;
  598.  
  599. length=sqrt((Point_X1.x-Point_X2.x)*(Point_X1.x-Point_X2.x)+(Point_X1.y-Point_X2.y)*(Point_X1.y-Point_X2.y));
  600. hight=(length*bugle)/2;
  601.     MidPoint.x=(Point_X1.x+Point_X2.x)/2;
  602.     MidPoint.y=(Point_X1.y+Point_X2.y)/2;
  603. if((Point_X1.y==MidPoint.y)&&(Point_X1.x>MidPoint.x))//当弦与X轴平行且弧向上弯曲
  604. {
  605. Point_X3.y=MidPoint.y+hight;
  606. Point_X3.x=MidPoint.x;
  607. }
  608. else if((Point_X1.y==MidPoint.y)&&(Point_X1.x<MidPoint.x))//当弦与X轴平行且弧向下弯曲
  609. {
  610. Point_X3.y=MidPoint.y-hight;
  611. Point_X3.x=MidPoint.x;
  612. }
  613. else if((Point_X1.x==MidPoint.x)&&(Point_X1.y<MidPoint.y))//当弦与Y轴平行且弧向右弯曲
  614. {
  615. Point_X3.x=MidPoint.x+hight;
  616. Point_X3.y=MidPoint.y;
  617. }
  618. else if((Point_X1.x==MidPoint.x)&&(Point_X1.y>MidPoint.y))//当弦与Y轴平行且弧向左弯曲
  619. {
  620. Point_X3.x=MidPoint.x-hight;
  621. Point_X3.y=MidPoint.y;
  622. }
  623. else
  624. {
  625. if(bugle>0)  //弧为逆时针方向
  626. {
  627. borderlen=fabs(MidPoint.x-Point_X2.x);
  628. SaveAngle=borderlen/length*2;             
  629. if((Point_X2.y>Point_X1.y)&&(Point_X2.x<Point_X1.x))
  630. {
  631. Point_X3.y=MidPoint.y+(hight*SaveAngle);
  632. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  633. Point_X3.x=MidPoint.x+X;
  634. }
  635. else if((Point_X2.y>Point_X1.y)&&(Point_X2.x>Point_X1.x))
  636. {
  637. Point_X3.y=MidPoint.y-(hight*SaveAngle);
  638. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  639. Point_X3.x=MidPoint.x+X;
  640. }
  641. else if((Point_X2.y<Point_X1.y)&&(Point_X2.x>Point_X1.x))
  642. {
  643. Point_X3.y=MidPoint.y-(hight*SaveAngle);
  644. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  645. Point_X3.x=MidPoint.x-X;
  646. }
  647. else if((Point_X2.y<Point_X1.y)&&(Point_X2.x<Point_X1.x))
  648. {
  649. Point_X3.y=(MidPoint.y+(hight*SaveAngle));
  650. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  651. Point_X3.x=MidPoint.x-X;
  652. }
  653. }
  654. else
  655. {
  656. borderlen=fabs(MidPoint.x-Point_X2.x);
  657. SaveAngle=borderlen/length*2;             
  658. if((Point_X2.y>Point_X1.y)&&(Point_X2.x<Point_X1.x))
  659. {
  660. Point_X3.y=MidPoint.y+(hight*SaveAngle);
  661. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  662. Point_X3.x=MidPoint.x-X;
  663. }
  664. else if((Point_X2.y>Point_X1.y)&&(Point_X2.x>Point_X1.x))
  665. {
  666. Point_X3.y=MidPoint.y-(hight*SaveAngle);
  667. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  668. Point_X3.x=MidPoint.x-X;
  669. }
  670. else if((Point_X2.y<Point_X1.y)&&(Point_X2.x>Point_X1.x))
  671. {
  672. Point_X3.y=MidPoint.y-(hight*SaveAngle);
  673. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  674. Point_X3.x=MidPoint.x+X;
  675. }
  676. else if((Point_X2.y<Point_X1.y)&&(Point_X2.x<Point_X1.x))
  677. {
  678. Point_X3.y=(MidPoint.y+(hight*SaveAngle));
  679. X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
  680. Point_X3.x=MidPoint.x+X;
  681. }
  682. }
  683. }
  684. if(bugle>0)  //弧为逆时针方向  counter-clockwise
  685. {
  686. calculate_three_point_Getcircle(rCircle,Point_X3,Point_X1,Point_X2,TRUE);  //通过Point_X1,Point_X3,Point_X2求圆
  687. }
  688. else 
  689. {
  690. calculate_three_point_Getcircle(rCircle,Point_X3,Point_X1,Point_X2,FALSE);  //通过Point_X1,Point_X3,Point_X2求圆
  691. }
  692. }
  693. //KmPoint1为中点
  694. void CReader::calculate_three_point_Getcircle(CIRCLE &rCircle,KmPoint KmPoint1,KmPoint KmPoint2,KmPoint KmPoint3,BOOL bccw)
  695. {
  696.     double mid_sita;
  697.     double rxyo[3];
  698.     double sita1,sita2,s1,s2;
  699. double first_seed_x=KmPoint1.x;   
  700. double first_seed_y=KmPoint1.y;
  701. double second_seed_x=KmPoint2.x;
  702. double second_seed_y=KmPoint2.y;
  703. double third_seed_x=KmPoint3.x;
  704. double third_seed_y=KmPoint3.y;
  705. if(fabs(second_seed_y-first_seed_y)<0.0000001&&fabs(second_seed_x-first_seed_x)<0.0000001) return;
  706. if(fabs(third_seed_y-first_seed_y)<0.0000001&&fabs(third_seed_x-first_seed_x)<0.0000001) return;
  707. //计算三点圆的圆心.
  708. cal_r_xyo(rxyo,first_seed_x,first_seed_y,second_seed_x,second_seed_y,third_seed_x,third_seed_y);
  709. sita1=atan2(second_seed_y-first_seed_y,second_seed_x-first_seed_x);
  710. sita2=atan2(third_seed_y-first_seed_y,third_seed_x-first_seed_x);
  711. s1=standard(rad_to_deg(sita1));
  712. s2=standard(rad_to_deg(sita2));
  713. rCircle.xo=rxyo[1];
  714. rCircle.yo=rxyo[2];
  715. rCircle.r=rxyo[0];
  716. {//1
  717. if(fabs(first_seed_y-rxyo[2])<0.0000001&&fabs(first_seed_x-rxyo[1])<0.0000001)return;
  718. if(fabs(third_seed_y-rxyo[2])<0.0000001&&fabs(third_seed_x-rxyo[1])<0.0000001)return;
  719. if(fabs(second_seed_y-rxyo[2])<0.0000001&&fabs(second_seed_x-rxyo[1])<0.0000001)return;
  720. rCircle.b_angle=standard(rad_to_deg(atan2(second_seed_y-rxyo[2],second_seed_x-rxyo[1])));
  721. rCircle.e_angle=standard(rad_to_deg(atan2(third_seed_y-rxyo[2],third_seed_x-rxyo[1])));
  722. mid_sita=(standard(rad_to_deg(atan2(first_seed_y-rxyo[2],first_seed_x-rxyo[1]))));
  723. //if((mid_sita<rCircle.b_angle||mid_sita>rCircle.e_angle)&&rCircle.b_angle<rCircle.e_angle||mid_sita>rCircle.e_angle&&rCircle.b_angle>mid_sita)
  724. if(!bccw)
  725. {//2
  726. mid_sita=rCircle.b_angle;
  727. rCircle.b_angle=rCircle.e_angle;
  728. rCircle.e_angle=mid_sita;
  729. }//2
  730. rCircle.message=MESSAGE_CIRCLE_POSITIVE;
  731. }//1
  732. }
  733. int CReader::calculate_cal_r_xyo(double rxyo[3],double first_seed_x,double first_seed_y,double second_seed_x,double second_seed_y,double third_seed_x,double third_seed_y)
  734. //求圆//rxyo[3]圆心//second_seed_x,second_seed_y,third_seed_x,third_seed_y)//圆上的点
  735. {
  736.     if(fabs(first_seed_x-third_seed_x)>=fabs(second_seed_x-third_seed_x))
  737.     {
  738.         return(calculate_get_r_xyo(rxyo,first_seed_x,first_seed_y,second_seed_x,second_seed_y,
  739.         third_seed_x,third_seed_y));
  740.     }
  741.     else
  742.     {
  743.         return (calculate_get_r_xyo(rxyo,second_seed_x,second_seed_y,first_seed_x,first_seed_y,
  744.         third_seed_x,third_seed_y));
  745.     }
  746. }
  747. int CReader::calculate_get_r_xyo(double rxyo[3],double x1,double y1,double x2,double y2,double x3,double y3)
  748. //求圆心
  749. //rxyo[3]  出访圆新的缓存
  750. //x1,y1,x2,y2,x3,y3圆上的三点
  751. {
  752.     double circle_a1,circle_b1,circle_c1;
  753.     double m,n,k,a2,b2,c2;
  754.     double d,e,f;
  755.     circle_a1=x1*x1+y1*y1;
  756.     circle_b1=x2*x2+y2*y2;
  757.     circle_c1=x3*x3+y3*y3;
  758.     if(fabs(x1-x3)<0.0000001) return 0;
  759.     a2=(circle_a1-circle_c1)/(x1-x3);
  760.     b2=circle_b1-circle_c1;
  761.     c2=circle_c1;
  762.     m=(y1-y3)/(x1-x3);
  763.     k=y2-y3-(y1-y3)/(x1-x3)*(x2-x3);
  764.     n=y3-(y1-y3)/(x1-x3)*x3;
  765.     circle_a1=a2;
  766.     circle_b1=b2-a2*(x2-x3);
  767.     circle_c1=c2-x3*a2;
  768.     if(fabs(k)<0.0000001) return 0;
  769.     d=-circle_a1+circle_b1/k*m;
  770.     e=-circle_b1/k;
  771.     f=-circle_c1+circle_b1/k*n;
  772.     rxyo[0]=sqrt(d*d+e*e-4.0*f)*0.5;
  773.     rxyo[1]=-d*0.5;
  774.     rxyo[2]=-e*0.5;
  775.     return 1;
  776. }
  777. BOOL CReader::calculate_findshape(AD_DB_HANDLE dwghandle,AD_OBJHANDLE shapefileobjhandle,int whichshape,double *px,double *py,double dAng,int bound_high,double text_h, double text_w,KmBuffer* pBuffer)
  778. {
  779. AD_TB adtbtemp;
  780. //extern  short  ADCDECL adSeekShapefile _((AD_DB_HANDLE handle,AD_OBJHANDLE thehandle,PAD_SHPTB theshptb));
  781. short sReturnValue = adSeekShapefile(dwghandle,shapefileobjhandle,&adtbtemp.shptb);
  782. if(sReturnValue!=1)
  783. {
  784. return FALSE;
  785. }
  786. CString filename=adtbtemp.shptb.file;
  787. if(filename.IsEmpty()){return FALSE;}
  788. CFileFind filefind;
  789. if(!filefind.FindFile(filename))
  790. {
  791. calculate_DefaultExamineFile(filename,"SUPPORT");
  792. {
  793. TCHAR szFileName[MAX_PATH]; 
  794. ::GetModuleFileName(::GetModuleHandle(_T("FileSwitch.dll")),szFileName,MAX_PATH); 
  795. (*_tcsrchr(szFileName,'\'))=''; 
  796. CString strPath=szFileName;
  797. strPath+="\";
  798. strPath+="SUPPORT";
  799. strPath+="\";
  800. strPath+=filename;
  801. if(!filefind.FindFile(strPath))
  802. {
  803. filefind.Close();
  804. return FALSE;
  805. }
  806. filename=strPath;
  807. }
  808. }
  809. //BYTE24 CHAR* 文件格式标记
  810. //BYTE2 int 形的起始序号
  811. //BYTE2 int 形的中止序号
  812. //BYTE2 int 形的数量
  813. //循环BYTE2 int 形的序号
  814. //   BYTE2 int 形的字节长度
  815. //循环BYTE至0 CHAR* 形的名称
  816. //   BYTE形的长度shorts形的内容
  817. //BYTE3 CHAR* 结束标记"EOF"
  818. CFile file;
  819. if(!file.Open(filename,CFile::modeRead))
  820. {
  821. return FALSE;
  822. __int8  byte;
  823. __int16 data;
  824. __int16 iBegin;
  825. __int16 iEnd;
  826. __int16 iNum;
  827. CArray<__int16,__int16> iLengths;
  828. if(file.Seek(24,CFile::begin)!=24){try{file.Close();}catch(...){};return FALSE;}
  829. if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}iBegin=data;
  830. if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}iEnd=data;
  831. if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}iNum=data;
  832. if(iNum!=(fabs(iEnd-iBegin)+1)){try{file.Close();}catch(...){};return FALSE;}
  833. if(iEnd<iBegin){data=iBegin;iBegin=iEnd;iEnd=data;}
  834. if(whichshape<iBegin||whichshape>iEnd){try{file.Close();}catch(...){};return FALSE;}
  835. for(__int16 index=iBegin;index<=iEnd;index++)
  836. {
  837. if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}
  838. if(index!=data){try{file.Close();}catch(...){};return FALSE;}
  839. if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}
  840. iLengths.Add(data);
  841. }
  842. if(iLengths[whichshape-iBegin]>2000){try{file.Close();}catch(...){};return FALSE;}
  843. __int32 iPos=30+iNum*4;
  844. for(index=0;index<(whichshape-iBegin);index++)
  845. {
  846. iPos+=iLengths[index];
  847. }
  848. if(file.Seek(iPos,CFile::begin)!=iPos){try{file.Close();}catch(...){};return FALSE;}
  849. CString strShapeName;
  850. for(index=0;index<25;index++)
  851. {
  852. if(file.Read(&byte,1)!=1){try{file.Close();}catch(...){};return FALSE;}
  853. if(byte==0)break;
  854. strShapeName+=byte;
  855. if(index==24){try{file.Close();}catch(...){};return FALSE;}
  856. }
  857. char str[2000];
  858. if( file.Read(str,iLengths[whichshape-iBegin]-strShapeName.GetLength()-1)!=((UINT)(iLengths[whichshape-iBegin]-strShapeName.GetLength()-1))){try{file.Close();}catch(...){};return FALSE;}
  859. file.Close();
  860. CreateShape(dwghandle,shapefileobjhandle,str,iLengths[whichshape-iBegin]-strShapeName.GetLength()-1,px,py,dAng,bound_high,text_h,text_w,pBuffer);
  861. filefind.Close();
  862. return TRUE;
  863. }
  864. double calculate_findTTFHightRate(CString strFontName)
  865. {
  866. FONTMAPITEM* pFontMapItem=NULL;
  867. if(CConverter::m_mapFont.Lookup(strFontName,(void* &)pFontMapItem))
  868. {
  869. strFontName=pFontMapItem->m_strFontName;
  870. }
  871. double dRate=1.0;
  872. if(strFontName.Find('.')!=-1)return dRate;
  873. CWinApp* pApp=::AfxGetApp();
  874. CString strTemp;
  875. if(pApp)
  876. {
  877. strTemp = pApp->GetProfileString(_T("DwgFontHightRate"),strFontName,"-1.0");
  878. dRate = ::atof(LPCTSTR(strTemp));
  879. if(dRate>0)
  880. {
  881. return dRate;
  882. }
  883. }
  884. dRate=1.0;
  885. CFont fonttext;fonttext.CreateFont(1000,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,0,0,0,0,strFontName);
  886. CWnd* pDesktop=CWnd::FromHandle(::GetDesktopWindow());
  887. CDC* pDC=pDesktop->GetDC();
  888. CFont* fontold=pDC->SelectObject(&fonttext);
  889. TEXTMETRIC tm;
  890. pDC->GetTextMetrics(&tm);
  891. pDC->SelectObject(fontold);
  892. if(fonttext.GetSafeHandle())
  893. fonttext.DeleteObject();
  894. try
  895. {
  896. dRate= ((double)(tm.tmHeight-tm.tmInternalLeading))*((double)(tm.tmAscent-tm.tmInternalLeading))/( ((double)(tm.tmHeight-tm.tmInternalLeading))*TEXT_ADJUST*((double)(tm.tmHeight+tm.tmExternalLeading)) );
  897. }
  898. catch(...)
  899. {
  900. dRate=1.0;
  901. }
  902. strTemp.Format("%lf",dRate);
  903. pApp->WriteProfileString(_T("DwgFontHightRate"),strFontName, strTemp);//用于保证保存了数据
  904. return dRate;
  905. }
  906. double calculate_findTTFWidthRate(CString strFontName)
  907. {
  908. FONTMAPITEM* pFontMapItem=NULL;
  909. if(CConverter::m_mapFont.Lookup(strFontName,(void* &)pFontMapItem))
  910. {
  911. strFontName=pFontMapItem->m_strFontName;
  912. }
  913. double dRate=1.0;
  914. if(strFontName.Find('.')!=-1)return dRate;
  915. CWinApp* pApp=::AfxGetApp();
  916. CString strTemp;
  917. if(pApp)
  918. {
  919. strTemp = pApp->GetProfileString(_T("DwgFontWidthRate"),strFontName,"-1.0");
  920. dRate = ::atof(LPCTSTR(strTemp));
  921. if(dRate>0)
  922. {
  923. return dRate;
  924. }
  925. }
  926. dRate=1.0;
  927. CFont fonttext;fonttext.CreateFont(1000,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,0,0,0,0,strFontName);
  928. CWnd* pDesktop=CWnd::FromHandle(::GetDesktopWindow());
  929. CDC* pDC=pDesktop->GetDC();
  930. CFont* fontold=pDC->SelectObject(&fonttext);
  931. TEXTMETRIC tm;
  932. pDC->GetTextMetrics(&tm);
  933. pDC->SelectObject(fontold);
  934. if(fonttext.GetSafeHandle())
  935. fonttext.DeleteObject();
  936. try
  937. {
  938. dRate=((double)tm.tmAveCharWidth)/((double)tm.tmHeight)*2.0;
  939. }
  940. catch(...)
  941. {
  942. dRate=1.0;
  943. }
  944. strTemp.Format("%lf",dRate);
  945. pApp->WriteProfileString(_T("DwgFontWidthRate"),strFontName, strTemp);//用于保证保存了数据
  946. return dRate;
  947. }
  948. double calculate_findTTFPosRate(CString strFontName)
  949. {
  950. FONTMAPITEM* pFontMapItem=NULL;
  951. if(CConverter::m_mapFont.Lookup(strFontName,(void* &)pFontMapItem))
  952. {
  953. strFontName=pFontMapItem->m_strFontName;
  954. }
  955. double dRate=1.0;
  956. if(strFontName.Find('.')!=-1)return dRate;
  957. CWinApp* pApp=::AfxGetApp();
  958. CString strTemp;
  959. if(pApp)
  960. {
  961. strTemp = pApp->GetProfileString(_T("DwgFontPosRate"),strFontName,"-1.0");
  962. dRate = ::atof(LPCTSTR(strTemp));
  963. if(dRate>0)
  964. {
  965. return dRate;
  966. }
  967. }
  968. dRate=1.0;
  969. CFont fonttext;fonttext.CreateFont(1000,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,0,0,0,0,strFontName);
  970. CWnd* pDesktop=CWnd::FromHandle(::GetDesktopWindow());
  971. CDC* pDC=pDesktop->GetDC();
  972. CFont* fontold=pDC->SelectObject(&fonttext);
  973. TEXTMETRIC tm;
  974. pDC->GetTextMetrics(&tm);
  975. pDC->SelectObject(fontold);
  976. if(fonttext.GetSafeHandle())
  977. fonttext.DeleteObject();
  978. try
  979. {
  980. //a=1.0+字高调整系数*TEXT_ADJUST*(扩展+发音)/(字高-线下-发音)
  981. dRate=1.0+::calculate_findTTFHightRate(strFontName)*TEXT_ADJUST*(tm.tmExternalLeading+
  982. tm.tmInternalLeading)/(1000.0-tm.tmDescent-tm.tmInternalLeading);
  983. }
  984. catch(...)
  985. {
  986. dRate=1.0;
  987. }
  988. strTemp.Format("%lf",dRate);
  989. pApp->WriteProfileString(_T("DwgFontPosRate"),strFontName, strTemp);//用于保证保存了数据
  990. return dRate;
  991. }
  992. BOOL CALLBACK AFX_EXPORT CReader::EnumFamScreenCallBack(ENUMLOGFONT* pelf, 
  993. NEWTEXTMETRICEX* /*lpntm*/, int FontType, LPVOID lp)
  994. {
  995. if (FontType & RASTER_FONTTYPE)
  996. return 1;
  997. LOGFONT& lf = pelf->elfLogFont;
  998. if ((lf.lfCharSet != ANSI_CHARSET) 
  999. &&(lf.lfCharSet != OEM_CHARSET) 
  1000. &&(lf.lfCharSet != SYMBOL_CHARSET) 
  1001. &&(lf.lfCharSet != GB2312_CHARSET) )
  1002. return 1 ;
  1003. // CStringArray* strarray;
  1004. // strarray = (CStringArray*)lp;
  1005. // strarray->Add(lf.lfFaceName);
  1006. CString strfilename;
  1007. strfilename=lf.lfFaceName;
  1008. // strfilename.MakeLower();
  1009. CTypedPtrMap<CMapStringToPtr, CString, void*>* pMapFont = 
  1010.   (CTypedPtrMap<CMapStringToPtr, CString, void*>*)lp;
  1011. void *p;
  1012. if(!pMapFont->Lookup(strfilename,p))
  1013. {
  1014. CString strTemp=strfilename;
  1015. strTemp.MakeLower();
  1016. if(strTemp=="symusic"||
  1017.    strTemp=="romand"||
  1018.    strTemp=="romans"||
  1019.    strTemp=="romant"||
  1020.    strTemp=="scriptc"||
  1021.    strTemp=="scripts"||
  1022.    strTemp=="syastro"||
  1023.    strTemp=="symap"||
  1024.    strTemp=="monotxt"||
  1025.    strTemp=="symeteo"||
  1026.    strTemp=="italict"||
  1027.    strTemp=="symath"||
  1028.    strTemp=="gothici"||
  1029.    strTemp=="bigfont"||
  1030.    strTemp=="complex"||
  1031.    strTemp=="romanc"||
  1032.    strTemp=="gothicg"||
  1033.    strTemp=="greekc"||
  1034.    strTemp=="greeks"||
  1035.    strTemp=="isocp"||
  1036.    strTemp=="isocp2"||
  1037.    strTemp=="isocp3"||
  1038.    strTemp=="isoct"||
  1039.    strTemp=="isoct2"||
  1040.    strTemp=="isoct3"||
  1041.    strTemp=="italic"||
  1042.    strTemp=="italicc"||
  1043.    strTemp=="gothice"||
  1044.    strTemp=="gbeitc"||
  1045.    strTemp=="gbcbig"||
  1046.    strTemp=="chineset"||
  1047.    strTemp=="extfont"||
  1048.    strTemp=="whgdtxt"||
  1049.    strTemp=="whgtxt"||
  1050.    strTemp=="whtmtxt"||
  1051.    strTemp=="htgtxt"||
  1052.    strTemp=="gbenor")
  1053. {
  1054. TRACE("同名 采用形文字");
  1055. }
  1056. else
  1057. {
  1058. pMapFont->SetAt(strfilename,NULL);
  1059. }
  1060. }
  1061. return 1;
  1062. }
  1063. BOOL CALLBACK AFX_EXPORT CReader::EnumFamScreenCallBackEx(ENUMLOGFONTEX* pelf, 
  1064. NEWTEXTMETRICEX* /*lpntm*/, int FontType, LPVOID lp)
  1065. {
  1066. if (FontType & RASTER_FONTTYPE)
  1067. return 1;
  1068. LOGFONT& lf = pelf->elfLogFont;
  1069. if ((lf.lfCharSet != ANSI_CHARSET) 
  1070. &&(lf.lfCharSet != OEM_CHARSET) 
  1071. &&(lf.lfCharSet != SYMBOL_CHARSET) 
  1072. &&(lf.lfCharSet != GB2312_CHARSET) )
  1073. return 1;
  1074. // CStringArray* strarray;
  1075. // strarray = (CStringArray*)lp;
  1076. // strarray->Add(lf.lfFaceName);
  1077. CString strfilename;
  1078. strfilename=lf.lfFaceName;
  1079. // strfilename.MakeLower();
  1080. CTypedPtrMap<CMapStringToPtr, CString, void*>* pMapFont = 
  1081.   (CTypedPtrMap<CMapStringToPtr, CString, void*>*)lp;
  1082. void *p;
  1083. if(!pMapFont->Lookup(strfilename,p))
  1084. {
  1085. CString strTemp=strfilename;
  1086. strTemp.MakeLower();
  1087. if(strTemp=="symusic"||
  1088.    strTemp=="romand"||
  1089.    strTemp=="romans"||
  1090.    strTemp=="romant"||
  1091.    strTemp=="scriptc"||
  1092.    strTemp=="scripts"||
  1093.    strTemp=="syastro"||
  1094.    strTemp=="symap"||
  1095.    strTemp=="monotxt"||
  1096.    strTemp=="symeteo"||
  1097.    strTemp=="italict"||
  1098.    strTemp=="symath"||
  1099.    strTemp=="gothici"||
  1100.    strTemp=="bigfont"||
  1101.    strTemp=="complex"||
  1102.    strTemp=="romanc"||
  1103.    strTemp=="gothicg"||
  1104.    strTemp=="greekc"||
  1105.    strTemp=="greeks"||
  1106.    strTemp=="isocp"||
  1107.    strTemp=="isocp2"||
  1108.    strTemp=="isocp3"||
  1109.    strTemp=="isoct"||
  1110.    strTemp=="isoct2"||
  1111.    strTemp=="isoct3"||
  1112.    strTemp=="italic"||
  1113.    strTemp=="italicc"||
  1114.    strTemp=="gothice"||
  1115.    strTemp=="gbeitc"||
  1116.    strTemp=="gbcbig"||
  1117.    strTemp=="chineset"||
  1118.    strTemp=="extfont"||
  1119.    strTemp=="whgdtxt"||
  1120.    strTemp=="whgtxt"||
  1121.    strTemp=="whtmtxt"||
  1122.    strTemp=="htgtxt"||
  1123.    strTemp=="gbenor")
  1124. {
  1125. TRACE("同名 采用形文字");
  1126. }
  1127. else
  1128. {
  1129. pMapFont->SetAt(strfilename,NULL);
  1130. }
  1131. }
  1132. return 1;
  1133. }
  1134. void CReader::calculate_findfonts(CTypedPtrMap<CMapStringToPtr, CString, void*>* pMapFont)
  1135. {
  1136. if(!pMapFont)return;
  1137. pMapFont->RemoveAll();
  1138. LOGFONT lf;
  1139. memset(&lf, 0, sizeof(LOGFONT));
  1140. lf.lfCharSet = DEFAULT_CHARSET;
  1141. CDC dcScreen;
  1142. dcScreen.Attach(::GetDC(NULL));
  1143. HDC hDC = dcScreen.m_hDC;
  1144. DWORD dwVersion = ::GetVersion();
  1145. BOOL m_bWin4 = (BYTE)dwVersion >= 4;
  1146. if (m_bWin4)
  1147. {
  1148. ::EnumFontFamiliesEx(hDC, &lf, 
  1149. (FONTENUMPROC) EnumFamScreenCallBackEx, (LPARAM)pMapFont, NULL);
  1150. }
  1151. else
  1152. {
  1153. ::EnumFontFamilies(hDC, NULL, 
  1154. (FONTENUMPROC) EnumFamScreenCallBack, (LPARAM)pMapFont);
  1155. }
  1156. }