📄 stylebar.cpp
字号:
if((boxcolor==color))
/*
(boxcolor==color+COLOR_FOR_BLOCK_PLUS)||
(boxcolor==color+COLOR_FOR_LAYER_PLUS))*/
{
if(ii!=m_wndColor.GetCurSel())
m_wndColor.SetCurSel(ii);
break;
}
}
if(ii==-1)
{
if(color!=-1)
{
boxcolor=RGBColorToACAD(color);
strColor.Format(IDS_MTEXT_COLOR_NORMAL,boxcolor);
ii=m_wndColor.AddString(strColor);
m_wndColor.SetItemData(ii,color);
m_wndColor.SetCurSel(ii);
}
else
m_wndColor.SetCurSel(-1);
}
CString strFontCAD;
CString strFontTTF;
if(IsInFontMap(strFontCAD,strFontTTF,FALSE))
{
_tcscpy(szFaceName,strFontCAD);
}
TCHAR szSelection[LF_FACESIZE];
m_wndFontNames.GetWindowText(szSelection,sizeof(szSelection)/sizeof(TCHAR));
if(::lstrcmp(szFaceName,szSelection)!=0)
{
if(szFaceName[0]==0)
{
m_wndFontNames.SetCurSel(-1);
}
else
{
if(m_wndFontNames.SelectString(-1,szFaceName)==CB_ERR)
m_wndFontNames.SetCurSel(-1);
}
}
if(!isFoucsInComBoxSize)
{
if(nTwips==-1)
{
m_wndFontSizes.SetCurSel(-1);
return;
}
CString strBoxSize;
CString strTextSize;
sds_real realFromText;
m_wndFontSizes.GetWindowText(strBoxSize);
LONG TwipsInBox;
LONG TwipsLOOP;
LONG Lack=0;
LONG MinLack=1000;
int index=-1;
for(int i=0;i<m_wndFontSizes.GetCount();i++)
{
TwipsInBox=m_wndFontSizes.GetItemData(i);
if(m_BoxTwipToEditTwip.Lookup(TwipsInBox,TwipsLOOP))
{
if(nTwips==TwipsLOOP)
{
Lack=abs(TwipsLOOP-TwipsInBox/m_FontSizeScale);
if(Lack<MinLack)
{
MinLack=Lack;
index=i;
}
}
}
}
if(index!=-1&&MinLack<10)
{
if(index!=m_wndFontSizes.GetCurSel())
{
m_wndFontSizes.SetCurSel(index);
}
return;
}
CMTextDlg::ConvertTwipsToTextHeight(realFromText,nTwips*m_FontSizeScale+0.0001);
strTextSize.Format("%.4lf",realFromText);
realFromText=atof(strBoxSize);
strBoxSize.Format("%.4lf",realFromText);
//
if(strBoxSize.GetLength()==0||strTextSize.Compare(strBoxSize)!=0)
{
m_wndFontSizes.SetWindowText(strTextSize);
}
}
}
void CMTextStyleBar::OnCloseUp()
{
CMTextDlg*p=(CMTextDlg*)GetParent();
p->m_ctlRichText.SetFocus();
}
COLORREF CMTextStyleBar::GetColor(CString &wszColor)
{
if ( wszColor == _T("black") || wszColor == _T("0") )
{
//focalColor = RGB(255,255,255);
return RGB(0,0,0);
}
else if ( wszColor == _T("red") || wszColor == _T("1"))
{
//focalColor = RGB(255,255,0);
return RGB(255,0,0);
}
else if ( wszColor == _T("yellow") || wszColor == _T("2"))
{
//focalColor = RGB(255,255,255);
return RGB(255,255,0);
}
else if ( wszColor == _T("green") || wszColor == _T("3"))
{
//focalColor = RGB(0,0,0);
return RGB(0,255,0);
}
else if ( wszColor == _T("cyan") || wszColor == _T("4") )
{
//focalColor = RGB(255,255,255);
return RGB(0,255,255);
}
else if ( wszColor == _T("blue") || wszColor == _T("5") )
{
//focalColor = RGB(255,255,255);
return RGB(0,0,255);
}
else if ( wszColor == _T("magenta") || wszColor == _T("6") )
{
///focalColor = RGB(255,50,255);
return RGB(255,0,255);
}
else if ( wszColor == _T("white") || wszColor == _T("7") )
{
return RGB(255,255,255);
}
else if ( atoi((LPCTSTR)wszColor) != 0 )
{
// In case an integer value is given which is greater than above colors, then
// Intellicad's "sds_getrgbvalue" function is called to get the
// corresponding value for the integer.
#ifndef _TESTEXE
HMODULE hmodule = GetModuleHandle(NULL);
ASSERT(hmodule);
if(hmodule)
{
typedef int (* getrgbvalue)(int nColor);
getrgbvalue pfnGetRGBValue;
pfnGetRGBValue = ( getrgbvalue)GetProcAddress(hmodule,"sds_getrgbvalue");
ASSERT(pfnGetRGBValue);
int nColorRef = RGB ( 255,255,255);
return ( nColorRef & pfnGetRGBValue(atoi((LPCTSTR)wszColor)));
}
#endif
return RGB(0,0,0);
}
return RGB(255,255,255);
}
int CMTextStyleBar::GetTextHeightFromTwips(sds_real& textHeight, long twipsHeight)
{
int nCount = m_wndFontSizes.GetCount();
//TCHAR array[50];
CString strHeight;
do
{
if(m_wndFontSizes.GetItemData(--nCount) == twipsHeight)
{
m_wndFontSizes.GetLBText(nCount,strHeight);
textHeight = _tcstod(strHeight,NULL);
return nCount;
}
}while(nCount);
return -1;
}
BOOL CMTextStyleBar::init(SDS_mTextData *pMTextData)
{
CString string = pMTextData->szTextStyle;
if(!string.IsEmpty())
{
int comboIndex = m_wndFontStyle.FindStringExact(-1, string);
if(CB_ERR == comboIndex)
m_wndFontStyle.SetCurSel(0);
else
m_wndFontStyle.SetCurSel(comboIndex);
}
m_wndFontNames.FillFontComboBox(GET_FONT_SHX | GET_FONT_TTF);
CToolBarCtrl &pToolCtrl =GetToolBarCtrl();
TBBUTTON button;
for(int l=0;l<4;l++)
{
pToolCtrl.GetButton(l,&button);
pToolCtrl.HideButton(button.idCommand,TRUE);
}
// m_wndColor.ShowWindow(SW_HIDE);
//pToolCtrl.SetStyle(TBSTYLE_WRAPABLE);
for(l=0;l<400;l++)
{
BOOL iSu;
ZeroMemory(&button, sizeof(button));
button.iBitmap=1;
button.fsState=TBSTATE_ENABLED;
button.fsStyle=TBSTYLE_SEP;
iSu=pToolCtrl.InsertButton(0,&button);
}
LONG yHeight;
CMTextDlg::ConvertTextHeightToTwips(pMTextData->rTextHeight,yHeight);
if(yHeight<=Mid_FontTwips)
//GetMTextDlg()->m_wndStyleBar.m_FontSizeScale=1.0;
m_FontSizeScale=double(yHeight)/double(Mid_FontTwips);
else
if(yHeight>=Mid_FontTwips&&yHeight<=NO_CHANGE_MAX)
m_FontSizeScale=1.0;
else
m_FontSizeScale=double(yHeight)/double(Mid_FontTwips);
UpdateStyle();
return TRUE;
}
void CMTextStyleBar::UpdateStyle()
{
m_wndFontStyle.GetTextStyle();
CString fontName = m_wndFontStyle.m_tableInfo.GetFontFilename(false);
if(fontName.IsEmpty())
fontName = m_wndFontStyle.m_tableInfo.GetFontFamily();
if(m_wndFontNames.FindStringExact(-1, fontName) != CB_ERR)
m_wndFontNames.SetCurrentFont(fontName);
else
{
int itemIndex;
if(fontName.Right(4) == ".shx" || fontName.Right(4) == ".SHX")
itemIndex = m_wndFontNames.AddFont(NULL, SHX_FONTTYPE, (char*)(LPCTSTR)fontName);
else
if(fontName.Right(4) == ".shp" || fontName.Right(4) == ".SHP")
itemIndex =m_wndFontNames.AddFont(NULL, SHP_FONTTYPE, (char*)(LPCTSTR)fontName);
else
{
LOGFONT logFont;
logFont.lfCharSet = DEFAULT_CHARSET;
strcpy(logFont.lfFaceName, m_wndFontStyle.m_tableInfo.GetFontFamily());
logFont.lfPitchAndFamily = 0;
itemIndex =m_wndFontNames.AddFont(&logFont, TRUETYPE_FONTTYPE, (char*)(LPCTSTR)m_wndFontStyle.m_tableInfo.GetFontFamily());
}
m_wndFontNames.SetCurSel(itemIndex);
}
CHARFORMAT cf;
CMTextDlg*pEdit=(CMTextDlg*)GetParent();
pEdit->m_ctlRichText.SetSel(0, -1);
pEdit->m_ctlRichText.GetSelectionCharFormat(cf);
_tcscpy(cf.szFaceName, m_wndFontNames.GetFontItem()->fontName);
cf.dwMask = CFM_FACE | CFM_SIZE | CFM_CHARSET; /*D.G.*/
//cf.bCharSet = GetSystemCharSet(); // Use system character set.
//cf.bCharSet = ((CMTextPropSheet*)GetParent())->GetFontCombo()->GetFontItem()->fontInfo()->lfCharSet;
// DP: because of stupid RICHEDIT make some steps with charset
// DP: at first enumerate all
CTTFInfoGetter::get().fillFontsInfo(cf.szFaceName, (BYTE)DEFAULT_CHARSET, GetDC()->GetSafeHdc());
if(CTTFInfoGetter::get().fontCount() > 0)
{
// DP: try to find font with charset of drawing
for(int i = 0; i < CTTFInfoGetter::get().fontCount(); ++i)
if(CTTFInfoGetter::get().fontInfo(i).elfLogFont.lfCharSet == GetDWGCharSet(SDS_CURDWG))
{
cf.bCharSet = GetDWGCharSet(SDS_CURDWG);
break;
}
}
struct resbuf rb;
SDS_getvar(NULL,DB_QTEXTSIZE,&rb,SDS_CURDWG,&SDS_CURCFG,&SDS_CURSES);
double fontHeight = m_wndFontStyle.m_tableInfo.GetHeight();
if (fontHeight <= 0.0009)
fontHeight = rb.resval.rreal; //Default fontheight
// Bugzilla No. 78034; 23-12-2002
//cf.yHeight = (int) ((fontHeight / 0.2) * 200 + 0.5);
CMTextDlg::ConvertTextHeightToTwips(fontHeight, cf.yHeight);
if((cf.yHeight>Max_FontTwips*m_FontSizeScale||cf.yHeight<Min_FontTwips*m_FontSizeScale)&&!pEdit->m_bIsOnInitial)
{
m_FontSizeScale=double(cf.yHeight)/Mid_FontTwips;
pEdit->SetLineLength(pEdit->m_dBoxWidth);
}
CString string;
LONG yHeight;
yHeight=cf.yHeight/m_FontSizeScale;
string.Format (_T ("%.4lf"), fontHeight);
int index = m_wndFontSizes.FindStringExact(-1, string);
// Bugzilla No. 78034; 23-12-2002 [
if (index == CB_ERR)
{
index =m_wndFontSizes.AddString(string);
m_wndFontSizes.SetItemData(index,cf.yHeight);
m_BoxTwipToEditTwip[cf.yHeight]=yHeight;
}
// Bugzilla No. 78034; 23-12-2002 ]
cf.yHeight=yHeight;
m_wndFontSizes.SetCurSel(index);
////////////////////////////////////////
CString strTTF;
CString strCAD;
strCAD=cf.szFaceName;
if(IsInFontMap(strCAD,strTTF,TRUE))
_tcscpy(cf.szFaceName,strTTF);
///////////////////////////////////////
pEdit->m_ctlRichText.SetSelectionCharFormat(cf);
pEdit->m_ctlRichText.SetDefaultCharFormat(cf); //to prevent a change to Arial the first run through
pEdit->m_ctlRichText.SetSel(pEdit->m_ctlRichText.GetTextLength(), pEdit->m_ctlRichText.GetTextLength());
// pEdit->m_ctlRichText.SetSel(pEdit->m_ctlRichText.GetTextLength(), pEdit->m_ctlRichText.GetTextLength());
pEdit->m_ctlRichText.EmptyUndoBuffer();
}
BOOL CMTextStyleBar::UpdateColorBox(int colorindex)
{
BOOL bHaveInBox=FALSE;
CString strColor;
int nIndex;
for(int i=0;i<m_wndColor.GetCount();i++)
{
m_wndColor.GetLBText(i,strColor);
strColor=strColor.Right(strColor.GetLength()-strColor.Find(_T(" "))-1);
if(atoi(strColor)==colorindex)
{
bHaveInBox=TRUE;
nIndex=i;
break;
}
}
if(!bHaveInBox)
{
strColor.Format(IDS_MTEXT_COLOR_NORMAL,colorindex);
nIndex=m_wndColor.AddString(strColor);
m_wndColor.SetItemData(nIndex,CMTextStyleBar::BOUND_SDS_RGBFromACADColor(colorindex));
}
m_wndColor.SetCurSel(nIndex);
return TRUE;
}
BOOL CMTextStyleBar::IsInFontMap(CString& strFontNameCAD,CString&strFontNameTTF,BOOL needTTF)
{
BOOL retVal;
retVal=FALSE;
if(needTTF)
{
strFontNameCAD.MakeUpper();
if(m_wndFontNames.m_CadFontToTrueTypeFont.Lookup(strFontNameCAD,strFontNameTTF))
retVal=TRUE;
}
else
{
POSITION pos=m_wndFontNames.m_CadFontToTrueTypeFont.GetStartPosition();
while(pos!=NULL)
{
CString strItem;
CString strKey;
m_wndFontNames.m_CadFontToTrueTypeFont.GetNextAssoc(pos,strKey,strItem);
if(strItem.Compare(strFontNameTTF)==0)
{
strFontNameCAD=strKey;
retVal=TRUE;
break;
}
}
}
return retVal;
}
int CMTextStyleBar::RGBColorToACAD(COLORREF color)
{
COLORREF boxcolor;
int retVal;
RGBQUAD* ary = SDS_CURPALLET;
retVal=-10;
if(color==COLOR_FOR_BLOCK_PLUS)
{
retVal=0;
}
else
if(color==COLOR_FOR_LAYER_PLUS)
{
retVal=256;
}
for(int ii=255;ii>-1&&retVal==-10;ii--)
{
boxcolor=RGB(ary[ii].rgbRed,
ary[ii].rgbGreen,
ary[ii].rgbBlue);
if(boxcolor==color)
{
retVal=ii+1;
break;
}
}
return retVal;
}
int CMTextStyleBar::BOUND_SDS_RGBFromACADColor(int colorindex)
{
COLORREF rgbcolor;
rgbcolor=SDS_RGBFromACADColor(colorindex);
if(colorindex==256)
rgbcolor=COLOR_FOR_LAYER_PLUS;
else
if(colorindex==0)
rgbcolor=COLOR_FOR_BLOCK_PLUS;
return rgbcolor;
}
void CMTextStyleBar::LoadColorString()
{
CString strLoad;
strLoad.LoadString(IDS_MTEXT_COLOR_POPULAR);
char*stringA;
stringA=strLoad.GetBuffer(0);
char seps[] = ",\n";
char *token;
CString strColor;
COLORREF rgbcolor;
int nIndex;
token = strtok( stringA, seps );
while( token != NULL )
{
nIndex=m_wndColor.AddString(token);
strColor=token;
if(strColor.Find('.')!=-1)
rgbcolor=300;
else
{
strColor=strColor.Right(strColor.GetLength()-strColor.Find(_T(" "))-1);
rgbcolor=CMTextStyleBar::BOUND_SDS_RGBFromACADColor(atoi(strColor));
}
m_wndColor.SetItemData(nIndex,rgbcolor);
token = strtok( NULL, seps );
}
strLoad.ReleaseBuffer(-1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -