diff options
author | Karl Berry <karl@freefriends.org> | 2009-05-16 00:19:13 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-05-16 00:19:13 +0000 |
commit | bab45528d65eaafe68a705dbb2a57075c7b7cbd8 (patch) | |
tree | 10b4ae2b5195c8dede153ab89359ec00f55f325f /Build/source/utils/asymptote/drawfill.cc | |
parent | 8643d90372e9c31e0f461c15c596b60a545bd7d3 (diff) |
asymptote 1.72 sources (not integrated into build yet)
git-svn-id: svn://tug.org/texlive/trunk@13110 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/drawfill.cc')
-rw-r--r-- | Build/source/utils/asymptote/drawfill.cc | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/drawfill.cc b/Build/source/utils/asymptote/drawfill.cc new file mode 100644 index 00000000000..af32b95e475 --- /dev/null +++ b/Build/source/utils/asymptote/drawfill.cc @@ -0,0 +1,174 @@ +/***** + * drawfill.cc + * Andy Hammerlindl 2002/06/06 + * + * Stores a cyclic path that will outline a filled shape in a picture. + *****/ + +#include "drawfill.h" + +namespace camp { + +void drawAxialShade::palette(psfile *out) +{ + pentype.convert(); + penb.convert(); + + colorspace=(ColorSpace) max(pentype.colorspace(),penb.colorspace()); + + switch(colorspace) { + case RGB: + { + if (pentype.grayscale()) pentype.greytorgb(); + else if (penb.grayscale()) penb.greytorgb(); + break; + } + + case CMYK: + { + if (pentype.grayscale()) pentype.greytocmyk(); + else if (penb.grayscale()) penb.greytocmyk(); + + if (pentype.rgb()) pentype.rgbtocmyk(); + else if (penb.rgb()) penb.rgbtocmyk(); + break; + } + default: + break; + } + + out->gsave(); +} + +bool drawFill::draw(psfile *out) +{ + if(pentype.invisible() || empty()) return true; + + palette(out); + writepath(out); + fill(out); + return true; +} + +drawElement *drawFill::transformed(const transform& t) +{ + return new drawFill(transpath(t),stroke,transpen(t)); +} + +drawElement *drawLatticeShade::transformed(const transform& t) +{ + return new drawLatticeShade(transpath(t),stroke,pentype,pens); +} + +drawElement *drawAxialShade::transformed(const transform& t) +{ + pair A=t*a, B=t*b; + return new drawAxialShade(transpath(t),stroke,pentype,A,penb,B); +} + +drawElement *drawRadialShade::transformed(const transform& t) +{ + pair A=t*a, B=t*b; + double RA=length(t*(a+ra)-A); + double RB=length(t*(b+rb)-B); + return new drawRadialShade(transpath(t),stroke,pentype,A,RA,penb,B,RB); +} + +drawElement *drawGouraudShade::transformed(const transform& t) +{ + size_t size=vertices.size(); + vm::array *Vertices=new vm::array(size); + for(size_t i=0; i < size; i++) + (*Vertices)[i]=t*vm::read<pair>(vertices,i); + + return new drawGouraudShade(transpath(t),stroke,pentype,pens,*Vertices,edges); +} + +drawElement *drawTensorShade::transformed(const transform& t) +{ + size_t size=boundaries.size(); + size_t zsize=z.size(); + vm::array *Boundaries=new vm::array(size); + vm::array *Z=new vm::array(zsize); + + for(size_t i=0; i < size; i++) + (*Boundaries)[i]=vm::read<path>(boundaries,i).transformed(t); + + for(size_t i=0; i < zsize; i++) { + vm::array *zi=vm::read<vm::array *>(z,i); + size_t zisize=checkArray(zi); + vm::array *Zi=new vm::array(zisize); + (*Z)[i]=Zi; + for(size_t j=0; j < zisize; j++) + (*Zi)[j]=t*vm::read<pair>(zi,j); + } + + return new drawTensorShade(transpath(t),stroke,pentype,pens,*Boundaries,*Z); +} + +bool drawFunctionShade::write(texfile *out, const bbox& box) +{ + if(empty()) return true; + + const char *units= + settings::texunits(settings::getSetting<string>("tex")); + + ColorSpace colorspace=pentype.colorspace(); + size_t ncomponents=ColorComponents[colorspace]; + + out->verbatim("\\pdfobj stream attr {/FunctionType 4"); + out->verbatim("/Domain [0 1 0 1]"); + out->verbatim("/Range ["); + for(size_t i=0; i < ncomponents; ++i) + out->verbatim("0 1 "); + out->verbatim("]}{{"); + out->verbatimline(shader); + out->verbatimline("}}%"); + out->verbatimline("\\edef\\lastobj{\\the\\pdflastobj}\\pdfrefobj\\lastobj"); + + out->verbatim("\\setbox\\ASYbox=\\hbox to "); + double Hoffset=out->hoffset(); + double hoffset=(bpath.Max().getx()-Hoffset)*ps2tex; + out->write(hoffset); + out->verbatim(units); + out->verbatim(" {"); + out->verbatim("\\vbox to "); + out->write((box.top-box.bottom)*ps2tex); + out->verbatim(units); + out->verbatimline(" {\\vfil%"); + out->gsave(); + out->beginspecial(); + out->beginraw(); + writeshiftedpath(out); + if(stroke) strokepath(out); + out->clip(pentype); + out->verbatimline("/Sh sh"); + out->endraw(); + out->endspecial(); + out->grestore(); + out->verbatimline("}\\hfil}%"); + + out->verbatimline("\\pdfxform resources {"); + out->verbatimline("/Shading << /Sh << /ShadingType 1"); + out->verbatim("/Matrix ["); + + out->write(shift(pair(-Hoffset,-box.bottom))*matrix(bpath.Min(),bpath.Max())); + out->verbatimline("]"); + out->verbatim("/Domain [0 1 0 1]"); + out->verbatimline("/ColorSpace /Device"+ColorDeviceSuffix[colorspace]); + out->verbatimline("/Function \\lastobj\\space 0 R >> >>}\\ASYbox"); + + out->verbatimline("\\pdfrefxform\\the\\pdflastxform"); + out->verbatim("\\kern"); + out->write(-hoffset); + out->verbatim(units); + out->verbatimline("%"); + return true; +} + +drawElement *drawFunctionShade::transformed(const transform& t) +{ + return new drawFunctionShade(transpath(t),stroke,pentype,shader); +} + +} // namespace camp |