1469
|
1 #!/usr/bin/perl
|
|
2 use 5.6.0;
|
|
3 use warnings;
|
|
4 use strict;
|
|
5 use Gtk; # just so that compilation fails without it
|
|
6 use Gimp qw(:auto);
|
|
7 use Gimp::Feature qw(gimp-1.2);
|
|
8 use Gimp::Fu;
|
|
9
|
|
10 my $head = <<EOF;
|
|
11 [files]
|
|
12 alpha arpi_osd_a.raw
|
|
13 bitmap arpi_osd_b.raw
|
|
14
|
|
15 [characters]
|
|
16 0x01 0 36
|
|
17 0x02 35 71
|
|
18 0x03 70 106
|
|
19 0x04 116 152
|
|
20 0x05 164 200
|
|
21 0x06 209 245
|
|
22 0x07 256 292
|
|
23 0x08 305 342
|
|
24 0x09 354 400
|
|
25 0x0A 407 442
|
|
26 0x0B 457 494
|
|
27
|
|
28 [files]
|
|
29 alpha arpi_progress_a.raw
|
|
30 bitmap arpi_progress_b.raw
|
|
31
|
|
32 [characters]
|
|
33 0x10 4 21
|
|
34 0x11 30 41
|
|
35 0x12 50 66
|
|
36 0x13 74 85
|
|
37
|
|
38 EOF
|
|
39
|
|
40 sub geninfo {
|
|
41 my ($font, $height) = @_;
|
|
42
|
|
43 my $size = (split("-", $font))[7];
|
|
44 $font = (split("-", $font))[2];
|
|
45
|
|
46 return(sprintf(<<EOF, $font, $size, int($size/2), -3-int($size/10), $size));
|
|
47 [info]
|
|
48 name "%s \@%d; created in gimp; plugin by lanzz\@lanzz.org"
|
|
49 descversion 1
|
|
50 spacewidth %d
|
|
51 charspace %d
|
|
52 height %d
|
|
53
|
|
54 EOF
|
|
55 }
|
|
56
|
|
57 sub basename($) {
|
|
58 my ($f) = @_;
|
|
59 $f =~ m#([^/]*)$#;
|
|
60 return($1);
|
|
61 }
|
|
62
|
|
63 sub render_subfont {
|
|
64 my ($font, $bfile, $afile, $dfile, $keep) = @_;
|
|
65
|
|
66 my ($raw) = gimp_procedural_db_query("^file_raw_save\$", "","","","","","");
|
|
67 if ($raw ne "file_raw_save") {
|
|
68 gimp_message("HSI Raw plugin not installed");
|
|
69 return(undef);
|
|
70 }
|
|
71
|
|
72 unless (open(D, "> $dfile")) {
|
|
73 gimp_message("Cannot write to $dfile");
|
|
74 return(undef);
|
|
75 }
|
|
76
|
|
77 my @size = xlfd_size($font);
|
|
78 $size[0] *= 2;
|
|
79
|
|
80 my (undef, $h) = gimp_text_get_extents_fontname(join("", map(chr($_), 33 .. 255)), @size, $font);
|
|
81 $h += 10;
|
|
82 my $w = 0;
|
|
83 gimp_palette_set_foreground([255, 255, 255]);
|
|
84 gimp_palette_set_background([0, 0, 0]);
|
|
85
|
|
86 my $img = gimp_image_new(1, $h, GRAY);
|
|
87 gimp_image_undo_disable($img);
|
|
88 gimp_image_set_filename($img, $bfile);
|
|
89 my $draw = gimp_layer_new($img, 1, $h, GRAY_IMAGE, "subfont", 100, NORMAL_MODE);
|
|
90 gimp_image_add_layer($img, $draw, 0);
|
|
91 gimp_edit_fill($draw, BG_IMAGE_FILL);
|
|
92
|
|
93 my $x = 0;
|
|
94 print D (geninfo($font));
|
|
95 print D ($head);
|
|
96 printf D (<<EOF, basename($afile), basename($bfile));
|
|
97 [files]
|
|
98 alpha %s
|
|
99 bitmap %s
|
|
100
|
|
101 EOF
|
|
102
|
|
103 print D ("[characters]\n");
|
|
104 gimp_progress_init("Rendering font...");
|
|
105 for (my $c = 33; $c <= 255; $c++) {
|
|
106 my ($cw) = gimp_text_get_extents_fontname(chr($c), @size, $font);
|
|
107 printf D ("0x%02X %d %d\n", $c, int($x / 2), int(($x + $cw + 5) / 2));
|
|
108 $cw = (int($cw / 8) + 2) * 8;
|
|
109 $w += $cw;
|
|
110 gimp_image_resize($img, $w, $h, 0, 0);
|
|
111 gimp_layer_resize($draw, $w, $h, 0, 0);
|
|
112 gimp_floating_sel_anchor(gimp_text_fontname($img, $draw, $x + 5, 5, chr($c), -1, 1, @size, $font));
|
|
113 $x += $cw;
|
|
114 gimp_progress_update(($c - 33) / 222);
|
|
115 }
|
|
116 close(D);
|
|
117
|
|
118 gimp_image_scale($img, int($w / 2), int($h / 2));
|
|
119 gimp_image_undo_enable($img);
|
|
120 file_raw_save($img, $draw, $bfile, $bfile);
|
|
121
|
|
122 my $aimg = gimp_channel_ops_duplicate($img);
|
|
123 gimp_image_undo_disable($aimg);
|
|
124 gimp_image_set_filename($aimg, $afile);
|
|
125 $draw = gimp_image_flatten($aimg);
|
|
126 gimp_by_color_select($draw, [0, 0, 0], 15, REPLACE, 1, 0, 0, 0);
|
|
127 gimp_selection_invert($aimg);
|
|
128 gimp_selection_grow($aimg, 1);
|
|
129 gimp_edit_fill($draw, FG_IMAGE_FILL);
|
|
130 gimp_selection_clear($aimg);
|
|
131 plug_in_gauss_rle2($img, $draw, 3, 3);
|
|
132 gimp_image_undo_enable($aimg);
|
|
133 file_raw_save($aimg, $draw, $afile, $afile);
|
|
134
|
|
135 gimp_message(<<EOF);
|
|
136 Render done.
|
|
137
|
|
138 Bitmap: $bfile
|
|
139 Alpha: $afile
|
|
140 Desc: $dfile
|
|
141 EOF
|
|
142 if ($keep) {
|
|
143 gimp_image_clean_all($img);
|
|
144 gimp_image_clean_all($aimg);
|
|
145 return($img, $aimg);
|
|
146 } else {
|
|
147 return(undef);
|
|
148 }
|
|
149 }
|
|
150
|
|
151 sub render_subfont_alpha {
|
|
152 my ($img) = @_;
|
|
153
|
|
154 my $aimg = gimp_channel_ops_duplicate($img);
|
|
155 gimp_image_undo_disable($aimg);
|
|
156 gimp_image_set_filename($aimg, "alpha.raw");
|
|
157 my $draw = gimp_image_flatten($aimg);
|
|
158 gimp_by_color_select($draw, [0, 0, 0], 15, REPLACE, 1, 0, 0, 0);
|
|
159 gimp_selection_invert($aimg);
|
|
160 gimp_selection_grow($aimg, 1);
|
|
161 gimp_edit_fill($draw, FG_IMAGE_FILL);
|
|
162 gimp_selection_clear($aimg);
|
|
163 plug_in_gauss_rle2($img, $draw, 3, 3);
|
|
164 gimp_image_undo_enable($aimg);
|
|
165
|
|
166 return($aimg);
|
|
167 }
|
|
168
|
|
169 register(
|
|
170 "render_subfont",
|
|
171 "Render a grayscale MPlayer subtitle font",
|
|
172 "No help (yet)",
|
|
173 "lanzz\@lanzz.org",
|
|
174 "Copyright 2001, lanzz\@lanzz.org",
|
|
175 "2001-07-31",
|
|
176 "<Toolbox>/Xtns/MPlayer/Render Subfont",
|
|
177 undef,
|
|
178 [
|
|
179 [PF_FONT, "font", "", "-*-arial-medium-r-normal-*-16-*-*-*-*-*-*-*", undef],
|
|
180 [PF_FILE, "bitmap", "", "bitmap.raw", undef],
|
|
181 [PF_FILE, "alpha", "", "alpha.raw", undef],
|
|
182 [PF_FILE, "desc", "", "font.desc", undef],
|
|
183 [PF_TOGGLE, "toggle", "Keep images opened", 0, undef]
|
|
184 ],
|
|
185 [ ],
|
|
186 [ ],
|
|
187 \&render_subfont
|
|
188 );
|
|
189
|
|
190 register(
|
|
191 "render_subfont_alpha",
|
|
192 "Render alpha shadow for MPlayer subtitle font",
|
|
193 "No help (yet)",
|
|
194 "lanzz\@lanzz.org",
|
|
195 "Copyright 2001, lanzz\@lanzz.org",
|
|
196 "2001-07-31",
|
|
197 "<Image>/Filters/MPlayer/Render Shadow",
|
|
198 "GRAY",
|
|
199 [ ],
|
|
200 [ PF_IMAGE ],
|
|
201 [ ],
|
|
202 \&render_subfont_alpha
|
|
203 );
|
|
204
|
|
205 exit(main());
|