📄 fshape.cpp
字号:
linestyle=false;
fillstyle1=false;
fillstyle0=false;
moveto=true;
dx=_dx;
dy=_dy;
}
void FlashShapeRecordChange::NewFillStyles(FlashFillStyleArray &a, FlashLineStyleArray &c)
{
newstyles=true;
fillstyles=a;
linestyles=c;
}
void FlashShapeRecordChange::ChangeFillStyle1(UWORD style)
{
fillstyle1=true;
stylefill1=style;
}
void FlashShapeRecordChange::ChangeFillStyle0(UWORD style)
{
fillstyle0=true;
stylefill0=style;
}
void FlashShapeRecordChange::ChangeLineStyle(UWORD style)
{
linestyle=true;
styleline=style;
}
void FlashShapeRecordChange::Write(BitBuffer &out, FlashShapeCommon &data)
{
BitBuffer &b=out;
b.Write(0,1);
b.Write(newstyles,1);
b.Write(linestyle,1);
b.Write(fillstyle1,1);
b.Write(fillstyle0,1);
b.Write(moveto,1);
if(moveto)
{
int m = fbase_max(GetBitSizeSigned(dx),GetBitSizeSigned(dy));
b.Write(m,5);
b.Write(PackBitsSigned(dx),m);
b.Write(PackBitsSigned(dy),m);
}
if(fillstyle0)
{
b.Write(stylefill0, data.NBitsFillStyle);
}
if(fillstyle1)
{
b.Write(stylefill1, data.NBitsFillStyle);
}
if(linestyle)
{
b.Write(styleline, data.NBitsLineStyle);
}
if(newstyles)
{
std::ostrstream str;
fillstyles.SetTagVersion(GetTagVersion());
linestyles.SetTagVersion(GetTagVersion());
str << fillstyles;
str << linestyles;
BitBuffer b2;
b2.Write(fillstyles.GetNBits(),4);
b2.Write(linestyles.GetNBits(),4);
str << b2;
b.Align();
b.WriteBytes(str.rdbuf()->str(),str.pcount());
data.NBitsFillStyle = fillstyles.GetNBits();
data.NBitsLineStyle = linestyles.GetNBits();
}
}
void FlashShapeRecordChange::Read(BitStreamIn &in, FlashShapeCommon &data)
{
BitStreamIn &b=in;
newstyles = (data.flags & 16) == 16;
linestyle = (data.flags & 8) == 8;
fillstyle1 = (data.flags & 4) == 4;
fillstyle0 = (data.flags & 2) == 2;
moveto = (data.flags & 1) == 1;
if(moveto)
{
int m;
b.Read(m,5);
b.Read(dx,m);
dx = UnPackBitsSigned(dx,m);
b.Read(dy,m);
dy = UnPackBitsSigned(dy,m);
}
if(fillstyle0)
{
b.Read(stylefill0, data.NBitsFillStyle);
}
if(fillstyle1)
{
b.Read(stylefill1, data.NBitsFillStyle);
}
if(linestyle)
{
b.Read(styleline, data.NBitsLineStyle);
}
if(newstyles)
{
b.Align();
fillstyles.SetTagVersion(GetTagVersion());
linestyles.SetTagVersion(GetTagVersion());
b.GetStream() >> fillstyles;
b.GetStream() >> linestyles;
b.Read(data.NBitsFillStyle,4);
b.Read(data.NBitsLineStyle,4);
}
}
void FlashShapeRecordEnd::Write(BitBuffer &out, FlashShapeCommon &data)
{
BitBuffer &b=out;
b.Write(0,1);
b.Write(0,5);
}
void FlashShapeRecordEnd::Read(BitStreamIn &in, FlashShapeCommon &data)
{
}
FlashRect FlashShape::GetBounds()
{
FlashRect prep;
SDWORD curx=0;
SDWORD cury=0;
std::vector<flash_pair<SDWORD, SDWORD> > coords;
for(std::vector<flash_pair<int,long> >::iterator i = record_sequencer.begin(); i != record_sequencer.end(); i++)
{
if((*i).first==0)
{
FlashShapeRecordChange &rec = record_change[(*i).second];
if(rec.moveto)
{
coords.push_back(flash_pair<SDWORD,SDWORD>(rec.dx,rec.dy));
curx = rec.dx;
cury = rec.dy;
}
}
else if((*i).first==1)
{
FlashShapeRecordStraight &rec =record_straight[(*i).second];
curx+=rec.dx;
cury+=rec.dy;
coords.push_back(flash_pair<SDWORD,SDWORD>(curx, cury));
}
else if((*i).first==2)
{
FlashShapeRecordCurved &rec =record_curved[(*i).second];
curx+=rec.dxc;
cury+=rec.dyc;
coords.push_back(flash_pair<SDWORD,SDWORD>(curx, cury));
curx+=rec.dxa;
cury+=rec.dya;
coords.push_back(flash_pair<SDWORD,SDWORD>(curx, cury));
}
}
if(coords.size() > 0)
{
prep=FlashRect(coords[0].first,coords[0].second, coords[0].first, coords[0].second);
for(std::vector<flash_pair< SDWORD, SDWORD> >::iterator i=coords.begin(); i != coords.end(); i++)
{
prep.BoundWith(FlashRect((*i).first,(*i).second,(*i).first,(*i).second));
}
}
prep.SetRect(prep.GetX1()-500, prep.GetY1()-500, prep.GetX2()+500, prep.GetY2()+500);
return prep;
}
std::ostream &operator<< (std::ostream &out, FlashShape &data)
{
BitBuffer b;
FlashShapeCommon c;
c.NBitsFillStyle = 1;
c.NBitsLineStyle = 1;
b.Write(1,4);
b.Write(1,4);
for(std::vector<flash_pair<int,long> >::iterator i = data.record_sequencer.begin(); i != data.record_sequencer.end(); i++)
{
if((*i).first==0)
{
data.record_change[(*i).second].Write(b,c);
}
else if((*i).first==1)
{
data.record_straight[(*i).second].Write(b,c);
}
else if((*i).first==2)
{
data.record_curved[(*i).second].Write(b,c);
}
}
FlashShapeRecordEnd e;
e.Write(b,c);
out << b;
return out;
}
std::istream &operator>> (std::istream &in, FlashShape &data)
{
BitStreamIn b(&in);
FlashShapeCommon c;
c.NBitsFillStyle = 1;
c.NBitsLineStyle = 1;
int tmp;
b.Read(tmp,4);
b.Read(tmp,4);
for(;;)
{
int type;
b.Read(type,1);
if(type == 0)
{
int flags;
b.Read(flags,5);
if(flags == 0)
break;
else
{
FlashShapeRecordChange r;
c.flags = flags;
r.Read(b, c);
data.AddRecord(r);
}
}
if(type == 1)
{
int type2;
b.Read(type2,1);
if(type2 == 1)
{
FlashShapeRecordStraight r;
r.Read(b, c);
data.AddRecord(r);
}
if(type2 == 0)
{
FlashShapeRecordCurved r;
r.Read(b, c);
data.AddRecord(r);
}
}
}
return in;
}
std::ostream &operator<< (std::ostream &out, FlashShapeWithStyle &data)
{
data.fillstyles.SetTagVersion(data.GetTagVersion());
data.linestyles.SetTagVersion(data.GetTagVersion());
out << data.fillstyles;
out << data.linestyles;
BitBuffer b;
data.fillstyles.SetTagVersion(data.GetTagVersion());
b.Write(data.fillstyles.GetNBits(),4);
b.Write(data.linestyles.GetNBits(),4);
FlashShapeCommon c;
c.NBitsFillStyle = data.fillstyles.GetNBits();
c.NBitsLineStyle = data.linestyles.GetNBits();
c.DefineTagVersion = data.GetTagVersion();
for(std::vector<flash_pair<int,long> >::iterator i = data.record_sequencer.begin(); i != data.record_sequencer.end(); i++)
{
if((*i).first==0)
{
data.record_change[(*i).second].SetTagVersion(data.GetTagVersion());
data.record_change[(*i).second].Write(b,c);
}
else if((*i).first==1)
{
data.record_straight[(*i).second].SetTagVersion(data.GetTagVersion());
data.record_straight[(*i).second].Write(b,c);
}
else if((*i).first==2)
{
data.record_curved[(*i).second].SetTagVersion(data.GetTagVersion());
data.record_curved[(*i).second].Write(b,c);
}
}
FlashShapeRecordEnd e;
e.Write(b,c);
out << b;
return out;
}
std::istream &operator>> (std::istream &in, FlashShapeWithStyle &data)
{
data.fillstyles.SetTagVersion(data.GetTagVersion());
data.linestyles.SetTagVersion(data.GetTagVersion());
in >> data.fillstyles;
in >> data.linestyles;
BitStreamIn b(&in);
FlashShapeCommon c;
b.Read(c.NBitsFillStyle,4);
b.Read(c.NBitsLineStyle,4);
c.DefineTagVersion = data.GetTagVersion();
int i = 0;
for( ; !b.GetStream().fail(); )
{
i++;
int type;
b.Read(type,1);
if(type == 0)
{
int flags;
b.Read(flags,5);
if(flags == 0)
{
break;
}
else
{
FlashShapeRecordChange r;
c.flags = flags;
r.SetTagVersion(data.GetTagVersion());
r.Read(b, c);
data.AddRecord(r);
}
}
if(type == 1)
{
int type2;
b.Read(type2,1);
if(type2 == 1)
{
FlashShapeRecordStraight r;
r.SetTagVersion(data.GetTagVersion());
r.Read(b, c);
data.AddRecord(r);
}
else if(type2 == 0)
{
FlashShapeRecordCurved r;
r.SetTagVersion(data.GetTagVersion());
r.Read(b, c);
data.AddRecord(r);
}
}
}
return in;
}
std::ostream &operator<< (std::ostream &out, FlashTagDefineShapeBase &data)
{
std::ostringstream str(std::ios_base::binary);
WRITE_UWORD2(data.GetID(),str);
str << data.shapes.GetBounds();
data.shapes.SetTagVersion(data.version);
str << data.shapes;
out << FlashTagHeader(data.header,str.str().size());
out.write(str.str().c_str(),str.str().size());
return out;
}
std::istream &operator>> (std::istream &in, FlashTagDefineShapeBase &data)
{
UWORD id;
READ_UWORD(id);
data.SetID(id);
in >> data.rimport;
data.shapes.SetTagVersion(data.version);
in >> data.shapes;
return in;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -