text_layer.pdb 28 KB
Newer Older
1 2 3 4 5 6
# GIMP - The GNU Image Manipulation Program
# Copyright (C) 1995 Spencer Kimball and Peter Mattis

# New Text PDB API
# Copyright (C) 2008 Marcus Heese <heese@cip.ifi.lmu.de>

7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10 11 12 13 14 15 16 17
# (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
18
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 20 21 22 23 24


sub text_layer_new {
    $blurb = 'Creates a new text layer.';

    $help = <<'HELP';
25 26 27 28
This procedure creates a new text layer. The arguments are kept as
simple as necessary for the normal case. All text attributes, however,
can be modified with the appropriate gimp_text_layer_set_*()
procedures. The new layer still needs to be added to the image, as
29
this is not automatic. Add the new layer using gimp_image_insert_layer().
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
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'image', type => 'image',
          desc => 'The image' },
        { name => 'text', type => 'string',
          desc => 'The text to generate (in UTF-8 encoding)' },
        { name => 'fontname', type => 'string',
          desc => 'The name of the font' },
        { name => 'size', type => '0.0 <= float <= 8192.0',
          desc => 'The size of text in either pixels or points' },
        { name => 'unit', type => 'unit',
          desc => 'The units of specified size' }
    );

    @outargs = (
        { name => 'layer', type => 'layer',
          desc => 'The new text layer.' }
    );

    %invoke = (
        code => <<'CODE'
{
  GimpText *gimp_text;
  GimpRGB   color;

  gimp_context_get_foreground (context, &color);
  
  gimp_text = g_object_new (GIMP_TYPE_TEXT,
                            "text",           text,
                            "font",           fontname,
                            "font-size",      size,
                            "font-size-unit", unit,
                            "color",          &color,
                            NULL);
  
  layer = gimp_text_layer_new (image, gimp_text);
  g_object_unref (gimp_text);

  if (! layer)
    {
73
      g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
74 75 76 77 78 79 80 81 82
                   _("Failed to create text layer"));

      success = FALSE;
    }
}
CODE
    );
}

83 84
sub text_layer_get_text {
    $blurb = 'Get the text from a text layer as string.';
85 86

    $help = <<'HELP';
87
This procedure returns the text from a text layer as a string.
88 89 90 91 92 93
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
94
          desc => 'The text layer' }
95 96
    );

97 98 99 100 101
    @outargs = (
        { name => 'text', type => 'string',
          desc => 'The text from the specified text layer.' }
    );
    
102 103 104
    %invoke = (
        code => <<'CODE'
{
105
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
106
    {
107 108 109
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
                    "text", &text,
                    NULL);
110 111 112 113 114 115 116 117 118 119
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

120 121
sub text_layer_set_text {
    $blurb = 'Set the text of a text layer.';
122 123

    $help = <<'HELP';
124
This procedure changes the text of a text layer.
125 126 127 128 129 130 131
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer' },
132 133
        { name => 'text', type => 'string',
          desc => 'The new text to set' }
134 135 136 137 138
    );

    %invoke = (
        code => <<'CODE'
{
139
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
140 141 142
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
143
                           "text", text,
144 145 146 147 148 149 150 151 152 153 154
                           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

155 156 157 158 159 160
sub text_layer_get_markup {
    $blurb = 'Get the markup from a text layer as string.';

    $help = <<'HELP';
This procedure returns the markup of the styles from a text layer.
The markup will be in the form of Pango's markup - See
161
https://www.pango.org/ for more information about Pango and its markup.
162 163 164 165
Note: Setting the markup of a text layer using Pango's markup is not
supported for now.
HELP

166
    barak_pdb_misc('2010', '2.8');
167 168 169 170 171 172 173 174 175 176 177 178 179 180

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer' }
    );

    @outargs = (
        { name => 'markup', type => 'string',
          desc => 'The markup which represents the style of the specified text layer.' }
    );
    
    %invoke = (
        code => <<'CODE'
{
181
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
182 183 184 185 186 187 188 189 190 191 192 193 194 195
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
                    "markup", &markup,
                    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

196 197
sub text_layer_get_font {
    $blurb = 'Get the font from a text layer as string.';
198 199

    $help = <<'HELP';
200
This procedure returns the name of the font from a text layer.
201 202 203 204 205 206
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
207
          desc => 'The text layer' }
208 209
    );

210 211 212 213 214
    @outargs = (
        { name => 'font', type => 'string',
          desc => 'The font which is used in the specified text layer.' }
    );
    
215 216 217
    %invoke = (
        code => <<'CODE'
{
218
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
219
    {
220 221 222
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
                    "font", &font,
                    NULL);
223 224 225 226 227 228 229 230 231 232
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

233 234
sub text_layer_set_font {
    $blurb = 'Set the font of a text layer.';
235 236

    $help = <<'HELP';
237
This procedure modifies the font used in the specified text layer.
238 239 240 241 242 243 244
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer' },
245 246
        { name => 'font', type => 'string',
          desc => 'The new font to use' }
247 248 249 250 251
    );

    %invoke = (
        code => <<'CODE'
{
252
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
253 254 255
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
256
                           "font", font,
257 258 259 260 261 262 263 264 265 266 267
                           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

268 269
sub text_layer_get_font_size {
    $blurb = 'Get the font size from a text layer.';
270 271

    $help = <<'HELP';
272 273 274
This procedure returns the size of the font which is used in a text
layer. You will receive the size as a float 'font-size' in 'unit'
units.
275 276 277 278 279 280
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
281
          desc => 'The text layer' }
282 283
    );

284 285 286 287 288 289 290
    @outargs = (
        { name => 'font_size', type => 'float',
          desc => 'The font size' },
        { name => 'unit', type => 'unit',
          desc => 'The unit used for the font size' }
    );
    
291 292 293
    %invoke = (
        code => <<'CODE'
{
294
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
295
    {
296 297 298 299
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
                    "font-size",      &font_size,
                    "font-size-unit", &unit,
                    NULL);
300 301 302 303 304 305 306 307 308 309
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

310 311
sub text_layer_set_font_size {
    $blurb = 'Set the font size.';
312 313

    $help = <<'HELP';
314 315
This procedure changes the font size of a text layer. The size of your
font will be a double 'font-size' of 'unit' units.
316 317 318 319 320 321 322
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer' },
323 324 325 326
        { name => 'font_size', type => '0.0 <= float <= 8192.0',
          desc => 'The font size' },
        { name => 'unit', type => 'unit',
          desc => 'The unit to use for the font size' }
327 328 329 330 331
    );

    %invoke = (
        code => <<'CODE'
{
332
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
333 334 335
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
336 337
                           "font-size-unit", unit,
                           "font-size",      font_size,
338 339 340 341 342 343 344 345 346 347 348
                           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

349 350
sub text_layer_get_antialias {
    $blurb = 'Check if antialiasing is used in the text layer.';
351 352

    $help = <<'HELP';
353
This procedure checks if antialiasing is enabled in the specified text layer.
354 355 356 357 358 359
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
360 361 362 363 364 365
          desc => 'The text layer' }
    );

    @outargs = (
        { name => 'antialias', type => 'boolean',
          desc => 'A flag which is true if antialiasing is used for rendering the font in the text layer.' }
366 367 368 369 370
    );

    %invoke = (
        code => <<'CODE'
{
371
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
372
    {
373 374 375
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
                    "antialias", &antialias,
                    NULL);
376 377 378 379 380 381 382 383 384 385
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

386 387
sub text_layer_set_antialias {
    $blurb = 'Enable/disable anti-aliasing in a text layer.';
388 389

    $help = <<'HELP';
390
This procedure enables or disables anti-aliasing of the text in a text layer.
391 392 393 394 395 396 397
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer' },
398 399
        { name => 'antialias', type => 'boolean',
          desc => 'Enable/disable antialiasing of the text' }
400 401 402 403 404
    );

    %invoke = (
        code => <<'CODE'
{
405
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
406 407 408
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
409
                           "antialias", antialias,
410 411 412 413 414 415 416 417 418 419 420
                           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
sub text_layer_get_hint_style {
    $blurb = 'Get information about hinting in the specified text layer.';

    $help = <<'HELP';
This procedure provides information about the hinting that is being
used in a text layer. Hinting can be optimized for fidelity or contrast
or it can be turned entirely off.
HELP

    &marcus_pdb_misc('2008', '2.8');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer' }
    );

    @outargs = (
        { name => 'style', type => 'enum GimpTextHintStyle',
          desc => 'The hint style used for font outlines' }
    );
    
    %invoke = (
        code => <<'CODE'
{
445
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
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
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
                    "hint-style", &style,
                    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

sub text_layer_set_hint_style {
    $blurb = 'Control how font outlines are hinted in a text layer.';

    $help = <<'HELP';
This procedure sets the hint style for font outlines in a text
layer. This controls whether to fit font outlines to the pixel grid,
and if so, whether to optimize for fidelity or contrast.
HELP

    &neo_pdb_misc('2008', '2.8');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer' },
        { name => 'style', type => 'enum GimpTextHintStyle',
          desc => 'The new hint style' }
    );

    %invoke = (
        code => <<'CODE'
{
481
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
                           "hint-style", style,
                           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

497 498
sub text_layer_get_kerning {
    $blurb = 'Check if kerning is used in the text layer.';
499 500

    $help = <<'HELP';
501
This procedure checks if kerning is enabled in the specified text layer.
502 503 504 505 506 507
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
508 509
          desc => 'The text layer' }
    );
510

511 512 513 514 515 516 517
    @outargs = (
        { name => 'kerning', type => 'boolean',
          desc => 'A flag which is true if kerning is used in the text layer.' }
    );

    %invoke = (
        code => <<'CODE'
518
{
519
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
520
    {
521 522 523
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
                    "kerning", &kerning,
                    NULL);
524 525 526 527 528 529 530 531 532 533
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

534 535
sub text_layer_set_kerning {
    $blurb = 'Enable/disable kerning in a text layer.';
536 537

    $help = <<'HELP';
538
This procedure enables or disables kerning in a text layer.
539 540 541 542 543 544 545
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer' },
546 547
        { name => 'kerning', type => 'boolean',
          desc => 'Enable/disable kerning in the text' }
548 549 550 551 552
    );

    %invoke = (
        code => <<'CODE'
{
553
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
554 555 556
    {
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
557
                           "kerning", kerning,
558 559 560 561 562 563 564 565 566 567 568
                           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

569 570
sub text_layer_get_language {
    $blurb = 'Get the language used in the text layer.';
571 572

    $help = <<'HELP';
573 574
This procedure returns the language string which is set for the text
in the text layer.
575 576 577 578 579 580
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
581
          desc => 'The text layer.' }
582
    );
583 584 585 586 587 588 589

    @outargs = (
        { name => 'language', type => 'string',
          desc => 'The language used in the text layer.' }
    );

    %invoke = (
590 591
        code => <<'CODE'
{
592
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
593
    {
594 595 596
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
                    "language", &language,
                    NULL);
597 598 599 600 601 602 603 604 605 606
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

607 608
sub text_layer_set_language {
    $blurb = 'Set the language of the text layer.';
609 610

    $help = <<'HELP';
611 612
This procedure sets the language of the text in text layer. For some
scripts the language has an influence of how the text is rendered.
613 614 615 616 617 618
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
619 620 621
          desc => 'The text layer' },
        { name => 'language', type => 'string',
          desc => 'The new language to use for the text layer' }
622 623 624 625 626
    );

    %invoke = (
        code => <<'CODE'
{
627
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
628
    {
629 630 631 632
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
                           "language", language,
                           NULL);
633 634 635 636 637 638 639 640 641 642
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

643 644
sub text_layer_get_base_direction {
    $blurb = 'Get the base direction used for rendering the text layer.';
645 646

    $help = <<'HELP';
647 648
This procedure returns the base direction used for rendering the text
in the text layer
649 650 651 652 653 654
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
655
          desc => 'The text layer.' }
656 657 658
    );

    @outargs = (
659 660
        { name => 'direction', type => 'enum GimpTextDirection',
          desc => 'The based direction used for the text layer.' }
661
    );
662

663 664 665
    %invoke = (
        code => <<'CODE'
{
666
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
667 668
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
669
                    "base-direction", &direction,
670 671 672 673 674 675 676 677 678 679 680
                    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

681 682
sub text_layer_set_base_direction {
    $blurb = 'Set the base direction in the text layer.';
683 684

    $help = <<'HELP';
685 686
This procedure sets the base direction used in applying the Unicode
bidirectional algorithm when rendering the text.
687 688 689 690 691 692
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
693 694 695
          desc => 'The text layer' },
        { name => 'direction', type => 'enum GimpTextDirection',
          desc => 'The base direction of the text.' }
696 697 698 699 700
    );

    %invoke = (
        code => <<'CODE'
{
701
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
702
    {
703 704 705 706
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
                           "base-direction", direction,
                           NULL);
707 708 709 710 711 712 713 714 715 716
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

717 718
sub text_layer_get_justification {
    $blurb = 'Get the text justification information of the text layer.';
719 720

    $help = <<'HELP';
721 722
This procedure returns the alignment of the lines in the text layer
relative to each other.
723 724 725 726 727 728
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
729
          desc => 'The text layer.' }
730 731 732
    );

    @outargs = (
733 734
        { name => 'justify', type => 'enum GimpTextJustification',
          desc => 'The justification used in the text layer.' }
735
    );
736

737 738 739
    %invoke = (
        code => <<'CODE'
{
740
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
741 742
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
743
                    "justify", &justify,
744 745 746 747 748 749 750 751 752 753 754
                    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

755 756
sub text_layer_set_justification {
    $blurb = 'Set the justification of the text in a text layer.';
757 758

    $help = <<'HELP';
759 760
This procedure sets the alignment of the lines in the text layer
relative to each other.
761 762 763 764 765 766
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
767 768 769
          desc => 'The text layer' },
        { name => 'justify', type => 'enum GimpTextJustification',
          desc => 'The justification for your text.' }
770 771 772 773 774
    );

    %invoke = (
        code => <<'CODE'
{
775
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
776
    {
777 778 779 780
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
                           "justify", justify,
                           NULL);
781 782 783 784 785 786 787 788 789 790
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

791 792
sub text_layer_get_color {
    $blurb = 'Get the color of the text in a text layer.';
793 794

    $help = <<'HELP';
795
This procedure returns the color of the text in a text layer.
796 797 798 799 800 801
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
802
          desc => 'The text layer.' }
803 804 805
    );

    @outargs = (
806 807
        { name => 'color', type => 'color', void_ret => 1,
          desc => 'The color of the text.' }
808 809 810 811 812
    );

    %invoke = (
        code => <<'CODE'
{
813
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
814
    {
815
      color = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer))->color;
816 817 818 819 820 821 822 823 824 825
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

826 827
sub text_layer_set_color {
    $blurb = 'Set the color of the text in the text layer.';
828 829

    $help = <<'HELP';
830
This procedure sets the text color in the text layer 'layer'.
831 832 833 834 835 836
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
837 838 839
          desc => 'The text layer' },
        { name => 'color', type => 'color',
          desc => 'The color to use for the text' }
840 841 842 843 844
    );

    %invoke = (
        code => <<'CODE'
{
845
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
846
    {
847 848 849 850
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
                           "color", &color,
                           NULL);
851 852 853 854 855 856 857 858 859 860
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

861 862
sub text_layer_get_indent {
    $blurb = 'Get the line indentation of text layer.';
863 864

    $help = <<'HELP';
865
This procedure returns the indentation of the first line in a text layer.
866 867 868 869 870 871 872 873 874 875
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer.' }
    );

    @outargs = (
876 877
        { name => 'indent', type => 'float',
          desc => 'The indentation value of the first line.' }
878 879 880 881 882
    );

    %invoke = (
        code => <<'CODE'
{
883
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
884 885
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
886
                    "indent", &indent,
887 888 889 890 891 892 893 894 895 896 897
                    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

898 899
sub text_layer_set_indent {
    $blurb = 'Set the indentation of the first line in a text layer.';
900 901

    $help = <<'HELP';
902
This procedure sets the indentation of the first line in the text layer.
903 904 905 906 907 908
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
909 910 911 912
          desc => 'The text layer' },
        { name => 'indent', type => '-8192.0 <= float <= 8192.0',
          desc => 'The indentation for the first line.' }
     );
913

914 915
     %invoke = (
         code => <<'CODE'
916
{
917
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
918
    {
919 920 921 922
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
                           "indent", indent,
                           NULL);
923 924 925 926 927 928 929 930 931 932
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

933 934
sub text_layer_get_line_spacing {
    $blurb = 'Get the spacing between lines of text.';
935 936

    $help = <<'HELP';
937
This procedure returns the line-spacing between lines of text in a text layer.
938 939 940 941 942 943 944 945 946 947
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer.' }
    );

    @outargs = (
948 949
        { name => 'line_spacing', type => 'float',
          desc => 'The line-spacing value.' }
950 951 952 953 954
    );

    %invoke = (
        code => <<'CODE'
{
955
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
956 957
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
958
                    "line-spacing", &line_spacing,
959 960 961 962 963 964 965 966 967 968 969
                    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

970 971
sub text_layer_set_line_spacing {
    $blurb = 'Adjust the line spacing in a text layer.';
972 973

    $help = <<'HELP';
974
This procedure sets the additional spacing used between lines a text layer.
975 976 977 978 979 980
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
981 982 983
          desc => 'The text layer' },
        { name => 'line_spacing', type => '-8192.0 <= float <= 8192.0',
          desc => 'The additional line spacing to use.' }
984 985 986 987 988
    );

    %invoke = (
        code => <<'CODE'
{
989
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
990
    {
991 992 993 994
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
                           "line-spacing", line_spacing,
                           NULL);
995 996 997 998 999 1000 1001 1002 1003 1004
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

1005 1006
sub text_layer_get_letter_spacing {
    $blurb = 'Get the letter spacing used in a text layer.';
1007 1008

    $help = <<'HELP';
Richard Kreckel's avatar
Richard Kreckel committed
1009
This procedure returns the additional spacing between the single glyphs
1010
in a text layer.
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer.' }
    );

    @outargs = (
1021 1022
        { name => 'letter_spacing', type => 'float',
          desc => 'The letter-spacing value.' }
1023 1024 1025 1026 1027
    );

    %invoke = (
        code => <<'CODE'
{
1028
  if (gimp_pdb_layer_is_text_layer (layer, 0, error))
1029 1030
    {
      g_object_get (gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer)),
1031
                    "letter-spacing", &letter_spacing,
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
                    NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

1043 1044
sub text_layer_set_letter_spacing {
    $blurb = 'Adjust the letter spacing in a text layer.';
1045 1046

    $help = <<'HELP';
1047 1048
This procedure sets the additional spacing between the single glyphs
in a text layer.
1049 1050 1051 1052 1053 1054
HELP

    &marcus_pdb_misc('2008', '2.6');

    @inargs = (
        { name => 'layer', type => 'layer',
1055 1056 1057
          desc => 'The text layer' },
        { name => 'letter_spacing', type => '-8192.0 <= float <= 8192.0',
          desc => 'The additional letter spacing to use.' }
1058
    );
1059 1060
    
    %invoke = (    
1061 1062
        code => <<'CODE'
{
1063
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
1064
    {
1065 1066 1067 1068
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
                           "letter-spacing", letter_spacing,
                           NULL);
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

1079 1080 1081 1082 1083 1084 1085 1086 1087
sub text_layer_resize {
    $blurb = 'Resize the box of a text layer.';

    $help = <<'HELP';
This procedure changes the width and height of a text layer while
keeping it as a text layer and not converting it to a bitmap like
gimp_layer_resize() would do.
HELP

1088
    barak_pdb_misc('2009', '2.8');
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101

    @inargs = (
        { name => 'layer', type => 'layer',
          desc => 'The text layer' },
        { name => 'width', type => '0.0 <= float <= GIMP_MAX_IMAGE_SIZE',
          desc => 'The new box width in pixels' },
        { name => 'height', type => '0.0 <= float <= GIMP_MAX_IMAGE_SIZE',
          desc => 'The new box height in pixels' },
    );

    %invoke = (
        code => <<'CODE'
{
1102
  if (gimp_pdb_layer_is_text_layer (layer, GIMP_PDB_ITEM_CONTENT, error))
1103
    {
1104 1105
      GimpText *text = gimp_text_layer_get_text (GIMP_TEXT_LAYER (layer));
      gdouble   xres, yres;
1106 1107 1108 1109

      gimp_image_get_resolution (gimp_item_get_image (GIMP_ITEM (layer)),
                                 &xres, &yres);

1110 1111
      gimp_text_layer_set (GIMP_TEXT_LAYER (layer),
                           _("Set text layer attribute"),
1112 1113
                           "box-mode",   GIMP_TEXT_BOX_FIXED,
                           "box-width",  gimp_pixels_to_units (width,
1114
                                                               text->box_unit,
1115 1116
                                                               xres),
                           "box-height", gimp_pixels_to_units (height,
1117
                                                               text->box_unit,
1118
                                                               yres),
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
                           NULL);
    }
  else
    {
      success = FALSE;
    }
}
CODE
    );
}

1130 1131 1132

@headers = qw("libgimpbase/gimpbase.h"
              "core/gimpcontext.h"
1133 1134 1135 1136
              "text/gimptext.h"
              "text/gimptextlayer.h"
              "gimppdb-utils.h"
              "gimppdberror.h"
1137 1138 1139 1140
              "gimp-intl.h");

@procs = qw(text_layer_new
            text_layer_get_text
1141
            text_layer_set_text
1142
            text_layer_get_markup
1143
            text_layer_get_font
1144 1145 1146
            text_layer_set_font
            text_layer_get_font_size
            text_layer_set_font_size
1147
            text_layer_get_antialias
1148
            text_layer_set_antialias
1149 1150
            text_layer_get_hint_style
            text_layer_set_hint_style
1151
            text_layer_get_kerning
1152
            text_layer_set_kerning
1153
            text_layer_get_language
1154
            text_layer_set_language
1155
            text_layer_get_base_direction
1156
            text_layer_set_base_direction
1157
            text_layer_get_justification
1158
            text_layer_set_justification
1159
            text_layer_get_color
1160
            text_layer_set_color
1161
            text_layer_get_indent
1162
            text_layer_set_indent
1163
            text_layer_get_line_spacing
1164 1165
            text_layer_set_line_spacing
            text_layer_get_letter_spacing
1166
            text_layer_set_letter_spacing
1167
            text_layer_resize);
1168 1169 1170 1171

%exports = (app => [@procs], lib => [@procs]);

$desc = 'Text layer procedures';
1172 1173 1174
$doc_title = 'gimptextlayer';
$doc_short_desc = 'Functions for querying and manipulating text layers.';
$doc_long_desc = 'Functions for querying and manipulating text layers.';
1175 1176

1;