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 = "字符串";
return str;
}
//参数绑定到对话框
void CObjTxt::BindingDlg()
{
#ifdef __DLG_PANE_VAR_STRING__
GetFrame()->m_DlgVariableString.BindingObjString(this);
#endif
}
void CObjTxt::CreatExt()
{
//清空容器
m_ObjContainer.Clear();
//获取字符串
CString Str = GetCurString();
//逆序处理
MakeReverse(Str);
//获取单个字符数据到m_ObjContainer
GetEachCharData(Str);
//调整字符宽度,高度
AdjustWidthHeight();
//调整字符间隔
AdjustGap();
//内外向处理
MakeOutDir();
//调整斜体的角度
AdjustItalic();
//调整圆弧文本
AdjustArcTxt();
//恢复之前的状态
RecoverPerState();
}
#if 1
//获取当前文本
CString CObjTxt::GetCurString()
{
//可变文本更新
m_ValStr.UpdateValStr();
return m_ValStr.GetString();
}
//获取单个字符数据
void CObjTxt::GetEachCharData(CString Str)
{
//先保存旧的字体
CFontTypeMgr &pFontTypeMgr = CFontTypeMgr::Instance();
CString OldFontTypeName = pFontTypeMgr.GetCurFontTypeName();
CString OldFontName = pFontTypeMgr.GetCurFontName();
//设置当前选用的字体
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)//两位是一个汉字
{
strncpy(Char,pStr,2);
Char[2]='\0';
pStr += 2;
StrLen -= 2;
}
else//一位一个字母
{
strncpy(Char,pStr,1);
Char[1]='\0';
pStr += 1;
StrLen -= 1;
}
CObjChar *p = new CObjChar(Char);
p->Creat();
m_ObjContainer.AddObject(p);
}
//还原旧的字体
pFontTypeMgr.SetCurFontByName(OldFontTypeName,OldFontName);
}
//逆序处理
void CObjTxt::MakeReverse(CString &Str)
{
if(m_FontPar.m_bReverse)
{
Str.MakeReverse();
}
}
//内外向处理
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//调整
//调整字符宽度,高度
void CObjTxt::AdjustWidthHeight()
{
DbRect rect = m_ObjContainer.GetObjRect(false);
double Scale = m_FontPar.m_CharHeight/rect.GetSize().h;
//确定缩放比例
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);
}
}
//调整字符间隔
void CObjTxt::AdjustGap()
{
int size = m_ObjContainer.GetSize();
for(int i=1;i<size;i++)
{
//获得char 的矩形范围
DbRect rect1 = m_ObjContainer.GetObjRect(i-1);
DbRect rect2 = m_ObjContainer.GetObjRect(i);
//得到两个基准点
Dbxy pt1;
Dbxy pt2;
if(m_FontPar.m_GapType == SFontPar::_Center)//以char 的中心点来计算
{
pt1 = rect1.GetCenterPt();
pt2 = rect2.GetCenterPt();
}
else
{
pt1.x = rect1.R;
pt2.x = rect2.L;
pt1.y = rect1.B;
pt2.y = rect2.T;
}
//计算偏移量
SObjOperatePar par;
par.OpType = _OP_MOVE;
if(m_FontPar.m_bVertical)//垂直方向排列
{
par.MoveY = (pt1.y - m_FontPar.m_CharGap)-pt2.y;
par.MoveX = rect1.L-rect2.L;//水平方向也要对齐
}
else
{
par.MoveX = (pt1.x + m_FontPar.m_CharGap)-pt2.x;
}
m_ObjContainer.Operate(par,i);
}
}
//调整斜体的角度
void CObjTxt::AdjustItalic()
{
}
//调整圆弧文本
void CObjTxt::AdjustArcTxt()
{
if(!m_FontPar.m_bArc)
return;
//先计算出圆弧文本的圆心点
DbRect AllCharRect = m_ObjContainer.GetObjRect(false);//所有字符的范围
//底部中心点
Dbxy BottomCenterPt = AllCharRect.GetBottomCenterPt();
Dbxy CenterPt;//圆心点
CenterPt.x = BottomCenterPt.x;
CenterPt.y = BottomCenterPt.y - m_FontPar.m_ArcRadius;
//计算圆的周长
double Perimeter = 2*PI*m_FontPar.m_ArcRadius;
//依次旋转偏移字符到合适的位置
int size = m_ObjContainer.GetSize();
for(int i=0;i<size;i++)
{
DbRect ObjRect = m_ObjContainer.GetObjRect(i);
Dbxy pt = ObjRect.GetBottomCenterPt();
//旋转角度(360)
double angle = 360*(BottomCenterPt.x-pt.x)/Perimeter;
//旋转后的点
Dbxy pt2 = RotatoPt(BottomCenterPt,_360ToAngle(angle),CenterPt);
//计算偏移量
double OffsetX = pt2.x-pt.x;
double OffsetY = pt2.y-pt.y;
//旋转字符
SObjOperatePar par;
par.OpType = _OP_ROTATO;
par.BasePt = ObjRect.GetCenterPt();
par.Angle = angle;
m_ObjContainer.Operate(par,i);
//偏移字符
par.OpType = _OP_MOVE;
par.MoveX = OffsetX;
par.MoveY = OffsetY;
m_ObjContainer.Operate(par,i);
}
}
//调整到之前的位置上
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();
//位置--------------------------------------------
for(int i=0;i<size;i++)
{
m_ObjContainer.Operate(par,i);
}
//旋转---------------------------------------------
//正切角度
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