fontTools
上のフレンドリーなフォント操作。 ?
pip インストール python-fontbro
フォントクラスをインポートするだけです。
from fontbro import Fontfont = Font("fonts/MyFont.ttf")# または、ファイルのようなオブジェクトを使用できます:with open("fonts/MyFont.ttf") as fh:font = Font(fh)
clone
close
from_collection
get_characters
get_characters_count
get_family_classification
get_family_name
get_features
get_features_tags
get_filename
get_fingerprint
get_fingerprint_match
get_format
get_glyphs
get_glyphs_count
get_image
get_italic_angle
get_name
get_names
get_style_flag
get_style_flags
get_style_name
get_svg
get_ttfont
get_unicode_block_by_name
get_unicode_blocks
get_unicode_script_by_name
get_unicode_scripts
get_variable_axes
get_variable_axes_tags
get_variable_axis_by_tag
get_variable_instances
get_variable_instance_by_style_name
get_variable_instance_closest_to_coordinates
get_version
get_vertical_metrics
get_weight
get_width
is_color
is_monospace
is_static
is_variable
rename
sanitize
save
save_as_woff
save_as_woff2
save_to_file_object
save_variable_instances
set_family_classification
set_family_name
set_name
set_names
set_style_flag
set_style_flags
set_style_flags_by_subfamily_name
set_style_name
set_vertical_metrics
subset
to_sliced_variable
to_static
clone
"""同じバイナリ ファイルを読み取る新しい Font インスタンスを作成します。"""font_clone = font.clone()
close
"""ラップされた TTFont インスタンスを閉じます。"""font.close()
from_collection
"""フォント コレクション ファイル (.ttc / .otc) から Font オブジェクトのリストを取得します:param filepath: filepath:type filepath: str または pathlib.Path:returns: Font オブジェクトのリスト。:rtype: list" ""fonts = Font.from_collection(filepath="my-font-collection.ttc")
get_characters
"""フォント文字を取得します。:paramignore_blank: True の場合、輪郭のない文字は返されません。:typeignore_blank: bool:returns: 文字。:rtype: dict のジェネレーター:raises TypeError: 見つからない場合フォント内の「最良の」Unicode cmap dict。"""chars = font.get_characters(ignore_blank=False)
get_characters_count
"""フォントの文字数を取得します。:paramignore_blank: True の場合、輪郭のない文字はカウントされません。:typeignore_blank: bool:returns: 文字数をカウントします。:rtype: int"""chars_count = font.get_characters_count(ignore_blank =偽)
get_family_classification
"""OS/2 テーブルから sFamilyClass フィールドを読み取ってフォント ファミリ分類情報を取得します。OS/2 テーブルが使用できない場合は、何も返されません。:戻り値: フォント ファミリ分類情報を含む辞書。例: { "full_name": "サンセリフ/ネオグロテスクゴシック"、"class_id": 8、"class_name": "Sans Serif"、"subclass_id": 5、"subclass_name": "ネオグロテスクゴシック", }:rtype: dict"""family_classification = font.get_family_classification()
get_family_name
"""名前レコードを優先順位 (16, 21, 1) で読み取ってファミリー名を取得します。:returns: フォントファミリー名。:rtype: str"""family_name = font.get_family_name()
get_features
"""フォントの opentype 機能を取得します。:returns: 機能。:rtype: dict のリスト"""features = font.get_features()
get_features_tags
"""フォントの OpenType 機能タグを取得します。:returns: 機能タグのリスト。:rtype: str のリスト"""features_tags = font.get_features_tags()
get_filename
"""フォントをファイル システムに保存するために使用するファイル名を取得します。:param variable_suffix: 変数の接尾辞、デフォルト "Variable":type variable_suffix: str:param variable_axes_tags: 変数の軸タグ フラグ (True の場合、軸タグ)追加されます。例: '[wght,wdth]':type variable_axes_tags: bool:param variable_axes_values: 変数軸値フラグ True の場合、各軸値が追加されます。例: '[wght(100,100,900),wdth(75,100,125)]':type variable_axes_values: bool:returns: ファイル名.:rtype: str"""filename = font.get_filename(variable_suffix="変数", variable_axes_tags=True、variable_axes_values=False)
get_fingerprint
"""フォント フィンガープリントを取得します: フォントの画像表現から計算されたハッシュ。テキスト オプションを変更すると、返されるフィンガープリントに影響します。:param text: フィンガープリントの生成に使用されるテキスト、デフォルト値: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".:type text : str:returns: フィンガープリントhash.:rtype: imagehash.ImageHash"""hash = font.get_fingerprint()
get_fingerprint_match
"""このフォントと別のフォントの間のフィンガープリントの一致を取得します。フィンガープリントが等しいかどうか (差 <= 許容値) をチェックすることによって取得します。:param other: 他のフォントは、ファイルパスまたはフォント インスタンスのいずれかです。:type other: str または Font:param許容値: diff 許容値、デフォルト 3.:type許容値: int:param text: フィンガープリントの生成に使用されるテキスト、デフォルト値: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".:type text: str:returns: 一致情報 (match、diff、hash、other_hash) を含むタプル。:rtype: tuple"""match、diff、hash、other_hash = font.get_fingerprint_match(other="other_font.ttf"、許容値=10)
get_format
"""フォント形式を取得します: otf、ttf、woff、woff2。:paramignore_flavor: True の場合、圧縮なしの元の形式が返されます。:typeignore_flavor: bool:returns: 形式。:rtype: str または None" ""format = font.get_format(ignore_flavor=False)
get_glyphs
"""フォントグリフとその独自の構成を取得します。:戻り値: グリフ。:rtype: dict のジェネレーター"""glyphs = font.get_glyphs()
get_glyphs_count
"""フォントのグリフ数を取得します。:returns: グリフ数。:rtype: int"""glyphs_count = font.get_glyphs_count()
get_image
"""指定されたオプションを使用してテキストをレンダリングするフォントのイメージ表現を取得します。:param text: 画像でレンダリングされるテキスト:type text: str:param size: フォント サイズ:type size: int:param color: テキストcolor:type color:タプル:parambackground_color:背景 color:typebackground_color:タプル"""img = font.get_image(text="Hello!", size=48, color=(0, 0, 0, 255)、背景色=(255, 255, 255, 255))
get_italic_angle
"""フォントのイタリック角度を取得します。:戻り値: バックスラント、イタリック、ローマン フラグを含む角度値。:rtype: dict または None"""italic_angle = font.get_italic_angle()
get_name
"""フォント名テーブルから識別子によって名前を取得します。:param key: 名前の ID またはキー (例: "family_name"):type key: int または str:returns: 名前。:rtype: str または None :raises KeyError: キーが有効な名前ではない場合 key/id"""family_name = font.get_name(key=Font.NAME_FAMILY_NAME)
get_names
"""プロパティ名によってマップされた名前レコードを取得します。:戻り値:名前。:rtype: dict"""names = font.get_names()
get_style_flag
"""OS/2 および macStyle テーブルを読み取るスタイル フラグを取得します。:param キー: key:type キー: string:returns: スタイル フラグ。:rtype: bool"""flag = font.get_style_flag(Font.STYLE_FLAG_BOLD)
get_style_flags
"""OS/2 および macStyle テーブルを読み取るスタイル フラグを取得します。:returns: スタイル フラグを表す dict。:rtype: dict"""flags = font.get_style_flags()
get_style_name
"""名前レコードを優先順位 (17、22、2) で読み取ってスタイル名を取得します。:returns: フォント スタイル名。:rtype: str"""style_name = font.get_style_name()
get_svg
"""指定されたオプションを使用してテキストをレンダリングするフォントの SVG 表現を取得します。:param text: SVG パスとしてレンダリングされるテキスト。:type text: str:param size: レンダリングに使用されるフォントのサイズテキスト、ポイント単位。:type size: int:returns: レンダリングされたテキストを表す SVG 文字列。:rtype: str"""svg_str = font.get_svg(text="こんにちは!", size=48)
get_ttfont
"""ラップされた TTFont インスタンスを取得します。:returns: TTFont インスタンス。:rtype: TTFont"""ttfont = font.get_ttfont()
get_unicode_block_by_name
"""Unicode ブロックを名前で取得します (名前は大文字と小文字が区別されず、「-」は無視されます)。:param name: name:type name: str:returns: 名前が有効な場合は Unicode ブロックの辞書、それ以外の場合は None。: rtype: dict または None"""block = font.get_unicode_block_by_name(name="Basic Latin")
get_unicode_blocks
"""Unicode ブロックとそのカバレッジを取得します。カバレッジ >= Coverage_threshold (0.0 <= Coverage_threshold <= 1.0) を持つブロックのみが返されます。:param Coverage_threshold: 返されるブロックに必要な最小カバレッジ。:type Coverage_threshold: float:returns: Unicode ブロックのリスト。:rtype: dict のリスト"""blocks = font.get_unicode_blocks(coverage_threshold=0.00001)
get_unicode_script_by_name
"""名前/タグによって Unicode スクリプトを取得します (名前/タグは大文字と小文字が区別されず、「-」は無視されます)。:param name: name:type name: str:returns: 名前/タグが次の場合の Unicode スクリプトの辞書有効、それ以外の場合はなし。:rtype: dict または None"""script = font.get_unicode_script_by_name(name="Latn")
get_unicode_scripts
"""Unicode スクリプトとそのカバレッジを取得します。カバレッジ >= Coverage_threshold (0.0 <= Coverage_threshold <= 1.0) を持つスクリプトのみが返されます。:param Coverage_threshold: 返されるスクリプトに必要な最小カバレッジ。:type Coverage_threshold: float:returns: Unicode スクリプトのリスト。:rtype: dict のリスト"""scripts = font.get_unicode_scripts(coverage_threshold=0.00001)
get_variable_axes
"""フォント変数 axes を取得します。:returns: フォントが可変フォントの場合は Axes のリスト、それ以外の場合は None.:rtype: dict のリストまたは None"""axes = font.get_variable_axes()
get_variable_axes_tags
"""変数軸のタグを取得します。:戻り値: 変数軸のタグ。:rtype: リストまたはなし"""axes_tags = font.get_variable_axes_tags()
get_variable_axis_by_tag
"""タグによって変数軸を取得します。:param タグ: tag:type タグ: string:returns: タグによって変数軸。:rtype: dict または None"""axis = font.get_variable_axis_by_tag(tag="wght" )
get_variable_instances
"""変数インスタンスを取得します。:returns: フォントが可変フォントの場合はインスタンスのリスト、それ以外の場合はなし。:rtype: dict のリストまたは None"""instances = font.get_variable_instances()
get_variable_instance_by_style_name
"""スタイル名で変数インスタンスを取得します。例: style_name = 'Bold':param style_name: スタイル名:type style_name: str:returns: 指定されたスタイル名に一致する変数インスタンス。:rtype: dict または None"" "instance = font.get_variable_instance_by_style_name(style_name="Bold")
get_variable_instance_closest_to_coordinates
"""座標に最も近い変数インスタンスを取得します。例: 座標 = {"wght": 1000, "slnt": 815, "wdth": 775}座標で一部の軸が指定されていない場合は、軸のデフォルト値が検索に使用されます。 :param 座標: 座標:型座標: dict:returns: 座標に最も近い変数インスタンス。:rtype: dict または None"""instance = font.get_variable_instance_closest_to_coowned(座標={"wght": 1000, "slnt": 815, "wdth": 775})
get_version
"""フォント バージョンを取得します。:returns: フォント バージョン値。:rtype: float"""version = font.get_version()
get_vertical_metrics
"""フォントの垂直方向のメトリックを取得します。:戻り値: 次の垂直方向のメトリックを含む辞書: "units_per_em"、"y_max"、"y_min"、"ascent"、"descent"、"line_gap"、"typo_ascender"、"typo_descender" "、"typo_line_gap"、"cap_height"、"x_height"、"win_ascent"、 "win_descent":rtype: dict"""metrics = font.get_vertical_metrics()
get_weight
"""フォントのウェイト値と名前を取得します。:戻り値: ウェイト名と値。:rtype: dict または None"""weight = font.get_weight()
get_width
"""フォント幅の値と名前を取得します。:戻り値: 幅の名前と値。:rtype: dict または None"""width = font.get_width()
is_color
"""フォントがカラー フォントかどうかを判断します。:returns: カラー フォントの場合は True、それ以外の場合は False。:rtype: bool"""color = font.is_color()
is_monospace
"""フォントが等幅フォントかどうかを決定します。:param しきい値: フォントを等幅とみなすための同じ幅を持つグリフのしきい値 (0.0 <= n <= 1.0)。:type Threshold: float:returns: True if等幅フォント、それ以外の場合は False。:rtype: bool"""mono = font.is_monospace(threshold=0.85)
is_static
"""フォントが静的フォントかどうかを判断します。:returns: 静的フォントの場合は True、それ以外の場合は False。:rtype: bool"""static = font.is_static()
is_variable
"""フォントが可変フォントかどうかを判断します。:戻り値: 可変フォントの場合は True、それ以外の場合は False。:rtype: bool"""variable = font.is_variable()
rename
"""指定された family_name と style_name (subfamily_name) に従ってフォント名レコード (1、2、4、6、16、17) の名前を変更します。 family_name が定義されていない場合は自動検出されます。 style_name が定義されていない場合は、自動検出されます。:param family_name: ファミリ名:type family_name: str:param style_name: スタイル名:type style_name: str:param update_style_flags: True の場合、スタイル フラグはサブファミリー名:type によって更新されます update_style_flags: bool:raises ValueError: 計算された PostScript-name が 63 文字を超える場合。"""font.rename(family_name="My Font New "、style_name="太字斜体"、update_style_flags=True)
sanitize
"""OpenType Sanitizer を使用してフォント ファイルをサニタイズします。https://github.com/googlefonts/ots-python:param strict: True (デフォルト) の場合、サニタイザーの警告でも例外が発生します。False の場合、例外が発生するだけです。サニタイザーの失敗 (ゼロ以外の終了コード)。:type strict: bool:raises 例外: OpenType Sanitizer がサニタイズ プロセス中にエラーを報告した場合。:return:なし: 注: OpenType サニタイザー (ots) を使用して、フォント ファイルを一時ディレクトリに保存し、保存されたファイルに対してサニタイザーを呼び出します。 `strict` が True (デフォルト) の場合、サニタイザーの警告をエラーとして扱います。 strict` は False で、サニタイザー エラーのみをチェックします。"""font.sanitize(strict=True)
save
"""フォントをファイルパスに保存します。:param filepath: ファイルパス、None の場合はソース ファイルパスが使用されます:type filepath: str または None:param overwrite: 上書き、True の場合はソース フォント ファイルを上書きできます:type overwrite : bool:returns: フォントが保存されているファイルパス。:rtype: str:raises ValueError: ファイルパスがソースフォントと同じで、上書きできない場合"""saved_font_path = font.save(ファイルパス=なし、上書き=False)
save_as_woff
"""フォントを woff として保存します。:param filepath: ファイルパス:type filepath: str:param overwrite: 上書き、True の場合はソース フォント ファイルを上書きできます:type overwrite: bool:returns: フォントが保存されているファイルパス保存先:rtype: str"""saved_font_path = font.save_as_woff(filepath=None、overwrite=True)
save_as_woff2
"""フォントを woff2 として保存します。:param filepath: ファイルパス:type filepath: str:param overwrite: 上書き、True の場合はソース フォント ファイルを上書きできます:type overwrite: bool:returns: フォントが保存されているファイルパス保存先:rtype: str"""saved_font_path = font.save_as_woff2(filepath=None、overwrite=True)
save_to_fileobject
"""フォントをファイルのようなオブジェクトに書き込みます。ファイル オブジェクトが渡されない場合、ユーザー用に `BytesIO` のインスタンスが作成されます。:param fileobject: 書き込むファイルのようなオブジェクト。:returns: ファイル元々渡されたオブジェクト、または新しい BytesIOinstance.:rtype: testing.io.IO"""fileobject = font.save_to_fileobject(fileobject=None)
save_variable_instances
"""可変フォントのすべてのインスタンスを、指定されたディレクトリに 1 つ以上の形式で保存します。:param dirpath: dirpath:type dirpath: インスタンスが保存されるディレクトリ パス。:param woff2: インスタンスを保存するかどうかデフォルトは True.:type woff2: bool:param woff: インスタンスを WOFF 形式でも保存するかどうか。デフォルトは True.:type woff: bool:param overwrite: ディレクトリ内の既存のファイルを上書きするかどうか。デフォルトは True。:type overwrite: bool:param options: 静的インスタンスの生成時にインスタンスに渡される追加オプション。:type options:dictionary:returns: リスト各保存されたインスタンスの辞書が含まれます。各辞書には、「インスタンス」(インスタンスのメタデータを含む) と「ファイル」(ファイル形式をキーとして、ファイルパスを値として含む辞書) が含まれます。 TypeError: フォントが可変フォントではない場合。"""saved_fonts = font.save_variable_instances(dirpath, woff2=True, woff=True, overwrite=True, **options)
set_family_classification
"""指定された class_id と subclass_id に基づいてフォント ファミリ分類 (OS/2 テーブルの sFamilyClass) を設定します。:param class_id: フォント ファミリ クラスの数値識別子。:param subclass_id: フォント ファミリ サブクラスのオプションの数値識別子 (デフォルトは0).:raises OperationError: OS/2 テーブルがフォントで利用できない場合.:raises ArgumentError: class_id が無効な場合または、subclass_id が指定されていますが無効です。"""font.set_family_classification(**font.FAMILY_CLASSIFICATION_SCRIPTS_CALLIGRAPHIC)# 代替案:font.set_family_classification(class_id=10, subclass_id=5)
set_family_name
"""関連するフォント名のレコードを更新するファミリー名を設定します。:param name: 名前:タイプ名: 新しいファミリー名。"""font.set_family_name(name="My Font New")
set_name
"""フォント名テーブル内の識別子によって名前を設定します。:param キー: 名前の ID またはキー (例: "family_name"):type キー: int または str:param 値: value:type 値: str" ""font.set_name(Font.NAME_FAMILY_NAME, "姓の名前が変更されました")
set_names
"""名前テーブル内の識別子によって名前を設定します。:param names: names:type names: dict"""font.set_names(names={Font.NAME_FAMILY_NAME: "ファミリー名が名前変更されました",Font.NAME_SUBFAMILY_NAME: "通常の名前変更", })
set_style_flag
"""スタイル フラグを設定します。:param キー: フラグ キー:type キー: str:param 値: value:type 値: bool"""font.set_style_flag(Font.STYLE_FLAG_BOLD, True)
set_style_flags
"""スタイル フラグを設定します。None に設定されたフラグは無視されます。:param ボールド: ボールド フラグの値。:type ボールド: bool または None:param italic: イタリック フラグの値。:type italic: bool または None:param下線: 下線フラグの値。:type 下線: bool または None:param アウトライン: アウトライン フラグの値。:type アウトライン: bool または None"""font.set_style_flags(normal=None,太字=なし、斜体=なし、アウトライン=なし、下線=なし)
set_style_flags_by_subfamily_name
"""サブファミリー名の値によってスタイル フラグを設定します。このメソッドが正しく機能するには、サブファミリーの値は「通常」、「斜体」、「太字」、または「太字斜体」である必要があります。"""font.set_style_flags_by_subfamily_name()
set_style_name
"""関連するフォント名のレコードを更新するスタイル名を設定します。:param name: name:type name: 新しいスタイル名。"""font.set_style_name(name="Bold Italic")
set_vertical_metrics
"""垂直メトリックを設定します。:param metrics: 設定できる垂直メトリックを表すキーワード引数: "units_per_em"、"y_max"、"y_min"、"ascent"、"descent"、"line_gap"、"typo_ascender" 、「typo_descender」、「typo_line_gap」、「cap_height」、「x_height」、「win_ascent」、 "win_descent""""font.set_vertical_metrics(units_per_em=2000, y_max=2102, y_min=-533, ascent=1800, descent=-400, line_gap=0, typo_ascender=1800, typo_descender=-400, typo_line_gap=0, cap_height=1400、x_height=1080、win_ascent=2160、win_descent=540)
subset
"""指定されたオプション (ユニコード、グリフ、またはテキスト) を使用してフォントをサブセットします。サブセッター オプションも渡すことができます。詳細はこちら:https://github.com/fonttools/fonttools/blob/main/Lib/fontTools /subset/__init__.py:param unicodes: unicodes:type unicodes: str または list:param glyphs: glyphs:typeグリフ: list:param text: text:type text: str:param options: サブセッター options:type options: dict"""font.subset(unicodes="", glyphs=[], text="", **オプション)
to_sliced_variable
"""変数フォントを、指定された座標で変数軸をスライスした部分フォントに変換します。軸の値が指定されていない場合、軸はそのまま残ります。軸の最小値と最大値が等しい場合、軸は固定されます。 .:param 座標: 座標辞書。各項目の値は、スライスの場合は tuple/list/dict ('min'、'default'、および 'max' キーを含む)、または float/int である必要があります。固定、例: {'wdth':100, 'wght':(100,600), 'ital':(30,65,70)} または {'wdth':100, 'wght':[100,600], 'ital' :[30,65,70]} または {'wdth':100, 'wght':{'min':100,'max':600}, 'ital':{'min':30,'default':65,'max':70}}:型座標: dict:param オプション: fontTools.varLib.instancer:type オプションのオプション:dictionary:raises TypeError: フォントが変数でない場合 font:raises ValueError: 座標が定義されていない場合(空): ValueError が発生します: 座標軸がすべて固定されている場合"""font.to_sliced_variable(coodys, **options)
to_static
"""変数フォントを、変数軸を指定された座標に固定する静的なフォントに変換します。軸の値が指定されていない場合、軸はデフォルト値に固定されます。座標が指定されていない場合、各軸はデフォルトに固定されます。 value.:param 座標: 座標、例: {'wght':500, 'ital':50}:type 座標: dict または None:param style_name: 既存のインスタンス スタイルname、例: 'Black':type style_name: str または None:param update_names: True の場合、名前レコードは最も近いインスタンスに基づいて更新されます。 update_names: bool:param update_style_flags: True の場合、スタイル フラグは最も近いものに基づいて更新されます。 instance:type update_style_flags: bool:param options: fontTools.varLib.instancer:type オプションのオプション:dictionary:raises TypeError: フォントがは変数ではありません font:raises ValueError: 座標軸がすべて固定されていない場合"""font.to_static(coodys=None, style_name=None, update_names=True, update_style_flags=True, **options)
# clone repositorygit clone https://github.com/fabiocaccamo/python-fontbro.git && cd python-fontbro# create virtualenv を作成し、itpython -m venv venv && をアクティブにします。 venv/bin/activate# upgrade pippython -m pip install --upgrade pip# install要件python -m pip install -r要件.txt -r要件-test.txt#インストールフォーマッタとリンターを実行するための事前コミット事前コミットインストール -- install-hooks# toxtox を使用してテストを実行する# または、unittestpython -m Unittest を使用してテストを実行する
MITライセンスに基づいてリリースされています。
Jérémie Hornus と Just Van Rossum に心より感謝いたします。
GitHub でこのプロジェクトにスターを付ける
GitHub でフォローしてください
? Twitterでフォローしてください
? Github でスポンサーになってください
python-benedict
- キーリスト/キーパスのサポート、I/O ショートカット (base64、csv、json、pickle、plist、クエリ文字列、toml、xml、yaml) および多くのユーティリティを備えた dict サブクラス。
python-fsutil
- 怠惰な開発者のためのファイルシステムユーティリティ。 ?♂️