⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtextdlg.cpp

📁 mtext,编辑器,支持潜入对象
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				//insert a space between the text and the formatting.
				format = " \\H";
				else
				format = "\\H";
				}
				else
				format = "\\H";
				* /
				// DP: next line inserted instead above statement
				format = "\\H";
				format.Insert(format.GetLength(), height);
				format.Insert(format.GetLength(), ";");
				m_text.Insert(textindex, format);
				textindex += format.GetLength();
			}
			
			if (underline != oldunderline)
			{
				if (underline == 0)
					m_text.Insert(textindex, "\\l");
				else
					m_text.Insert(textindex, "\\L");
				textindex += 2;
			}
			
			//the index counter does not pick up the change in formatting until a space after it is
			//necessary.  Textindex must start at 0, however, to properly insert the preliminary
			//formatting information.
			if (index != 0)
				textindex++;
			index++;
			oldfonttype = fonttype;
			oldbold = bold;
			olditalic = italic;
			oldunderline = underline;
			oldfontsize = fontsize;
		}
			
		// checking for strings with formatting information but no text, and clearing the string.
		index = m_text.Find("\\f");
		int length = m_text.GetLength();
		if (index == 0)
		{
			index = m_text.Find(";");
			if (index != -1)
			{
				int nextindex = m_text.Find("\\H", index);
				if (nextindex - 1 == index)
				{
					index = m_text.Find(";", nextindex);
					if (index != -1)
					{
						nextindex = m_text.Find("\\L");
						if (nextindex - 1 == index)
						{
							index = nextindex + 2;
							if (index >= length)
								m_text.Delete(0, length);
						}
						else
						{
							index++;
							if (index >= length)
								m_text.Delete(0, length);
						}
					}
				}
				else
				{
					nextindex = m_text.Find("\\L");
					if (nextindex - 1 == index)
					{
						index = nextindex + 2;
						if (index >= length)
							m_text.Delete(0, length);
					}
					else
					{
						index++;
						if (index >= length)
							m_text.Delete(0, length);
					}
				}
			}
		}
		else
		{
			int nextindex = m_text.Find("\\H");
			if (nextindex - 1 == index)
			{
				index = m_text.Find(";");
				if (index != -1)
				{
					nextindex = m_text.Find("\\L");
					if (nextindex - 1 == index)
					{
						index = nextindex + 2;
						if (index >= length)
							m_text.Delete(0, length);
					}
					else
					{
						index++;
						if (index >= length)
							m_text.Delete(0, length);
					}
				}
			}
			else
			{
				nextindex = m_text.Find("\\L");
				if (nextindex - 1 == index)
				{
					index = nextindex + 2;
					if (index >= length)
						m_text.Delete(0, length);
				}
				else
				{
					index++;
					if (index >= length)
						m_text.Delete(0, length);
				}
			}
		}
		// Bugzilla No. 78394; 09-12-2002 [
		/ *if(m_propertiesTab.m_hWnd)
		{
			m_propertiesTab.m_cwidth.GetWindowText(text);
			if (text == "(no wrap)")
			{
				//Modified Cybage AW 12-05-01
				//Reason : "no wrap" option in width edit box was not retained.
				//m_width = -1.0;
				m_pMTextData->rBoxWidth = 0.0;
			}
			else
				m_pMTextData->rBoxWidth = atof(text);
		}
	
		m_text.Replace("\r","\\P");
		m_text.Replace("\n","");
		
		m_pMTextData->rRotAngle = atof(m_propertiesTab.m_rotation);
		m_pMTextData->nAlignment = m_propertiesTab.m_justification + 1;
		strncpy(m_pMTextData->szTextStyle, m_propertiesTab.m_style.GetBuffer(0), 512);
		m_pMTextData->text = m_text;* /
		// Bugzilla No. 78394; 09-12-2002 ]*/

}

BOOL CMTextDlg::needCreation()
{
return TRUE;//strcmp(m_pParentWnd->GetRuntimeClass()->m_lpszClassName, "CDialog");
}

