Merge pull request #99 from gergelypolonkai/png-export

Add PNG save support
This commit is contained in:
Gergely Polonkai 2014-10-05 19:39:56 +02:00
commit 4a9bdc2f66
6 changed files with 43 additions and 8 deletions

View File

@ -152,11 +152,11 @@ dependent on the chart's size (currently, for the big chart it's
* Regiomontanus import :version_2.0:
* Chart export as different image types [2/3] :version_1.0:
* Chart export as different image types [3/3] :version_1.0:
- [X] SVG
- [X] JPEG
- [ ] PNG
- [X] PNG
Other formats supported by GDK-PixBuf are considered useless, and
most people should be able to open these types.

View File

@ -1983,11 +1983,12 @@ ag_chart_get_pixbuf(AgChart *chart,
return pixbuf;
}
void
ag_chart_export_jpg_to_file(AgChart *chart,
GFile *file,
AgDisplayTheme *theme,
GError **err)
static void
ag_chart_export_to_image(AgChart *chart,
GFile *file,
AgDisplayTheme *theme,
gchar *format,
GError **err)
{
gchar *jpg;
gsize jpg_length;
@ -2003,7 +2004,7 @@ ag_chart_export_jpg_to_file(AgChart *chart,
pixbuf,
&jpg,
&jpg_length,
"jpeg",
format,
err,
NULL
)) {
@ -2029,6 +2030,24 @@ ag_chart_export_jpg_to_file(AgChart *chart,
g_free(jpg);
}
void
ag_chart_export_jpg_to_file(AgChart *chart,
GFile *file,
AgDisplayTheme *theme,
GError **err)
{
ag_chart_export_to_image(chart, file, theme, "jpeg", err);
}
void
ag_chart_export_png_to_file(AgChart *chart,
GFile *file,
AgDisplayTheme *theme,
GError **err)
{
ag_chart_export_to_image(chart, file, theme, "png", err);
}
void
ag_chart_set_note(AgChart *chart, const gchar *note)
{

View File

@ -110,6 +110,11 @@ void ag_chart_export_jpg_to_file(AgChart *chart,
AgDisplayTheme *theme,
GError **err);
void ag_chart_export_png_to_file(AgChart *chart,
GFile *file,
AgDisplayTheme *theme,
GError **err);
void ag_chart_set_name(AgChart *chart,
const gchar *name);

View File

@ -922,6 +922,7 @@ ag_window_export_image(AgWindow *window, GError **err)
NULL);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter_svg);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter_jpg);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter_png);
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fs), filter_svg);
gtk_dialog_set_default_response(GTK_DIALOG(fs), GTK_RESPONSE_ACCEPT);
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(fs), FALSE);
@ -953,6 +954,9 @@ ag_window_export_image(AgWindow *window, GError **err)
} else if (filter == filter_jpg) {
extension = ".jpg";
save_func = &ag_chart_export_jpg_to_file;
} else if (filter == filter_png) {
extension = ".png";
save_func = &ag_chart_export_png_to_file;
} else {
g_warning("Unknown file type");
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fs), filter_svg);

View File

@ -44,6 +44,7 @@ GtkFileFilter *filter_chart = NULL;
GtkFileFilter *filter_hor = NULL;
GtkFileFilter *filter_svg = NULL;
GtkFileFilter *filter_jpg = NULL;
GtkFileFilter *filter_png = NULL;
GtkTreeModel *country_list = NULL;
GtkTreeModel *city_list = NULL;
GHashTable *xinclude_positions;
@ -117,6 +118,11 @@ init_filters(void)
gtk_file_filter_add_pattern(filter_jpg, "*.jpe");
gtk_file_filter_add_pattern(filter_jpg, "*.jpeg");
g_object_ref_sink(filter_jpg);
filter_png = gtk_file_filter_new();
gtk_file_filter_set_name(filter_png, _("PNG image"));
gtk_file_filter_add_pattern(filter_png, "*.png");
g_object_ref_sink(filter_png);
}
static int

View File

@ -33,6 +33,7 @@ extern GtkFileFilter *filter_chart;
extern GtkFileFilter *filter_hor;
extern GtkFileFilter *filter_svg;
extern GtkFileFilter *filter_jpg;
extern GtkFileFilter *filter_png;
extern GtkTreeModel *country_list;
extern GtkTreeModel *city_list;
extern const GswePlanet used_planets[];