90 lines
2.8 KiB
Perl
Executable File
90 lines
2.8 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
# <sjburges@gimp.org>
|
|
# This is adrian and xachs idea - take a rectangluar selection, and select
|
|
# font type and string. Then fill it with whatever size is needed.
|
|
|
|
use Gimp;
|
|
use Gimp::Fu;
|
|
use Gimp::Util;
|
|
|
|
# Gimp::set_trace(TRACE_ALL);
|
|
|
|
$defaultfont = "-*-blippo-heavy-r-normal-*-*-360-*-*-p-*-iso8859-1";
|
|
undef $defaultfont;
|
|
|
|
sub growfont {
|
|
($fontname, $plussize) = @_;
|
|
@fontdesc = split /-/, $fontname;
|
|
$fontdesc[8] += $plussize;
|
|
$outname = join "-", @fontdesc;
|
|
return $outname;
|
|
}
|
|
|
|
register "fit_text",
|
|
"Fit Text - fit text to a selection",
|
|
"Have a rectangular selection, and select the font type and spacing. It will fill the selection with text as closely as possible. If no selection is made prior to running, it will fill the entire image.",
|
|
"Seth Burgess",
|
|
"Seth Burgess <sjburges\@gimp.org>",
|
|
"1999-03-21",
|
|
"<Image>/Filters/Render/Fit Text",
|
|
"*",
|
|
[
|
|
[PF_FONT, "font", "What font type to use - size will be ignored", $defaultfont],
|
|
[PF_STRING, "string", "Text String to fill with", "Fit Text"],
|
|
],
|
|
[],
|
|
['gimp-1.1'],
|
|
sub {
|
|
my($img,$layer,$xlfd,$string) =@_;
|
|
($sel,$x1,$y1,$x2,$y2) = $img->gimp_selection_bounds;
|
|
$width = $x2-$x1;
|
|
$height = $y2-$y1;
|
|
|
|
@extents=gimp_text_get_extents_fontname($string,xlfd_size($xlfd),$xlfd);
|
|
$growsize = ($extents[0]<$width && $extents[1]<$height) ? 80 : -80;
|
|
if ($growsize > 0 ) {
|
|
while ($extents[0]<$width && $extents[1]<$height) {
|
|
$xlfd = growfont($xlfd,$growsize);
|
|
@extents=gimp_text_get_extents_fontname($string,xlfd_size($xlfd),$xlfd);
|
|
}
|
|
$xlfd = growfont($xlfd, -$growsize);
|
|
}
|
|
else {
|
|
while ($extents[0]>$width || $extents[1]>$height) {
|
|
$xlfd = growfont($xlfd,$growsize);
|
|
@extents=gimp_text_get_extents_fontname($string,xlfd_size($xlfd),$xlfd);
|
|
}
|
|
}
|
|
|
|
while ($extents[0]<$width && $extents[1]<$height) {
|
|
$xlfd = growfont($xlfd,10); # precision for the last bit
|
|
@extents=gimp_text_get_extents_fontname($string,xlfd_size($xlfd),$xlfd);
|
|
}
|
|
|
|
while ($extents[0]>$width || $extents[1]>$height) {
|
|
$xlfd = growfont($xlfd,-4);
|
|
@extents=gimp_text_get_extents_fontname($string,xlfd_size($xlfd),$xlfd);
|
|
}
|
|
# print $xlfd, "\n";
|
|
|
|
$tmplay = $layer->text_fontname($x1,$y1,$string,0,1,xlfd_size($xlfd), $xlfd);
|
|
$width2=$tmplay->width;
|
|
$height2=$tmplay->height;
|
|
|
|
# X returns crap, so fine tune it here.
|
|
# print "$width2, $height2:$width, $height\n";
|
|
while ($width2<$width && $height2<$height) {
|
|
$tmplay->remove;
|
|
$xlfd = growfont($xlfd,4);
|
|
$tmplay=$layer->text_fontname($x1,$y1,$string,0,1,xlfd_size($xlfd), $xlfd);
|
|
$width2=$tmplay->width;
|
|
$height2=$tmplay->height;
|
|
}
|
|
|
|
$tmplay->remove;
|
|
$xlfd = growfont($xlfd,-2);
|
|
$tmplay=$layer->text_fontname($x1,$y1,$string,0,1,xlfd_size($xlfd), $xlfd);
|
|
return();
|
|
};
|
|
exit main;
|