From 6457cd3f6e21e23e21db6dafff021d17f5457567 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 2 Jan 2021 16:31:31 +0000 Subject: asy 2.68 sources git-svn-id: svn://tug.org/texlive/trunk@57291 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/utils/asymptote/pen.h | 294 ++++++++++++++++++------------------- 1 file changed, 147 insertions(+), 147 deletions(-) (limited to 'Build/source/utils/asymptote/pen.h') diff --git a/Build/source/utils/asymptote/pen.h b/Build/source/utils/asymptote/pen.h index d9572eee5c9..d2894cc01dd 100644 --- a/Build/source/utils/asymptote/pen.h +++ b/Build/source/utils/asymptote/pen.h @@ -20,19 +20,19 @@ namespace camp { class LineType { -public: +public: vm::array pattern; // Array of PostScript style line pattern entries. double offset; // The offset in the pattern at which to start drawing. bool scale; // Scale the line type values by the pen width? bool adjust; // Adjust the line type values to fit the arclength? - bool isdefault; - + bool isdefault; + LineType() : offset(0.0), scale(true), adjust(true), isdefault(true) {} - - LineType(vm::array pattern, double offset, bool scale, bool adjust) : + + LineType(vm::array pattern, double offset, bool scale, bool adjust) : pattern(pattern), offset(offset), scale(scale), adjust(adjust), isdefault(false) {} - + void Scale(double factor) { size_t n=pattern.size(); for(size_t i=0; i < n; i++) @@ -40,7 +40,7 @@ public: offset *= factor; } }; - + extern const char* DEFPAT; extern const char* DEFLATEXFONT; extern const char* DEFCONTEXTFONT; @@ -62,30 +62,30 @@ static const struct setmiterlimit_t {} setmiterlimit={}; static const struct setoverwrite_t {} setoverwrite={}; static const struct initialpen_t {} initialpen={}; static const struct resolvepen_t {} resolvepen={}; - + extern const char* PSCap[]; extern const char* Cap[]; extern const Int nCap; extern const char* Join[]; extern const Int nJoin; - + enum overwrite_t {DEFWRITE=-1,ALLOW,SUPPRESS,SUPPRESSQUIET,MOVE,MOVEQUIET}; extern const char* OverwriteTag[]; extern const Int nOverwrite; - + enum FillRule {DEFFILL=-1,ZEROWINDING,EVENODD}; extern const char* FillRuleTag[]; extern const Int nFill; - + enum BaseLine {DEFBASE=-1,NOBASEALIGN,BASEALIGN}; extern const char* BaseLineTag[]; extern const Int nBaseLine; - + enum ColorSpace {DEFCOLOR=0,INVISIBLE,GRAYSCALE,RGB,CMYK,PATTERN}; extern const size_t ColorComponents[]; extern const char* ColorDeviceSuffix[]; extern const unsigned nColorSpace; - + inline bool operator == (const vm::array& a, const vm::array& b) { size_t asize=a.size(); @@ -95,21 +95,21 @@ inline bool operator == (const vm::array& a, const vm::array& b) if(vm::read(a,i) != vm::read(b,i)) return false; return true; } - + inline bool operator == (const LineType& a, const LineType& b) { return a.pattern == b.pattern && a.offset == b.offset && a.scale == b.scale && a.adjust == b.adjust; } - + inline ostream& operator << (ostream& out, const vm::array& a) { out << "["; size_t n=a.size(); if(n > 0) { out << vm::read(a,0); - for(size_t i=1; i < n; ++i) - out << " " << vm::read(a,i); + for(size_t i=1; i < n; ++i) + out << " " << vm::read(a,i); } out << "]"; return out; @@ -117,29 +117,29 @@ inline ostream& operator << (ostream& out, const vm::array& a) class Transparency { -public: +public: string blend; double opacity; - bool isdefault; - + bool isdefault; + Transparency() : blend("Compatible"), opacity(1.0), isdefault(true) {} - + Transparency(const string& blend, double opacity) : blend(blend), opacity(opacity), isdefault(false) {} }; - + inline bool operator == (const Transparency& a, const Transparency& b) { return a.blend == b.blend && a.opacity == b.opacity; } - + extern const char* BlendMode[]; extern const Int nBlendMode; const double bytescale=256.0*(1.0-DBL_EPSILON); // Map [0,1] to [0,255] -inline unsigned int byte(double r) +inline unsigned int byte(double r) { if(r < 0.0) r=0.0; else if(r > 1.0) r=1.0; @@ -149,7 +149,7 @@ inline unsigned int byte(double r) class pen; pen& defaultpen(); -class pen : public gc { +class pen : public gc { LineType line; // Width of line, in PS units. @@ -157,13 +157,13 @@ class pen : public gc { path P; // A polygonal path defining a custom pen nib; // nullpath means the default (typically circular) nib. string font; - double fontsize; - double lineskip; - + double fontsize; + double lineskip; + ColorSpace color; double r,g,b; // RGB or CMY value double grey; // grayscale or K value - + string pattern; // The name of the user-defined fill/draw pattern FillRule fillrule; // Zero winding-number (default) or even-odd rule BaseLine baseline; // Align to TeX baseline? @@ -172,16 +172,16 @@ class pen : public gc { Int linejoin; double miterlimit; overwrite_t overwrite; - + // The transformation applied to the pen nib for calligraphic effects. // nullTransform means the default (typically identity) transformation. transform t; - + public: static double pos0(double x) {return x >= 0 ? x : 0;} - + void greyrange() {if(grey > 1.0) grey=1.0;} - + void rgbrange() { double sat=rgbsaturation(); if(sat > 1.0) { @@ -191,7 +191,7 @@ public: b *= scale; } } - + void cmykrange() { double sat=cmyksaturation(); if(sat > 1.0) { @@ -202,12 +202,12 @@ public: grey *= scale; } } - + void colorless() { r=g=b=grey=0.0; color=DEFCOLOR; } - + pen() : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -231,8 +231,8 @@ public: transparency(transparency), linecap(linecap), linejoin(linejoin), miterlimit(miterlimit), overwrite(overwrite), t(t) {} - - pen(invisiblepen_t) : + + pen(invisiblepen_t) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(INVISIBLE), r(0), g(0), b(0), grey(0), @@ -240,8 +240,8 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - - pen(setlinewidth_t, double linewidth) : + + pen(setlinewidth_t, double linewidth) : line(), linewidth(linewidth), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), r(0), g(0), b(0), grey(0), @@ -249,8 +249,8 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - - pen(path P) : + + pen(path P) : line(), linewidth(DEFWIDTH), P(P), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), r(0), g(0), b(0), grey(0), @@ -258,7 +258,7 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(const LineType& line) : line(line), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -267,7 +267,7 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(setfont_t, string font) : line(), linewidth(DEFWIDTH), P(nullpath), font(font), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -276,7 +276,7 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(setfontsize_t, double fontsize, double lineskip) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(fontsize), lineskip(lineskip), color(DEFCOLOR), @@ -285,7 +285,7 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(setpattern_t, const string& pattern) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(PATTERN), @@ -294,7 +294,7 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(FillRule fillrule) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -303,7 +303,7 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(BaseLine baseline) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -312,7 +312,7 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(const Transparency& transparency) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -321,7 +321,7 @@ public: transparency(transparency), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(setlinecap_t, Int linecap) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -330,7 +330,7 @@ public: transparency(), linecap(linecap), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(setlinejoin_t, Int linejoin) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -339,7 +339,7 @@ public: transparency(), linecap(DEFCAP), linejoin(linejoin), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {} - + pen(setmiterlimit_t, double miterlimit) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -348,7 +348,7 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(miterlimit), overwrite(DEFWRITE), t(nullTransform) {} - + pen(setoverwrite_t, overwrite_t overwrite) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(DEFCOLOR), @@ -357,7 +357,7 @@ public: transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(overwrite), t(nullTransform) {} - + explicit pen(double grey) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(GRAYSCALE), @@ -367,17 +367,17 @@ public: linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {greyrange();} - - pen(double r, double g, double b) : + + pen(double r, double g, double b) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(RGB), - r(pos0(r)), g(pos0(g)), b(pos0(b)), grey(0.0), + r(pos0(r)), g(pos0(g)), b(pos0(b)), grey(0.0), pattern(DEFPAT), fillrule(DEFFILL), baseline(DEFBASE), transparency(), linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {rgbrange();} - + pen(double c, double m, double y, double k) : line(), linewidth(DEFWIDTH), P(nullpath), font(""), fontsize(0.0), lineskip(0.0), color(CMYK), @@ -387,9 +387,9 @@ public: linecap(DEFCAP), linejoin(DEFJOIN), miterlimit(DEFMITER), overwrite(DEFWRITE), t(nullTransform) {cmykrange();} - + // Construct one pen from another, resolving defaults - pen(resolvepen_t, const pen& p) : + pen(resolvepen_t, const pen& p) : line(LineType(p.line.pattern,p.line.offset,p.line.scale,p.line.adjust)), linewidth(p.width()), P(p.Path()), font(p.Font()), fontsize(p.size()), lineskip(p.Lineskip()), @@ -399,34 +399,34 @@ public: transparency(Transparency(p.blend(), p.opacity())), linecap(p.cap()), linejoin(p.join()), miterlimit(p.miter()), overwrite(p.Overwrite()), t(p.getTransform()) {} - + static pen initialpen() { return pen(LineType(vm::array(0),0.0,true,true),0.5,nullpath,"", 12.0*settings::tex2ps,12.0*1.2*settings::tex2ps,GRAYSCALE, 0.0,0.0,0.0,0.0,"",ZEROWINDING,NOBASEALIGN, Transparency(),1,1,10.0,ALLOW,identity); } - - pen(initialpen_t) : + + pen(initialpen_t) : line(), linewidth(-2.0), P(nullpath), font(""), fontsize(-1.0), lineskip(-1.0), color(INVISIBLE), r(0.0), g(0.0), b(0.0), grey(0.0), pattern(DEFPAT), fillrule(DEFFILL), baseline(NOBASEALIGN), transparency(),linecap(-2), linejoin(-2), miterlimit(-1.0), overwrite(DEFWRITE), t(nullTransform) {} - + double width() const { return linewidth == DEFWIDTH ? defaultpen().linewidth : linewidth; } - + path Path() const { return P.empty() ? defaultpen().P : P; } - + double size() const { return fontsize == 0.0 ? defaultpen().fontsize : fontsize; } - + string Font() const { if(font.empty()) { if(defaultpen().font.empty()) { @@ -437,10 +437,10 @@ public: return settings::getSetting("textinitialfont"); else { ostringstream buf; - // Work around misalignment in ConTeXt switchtobodyfont if font is not found. + // Work around misalignment in ConTeXt switchtobodyfont if font is not found. if(texengine == "context") - buf << "\\switchtobodyfont[" - << DEFCONTEXTFONT << "," << size()*settings::ps2tex + buf << "\\switchtobodyfont[" + << DEFCONTEXTFONT << "," << size()*settings::ps2tex << "pt]\\removeunwantedspaces%" << newl; else buf << "\\font\\ASYfont=" << DEFTEXFONT @@ -452,88 +452,88 @@ public: } return font; } - + double Lineskip() const { return lineskip == 0.0 ? defaultpen().lineskip : lineskip; } - + const LineType *linetype() const { return line.isdefault ? &defaultpen().line : &line; } - + void adjust(double factor) { - if(line.isdefault) + if(line.isdefault) line=defaultpen().line; line.Scale(factor); } - + void setstroke(const vm::array& s) {line.pattern=s;} void setoffset(const double& offset) {line.offset=offset;} - + string fillpattern() const { return pattern == DEFPAT ? (string)"" : pattern; } - + FillRule Fillrule() const { return fillrule == DEFFILL ? defaultpen().fillrule : fillrule; } - + bool evenodd() const { return Fillrule() == EVENODD; } - + bool inside(Int count) const { return evenodd() ? count % 2 : count != 0; } - + BaseLine Baseline() const { return baseline == DEFBASE ? defaultpen().baseline : baseline; } - + Transparency transp() const { return transparency.isdefault ? defaultpen().transparency : transparency; } - + string blend() const { return transparency.isdefault ? defaultpen().transparency.blend : transparency.blend; } - + double opacity() const { return transparency.isdefault ? defaultpen().transparency.opacity : transparency.opacity; } - + Int cap() const { return linecap == DEFCAP ? defaultpen().linecap : linecap; } - + Int join() const { return linejoin == DEFJOIN ? defaultpen().linejoin : linejoin; } - + double miter() const { return miterlimit == DEFMITER ? defaultpen().miterlimit : miterlimit; } - + overwrite_t Overwrite() const { return overwrite == DEFWRITE ? defaultpen().overwrite : overwrite; } - + ColorSpace colorspace() const { return color == DEFCOLOR ? defaultpen().color : color; } - + string hex() const { int n=ColorComponents[colorspace()]; ostringstream buf; buf.setf(std::ios::hex,std::ios::basefield); buf.fill('0'); - + switch(n) { case 0: break; - case 1: + case 1: buf << std::setw(2) << byte(gray()); break; case 3: @@ -552,52 +552,52 @@ public: } return buf.str(); } - + bool invisible() const {return colorspace() == INVISIBLE;} - + bool grayscale() const {return colorspace() == GRAYSCALE;} - + bool rgb() const {return colorspace() == RGB;} - + bool cmyk() const {return colorspace() == CMYK;} - + double gray() const {return color == DEFCOLOR ? defaultpen().grey : grey;} - + double red() const {return color == DEFCOLOR ? defaultpen().r : r;} - + double green() const {return color == DEFCOLOR ? defaultpen().g : g;} - + double blue() const {return color == DEFCOLOR ? defaultpen().b : b;} - + double cyan() const {return red();} - + double magenta() const {return green();} - + double yellow() const {return blue();} - + double black() const {return gray();} - + double rgbsaturation() const {return max(max(r,g),b);} - + double cmyksaturation() const {return max(rgbsaturation(),black());} - + void greytorgb() { r=g=b=grey; grey=0.0; color=RGB; } - + void rgbtogrey() { grey=0.299*r+0.587*g+0.114*b; // Standard YUV luminosity coefficients r=g=b=0.0; color=GRAYSCALE; } - + void greytocmyk() { grey=1.0-grey; r=g=b=0.0; color=CMYK; } - + void rgbtocmyk() { double sat=rgbsaturation(); grey=1.0-sat; @@ -623,48 +623,48 @@ public: cmyktorgb(); rgbtogrey(); } - + void togrey() { if(rgb()) rgbtogrey(); else if(cmyk()) cmyktogrey(); } - + void torgb() { if(cmyk()) cmyktorgb(); else if(grayscale()) greytorgb(); } - + void tocmyk() { if(rgb()) rgbtocmyk(); else if(grayscale()) greytocmyk(); } - + void settransparency(const pen& p) { transparency=p.transparency; } - + void setfont(const pen& p) { font=p.font; } - + void setfillrule(const pen& p) { fillrule=p.fillrule; } - + void convert() { if(settings::gray || settings::bw) { if(rgb()) rgbtogrey(); else if(cmyk()) cmyktogrey(); if(settings::bw) {grey=(grey == 1.0) ? 1.0 : 0.0;} - } + } else if(settings::rgb && cmyk()) cmyktorgb(); else if(settings::cmyk && rgb()) rgbtocmyk(); - } - + } + // Try to upgrade to the specified colorspace. bool promote(ColorSpace c) { if(color == c) return true; - + switch(color) { case PATTERN: case INVISIBLE: @@ -693,7 +693,7 @@ public: } return false; } - + friend pen operator * (double x, const pen& q) { pen p=q; if(x < 0.0) x = 0.0; @@ -728,17 +728,17 @@ public: } return p; } - + friend pen operator + (const pen& p, const pen& q) { pen P=p; pen Q=q; - + if(P.color == PATTERN && P.pattern.empty()) P.color=DEFCOLOR; ColorSpace colorspace=(ColorSpace) max((Int) P.color,(Int) Q.color); - + if(!(p.transparency.isdefault && q.transparency.isdefault)) P.transparency.opacity=max(p.opacity(),q.opacity()); - + switch(colorspace) { case PATTERN: case INVISIBLE: @@ -750,27 +750,27 @@ public: P.greyrange(); break; } - + case RGB: { if(P.color == GRAYSCALE) P.greytorgb(); else if(Q.color == GRAYSCALE) Q.greytorgb(); - + P.r += Q.r; P.g += Q.g; P.b += Q.b; P.rgbrange(); break; } - + case CMYK: { if(P.color == GRAYSCALE) P.greytocmyk(); else if(Q.color == GRAYSCALE) Q.greytocmyk(); - + if(P.color == RGB) P.rgbtocmyk(); else if(Q.color == RGB) Q.rgbtocmyk(); - + P.r += Q.r; P.g += Q.g; P.b += Q.b; @@ -779,7 +779,7 @@ public: break; } } - + return pen(q.line.isdefault ? p.line : q.line, q.linewidth == DEFWIDTH ? p.linewidth : q.linewidth, q.P.empty() ? p.P : q.P, @@ -801,10 +801,10 @@ public: friend pen interpolate(const pen& p, const pen& q, double t) { pen P=p; pen Q=q; - + if(P.color == PATTERN && P.pattern.empty()) P.color=DEFCOLOR; ColorSpace colorspace=(ColorSpace) max((Int) P.color,(Int) Q.color); - + switch(colorspace) { case PATTERN: case INVISIBLE: @@ -817,24 +817,24 @@ public: else if(Q.color == GRAYSCALE) Q.greytorgb(); break; } - + case CMYK: { if(P.color == GRAYSCALE) P.greytocmyk(); else if(Q.color == GRAYSCALE) Q.greytocmyk(); - + if(P.color == RGB) P.rgbtocmyk(); else if(Q.color == RGB) Q.rgbtocmyk(); break; } } - + return (1-t)*P+t*Q; } friend bool operator == (const pen& p, const pen& q) { - return *(p.linetype()) == *(q.linetype()) - && p.width() == q.width() + return *(p.linetype()) == *(q.linetype()) + && p.width() == q.width() && p.Path() == q.Path() && p.Font() == q.Font() && p.Lineskip() == q.Lineskip() @@ -854,11 +854,11 @@ public: && p.Overwrite() == q.Overwrite() && p.t == q.t; } - + friend bool operator != (const pen& p, const pen& q) { return !(p == q); } - + friend ostream& operator << (ostream& out, const pen& p) { out << "("; if(p.line.isdefault) @@ -892,10 +892,10 @@ public: else if(p.color == GRAYSCALE) out << ", gray=" << p.grey; else if(p.color == RGB) - out << ", red=" << p.red() << ", green=" << p.green() + out << ", red=" << p.red() << ", green=" << p.green() << ", blue=" << p.blue(); else if(p.color == CMYK) - out << ", cyan=" << p.cyan() << ", magenta=" << p.magenta() + out << ", cyan=" << p.cyan() << ", magenta=" << p.magenta() << ", yellow=" << p.yellow() << ", black=" << p.black(); if(p.pattern != DEFPAT) out << ", pattern=" << "\"" << p.pattern << "\""; @@ -912,14 +912,14 @@ public: if(!p.t.isNull()) out << ", transform=" << p.t; out << ")"; - + return out; } const transform getTransform() const { return t.isNull() ? defaultpen().t : t; } - + // The bounds of the circle or ellipse the pen describes. bbox bounds() const { @@ -927,9 +927,9 @@ public: pair shift; if(!P.empty()) return P.bounds(); - + transform t=getTransform(); - + if(t.isIdentity()) { maxx = 1; maxy = 1; @@ -963,7 +963,7 @@ public: } }; - + pen transformed(const transform& t, const pen &p); } -- cgit v1.2.3