BOOL CMTextDlg::Init(SDS_mTextData *dataPtr)
{
	m_iTextAlign=dataPtr->nAlignment;
	m_iLineSpaceStyle=dataPtr->nLineSpaceStyle;
	m_dLineSpace=dataPtr->rLineSpaceFractor;
	if(m_iLineSpaceStyle==0)
	{
		m_iLineSpaceStyle=1;
		dataPtr->nLineSpaceStyle=1;
	}
	AllCADStringToStack();
	SetWindowPlace();
	m_ctlRichText.EmptyUndoBuffer();
	return TRUE;
}

BOOL CMTextDlg::AllCADStringToStack()
{
	
//	return FALSE;//当前以下代码无效,返回 FALSE;

	
	ASSERT_VALID(this);
	
	FINDTEXTEX ftS;
	FINDTEXTEX ftF;
	LONG SIndex;
	LONG FIndex;
	ftS.chrg.cpMin = 0;
	ftS.chrg.cpMax = -1;
	ftS.lpstrText = (LPSTR)_T("\\S");
	
	ftF.chrg.cpMin = 0;
	ftF.chrg.cpMax = -1;
	ftF.lpstrText = (LPSTR)_T(";");
	DWORD dwFlags = NULL;
	dwFlags |= FR_DOWN;
	
	SIndex = m_ctlRichText.FindText(dwFlags, &ftS);
	FIndex = m_ctlRichText.FindText(dwFlags, &ftF);
	
	CHARRANGE cr;
	m_ctlRichText.HideSelection(TRUE, FALSE);
	while(SIndex!=-1&&FIndex!=-1&&SIndex<FIndex)
	{
		m_ctlRichText.SetSel(ftS.chrgText.cpMax,ftF.chrgText.cpMin);
		if(!MakeStack())
		{
			return FALSE;
		}
		m_ctlRichText.SetSel(ftS.chrgText);
		m_ctlRichText.ReplaceSel(_T(""),FALSE);	
		m_ctlRichText.GetSel( cr );	
		m_ctlRichText.SetSel(cr.cpMax+1,cr.cpMax+2); //消去 ';'
		m_ctlRichText.ReplaceSel(_T(""),FALSE);
		m_ctlRichText.GetSel( cr );	
		ftS.chrg.cpMin=cr.cpMax;
		ftF.chrg.cpMin=cr.cpMax;
		SIndex = m_ctlRichText.FindText(dwFlags, &ftS);
		FIndex = m_ctlRichText.FindText(dwFlags, &ftF);
	}
	m_ctlRichText.HideSelection(FALSE, FALSE);
	ASSERT_VALID(this);
	return TRUE;
}

BOOL CMTextDlg::AllStackToCADString()
{
	LONG iStackNumber;
	BOOL reVal;
	iStackNumber=m_pRichEditOle->GetObjectCount();
	m_CurrentSelStackIndex=-1;
	reVal=TRUE;
	CString strReplaceStr;
	while ((--iStackNumber)>=0) 
	{
		if(!SetStackSelected(iStackNumber))
		{	
			reVal=FALSE;
			break;
		}
		CMTextStack StackObj;
		if(!GetStackObject(StackObj))
		{
			reVal=FALSE;
			break;
		}
		strReplaceStr=_T("\\S");
		StackObj.m_lf.lfHeight=StackObj.m_fSizeScale*StackObj.m_lf.lfHeight*1440/-90;
		m_ctlRichText.ChangeFontSize(StackObj.m_lf.lfHeight);
		m_ctlRichText.ChangeFont(StackObj.m_lf.lfFaceName);
	//	m_ctlRichText.ReplaceSel(_T("\\S"));
	//	m_ctlRichText.ReplaceSel(StackObj.m_strUpString,FALSE);
		strReplaceStr+=StackObj.m_strUpString;
		switch(StackObj.m_StackStyle)
		{
		case 0:
	//		m_ctlRichText.ReplaceSel(_T("/"),FALSE);
			strReplaceStr+=_T("/");
			break;
		case 1:
	//		m_ctlRichText.ReplaceSel(_T("#"),FALSE);
			strReplaceStr+=_T("#");
			break;
		case 2:
	//		m_ctlRichText.ReplaceSel(_T("^"),FALSE);
			strReplaceStr+=_T("^");
	
		}
	
	//	m_ctlRichText.ReplaceSel(StackObj.m_strDownString,FALSE);
		strReplaceStr+=StackObj.m_strDownString;
		strReplaceStr+=_T(";");
		strReplaceStr.Remove('\r');
		strReplaceStr.Remove('\n');
		m_ctlRichText.ReplaceSel(strReplaceStr,FALSE);
	}
	
	return reVal;
}

BOOL CMTextDlg::SetStackSelected(LONG index)
{
	REOBJECT reobject;
	LONG iStackNumber;
	iStackNumber=m_pRichEditOle->GetObjectCount();
	if(index>=iStackNumber)
	{
		m_CurrentSelStackIndex=-1;
		return FALSE;
	}
	
		ZeroMemory(&reobject, sizeof(REOBJECT));
		reobject.cbStruct = sizeof(REOBJECT);
		m_pRichEditOle->GetObject(
			index,                   
			&reobject,  
			REO_GETOBJ_NO_INTERFACES               
			);
	
	m_ctlRichText.SetSel(reobject.cp,reobject.cp+1);
	m_CurrentSelStackIndex=index;
	return TRUE;
}

BOOL CMTextDlg::ConvertMTextStrToCADStr()
{
	m_ctlRichText.HideSelection(TRUE,FALSE);
	m_ctlRichText.SetOptions(ECOOP_XOR, ECO_AUTOVSCROLL | ECO_AUTOHSCROLL|ECO_NOHIDESEL);

	AllStackToCADString();
//	ParseLineIdentToCADStr(); 由于不能达到所见所得,放弃调用
	CHARRANGE cr;
	/*
	TEXTRANGE range;
		range.chrg.cpMin = 0;
		range.chrg.cpMax = m_ctlRichText.GetTextLength();
		range.lpstrText = m_text.GetBufferSetLength(range.chrg.cpMax);
		m_ctlRichText.SendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&range);
		m_text.ReleaseBuffer(-1);*/
	
	CString text = "";
	m_ctlRichText.SetSel(0, 0);
	int index = 0, bold = 0, italic = 0, underline = 0;
	LONG fontsize = 200;
	int textindex = 0, oldbold = 0, olditalic = 0, oldunderline = 0, oldfontsize = -1;
	int oldcolor=-1,newcolor;
	CString fonttype = "Arial", oldfonttype = "", height = "";
	bool isSHX = 0;
	int pitch = 0, charset = 0; 
	
	double defaultsize;
	struct resbuf rb;
    SDS_getvar(NULL,DB_QTEXTSIZE,&rb,SDS_CURDWG,&SDS_CURCFG,&SDS_CURSES);
	
	m_wndStyleBar.m_wndFontStyle.GetTextStyle();
	defaultsize = m_wndStyleBar.m_wndFontStyle.m_tableInfo.GetHeight();
	if (defaultsize <= 0.0009)

	ConvertTextHeightToPix(defaultsize, SDS_CURGRVW, oldfontsize);
	
	fonttype = m_wndStyleBar.m_wndFontStyle.m_tableInfo.GetFontFilename(false);
	if (fonttype.Right(4) == ".shx" || fonttype.Right(4) == ".SHX" ||
		fonttype.Right(4) == ".shp" || fonttype.Right(4) == ".SHP")
		isSHX = 1;
	if (!isSHX)
		oldfonttype = m_wndStyleBar.m_wndFontStyle.m_tableInfo.GetFontFamily();
	else
		oldfonttype = m_wndStyleBar.m_wndFontStyle.m_tableInfo.GetFontFilename(false);
	
	
	while (index < m_ctlRichText.GetTextLength())
	{
		CHARFORMAT cf;
		CString strFormat;
		strFormat=_T("");
		m_ctlRichText.SetSel(index+1, index+1);
		m_ctlRichText.GetSelectionCharFormat(cf);
		/////////////////////////////////////////////////
		CString strFontCAD;
		CString strFontTTF;
		strFontTTF=cf.szFaceName;
		if(m_wndStyleBar.IsInFontMap(strFontCAD,strFontTTF,FALSE))
		{
			_tcscpy(cf.szFaceName,strFontCAD);
		}
		
		/////////////////////////////////////////////////
		bold = (cf.dwEffects & CFE_BOLD);
		italic = (cf.dwEffects & CFE_ITALIC);
		underline = (cf.dwEffects & CFE_UNDERLINE);
		fontsize = cf.yHeight*m_wndStyleBar.m_FontSizeScale;
		fonttype = cf.szFaceName;
		isSHX = 0;
		pitch = ( cf.bPitchAndFamily & 0x00ff); 
		charset = ( cf.bCharSet & 0x00ff );	
		newcolor=cf.crTextColor;
		int i = m_wndStyleBar.m_wndFontNames.FindStringExact(-1, fonttype);
		
		if(i == -1)
		{
			pitch = ( FF_SWISS | VARIABLE_PITCH );
			charset = ANSI_CHARSET;
		}
		
		double newsize;
	//	
	/*
		if(index==0)
			{
				CMTextDlg::ConvertTwipsToTextHeight(newsize,fontsize);
				height.Format(_T ("%.4lf"), newsize);
				while(height.Right(1) == '0')
					height.Delete(height.GetLength() - 1, 1);
				if(index == 0)
					m_wndStyleBar.m_wndFontStyle.m_tableInfo.SetHeight(atof(height));
			}*/
	
		
		if (fonttype.Right(4) == ".shx" || fonttype.Right(4) == ".SHX" ||
			fonttype.Right(4) == ".shp" || fonttype.Right(4) == ".SHP")
			isSHX = 1;
		if (bold != oldbold || italic != olditalic || fonttype.CompareNoCase(oldfonttype) != 0)
		{
		
			CString format = "\\f";
			format.Insert(format.GetLength(), fonttype);
		
			if (!isSHX)
			{
				CString fontFormat;
				fontFormat.Format(
					"|b%d|i%d|c%d|p%d",
					(bold	 == 0 ? 0 : 1),
					(italic == 0 ? 0 : 1),
					charset,
					pitch);
				format.Insert(format.GetLength(),fontFormat);
			
			}
			format.Insert(format.GetLength(), ";");
			strFormat+=format;
			}
		
		if (fontsize != oldfontsize)
		{
			//////////////////////////////////////////////////////////////////////////////////
			int  Boxindex=-1;
			LONG TwipsInBox;
			LONG TwipsLOOP;
			LONG Lack;
			LONG MinLack=10;
			int indexfind=-1;
			for(int i=0;i<m_wndStyleBar.m_wndFontSizes.GetCount();i++)
			{
				
				TwipsInBox=m_wndStyleBar.m_wndFontSizes.GetItemData(i);
				
				if(m_wndStyleBar.m_BoxTwipToEditTwip.Lookup(TwipsInBox,TwipsLOOP))
				{
					if(cf.yHeight ==TwipsLOOP)
					{
						Lack=abs(TwipsLOOP-TwipsInBox/m_wndStyleBar.m_FontSizeScale);
						if(Lack<MinLack)
						{
							MinLack=Lack;
							Boxindex=i;
							if(Lack==0)
								break;
						}
					}
				}
			}
			if(Boxindex!=-1&&MinLack<10)
			{
				CString strSize;
				m_wndStyleBar.m_wndFontSizes.GetLBText(Boxindex,strSize);
				newsize=atof(strSize);
			}
			else
				CMTextDlg::ConvertTwipsToTextHeight(newsize,fontsize);
			////////////////////////////////////////////////////////////////////////////////////

			height.Format(_T ("%.4lf"), newsize);
			while(height.Right(1) == '0')
				height.Delete(height.GetLength() - 1, 1);
			
			if(index == 0)
				m_wndStyleBar.m_wndFontStyle.m_tableInfo.SetHeight(atof(height));
			else
			{
				CString format;
				format = "\\H";
				format.Insert(format.GetLength(), height);
				format.Insert(format.GetLength(), ";");
				strFormat+=format;
			}
		}
		
		if (underline != oldunderline)
		{
			if (underline == 0)
			{
				strFormat+=_T("\\l");
			}
			else
			{
				strFormat+=_T("\\L");
			}
		
		}
		if (newcolor != oldcolor)
		{	
			int     cadColor;
			cadColor=m_wndStyleBar.RGBColorToACAD(newcolor);
			if(index==0)
			{
				m_color=cadColor;
			}
			else
			{
				CString strColor;
				
				strColor.Format(_T("\\C%d;"),cadColor);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -