www.mxdraw.com
内容索引主面
前一个向上下一个
McDbTextStyleTable 类

数据库的文字样式表

C++
class McDbTextStyleTable : public McDbSymbolTable;

McDbSymbolTable.h

例如:得到所有的文字样式

    void GetAllTextStyle()
    {
        // 读方式打开文字样表
        McDbTextStyleTablePointer spTextStyleTable(acdbCurDwg(),McDb::kForRead);
        if(spTextStyleTable.openStatus() != Mcad::eOk)
            return;

        // 创建一个遍历器,准备遍历块表

        McDbTextStyleTableIterator* pIterator = NULL;
        spTextStyleTable->newIterator(pIterator);

        if(pIterator == NULL)
            return;
        // 把遍历器的指针交给智能指针管理
        std::auto_ptr<McDbTextStyleTableIterator> spIterator(pIterator);

        // 遍历所有记录

        for(;!pIterator->done();pIterator->step())
        {
            McDbObjectId id;
            pIterator->getRecordId(id);

            // 读方式打开记录
            McDbObjectPointer<McDbTextStyleTableRecord> spTextStyleRec(id,McDb::kForRead);
            if(spTextStyleRec.openStatus() != Mcad::eOk)
                continue;
            LPCTSTR pszName = NULL;
            spTextStyleRec->getName(pszName);

            CString sT;
            sT.Format(_T("发现文字样式名:%s"),pszName);
            AfxMessageBox(sT);
        }
    };

例如:添加文字样式

    McDbObjectId AddTextStyle1(MxDraw::MXDRAWOCXHANDLE m_hDrawOcx,
                               LPCTSTR pszName, LPCTSTR pszFileName, 
                               LPCTSTR pszBigFontFileName, DOUBLE dXScale)
    {
        CString sName(pszName);
        if(sName.IsEmpty() )
            return McDbObjectId::kNull;

        CString sFileName(pszFileName);
        if(sFileName.IsEmpty() )
            return McDbObjectId::kNull;

        CString sBigFontFileName(pszBigFontFileName);
        if(sBigFontFileName.IsEmpty() )
            return McDbObjectId::kNull;

        if(dXScale < 0.1)
            dXScale = 1.0;



        {
            McDbTextStyleTableRecordPointer spTextTabRec(sName,
                MxDraw::GetDatabase(m_hDrawOcx),McDb::kForRead);
            if(spTextTabRec.openStatus() == Mcad::eOk)
            {
                // 控件内已经有该名称的文字样式。

                return McDbObjectId::kNull;
            }
        }

        McDbTextStyleTablePointer spTextStyleTable(MxDraw::GetDatabase(m_hDrawOcx),AcDb::kForWrite);
        if(spTextStyleTable.openStatus() != Acad::eOk)
        {
            return McDbObjectId::kNull;
        }

        McDbTextStyleTableRecord* pRecord = new McDbTextStyleTableRecord;
        pRecord->setName(sName);
        pRecord->setFileName(sFileName);
        pRecord->setBigFontFileName(sBigFontFileName);
        pRecord->setXScale(dXScale);

        spTextStyleTable->add(pRecord);

        McDbObjectId recId = pRecord->objectId();
        pRecord->close();

        return recId;
    }

    McDbObjectId  AddTextStyle2(MxDraw::MXDRAWOCXHANDLE m_hDrawOcx,
                                LPCTSTR pszName, LPCTSTR pszTrueTypeFontName,
                                DOUBLE dXScale)
    {
        CString sName(pszName);
        if(sName.IsEmpty() )
            return McDbObjectId::kNull;
        CString sTrueTypeFontName(pszTrueTypeFontName);
        if(sTrueTypeFontName.IsEmpty() )
            return McDbObjectId::kNull;

        if(dXScale < 0.1)
            dXScale = 1.0;
        {
            McDbTextStyleTableRecordPointer spTextTabRec(sName,
                MxDraw::GetDatabase(m_hDrawOcx),McDb::kForRead);
            if(spTextTabRec.openStatus() == Mcad::eOk)
            {
                // 控件内已经有该名称的文字样式。

                return McDbObjectId::kNull;
            }
        }

        McDbTextStyleTablePointer spTextStyleTable(MxDraw::GetDatabase(m_hDrawOcx),AcDb::kForWrite);
        if(spTextStyleTable.openStatus() != Acad::eOk)
        {
            return McDbObjectId::kNull;
        }

        McDbTextStyleTableRecord* pRecord = new McDbTextStyleTableRecord;
        pRecord->setName(sName);
        pRecord->setFont(sTrueTypeFontName, Mdesk::kFalse, 
            Mdesk::kFalse, DEFAULT_CHARSET, DEFAULT_PITCH | FF_SWISS);

        pRecord->setXScale(dXScale);
        spTextStyleTable->add(pRecord);

        McDbObjectId recId = pRecord->objectId();

        pRecord->close();

        return recId;
    }
    // 使用代码
    // 增加一个shx字体样式
    AddTextStyle1 (MxDraw::GetCurOcxHandle(),_T("MyTextStyle"), _T("italicc.shx"), _T("gbcbig.shx"), 0.7);

    // 增加一个TrueType字体样式
    AddTextStyle2 (MxDraw::GetCurOcxHandle(),_T("MyTrueTypeStyle"), _T("黑体"), 0.7);
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!