Export layer collections through paint renderer
This commit is contained in:
@@ -41,6 +41,11 @@ struct DocumentCubeFaceExportPayload {
|
||||
std::span<const std::byte> bytes;
|
||||
};
|
||||
|
||||
struct DocumentExportCollectionPngPayload {
|
||||
std::string path_suffix;
|
||||
std::span<const std::byte> bytes;
|
||||
};
|
||||
|
||||
struct DocumentExportSuggestedName {
|
||||
std::string name;
|
||||
};
|
||||
@@ -190,6 +195,16 @@ public:
|
||||
virtual void publish_exported_image(std::string_view path) = 0;
|
||||
};
|
||||
|
||||
class DocumentExportCollectionWriteServices {
|
||||
public:
|
||||
virtual ~DocumentExportCollectionWriteServices() = default;
|
||||
|
||||
virtual pp::foundation::Status write_binary_file(
|
||||
std::string_view path,
|
||||
std::span<const std::byte> bytes) = 0;
|
||||
virtual void publish_exported_image(std::string_view path) = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] constexpr DocumentExportStartDecision plan_document_export_start(
|
||||
bool requires_license,
|
||||
bool license_valid,
|
||||
@@ -608,6 +623,41 @@ document_cube_face_export_names() noexcept
|
||||
return pp::foundation::Result<DocumentCubeFaceExportTarget>::success(std::move(target));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::string document_export_two_digit_index(std::size_t index)
|
||||
{
|
||||
auto value = std::to_string(index);
|
||||
if (value.size() < 2U) {
|
||||
value.insert(value.begin(), '0');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::string make_document_layer_export_path_suffix(
|
||||
std::size_t layer_index,
|
||||
std::string_view layer_name)
|
||||
{
|
||||
std::string suffix;
|
||||
const auto index = document_export_two_digit_index(layer_index);
|
||||
suffix.reserve(10U + index.size() + layer_name.size());
|
||||
suffix += "-layer";
|
||||
suffix += index;
|
||||
suffix += "-";
|
||||
suffix += layer_name;
|
||||
suffix += ".png";
|
||||
return suffix;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::string make_document_animation_frame_export_path_suffix(std::size_t frame_index)
|
||||
{
|
||||
std::string suffix;
|
||||
const auto index = document_export_two_digit_index(frame_index);
|
||||
suffix.reserve(5U + index.size());
|
||||
suffix += "-";
|
||||
suffix += index;
|
||||
suffix += ".png";
|
||||
return suffix;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Result<DocumentExportSuggestedName> make_document_export_suggested_name(
|
||||
std::string_view document_name,
|
||||
std::string_view suffix)
|
||||
@@ -656,6 +706,41 @@ document_cube_face_export_names() noexcept
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_document_export_collection_write(
|
||||
const DocumentExportCollectionTarget& target,
|
||||
std::span<const DocumentExportCollectionPngPayload> payloads,
|
||||
DocumentExportCollectionWriteServices& services)
|
||||
{
|
||||
if (target.stem_path.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("export collection target requires a stem path");
|
||||
}
|
||||
|
||||
if (payloads.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("export collection payloads must not be empty");
|
||||
}
|
||||
|
||||
for (const auto& payload : payloads) {
|
||||
if (payload.path_suffix.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("export collection payload suffix must not be empty");
|
||||
}
|
||||
if (payload.bytes.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("export collection payload must not be empty");
|
||||
}
|
||||
|
||||
std::string path;
|
||||
path.reserve(target.stem_path.size() + payload.path_suffix.size());
|
||||
path += target.stem_path;
|
||||
path += payload.path_suffix;
|
||||
const auto write_status = services.write_binary_file(path, payload.bytes);
|
||||
if (!write_status.ok()) {
|
||||
return write_status;
|
||||
}
|
||||
services.publish_exported_image(path);
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_document_export_file(
|
||||
const DocumentExportFileTarget& target,
|
||||
DocumentExportServices& services)
|
||||
|
||||
Reference in New Issue
Block a user