ASE_DAG
Gold Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Да, блин! Эта Панга, конечно, штука архизанятная, но чем я в конце концов занимаюсь? Допустим даже, что не один только черт разберет, как ей подсунуть файл шрифта не из каталогов fontconfigа (По всей видимости предусмотренным образом — никак, по крайней мере в документации про это ни слова.) Даже тогда — нафига это делать? Ведь велика ли проблема — верстка пословным переносом с выключкой по левому краю — набыдлокодить быстрее, чем в библиотеках копаться. Не, не ХеТеХ же подключать, правда? Так что держите-ка скриптик: Код: #!/usr/bin/perl # Copyright © 2015 Dmitry Alexandrov # # Copying and distribution of this file, with or without modification, # are permitted in any medium without royalty provided the copyright # notice and this notice are preserved. This file is offered as-is, # without any warranty. use warnings; use utf8; use Cairo; use Font::FreeType; binmode STDERR, ":utf8"; my $USAGE = "Usage: font-thumbnailer <font> <thumbnail-size> <output> Generate a pangram thumbnail for a font file. Intended to be used with GNOME, so <font> is a path to font file, possibly with ‘file:// scheme, <thumbnail-size> is a side of square in pixels, <output> is a name of a (temporary) file to write a PNG thumbnail."; my $pangrams = { en => "The juick brown fox jumps over the lazy dog.", ru => "Сешь еще этих мягких французских булок, да выпей же чаю.", }; my $font_size_min = 9; my $font_size_step = 3; my $margin_left = 1; my $margin_right = 1; my $margin_top = 1; my $line_height = 1.1; @ARGV == 3 or die "$USAGE\n"; my ( $font_file, $thumb_size, $thumb_file ) = @ARGV; $font_file =~ s,^file://,,; -f $font_file && -r $font_file or die "Cannot read ‘$font_file\n"; $thumb_size > 0 or die "‘$thumb_size is not a positive number\n"; my $canvas_width = my $canvas_height = $thumb_size; my ($lang) = split '[_.]', $ENV{LANG}; my $pangram = $pangrams->{$lang} ? $pangrams->{$lang} : $pangrams->{en}; my $surface = Cairo::ImageSurface->create( 'argb32', $canvas_width, $canvas_height ); my $cr = Cairo::Context->create($surface); my $ft_font_face = Font::FreeType->new->face($font_file); my $cr_font_face = Cairo::FtFontFace->create($ft_font_face); $cr->set_font_face($cr_font_face); for (my $font_size = $font_size_min, my $y = 0 + $margin_top + $font_size_min ; $y <= $canvas_height ; $font_size += $font_size_step, $y += $line_height * $font_size) { my $x = 0 + $margin_left; $cr->move_to( $x, $y ); $cr->set_font_size($font_size); my $space_width = $cr->text_extents(' ')->{x_advance}; for my $word ( split ' ', $pangram ) { my $word_width = $cr->text_extents($word)->{x_advance}; if ( $canvas_width - $x - $margin_right < $word_width ) { $x = $margin_left; $y += $line_height * $font_size; } $cr->move_to( $x, $y ); $cr->show_text($word); $x += $word_width + $space_width; } } $cr->fill; $surface->write_to_png($thumb_file) or die "Cannot write to $thumb_file\n"; | (Вся циферь с абсолютного потолка, меняйте без задних мыслей, если считаете нужным.) Положить (к примеру) в ~/.local/bin/font-thumbnailer, назначить бит исполняемости, убедиться, что ~/.local/bin числится в $PATH. То есть, что в ~/.profile есть что-то наподобие: # Set PATH so it includes users private local bin if it exists if [ -d "$HOME/.local/bin" ]; then export PATH="$HOME/.local/bin:$PATH" fi Оформить ~/.local/share/thumbnailer/font.thumbnailer подобным образом: [Thumbnailer Entry] TryExec=font-thumbnailer Exec=font-thumbnailer %u %s %o MimeType=application/x-font-ttf;application/x-font-pcf;application/x-font-type1;application/x-font-otf; И да, кэш эскизов — ~/.cache/thumbnails/ — если захотите его пересоздать по-новому, вероятно проще всего будет просто удалить целиком — не великой важности вещь. Выглядеть в Наутилусе это будет как-то так:
| Всего записей: 9272 | Зарегистр. 12-05-2005 | Отправлено: 02:35 03-11-2015 | Исправлено: ASE_DAG, 04:40 03-11-2015 |
|