Add DPI export targets

This commit is contained in:
GenevensiS
2025-12-04 18:12:10 +01:00
committed by GitHub
parent 2932d0007d
commit 4e197a75cb
7 changed files with 128 additions and 122 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ Bitmap export_bitmap(const SetP& set, const vector<CardP>& cards, bool scale_to_
Image export_image(const SetP& set, const CardP& card, const double zoom = 1.0, const Radians angle_radians = 0.0);
Image export_image(const SetP& set, const vector<CardP>& cards, bool scale_to_lowest_dpi = false, int padding = 0, const double zoom = 1.0, const Radians angle_radians = 0.0);
/// Export the image of one or more cards to a given filename
/// Export the image of one or more cards to a given filename, using the app's zoom and rotation settings
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);
+8 -5
View File
@@ -52,7 +52,7 @@ Rotation UnzoomedDataViewer::getRotation() const {
return Rotation(angle, stylesheet->getCardRect(), zoom, 1.0, ROTATION_ATTACH_TOP_LEFT);
}
double export_zoom = settings.stylesheetSettingsFor(set->stylesheetFor(card)).export_zoom();
double export_zoom = settings.exportZoomSettingsFor(set->stylesheetFor(card));
bool use_viewer_rotation = !settings.stylesheetSettingsFor(set->stylesheetFor(card)).card_normal_export();
if (use_viewer_rotation) {
@@ -195,10 +195,13 @@ Image export_image(const SetP& set, const vector<CardP>& cards, bool scale_to_lo
return img;
}
void export_image(const SetP& set, const CardP& card, const String& filename) {
Image img = export_image(set, card);
img.SaveFile(filename); // can't use Bitmap::saveFile, it wants to know the file type
// but image.saveFile determines it automagicly
void export_image(const SetP& set, const CardP& card, const String& filename) {
const StyleSheet& stylesheet = set->stylesheetFor(card);
StyleSheetSettings& stylesheet_settings = settings.stylesheetSettingsFor(stylesheet);
double zoom = settings.exportZoomSettingsFor(stylesheet);
Radians angle = stylesheet_settings.card_normal_export() ? 0.0 : stylesheet_settings.card_angle() / 360.0 * 2.0 * M_PI;
Image img = export_image(set, card, zoom, angle);
img.SaveFile(filename);
}
void export_image(const SetP& set, const vector<CardP>& cards,
+1 -1
View File
@@ -164,7 +164,7 @@ public:
~SetView();
/// Get the set that is currently being viewed
//inline SetP getSet() const { return set; }
inline SetP getSet() const { return set; }
/// Change the set that is being viewed
void setSet(const SetP& set);
+43 -21
View File
@@ -53,6 +53,8 @@ IMPLEMENT_REFLECTION_ENUM(FilenameConflicts) {
VALUE_N("number overwrite", CONFLICT_NUMBER_OVERWRITE);
}
const vector<int> Settings::export_zoom_choices = { 50,66,75,80,100,120,125,150,175,200 };
const int COLUMN_NOT_INITIALIZED = -100000;
ColumnSettings::ColumnSettings()
@@ -127,7 +129,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(GameSettings) {
StyleSheetSettings::StyleSheetSettings()
: card_zoom (1.0, true)
, export_zoom (1.0, true)
, export_zoom_selection (0, true)
, card_angle (0, true)
, card_anti_alias (true, true)
, card_borders (true, true)
@@ -139,7 +141,7 @@ StyleSheetSettings::StyleSheetSettings()
void StyleSheetSettings::useDefault(const StyleSheetSettings& ss) {
if (card_zoom .isDefault()) card_zoom .assignDefault(ss.card_zoom);
if (export_zoom .isDefault()) export_zoom .assignDefault(ss.export_zoom);
if (export_zoom_selection .isDefault()) export_zoom_selection .assignDefault(ss.export_zoom_selection);
if (card_angle .isDefault()) card_angle .assignDefault(ss.card_angle);
if (card_anti_alias .isDefault()) card_anti_alias .assignDefault(ss.card_anti_alias);
if (card_borders .isDefault()) card_borders .assignDefault(ss.card_borders);
@@ -151,7 +153,7 @@ void StyleSheetSettings::useDefault(const StyleSheetSettings& ss) {
IMPLEMENT_REFLECTION_NO_SCRIPT(StyleSheetSettings) {
REFLECT(card_zoom);
REFLECT(export_zoom);
REFLECT(export_zoom_selection);
REFLECT(card_angle);
REFLECT(card_anti_alias);
REFLECT(card_borders);
@@ -182,19 +184,19 @@ IMPLEMENT_REFLECTION_ENUM(DarkModeType) {
Settings settings;
Settings::Settings()
: locale (_("en"))
, set_window_maximized (false)
, set_window_width (790)
, set_window_height (300)
, card_notes_height (40)
, open_sets_in_new_window(true)
, symbol_grid_size (30)
, symbol_grid (true)
, symbol_grid_snap (false)
, print_spacing (0.33)
, print_cutter_lines (CUTTER_ALL)
, dark_mode_type (DARKMODE_SYSTEM)
, internal_scale (1.0)
: locale (_("en"))
, set_window_maximized (false)
, set_window_width (790)
, set_window_height (300)
, card_notes_height (40)
, open_sets_in_new_window (true)
, symbol_grid_size (30)
, symbol_grid (true)
, symbol_grid_snap (false)
, print_spacing (0.33)
, print_cutter_lines (CUTTER_ALL)
, dark_mode_type (DARKMODE_SYSTEM)
, internal_scale_selection(0)
, internal_image_extension(true)
#if USE_OLD_STYLE_UPDATE_CHECKER
, updates_url (_("https://magicseteditor.boards.net/page/downloads"))
@@ -249,7 +251,29 @@ StyleSheetSettings& Settings::stylesheetSettingsFor(const StyleSheet& stylesheet
if (!ss) ss = make_intrusive<StyleSheetSettings>();
ss->useDefault(default_stylesheet_settings); // update default settings
return *ss;
}
}
double Settings::exportZoomSettingsFor(const StyleSheet& stylesheet) {
StyleSheetSettings& ss = stylesheetSettingsFor(stylesheet);
int export_zoom = ss.export_zoom_selection();
if (export_zoom == 0) return adaptiveZoomSettingsFor(stylesheet, 300.0, 50.0);
if (export_zoom == 1) return adaptiveZoomSettingsFor(stylesheet, 300.0, 1.0);
if (export_zoom == 2) return adaptiveZoomSettingsFor(stylesheet, 150.0, 1.0);
return export_zoom_choices[export_zoom - 3] / 100;
}
double Settings::internalScaleSettingsFor(const StyleSheet& stylesheet) {
if (internal_scale_selection == 0) return exportZoomSettingsFor(stylesheet);
if (internal_scale_selection == 1) return adaptiveZoomSettingsFor(stylesheet, 300.0, 50.0);
if (internal_scale_selection == 2) return adaptiveZoomSettingsFor(stylesheet, 300.0, 1.0);
if (internal_scale_selection == 3) return adaptiveZoomSettingsFor(stylesheet, 150.0, 1.0);
return export_zoom_choices[internal_scale_selection - 4] / 100;
}
double Settings::adaptiveZoomSettingsFor(const StyleSheet& stylesheet, double dpi_target, double dpi_leeway) {
if (abs(stylesheet.card_dpi - dpi_target) <= dpi_leeway) return 1.0;
return dpi_target / max(10.0, stylesheet.card_dpi);
}
IndexMap<FieldP,ValueP>& Settings::exportOptionsFor(const ExportTemplate& export_template) {
return export_options.get(export_template.name(), export_template.option_fields);
@@ -300,7 +324,7 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) {
REFLECT(print_cutter_lines);
REFLECT(dark_mode_type);
REFLECT(apprentice_location);
REFLECT(internal_scale);
REFLECT(internal_scale_selection);
REFLECT(internal_image_extension);
#if USE_OLD_STYLE_UPDATE_CHECKER
REFLECT(updates_url);
@@ -341,9 +365,7 @@ void Settings::read() {
// make sure things aren't in a problematic state
if (locale.Trim().empty()) locale = _("en");
if (symbol_grid_size < 30) symbol_grid_size = 30;
if (internal_scale < 1.0) internal_scale = 1.0;
if (default_stylesheet_settings.card_zoom < 0.5) default_stylesheet_settings.card_zoom = 1.0;
if (default_stylesheet_settings.export_zoom < 0.5) default_stylesheet_settings.export_zoom = 1.0;
if (default_stylesheet_settings.card_zoom < 0.5) default_stylesheet_settings.card_zoom = 1.0;
}
}
+25 -16
View File
@@ -97,15 +97,15 @@ public:
StyleSheetSettings();
// Rendering/display settings
Defaultable<double> card_zoom;
Defaultable<double> export_zoom;
Defaultable<double> card_zoom;
Defaultable<int> export_zoom_selection;
Defaultable<Degrees> card_angle;
Defaultable<bool> card_anti_alias;
Defaultable<bool> card_borders;
Defaultable<bool> card_draw_editing;
Defaultable<bool> card_normal_export;
Defaultable<bool> card_notes_export;
Defaultable<bool> card_spellcheck_enabled;
Defaultable<bool> card_anti_alias;
Defaultable<bool> card_borders;
Defaultable<bool> card_draw_editing;
Defaultable<bool> card_normal_export;
Defaultable<bool> card_notes_export;
Defaultable<bool> card_spellcheck_enabled;
/// Where the settings are the default, use the value from ss
void useDefault(const StyleSheetSettings& ss);
@@ -175,12 +175,17 @@ public:
// --------------------------------------------------- : Game/stylesheet specific
/// Get the settings object for a specific game
GameSettings& gameSettingsFor (const Game& game);
GameSettings& gameSettingsFor (const Game& game);
/// Get the settings for a column for a specific field in a game
ColumnSettings& columnSettingsFor (const Game& game, const Field& field);
ColumnSettings& columnSettingsFor (const Game& game, const Field& field);
/// Get the settings object for a specific stylesheet
StyleSheetSettings& stylesheetSettingsFor(const StyleSheet& stylesheet);
StyleSheetSettings& stylesheetSettingsFor (const StyleSheet& stylesheet);
double exportZoomSettingsFor (const StyleSheet& stylesheet);
double internalScaleSettingsFor(const StyleSheet& stylesheet);
double adaptiveZoomSettingsFor (const StyleSheet& stylesheet, double target_dpi, double leeway_dpi);
static const vector<int> export_zoom_choices;
private:
map<String,GameSettingsP> game_settings;
map<String,StyleSheetSettingsP> stylesheet_settings;
@@ -211,13 +216,16 @@ public:
Color darkModeColor();
// --------------------------------------------------- : Special game stuff
String apprentice_location;
// --------------------------------------------------- : Internal settings
double internal_scale;
// --------------------------------------------------- : Internal settings
int internal_scale_selection;
bool internal_image_extension;
// --------------------------------------------------- : Update checking
// --------------------------------------------------- : Update checking
#if USE_OLD_STYLE_UPDATE_CHECKER
String updates_url;
#endif
@@ -227,7 +235,8 @@ public:
bool check_updates_all; ///< Check updates of all packages, not just the program
String website_url;
// --------------------------------------------------- : Installation settings
// --------------------------------------------------- : Installation settings
InstallType install_type;
// --------------------------------------------------- : The io