Files
envi-code/SourceCode/Code2026/tg_shs/shs_annotate/TextStyleDlg.cpp
T
2026-09-28 15:28:50 +08:00

896 lines
24 KiB
C++

// TextStyleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "TextStyleDlg.h"
#include "TextStyleNew.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTextStyleDlg dialog
static XStringList lstWinfont;
static DList<int> lstCharset, lstPitch;
CTextStyleDlg::CTextStyleDlg(CWnd* pParent /*=NULL*/)
: CModelessDialog(CTextStyleDlg::IDD, pParent), mPreviewDb(true,true)
{
m_bInitReady=FALSE;
//{{AFX_DATA_INIT(CTextStyleDlg)
m_strTextHeight = _T("3.5");
m_nType = 0;
m_strStyleName = _T("");
m_strBigFont = _T("");
m_strShapes = _T("");
m_strPreText = _T("示例:ShangHua");
m_nHScale = 1.0;
m_nWHScale = 1.0;
m_nWScale = 1.0;
//}}AFX_DATA_INIT
m_bIsRename = FALSE;
m_nTextColor = 0;
AcDbRegAppTable *pTab = NULL;
VERIFY(mPreviewDb.getSymbolTable(pTab, AcDb::kForWrite)==Acad::eOk);
if(!pTab->has(TCHXD)) {
AcDbRegAppTableRecord *pRec=new AcDbRegAppTableRecord();
pRec->setName(TCHXD);
pTab->add(pRec);
pRec->close();
}
pTab->close();
AcDbTextStyleTable *pStyleTab=NULL;
VERIFY(mPreviewDb.getSymbolTable(pStyleTab, AcDb::kForRead)==Acad::eOk);
AcDbTextStyleTableRecord *pRec=NULL;
VERIFY(pStyleTab->getAt(_T("STANDARD"), pRec, AcDb::kForRead)==Acad::eOk);
pStyleTab->close();
AcDbObjectId idStyle=pRec->objectId();
pRec->close();
AcDbBlockTable *pBlockTab=NULL;
VERIFY(mPreviewDb.getSymbolTable(pBlockTab, AcDb::kForRead)==Acad::eOk);
AcDbBlockTableRecord *pMspace=NULL;
VERIFY(pBlockTab->getAt(ACDB_MODEL_SPACE, pMspace, AcDb::kForWrite)==Acad::eOk);
pBlockTab->close();
TDbText *pText=new TDbText;
pText->setDatabaseDefaults(&mPreviewDb);
pText->SetAlignment(XExplodeDraw::kMiddleCenter);
pText->SetHeight(6.0);
pText->SetPScale(1.0);
pText->SetStyleId(idStyle);
pText->SetText(_T("SampleText"));
VERIFY(pMspace->appendAcDbEntity(mIdText, pText)==Acad::eOk);
pText->close();
pMspace->close();
}
CTextStyleDlg::~CTextStyleDlg()
{
}
void CTextStyleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTextStyleDlg)
DDX_Control(pDX, IDC_TEXTCOLOR, m_colorComboBox);
DDX_Control(pDX, IDC_COMBO_STYLENAME, m_comboStyleName);
DDX_Control(pDX, IDC_COMBO_TEXTSTYLE_ENG, m_comboShapes);
DDX_Control(pDX, IDC_COMBO_TEXTSTYLE, m_comboBigFont);
DDX_CBString(pDX, IDC_COMBO_TEXTHEIGHT, m_strTextHeight);
DDX_Radio(pDX, IDC_RADIO_CAD, m_nType);
DDX_Text(pDX, IDC_PREVIEW_TEXT, m_strPreText);
DDX_Text(pDX, IDC_SCALE_HEIGHT, m_nHScale);
DDX_Text(pDX, IDC_SCALE_WH, m_nWHScale);
DDX_Text(pDX, IDC_SCALE_WIDTH, m_nWScale);
//}}AFX_DATA_MAP
if(!m_bInitReady)
return;
if(pDX->m_bSaveAndValidate) { // dlg 2 str
DDX_CBString(pDX, IDC_COMBO_STYLENAME, m_strStyleName);
DDX_CBString(pDX, IDC_COMBO_TEXTSTYLE, m_strBigFont);
DDX_CBString(pDX, IDC_COMBO_TEXTSTYLE_ENG, m_strShapes);
m_nTextColor = m_colorComboBox.GetCurrentItemColorIndex();
} else {
m_comboStyleName.SetCurSel(m_comboStyleName.FindStringExact(0, m_strStyleName));
m_comboShapes.SetCurSel(m_comboShapes.FindStringExact(0, m_strShapes));
m_comboBigFont.SetCurSel(m_comboBigFont.FindStringExact(0, m_strBigFont));
int nItem = m_colorComboBox.FindItemByColorIndex(m_nTextColor);
if(nItem<0) {
m_colorComboBox.AddColorToMRU(m_nTextColor);
nItem = m_colorComboBox.FindItemByColorIndex(m_nTextColor);
}
if(nItem>=0) m_colorComboBox.SetCurSel(nItem);
CWnd *pWnd1 = GetDlgItem(IDC_SCALE_WIDTH);
CWnd *pWnd2 = GetDlgItem(IDC_SCALE_HEIGHT);
CWnd *pWnd3 = GetDlgItem(IDC_COMBO_TEXTSTYLE_ENG);
CWnd *pWnd4 = GetDlgItem(IDC_STATIC_WSCALE);
CWnd *pWnd5 = GetDlgItem(IDC_STATIC_HSCALE);
CWnd *pWnd6 = GetDlgItem(IDC_STATIC_TEXTSTYLE_ENG);
CWnd *pWnd7 = GetDlgItem(IDC_STATIC_ENG);
if(m_strStyleName == _T("STANDARD")) {
// Zyu modify on 100726,去掉编译警告
//(CWnd *)GetDlgItem(IDC_BUTTON_RENAME)->EnableWindow(FALSE);
//(CWnd *)GetDlgItem(IDC_BUTTON_DEL)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_RENAME)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_DEL)->EnableWindow(FALSE);
}
else {
// Zyu modify on 100726,去掉编译警告
//(CWnd *)GetDlgItem(IDC_BUTTON_RENAME)->EnableWindow(TRUE);
//(CWnd *)GetDlgItem(IDC_BUTTON_DEL)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_RENAME)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_DEL)->EnableWindow(TRUE);
}
int len = m_lstStyleOnUsed.Length();
for(int i = 0; i < len; i ++) {
if(m_strStyleName == m_lstStyleOnUsed[i])
// Zyu modify on 100726,去掉编译警告
//(CWnd *)GetDlgItem(IDC_BUTTON_DEL)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_DEL)->EnableWindow(FALSE);
}
if(m_nType == 0) {
pWnd1->EnableWindow(TRUE);
pWnd2->EnableWindow(TRUE);
pWnd3->EnableWindow(TRUE);
pWnd4->EnableWindow(TRUE);
pWnd5->EnableWindow(TRUE);
pWnd6->EnableWindow(TRUE);
pWnd7->EnableWindow(TRUE);
}
else if(m_nType == 1) {
pWnd1->EnableWindow(FALSE);
pWnd2->EnableWindow(FALSE);
pWnd3->EnableWindow(FALSE);
pWnd4->EnableWindow(FALSE);
pWnd5->EnableWindow(FALSE);
pWnd6->EnableWindow(FALSE);
pWnd7->EnableWindow(FALSE);
}
}
}
BEGIN_MESSAGE_MAP(CTextStyleDlg, CModelessDialog)
//{{AFX_MSG_MAP(CTextStyleDlg)
ON_CBN_SELCHANGE(IDC_COMBO_STYLENAME, OnSelchangeComboStylename)
ON_BN_CLICKED(IDC_BUTTON_CREATE, OnButtonCreate)
ON_BN_CLICKED(IDC_BUTTON_RENAME, OnButtonRename)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
ON_BN_CLICKED(IDC_BUTTON_PREVIEW, OnButtonPreview)
ON_CBN_SELCHANGE(IDC_COMBO_TEXTSTYLE, OnSelchangeComboTextstyle)
ON_BN_CLICKED(IDC_RADIO_CAD, UpdateDlg)
ON_BN_CLICKED(IDC_RADIO_WINDOW, UpdateDlg)
ON_CBN_SELCHANGE(IDC_COMBO_TEXTSTYLE_ENG, OnSelchangeComboTextstyleEng)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int CALLBACK EnumFontFamExProc(ENUMLOGFONTEX *lplf, NEWTEXTMETRICEX *lpntme,
int FontType, LONG lParam)
{
if (!(FontType & TRUETYPE_FONTTYPE))
return 1 ;
if (*(lplf->elfLogFont.lfFaceName))
{
if(!_tcsicmp(lplf->elfLogFont.lfFaceName, _T("marlett")))
return 1;
if(lstWinfont.Index(lplf->elfLogFont.lfFaceName, 0) < 0) {// winFont
lstWinfont.Append(tstrnew(lplf->elfLogFont.lfFaceName));
lstCharset.Append(new int(lplf->elfLogFont.lfCharSet));
lstPitch.Append(new int(lplf->elfLogFont.lfPitchAndFamily));
}
}
return 1 ;
}
/////////////////////////////////////////////////////////////////////////////
// CTextStyleDlg message handlers
BOOL CTextStyleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if (!mPreviewCtrl.SubclassDlgItem(IDC_PREVIEW,this))
return FALSE;
XString sTextStyle;
xg_getvar(_T("TEXTSTYLE"), sTextStyle);
m_strStyleName = (const TCHAR *)sTextStyle;
LoadFontList(); // AutoCAD and Windows 字体的导入
LoadFontStyleList(); // 读字体样式名称
LoadStyleOnUsed(); // 判断有哪些文字样式已被使用
m_bInitReady=TRUE;
Obj2Dlg();
UpdateData(false);
UpdatePreview();
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CTextStyleDlg::AddNewFontStyle(CString strNewStyle) // 新建文字样式
{
AcDbDatabase *pCurDwg=acdbCurDwg();
AcDbTextStyleTable* pTT = NULL;
VERIFY(pCurDwg->getSymbolTable(pTT, AcDb::kForWrite) == Acad::eOk);
AcDbTextStyleTableRecord* pTTR = new AcDbTextStyleTableRecord;
if(pTTR->setName(strNewStyle) != Acad::eOk) {
AfxMessageBox(_T("文字样式名称不合法!请重新输入。"));
delete pTTR;
pTT->close();
return FALSE;
}
if(!WriteRecord(pTTR)) {
delete pTTR;
pTT->close();
return FALSE;
}
if(pTT->add(pTTR) != Acad::eOk ) {
pTT->close();
delete pTTR;
return FALSE;
}
pTT->close();
pTTR->close();
return TRUE;
}
void CTextStyleDlg::RenameFontStyle(CString strOld, CString strNew)
{
AcDbObjectId idTextStyle=GetTextStyleId(strOld);
if(!idTextStyle)
return;
OPENOBJ_BEGIN(idTextStyle, AcDb::kForWrite, AcDbTextStyleTableRecord, pRec);
pRec->setName(strNew);
OPENOBJ_END();
}
void CTextStyleDlg::LoadFontStyleList()
{
AcDbDatabase *pCurDwg = acdbCurDwg();
AcDbTextStyleTable* pTT = NULL;
if (pCurDwg->getSymbolTable(pTT, AcDb::kForRead) != Acad::eOk)
return;
AcDbTextStyleTableIterator* pIter = NULL;
if (pTT->newIterator(pIter) != Acad::eOk)
return;
pTT->close();
for (pIter->start(); !pIter->done(); pIter->step())
{
AcDbTextStyleTableRecord* pTTR;
if (pIter->getRecord(pTTR, AcDb::kForRead) != Acad::eOk)
continue;
const TCHAR* pName = NULL;
if (pTTR->getName(pName) == Acad::eOk && pName != NULL)
{
if(m_lstStyle.Index(pName, 0) < 0 ) // 如果没有重复
m_lstStyle.Append(tstrnew(pName)); // 读字体风格
}
pTTR->close();
}
delete pIter;
ResetCombo(); // 读符号表字体风格 后 立即更新ComboBox
return;
}
void CTextStyleDlg::LoadStyleOnUsed() // 判断有哪些文字样式已被使用 -> m_lstStyleOnUsed
{
m_lstStyleOnUsed.Reset();
AcDbObjectId idTextStyle;
AcDbObjectIdArray objIds;
int len = m_lstStyle.Length();
for(int i = 0; i < len; i ++) {
idTextStyle = GetTextStyleId(m_lstStyle[i]);
if(!idTextStyle)
return;
if (objIds.contains(idTextStyle) == Adesk::kFalse)
objIds.append(idTextStyle);
}
Adesk::UInt32* count = new Adesk::UInt32[len];
for (int j = 0; j < len; j ++)
count[j] = 0; // init count values;
AcDbDatabase *pCurDwg = acdbCurDwg();
Acad::ErrorStatus es = pCurDwg->countHardReferences(objIds, count);
if (es != Acad::eOk) {
delete [] count;
return;
}
for (int m = 0; m < len; m ++) {
if(count[m] > 0) {
if(m_lstStyleOnUsed.Index(m_lstStyle[m], 0) < 0 ) // 如果没有重复
m_lstStyleOnUsed.Append(tstrnew(m_lstStyle[m])); // 读字体风格
}
}
delete [] count;
}
//add by wlw on 20160907,利用基类GetSearchPath函数得到的字符串可能会越界,造成崩溃
void CTextStyleDlg::GetSearchPathEx(TCStringList &lstSearchPath)
{
TCString sAcadPath;
if (ads_findfile(_T("acad.exe"), sAcadPath) != RTNORM)
{
return;
}
TCHAR drive[_MAX_DRIVE] = _T(""), dir[_MAX_DIR] = _T(""), file[_MAX_FNAME], ext[_MAX_EXT];
_tsplitpath(sAcadPath, drive, dir, file, ext);
TCString sDwgPrefix(2048), sAcadPrefix(2048);
TchExport::TGGetVar(_T("DWGPREFIX"), sDwgPrefix);
TchExport::TGGetVar(_T("ACADPREFIX"), sAcadPrefix);
lstSearchPath.Append(tstrnew(sDwgPrefix));
lstSearchPath.Append(tstrnew(TCString(_T("%s%s"),drive, dir)));
TCHAR *pBeg = sAcadPrefix, *pEnd = NULL;
do
{
TCString sPath(2048);
pEnd = _tcschr(pBeg, _T(';'));
StrCpy(sPath, pBeg, pEnd);
if (AsStdPath(sPath))
{
lstSearchPath.Append(tstrnew(sPath));
}
if (pEnd)
{
pBeg = pEnd+1;
}
} while(pEnd);
}
void CTextStyleDlg::LoadFontList() // AutoCAD and Windows 字体的导入
{
lstWinfont.Reset();
lstCharset.Reset();
lstPitch.Reset();;
CDC *pDC=m_comboBigFont.GetDC();
ASSERT(pDC);
//HDC hDC;
//hDC = ::GetDC(this->m_hWnd); //读Windows字体
LOGFONT lf;
ZeroMemory(&lf,sizeof(lf));
lf.lfCharSet = DEFAULT_CHARSET;
EnumFontFamiliesEx(pDC->m_hDC, &lf,
(FONTENUMPROC)EnumFontFamExProc, NULL, 0);
m_comboBigFont.ReleaseDC(pDC);
XStringList lstSearchPath;
GetSearchPathEx(lstSearchPath);
for(int i=0; i<lstSearchPath.Length(); i++)
{
XString sFilter(256);
sFilter << lstSearchPath[i] << _T("*.SHX");
XStringList lstFilesFound;
struct _tfinddata_t fb;
intptr_t hand;
// Zyu modif y on 100726,强制转换,去除编译警告
//hand=_tfindfirst(sFilter,&fb);
hand = _tfindfirst(sFilter,&fb);
if(hand==-1L) continue;
lstFilesFound.Append(_tcsupr(tstrnew(fb.name)));
while (!_tfindnext(hand,&fb))
{
lstFilesFound.Append(_tcsupr(tstrnew(fb.name)));
}
_findclose(hand);
for(int n = 0; n < lstFilesFound.Length(); n++)
{
XString sFontFile(256);
sFontFile << lstSearchPath[i] << lstFilesFound[n];
#if (ADS>15)
std::
#endif
ifstream in(sFontFile, _ios::binary);
if(!in) continue;
char sBuf[17];
in.read(sBuf, 16);
sBuf[16]=0;
// Zyu modify on 100726,去掉编译警告
//if(stricmp(&sBuf[11], "shape")==0 || stricmp(&sBuf[11], "unifo")==0)
if(_stricmp(&sBuf[11], "shape")==0 || _stricmp(&sBuf[11], "unifo")==0)
{
if(m_lstShapes.Index(lstFilesFound[n], 0)<0) // english font
m_lstShapes.Append(tstrnew(lstFilesFound[n]));
}
// Zyu modify on 100726,去掉编译警告
//else if(stricmp(&sBuf[11], "bigfo")==0)
else if(_stricmp(&sBuf[11], "bigfo")==0)
{
if(m_lstBigfonts.Index(lstFilesFound[n], 0)<0) // bigfont
m_lstBigfonts.Append(tstrnew(lstFilesFound[n]));
}
}
}
for(i = 0; i < m_lstBigfonts.Length(); i++)
{
TCHAR *p = _tcschr(m_lstBigfonts[i], _T('.'));
if(p) *p = 0;
}
for(i = 0; i < m_lstShapes.Length(); i++)
{
TCHAR *p = _tcschr(m_lstShapes[i], _T('.'));
if(p) *p = 0;
}
m_lstBigfonts.QuickSort(_tcscmp);
m_lstShapes.QuickSort(_tcscmp);
}
void CTextStyleDlg::UpdateDlg()
{
UpdateData(TRUE);
ResetCombo();
if(m_nType == 1)
m_strBigFont = _T("宋体");
UpdateData(FALSE);
UpdatePreview();
}
void CTextStyleDlg::OnSelchangeComboStylename()
{
CString strTextStyle = m_strStyleName;
if(!Check()) {
if(MessageBox(_T("参数已修改,是否保存?"),_T("提示"),MB_OKCANCEL|MB_ICONQUESTION) == IDOK)
Dlg2Obj(strTextStyle);
}
Obj2Dlg();
UpdatePreview();
}
void CTextStyleDlg::ResetCombo()
{
m_comboStyleName.ResetContent();
if(m_nType == 0 && !m_bIsRename) {
m_comboBigFont.ResetContent();
m_comboShapes.ResetContent();
for (int j =0; j < m_lstBigfonts.Length(); j++)
m_comboBigFont.AddString(m_lstBigfonts[j]);
for (int i =0; i < m_lstShapes.Length(); i++)
m_comboShapes.AddString(m_lstShapes[i]);
}
else if(m_nType == 1 && !m_bIsRename) {
m_comboBigFont.ResetContent();
for (int n =0; n < lstWinfont.Length(); n++)
m_comboBigFont.AddString(lstWinfont[n]);
//m_strBigFont = _T("宋体");
}
for (int m =0; m < m_lstStyle.Length(); m++)
m_comboStyleName.AddString(m_lstStyle[m]);
UpdateData(false);
}
void CTextStyleDlg::OnButtonCreate()
{
// ZJQ add this 2 lines, 修正连续创建时未正确设置字体的错误
UpdateData(TRUE);
if(!Dlg2Obj(m_strStyleName))
return;
CTextStyleNew dlg(this);
dlg.m_bIsNew = TRUE;
{
CTemporaryResourceOverride vTemp;
if(dlg.DoModal() != IDOK)
return;
}
UpdateData(TRUE);
if(m_strStyleName == _T("STANDARD")) {
// Zyu modify on 100726,去掉编译警告
//(CWnd *)GetDlgItem(IDC_BUTTON_RENAME)->EnableWindow(TRUE);
//(CWnd *)GetDlgItem(IDC_BUTTON_DEL)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_RENAME)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_DEL)->EnableWindow(TRUE);
}
if(AddNewFontStyle(dlg.m_strNewStyleName)) {
m_strStyleName = dlg.m_strNewStyleName;
LoadFontStyleList();
}
Obj2Dlg();
UpdateData(false);
}
void CTextStyleDlg::OnButtonRename()
{
UpdateData(TRUE);
m_bIsRename = TRUE;
CTextStyleNew dlg(this);
dlg.m_bIsNew = FALSE;
dlg.m_strNewStyleName = m_strStyleName;
{
CTemporaryResourceOverride vTemp;
if(dlg.DoModal() != IDOK) {
m_bIsRename = FALSE;
return;
}
}
AcDbObjectId idTextStyle = GetTextStyleId(m_strStyleName);
if(!idTextStyle) {
m_bIsRename = FALSE;
return;
}
OPENOBJ_BEGIN(idTextStyle, AcDb::kForWrite, AcDbTextStyleTableRecord, pRec);
if(pRec->setName(dlg.m_strNewStyleName) != Acad::eOk) {
AfxMessageBox(_T("文字样式名称不合法!请重新输入。"));
m_bIsRename = FALSE;
return;
}
if(!WriteRecord(pRec)) {
m_bIsRename = FALSE;
return;
}
OPENOBJ_END();
int n = m_lstStyleOnUsed.Index(m_strStyleName, 0);
if(n > -1) {
m_lstStyleOnUsed.Remove(n);
m_lstStyleOnUsed.Append(tstrnew(dlg.m_strNewStyleName));
}
m_strStyleName = dlg.m_strNewStyleName;
m_lstStyle.Reset();
LoadFontStyleList();
m_bIsRename = FALSE;
UpdateData(false);
}
void CTextStyleDlg::OnButtonDel()
{
UpdateData(true);
if(m_strStyleName == _T("STANDARD")) return;
AcDbObjectId idTextStyle = GetTextStyleId(m_strStyleName);
if(!idTextStyle)
return;
if(MessageBox(_T("您是否真的删除此样式?"),_T("警告"),MB_OKCANCEL|MB_ICONQUESTION) != IDOK)
return;
AcDbObject* pObj=NULL;
acdbOpenAcDbObject(pObj, idTextStyle, AcDb::kForWrite);
if(pObj!=NULL)
{
pObj->erase(Adesk::kTrue);
pObj->close();
}
m_strStyleName = _T("STANDARD");
m_lstStyle.Reset();
UpdateData(false);
LoadFontStyleList();
Obj2Dlg();
}
void CTextStyleDlg::Obj2Dlg()
{
GetFontInfo(m_strBigFont, m_strShapes, m_nWHScale, m_strTextHeight, m_nHScale,
m_nWScale, m_nType, m_nTextColor);
ResetCombo();
//wlw add 121018 四舍五入
CString stmp;
stmp.Format(_T("%.3f"), m_nWHScale);
m_nWHScale = _tstof(stmp);
UpdateData(false);
}
void ConvertFontFileName(CString& strFileName)
{
int i = strFileName.GetLength();
strFileName = (const TCHAR *)XPathParser(strFileName).m_sFileName;
strFileName.MakeUpper();
}
void CTextStyleDlg::GetFontInfo(CString& strFontName, CString& strShapes,
double& nWHScale, CString& strTextHeight,
double& nHeightFactor, double& nWidthFactor,
int& nFontType, Adesk::UInt16& nTextColor)
{
nHeightFactor = 1.0;
nWidthFactor = 1.0;
AcDbObjectId idTextStyle = GetTextStyleId(m_strStyleName);
if(!idTextStyle)
return;
OPENOBJ_BEGIN(idTextStyle, AcDb::kForRead, AcDbTextStyleTableRecord, pRec);
strTextHeight.Format(_T("%.1f"), pRec->textSize()); // 字高
nWHScale = pRec->xScale(); // 宽高比
const TCHAR* pShxName = NULL;
TCHAR* pfileName = NULL;
Adesk::Boolean bold, italic; int i, j;
#if ADS < 21
pRec->font(pfileName, bold ,italic, i, j);
#else
Autodesk::AutoCAD::PAL::FontUtils::FontPitch pitch;
Autodesk::AutoCAD::PAL::FontUtils::FontFamily family;
Charset charset;
pRec->font(pfileName, bold, italic, charset, pitch, family);
#endif
if(pfileName && _tcscmp(pfileName,_T("")) != 0) { // Windows 字体
nFontType = 1;
m_strShapes = _T("");
strFontName = pfileName;
}
else { // Auto CAD 字体
pRec->fileName(pShxName);
strShapes = pShxName;
nFontType = 0;
const TCHAR* pbigFontFileName = NULL;
pRec->bigFontFileName(pbigFontFileName);
if(pbigFontFileName)
strFontName = pbigFontFileName;
else
strFontName = _T("");
resbuf *pxData = pRec->xData(TCHXD); // 读扩展数据
if(pxData) {
resbuf *pNext = pxData->rbnext;
if(pNext && pNext->restype == 1040) {
nHeightFactor = pNext->resval.rreal;
pNext = pNext->rbnext;
if(pNext && pNext->restype == 1040)
nWidthFactor = pNext->resval.rreal;
pNext = pNext->rbnext;
if(pNext && pNext->restype == 1070)
nTextColor = pNext->resval.rint;
else
nTextColor = 0;
}
ads_relrb(pxData);
}
ConvertFontFileName(strFontName);
ConvertFontFileName(strShapes);
}
if(pfileName) delete [] pfileName;
OPENOBJ_END();
}
BOOL CTextStyleDlg::WriteRecord(AcDbTextStyleTableRecord* pRec)
{
pRec->setTextSize(_tstof(m_strTextHeight));
pRec->setXScale(m_nWHScale);
if(m_nType == 0) {
if(m_strShapes == _T("")) {
AfxMessageBox(_T("必须选一种字体!请重新输入。"));
return FALSE;
}
#if ADS < 21
pRec->setFont(NULL, 0,0,0,0);
#else
Autodesk::AutoCAD::PAL::FontUtils::FontPitch pitch;
Autodesk::AutoCAD::PAL::FontUtils::FontFamily family;
Charset charset;
pRec->setFont(NULL, Adesk::kFalse, Adesk::kFalse, charset, pitch, family);
#endif
ASSERT(!m_strShapes.IsEmpty());
if(m_strShapes != _T(""))
pRec->setFileName(m_strShapes);
if(m_strBigFont != _T(""))
pRec->setBigFontFileName(m_strBigFont);
else
pRec->setBigFontFileName(NULL);
// 扩展数据
resbuf *pXData = ads_buildlist(1001, TCHXD, 1040, m_nHScale, 1040, m_nWScale, 1070, m_nTextColor, NULL);
if(!XSymbolTable(_T("APPID"), TCHXD))
ads_regapp(TCHXD);
pRec->setXData(pXData);
ads_relrb(pXData);
}
else if(m_nType == 1) {
if(m_strBigFont == _T("")) {
AfxMessageBox(_T("必须选一种字体!请重新输入。"));
return FALSE;
}
int Index = lstWinfont.Index(m_strBigFont, 0);
if(Index < 0) {
AfxMessageBox(_T("没有此字体文件!"));
return FALSE;
}
pRec->setBigFontFileName(NULL);
#if ADS < 21
if(pRec->setFont(m_strBigFont, FALSE, FALSE, *lstCharset[Index], *lstPitch[Index]) != Acad::eOk)
#else
byte pf(*lstPitch[Index]);
typedef Autodesk::AutoCAD::PAL::FontUtils::FontPitch FontPitch;
typedef Autodesk::AutoCAD::PAL::FontUtils::FontFamily FontFamily;
FontPitch pitch((FontPitch)(pf & 0x3));
FontFamily family((FontFamily)(pf & 0xF0));
if(pRec->setFont(m_strBigFont, Adesk::kFalse, Adesk::kFalse, (Charset)(*lstCharset[Index]), pitch, family) != Acad::eOk)
#endif
return FALSE;
}
return TRUE;
}
BOOL CTextStyleDlg::Dlg2Obj(CString strTextStyle)
{
AcDbObjectId idTextStyle = GetTextStyleId(strTextStyle);
if(!idTextStyle)
return FALSE;
OPENOBJ_BEGIN(idTextStyle, AcDb::kForWrite, AcDbTextStyleTableRecord, pRec);
if(!pRec)
return FALSE;
if(pRec->setName(strTextStyle) != Acad::eOk) {
AfxMessageBox(_T("文字样式名称不合法!请重新输入。"));
return FALSE;
}
if(!WriteRecord(pRec)) {
return FALSE;
}
OPENOBJ_END();
return TRUE;
}
void CTextStyleDlg::OnCancel()
{
lstWinfont.Reset();
lstCharset.Reset();
lstPitch.Reset();
CDialog::OnCancel();
}
void CTextStyleDlg::OnOK()
{
UpdateData(TRUE);
if(!Dlg2Obj(m_strStyleName))
return;
XString sTextStyle = m_strStyleName;
xg_setvar(_T("TEXTSTYLE"), sTextStyle);
PickSet ss(SS_FREE);
if(ss.Get(_T("X"), NULL, NULL, RBList(RTDXF0, _T("ATS_TEXT,ATS_MTEXT"), NULL)) == RTNORM)
UpdateGraphic(ss);
lstWinfont.Reset();
lstCharset.Reset();
lstPitch.Reset();
CDialog::OnOK();
}
BOOL CTextStyleDlg::Check()
{
CString strFontName, strShapes, strTextHeight;
CString strShapesDlg, strTextHeightDlg, strFontNameDlg;
double nWHScale, nHScale, nWScale;
int nType;
Adesk::UInt16 nTextColor = 0;
GetFontInfo(strFontName, strShapes, nWHScale, strTextHeight, nHScale,
nWScale, nType, nTextColor);
UpdateData(TRUE);
if(fabs(nWHScale - m_nWHScale) > 1.0E-5) return FALSE;
if(fabs(nHScale - m_nHScale) > 1.0E-5) return FALSE;
if(fabs(nWScale - m_nWScale) > 1.0E-5) return FALSE;
if(m_nTextColor != nTextColor) return FALSE;
if(m_strTextHeight != strTextHeight) return FALSE;
if(m_comboBigFont.GetCurSel()>=0)
m_comboBigFont.GetLBText(m_comboBigFont.GetCurSel(), strFontNameDlg);
if(strFontNameDlg != strFontName) return FALSE;
if(nType == 0) {
if(m_comboShapes.GetCurSel()>=0)
m_comboShapes.GetLBText(m_comboShapes.GetCurSel(), strShapesDlg);
if(strShapesDlg != strShapes) return FALSE;
}
return TRUE;
}
void CTextStyleDlg::OnButtonPreview()
{
UpdateData(TRUE);
UpdatePreview();
}
void CTextStyleDlg::UpdatePreview()
{
OPENOBJ_BEGIN(mIdText, AcDb::kForWrite, TDbText, pText);
ASSERT(pText);
pText->SetText(m_strPreText);
pText->setColorIndex(m_nTextColor);
AcDbObjectId idStyle=pText->GetStyleId();
OPENOBJ_BEGIN(idStyle, AcDb::kForWrite, AcDbTextStyleTableRecord, pRec);
ASSERT(pRec);
WriteRecord(pRec);
OPENOBJ_END();
OPENOBJ_END();
mPreviewCtrl.clearAll();
mPreviewCtrl.init(true);
{
AcGePoint3d target(0.0,0.0,0.0);
AcGePoint3d position(target);
position.z = 1;
AcGsView* pView = mPreviewCtrl.view();
pView->setView(position, target,
AcGeVector3d(0.0, 1.0, 0.0), // upvector
20.0, 9.0);
OPENOBJ_BEGIN(mIdText, AcDb::kForRead, AcDbEntity, pEnt);
AcDbObjectId idMSpace=pEnt->ownerId();
OPENOBJ_BEGIN(idMSpace, AcDb::kForRead, AcDbBlockTableRecord, pMspace);
ASSERT(pMspace);
mPreviewCtrl.view()->add(pMspace,mPreviewCtrl.model());
OPENOBJ_END();
OPENOBJ_END();
}
mPreviewCtrl.Invalidate();
}
BOOL CTextStyleDlg::DestroyWindow()
{
mPreviewCtrl.clearAll();
return CDialog::DestroyWindow();
}
void CTextStyleDlg::OnSelchangeComboTextstyle()
{
UpdateData(TRUE);
// TODO: Add your control notification handler code here
UpdatePreview();
}
void CTextStyleDlg::OnSelchangeComboTextstyleEng()
{
UpdateData(TRUE);
// TODO: Add your control notification handler code here
UpdatePreview();
}