Files
godot-docs-l10n/classes/zh_Hans/class_resourceimporterimagefont.rst
Rémi Verschelde c3f2364c10 Sync classref with 4.6 branch
Lots of translations invalidated (fuzzied) as we just synced Weblate.
2025-12-19 16:39:51 +01:00

218 lines
12 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:github_url: hide
.. _class_ResourceImporterImageFont:
ResourceImporterImageFont
=========================
**继承:** :ref:`ResourceImporter<class_ResourceImporter>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
导入位图字体,所有字形使用的都是相同的宽高。
.. rst-class:: classref-introduction-group
描述
----
这种基于图像的工作流程比 :ref:`ResourceImporterBMFont<class_ResourceImporterBMFont>` 更易于使用,但它要求所有字形具有相同的宽度和高度,字形前进和绘制偏移可以自定义。这使得 **ResourceImporterImageFont** 最适合固定宽度的字体。
另见 :ref:`ResourceImporterDynamicFont<class_ResourceImporterDynamicFont>`\ 。
.. rst-class:: classref-introduction-group
教程
----
- `位图字体——使用字体 <../tutorials/ui/gui_using_fonts.html#bitmap-fonts>`__
.. rst-class:: classref-reftable-group
属性
----
.. table::
:widths: auto
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`int<class_int>` | :ref:`ascent<class_ResourceImporterImageFont_property_ascent>` | ``0`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`Rect2i<class_Rect2i>` | :ref:`character_margin<class_ResourceImporterImageFont_property_character_margin>` | ``Rect2i(0, 0, 0, 0)`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`character_ranges<class_ResourceImporterImageFont_property_character_ranges>` | ``PackedStringArray()`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`int<class_int>` | :ref:`columns<class_ResourceImporterImageFont_property_columns>` | ``1`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`bool<class_bool>` | :ref:`compress<class_ResourceImporterImageFont_property_compress>` | ``true`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`int<class_int>` | :ref:`descent<class_ResourceImporterImageFont_property_descent>` | ``0`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`Array<class_Array>` | :ref:`fallbacks<class_ResourceImporterImageFont_property_fallbacks>` | ``[]`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`Rect2i<class_Rect2i>` | :ref:`image_margin<class_ResourceImporterImageFont_property_image_margin>` | ``Rect2i(0, 0, 0, 0)`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`kerning_pairs<class_ResourceImporterImageFont_property_kerning_pairs>` | ``PackedStringArray()`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`int<class_int>` | :ref:`rows<class_ResourceImporterImageFont_property_rows>` | ``1`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
| :ref:`int<class_int>` | :ref:`scaling_mode<class_ResourceImporterImageFont_property_scaling_mode>` | ``2`` |
+---------------------------------------------------+------------------------------------------------------------------------------------+-------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
属性说明
--------
.. _class_ResourceImporterImageFont_property_ascent:
.. rst-class:: classref-property
:ref:`int<class_int>` **ascent** = ``0`` :ref:`🔗<class_ResourceImporterImageFont_property_ascent>`
字体的上高(基线上方的像素数)。如果设为 ``0`` 则使用字符高度的一半。
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_character_margin:
.. rst-class:: classref-property
:ref:`Rect2i<class_Rect2i>` **character_margin** = ``Rect2i(0, 0, 0, 0)`` :ref:`🔗<class_ResourceImporterImageFont_property_character_margin>`
在每个导入的字形周围应用边距。如果你的字体图像包含参考线(以字形之间的线的形式)或者字符之间的间距看起来不正确,请尝试调整 :ref:`character_margin<class_ResourceImporterImageFont_property_character_margin>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_character_ranges:
.. rst-class:: classref-property
:ref:`PackedStringArray<class_PackedStringArray>` **character_ranges** = ``PackedStringArray()`` :ref:`🔗<class_ResourceImporterImageFont_property_character_ranges>`
The character ranges to import from the font image. This is an array that maps each position on the image (in tile coordinates, not pixels). The font atlas is traversed from left to right and top to bottom. Characters can be specified with decimal numbers (126), hexadecimal numbers (``0x007e`` or ``U+007e``), or between single quotes (``'~'``). Ranges can be specified with a hyphen between characters.
For example, ``0-127`` represents the full ASCII range. It can also be written as ``0x0000-0x007f`` (or ``U+0000-U+007f``). As another example, ``' '-'~'`` is equivalent to ``32-126`` and represents the range of printable (visible) ASCII characters.
For any range, the character advance and offset can be customized by appending three space-separated integer values (additional advance, x offset, y offset) to the end. For example ``'a'-'b' 4 5 2`` sets the advance to ``char_width + 4`` and offset to ``Vector2(5, 2)`` for both `a` and `b` characters.
\ **Note:** The overall number of characters must not exceed the number of :ref:`columns<class_ResourceImporterImageFont_property_columns>` multiplied by :ref:`rows<class_ResourceImporterImageFont_property_rows>`. Otherwise, the font will fail to import.
**Note:** The returned array is *copied* and any changes to it will not update the original property value. See :ref:`PackedStringArray<class_PackedStringArray>` for more details.
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_columns:
.. rst-class:: classref-property
:ref:`int<class_int>` **columns** = ``1`` :ref:`🔗<class_ResourceImporterImageFont_property_columns>`
字体图像中的列数。另见 :ref:`rows<class_ResourceImporterImageFont_property_rows>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_compress:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **compress** = ``true`` :ref:`🔗<class_ResourceImporterImageFont_property_compress>`
如果为 ``true``\ ,则会对得到的字体使用无损压缩。
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_descent:
.. rst-class:: classref-property
:ref:`int<class_int>` **descent** = ``0`` :ref:`🔗<class_ResourceImporterImageFont_property_descent>`
字体的下深(基线下方的像素数)。如果设为 ``0`` 则使用字符高度的一半。
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_fallbacks:
.. rst-class:: classref-property
:ref:`Array<class_Array>` **fallbacks** = ``[]`` :ref:`🔗<class_ResourceImporterImageFont_property_fallbacks>`
回退字体列表,在这个位图字体中未找到某个字形时使用。优先尝试靠前的字体。
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_image_margin:
.. rst-class:: classref-property
:ref:`Rect2i<class_Rect2i>` **image_margin** = ``Rect2i(0, 0, 0, 0)`` :ref:`🔗<class_ResourceImporterImageFont_property_image_margin>`
整个图像两侧的裁减边距。这可被用于裁减该图像包含属性信息或类似信息的部分。
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_kerning_pairs:
.. rst-class:: classref-property
:ref:`PackedStringArray<class_PackedStringArray>` **kerning_pairs** = ``PackedStringArray()`` :ref:`🔗<class_ResourceImporterImageFont_property_kerning_pairs>`
字体中的字偶列表。字偶的作用是调整特定的两个字符的间距。
每个字符串都是由空格分隔的三个值“from”字符串、“to”字符串、整数偏移量。两个字符串中的字符两两组合成字偶例如 ``ab cd -3`` 会创建字偶 ``ac``\ 、\ ``ad``\ 、\ ``bc``\ 、\ ``bd``\ ,这些字偶的偏移量都是 ``-3``\ 。可以使用转义序列 ``\uXXXX`` 添加 Unicode 字符。
**Note:** The returned array is *copied* and any changes to it will not update the original property value. See :ref:`PackedStringArray<class_PackedStringArray>` for more details.
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_rows:
.. rst-class:: classref-property
:ref:`int<class_int>` **rows** = ``1`` :ref:`🔗<class_ResourceImporterImageFont_property_rows>`
字体图像中的行数。另见 :ref:`columns<class_ResourceImporterImageFont_property_columns>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_ResourceImporterImageFont_property_scaling_mode:
.. rst-class:: classref-property
:ref:`int<class_int>` **scaling_mode** = ``2`` :ref:`🔗<class_ResourceImporterImageFont_property_scaling_mode>`
字体缩放模式。
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
.. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)`
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)`
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)`
.. |void| replace:: :abbr:`void (无返回值。)`