From 5425388e6075ad72914324069fb3c6a1eec8677c Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Thu, 15 Apr 2021 17:21:07 +0200 Subject: GPencil: Fix unreported error exporting big files in PDF The exporting was creating a pdf state for each stroke, but this was necessary only for strokes with opacity. Now, the state is only created when needed and remove the state variable from class. Also, avoid exporting invisible strokes. --- .../io/gpencil/intern/gpencil_io_export_pdf.cc | 39 ++++++++++++++++------ .../io/gpencil/intern/gpencil_io_export_pdf.hh | 2 -- 2 files changed, 28 insertions(+), 13 deletions(-) (limited to 'source/blender/io') diff --git a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc index 9b2dc6d12a3..11278a3ccd7 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc +++ b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc @@ -69,7 +69,6 @@ GpencilExporterPDF::GpencilExporterPDF(const char *filename, const GpencilIOPara pdf_ = nullptr; page_ = nullptr; - gstate_ = nullptr; } bool GpencilExporterPDF::new_document() @@ -169,15 +168,27 @@ void GpencilExporterPDF::export_gpencil_layers() if (!ED_gpencil_stroke_material_visible(ob, gps)) { continue; } - /* Duplicate the stroke to apply any layer thickness change. */ - bGPDstroke *gps_duplicate = BKE_gpencil_stroke_duplicate(gps, true, false); - MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, - gps_duplicate->mat_nr + 1); + /* Skip invisible lines. */ + const float fill_opacity = fill_color_[3] * gpl->opacity; + const float stroke_opacity = stroke_color_[3] * stroke_average_opacity_get() * + gpl->opacity; + if ((fill_opacity < GPENCIL_ALPHA_OPACITY_THRESH) && + (stroke_opacity < GPENCIL_ALPHA_OPACITY_THRESH)) { + continue; + } + MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, gps->mat_nr + 1); const bool is_stroke = ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) && (gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH)); const bool is_fill = ((gp_style->flag & GP_MATERIAL_FILL_SHOW) && (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH)); + + if ((!is_stroke) && (!is_fill)) { + continue; + } + + /* Duplicate the stroke to apply any layer thickness change. */ + bGPDstroke *gps_duplicate = BKE_gpencil_stroke_duplicate(gps, true, false); prepare_stroke_export_colors(ob, gps_duplicate); /* Apply layer thickness change. */ @@ -283,29 +294,35 @@ void GpencilExporterPDF::color_set(bGPDlayer *gpl, const bool do_fill) { const float fill_opacity = fill_color_[3] * gpl->opacity; const float stroke_opacity = stroke_color_[3] * stroke_average_opacity_get() * gpl->opacity; + const bool need_state = (do_fill && fill_opacity < 1.0f) || (stroke_opacity < 1.0f); HPDF_Page_GSave(page_); - gstate_ = HPDF_CreateExtGState(pdf_); + HPDF_ExtGState gstate = (need_state) ? HPDF_CreateExtGState(pdf_) : nullptr; float col[3]; if (do_fill) { interp_v3_v3v3(col, fill_color_, gpl->tintcolor, gpl->tintcolor[3]); linearrgb_to_srgb_v3_v3(col, col); CLAMP3(col, 0.0f, 1.0f); - - HPDF_ExtGState_SetAlphaFill(gstate_, clamp_f(fill_opacity, 0.0f, 1.0f)); HPDF_Page_SetRGBFill(page_, col[0], col[1], col[2]); + if (gstate) { + HPDF_ExtGState_SetAlphaFill(gstate, clamp_f(fill_opacity, 0.0f, 1.0f)); + } } else { interp_v3_v3v3(col, stroke_color_, gpl->tintcolor, gpl->tintcolor[3]); linearrgb_to_srgb_v3_v3(col, col); CLAMP3(col, 0.0f, 1.0f); - HPDF_ExtGState_SetAlphaFill(gstate_, clamp_f(stroke_opacity, 0.0f, 1.0f)); - HPDF_ExtGState_SetAlphaStroke(gstate_, clamp_f(stroke_opacity, 0.0f, 1.0f)); HPDF_Page_SetRGBFill(page_, col[0], col[1], col[2]); HPDF_Page_SetRGBStroke(page_, col[0], col[1], col[2]); + if (gstate) { + HPDF_ExtGState_SetAlphaFill(gstate, clamp_f(stroke_opacity, 0.0f, 1.0f)); + HPDF_ExtGState_SetAlphaStroke(gstate, clamp_f(stroke_opacity, 0.0f, 1.0f)); + } + } + if (gstate) { + HPDF_Page_SetExtGState(page_, gstate); } - HPDF_Page_SetExtGState(page_, gstate_); } } // namespace blender::io::gpencil diff --git a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.hh b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.hh index 20970151344..89d97f79783 100644 --- a/source/blender/io/gpencil/intern/gpencil_io_export_pdf.hh +++ b/source/blender/io/gpencil/intern/gpencil_io_export_pdf.hh @@ -49,8 +49,6 @@ class GpencilExporterPDF : public GpencilExporter { HPDF_Doc pdf_; /* PDF page. */ HPDF_Page page_; - /* State. */ - HPDF_ExtGState gstate_; bool create_document(); bool add_page(); -- cgit v1.2.3