Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/gpencil/intern/gpencil_io_export_pdf.cc
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| filename_set(filename); | filename_set(filename); | ||||
| invert_axis_[0] = false; | invert_axis_[0] = false; | ||||
| invert_axis_[1] = false; | invert_axis_[1] = false; | ||||
| pdf_ = nullptr; | pdf_ = nullptr; | ||||
| page_ = nullptr; | page_ = nullptr; | ||||
| gstate_ = nullptr; | |||||
| } | } | ||||
| bool GpencilExporterPDF::new_document() | bool GpencilExporterPDF::new_document() | ||||
| { | { | ||||
| return create_document(); | return create_document(); | ||||
| } | } | ||||
| bool GpencilExporterPDF::add_newpage() | bool GpencilExporterPDF::add_newpage() | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd_eval->layers) { | ||||
| LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { | LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { | ||||
| if (gps->totpoints < 2) { | if (gps->totpoints < 2) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (!ED_gpencil_stroke_material_visible(ob, gps)) { | if (!ED_gpencil_stroke_material_visible(ob, gps)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* Duplicate the stroke to apply any layer thickness change. */ | /* Skip invisible lines. */ | ||||
| bGPDstroke *gps_duplicate = BKE_gpencil_stroke_duplicate(gps, true, false); | prepare_stroke_export_colors(ob, gps); | ||||
| MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, | const float fill_opacity = fill_color_[3] * gpl->opacity; | ||||
| gps_duplicate->mat_nr + 1); | 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) && | const bool is_stroke = ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) && | ||||
| (gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH)); | (gp_style->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) && | ||||
| (stroke_opacity > GPENCIL_ALPHA_OPACITY_THRESH)); | |||||
| const bool is_fill = ((gp_style->flag & GP_MATERIAL_FILL_SHOW) && | const bool is_fill = ((gp_style->flag & GP_MATERIAL_FILL_SHOW) && | ||||
| (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH)); | (gp_style->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH)); | ||||
| prepare_stroke_export_colors(ob, gps_duplicate); | |||||
| 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); | |||||
| /* Apply layer thickness change. */ | /* Apply layer thickness change. */ | ||||
| gps_duplicate->thickness += gpl->line_change; | gps_duplicate->thickness += gpl->line_change; | ||||
| /* Apply object scale to thickness. */ | /* Apply object scale to thickness. */ | ||||
| gps_duplicate->thickness *= mat4_to_scale(ob->obmat); | gps_duplicate->thickness *= mat4_to_scale(ob->obmat); | ||||
| CLAMP_MIN(gps_duplicate->thickness, 1.0f); | CLAMP_MIN(gps_duplicate->thickness, 1.0f); | ||||
| /* Fill. */ | /* Fill. */ | ||||
| if ((is_fill) && (params_.flag & GP_EXPORT_FILL)) { | if ((is_fill) && (params_.flag & GP_EXPORT_FILL)) { | ||||
| ▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Set color | * Set color | ||||
| * @param do_fill: True if the stroke is only fill | * @param do_fill: True if the stroke is only fill | ||||
| */ | */ | ||||
| void GpencilExporterPDF::color_set(bGPDlayer *gpl, const bool do_fill) | void GpencilExporterPDF::color_set(bGPDlayer *gpl, const bool do_fill) | ||||
| { | { | ||||
| const float fill_opacity = fill_color_[3] * gpl->opacity; | const float fill_opacity = fill_color_[3] * gpl->opacity; | ||||
| const float stroke_opacity = stroke_color_[3] * stroke_average_opacity_get() * 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_); | HPDF_Page_GSave(page_); | ||||
| gstate_ = HPDF_CreateExtGState(pdf_); | HPDF_ExtGState gstate = (need_state) ? HPDF_CreateExtGState(pdf_) : nullptr; | ||||
| float col[3]; | float col[3]; | ||||
| if (do_fill) { | if (do_fill) { | ||||
| interp_v3_v3v3(col, fill_color_, gpl->tintcolor, gpl->tintcolor[3]); | interp_v3_v3v3(col, fill_color_, gpl->tintcolor, gpl->tintcolor[3]); | ||||
| linearrgb_to_srgb_v3_v3(col, col); | linearrgb_to_srgb_v3_v3(col, col); | ||||
| CLAMP3(col, 0.0f, 1.0f); | 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]); | 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 { | else { | ||||
| interp_v3_v3v3(col, stroke_color_, gpl->tintcolor, gpl->tintcolor[3]); | interp_v3_v3v3(col, stroke_color_, gpl->tintcolor, gpl->tintcolor[3]); | ||||
| linearrgb_to_srgb_v3_v3(col, col); | linearrgb_to_srgb_v3_v3(col, col); | ||||
| CLAMP3(col, 0.0f, 1.0f); | 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_SetRGBFill(page_, col[0], col[1], col[2]); | ||||
| HPDF_Page_SetRGBStroke(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 | } // namespace blender::io::gpencil | ||||