1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
|
# GIMP - The GNU Image Manipulation Program
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (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
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
sub resource_get_by_name {
$blurb = "Returns a resource with the given name.";
$help = <<HELP;
Returns an existing resource having the given name.
Returns %NULL when no resource exists of that name.
There may be many fonts having the same name.
See gimp_font_get_by_name().
HELP
&jehan_pdb_misc('2023', '3.0');
$lib_private = 1;
@inargs = (
{ name => 'type_name', type => 'string', non_empty => 1,
desc => 'The name of the resource type e.g. GimpFont' },
{ name => 'resource_name', type => 'string', non_empty => 1,
desc => 'The name of the resource' }
);
@outargs = (
{ name => 'resource',
type => 'resource',
desc => "The resource",
none_ok => 1}
);
%invoke = (
code => <<'CODE'
{
resource = gimp_pdb_get_resource (gimp, g_type_from_name (type_name), resource_name,
GIMP_PDB_DATA_ACCESS_READ, error);
/* gimp_pdb_get_resource can return errors about writeable or renameable when not ACCESS_READ,
* but only "not found" error for ACCESS_READ.
* Ignore "not found" error, just return NULL.
*/
g_clear_error (error);
}
CODE
);
}
sub resource_get_by_identifiers {
$blurb = "Returns the resource contained in a given file with a given name.";
$help = <<'HELP';
Returns a resource specifically stored in a given file path, under a given name
(a single path may be a collection containing several resources).
HELP
&jehan_pdb_misc('2023', '3.0');
$lib_private = 1;
@inargs = (
{ name => 'type_name', type => 'string', non_empty => 1,
desc => 'The name of the resource type' },
{ name => 'resource_name', type => 'string', non_empty => 1,
desc => 'The name of the resource' },
{ name => 'collection', type => 'string', non_empty => 1,
desc => 'The collection identifier' },
{ name => 'is_internal', type => 'boolean',
desc => 'Whether this is the identifier for internal data'}
);
@outargs = (
{ name => 'resource',
type => 'resource',
desc => "The resource" }
);
%invoke = (
code => <<'CODE'
{
resource = gimp_pdb_get_resource_by_id (gimp, g_type_from_name (type_name),
resource_name, collection, is_internal,
GIMP_PDB_DATA_ACCESS_READ, error);
if (! resource)
success = FALSE;
}
CODE
);
}
sub resource_id_is_valid {
$blurb = 'Returns TRUE if the resource ID is valid.';
$help = <<'HELP';
This procedure checks if the given resource ID is valid and refers to an
existing resource.
*Note*: in most use cases, you should not use this function. If you got a
[class@Gimp.Resource] from the API, you should trust it is valid. This
function is mostly for internal usage.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID to check' }
);
@outargs = (
{ name => 'valid', type => 'boolean',
desc => 'Whether the resource ID is valid' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
valid = GIMP_IS_DATA (data);
}
CODE
);
}
sub resource_id_is_brush {
$blurb = 'Returns whether the resource ID is a brush.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a brush.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'brush', type => 'boolean',
desc => 'TRUE if the resource ID is a brush, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
brush = GIMP_IS_BRUSH (data);
}
CODE
);
}
sub resource_id_is_pattern {
$blurb = 'Returns whether the resource ID is a pattern.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a pattern.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'pattern', type => 'boolean',
desc => 'TRUE if the resource ID is a pattern, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
pattern = GIMP_IS_PATTERN (data);
}
CODE
);
}
sub resource_id_is_gradient {
$blurb = 'Returns whether the resource ID is a gradient.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a gradient.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'gradient', type => 'boolean',
desc => 'TRUE if the resource ID is a gradient, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
gradient = GIMP_IS_GRADIENT (data);
}
CODE
);
}
sub resource_id_is_palette {
$blurb = 'Returns whether the resource ID is a palette.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a palette.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'palette', type => 'boolean',
desc => 'TRUE if the resource ID is a palette, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
palette = GIMP_IS_PALETTE (data);
}
CODE
);
}
sub resource_id_is_font {
$blurb = 'Returns whether the resource ID is a font.';
$help = <<HELP;
This procedure returns TRUE if the specified resource ID is a font.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource_id', type => 'int32',
desc => 'The resource ID' }
);
@outargs = (
{ name => 'font', type => 'boolean',
desc => 'TRUE if the resource ID is a font, FALSE otherwise' }
);
%invoke = (
code => <<'CODE'
{
GimpData *data = gimp_data_get_by_id (resource_id);
font = GIMP_IS_FONT (data);
}
CODE
);
}
sub resource_get_name {
$blurb = "Returns the resource's name.";
$help = <<HELP;
This procedure returns the resource's name.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource', type => 'resource',
desc => 'The resource' }
);
@outargs = (
{ name => 'name', type => 'string',
desc => "The resource's name" }
);
%invoke = (
code => <<'CODE'
{
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (resource)));
}
CODE
);
}
sub resource_get_identifiers {
$blurb = "Returns a triplet identifying the resource.";
$help = <<HELP;
This procedure returns 2 strings and a boolean. The first string is the resource
name, similar to what you would obtain calling gimp_resource_get_name(). The
second is an opaque identifier for the collection this resource belongs to.
*Note*: as far as GIMP is concerned, a collection of resource usually corresponds
to a single file on disk (which may or may not contain several resources).
Therefore the identifier may be derived from the local file path. Nevertheless
you should not use this string as such as this is not guaranteed to be always
the case. You should consider it as an opaque identifier only to be used again
through _gimp_resource_get_by_identifier().
HELP
&jehan_pdb_misc('2023', '3.0');
$lib_private = 1;
@inargs = (
{ name => 'resource', type => 'resource',
desc => 'The resource' }
);
@outargs = (
{ name => 'is_internal', type => 'boolean',
desc => 'Whether this is the identifier for internal data'},
{ name => 'name', type => 'string',
desc => "The resource's name" },
{ name => 'collection_id', type => 'string',
desc => "The resource's collection identifier" }
);
%invoke = (
code => <<'CODE'
{
gimp_data_get_identifiers (GIMP_DATA (resource), &name, &collection_id, &is_internal);
}
CODE
);
}
sub resource_is_editable {
$blurb = "Whether the resource can be edited.";
$help = "Returns TRUE if you have permission to change the resource.";
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource', type => 'resource',
desc => 'The resource' }
);
@outargs = (
{ name => 'editable', type => 'boolean',
desc => 'TRUE if the resource can be edited' }
);
%invoke = (
code => <<'CODE'
{
editable = gimp_data_is_writable (GIMP_DATA (resource));
}
CODE
);
}
sub resource_duplicate {
$blurb = "Duplicates a resource.";
$help = "Returns a copy having a different, unique ID.";
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource', type => 'resource',
desc => 'The resource' }
);
@outargs = (
{ name => 'resource_copy',
type => 'resource',
desc => "A copy of the resource." }
);
%invoke = (
code => <<'CODE'
{
GimpDataFactory *factory;
factory = gimp_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
resource_copy = (GimpResource *)
gimp_data_factory_data_duplicate (factory, GIMP_DATA (resource));
if (! resource_copy)
success = FALSE;
}
CODE
);
}
sub resource_rename {
$blurb = "Renames a resource. When the name is in use, renames to a unique name.";
$help = <<'HELP';
Renames a resource. When the proposed name is already used, GIMP
generates a unique name.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource', type => 'resource',
desc => 'The resource' },
{ name => 'new_name', type => 'string', non_empty => 1,
desc => 'The proposed new name of the resource' }
);
%invoke = (
code => <<'CODE'
{
if (gimp_viewable_is_name_editable (GIMP_VIEWABLE (resource)))
{
gimp_object_set_name (GIMP_OBJECT (resource), new_name);
}
else
{
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
_("Resource '%s' is not renamable"),
gimp_object_get_name (GIMP_OBJECT (resource)));
success = FALSE;
}
}
CODE
);
}
sub resource_delete {
$blurb = "Deletes a resource.";
$help = <<'HELP';
Deletes a resource. Returns an error if the resource is not deletable.
Deletes the resource's data. You should not use the resource afterwards.
HELP
&mitch_pdb_misc('2023', '3.0');
@inargs = (
{ name => 'resource', type => 'resource',
desc => 'The resource' }
);
%invoke = (
code => <<'CODE'
{
GimpDataFactory *factory;
factory = gimp_get_data_factory (gimp, G_TYPE_FROM_INSTANCE (resource));
if (gimp_data_is_deletable (GIMP_DATA (resource)))
success = gimp_data_factory_data_delete (factory, GIMP_DATA (resource),
TRUE, error);
else
success = FALSE;
}
CODE
);
}
@headers = qw("core/gimp.h"
"core/gimpbrush.h"
"core/gimpdatafactory.h"
"core/gimpgradient.h"
"core/gimppalette.h"
"core/gimppattern.h"
"text/gimpfont.h"
"gimppdb-utils.h"
"gimppdberror.h"
"gimp-intl.h");
@procs = qw(resource_get_by_name
resource_get_by_identifiers
resource_id_is_valid
resource_id_is_brush
resource_id_is_pattern
resource_id_is_gradient
resource_id_is_palette
resource_id_is_font
resource_get_name
resource_get_identifiers
resource_is_editable
resource_duplicate
resource_rename
resource_delete);
%exports = (app => [@procs], lib => [@procs]);
$desc = 'Resource procedures';
$doc_title = 'gimpresource';
$doc_short_desc = 'Functions to manipulate resources.';
$doc_long_desc = 'Functions to manipulate resources.';
1;
|