Converterfile2.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:49k
- // KmgConverter.cpp: implementation of the CKmgConverter class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "FileSwitch.h"
- #include "KmgConverter.h"
- #include "KmLayer.h"
- #include "showdef.h"
- #include "entdef.h"
- #include "KmEntity.h"
- #include "Block.h"
- #include "WordStyle.h"
- #include "DwgReader.h"
- #include "Reader.h"
- #include "UnicodeCharMapWideChar.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- extern CStdioFile g_CensorialFile; //监察转换进度的文件
- extern int g_mode;
- extern CTypedPtrMap<CMapStringToPtr, CString, void*> g_afont;
- extern double calculate_findTTFHightRate(CString strFontName);
- extern CUnicodeCharMapWideChar g_UnicodeCharMapWideChar;
- #define ACADTEXTSPACE 1
- KMOBJECTID CKmgConverter::ConverterEntiey_KmSText(CString strText,double x0,double y0,double z0,PAD_TDATA style,CShape* shape)
- {
- KmText* pText=new KmText;
- // 1.使用文本编辑实体中的方法向文本中添加字符
- // b.构造并以(字符+字样式)初始化字符或字符串(在此讨论转义字符)
- UINT wsID=0;
- CWordStyle ws(WORDS_STANDARD);
- // b1.字体名称wsFontName 采用默认字体,暂不考虑
- if(shape->m_bUseSHX){if(shape->m_strBigFontfilename.IsEmpty())shape->m_strBigFontfilename="bzdft.shx";ws.SetFontName(shape->m_strShapefilename + ';' + shape->m_strBigFontfilename );}
- else{ws.SetFontName( shape->m_strShapefilename);style->height*=calculate_findTTFHightRate(ws.GetFontName());}
- // b2.高wsfHeight
- ws.SetHeight(style->height);
- // b3.宽高比例wsfWFactor
- ws.SetWFactor(style->widthfactor);
- // b4.字间距因子,为字间距与字宽的比例 采用默认间距
- ws.SetPFactor(ACADTEXTSPACE);
- // b5.方向,0,1,2,3分别表示0,90,180,270度
- // b6.字体效果SetEffect
- //if(style->generationflag&AD_TEXT_GEN_BACKWARD)//反向{//ws.SetEffect(WS_EFFECT_YMIRROR,TRUE);}if(style->generationflag&AD_TEXT_GEN_UPSIDEDOWN)//颠倒{//ws.SetEffect(WS_EFFECT_XMIRROR,TRUE);}
- if(style->oblique!=0){ws.SetEffect(WS_EFFECT_ITALIC,TRUE);}
- wsID=pText->AddWordStyle(&ws);
- if(wsID){if(pText->SetCurWSID(wsID)==-1){_WRITE(str="设置字样式失败");}}else{_WRITE(str="设置字样式失败");}
- // c.将字符或字符串添加到文本编辑器中
- if(!ConverterEntiey_KmString(pText,strText,wsID))
- {
- delete pText;
- KMOBJECTID id;
- return id;
- }
- // 2.设置文本的其他属性
- // a.对齐方式
- // switch(style->justification){case AD_TEXT_JUST_LEFT:case AD_TEXT_JUST_CENTER:case AD_TEXT_JUST_RIGHT:case AD_TEXT_JUST_ALIGNED:case AD_TEXT_JUST_MIDDLE:case AD_TEXT_JUST_FIT:break;}
- // switch(style->vertalignment){case AD_TEXT_VALIGN_BASELINE:case AD_TEXT_VALIGN_BOTTOM:case AD_TEXT_VALIGN_MIDDLE:case AD_TEXT_VALIGN_TOP:break;}
- // e.角度SetAngle
- if( (style->generationflag&AD_TEXT_GEN_BACKWARD)&&(style->generationflag&AD_TEXT_GEN_UPSIDEDOWN) ){y0-=1.5*style->height;pText->SetOrient(180+style->rotang*180/PI);}
- else{pText->SetOrient(style->rotang*180/PI);}
- pText->ReadjustText();
- // 3.设置文本的放置点(左上角)
- pText->SetTopLeft(KmPoint(x0,y0));
- return AddObject(pText);
- }
- KMOBJECTID CKmgConverter::ConverterEntiey_KmText(CString strEnter,double x0,double y0,double z0,double angle,double texthight,double widthhight,double spacehight,char flag,double height,double width,CShape* shape,double maxWidth)
- {
- KmText* pText=new KmText;
- // 1.使用文本编辑实体中的方法向文本中添加字符
- // b.构造并以(字符+字样式)初始化字符或字符串(在此讨论转义字符)
- UINT wsID=0;
- CWordStyle ws(WORDS_STANDARD);
- // b1.字体名称wsFontName 采用默认字体,暂不考虑
- if(shape->m_bUseSHX){if(shape->m_strBigFontfilename.IsEmpty())shape->m_strBigFontfilename="bzdft.shx";ws.SetFontName(shape->m_strShapefilename + ';' + shape->m_strBigFontfilename );}
- else{ws.SetFontName( shape->m_strShapefilename);texthight*=calculate_findTTFHightRate(ws.GetFontName());}
- // b2.高wsfHeight
- ws.SetHeight(texthight);
- // b3.宽高比例wsfWFactor =字宽/字高
- ws.SetWFactor(widthhight);
- // b4.字间距因子 =(字宽+字间距)/字宽
- ws.SetPFactor(ACADTEXTSPACE);//认为DWG中字宽+字间距=字高*(DWG宽度比例,适当调整)
- // b5.方向,0,1,2,3分别表示0,90,180,270度
- // b6.字体效果SetEffect
- wsID=pText->AddWordStyle(&ws);
- if(wsID){if(pText->SetCurWSID(wsID)==-1){_WRITE(str="设置字样式失败");}}
- else{_WRITE(str="设置字样式失败");}
- // c.将字符或字符串添加到文本编辑器中
- CUIntArray aWSIDs;
- if(!ConverterEntiey_KmMString(pText,strEnter,wsID,aWSIDs))
- {
- delete pText;
- KMOBJECTID id;
- return id;
- }
- // 2.设置文本的其他属性
- // a.对齐方式
- pText->SetRowAlign(KT_ALIGN_BOTTOM); //列对齐方式
- switch(flag)
- {
- case AD_MTEXT_ATTACH_TOPLEFT:
- pText->SetColAlign(KT_ALIGN_LEFT); //行对齐方式
- break;
- case AD_MTEXT_ATTACH_TOPCENTER:
- pText->SetColAlign(KT_ALIGN_MIDDLE); //行对齐方式
- break;
- case AD_MTEXT_ATTACH_TOPRIGHT:
- pText->SetColAlign(KT_ALIGN_RIGHT); //行对齐方式
- break;
- case AD_MTEXT_ATTACH_MIDDLELEFT:
- pText->SetColAlign(KT_ALIGN_LEFT); //行对齐方式
- break;
- case AD_MTEXT_ATTACH_MIDDLECENTER:
- pText->SetColAlign(KT_ALIGN_MIDDLE); //行对齐方式
- break;
- case AD_MTEXT_ATTACH_MIDDLERIGHT:
- pText->SetColAlign(KT_ALIGN_RIGHT); //行对齐方式
- break;
- case AD_MTEXT_ATTACH_BOTTOMLEFT:
- pText->SetColAlign(KT_ALIGN_LEFT); //行对齐方式
- break;
- case AD_MTEXT_ATTACH_BOTTOMCENTER:
- pText->SetColAlign(KT_ALIGN_MIDDLE); //行对齐方式
- break;
- case AD_MTEXT_ATTACH_BOTTOMRIGHT:
- pText->SetColAlign(KT_ALIGN_RIGHT); //行对齐方式
- break;
- }
- // b.行间距SetLinePitch 单倍行距等
- pText->SetLinePitch(1+spacehight/texthight);
- // e.角度SetAngle
- pText->SetOrient(angle*180/PI);
- // f.矩形和文本之间的关系SetRelevance //采用默认设置
- // g.重新调整文本
- pText->ReadjustText();
- // 3.设置文本的放置点(左上角)
- pText->SetTopLeft(KmPoint(x0,y0));
- if(maxWidth>PRECISION)
- {
- double dAddAutoReturnWidth=1.1;
- CWinApp* pApp=::AfxGetApp();
- if(pApp)
- {
- CString str=pApp->GetProfileString(_T("Dwg2Kmg"),_T("AddAutoReturnWidth"),"1.1");
- dAddAutoReturnWidth=::atof(str);
- if(dAddAutoReturnWidth>100||dAddAutoReturnWidth<0.1)
- {
- dAddAutoReturnWidth=dAddAutoReturnWidth;
- }
- }
- {
- CWordStyle* pWordStyle;
- if(!m_mapFont.IsEmpty())
- {
- for(int i=0;i<((KmText*)pText)->GetWordStyleNum();i++)
- {
- pWordStyle=((KmText*)pText)->GetNoNWordStyle(i);
- if(pWordStyle)
- {
- Calculate_ChangeFont(pWordStyle);
- }
- }
- }
- }
- pText->AutoReturn(maxWidth*dAddAutoReturnWidth);//自动换行,增大宽度百分之四十
- }
- return AddObject(pText);
- }
- KmText* CKmgConverter::ConverterEntiey_KmText(BOOL btol,double x0,double y0,double z0,double texthight,double angle,double width,double space,CShape* shape,CString strEnter)
- {
- KmText* pText=new KmText;
- // 1.使用文本编辑实体中的方法向文本中添加字符
- // b.构造并以(字符+字样式)初始化字符或字符串(在此讨论转义字符)
- UINT wsID=0;
- CWordStyle ws(WORDS_STANDARD);
- // b1.字体名称wsFontName 采用默认字体,暂不考虑
- if(shape->m_bUseSHX){if(shape->m_strBigFontfilename.IsEmpty())shape->m_strBigFontfilename="bzdft.shx";ws.SetFontName(shape->m_strShapefilename + ';' + shape->m_strBigFontfilename );}
- else{ws.SetFontName( shape->m_strShapefilename);texthight*=calculate_findTTFHightRate(ws.GetFontName());}
- // b2.高wsfHeight
- ws.SetHeight(texthight);
- // b3.宽高比例wsfWFactor
- ws.SetWFactor(width);
- // b4.字间距因子 =(字宽+字间距)/字宽
- ws.SetPFactor(space);
- // b5.方向,0,1,2,3分别表示0,90,180,270度
- // b6.字体效果SetEffect
- wsID=pText->AddWordStyle(&ws);
- if(wsID){if(pText->SetCurWSID(wsID)==-1){_WRITE(str="设置字样式失败");}}
- else{_WRITE(str="设置字样式失败");}
- // c.将字符或字符串添加到文本编辑器中
- if(btol)
- {
- if(!ConverterEntiey_KmTString(pText,strEnter,wsID))
- {
- delete pText;
- return NULL;
- }
- }
- else
- {
- CUIntArray aWSIDs;
- if(!ConverterEntiey_KmMString(pText,strEnter,wsID,aWSIDs))
- {
- delete pText;
- return NULL;
- }
- }
- // 2.设置文本的其他属性
- // a.对齐方式
- // b.行间距SetLinePitch 单倍行距等
- pText->SetLinePitch(1.0); //※保证两个形位公差紧密相连接
- // e.角度SetAngle
- pText->SetOrient(angle*180/PI);
- // f.矩形和文本之间的关系SetRelevance //采用默认设置
- // g.重新调整文本
- pText->ReadjustText();
- // 3.设置文本的放置点(左上角)
- pText->SetTopLeft(KmPoint(x0,y0));
- return pText;
- }
- KMOBJECTID CKmgConverter::ConverterEntiey_KmText(BOOL btol,CString strEnter,double x0,double y0,double z0,double texthight,double angle,double width,double space,CShape* shape)
- {
- KmText* pText=ConverterEntiey_KmText(btol,x0,y0,z0,texthight,angle,width,space,shape,strEnter);
- if(pText==NULL)
- {
- KMOBJECTID id;
- return id;
- }
- return AddObject(pText);
- }
- #define ADDCHAR(x,y)
- if(pText&&x>=0&&x<=0x7f&&x!=' ')
- {
- CWordStyle * pws=pText->GetWordStyle(curws);
- if(pws)
- {
- CString strFontName=pws->GetFontName();
- strFontName.MakeLower();
- if(strFontName.Find(".shx")!=-1)
- {
- CWordStyle * pws2=new CWordStyle;
- *pws2=*pws;
- pws2->SetWFactor(pws2->GetWFactor()/CFACTOR);
- UINT ut=pText->AddWordStyle(pws2);
- strNew+=(char)x;aWSIDs.Add(ut);index+=y;
- delete pws2;
- }
- else
- {
- strNew+=(char)x;aWSIDs.Add(curws);index+=y;
- }
- }
- else
- {
- ASSERT(FALSE);
- strNew+=(char)x;aWSIDs.Add(curws);index+=y;
- }
- }
- else
- {
- strNew+=(char)x;aWSIDs.Add(curws);index+=y;
- }
- BOOL CKmgConverter::ConverterEntiey_KmString(KmText* pText,CString strText,UINT baseWS)
- {
- #ifdef _BAOJI_
- calculate_convert_ii(strText);
- #endif
- //单行文字
- // Unicode字符 %%nnn %%% %%c 格式控制符
- // 代码页无关 多字节交换
- //单行文字 是 是 是 是 是(dpc+ou) 否
- CUIntArray aWSIDs;
- CString strNew;
- UINT curws=baseWS;
- for(int index=0;index<strText.GetLength();)
- {
- switch(strText[index])
- {
- case 0x25://'%'
- if((index+2)<strText.GetLength())
- {
- if(strText[index+1]==0x25)//'%'
- {
- switch(strText[index+2])
- {
- //{xlf: 为单行文本增加对%%c %%d %%p %%% 的讨论
- case 'c':
- case 'C':
- case 'd':
- case 'D':
- case 'p':
- case 'P':
- case '%':
- ADDCHAR('%',0);
- ADDCHAR('%',0);
- ADDCHAR(strText[index+2],3);
- goto nextcode;
- break;
- case 0x6F://'o'
- case 0x4f://'O'
- index+=3;
- goto nextcode;
- break;
- case 0x75://'u'
- case 0x55://'U'
- index+=3;
- goto nextcode;
- break;
- //xlf}
- default:
- if(strText[index+2]>=0x30&&strText[index+2]<=0x39)//'0'-'9'
- {
- if((index+3)<strText.GetLength())
- {
- if(strText[index+3]>=0x30&&strText[index+3]<=0x39)
- {
- if((index+4)<strText.GetLength())
- {
- if(strText[index+4]>=0x30&&strText[index+4]<=0x39)
- {
- ADDCHAR((strText[index+2]-0x30)*100+(strText[index+3]-0x30)*10+(strText[index+4]-0x30),5);
- goto nextcode;
- break;
- }
- else
- {
- ADDCHAR((strText[index+2]-0x30)*10+(strText[index+3]-0x30),4);
- goto nextcode;
- break;
- }
- }
- else
- {
- ADDCHAR((strText[index+2]-0x30)*10+(strText[index+3]-0x30),4);
- goto nextcode;
- break;
- }
- }
- else
- {
- ADDCHAR(strText[index+2]-0x30,3);
- goto nextcode;
- break;
- }
- }
- else
- {
- ADDCHAR(strText[index+2]-0x30,3);
- goto nextcode;
- break;
- }
- }
- break;
- }
- }
- }
- ADDCHAR(strText[index],1);
- ADDCHAR('%',0);
- ADDCHAR('%',0);
- goto nextcode;
- break;
- case 0x5c://'\'
- if((index+2)<strText.GetLength())
- {
- if(strText[index+2]==0x2b)//'+'
- {
- if(strText[index+1]==0x6d||strText[index+1]==0x4d)//'m''M'
- {
- if((index+2+5)<strText.GetLength())
- {
- if((strText[index+4]>=0x30&&strText[index+4]<=0x39)//'0'-'9'
- ||(strText[index+4]>=0x61&&strText[index+4]<=0x66)//'A'-'F'
- ||(strText[index+4]>=0x41&&strText[index+4]<=0x46))//'a'-'f'
- if((strText[index+5]>=0x30&&strText[index+5]<=0x39)//'0'-'9'
- ||(strText[index+5]>=0x61&&strText[index+5]<=0x66)//'A'-'F'
- ||(strText[index+5]>=0x41&&strText[index+5]<=0x46))//'a'-'f'
- if((strText[index+6]>=0x30&&strText[index+6]<=0x39)//'0'-'9'
- ||(strText[index+6]>=0x61&&strText[index+6]<=0x66)//'A'-'F'
- ||(strText[index+6]>=0x41&&strText[index+6]<=0x46))//'a'-'f'
- if((strText[index+7]>=0x30&&strText[index+7]<=0x39)//'0'-'9'
- ||(strText[index+7]>=0x61&&strText[index+7]<=0x66)//'A'-'F'
- ||(strText[index+7]>=0x41&&strText[index+7]<=0x46))//'a'-'f'
- {
- char ch;
- if(strText[index+4]>=0x61)
- {
- ch=strText[index+4]-0x61+10;
- }
- else if(strText[index+4]>=0x41)
- {
- ch=strText[index+4]-0x41+10;
- }
- else
- {
- ch=strText[index+4]-0x30;
- }
- if(strText[index+5]>=0x61)
- {
- ADDCHAR(ch*16+strText[index+5]-0x61+10,0);
- }
- else if(strText[index+5]>=0x41)
- {
- ADDCHAR(ch*16+strText[index+5]-0x41+10,0);
- }
- else
- {
- ADDCHAR(ch*16+strText[index+5]-0x30,0);
- }
- if(strText[index+6]>=0x61)
- {
- ch=strText[index+6]-0x61+10;
- }
- else if(strText[index+6]>=0x41)
- {
- ch=strText[index+6]-0x41+10;
- }
- else
- {
- ch=strText[index+6]-0x30;
- }
- if(strText[index+7]>=0x61)
- {
- ADDCHAR(ch*16+strText[index+7]-0x61+10,8);
- }
- else if(strText[index+7]>=0x41)
- {
- ADDCHAR(ch*16+strText[index+7]-0x41+10,8);
- }
- else
- {
- ADDCHAR(ch*16+strText[index+7]-0x30,8);
- }
- goto nextcode;
- break;
- }
- }
- }
- else if(strText[index+1]==0x75||strText[index+1]==0x55)//'u''U'
- {
- if((index+2+4)<strText.GetLength())
- {
- if((strText[index+3]>=0x30&&strText[index+3]<=0x39)//'0'-'9'
- ||(strText[index+3]>=0x61&&strText[index+3]<=0x66)//'A'-'F'
- ||(strText[index+3]>=0x41&&strText[index+3]<=0x46))//'a'-'f'
- if((strText[index+4]>=0x30&&strText[index+4]<=0x39)//'0'-'9'
- ||(strText[index+4]>=0x61&&strText[index+4]<=0x66)//'A'-'F'
- ||(strText[index+4]>=0x41&&strText[index+4]<=0x46))//'a'-'f'
- if((strText[index+5]>=0x30&&strText[index+5]<=0x39)//'0'-'9'
- ||(strText[index+5]>=0x61&&strText[index+5]<=0x66)//'A'-'F'
- ||(strText[index+5]>=0x41&&strText[index+5]<=0x46))//'a'-'f'
- if((strText[index+6]>=0x30&&strText[index+6]<=0x39)//'0'-'9'
- ||(strText[index+6]>=0x61&&strText[index+6]<=0x66)//'A'-'F'
- ||(strText[index+6]>=0x41&&strText[index+6]<=0x46))//'a'-'f'
- {
- unsigned short ch;
- if(strText[index+3]>=0x61)
- {
- ch=strText[index+3]-0x61+10;
- }
- else if(strText[index+3]>=0x41)
- {
- ch=strText[index+3]-0x41+10;
- }
- else
- {
- ch=strText[index+3]-0x30;
- }
- if(strText[index+4]>=0x61)
- {
- ch=ch*16+strText[index+4]-0x61+10;
- }
- else if(strText[index+4]>=0x41)
- {
- ch=ch*16+strText[index+4]-0x41+10;
- }
- else
- {
- ch=ch*16+strText[index+4]-0x30;
- }
- if(strText[index+5]>=0x61)
- {
- ch=ch*16+strText[index+5]-0x61+10;
- }
- else if(strText[index+5]>=0x41)
- {
- ch=ch*16+strText[index+5]-0x41+10;
- }
- else
- {
- ch=ch*16+strText[index+5]-0x30;
- }
- if(strText[index+6]>=0x61)
- {
- ch=ch*16+strText[index+6]-0x61+10;
- }
- else if(strText[index+6]>=0x41)
- {
- ch=ch*16+strText[index+6]-0x41+10;
- }
- else
- {
- ch=ch*16+strText[index+6]-0x30;
- }
- switch(ch)
- {
- case 0x00b0://°
- {
- //CWordStyle ws;
- //ws=*pText->GetWordStyle(curws);
- //if(ws.GetFontName().Find("shx")!=-1)
- {
- ADDCHAR('%',7);
- ADDCHAR('%',0);
- ADDCHAR('d',0);
- goto nextcode;//°
- }
- }
- break;
- case 0x00B1:
- {
- //CWordStyle ws;
- //ws=*pText->GetWordStyle(curws);
- //if(ws.GetFontName().Find("shx")!=-1)
- {
- ADDCHAR('%',7);
- ADDCHAR('%',0);
- ADDCHAR('p',0);
- goto nextcode;//°
- }
- }
- break;
- case 0x2205:
- {
- //CWordStyle ws;
- //ws=*pText->GetWordStyle(curws);
- //if(ws.GetFontName().Find("shx")!=-1)
- {
- ADDCHAR('%',7);
- ADDCHAR('%',0);
- ADDCHAR('c',0);
- goto nextcode;//°
- }
- }
- }
- CString strWide;
- if(g_UnicodeCharMapWideChar.GetWideChar(ch,strWide))
- {
- for(UINT i=0;i<strWide.GetLength();i++)
- {
- if(i==0)
- {
- ADDCHAR(strWide.GetAt(i),7);
- }
- else
- {
- ADDCHAR(strWide.GetAt(i),0);
- }
- }
- goto nextcode;
- }
- short ch2;
- short sReturnValue=adUnicodeToCodePageChar(ch,m_sCodePage,&ch2);//936表示是中文
- if(sReturnValue!=1)
- {
- _WRITE(str="无法进行Unicode转换");
- _ERROR;
-
- {
- BYTE chs[3];
- chs[0]=ch&0xff;
- chs[1]=ch>>8;
- chs[2]=0;
- //WC_NO_BEST_FIT_CHARS Any Unicode characters that do not translate directly to multibyte equivalents will be translated to the default character (see lpDefaultChar parameter). In other words, if translating from Unicode to multibyte and back to Unicode again does not yield the exact same Unicode character, the default character is used.This flag may be used by itself or in combination with the other dwFlag options.
- //WC_COMPOSITECHECK Convert composite characters to precomposed characters.
- //WC_DISCARDNS Discard nonspacing characters during conversion.
- //WC_SEPCHARS Generate separate characters during conversion. This is the default conversion behavior.
- //WC_DEFAULTCHAR Replace exceptions with the default character during conversion.
- UINT nBytesNeeded = ::WideCharToMultiByte(
- GetACP(),
- 0,
- (LPWSTR)chs,
- 1,
- NULL,
- 0,
- 0,
- NULL);
- if (nBytesNeeded != 0)
- {
- BYTE* pDestination=new BYTE[nBytesNeeded+2];
- ::memset(pDestination,0,nBytesNeeded+2);
- nBytesNeeded = ::WideCharToMultiByte(
- GetACP(),
- 0,
- (LPWSTR)chs,
- 1,
- (LPSTR)pDestination,
- nBytesNeeded,
- 0,
- NULL);
- if(nBytesNeeded!=0)
- {
- for(UINT i=0;i<nBytesNeeded;i++)
- {
- if(i==0)
- {
- ADDCHAR(pDestination[i],7);
- }
- else
- {
- ADDCHAR(pDestination[i],0);
- }
- }
- delete pDestination;
- goto nextcode;
- }
- delete pDestination;
- }
- }
-
- ch2=ch;
- }
- short ch3=ch2;
- ch3=ch3>>8;
- ch2=ch2&0x00ff;
- if(ch3!=0)
- {
- if(ch2!=0)
- {
- ADDCHAR(ch3,7);
- ADDCHAR(ch2,0);
- }
- else
- {
- ADDCHAR(ch3,7);
- }
- }
- else
- {
- if(ch2!=0)
- {
- ADDCHAR(ch2,7);
- }
- }
- goto nextcode;
- break;
- }
- }
- }
- }
- }
- break;
- default:
- break;
- }
- if((unsigned char)strText[index]>0x7f)//中文字符
- {
- if((index+1)<strText.GetLength())
- {
- if( (strText[index]==TCHAR(0xa1)&&strText[index+1]==TCHAR(0xe3))||//°
- (strText[index]==TCHAR(0xa1)&&strText[index+1]==TCHAR(0xc0))||//±
- (strText[index]==TCHAR(0xa6)&&strText[index+1]==TCHAR(0xb5)) )//Φ
- {
- //CWordStyle ws;
- //ws=*pText->GetWordStyle(curws);
- //if(ws.GetFontName().Find("shx")!=-1)
- {
- if(strText[index+1]==TCHAR(0xe3))
- {
- ADDCHAR('%',2);
- ADDCHAR('%',0);
- ADDCHAR('d',0);
- goto nextcode;
- }
- if(strText[index+1]==TCHAR(0xc0))
- {
- ADDCHAR('%',2);
- ADDCHAR('%',0);
- ADDCHAR('p',0);
- goto nextcode;
- }
- if(strText[index+1]==TCHAR(0xb5))
- {
- ADDCHAR('%',2);
- ADDCHAR('%',0);
- ADDCHAR('c',0);
- goto nextcode;
- }
- }
- }
- ADDCHAR(strText[index],0);
- ADDCHAR(strText[index+1],2);
- goto nextcode;
- }
- }
- ADDCHAR(strText[index],1);
- nextcode:
- continue;
- }
- if(strNew.GetLength()>0)
- {
- pText->SetNewCString(strNew,&aWSIDs);
- return TRUE;
- }
- return FALSE;
- }
- BOOL CKmgConverter::ConverterEntiey_KmMString(KmText* pText,CString& strText,UINT baseWS,CUIntArray& aWSIDs,BOOL btol,BOOL bdim)
- {
- #ifdef _BAOJI_
- calculate_convert_ii(strText);
- #endif
- //预处理strText为W增加;
- if(strText.Find("\w")!=-1||strText.Find("\W")!=-1)
- {
- CString strTemp;
- for(int p=0;p+1<strText.GetLength();p++)
- {
- if(strText[p]=='\'&&(strText[p+1]=='W'||strText[p+1]=='w'))
- {
- strTemp+=strText[p];
- p++;
- strTemp+=strText[p];
- if(p+1<strText.GetLength())
- {
- BOOL bDot=FALSE;
- if(strText[p+1]=='+'||strText[p+1]=='-'||(strText[p+1]>='0'&&strText[p+1]<='9'))
- {
- p++;
- strTemp+=strText[p];
- }
- else if(strText[p+1]=='.')
- {
- bDot=TRUE;
- p++;
- strTemp+=strText[p];
- }
- else
- {
- continue;
- }
- for(;p+1<strText.GetLength();p++)
- {
- if(strText[p+1]=='.')
- {
- if(bDot)
- {
- strTemp+=';';
- break;
- }
- else
- {
- bDot=TRUE;
- strTemp+=strText[p+1];//p++
- }
- }
- else if(strText[p+1]>='0'&&strText[p+1]<='9')
- {
- strTemp+=strText[p+1];//p++
- }
- else if(strText[p+1]>='x')
- {
- p++;
- strTemp+=';';
- break;
- }
- else if(strText[p+1]==';')
- {
- break;
- }
- else
- {
- strTemp+=';';
- break;
- }
- }
-
- }
- }
- else
- {
- strTemp+=strText[p];
- }
- }
- if(p<strText.GetLength())
- {
- strTemp+=strText[p];
- }
- strText=strTemp;
- }
- aWSIDs.RemoveAll();
- CString strNew;
- UINT curws=baseWS;
- CList<UINT,UINT> lWSIDs;
- for(int index=0;index<strText.GetLength();)
- {
- switch(strText[index])
- {
- case 0x7b:
- if(btol)
- {
- char symbl;
- int index2=index;
- if(calculate_findtolchars(strText,index2,symbl))
- {
- if(symbl==0x6e||symbl==0x4e)
- {
- ADDCHAR(0xa6,0);
- ADDCHAR(0xb5,0);//直径符号
- }
- else
- {
- ADDCHAR(symbl,0);
- }
- index=index2;
- goto nextcode;
- }
- else
- {
- ADDCHAR(0x7b,1);
- goto nextcode;
- }
- }
- else if(bdim==TRUE)
- {
- index++;
- goto nextcode;
- }
- else
- {
- lWSIDs.AddTail(curws);
- index++;
- goto nextcode;
- }
- break;
- case 0x7d://'}'
- if(btol)
- {
- ADDCHAR(0x7d,1);
- goto nextcode;
- }
- else if(bdim)
- {
- index++;
- goto nextcode;
- }
- else
- {
- if(lWSIDs.GetTailPosition()!=NULL)
- {
- curws=lWSIDs.RemoveTail();
- }
- else
- {
- _WRITE(str="多行文字中发现不匹配的}符号");
- }
- index++;
- goto nextcode;
- }
- break;
- case 0x5c://'\'
- if((index+2)<strText.GetLength())
- {
- if(strText[index+2]==0x2b)//'+'
- {
- if(strText[index+1]==0x6d||strText[index+1]==0x4d)//'m''M'
- {
- if((index+2+5)<strText.GetLength())
- {
- if((strText[index+4]>=0x30&&strText[index+4]<=0x39)//'0'-'9'
- ||(strText[index+4]>=0x61&&strText[index+4]<=0x66)//'A'-'F'
- ||(strText[index+4]>=0x41&&strText[index+4]<=0x46))//'a'-'f'
- if((strText[index+5]>=0x30&&strText[index+5]<=0x39)//'0'-'9'
- ||(strText[index+5]>=0x61&&strText[index+5]<=0x66)//'A'-'F'
- ||(strText[index+5]>=0x41&&strText[index+5]<=0x46))//'a'-'f'
- if((strText[index+6]>=0x30&&strText[index+6]<=0x39)//'0'-'9'
- ||(strText[index+6]>=0x61&&strText[index+6]<=0x66)//'A'-'F'
- ||(strText[index+6]>=0x41&&strText[index+6]<=0x46))//'a'-'f'
- if((strText[index+7]>=0x30&&strText[index+7]<=0x39)//'0'-'9'
- ||(strText[index+7]>=0x61&&strText[index+7]<=0x66)//'A'-'F'
- ||(strText[index+7]>=0x41&&strText[index+7]<=0x46))//'a'-'f'
- {
- char ch;
- if(strText[index+4]>=0x61)
- {
- ch=strText[index+4]-0x61+10;
- }
- else if(strText[index+4]>=0x41)
- {
- ch=strText[index+4]-0x41+10;
- }
- else
- {
- ch=strText[index+4]-0x30;
- }
- if(strText[index+5]>=0x61)
- {
- ADDCHAR(ch*16+strText[index+5]-0x61+10,0);
- }
- else if(strText[index+5]>=0x41)
- {
- ADDCHAR(ch*16+strText[index+5]-0x41+10,0);
- }
- else
- {
- ADDCHAR(ch*16+strText[index+5]-0x30,0);
- }
- if(strText[index+6]>=0x61)
- {
- ch=strText[index+6]-0x61+10;
- }
- else if(strText[index+6]>=0x41)
- {
- ch=strText[index+6]-0x41+10;
- }
- else
- {
- ch=strText[index+6]-0x30;
- }
- if(strText[index+7]>=0x61)
- {
- ADDCHAR(ch*16+strText[index+7]-0x61+10,8);
- }
- else if(strText[index+7]>=0x41)
- {
- ADDCHAR(ch*16+strText[index+7]-0x41+10,8);
- }
- else
- {
- ADDCHAR(ch*16+strText[index+7]-0x30,8);
- }
- goto nextcode;
- break;
- }
- }
- }
- else if(strText[index+1]==0x75||strText[index+1]==0x55)//'u''U'
- {
- if((index+2+4)<strText.GetLength())
- {
- if((strText[index+3]>=0x30&&strText[index+3]<=0x39)//'0'-'9'
- ||(strText[index+3]>=0x61&&strText[index+3]<=0x66)//'A'-'F'
- ||(strText[index+3]>=0x41&&strText[index+3]<=0x46))//'a'-'f'
- if((strText[index+4]>=0x30&&strText[index+4]<=0x39)//'0'-'9'
- ||(strText[index+4]>=0x61&&strText[index+4]<=0x66)//'A'-'F'
- ||(strText[index+4]>=0x41&&strText[index+4]<=0x46))//'a'-'f'
- if((strText[index+5]>=0x30&&strText[index+5]<=0x39)//'0'-'9'
- ||(strText[index+5]>=0x61&&strText[index+5]<=0x66)//'A'-'F'
- ||(strText[index+5]>=0x41&&strText[index+5]<=0x46))//'a'-'f'
- if((strText[index+6]>=0x30&&strText[index+6]<=0x39)//'0'-'9'
- ||(strText[index+6]>=0x61&&strText[index+6]<=0x66)//'A'-'F'
- ||(strText[index+6]>=0x41&&strText[index+6]<=0x46))//'a'-'f'
- {
- unsigned short ch;
- if(strText[index+3]>=0x61)
- {
- ch=strText[index+3]-0x61+10;
- }
- else if(strText[index+3]>=0x41)
- {
- ch=strText[index+3]-0x41+10;
- }
- else
- {
- ch=strText[index+3]-0x30;
- }
- if(strText[index+4]>=0x61)
- {
- ch=ch*16+strText[index+4]-0x61+10;
- }
- else if(strText[index+4]>=0x41)
- {
- ch=ch*16+strText[index+4]-0x41+10;
- }
- else
- {
- ch=ch*16+strText[index+4]-0x30;
- }
- if(strText[index+5]>=0x61)
- {
- ch=ch*16+strText[index+5]-0x61+10;
- }
- else if(strText[index+5]>=0x41)
- {
- ch=ch*16+strText[index+5]-0x41+10;
- }
- else
- {
- ch=ch*16+strText[index+5]-0x30;
- }
- if(strText[index+6]>=0x61)
- {
- ch=ch*16+strText[index+6]-0x61+10;
- }
- else if(strText[index+6]>=0x41)
- {
- ch=ch*16+strText[index+6]-0x41+10;
- }
- else
- {
- ch=ch*16+strText[index+6]-0x30;
- }
- switch(ch)
- {
- case 0x00b0://°
- {
- //CWordStyle ws;
- //ws=*pText->GetWordStyle(curws);
- //if(ws.GetFontName().Find("shx")!=-1)
- {
- ADDCHAR('%',7);
- ADDCHAR('%',0);
- ADDCHAR('d',0);
- goto nextcode;//°
- }
- }
- break;
- case 0x00B1:
- {
- //CWordStyle ws;
- //ws=*pText->GetWordStyle(curws);
- //if(ws.GetFontName().Find("shx")!=-1)
- {
- ADDCHAR('%',7);
- ADDCHAR('%',0);
- ADDCHAR('p',0);
- goto nextcode;//°
- }
- }
- break;
- case 0x2205:
- {
- //CWordStyle ws;
- //ws=*pText->GetWordStyle(curws);
- //if(ws.GetFontName().Find("shx")!=-1)
- {
- ADDCHAR('%',7);
- ADDCHAR('%',0);
- ADDCHAR('c',0);
- goto nextcode;//°
- }
- }
- }
- CString strWide;
- if(g_UnicodeCharMapWideChar.GetWideChar(ch,strWide))
- {
- for(UINT i=0;i<strWide.GetLength();i++)
- {
- if(i==0)
- {
- ADDCHAR(strWide.GetAt(i),7);
- }
- else
- {
- ADDCHAR(strWide.GetAt(i),0);
- }
- }
- goto nextcode;
- }
- short ch2;
- short sReturnValue=adUnicodeToCodePageChar(ch,m_sCodePage,&ch2);//936表示是中文
- if(sReturnValue!=1)
- {
- _WRITE(str="无法进行Unicode转换");
- _ERROR;
- {
- BYTE chs[3];
- chs[0]=ch&0xff;
- chs[1]=ch>>8;
- chs[2]=0;
- //WC_NO_BEST_FIT_CHARS Any Unicode characters that do not translate directly to multibyte equivalents will be translated to the default character (see lpDefaultChar parameter). In other words, if translating from Unicode to multibyte and back to Unicode again does not yield the exact same Unicode character, the default character is used.This flag may be used by itself or in combination with the other dwFlag options.
- //WC_COMPOSITECHECK Convert composite characters to precomposed characters.
- //WC_DISCARDNS Discard nonspacing characters during conversion.
- //WC_SEPCHARS Generate separate characters during conversion. This is the default conversion behavior.
- //WC_DEFAULTCHAR Replace exceptions with the default character during conversion.
- UINT nBytesNeeded = ::WideCharToMultiByte(
- GetACP(),
- 0,
- (LPWSTR)chs,
- 1,
- NULL,
- 0,
- 0,
- NULL);
- if (nBytesNeeded != 0)
- {
- BYTE* pDestination=new BYTE[nBytesNeeded+2];
- ::memset(pDestination,0,nBytesNeeded+2);
- nBytesNeeded = ::WideCharToMultiByte(
- GetACP(),
- 0,
- (LPWSTR)chs,
- 1,
- (LPSTR)pDestination,
- nBytesNeeded,
- 0,
- NULL);
- if(nBytesNeeded!=0)
- {
- for(UINT i=0;i<nBytesNeeded;i++)
- {
- if(i==0)
- {
- ADDCHAR(pDestination[i],7);
- }
- else
- {
- ADDCHAR(pDestination[i],0);
- }
- }
- delete pDestination;
- goto nextcode;
- }
- delete pDestination;
- }
- }
- ch2=ch;
- }
- short ch3=ch2;
- ch3=ch3>>8;
- ch2=ch2&0x00ff;
- if(ch3!=0)
- {
- if(ch2!=0)
- {
- ADDCHAR(ch3,7);
- ADDCHAR(ch2,0);
- }
- else
- {
- ADDCHAR(ch3,7);
- }
- }
- else
- {
- if(ch2!=0)
- {
- ADDCHAR(ch2,7);
- }
- }
- goto nextcode;
- break;
- }
- }
- }
- }
- }
- if((index+1)<strText.GetLength())
- {
- switch(strText[index+1])
- {
- case 0x6f://'o'
- case 0x4f://'O'
- case 0x6c://'l'
- case 0x4c://'L'
- index+=2;
- goto nextcode;
- break;
- case 0x7e://'~'
- ADDCHAR(0x20,2);//' '
- goto nextcode;
- break;
- case 0x5c://''
- case 0x7b://'{'
- case 0x7d://'}'
- ADDCHAR(strText[index+1],2);
- goto nextcode;
- break;
- case 0x63://'c'
- case 0x43://'C'
- case 0x66://'f'
- case 0x46://'F'
- case 0x68://'h'
- case 0x48://'H'
- case 0x74://'t'
- case 0x54://'T'
- case 0x71://'q'
- case 0x51://'Q'
- case 0x61://'a'
- case 0x41://'A'
- case 0x77://'w'
- case 0x57://'W'
- case 0x73://'s'
- case 0x53://'S'
- {
- CString strTemp;
- for(int l=index+2;l<strText.GetLength();l++)
- {
- if(strText[l]==0x3b||strText[l]=='\'||l==strText.GetLength()-1)//';'
- {
- if(l==strText.GetLength()-1)
- {
- strTemp+=strText[l];
- }
- if(bdim)
- {
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- }
- switch(strText[index+1])
- {
- case 0x43://'C'
- case 0x63://'C'
- //没有处理颜色变为strTemp
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- break;
- case 0x46://'F'
- case 0x66://'F'
- {
- double temp1;
- double temp2;
- CWordStyle ws;
- ws=*pText->GetWordStyle(curws);
- if(calculate_findfont(strTemp))
- {
- if(strTemp=="??")
- {
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- }
- if(strTemp=="??.shx")
- {
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- }
- ws.SetFontName ( strTemp );
- if((temp1=calculate_findTTFHightRate(ws.GetFontName()))==1.0)
- {
- if((temp2=calculate_findTTFHightRate(strTemp))!=1.0)
- {
- ws.SetHeight(ws.GetHeight()*temp2);
- }
- }
- else
- {
- if((temp2=calculate_findTTFHightRate(strTemp))==1.0)
- {
- ws.SetHeight(ws.GetHeight()/temp1);
- }
- else
- {
- ws.SetHeight(ws.GetHeight()/temp1*temp2);
- }
- }
- if((temp1=calculate_findTTFWidthRate(ws.GetFontName()))==1.0)
- {
- if((temp2=calculate_findTTFWidthRate(strTemp))!=1.0)
- {
- ws.SetWFactor(ws.GetWFactor()*temp2);
- }
- }
- else
- {
- if((temp2=calculate_findTTFWidthRate(strTemp))==1.0)
- {
- ws.SetWFactor(ws.GetWFactor()/temp1);
- }
- else
- {
- ws.SetWFactor(ws.GetWFactor()/temp1*temp2);
- }
- }
- curws=pText->AddWordStyle(&ws);
- }
- }
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- break;
- case 0x41://'A'
- case 0x61://'A'
- //没有对齐方式改变变为strTemp
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- break;
- case 0x48://'H'
- case 0x68://'H'
- {
- CWordStyle ws;
- ws=*pText->GetWordStyle(curws);
- double hight=atof(strTemp);
- if((strText[l-1]==0x78)||(strText[l-1]==0x58))//'X''x'
- {
- ws.SetHeight(hight*ws.GetHeight());
- }
- else
- {
- double temp1;
- if((temp1=calculate_findTTFHightRate(ws.GetFontName()))!=1.0)
- {
- hight*=temp1;
- }
- ws.SetHeight(hight);
- }
- curws=pText->AddWordStyle(&ws);
- }
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- break;
- case 0x54://'T'
- case 0x74://'T'
- {
- double space=atof(strTemp);
- CWordStyle ws;
- ws=*pText->GetWordStyle(curws);
- if(ws.GetHeight()*ws.GetWFactor()!=0)
- {
- ws.SetPFactor(space);
- curws=pText->AddWordStyle(&ws);
- }
- }
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- break;
- case 0x51://'Q'
- case 0x71://'Q'
- {
- double angle=atof(strTemp);
- CWordStyle ws;
- ws=*pText->GetWordStyle(curws);
- ws.SetEffect(WS_EFFECT_ITALIC,TRUE);
- if(angle!=0)
- {
- ws.SetEffect(WS_EFFECT_ITALIC,TRUE);
- }
- else
- {
- ws.SetEffect(WS_EFFECT_ITALIC,FALSE);
- }
- curws=pText->AddWordStyle(&ws);
- }
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- break;
- case 0x57://'W'
- case 0x77://'W'
- {
- double width=atof(strTemp);
- CWordStyle ws;
- ws=*pText->GetWordStyle(curws);
- ws.SetWFactor(width);
- curws=pText->AddWordStyle(&ws);
- }
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- break;
- case 0x53://'S'
- case 0x73://'S'
- {
- if(calculate_findpilechars(strTemp))
- {
- CWordStyle ws;
- ws=*pText->GetWordStyle(curws);
- ws.SetHeight(ws.GetHeight()*2.04081633);
- curws=pText->AddWordStyle(&ws);
- for(int j=0;j<strTemp.GetLength();j++)
- {
- ADDCHAR(strTemp[j],0);
- }
- }
- }
- if(strText[l]=='\')
- index=l;
- else
- index=l+1;
- goto nextcode;
- break;
- }
- break;
- }
- strTemp+=strText[l];
- }
- }
- break;
- case 0x70://'P'
- case 0x50://'p'
- ADDCHAR(0x0d,2);//东方CAD中的回车
- goto nextcode;
- break;
- }
- }
- break;
- case 0x3b://';'
- if(btol)
- {
- //形位公差中忽略;号
- goto nextcode;
- }
- else
- {
- ADDCHAR(strText[index],1);
- goto nextcode;
- }
- break;
- default:
- break;
- }
- if((unsigned char)strText[index]>0x7f)//中文字符
- {
- if((index+1)<strText.GetLength())
- {
- if( (strText[index]==TCHAR(0xa1)&&strText[index+1]==TCHAR(0xe3))||//°
- (strText[index]==TCHAR(0xa1)&&strText[index+1]==TCHAR(0xc0))||//±
- (strText[index]==TCHAR(0xa6)&&strText[index+1]==TCHAR(0xb5)) )//Φ
- {
- //CWordStyle ws;
- //ws=*pText->GetWordStyle(curws);
- //if(ws.GetFontName().Find("shx")!=-1)
- {
- if(strText[index+1]==TCHAR(0xe3))
- {
- ADDCHAR('%',2);
- ADDCHAR('%',0);
- ADDCHAR('d',0);
- goto nextcode;
- }
- if(strText[index+1]==TCHAR(0xc0))
- {
- ADDCHAR('%',2);
- ADDCHAR('%',0);
- ADDCHAR('p',0);
- goto nextcode;
- }
- if(strText[index+1]==TCHAR(0xb5))
- {
- ADDCHAR('%',2);
- ADDCHAR('%',0);
- ADDCHAR('c',0);
- goto nextcode;
- }
- }
- }
- ADDCHAR(strText[index],0);
- ADDCHAR(strText[index+1],2);
- goto nextcode;
- }
- }
- ADDCHAR(strText[index],1);
- nextcode:
- continue;
- }
- if(btol)
- {
- strText=strNew;
- }
- else if(bdim)
- {
- strText=strNew;
- }
- else
- {
- if(strNew.GetLength()>0)
- {
- pText->SetNewCString(strNew,&aWSIDs);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- return TRUE;
- }
- BOOL CKmgConverter::calculate_findfont(CString& strFont)
- {
- if(strFont.GetLength()==0){return FALSE;}
- int firstpos=strFont.Find('|');
- if(firstpos!=-1){strFont=strFont.Left(firstpos);}
- if(strFont.GetLength()==0){return FALSE;}
- firstpos=strFont.Find('.');
- if(firstpos==-1)
- {//还要讨论是否是形文字。
- try
- {
- void* pv = NULL;
- if (g_afont.Lookup(strFont, pv)) // found it
- {
- return TRUE;
- }
- else
- {
- strFont+=".shx";
- return TRUE;
- }
- // CFont fonttext;
- // if(fonttext.CreateFont(1000,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,0,0,0,0,strFont))
- // {
- // return TRUE;
- // }
- // else
- // {
- // strFont+=".shx";
- // return TRUE;
- // }
- }
- catch(...)
- {
- strFont+=".shx";
- return TRUE;
- }
- return TRUE;
- }
- CString strExt=strFont.Right(strFont.GetLength()-1-firstpos);
- strExt.MakeLower();
- if(strExt=="ttf")
- {
- TCHAR szDirName[MAX_PATH];
- if(::GetWindowsDirectory(szDirName,MAX_PATH))
- {
- CString strTemp=strFont;
- CString strDirName=szDirName;
- strTemp=strDirName+"\Fonts\"+strTemp;
- if(CReader::calculate_findfontname(strFont,strTemp,strTemp))
- {
- strFont=strTemp;
- }
- }
- }
- else
- {
- CReader::calculate_DefaultExamineFile(strFont,"fonts");
- }
- return TRUE;
- }
- BOOL CKmgConverter::ConverterEntiey_KmMString(CString& strText)
- {
- CUIntArray aWSIDs;
- return ConverterEntiey_KmMString(NULL,strText,m_pDataManager->GetCurWSID(),aWSIDs,FALSE,TRUE);
- }
- BOOL CKmgConverter::calculate_findpilechars(CString& strText)
- {
- CString strFirst;
- CString strSecond;
- for(int i=0;i<strText.GetLength();i++)
- {
- if((strText[i]=='/')||(strText[i]=='#'))
- {
- //分式fs;B;C;;
- strSecond+="\fs;"+strFirst+';';
- i++;
- for(;i<strText.GetLength();i++)
- {
- strSecond+=strText[i];
- }
- strSecond+=";\;";
- strText.Empty();
- strText=strSecond;
- return TRUE;
- }
- else if(strText[i]=='^')
- {
- //上下标sxA;B;
- strSecond+="\sx"+strFirst+';';
- i++;
- for(;i<strText.GetLength();i++)
- {
- strSecond+=strText[i];
- }
- strSecond+="\;";
- strText.Empty();
- strText=strSecond;
- return TRUE;
- }
- else
- {
- strFirst+=strText[i];
- }
- }
- return FALSE;
- }
- BOOL CKmgConverter::ConverterEntiey_KmTString(KmText* pText,CString strEnter,UINT baseWS)
- {
- #ifdef _BAOJI_
- calculate_convert_ii(strEnter);
- #endif
-
- #ifdef _DEBUG
- TRACE(strEnter);
- for(int s=0;s<strEnter.GetLength();s++)
- {
- CString strrr;
- strrr.Format("%d%cn",strEnter[s],strEnter[s]);
- TRACE(strrr);
- }
- #endif
- CString strNew;
- CUIntArray aWSIDs;
- CUIntArray aWSIDs2;
- UINT curws=baseWS;
- int i;
- CStringArray strArray;
- while((i = strEnter.Find(0x0a)) != -1)
- {
- strArray.Add(strEnter.Left(i));
- strEnter=strEnter.Right(strEnter.GetLength() - i - 1);
- }
- strArray.Add(strEnter);
-
- for(int k = 0; k < strArray.GetSize(); k++)
- {
- curws=baseWS;
- char symbl;
- CString strTemp=strArray[k];
- if(strTemp.GetLength()==0)
- {
- continue;
- }
- if(strTemp[0]!=0x7b)//'{'是高度和基准
- {//按带框字符转换 (注意 即便是带框字符也存在着%%v的问题 故要转换为连续方框)
- int index=0;
- ADDCHAR(0x5c,1);//'\'
- ADDCHAR(0x66,1);//'f'
- ADDCHAR(0x6b,1);//'k'
- ConverterEntiey_KmMString(pText,strTemp,baseWS,aWSIDs2,TRUE);
- for(int l=0;l<strTemp.GetLength();l++)
- {
- if(l<strTemp.GetLength()-2)
- {
- if(strTemp[l]==0x25&&strTemp[l+1]==0x25&&strTemp[l+2]==0x76)//%%v
- {
- ADDCHAR(0x5c,1);//'\'
- ADDCHAR(0x3b,1);//';'
- ADDCHAR(0x5c,1);//'\'
- ADDCHAR(0x66,1);//'f'
- ADDCHAR(0x6b,1);//'k'
- l+=2;
- continue;
- }
- }
- if(aWSIDs2.GetSize()>l)
- {
- curws=aWSIDs2[l];
- ADDCHAR(strTemp[l],1);
- }
- else
- {
- curws=baseWS;
- ADDCHAR(strTemp[l],1);
- }
- }
- ADDCHAR(0x5c,1);//'\'
- ADDCHAR(0x3b,1);//';'
- ADDCHAR(0x0d,1);//东方CAD中的硬回车符号
- continue;//注意该行已经转换完成
- }
- int begin=0;
- if(!calculate_findtolchars(strTemp,begin,symbl))
- {
- int index=0;
- ADDCHAR(0x5c,1);//'\'
- ADDCHAR(0x66,1);//'f'
- ADDCHAR(0x6b,1);//'k'
- ConverterEntiey_KmMString(pText,strTemp,baseWS,aWSIDs2,TRUE);
- for(int l=0;l<strTemp.GetLength();l++)
- {
- if(l<strTemp.GetLength()-2)
- {
- if(strTemp[l]==0x25&&strTemp[l+1]==0x25&&strTemp[l+2]==0x76)//%%v
- {
- ADDCHAR(0x5c,1);//'\'
- ADDCHAR(0x3b,1);//';'
- ADDCHAR(0x5c,1);//'\'
- ADDCHAR(0x66,1);//'f'
- ADDCHAR(0x6b,1);//'k'
- l+=2;
- continue;
- }
- }
- if(aWSIDs2.GetSize()>l)
- {
- curws=aWSIDs2[l];
- ADDCHAR(strTemp[l],1);
- }
- else
- {
- curws=baseWS;
- ADDCHAR(strTemp[l],1);
- }
- }
- ADDCHAR(0x5c,1);//'\'
- ADDCHAR(0x3b,1);//';'
- ADDCHAR(0x0d,1);//东方CAD中的硬回车符号
- continue;//注意该行已经转换完成
- }
- {
- int sqnum=0;
- int index=0;
- ADDCHAR(0x5c,1);//'\'
- ADDCHAR(0x67,1);//'g'
- ADDCHAR(0x63,1);//'c'
- ADDCHAR(symbl,1);
- CString strTemp2;
- for(int l=begin;l<strTemp.GetLength();)
- {
- if(l<strTemp.GetLength()-2)
- {
- if(strTemp[l]==0x25&&strTemp[l+1]==0x25&&strTemp[l+2]==0x76)//%%v
- {
- ConverterEntiey_KmMString(pText,strTemp2,baseWS,aWSIDs2,TRUE);
- for(int m=0;m<strTemp2.GetLength();m++)
- {
- if(aWSIDs2.GetSize()>m)
- {
- curws=aWSIDs2[m];
- ADDCHAR(strTemp2[m],1);
- }
- else
- {
- curws=baseWS;
- ADDCHAR(strTemp2[m],1);
- }
- }
- sqnum++;
- if(sqnum>1&&sqnum<=6)//第一个%%v略过
- {
- ADDCHAR(0x3b,1);//';'
- }
- l+=3;
- strTemp2.Empty();
- continue;
- }
- }
- strTemp2+=strTemp[l];
- l++;
- }
- {
- ConverterEntiey_KmMString(pText,strTemp2,baseWS,aWSIDs2,TRUE);
- for(int m=0;m<strTemp2.GetLength();m++)
- {
- if(aWSIDs2.GetSize()>m)
- {
- curws=aWSIDs2[m];
- ADDCHAR(strTemp2[m],1);
- }
- else
- {
- curws=baseWS;
- ADDCHAR(strTemp2[m],1);
- }
- }
- sqnum++;
- if(sqnum>1&&sqnum<=6)
- {
- ADDCHAR(0x3b,1);//';'
- }
- }
- if(sqnum==0||sqnum==1)
- {
- sqnum=2;
- }
- for(l=sqnum;l<=6;l++)
- {
- strNew+=0x3b;//';'
- }
- ADDCHAR(0x5c,0);
- ADDCHAR(0x3b,0);
- ADDCHAR(0x0d,0);//东方CAD中的硬回车符号
- }
- }
- aWSIDs.RemoveAll();
- aWSIDs.Add(baseWS);
- if(strNew.GetLength()>0)
- {
- pText->SetNewCString(strNew,&aWSIDs);
- return TRUE;
- }
- return FALSE;
- }
- BOOL CKmgConverter::calculate_findtolchars(CString strText,int &i,char &symbl)
- {
- for(int j=i;j<strText.GetLength();j++)
- {
- if(strText[j]==0x7d)//'}'
- {
- symbl=strText[j-1];
- i=j+1;
- symbl=calculate_findtoltype(symbl);
- return TRUE;
- }
- }
- return FALSE;
- }
- char CKmgConverter::calculate_findtoltype(char symbl)
- {
- char symbltemp=symbl; //转换为大写
- if(symbl>=0x61||symbl<=0x7A)//>='a' <='z'
- {
- symbl-=0x20;
- }
- switch(symbl)
- {
- case 'A'://1
- return 'i';
- case 'B'://2
- return 'h';
- case 'C'://3
- return 'b';
- case 'D'://4
- return 'f';
- case 'E'://5
- return 'c';
- case 'F'://6
- return 'g';
- case 'G'://7
- return 'p';
- case 'H'://8
- return 'm';
- case 'I'://9
- return 'k';
- case 'J'://10
- return 'l';
- case 'K'://11
- return 'e';
- case 'R'://12
- return 'j';
- case 'T'://13
- return 'n';
- case 'U'://14
- return 'a';
- default:
- break;
- }
- return symbltemp;
- }