You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
6.2 KiB
C++

#include "StdAfx.h"
#include "ObjTxt.h"
#include "GlobalFunction.h"
#include "LogMgr.h"
#include "FontTypeMgr.h"
CObjTxt::CObjTxt(void)
{
}
CObjTxt::~CObjTxt(void)
{
}
CObjTxt::CObjTxt(CObjTxt &rhs)
:CObjString(rhs)
{
m_FontPar = rhs.m_FontPar;
CreatExt();
}
CString CObjTxt::GetStr()
{
CString str = "<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>";
return str;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>󶨵<EFBFBD><F3B6A8B5>Ի<EFBFBD><D4BB><EFBFBD>
void CObjTxt::BindingDlg()
{
#ifdef __DLG_PANE_VAR_STRING__
GetFrame()->m_DlgVariableString.BindingObjString(this);
#endif
}
void CObjTxt::CreatExt()
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m_ObjContainer.Clear();
//<2F><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
CString Str = GetCurString();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MakeReverse(Str);
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ݵ<EFBFBD>m_ObjContainer
GetEachCharData(Str);
//<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ȣ<EFBFBD><C8A3>߶<EFBFBD>
AdjustWidthHeight();
//<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
AdjustGap();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MakeOutDir();
//<2F><><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>ĽǶ<C4BD>
AdjustItalic();
//<2F><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>ı<EFBFBD>
AdjustArcTxt();
//<2F>ָ<EFBFBD>֮ǰ<D6AE><C7B0>״̬
RecoverPerState();
}
#if 1
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD>ı<EFBFBD>
CString CObjTxt::GetCurString()
{
//<2F>ɱ<EFBFBD><C9B1>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
m_ValStr.UpdateValStr();
return m_ValStr.GetString();
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
void CObjTxt::GetEachCharData(CString Str)
{
//<2F>ȱ<EFBFBD><C8B1><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD>
CFontTypeMgr &pFontTypeMgr = CFontTypeMgr::Instance();
CString OldFontTypeName = pFontTypeMgr.GetCurFontTypeName();
CString OldFontName = pFontTypeMgr.GetCurFontName();
//<2F><><EFBFBD>õ<EFBFBD>ǰѡ<C7B0>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>
pFontTypeMgr.SetCurFontByName(m_FontTypeName,m_FontName);
const char* pStr=(const char*)(Str);
int StrLen = strlen(pStr);
while(StrLen>0)
{
unsigned char char1,char2;
char Char[3];
char1 = *pStr;
char2 = *(pStr+1);
if(char1>160 && char2>160)//<2F><>λ<EFBFBD><CEBB>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
strncpy(Char,pStr,2);
Char[2]='\0';
pStr += 2;
StrLen -= 2;
}
else//һλһ<CEBB><D2BB><EFBFBD><EFBFBD>ĸ
{
strncpy(Char,pStr,1);
Char[1]='\0';
pStr += 1;
StrLen -= 1;
}
CObjChar *p = new CObjChar(Char);
p->Creat();
m_ObjContainer.AddObject(p);
}
//<2F><>ԭ<EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD>
pFontTypeMgr.SetCurFontByName(OldFontTypeName,OldFontName);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CObjTxt::MakeReverse(CString &Str)
{
if(m_FontPar.m_bReverse)
{
Str.MakeReverse();
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CObjTxt::MakeOutDir()
{
if(m_FontPar.m_bOutDir)
{
DbRect rect = m_ObjContainer.GetObjRect(false);
SObjOperatePar par;
par.OpType = _OP_MIRROR;
par.BasePt = rect.GetCenterPt();
par.xy = _Y;
m_ObjContainer.OperateObj(par,false);
}
}
#endif
#if 1//<2F><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ȣ<EFBFBD><C8A3>߶<EFBFBD>
void CObjTxt::AdjustWidthHeight()
{
DbRect rect = m_ObjContainer.GetObjRect(false);
double Scale = m_FontPar.m_CharHeight/rect.GetSize().h;
//ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD><C5B1><EFBFBD>
SObjOperatePar par;
par.OpType = _OP_SCALE;
par.Scale = Scale;
int size = m_ObjContainer.GetSize();
for(int i=0;i<size;i++)
{
m_ObjContainer.Operate(par,i);
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
void CObjTxt::AdjustGap()
{
int size = m_ObjContainer.GetSize();
for(int i=1;i<size;i++)
{
//<2F><><EFBFBD><EFBFBD>char <20>ľ<EFBFBD><C4BE>η<EFBFBD>Χ
DbRect rect1 = m_ObjContainer.GetObjRect(i-1);
DbRect rect2 = m_ObjContainer.GetObjRect(i);
//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><D7BC>
Dbxy pt1;
Dbxy pt2;
if(m_FontPar.m_GapType == SFontPar::_Center)//<2F><>char <20><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
pt1 = rect1.GetCenterPt();
pt2 = rect2.GetCenterPt();
}
else
{
pt1.x = rect1.R;
pt2.x = rect2.L;
pt1.y = rect1.B;
pt2.y = rect2.T;
}
//<2F><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
SObjOperatePar par;
par.OpType = _OP_MOVE;
if(m_FontPar.m_bVertical)//<2F><>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
par.MoveY = (pt1.y - m_FontPar.m_CharGap)-pt2.y;
par.MoveX = rect1.L-rect2.L;//ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD>ҲҪ<D2B2><D2AA><EFBFBD><EFBFBD>
}
else
{
par.MoveX = (pt1.x + m_FontPar.m_CharGap)-pt2.x;
}
m_ObjContainer.Operate(par,i);
}
}
//<2F><><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>ĽǶ<C4BD>
void CObjTxt::AdjustItalic()
{
}
//<2F><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>ı<EFBFBD>
void CObjTxt::AdjustArcTxt()
{
if(!m_FontPar.m_bArc)
return;
//<2F>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>Բ<EFBFBD>ĵ<EFBFBD>
DbRect AllCharRect = m_ObjContainer.GetObjRect(false);//<2F><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ķ<EFBFBD>Χ
//<2F>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD>ĵ<EFBFBD>
Dbxy BottomCenterPt = AllCharRect.GetBottomCenterPt();
Dbxy CenterPt;//Բ<>ĵ<EFBFBD>
CenterPt.x = BottomCenterPt.x;
CenterPt.y = BottomCenterPt.y - m_FontPar.m_ArcRadius;
//<2F><><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD>ܳ<EFBFBD>
double Perimeter = 2*PI*m_FontPar.m_ArcRadius;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>תƫ<D7AA><C6AB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>λ<EFBFBD><CEBB>
int size = m_ObjContainer.GetSize();
for(int i=0;i<size;i++)
{
DbRect ObjRect = m_ObjContainer.GetObjRect(i);
Dbxy pt = ObjRect.GetBottomCenterPt();
//<2F><>ת<EFBFBD>Ƕ<EFBFBD>(360)
double angle = 360*(BottomCenterPt.x-pt.x)/Perimeter;
//<2F><>ת<EFBFBD><D7AA><EFBFBD>ĵ<EFBFBD>
Dbxy pt2 = RotatoPt(BottomCenterPt,_360ToAngle(angle),CenterPt);
//<2F><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
double OffsetX = pt2.x-pt.x;
double OffsetY = pt2.y-pt.y;
//<2F><>ת<EFBFBD>ַ<EFBFBD>
SObjOperatePar par;
par.OpType = _OP_ROTATO;
par.BasePt = ObjRect.GetCenterPt();
par.Angle = angle;
m_ObjContainer.Operate(par,i);
//ƫ<><C6AB><EFBFBD>ַ<EFBFBD>
par.OpType = _OP_MOVE;
par.MoveX = OffsetX;
par.MoveY = OffsetY;
m_ObjContainer.Operate(par,i);
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
void CObjTxt::RecoverPerState()
{
DbRect rect = m_ObjContainer.GetObjRect(false);
SObjOperatePar par;
par.OpType = _OP_MOVE;
par.MoveX = m_BasePt1.x-rect.L;
par.MoveY = m_BasePt1.y-rect.B;
int size = m_ObjContainer.GetSize();
//λ<><CEBB>--------------------------------------------
for(int i=0;i<size;i++)
{
m_ObjContainer.Operate(par,i);
}
//<2F><>ת---------------------------------------------
//<2F><><EFBFBD>нǶ<D0BD>
Dbxy StartPt;
StartPt.x = m_BasePt1.x + m_Distance;
StartPt.y = m_BasePt1.y;
double ang = CalAngle(m_BasePt1,StartPt,m_BasePt2);
par.OpType = _OP_ROTATO;
par.Angle = AngleTo360(ang);
par.BasePt = m_BasePt1;
for(int i=0;i<size;i++)
{
m_ObjContainer.Operate(par,i);
}
}
#endif