小学館の雑誌「サライ」[1] の最新号 2024年 9月号の大特集、「漢字」に遊ぶ を大変興味深く読みました。特に、石川祐基さんが案内する記事「町の漢字看板を楽しむ」(44 ページ)に触発され、自分も町を歩いて看板の文字を楽しんでみたくなりました。
さらに、今はフリーあるいはオープンソースのフォントが利用できるこの時代です。看板の漢字ではありませんが、デスクトップ画面でいろいろなデザインのフォントを見て楽しむこともできます。いろいろなフォントを紹介しているサイトはありますが、気に入ったデザインのフォントを自分なりのやり方で紹介したいと思いました。
紹介する第一弾のフォントは「ポプらむ☆キウイ」という、ポップ体のフォントです。ポップ体とは、POP 広告を制作するのに利用に適した書体のフォントです。
フォント名 | ポプらむ☆キウイ |
---|---|
収録字数 | JIS 第一水準 + JIS第二水準(184字)IBM 拡張漢字 |
配布ライセンス | SIL Open Font License, Version 1.1 |
配布サイト | ポプらむ☆キウイ | キウイ皮ごと齧る |
利用例を下記に示しました。
PopRumKiwi-Telop.ttf の利用例
使用したプログラム
スクリーンショット用に使用したプログラムを紹介しておきます。
下記の OS 環境で動作確認をしています。
![]() |
RHEL 9.4 | x86_64 |
Python | 3.12.1 | |
PySide6 | 6.7.2 |
プログラムを以下に示しました。
フォルダーボタンをクリックすると、ttf か otf の拡張子を持ったファイルを選択するダイアログが表示されます。読み込みたいファイルを選択すると、QPlainTextEdit のインスタンス内に入力する文字が読み込んだフォントで表示されます。
font-explorer.py
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
import os | |
import sys | |
from PySide6.QtCore import Qt | |
from PySide6.QtGui import QFontDatabase | |
from PySide6.QtWidgets import ( | |
QApplication, | |
QFileDialog, | |
QMainWindow, | |
QPlainTextEdit, | |
QStyle, | |
QToolBar, | |
QToolButton, | |
QVBoxLayout, | |
QWidget, | |
) | |
class FontChooser(QMainWindow): | |
__version__ = '1.0.0' | |
# CSS | |
style_panel = """ | |
QPlainTextEdit { | |
padding: 0.2em; | |
font-family: %s; | |
font-size: 32px; | |
color: Navy; | |
background-color: Ivory; | |
} | |
""" | |
def __init__(self): | |
super().__init__() | |
self.setWindowTitle('Font Explorer') | |
self.resize(450, 250) | |
toolbar = QToolBar() | |
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, toolbar) | |
but_open = QToolButton() | |
pixmap_icon = QStyle.StandardPixmap.SP_DirIcon | |
icon = self.style().standardIcon(pixmap_icon) | |
but_open.setIcon(icon) | |
but_open.clicked.connect(self.on_open) | |
toolbar.addWidget(but_open) | |
base = QWidget() | |
self.setCentralWidget(base) | |
layout = QVBoxLayout() | |
layout.setContentsMargins(0, 0, 0, 0) | |
base.setLayout(layout) | |
self.pte_font = pte_font = QPlainTextEdit() | |
pte_font.setStyleSheet(self.style_panel % 'sans-serif') | |
layout.addWidget(pte_font) | |
def on_open(self): | |
dialog = QFileDialog() | |
dialog.setNameFilters(['Font files (*.ttf *.otf)']) | |
if not dialog.exec(): | |
return | |
fontfile = dialog.selectedFiles()[0] | |
self.setWindowTitle(os.path.basename(fontfile)) | |
id = QFontDatabase.addApplicationFont(fontfile) | |
family = QFontDatabase.applicationFontFamilies(id)[0] | |
self.pte_font.setStyleSheet(self.style_panel % family) | |
def main(): | |
app = QApplication(sys.argv) | |
ex = FontChooser() | |
ex.show() | |
sys.exit(app.exec()) | |
if __name__ == '__main__': | |
main() |
参考・関連サイト

にほんブログ村
#オープンソース

0 件のコメント:
コメントを投稿