2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1998-07-09 13:31:06 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimp_brush_generated module Copyright 1998 Jay Cox <jaycox@earthlink.net>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-07-09 13:31: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-07-09 13:31: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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1998-07-09 13:31:06 +08:00
|
|
|
*/
|
2000-09-29 20:00:00 +08:00
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2004-01-19 09:54:11 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
1998-07-09 13:31:06 +08:00
|
|
|
#include "gimpbrushgenerated.h"
|
2006-10-03 20:29:07 +08:00
|
|
|
#include "gimpbrushgenerated-save.h"
|
1998-07-09 13:31:06 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-12-02 21:39:09 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2006-10-03 20:29:07 +08:00
|
|
|
gboolean
|
2014-07-04 05:44:38 +08:00
|
|
|
gimp_brush_generated_save (GimpData *data,
|
|
|
|
GOutputStream *output,
|
|
|
|
GError **error)
|
2001-02-11 09:39:24 +08:00
|
|
|
{
|
2004-01-30 00:19:57 +08:00
|
|
|
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
|
2009-09-01 04:47:18 +08:00
|
|
|
const gchar *name = gimp_object_get_name (data);
|
2014-07-03 04:16:09 +08:00
|
|
|
GString *string;
|
2001-10-29 20:51:21 +08:00
|
|
|
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
|
2004-08-02 01:20:00 +08:00
|
|
|
gboolean have_shape = FALSE;
|
2001-02-05 01:34:30 +08:00
|
|
|
|
2006-05-29 23:43:05 +08:00
|
|
|
g_return_val_if_fail (name != NULL && *name != '\0', FALSE);
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* write magic header */
|
2014-07-03 04:16:09 +08:00
|
|
|
string = g_string_new ("GIMP-VBR\n");
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write version */
|
2004-08-02 01:20:00 +08:00
|
|
|
if (brush->shape != GIMP_BRUSH_GENERATED_CIRCLE || brush->spikes > 2)
|
|
|
|
{
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append (string, "1.5\n");
|
2004-08-02 01:20:00 +08:00
|
|
|
have_shape = TRUE;
|
|
|
|
}
|
2004-08-01 11:06:58 +08:00
|
|
|
else
|
2004-08-02 01:20:00 +08:00
|
|
|
{
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append (string, "1.0\n");
|
2004-08-02 01:20:00 +08:00
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write name */
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append_printf (string, "%.255s\n", name);
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
if (have_shape)
|
2004-08-01 11:06:58 +08:00
|
|
|
{
|
|
|
|
GEnumClass *enum_class;
|
|
|
|
GEnumValue *shape_val;
|
|
|
|
|
|
|
|
enum_class = g_type_class_peek (GIMP_TYPE_BRUSH_GENERATED_SHAPE);
|
|
|
|
|
|
|
|
/* write shape */
|
|
|
|
shape_val = g_enum_get_value (enum_class, brush->shape);
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append_printf (string, "%s\n", shape_val->value_nick);
|
2004-08-01 11:06:58 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* write brush spacing */
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
gimp_brush_get_spacing (GIMP_BRUSH (brush))));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write brush radius */
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
brush->radius));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2004-08-02 01:20:00 +08:00
|
|
|
if (have_shape)
|
|
|
|
{
|
|
|
|
/* write brush spikes */
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append_printf (string, "%d\n", brush->spikes);
|
2004-08-02 01:20:00 +08:00
|
|
|
}
|
|
|
|
|
1999-10-27 02:27:27 +08:00
|
|
|
/* write brush hardness */
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
brush->hardness));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write brush aspect_ratio */
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
brush->aspect_ratio));
|
1999-10-27 02:27:27 +08:00
|
|
|
|
|
|
|
/* write brush angle */
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_append_printf (string, "%s\n",
|
|
|
|
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
|
|
|
brush->angle));
|
|
|
|
|
|
|
|
if (! g_output_stream_write_all (output, string->str, string->len,
|
2014-09-08 02:30:14 +08:00
|
|
|
NULL, NULL, error))
|
2014-07-03 04:16:09 +08:00
|
|
|
{
|
|
|
|
g_string_free (string, TRUE);
|
2014-07-05 00:46:02 +08:00
|
|
|
|
2014-07-03 04:16:09 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2014-07-03 04:16:09 +08:00
|
|
|
g_string_free (string, TRUE);
|
1999-10-27 02:27:27 +08:00
|
|
|
|
2001-02-11 09:39:24 +08:00
|
|
|
return TRUE;
|
1998-07-15 20:15:24 +08:00
|
|
|
}
|