Created
November 10, 2023 11:57
-
-
Save kuniyoshi/e448d27449513c557352473c78a952b9 to your computer and use it in GitHub Desktop.
TTF フォントを鏡文字に変換します
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Data::Dumper; | |
use Font::TTF::Font; | |
# 元のフォントファイルと出力するフォントファイルのパス | |
my $input_font_file = '/Users/kuniyoshi/Downloads/0xProto-Regular.ttf'; | |
my $output_font_file = '/Users/kuniyoshi/Desktop/reverse.ttf'; | |
# フォントを読み込む | |
my $font = Font::TTF::Font->open($input_font_file) or die "Cannot open font: $!"; | |
$font->tables_do(sub { $_[0]->read; }); | |
# 'name' テーブルを読み込む | |
$font->{'name'}->read; | |
# フォント名を変更する | |
foreach my $nameRecord (@{$font->{'name'}{'strings'}}) { | |
next | |
unless $nameRecord->[3]; | |
$nameRecord->[3][1]{1033} = join q{}, reverse split m{}, $nameRecord->[3][1]{1033}; | |
} | |
# 各グリフに対して処理を実行 | |
$font->{loca}->glyphs_do(sub { | |
my ($glyph) = @_; | |
return unless $glyph; | |
$glyph->read_dat; | |
$_ *= -1 | |
for @{ $glyph->{x} }; | |
$glyph->dirty(1); | |
$glyph->update; | |
}); | |
# 変更を加えたフォントを書き出す | |
$font->update; | |
$font->out($output_font_file); | |
# フォントを閉じる | |
$font->release; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment