From: ulferikson Date: Sun, 2 Jul 2006 12:50:47 +0000 (+0000) Subject: The stack of alphas must be pushed/poped for each bind/release pair; X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9eab7d65639a755bf6d319dcf7736d4d9b18a047;p=inkscape.git The stack of alphas must be pushed/poped for each bind/release pair; not only for those with an opacity set. --- diff --git a/src/extension/internal/pdf.cpp b/src/extension/internal/pdf.cpp index 0951d97f2..796e410cb 100644 --- a/src/extension/internal/pdf.cpp +++ b/src/extension/internal/pdf.cpp @@ -480,30 +480,14 @@ PrintPDF::bind(Inkscape::Extension::Print *mod, NRMatrix const *transform, float << transform->c[4] << " " << transform->c[5] << " cm\n"; - if (opacity!=1.0) { - float alpha = opacity * _pushed_alphas[_curr_alpha]; - - fprintf(stderr, "bind: opacity=%f, pushed=%f, alpha=%f\n", - opacity, _pushed_alphas[_curr_alpha], alpha); - - _curr_alpha++; - if (_curr_alpha >= _num_alphas) { - _num_alphas = _num_alphas*2; - _pushed_alphas = (float *) realloc(_pushed_alphas, _num_alphas*sizeof(float)); - } - _pushed_alphas[_curr_alpha] = alpha; - - PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate); - *pdf_alpha << "<< /Type /ExtGState\n"; - *pdf_alpha << " /ca " << alpha << "\n"; - *pdf_alpha << " /AIS false\n"; - *pdf_alpha << ">>\n"; - - *page_stream << pdf_alpha->get_name() - << " gs\n"; + float alpha = opacity * _pushed_alphas[_curr_alpha]; - pdf_file->end_resource(pdf_alpha); + _curr_alpha++; + if (_curr_alpha >= _num_alphas) { + _num_alphas = _num_alphas*2; + _pushed_alphas = (float *) realloc(_pushed_alphas, _num_alphas*sizeof(float)); } + _pushed_alphas[_curr_alpha] = alpha; return 1; } @@ -514,7 +498,8 @@ PrintPDF::release(Inkscape::Extension::Print *mod) if (!_stream) return 0; // XXX: fixme, returning -1 as unsigned. if (_bitmap) return 0; - _curr_alpha--; + if (_curr_alpha > 0) + _curr_alpha--; *page_stream << "Q\n"; @@ -542,23 +527,17 @@ PrintPDF::print_fill_alpha(SVGOStringStream &/*os*/, SPStyle const *const style, if (style->fill.type == SP_PAINT_TYPE_COLOR) { float alpha = 1.0; alpha *= SP_SCALE24_TO_FLOAT(style->fill_opacity.value); + alpha *= _pushed_alphas[_curr_alpha]; if (alpha != 1.0) { PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate); *pdf_alpha << "<< /Type /ExtGState\n"; - *pdf_alpha << " /ca " << alpha*_pushed_alphas[_curr_alpha] << "\n"; + *pdf_alpha << " /ca " << alpha << "\n"; *pdf_alpha << " /AIS false\n"; *pdf_alpha << ">>\n"; *page_stream << pdf_alpha->get_name() << " gs\n"; - - - fprintf(stderr, "print_fill_alpha: opacity=%f, fill-opacity=%f, pushed_alphas=%f ==> %f\n", - SP_SCALE24_TO_FLOAT(style->opacity.value), - SP_SCALE24_TO_FLOAT(style->fill_opacity.value), - _pushed_alphas[_curr_alpha], - alpha*_pushed_alphas[_curr_alpha]); pdf_file->end_resource(pdf_alpha); } @@ -586,7 +565,7 @@ PrintPDF::print_fill_alpha(SVGOStringStream &/*os*/, SPStyle const *const style, alpha *= lg->vector.stops[i].opacity; } - if (alpha != 1.0) { + if (alpha != 1.0 || _pushed_alphas[_curr_alpha] != 1.0) { PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate); *pdf_gstate << "<< /Type /ExtGState\n"; @@ -715,7 +694,7 @@ PrintPDF::print_fill_alpha(SVGOStringStream &/*os*/, SPStyle const *const style, alpha *= rg->vector.stops[i].opacity; } - if (alpha != 1.0) { + if (alpha != 1.0 || _pushed_alphas[_curr_alpha] != 1.0) { PdfObject *pdf_gstate = pdf_file->begin_resource(pdf_extgstate); *pdf_gstate << "<< /Type /ExtGState\n"; @@ -951,11 +930,12 @@ PrintPDF::print_stroke_style(SVGOStringStream &os, SPStyle const *style) float alpha = 1.0; alpha *= SP_SCALE24_TO_FLOAT(style->stroke_opacity.value); + alpha *= _pushed_alphas[_curr_alpha]; if (alpha != 1.0) { PdfObject *pdf_alpha = pdf_file->begin_resource(pdf_extgstate); *pdf_alpha << "<< /Type /ExtGState\n"; - *pdf_alpha << " /CA " << alpha*_pushed_alphas[_curr_alpha] << "\n"; + *pdf_alpha << " /CA " << alpha << "\n"; *pdf_alpha << " /AIS false\n"; *pdf_alpha << ">>\n";