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: * 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] SVG
- [X] JPEG - [X] JPEG
- [ ] PNG - [X] PNG
Other formats supported by GDK-PixBuf are considered useless, and Other formats supported by GDK-PixBuf are considered useless, and
most people should be able to open these types. most people should be able to open these types.

View File

@ -1983,10 +1983,11 @@ ag_chart_get_pixbuf(AgChart *chart,
return pixbuf; return pixbuf;
} }
void static void
ag_chart_export_jpg_to_file(AgChart *chart, ag_chart_export_to_image(AgChart *chart,
GFile *file, GFile *file,
AgDisplayTheme *theme, AgDisplayTheme *theme,
gchar *format,
GError **err) GError **err)
{ {
gchar *jpg; gchar *jpg;
@ -2003,7 +2004,7 @@ ag_chart_export_jpg_to_file(AgChart *chart,
pixbuf, pixbuf,
&jpg, &jpg,
&jpg_length, &jpg_length,
"jpeg", format,
err, err,
NULL NULL
)) { )) {
@ -2029,6 +2030,24 @@ ag_chart_export_jpg_to_file(AgChart *chart,
g_free(jpg); 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 void
ag_chart_set_note(AgChart *chart, const gchar *note) 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, AgDisplayTheme *theme,
GError **err); GError **err);
void ag_chart_export_png_to_file(AgChart *chart,
GFile *file,
AgDisplayTheme *theme,
GError **err);
void ag_chart_set_name(AgChart *chart, void ag_chart_set_name(AgChart *chart,
const gchar *name); const gchar *name);

View File

@ -922,6 +922,7 @@ ag_window_export_image(AgWindow *window, GError **err)
NULL); NULL);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter_svg); 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_jpg);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter_png);
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fs), filter_svg); gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fs), filter_svg);
gtk_dialog_set_default_response(GTK_DIALOG(fs), GTK_RESPONSE_ACCEPT); gtk_dialog_set_default_response(GTK_DIALOG(fs), GTK_RESPONSE_ACCEPT);
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(fs), FALSE); 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) { } else if (filter == filter_jpg) {
extension = ".jpg"; extension = ".jpg";
save_func = &ag_chart_export_jpg_to_file; save_func = &ag_chart_export_jpg_to_file;
} else if (filter == filter_png) {
extension = ".png";
save_func = &ag_chart_export_png_to_file;
} else { } else {
g_warning("Unknown file type"); g_warning("Unknown file type");
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(fs), filter_svg); 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_hor = NULL;
GtkFileFilter *filter_svg = NULL; GtkFileFilter *filter_svg = NULL;
GtkFileFilter *filter_jpg = NULL; GtkFileFilter *filter_jpg = NULL;
GtkFileFilter *filter_png = NULL;
GtkTreeModel *country_list = NULL; GtkTreeModel *country_list = NULL;
GtkTreeModel *city_list = NULL; GtkTreeModel *city_list = NULL;
GHashTable *xinclude_positions; 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, "*.jpe");
gtk_file_filter_add_pattern(filter_jpg, "*.jpeg"); gtk_file_filter_add_pattern(filter_jpg, "*.jpeg");
g_object_ref_sink(filter_jpg); 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 static int

View File

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