mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
convert to CRLF line endings
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/keyword.hpp>
|
||||
#include <util/io/package.hpp>
|
||||
#include <script/scriptable.hpp>
|
||||
#include <script/scriptable.hpp>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/sstream.h>
|
||||
|
||||
@@ -145,20 +145,20 @@ KeywordP KeywordDataObject::getKeyword(const SetP& set) {
|
||||
|
||||
CardsOnClipboard::CardsOnClipboard(const SetP& set, const String id, const vector<CardP>& cards) {
|
||||
// Conversion to image file
|
||||
if (cards.size() < 6) {
|
||||
Image img;
|
||||
if (cards.size() == 1) {
|
||||
if (cards.size() < 6) {
|
||||
Image img;
|
||||
if (cards.size() == 1) {
|
||||
img = export_image(set, cards[0]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
img = export_image(set, cards);
|
||||
}
|
||||
String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png");
|
||||
img.SaveFile(temp_path, wxBITMAP_TYPE_PNG);
|
||||
wxFileDataObject* data = new wxFileDataObject();
|
||||
data->AddFile(temp_path);
|
||||
}
|
||||
String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png");
|
||||
img.SaveFile(temp_path, wxBITMAP_TYPE_PNG);
|
||||
wxFileDataObject* data = new wxFileDataObject();
|
||||
data->AddFile(temp_path);
|
||||
Add(data);
|
||||
}
|
||||
// Conversion to serialized card format
|
||||
// Conversion to serialized card format
|
||||
Add(new CardsDataObject(set, id, cards), true);
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ Image export_image(const SetP& set, const CardP& card, const bool write_metadata
|
||||
Image export_image(const SetP& set, const vector<CardP>& cards, const int padding = 2, const double global_zoom = 1.0, const bool use_zoom_setting = true, const bool use_rotation_setting = true, const bool use_bleed_setting = false);
|
||||
|
||||
/// Export the image of one or more cards to a given filename, using the app's zoom, rotation and bleed settings, and including metadata
|
||||
void export_image(const SetP& set, const CardP& card, const String& filename);
|
||||
void export_image(const SetP& set, const vector<CardP>& cards, const String& path, const String& filename_template, FilenameConflicts conflicts);
|
||||
void export_image(const SetP& set, const CardP& card, const String& filename);
|
||||
void export_image(const SetP& set, const vector<CardP>& cards, const String& path, const String& filename_template, FilenameConflicts conflicts);
|
||||
|
||||
/// Export a set to Magic Workstation format
|
||||
void export_mws(Window* parent, const SetP& set);
|
||||
|
||||
+68
-68
@@ -19,14 +19,14 @@
|
||||
#include <data/settings.hpp>
|
||||
#include <script/functions/json.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <render/card/viewer.hpp>
|
||||
#include <render/card/viewer.hpp>
|
||||
|
||||
class ZoomedUnrotatedDataViewer : public DataViewer {
|
||||
public:
|
||||
ZoomedUnrotatedDataViewer(double zoom) : zoom(zoom) {};
|
||||
virtual ~ZoomedUnrotatedDataViewer() {};
|
||||
Rotation getRotation() const override;
|
||||
private:
|
||||
Rotation getRotation() const override;
|
||||
private:
|
||||
double zoom;
|
||||
};
|
||||
|
||||
@@ -36,14 +36,14 @@ Rotation ZoomedUnrotatedDataViewer::getRotation() const {
|
||||
|
||||
// ----------------------------------------------------------------------------- : wxImage export
|
||||
|
||||
Image export_image(const SetP& set, const CardP& card, const bool write_metadata, const double zoom, const Radians angle_radians, const double bleed_pixels) {
|
||||
Image export_image(const SetP& set, const CardP& card, const bool write_metadata, const double zoom, const Radians angle_radians, const double bleed_pixels) {
|
||||
if (!set) throw Error(_("no set"));
|
||||
/// create and zoom
|
||||
/// create and zoom
|
||||
ZoomedUnrotatedDataViewer viewer = ZoomedUnrotatedDataViewer(zoom);
|
||||
viewer.setSet(set);
|
||||
viewer.setCard(card);
|
||||
RealSize size = viewer.getRotation().getExternalSize();
|
||||
int bleed = lround(bleed_pixels);
|
||||
int bleed = lround(bleed_pixels);
|
||||
Bitmap bitmap((int)size.width + 2 * bleed, (int)size.height + 2 * bleed);
|
||||
if (!bitmap.Ok()) throw InternalError(_("Unable to create bitmap"));
|
||||
wxMemoryDC dc;
|
||||
@@ -51,18 +51,18 @@ Image export_image(const SetP& set, const CardP& card, const bool write_metadata
|
||||
dc.SetDeviceOrigin(bleed, bleed);
|
||||
viewer.draw(dc);
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
Image img = bitmap.ConvertToImage();
|
||||
|
||||
/// rotate
|
||||
img = rotate_image(img, angle_radians);
|
||||
|
||||
/// add print bleed edge
|
||||
int width = img.GetWidth(), height = img.GetHeight();
|
||||
bleed = max(0, min(width-1, min(height-1, bleed)));
|
||||
Image img = bitmap.ConvertToImage();
|
||||
|
||||
/// rotate
|
||||
img = rotate_image(img, angle_radians);
|
||||
|
||||
/// add print bleed edge
|
||||
int width = img.GetWidth(), height = img.GetHeight();
|
||||
bleed = max(0, min(width-1, min(height-1, bleed)));
|
||||
if (size.width < bleed + 2 || size.height < bleed + 2) {
|
||||
queue_message(MESSAGE_ERROR, _("Image too small to add bleed edge"));
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
if (!img.HasAlpha()) img.InitAlpha();
|
||||
Byte* pixels = img.GetData();
|
||||
Byte* alpha = img.GetAlpha();
|
||||
@@ -126,17 +126,17 @@ Image export_image(const SetP& set, const CardP& card, const bool write_metadata
|
||||
pixels[3 * pixel + 2] = pixels[3 * mirror + 2];
|
||||
alpha[pixel] = alpha[mirror];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// add metadata
|
||||
}
|
||||
}
|
||||
|
||||
/// add metadata
|
||||
if (write_metadata) {
|
||||
String metadata = _("<mse-card-data>[");
|
||||
IndexMap<FieldP, ValueP>& card_data = card->data;
|
||||
boost::json::object cardv = mse_to_json(card, set.get());
|
||||
boost::json::object& cardv_data = cardv["data"].as_object();
|
||||
StyleSheetP stylesheet = set->stylesheetForP(card);
|
||||
if (!settings.stylesheetSettingsFor(*stylesheet).card_notes_export()) cardv["notes"] = "";
|
||||
if (!settings.stylesheetSettingsFor(*stylesheet).card_notes_export()) cardv["notes"] = "";
|
||||
// iterate over all image fields
|
||||
for(IndexMap<FieldP, ValueP>::iterator it = card_data.begin() ; it != card_data.end() ; ++it) {
|
||||
ImageValue* value = dynamic_cast<ImageValue*>(it->get());
|
||||
@@ -144,64 +144,64 @@ Image export_image(const SetP& set, const CardP& card, const bool write_metadata
|
||||
FieldP field = (*it)->fieldP;
|
||||
ImageStyle* style = dynamic_cast<ImageStyle*>(stylesheet->card_style.at(field->index).get());
|
||||
if (style) {
|
||||
style->update(set->getContext(card));
|
||||
// store the entire image in the metadata
|
||||
if (style->store_in_metadata()) {
|
||||
std::string bytes = style->getExternalImageString(set, value);
|
||||
cardv_data[field->name.ToStdString()] = bytes;
|
||||
}
|
||||
// store only crop coordinates
|
||||
else {
|
||||
style->update(set->getContext(card));
|
||||
// store the entire image in the metadata
|
||||
if (style->store_in_metadata()) {
|
||||
std::string bytes = style->getExternalImageString(set, value);
|
||||
cardv_data[field->name.ToStdString()] = bytes;
|
||||
}
|
||||
// store only crop coordinates
|
||||
else {
|
||||
std::string rect = style->getExternalRectString(zoom, angle_radians, bleed_pixels, width, height, 0);
|
||||
cardv_data[field->name.ToStdString()] = rect;
|
||||
cardv_data[field->name.ToStdString()] = rect;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
metadata += json_ugly_print(cardv) + _("]</mse-card-data>");
|
||||
img.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
Image export_image( const SetP& set, const vector<CardP>& cards,
|
||||
const int padding,
|
||||
const double global_zoom,
|
||||
const bool use_zoom_setting,
|
||||
const bool use_rotation_setting,
|
||||
Image export_image( const SetP& set, const vector<CardP>& cards,
|
||||
const int padding,
|
||||
const double global_zoom,
|
||||
const bool use_zoom_setting,
|
||||
const bool use_rotation_setting,
|
||||
const bool use_bleed_setting) {
|
||||
if (!set) throw Error(_("no set"));
|
||||
if (cards.size() == 0) throw Error(_("no cards"));
|
||||
vector<Image> imgs;
|
||||
vector<int> offsets;
|
||||
vector<int> offsets;
|
||||
vector<double> zooms;
|
||||
vector<double> angles;
|
||||
vector<double> bleeds;
|
||||
// Draw card images
|
||||
FOR_EACH(card, cards) {
|
||||
FOR_EACH(card, cards) {
|
||||
Settings::ExportSettings card_settings = settings.exportSettingsFor(set->stylesheetFor(card));
|
||||
double zoom = use_zoom_setting ? global_zoom * card_settings.zoom : global_zoom;
|
||||
double angle = use_rotation_setting ? card_settings.angle_radians : 0.0;
|
||||
double bleed = use_bleed_setting ? card_settings.bleed_pixels : 0.0;
|
||||
imgs.push_back(export_image(set, card, false, zoom, angle, bleed));
|
||||
zooms.push_back(zoom);
|
||||
angles.push_back(angle);
|
||||
imgs.push_back(export_image(set, card, false, zoom, angle, bleed));
|
||||
zooms.push_back(zoom);
|
||||
angles.push_back(angle);
|
||||
bleeds.push_back(bleed);
|
||||
}
|
||||
}
|
||||
int global_width = 0;
|
||||
int global_height = 0;
|
||||
vector<int> widths;
|
||||
vector<int> heights;
|
||||
FOR_EACH(img, imgs) {
|
||||
int width = img.GetWidth();
|
||||
int height = img.GetHeight();
|
||||
widths.push_back(width);
|
||||
heights.push_back(height);
|
||||
offsets.push_back(global_width);
|
||||
global_width += padding + width;
|
||||
global_height = max(global_height, height);
|
||||
}
|
||||
FOR_EACH(img, imgs) {
|
||||
int width = img.GetWidth();
|
||||
int height = img.GetHeight();
|
||||
widths.push_back(width);
|
||||
heights.push_back(height);
|
||||
offsets.push_back(global_width);
|
||||
global_width += padding + width;
|
||||
global_height = max(global_height, height);
|
||||
}
|
||||
global_width -= padding;
|
||||
// Draw global image
|
||||
Image global_img = Image(global_width, global_height);
|
||||
@@ -215,11 +215,11 @@ Image export_image( const SetP& set, const vector<CardP>& cards,
|
||||
pixels[3 * i + 1] = 0;
|
||||
pixels[3 * i + 2] = 0;
|
||||
alpha[i] = 0;
|
||||
}
|
||||
}
|
||||
// Paste card images
|
||||
FOR_EACH_2(img, imgs, offset, offsets) {
|
||||
global_img.Paste(img, offset, 0);
|
||||
}
|
||||
FOR_EACH_2(img, imgs, offset, offsets) {
|
||||
global_img.Paste(img, offset, 0);
|
||||
}
|
||||
// Write metadata
|
||||
String metadata = _("<mse-card-data>[");
|
||||
for (int i = 0; i < cards.size(); ++i) {
|
||||
@@ -233,19 +233,19 @@ Image export_image( const SetP& set, const vector<CardP>& cards,
|
||||
for(IndexMap<FieldP, ValueP>::iterator it = card_data.begin() ; it != card_data.end() ; ++it) {
|
||||
ImageValue* value = dynamic_cast<ImageValue*>(it->get());
|
||||
if (value && !value->filename.empty()) {
|
||||
FieldP field = (*it)->fieldP;
|
||||
FieldP field = (*it)->fieldP;
|
||||
ImageStyle* style = dynamic_cast<ImageStyle*>(stylesheet->card_style.at(field->index).get());
|
||||
if (style) {
|
||||
style->update(set->getContext(card));
|
||||
// store the entire image in the metadata
|
||||
if (style->store_in_metadata()) {
|
||||
std::string bytes = style->getExternalImageString(set, value);
|
||||
cardv_data[field->name.ToStdString()] = bytes;
|
||||
}
|
||||
// store only crop coordinates
|
||||
else {
|
||||
style->update(set->getContext(card));
|
||||
// store the entire image in the metadata
|
||||
if (style->store_in_metadata()) {
|
||||
std::string bytes = style->getExternalImageString(set, value);
|
||||
cardv_data[field->name.ToStdString()] = bytes;
|
||||
}
|
||||
// store only crop coordinates
|
||||
else {
|
||||
std::string rect = style->getExternalRectString(zooms[i], angles[i], bleeds[i], widths[i], heights[i], offsets[i]);
|
||||
cardv_data[field->name.ToStdString()] = rect;
|
||||
cardv_data[field->name.ToStdString()] = rect;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -253,14 +253,14 @@ Image export_image( const SetP& set, const vector<CardP>& cards,
|
||||
metadata += json_ugly_print(cardv);
|
||||
}
|
||||
metadata += _("]</mse-card-data>");
|
||||
global_img.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, metadata);
|
||||
global_img.SetOption(wxIMAGE_OPTION_PNG_DESCRIPTION, metadata);
|
||||
|
||||
return global_img;
|
||||
}
|
||||
|
||||
void export_image(const SetP& set, const CardP& card, const String& filename) {
|
||||
void export_image(const SetP& set, const CardP& card, const String& filename) {
|
||||
const StyleSheet& stylesheet = set->stylesheetFor(card);
|
||||
StyleSheetSettings& stylesheet_settings = settings.stylesheetSettingsFor(stylesheet);
|
||||
StyleSheetSettings& stylesheet_settings = settings.stylesheetSettingsFor(stylesheet);
|
||||
Settings::ExportSettings export_settings = settings.exportSettingsFor(stylesheet);
|
||||
Image img = export_image(set, card, true, export_settings.zoom, export_settings.angle_radians, export_settings.bleed_pixels);
|
||||
img.SaveFile(filename);
|
||||
|
||||
Reference in New Issue
Block a user