2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1998-02-22 06:14:06 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* GTM plug-in --- GIMP Table Magic
|
2016-02-16 09:35:43 +08:00
|
|
|
* Allows images to be exported as HTML tables with different colored cells.
|
1998-02-22 06:14:06 +08:00
|
|
|
* It doesn't have very much practical use other than being able to
|
|
|
|
* easily design a table by "painting" it in GIMP, or to make small HTML
|
|
|
|
* table images/icons.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Daniel Dunbar
|
|
|
|
* Email: ddunbar@diads.com
|
|
|
|
* WWW: http://millennium.diads.com/gimp/
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-02-22 06:14:06 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-02-22 06:14:06 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1998-02-22 06:14:06 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Version 1.0:
|
|
|
|
* Once I first found out that it was possible to have pixel level control
|
|
|
|
* of HTML tables I instantly realized that it would be possible, however
|
|
|
|
* pointless, to save an image as a, albeit huge, HTML table.
|
|
|
|
*
|
|
|
|
* One night when I was feeling in an adventourously stupid programming mood
|
|
|
|
* I decided to write a program to do it.
|
|
|
|
*
|
|
|
|
* At first I just wrote a really ugly hack to do it, which I then planned
|
2003-11-06 23:27:05 +08:00
|
|
|
* on using once just to see how it worked, and then posting a URL and
|
1998-02-22 06:14:06 +08:00
|
|
|
* laughing about it on #gimp. As it turns out, tigert thought it actually
|
|
|
|
* had potential to be a useful plugin, so I started adding features and
|
|
|
|
* and making a nice UI.
|
|
|
|
*
|
2000-02-23 08:15:12 +08:00
|
|
|
* It's still not very useful, but I did manage to significantly improve my
|
1998-02-22 06:14:06 +08:00
|
|
|
* C programming skills in the process, so it was worth it.
|
|
|
|
*
|
2013-01-27 23:52:38 +08:00
|
|
|
* If you happen to find it useful I would appreciate any email about it.
|
1998-02-22 06:14:06 +08:00
|
|
|
* - Daniel Dunbar
|
|
|
|
* ddunbar@diads.com
|
|
|
|
*/
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
#include "config.h"
|
1998-02-22 06:14:06 +08:00
|
|
|
|
|
|
|
#include <string.h>
|
2000-01-07 06:26:10 +08:00
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
2000-01-07 06:26:10 +08:00
|
|
|
|
1999-12-26 05:49:51 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2000-05-01 05:03:44 +08:00
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
#define EXPORT_PROC "file-html-table-export"
|
2008-08-11 18:06:13 +08:00
|
|
|
#define PLUG_IN_BINARY "file-html-table"
|
1998-02-22 06:14:06 +08:00
|
|
|
|
|
|
|
|
2019-08-24 19:53:16 +08:00
|
|
|
typedef struct _Html Html;
|
|
|
|
typedef struct _HtmlClass HtmlClass;
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2019-08-24 19:53:16 +08:00
|
|
|
struct _Html
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _HtmlClass
|
|
|
|
{
|
|
|
|
GimpPlugInClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define HTML_TYPE (html_get_type ())
|
2023-10-19 00:29:37 +08:00
|
|
|
#define HTML(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HTML_TYPE, Html))
|
2019-08-24 19:53:16 +08:00
|
|
|
|
|
|
|
GType html_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
static GList * html_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * html_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
static GimpValueArray * html_export (GimpProcedure *procedure,
|
2019-08-24 19:53:16 +08:00
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
GFile *file,
|
2023-07-22 00:08:00 +08:00
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
2019-08-24 19:53:16 +08:00
|
|
|
gpointer run_data);
|
2008-05-10 18:42:18 +08:00
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
static gboolean export_image (GFile *file,
|
2019-08-24 19:53:16 +08:00
|
|
|
GeglBuffer *buffer,
|
2019-10-06 21:36:48 +08:00
|
|
|
GObject *config,
|
2019-08-24 19:53:16 +08:00
|
|
|
GError **error);
|
2019-10-06 21:36:48 +08:00
|
|
|
static gboolean save_dialog (GimpImage *image,
|
|
|
|
GimpProcedure *procedure,
|
|
|
|
GObject *config);
|
2008-05-10 18:42:18 +08:00
|
|
|
|
2019-08-24 19:53:16 +08:00
|
|
|
static gboolean print (GOutputStream *output,
|
|
|
|
GError **error,
|
|
|
|
const gchar *format,
|
|
|
|
...) G_GNUC_PRINTF (3, 0);
|
|
|
|
static gboolean color_comp (guchar *buffer,
|
|
|
|
guchar *buf2);
|
2014-10-05 22:42:31 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2019-08-24 19:53:16 +08:00
|
|
|
G_DEFINE_TYPE (Html, html, GIMP_TYPE_PLUG_IN)
|
2014-10-05 22:42:31 +08:00
|
|
|
|
2019-08-24 19:53:16 +08:00
|
|
|
GIMP_MAIN (HTML_TYPE)
|
2022-05-26 06:59:36 +08:00
|
|
|
DEFINE_STD_SET_I18N
|
2019-08-24 19:53:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
html_class_init (HtmlClass *klass)
|
|
|
|
{
|
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2019-08-24 19:53:16 +08:00
|
|
|
plug_in_class->query_procedures = html_query_procedures;
|
|
|
|
plug_in_class->create_procedure = html_create_procedure;
|
2022-05-26 06:59:36 +08:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
2019-08-24 19:53:16 +08:00
|
|
|
}
|
1998-02-22 06:14:06 +08:00
|
|
|
|
|
|
|
static void
|
2019-08-24 19:53:16 +08:00
|
|
|
html_init (Html *html)
|
1998-02-22 06:14:06 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-24 19:53:16 +08:00
|
|
|
static GList *
|
|
|
|
html_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
2024-04-13 23:10:25 +08:00
|
|
|
return g_list_append (NULL, g_strdup (EXPORT_PROC));
|
2019-08-24 19:53:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GimpProcedure *
|
|
|
|
html_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
if (! strcmp (name, EXPORT_PROC))
|
2019-08-24 19:53:16 +08:00
|
|
|
{
|
2024-04-20 11:08:57 +08:00
|
|
|
procedure = gimp_export_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
FALSE, html_export, NULL, NULL);
|
2019-08-24 19:53:16 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "*");
|
|
|
|
|
2022-07-05 04:50:53 +08:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("HTML table"));
|
2023-04-17 00:38:17 +08:00
|
|
|
gimp_file_procedure_set_format_name (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
_("HTML Table"));
|
2019-08-24 19:53:16 +08:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2023-04-17 00:38:17 +08:00
|
|
|
_("GIMP Table Magic"),
|
|
|
|
_("Allows you to draw an HTML table "
|
|
|
|
"in GIMP. See help for more info."),
|
2019-08-24 19:53:16 +08:00
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Daniel Dunbar",
|
|
|
|
"Daniel Dunbar",
|
|
|
|
"1998");
|
|
|
|
|
|
|
|
gimp_file_procedure_set_handles_remote (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
TRUE);
|
|
|
|
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"text/html");
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"html,htm");
|
2019-10-06 21:36:48 +08:00
|
|
|
|
2024-06-13 00:53:12 +08:00
|
|
|
gimp_procedure_add_boolean_aux_argument (procedure, "use-caption",
|
|
|
|
_("Use c_aption"),
|
|
|
|
_("Enable if you would like to have the table "
|
|
|
|
"captioned."),
|
|
|
|
FALSE,
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_string_aux_argument (procedure, "caption-text",
|
|
|
|
_("Capt_ion"),
|
|
|
|
_("The text for the table caption."),
|
|
|
|
"Made with GIMP Table Magic",
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_string_aux_argument (procedure, "cell-content",
|
|
|
|
_("Cell con_tent"),
|
|
|
|
_("The text to go into each cell."),
|
|
|
|
" ",
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_string_aux_argument (procedure, "cell-width",
|
|
|
|
_("_Width"),
|
|
|
|
_("The width for each table cell. "
|
|
|
|
"Can be a number or a percent."),
|
|
|
|
"",
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_string_aux_argument (procedure, "cell-height",
|
|
|
|
_("_Height"),
|
|
|
|
_("The height for each table cell. "
|
|
|
|
"Can be a number or a percent."),
|
|
|
|
"",
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_boolean_aux_argument (procedure, "full-document",
|
|
|
|
_("_Generate full HTML document"),
|
|
|
|
_("If enabled GTM will output a full HTML "
|
|
|
|
"document with <HTML>, <BODY>, etc. tags "
|
|
|
|
"instead of just the table html."),
|
|
|
|
TRUE,
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_int_aux_argument (procedure, "border",
|
|
|
|
_("_Border"),
|
|
|
|
_("The number of pixels in the table border."),
|
|
|
|
0, 1000, 2,
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_boolean_aux_argument (procedure, "span-tags",
|
|
|
|
_("_Use cellspan"),
|
|
|
|
_("If enabled GTM will replace any "
|
|
|
|
"rectangular sections of identically "
|
|
|
|
"colored blocks with one large cell with "
|
|
|
|
"ROWSPAN and COLSPAN values."),
|
|
|
|
FALSE,
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_boolean_aux_argument (procedure, "compress-td-tags",
|
|
|
|
_("Co_mpress TD tags"),
|
|
|
|
_("Enabling this will cause GTM to "
|
|
|
|
"leave no whitespace between the TD "
|
|
|
|
"tags and the cell content. This is only "
|
|
|
|
"necessary for pixel level positioning "
|
|
|
|
"control."),
|
|
|
|
FALSE,
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_int_aux_argument (procedure, "cell-padding",
|
|
|
|
_("Cell-pa_dding"),
|
|
|
|
_("The amount of cell padding."),
|
|
|
|
0, 1000, 4,
|
|
|
|
GIMP_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_int_aux_argument (procedure, "cell-spacing",
|
|
|
|
_("Cell spaci_ng"),
|
|
|
|
_("The amount of cell spacing."),
|
|
|
|
0, 1000, 0,
|
|
|
|
GIMP_PARAM_READWRITE);
|
2019-08-24 19:53:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return procedure;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
2024-04-13 23:10:25 +08:00
|
|
|
html_export (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data)
|
1998-02-22 06:14:06 +08:00
|
|
|
{
|
2024-04-30 21:50:24 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
GList *drawables = gimp_image_list_layers (image);
|
2023-07-22 00:08:00 +08:00
|
|
|
GeglBuffer *buffer;
|
2024-04-30 21:50:24 +08:00
|
|
|
GError *error = NULL;
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2012-11-20 02:34:33 +08:00
|
|
|
gegl_init (NULL, NULL);
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
if (run_mode != GIMP_RUN_INTERACTIVE)
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CALLING_ERROR,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (! save_dialog (image, procedure, G_OBJECT (config)))
|
2019-08-24 19:53:16 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CANCEL,
|
|
|
|
NULL);
|
2012-11-20 02:34:33 +08:00
|
|
|
|
2024-04-30 21:50:24 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (drawables->data);
|
2012-11-20 02:34:33 +08:00
|
|
|
|
2024-04-13 23:10:25 +08:00
|
|
|
if (! export_image (file, buffer, G_OBJECT (config),
|
|
|
|
&error))
|
2000-01-26 01:46:56 +08:00
|
|
|
{
|
2019-08-24 19:53:16 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
2000-01-26 01:46:56 +08:00
|
|
|
}
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2019-08-24 19:53:16 +08:00
|
|
|
g_object_unref (buffer);
|
2008-08-20 22:00:44 +08:00
|
|
|
|
2024-04-30 21:50:24 +08:00
|
|
|
g_list_free (drawables);
|
2019-08-24 19:53:16 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure, status, error);
|
1998-02-22 06:14:06 +08:00
|
|
|
}
|
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
static gboolean
|
2024-04-13 23:10:25 +08:00
|
|
|
export_image (GFile *file,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
GObject *config,
|
|
|
|
GError **error)
|
1998-02-22 06:14:06 +08:00
|
|
|
{
|
2014-10-05 22:59:16 +08:00
|
|
|
const Babl *format = babl_format ("R'G'B'A u8");
|
2018-05-14 07:27:03 +08:00
|
|
|
GeglSampler *sampler;
|
2018-11-27 19:27:20 +08:00
|
|
|
GCancellable *cancellable;
|
2014-10-05 22:59:16 +08:00
|
|
|
GOutputStream *output;
|
|
|
|
gint row, col;
|
|
|
|
gint cols, rows;
|
|
|
|
gint x, y;
|
|
|
|
gint colcount, colspan, rowspan;
|
|
|
|
gint *palloc;
|
|
|
|
guchar *buf, *buf2;
|
|
|
|
gchar *width = NULL;
|
|
|
|
gchar *height = NULL;
|
2019-10-06 21:36:48 +08:00
|
|
|
gboolean config_use_caption;
|
|
|
|
gchar *config_caption_text;
|
|
|
|
gchar *config_cell_content;
|
|
|
|
gchar *config_cell_width;
|
|
|
|
gchar *config_cell_height;
|
|
|
|
gboolean config_full_document;
|
|
|
|
gint config_border;
|
|
|
|
gboolean config_span_tags;
|
|
|
|
gboolean config_compress_td_tags;
|
|
|
|
gint config_cell_padding;
|
|
|
|
gint config_cell_spacing;
|
|
|
|
|
|
|
|
g_object_get (config,
|
|
|
|
"use-caption", &config_use_caption,
|
|
|
|
"caption-text", &config_caption_text,
|
|
|
|
"cell-content", &config_cell_content,
|
|
|
|
"cell-width", &config_cell_width,
|
|
|
|
"cell-height", &config_cell_height,
|
|
|
|
"full-document", &config_full_document,
|
|
|
|
"border", &config_border,
|
|
|
|
"span-tags", &config_span_tags,
|
|
|
|
"compress-td-tags", &config_compress_td_tags,
|
|
|
|
"cell-padding", &config_cell_padding,
|
|
|
|
"cell-spacing", &config_cell_spacing,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (! config_caption_text) config_caption_text = g_strdup ("");
|
|
|
|
if (! config_cell_content) config_cell_content = g_strdup ("");
|
|
|
|
if (! config_cell_width) config_cell_width = g_strdup ("");
|
|
|
|
if (! config_cell_height) config_cell_height = g_strdup ("");
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2012-11-20 02:34:33 +08:00
|
|
|
cols = gegl_buffer_get_width (buffer);
|
|
|
|
rows = gegl_buffer_get_height (buffer);
|
|
|
|
|
2016-02-16 09:35:43 +08:00
|
|
|
gimp_progress_init_printf (_("Exporting '%s'"),
|
2014-10-05 22:59:16 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2014-07-23 22:39:00 +08:00
|
|
|
|
2014-10-05 22:59:16 +08:00
|
|
|
output = G_OUTPUT_STREAM (g_file_replace (file,
|
|
|
|
NULL, FALSE, G_FILE_CREATE_NONE,
|
|
|
|
NULL, error));
|
|
|
|
if (output)
|
|
|
|
{
|
|
|
|
GOutputStream *buffered;
|
|
|
|
|
|
|
|
buffered = g_buffered_output_stream_new (output);
|
|
|
|
g_object_unref (output);
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2014-10-05 22:59:16 +08:00
|
|
|
output = buffered;
|
|
|
|
}
|
|
|
|
else
|
2003-06-13 22:37:00 +08:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-05-14 07:27:03 +08:00
|
|
|
sampler = gegl_buffer_sampler_new (buffer, format, GEGL_SAMPLER_NEAREST);
|
|
|
|
|
2012-11-28 03:58:05 +08:00
|
|
|
palloc = g_new (int, rows * cols);
|
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
if (config_full_document)
|
2003-06-13 22:37:00 +08:00
|
|
|
{
|
2014-10-05 22:59:16 +08:00
|
|
|
if (! print (output, error,
|
|
|
|
"<HTML>\n<HEAD><TITLE>%s</TITLE></HEAD>\n<BODY>\n",
|
|
|
|
gimp_file_get_utf8_name (file)) ||
|
|
|
|
! print (output, error, "<H1>%s</H1>\n",
|
|
|
|
gimp_file_get_utf8_name (file)))
|
|
|
|
{
|
|
|
|
goto fail;
|
|
|
|
}
|
2003-06-13 22:37:00 +08:00
|
|
|
}
|
|
|
|
|
2014-10-05 22:59:16 +08:00
|
|
|
if (! print (output, error,
|
|
|
|
"<TABLE BORDER=%d CELLPADDING=%d CELLSPACING=%d>\n",
|
2019-10-06 21:36:48 +08:00
|
|
|
config_border, config_cell_padding, config_cell_spacing))
|
2014-10-05 22:59:16 +08:00
|
|
|
goto fail;
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
if (config_use_caption)
|
2014-10-05 22:59:16 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error, "<CAPTION>%s</CAPTION>\n",
|
2019-10-06 21:36:48 +08:00
|
|
|
config_caption_text))
|
2014-10-05 22:59:16 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2013-01-19 12:10:32 +08:00
|
|
|
buf = g_newa (guchar, babl_format_get_bytes_per_pixel (format));
|
|
|
|
buf2 = g_newa (guchar, babl_format_get_bytes_per_pixel (format));
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
if (strcmp (config_cell_width, "") != 0)
|
2003-06-13 22:37:00 +08:00
|
|
|
{
|
2019-10-06 21:36:48 +08:00
|
|
|
width = g_strdup_printf (" WIDTH=\"%s\"", config_cell_width);
|
2003-06-13 22:37:00 +08:00
|
|
|
}
|
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
if (strcmp (config_cell_height, "") != 0)
|
2003-06-13 22:37:00 +08:00
|
|
|
{
|
2019-10-06 21:36:48 +08:00
|
|
|
height = g_strdup_printf (" HEIGHT=\"%s\" ", config_cell_height);
|
2003-06-13 22:37:00 +08:00
|
|
|
}
|
2008-05-10 18:42:18 +08:00
|
|
|
|
2007-05-31 01:37:42 +08:00
|
|
|
if (! width)
|
|
|
|
width = g_strdup (" ");
|
2008-05-10 18:42:18 +08:00
|
|
|
|
2007-05-31 01:37:42 +08:00
|
|
|
if (! height)
|
|
|
|
height = g_strdup (" ");
|
2003-06-13 22:37:00 +08:00
|
|
|
|
|
|
|
/* Initialize array to hold ROWSPAN and COLSPAN cell allocation table */
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
for (row = 0; row < rows; row++)
|
|
|
|
for (col = 0; col < cols; col++)
|
2012-11-20 02:34:33 +08:00
|
|
|
palloc[cols * row + col] = 1;
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
colspan = 0;
|
|
|
|
rowspan = 0;
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
for (y = 0; y < rows; y++)
|
|
|
|
{
|
2014-10-05 22:59:16 +08:00
|
|
|
if (! print (output, error, " <TR>\n"))
|
|
|
|
goto fail;
|
2003-06-13 22:37:00 +08:00
|
|
|
|
|
|
|
for (x = 0; x < cols; x++)
|
|
|
|
{
|
2018-05-14 07:27:03 +08:00
|
|
|
gegl_sampler_get (sampler, x, y, NULL, buf, GEGL_ABYSS_NONE);
|
2003-06-13 22:37:00 +08:00
|
|
|
|
|
|
|
/* Determine ROWSPAN and COLSPAN */
|
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
if (config_span_tags)
|
2003-06-13 22:37:00 +08:00
|
|
|
{
|
|
|
|
col = x;
|
|
|
|
row = y;
|
|
|
|
colcount = 0;
|
|
|
|
colspan = 0;
|
|
|
|
rowspan = 0;
|
|
|
|
|
2018-05-14 07:27:03 +08:00
|
|
|
gegl_sampler_get (sampler, col, row, NULL, buf2, GEGL_ABYSS_NONE);
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2012-11-20 02:34:33 +08:00
|
|
|
while (color_comp (buf, buf2) &&
|
|
|
|
palloc[cols * row + col] == 1 &&
|
|
|
|
row < rows)
|
2003-06-13 22:37:00 +08:00
|
|
|
{
|
2012-11-20 02:34:33 +08:00
|
|
|
while (color_comp (buf, buf2) &&
|
|
|
|
palloc[cols * row + col] == 1 &&
|
|
|
|
col < cols)
|
2003-06-13 22:37:00 +08:00
|
|
|
{
|
|
|
|
colcount++;
|
|
|
|
col++;
|
|
|
|
|
2018-05-14 07:27:03 +08:00
|
|
|
gegl_sampler_get (sampler,
|
|
|
|
col, row, NULL, buf2, GEGL_ABYSS_NONE);
|
2003-06-13 22:37:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (colcount != 0)
|
|
|
|
{
|
|
|
|
row++;
|
|
|
|
rowspan++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (colcount < colspan || colspan == 0)
|
|
|
|
colspan = colcount;
|
|
|
|
|
|
|
|
col = x;
|
|
|
|
colcount = 0;
|
|
|
|
|
2018-05-14 07:27:03 +08:00
|
|
|
gegl_sampler_get (sampler,
|
|
|
|
col, row, NULL, buf2, GEGL_ABYSS_NONE);
|
2003-06-13 22:37:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (colspan > 1 || rowspan > 1)
|
|
|
|
{
|
|
|
|
for (row = 0; row < rowspan; row++)
|
|
|
|
for (col = 0; col < colspan; col++)
|
2012-11-20 02:34:33 +08:00
|
|
|
palloc[cols * (row + y) + (col + x)] = 0;
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2012-11-20 02:34:33 +08:00
|
|
|
palloc[cols * y + x] = 2;
|
2003-06-13 22:37:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:34:33 +08:00
|
|
|
if (palloc[cols * y + x] == 1)
|
2014-10-05 22:59:16 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error,
|
|
|
|
" <TD%s%sBGCOLOR=#%02x%02x%02x>",
|
|
|
|
width, height, buf[0], buf[1], buf[2]))
|
|
|
|
goto fail;
|
|
|
|
}
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2012-11-20 02:34:33 +08:00
|
|
|
if (palloc[cols * y + x] == 2)
|
2014-10-05 22:59:16 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error,
|
|
|
|
" <TD ROWSPAN=\"%d\" COLSPAN=\"%d\"%s%sBGCOLOR=#%02x%02x%02x>",
|
|
|
|
rowspan, colspan, width, height,
|
|
|
|
buf[0], buf[1], buf[2]))
|
|
|
|
goto fail;
|
|
|
|
}
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2012-11-20 02:34:33 +08:00
|
|
|
if (palloc[cols * y + x] != 0)
|
2003-06-13 22:37:00 +08:00
|
|
|
{
|
2019-10-06 21:36:48 +08:00
|
|
|
if (config_compress_td_tags)
|
2014-10-05 22:59:16 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error,
|
2019-10-06 21:36:48 +08:00
|
|
|
"%s</TD>\n", config_cell_content))
|
2014-10-05 22:59:16 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2003-06-13 22:37:00 +08:00
|
|
|
else
|
2014-10-05 22:59:16 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error,
|
2019-10-06 21:36:48 +08:00
|
|
|
"\n %s\n </TD>\n", config_cell_content))
|
2014-10-05 22:59:16 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2003-06-13 22:37:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-05 22:59:16 +08:00
|
|
|
if (! print (output, error, " </TR>\n"))
|
|
|
|
goto fail;
|
2003-06-13 22:37:00 +08:00
|
|
|
|
|
|
|
gimp_progress_update ((double) y / (double) rows);
|
1998-02-22 06:14:06 +08:00
|
|
|
}
|
2012-11-20 02:34:33 +08:00
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
if (config_full_document)
|
2014-10-05 22:59:16 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error, "</TABLE></BODY></HTML>\n"))
|
|
|
|
goto fail;
|
|
|
|
}
|
2003-06-13 22:37:00 +08:00
|
|
|
else
|
2014-10-05 22:59:16 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error, "</TABLE>\n"))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! g_output_stream_close (output, NULL, error))
|
|
|
|
goto fail;
|
2003-06-13 22:37:00 +08:00
|
|
|
|
2014-10-05 22:59:16 +08:00
|
|
|
g_object_unref (output);
|
2018-05-14 07:27:03 +08:00
|
|
|
g_object_unref (sampler);
|
2003-06-13 22:37:00 +08:00
|
|
|
g_free (width);
|
|
|
|
g_free (height);
|
|
|
|
g_free (palloc);
|
1998-03-09 09:45:26 +08:00
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
g_free (config_caption_text);
|
|
|
|
g_free (config_cell_content);
|
|
|
|
g_free (config_cell_width);
|
|
|
|
g_free (config_cell_height);
|
|
|
|
|
2014-10-05 22:59:16 +08:00
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
return TRUE;
|
2014-10-05 22:59:16 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
2018-11-27 19:27:20 +08:00
|
|
|
cancellable = g_cancellable_new ();
|
|
|
|
g_cancellable_cancel (cancellable);
|
|
|
|
g_output_stream_close (output, cancellable, NULL);
|
|
|
|
g_object_unref (cancellable);
|
|
|
|
|
2014-10-05 22:59:16 +08:00
|
|
|
g_object_unref (output);
|
2018-05-14 07:27:03 +08:00
|
|
|
g_object_unref (sampler);
|
2014-10-05 22:59:16 +08:00
|
|
|
g_free (width);
|
|
|
|
g_free (height);
|
|
|
|
g_free (palloc);
|
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
g_free (config_caption_text);
|
|
|
|
g_free (config_cell_content);
|
|
|
|
g_free (config_cell_width);
|
|
|
|
g_free (config_cell_height);
|
|
|
|
|
2014-10-05 22:59:16 +08:00
|
|
|
return FALSE;
|
1998-02-22 06:14:06 +08:00
|
|
|
}
|
|
|
|
|
2000-01-07 06:26:10 +08:00
|
|
|
static gint
|
2019-10-06 21:36:48 +08:00
|
|
|
save_dialog (GimpImage *image,
|
|
|
|
GimpProcedure *procedure,
|
|
|
|
GObject *config)
|
1998-02-22 06:14:06 +08:00
|
|
|
{
|
2019-10-06 21:36:48 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *frame;
|
|
|
|
gboolean run;
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2019-09-21 01:39:00 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2024-04-20 11:08:57 +08:00
|
|
|
dialog = gimp_export_procedure_dialog_new (GIMP_EXPORT_PROCEDURE (procedure),
|
|
|
|
GIMP_PROCEDURE_CONFIG (config),
|
|
|
|
image);
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2021-04-06 06:47:07 +08:00
|
|
|
if (gimp_image_get_width (image) * gimp_image_get_height (image) > 4096)
|
2000-02-23 08:15:12 +08:00
|
|
|
{
|
|
|
|
GtkWidget *eek;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
|
2023-04-17 00:38:17 +08:00
|
|
|
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"warning-label",
|
|
|
|
_("You are about to create a huge\n"
|
|
|
|
"HTML file which will most likely\n"
|
2023-07-18 06:06:26 +08:00
|
|
|
"crash your browser."),
|
|
|
|
FALSE, FALSE);
|
2023-04-17 00:38:17 +08:00
|
|
|
hbox = gimp_procedure_dialog_fill_box (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"warning-hbox", "warning-label",
|
|
|
|
NULL);
|
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (hbox),
|
|
|
|
GTK_ORIENTATION_HORIZONTAL);
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2017-03-05 23:01:59 +08:00
|
|
|
eek = gtk_image_new_from_icon_name (GIMP_ICON_WILBER_EEK,
|
2014-05-12 06:20:48 +08:00
|
|
|
GTK_ICON_SIZE_DIALOG);
|
2004-05-19 23:28:01 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), eek, FALSE, FALSE, 0);
|
2023-04-17 00:38:17 +08:00
|
|
|
gtk_widget_show (eek);
|
|
|
|
gtk_box_reorder_child (GTK_BOX (hbox), eek, 0);
|
|
|
|
gtk_widget_set_margin_end (eek, 24);
|
|
|
|
|
|
|
|
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dialog),
|
2023-07-18 06:06:26 +08:00
|
|
|
"warning-frame-label", _("Warning"),
|
|
|
|
FALSE, FALSE);
|
2023-04-17 00:38:17 +08:00
|
|
|
frame = gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"warning-frame",
|
|
|
|
"warning-frame-label",
|
|
|
|
FALSE, "warning-hbox");
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
2000-02-23 08:15:12 +08:00
|
|
|
|
2023-04-17 00:38:17 +08:00
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"warning-frame", NULL);
|
2000-02-23 08:15:12 +08:00
|
|
|
}
|
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
/* HTML Page Options */
|
2023-04-17 00:38:17 +08:00
|
|
|
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dialog),
|
2023-07-18 06:06:26 +08:00
|
|
|
"page-label", _("HTML Page Options"),
|
|
|
|
FALSE, FALSE);
|
2023-04-17 00:38:17 +08:00
|
|
|
frame = gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"page-frame",
|
|
|
|
"page-label",
|
|
|
|
FALSE, "full-document");
|
|
|
|
gtk_widget_set_margin_bottom (frame, 8);
|
1998-02-22 06:14:06 +08:00
|
|
|
|
|
|
|
/* HTML Table Creation Options */
|
2023-04-17 00:38:17 +08:00
|
|
|
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"creation-label",
|
2023-07-18 06:06:26 +08:00
|
|
|
_("Table Creation Options"),
|
|
|
|
FALSE, FALSE);
|
2023-04-17 00:38:17 +08:00
|
|
|
|
|
|
|
gimp_procedure_dialog_fill_box (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"creation-vbox", "span-tags",
|
|
|
|
"compress-td-tags", "use-caption",
|
|
|
|
"caption-text", "cell-content", NULL);
|
|
|
|
|
|
|
|
gimp_procedure_dialog_set_sensitive (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"caption-text", TRUE,
|
|
|
|
config, "use-caption",
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
frame = gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"creation-frame",
|
|
|
|
"creation-label",
|
|
|
|
FALSE, "creation-vbox");
|
|
|
|
gtk_widget_set_margin_bottom (frame, 8);
|
1998-02-22 06:14:06 +08:00
|
|
|
/* HTML Table Options */
|
2023-04-17 00:38:17 +08:00
|
|
|
gimp_procedure_dialog_get_label (GIMP_PROCEDURE_DIALOG (dialog),
|
2023-07-18 06:06:26 +08:00
|
|
|
"table-label", _("Table Options"),
|
|
|
|
FALSE, FALSE);
|
2023-04-17 00:38:17 +08:00
|
|
|
|
|
|
|
gimp_procedure_dialog_fill_box (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"table-vbox", "border", "cell-width",
|
|
|
|
"cell-height", "cell-padding",
|
|
|
|
"cell-spacing", NULL);
|
|
|
|
|
|
|
|
frame = gimp_procedure_dialog_fill_frame (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"table-frame", "table-label",
|
|
|
|
FALSE, "table-vbox");
|
|
|
|
gtk_widget_set_margin_bottom (frame, 8);
|
|
|
|
|
|
|
|
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog),
|
|
|
|
"page-frame", "creation-frame",
|
|
|
|
"table-frame", NULL);
|
2001-12-29 21:26:29 +08:00
|
|
|
|
2005-09-10 02:38:00 +08:00
|
|
|
gtk_widget_show (dialog);
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2019-10-06 21:36:48 +08:00
|
|
|
run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2005-09-10 02:38:00 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
1998-02-22 06:14:06 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
1998-02-22 06:14:06 +08:00
|
|
|
}
|
|
|
|
|
2014-10-05 22:59:16 +08:00
|
|
|
static gboolean
|
|
|
|
print (GOutputStream *output,
|
|
|
|
GError **error,
|
|
|
|
const gchar *format,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
success = g_output_stream_vprintf (output, NULL, NULL,
|
|
|
|
error, format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2003-01-19 22:40:56 +08:00
|
|
|
static gboolean
|
2012-11-20 02:34:33 +08:00
|
|
|
color_comp (guchar *buf,
|
2008-10-20 14:04:39 +08:00
|
|
|
guchar *buf2)
|
2000-01-07 06:26:10 +08:00
|
|
|
{
|
2012-11-20 02:34:33 +08:00
|
|
|
return (buf[0] == buf2[0] &&
|
|
|
|
buf[1] == buf2[1] &&
|
|
|
|
buf[2] == buf2[2]);
|
2003-11-06 23:27:05 +08:00
|
|
|
}
|