Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/io')
-rw-r--r--source/blender/editors/io/CMakeLists.txt15
-rw-r--r--source/blender/editors/io/io_gpencil.h45
-rw-r--r--source/blender/editors/io/io_gpencil_export.c432
-rw-r--r--source/blender/editors/io/io_gpencil_import.c195
-rw-r--r--source/blender/editors/io/io_gpencil_utils.c64
-rw-r--r--source/blender/editors/io/io_ops.c11
6 files changed, 762 insertions, 0 deletions
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index e7effd05d34..44b5f85050f 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
../../depsgraph
../../io/alembic
../../io/collada
+ ../../io/gpencil
../../io/usd
../../makesdna
../../makesrna
@@ -39,12 +40,16 @@ set(SRC
io_alembic.c
io_cache.c
io_collada.c
+ io_gpencil_export.c
+ io_gpencil_import.c
+ io_gpencil_utils.c
io_ops.c
io_usd.c
io_alembic.h
io_cache.h
io_collada.h
+ io_gpencil.h
io_ops.h
io_usd.h
)
@@ -79,4 +84,14 @@ if(WITH_INTERNATIONAL)
add_definitions(-DWITH_INTERNATIONAL)
endif()
+if(WITH_PUGIXML)
+ add_definitions(-DWITH_PUGIXML)
+endif()
+
+if(WITH_HARU)
+ add_definitions(-DWITH_HARU)
+endif()
+
+list(APPEND LIB bf_gpencil)
+
blender_add_lib(bf_editor_io "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/source/blender/editors/io/io_gpencil.h b/source/blender/editors/io/io_gpencil.h
new file mode 100644
index 00000000000..98cb8b13310
--- /dev/null
+++ b/source/blender/editors/io/io_gpencil.h
@@ -0,0 +1,45 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+#ifndef __IO_GPENCIL_H__
+#define __IO_GPENCIL_H__
+
+/** \file
+ * \ingroup editor/io
+ */
+
+struct ARegion;
+struct bContext;
+struct View3D;
+struct wmOperator;
+struct wmOperatorType;
+
+void WM_OT_gpencil_import_svg(struct wmOperatorType *ot);
+
+#ifdef WITH_PUGIXML
+void WM_OT_gpencil_export_svg(struct wmOperatorType *ot);
+#endif
+#ifdef WITH_HARU
+void WM_OT_gpencil_export_pdf(struct wmOperatorType *ot);
+#endif
+
+struct ARegion *get_invoke_region(struct bContext *C);
+struct View3D *get_invoke_view3d(struct bContext *C);
+
+#endif /* __IO_GPENCIL_H__ */
diff --git a/source/blender/editors/io/io_gpencil_export.c b/source/blender/editors/io/io_gpencil_export.c
new file mode 100644
index 00000000000..10e4e598bad
--- /dev/null
+++ b/source/blender/editors/io/io_gpencil_export.c
@@ -0,0 +1,432 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup editor/io
+ */
+
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+
+#include "DNA_gpencil_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_gpencil.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
+#include "BKE_screen.h"
+
+#include "BLT_translation.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "io_gpencil.h"
+
+#include "gpencil_io.h"
+
+#if defined(WITH_PUGIXML) || defined(WITH_HARU)
+/* Definition of enum elements to export. */
+/* Common props for exporting. */
+static void gpencil_export_common_props_definition(wmOperatorType *ot)
+{
+ static const EnumPropertyItem select_items[] = {
+ {GP_EXPORT_ACTIVE, "ACTIVE", 0, "Active", "Include only the active object"},
+ {GP_EXPORT_SELECTED, "SELECTED", 0, "Selected", "Include selected objects"},
+ {GP_EXPORT_VISIBLE, "VISIBLE", 0, "Visible", "Include all visible objects"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ RNA_def_boolean(ot->srna, "use_fill", true, "Fill", "Export strokes with fill enabled");
+ RNA_def_enum(ot->srna,
+ "selected_object_type",
+ select_items,
+ GP_EXPORT_SELECTED,
+ "Object",
+ "Which objects to include in the export");
+ RNA_def_float(ot->srna,
+ "stroke_sample",
+ 0.0f,
+ 0.0f,
+ 100.0f,
+ "Sampling",
+ "Precision of stroke sampling. Low values mean a more precise result, and zero "
+ "disables sampling",
+ 0.0f,
+ 100.0f);
+ RNA_def_boolean(ot->srna,
+ "use_normalized_thickness",
+ false,
+ "Normalize",
+ "Export strokes with constant thickness");
+}
+
+static void set_export_filepath(bContext *C, wmOperator *op, const char *extension)
+{
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ Main *bmain = CTX_data_main(C);
+ char filepath[FILE_MAX];
+
+ if (BKE_main_blendfile_path(bmain)[0] == '\0') {
+ BLI_strncpy(filepath, "untitled", sizeof(filepath));
+ }
+ else {
+ BLI_strncpy(filepath, BKE_main_blendfile_path(bmain), sizeof(filepath));
+ }
+
+ BLI_path_extension_replace(filepath, sizeof(filepath), extension);
+ RNA_string_set(op->ptr, "filepath", filepath);
+ }
+}
+#endif
+
+/* <-------- SVG single frame export. --------> */
+#ifdef WITH_PUGIXML
+static bool wm_gpencil_export_svg_common_check(bContext *UNUSED(C), wmOperator *op)
+{
+ char filepath[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filepath);
+
+ if (!BLI_path_extension_check(filepath, ".svg")) {
+ BLI_path_extension_ensure(filepath, FILE_MAX, ".svg");
+ RNA_string_set(op->ptr, "filepath", filepath);
+ return true;
+ }
+
+ return false;
+}
+
+static int wm_gpencil_export_svg_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ set_export_filepath(C, op, ".svg");
+
+ WM_event_add_fileselect(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int wm_gpencil_export_svg_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = CTX_data_active_object(C);
+
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ BKE_report(op->reports, RPT_ERROR, "No filename given");
+ return OPERATOR_CANCELLED;
+ }
+
+ ARegion *region = get_invoke_region(C);
+ if (region == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "Unable to find valid 3D View area");
+ return OPERATOR_CANCELLED;
+ }
+ View3D *v3d = get_invoke_view3d(C);
+
+ char filename[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filename);
+
+ const bool use_fill = RNA_boolean_get(op->ptr, "use_fill");
+ const bool use_norm_thickness = RNA_boolean_get(op->ptr, "use_normalized_thickness");
+ const eGpencilExportSelect select_mode = RNA_enum_get(op->ptr, "selected_object_type");
+
+ const bool use_clip_camera = RNA_boolean_get(op->ptr, "use_clip_camera");
+
+ /* Set flags. */
+ int flag = 0;
+ SET_FLAG_FROM_TEST(flag, use_fill, GP_EXPORT_FILL);
+ SET_FLAG_FROM_TEST(flag, use_norm_thickness, GP_EXPORT_NORM_THICKNESS);
+ SET_FLAG_FROM_TEST(flag, use_clip_camera, GP_EXPORT_CLIP_CAMERA);
+
+ GpencilIOParams params = {.C = C,
+ .region = region,
+ .v3d = v3d,
+ .ob = ob,
+ .mode = GP_EXPORT_TO_SVG,
+ .frame_start = CFRA,
+ .frame_end = CFRA,
+ .frame_cur = CFRA,
+ .flag = flag,
+ .scale = 1.0f,
+ .select_mode = select_mode,
+ .frame_mode = GP_EXPORT_FRAME_ACTIVE,
+ .stroke_sample = RNA_float_get(op->ptr, "stroke_sample"),
+ .resolution = 1.0f};
+
+ /* Do export. */
+ WM_cursor_wait(true);
+ const bool done = gpencil_io_export(filename, &params);
+ WM_cursor_wait(false);
+
+ if (!done) {
+ BKE_report(op->reports, RPT_WARNING, "Unable to export SVG");
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+static void ui_gpencil_export_svg_settings(uiLayout *layout, PointerRNA *imfptr)
+{
+ uiLayout *box, *row;
+
+ uiLayoutSetPropSep(layout, true);
+ uiLayoutSetPropDecorate(layout, false);
+
+ box = uiLayoutBox(layout);
+
+ row = uiLayoutRow(box, false);
+ uiItemL(row, IFACE_("Scene Options"), ICON_NONE);
+
+ row = uiLayoutRow(box, false);
+ uiItemR(row, imfptr, "selected_object_type", 0, NULL, ICON_NONE);
+
+ box = uiLayoutBox(layout);
+ row = uiLayoutRow(box, false);
+ uiItemL(row, IFACE_("Export Options"), ICON_NONE);
+
+ uiLayout *col = uiLayoutColumn(box, false);
+ uiItemR(col, imfptr, "stroke_sample", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "use_fill", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "use_normalized_thickness", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "use_clip_camera", 0, NULL, ICON_NONE);
+}
+
+static void wm_gpencil_export_svg_draw(bContext *UNUSED(C), wmOperator *op)
+{
+ PointerRNA ptr;
+
+ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+
+ ui_gpencil_export_svg_settings(op->layout, &ptr);
+}
+
+static bool wm_gpencil_export_svg_poll(bContext *C)
+{
+ if ((CTX_wm_window(C) == NULL) || (CTX_data_mode_enum(C) != CTX_MODE_OBJECT)) {
+ return false;
+ }
+
+ return true;
+}
+
+void WM_OT_gpencil_export_svg(wmOperatorType *ot)
+{
+ ot->name = "Export to SVG";
+ ot->description = "Export grease pencil to SVG";
+ ot->idname = "WM_OT_gpencil_export_svg";
+
+ ot->invoke = wm_gpencil_export_svg_invoke;
+ ot->exec = wm_gpencil_export_svg_exec;
+ ot->poll = wm_gpencil_export_svg_poll;
+ ot->ui = wm_gpencil_export_svg_draw;
+ ot->check = wm_gpencil_export_svg_common_check;
+
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_OBJECT_IO,
+ FILE_BLENDER,
+ FILE_SAVE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_ALPHA);
+
+ gpencil_export_common_props_definition(ot);
+
+ RNA_def_boolean(ot->srna,
+ "use_clip_camera",
+ false,
+ "Clip Camera",
+ "Clip drawings to camera size when export in camera view");
+}
+#endif
+
+/* <-------- PDF single frame export. --------> */
+#ifdef WITH_HARU
+static bool wm_gpencil_export_pdf_common_check(bContext *UNUSED(C), wmOperator *op)
+{
+
+ char filepath[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filepath);
+
+ if (!BLI_path_extension_check(filepath, ".pdf")) {
+ BLI_path_extension_ensure(filepath, FILE_MAX, ".pdf");
+ RNA_string_set(op->ptr, "filepath", filepath);
+ return true;
+ }
+
+ return false;
+}
+
+static int wm_gpencil_export_pdf_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ set_export_filepath(C, op, ".pdf");
+
+ WM_event_add_fileselect(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int wm_gpencil_export_pdf_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = CTX_data_active_object(C);
+
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ BKE_report(op->reports, RPT_ERROR, "No filename given");
+ return OPERATOR_CANCELLED;
+ }
+
+ ARegion *region = get_invoke_region(C);
+ if (region == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "Unable to find valid 3D View area");
+ return OPERATOR_CANCELLED;
+ }
+ View3D *v3d = get_invoke_view3d(C);
+
+ char filename[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filename);
+
+ const bool use_fill = RNA_boolean_get(op->ptr, "use_fill");
+ const bool use_norm_thickness = RNA_boolean_get(op->ptr, "use_normalized_thickness");
+ const short select_mode = RNA_enum_get(op->ptr, "selected_object_type");
+ const short frame_mode = RNA_enum_get(op->ptr, "frame_mode");
+
+ /* Set flags. */
+ int flag = 0;
+ SET_FLAG_FROM_TEST(flag, use_fill, GP_EXPORT_FILL);
+ SET_FLAG_FROM_TEST(flag, use_norm_thickness, GP_EXPORT_NORM_THICKNESS);
+
+ GpencilIOParams params = {.C = C,
+ .region = region,
+ .v3d = v3d,
+ .ob = ob,
+ .mode = GP_EXPORT_TO_PDF,
+ .frame_start = SFRA,
+ .frame_end = EFRA,
+ .frame_cur = CFRA,
+ .flag = flag,
+ .scale = 1.0f,
+ .select_mode = select_mode,
+ .frame_mode = frame_mode,
+ .stroke_sample = RNA_float_get(op->ptr, "stroke_sample"),
+ .resolution = 1.0f};
+
+ /* Do export. */
+ WM_cursor_wait(true);
+ const bool done = gpencil_io_export(filename, &params);
+ WM_cursor_wait(false);
+
+ if (!done) {
+ BKE_report(op->reports, RPT_WARNING, "Unable to export PDF");
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+static void ui_gpencil_export_pdf_settings(uiLayout *layout, PointerRNA *imfptr)
+{
+ uiLayout *box, *row, *col, *sub;
+
+ uiLayoutSetPropSep(layout, true);
+ uiLayoutSetPropDecorate(layout, false);
+
+ box = uiLayoutBox(layout);
+
+ row = uiLayoutRow(box, false);
+ uiItemL(row, IFACE_("Scene Options"), ICON_NONE);
+
+ row = uiLayoutRow(box, false);
+ uiItemR(row, imfptr, "selected_object_type", 0, NULL, ICON_NONE);
+
+ box = uiLayoutBox(layout);
+ row = uiLayoutRow(box, false);
+ uiItemL(row, IFACE_("Export Options"), ICON_NONE);
+
+ col = uiLayoutColumn(box, false);
+ sub = uiLayoutColumn(col, true);
+ uiItemR(sub, imfptr, "frame_mode", 0, IFACE_("Frame"), ICON_NONE);
+
+ uiLayoutSetPropSep(box, true);
+
+ sub = uiLayoutColumn(col, true);
+ uiItemR(sub, imfptr, "stroke_sample", 0, NULL, ICON_NONE);
+ uiItemR(sub, imfptr, "use_fill", 0, NULL, ICON_NONE);
+ uiItemR(sub, imfptr, "use_normalized_thickness", 0, NULL, ICON_NONE);
+}
+
+static void wm_gpencil_export_pdf_draw(bContext *UNUSED(C), wmOperator *op)
+{
+ PointerRNA ptr;
+
+ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+
+ ui_gpencil_export_pdf_settings(op->layout, &ptr);
+}
+
+static bool wm_gpencil_export_pdf_poll(bContext *C)
+{
+ if ((CTX_wm_window(C) == NULL) || (CTX_data_mode_enum(C) != CTX_MODE_OBJECT)) {
+ return false;
+ }
+
+ return true;
+}
+
+void WM_OT_gpencil_export_pdf(wmOperatorType *ot)
+{
+ ot->name = "Export to PDF";
+ ot->description = "Export grease pencil to PDF";
+ ot->idname = "WM_OT_gpencil_export_pdf";
+
+ ot->invoke = wm_gpencil_export_pdf_invoke;
+ ot->exec = wm_gpencil_export_pdf_exec;
+ ot->poll = wm_gpencil_export_pdf_poll;
+ ot->ui = wm_gpencil_export_pdf_draw;
+ ot->check = wm_gpencil_export_pdf_common_check;
+
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_OBJECT_IO,
+ FILE_BLENDER,
+ FILE_SAVE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_SHOW_PROPS,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_ALPHA);
+
+ static const EnumPropertyItem gpencil_export_frame_items[] = {
+ {GP_EXPORT_FRAME_ACTIVE, "ACTIVE", 0, "Active", "Include only active frame"},
+ {GP_EXPORT_FRAME_SELECTED, "SELECTED", 0, "Selected", "Include selected frames"},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ gpencil_export_common_props_definition(ot);
+ ot->prop = RNA_def_enum(ot->srna,
+ "frame_mode",
+ gpencil_export_frame_items,
+ GP_EXPORT_ACTIVE,
+ "Frames",
+ "Which frames to include in the export");
+}
+#endif
diff --git a/source/blender/editors/io/io_gpencil_import.c b/source/blender/editors/io/io_gpencil_import.c
new file mode 100644
index 00000000000..9768da85940
--- /dev/null
+++ b/source/blender/editors/io/io_gpencil_import.c
@@ -0,0 +1,195 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup editor/io
+ */
+
+#include "BLI_path_util.h"
+
+#include "DNA_gpencil_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_context.h"
+#include "BKE_gpencil.h"
+#include "BKE_report.h"
+
+#include "BLT_translation.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "ED_gpencil.h"
+
+#include "io_gpencil.h"
+
+#include "gpencil_io.h"
+
+/* <-------- SVG single frame import. --------> */
+static bool wm_gpencil_import_svg_common_check(bContext *UNUSED(C), wmOperator *op)
+{
+
+ char filepath[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filepath);
+
+ if (!BLI_path_extension_check(filepath, ".svg")) {
+ BLI_path_extension_ensure(filepath, FILE_MAX, ".svg");
+ RNA_string_set(op->ptr, "filepath", filepath);
+ return true;
+ }
+
+ return false;
+}
+
+static int wm_gpencil_import_svg_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ WM_event_add_fileselect(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int wm_gpencil_import_svg_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+
+ if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
+ BKE_report(op->reports, RPT_ERROR, "No filename given");
+ return OPERATOR_CANCELLED;
+ }
+
+ ARegion *region = get_invoke_region(C);
+ if (region == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "Unable to find valid 3D View area");
+ return OPERATOR_CANCELLED;
+ }
+ View3D *v3d = get_invoke_view3d(C);
+
+ char filename[FILE_MAX];
+ RNA_string_get(op->ptr, "filepath", filename);
+
+ /* Set flags. */
+ int flag = 0;
+
+ const int resolution = RNA_int_get(op->ptr, "resolution");
+ const float scale = RNA_float_get(op->ptr, "scale");
+
+ GpencilIOParams params = {
+ .C = C,
+ .region = region,
+ .v3d = v3d,
+ .ob = NULL,
+ .mode = GP_IMPORT_FROM_SVG,
+ .frame_start = CFRA,
+ .frame_end = CFRA,
+ .frame_cur = CFRA,
+ .flag = flag,
+ .scale = scale,
+ .select_mode = 0,
+ .frame_mode = 0,
+ .stroke_sample = 0.0f,
+ .resolution = resolution,
+ };
+
+ /* Do Import. */
+ WM_cursor_wait(1);
+ const bool done = gpencil_io_import(filename, &params);
+ WM_cursor_wait(0);
+
+ if (!done) {
+ BKE_report(op->reports, RPT_WARNING, "Unable to import SVG");
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+static void ui_gpencil_import_svg_settings(uiLayout *layout, PointerRNA *imfptr)
+{
+ uiLayoutSetPropSep(layout, true);
+ uiLayoutSetPropDecorate(layout, false);
+ uiLayout *col = uiLayoutColumn(layout, false);
+ uiItemR(col, imfptr, "resolution", 0, NULL, ICON_NONE);
+ uiItemR(col, imfptr, "scale", 0, NULL, ICON_NONE);
+}
+
+static void wm_gpencil_import_svg_draw(bContext *UNUSED(C), wmOperator *op)
+{
+ PointerRNA ptr;
+ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
+
+ ui_gpencil_import_svg_settings(op->layout, &ptr);
+}
+
+static bool wm_gpencil_import_svg_poll(bContext *C)
+{
+ if ((CTX_wm_window(C) == NULL) || (CTX_data_mode_enum(C) != CTX_MODE_OBJECT)) {
+ return false;
+ }
+
+ return true;
+}
+
+void WM_OT_gpencil_import_svg(wmOperatorType *ot)
+{
+ ot->name = "Import SVG";
+ ot->description = "Import SVG into grease pencil";
+ ot->idname = "WM_OT_gpencil_import_svg";
+
+ ot->invoke = wm_gpencil_import_svg_invoke;
+ ot->exec = wm_gpencil_import_svg_exec;
+ ot->poll = wm_gpencil_import_svg_poll;
+ ot->ui = wm_gpencil_import_svg_draw;
+ ot->check = wm_gpencil_import_svg_common_check;
+
+ WM_operator_properties_filesel(ot,
+ FILE_TYPE_OBJECT_IO,
+ FILE_BLENDER,
+ FILE_OPENFILE,
+ WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_SHOW_PROPS,
+ FILE_DEFAULTDISPLAY,
+ FILE_SORT_DEFAULT);
+
+ RNA_def_int(ot->srna,
+ "resolution",
+ 10,
+ 1,
+ 30,
+ "Resolution",
+ "Resolution of the generated strokes",
+ 1,
+ 20);
+
+ RNA_def_float(ot->srna,
+ "scale",
+ 10.0f,
+ 0.001f,
+ 100.0f,
+ "Scale",
+ "Scale of the final strokes",
+ 0.001f,
+ 100.0f);
+}
diff --git a/source/blender/editors/io/io_gpencil_utils.c b/source/blender/editors/io/io_gpencil_utils.c
new file mode 100644
index 00000000000..259a669519a
--- /dev/null
+++ b/source/blender/editors/io/io_gpencil_utils.c
@@ -0,0 +1,64 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup editor/io
+ */
+
+#include "DNA_space_types.h"
+
+#include "BKE_context.h"
+#include "BKE_screen.h"
+
+#include "WM_api.h"
+
+#include "io_gpencil.h"
+
+ARegion *get_invoke_region(bContext *C)
+{
+ bScreen *screen = CTX_wm_screen(C);
+ if (screen == NULL) {
+ return NULL;
+ }
+ ScrArea *area = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0);
+ if (area == NULL) {
+ return NULL;
+ }
+
+ ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
+
+ return region;
+}
+
+View3D *get_invoke_view3d(bContext *C)
+{
+ bScreen *screen = CTX_wm_screen(C);
+ if (screen == NULL) {
+ return NULL;
+ }
+ ScrArea *area = BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0);
+ if (area == NULL) {
+ return NULL;
+ }
+ if (area) {
+ return area->spacedata.first;
+ }
+
+ return NULL;
+}
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index acb511a414d..9fa34a1c55d 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -38,6 +38,7 @@
#endif
#include "io_cache.h"
+#include "io_gpencil.h"
void ED_operatortypes_io(void)
{
@@ -54,6 +55,16 @@ void ED_operatortypes_io(void)
WM_operatortype_append(WM_OT_usd_export);
#endif
+ WM_operatortype_append(WM_OT_gpencil_import_svg);
+
+#ifdef WITH_PUGIXML
+ WM_operatortype_append(WM_OT_gpencil_export_svg);
+#endif
+
+#ifdef WITH_HARU
+ WM_operatortype_append(WM_OT_gpencil_export_pdf);
+#endif
+
WM_operatortype_append(CACHEFILE_OT_open);
WM_operatortype_append(CACHEFILE_OT_reload);
}