FontFile
Hereda: Font < Resource < RefCounted < Object
Contiene los datos de origen de la fuente y la caché de glifos pre-renderizados, importados de una fuente dinámica o de mapa de bits.
Descripción
FontFile contains a set of glyphs to represent Unicode characters imported from a font file, as well as a cache of rasterized glyphs, and a set of fallback Fonts to use.
Use FontVariation to access specific OpenType variation of the font, create simulated bold / slanted version, and draw lines of text.
For more complex text processing, use FontVariation in conjunction with TextLine or TextParagraph.
Supported font formats:
Dynamic font importer: TrueType (.ttf), TrueType collection (.ttc), OpenType (.otf), OpenType collection (.otc), WOFF (.woff), WOFF2 (.woff2), Type 1 (.pfb, .pfm).
Bitmap font importer: AngelCode BMFont (.fnt, .font), text and binary (version 3) format variants.
Monospace image font importer: All supported image formats.
Note: A character is a symbol that represents an item (letter, digit etc.) in an abstract way.
Note: A glyph is a bitmap or a shape used to draw one or more characters in a context-dependent manner. Glyph indices are bound to the specific font data source.
Note: If none of the font data sources contain glyphs for a character used in a string, the character in question will be replaced with a box displaying its hexadecimal code.
var f = load("res://BarlowCondensed-Bold.ttf")
$Label.add_theme_font_override("font", f)
$Label.add_theme_font_size_override("font_size", 64)
var f = ResourceLoader.Load<FontFile>("res://BarlowCondensed-Bold.ttf");
GetNode("Label").AddThemeFontOverride("font", f);
GetNode("Label").AddThemeFontSizeOverride("font_size", 64);
Tutoriales
Propiedades
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
BitField[FontStyle] |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Métodos
void |
|
void |
clear_glyphs(cache_index: int, size: Vector2i) |
void |
clear_kerning_map(cache_index: int, size: int) |
void |
clear_size_cache(cache_index: int) |
void |
clear_textures(cache_index: int, size: Vector2i) |
get_cache_ascent(cache_index: int, size: int) const |
|
get_cache_count() const |
|
get_cache_descent(cache_index: int, size: int) const |
|
get_cache_scale(cache_index: int, size: int) const |
|
get_cache_underline_position(cache_index: int, size: int) const |
|
get_cache_underline_thickness(cache_index: int, size: int) const |
|
get_char_from_glyph_index(size: int, glyph_index: int) const |
|
get_embolden(cache_index: int) const |
|
get_extra_baseline_offset(cache_index: int) const |
|
get_extra_spacing(cache_index: int, spacing: SpacingType) const |
|
get_face_index(cache_index: int) const |
|
get_glyph_advance(cache_index: int, size: int, glyph: int) const |
|
get_glyph_index(size: int, char: int, variation_selector: int) const |
|
get_glyph_list(cache_index: int, size: Vector2i) const |
|
get_glyph_offset(cache_index: int, size: Vector2i, glyph: int) const |
|
get_glyph_size(cache_index: int, size: Vector2i, glyph: int) const |
|
get_glyph_texture_idx(cache_index: int, size: Vector2i, glyph: int) const |
|
get_glyph_uv_rect(cache_index: int, size: Vector2i, glyph: int) const |
|
get_kerning(cache_index: int, size: int, glyph_pair: Vector2i) const |
|
get_kerning_list(cache_index: int, size: int) const |
|
get_language_support_override(language: String) const |
|
get_language_support_overrides() const |
|
get_script_support_override(script: String) const |
|
get_script_support_overrides() const |
|
get_size_cache_list(cache_index: int) const |
|
get_texture_count(cache_index: int, size: Vector2i) const |
|
get_texture_image(cache_index: int, size: Vector2i, texture_index: int) const |
|
get_texture_offsets(cache_index: int, size: Vector2i, texture_index: int) const |
|
get_transform(cache_index: int) const |
|
get_variation_coordinates(cache_index: int) const |
|
load_bitmap_font(path: String) |
|
load_dynamic_font(path: String) |
|
void |
remove_cache(cache_index: int) |
void |
remove_glyph(cache_index: int, size: Vector2i, glyph: int) |
void |
remove_kerning(cache_index: int, size: int, glyph_pair: Vector2i) |
void |
remove_language_support_override(language: String) |
void |
remove_script_support_override(script: String) |
void |
remove_size_cache(cache_index: int, size: Vector2i) |
void |
remove_texture(cache_index: int, size: Vector2i, texture_index: int) |
void |
render_glyph(cache_index: int, size: Vector2i, index: int) |
void |
render_range(cache_index: int, size: Vector2i, start: int, end: int) |
void |
set_cache_ascent(cache_index: int, size: int, ascent: float) |
void |
set_cache_descent(cache_index: int, size: int, descent: float) |
void |
set_cache_scale(cache_index: int, size: int, scale: float) |
void |
set_cache_underline_position(cache_index: int, size: int, underline_position: float) |
void |
set_cache_underline_thickness(cache_index: int, size: int, underline_thickness: float) |
void |
set_embolden(cache_index: int, strength: float) |
void |
set_extra_baseline_offset(cache_index: int, baseline_offset: float) |
void |
set_extra_spacing(cache_index: int, spacing: SpacingType, value: int) |
void |
set_face_index(cache_index: int, face_index: int) |
void |
set_glyph_advance(cache_index: int, size: int, glyph: int, advance: Vector2) |
void |
set_glyph_offset(cache_index: int, size: Vector2i, glyph: int, offset: Vector2) |
void |
set_glyph_size(cache_index: int, size: Vector2i, glyph: int, gl_size: Vector2) |
void |
set_glyph_texture_idx(cache_index: int, size: Vector2i, glyph: int, texture_idx: int) |
void |
set_glyph_uv_rect(cache_index: int, size: Vector2i, glyph: int, uv_rect: Rect2) |
void |
set_kerning(cache_index: int, size: int, glyph_pair: Vector2i, kerning: Vector2) |
void |
set_language_support_override(language: String, supported: bool) |
void |
set_script_support_override(script: String, supported: bool) |
void |
set_texture_image(cache_index: int, size: Vector2i, texture_index: int, image: Image) |
void |
set_texture_offsets(cache_index: int, size: Vector2i, texture_index: int, offset: PackedInt32Array) |
void |
set_transform(cache_index: int, transform: Transform2D) |
void |
set_variation_coordinates(cache_index: int, variation_coordinates: Dictionary) |
Descripciones de Propiedades
bool allow_system_fallback = true 🔗
Si se establece en true, las fuentes del sistema se pueden utilizar automáticamente como alternativas.
FontAntialiasing antialiasing = 1 🔗
void set_antialiasing(value: FontAntialiasing)
FontAntialiasing get_antialiasing()
Modo de antialiasing de la fuente.
PackedByteArray data = PackedByteArray() 🔗
void set_data(value: PackedByteArray)
PackedByteArray get_data()
Contenido del archivo fuente de la fuente dinámica.
Note: The returned array is copied and any changes to it will not update the original property value. See PackedByteArray for more details.
bool disable_embedded_bitmaps = true 🔗
Si se establece en true, la carga de mapas de bits de fuentes incrustados se desactiva (las fuentes solo de mapa de bits y de color ignoran esta propiedad).
Tamaño de la fuente, usado solo para las fuentes de mapa de bits.
FixedSizeScaleMode fixed_size_scale_mode = 0 🔗
void set_fixed_size_scale_mode(value: FixedSizeScaleMode)
FixedSizeScaleMode get_fixed_size_scale_mode()
Modo de escalado, usado solo para las fuentes de mapa de bits con fixed_size mayor que cero.
Nombre de la familia de fuentes.
Cantidad de estiramiento de la fuente, comparado con un ancho normal. Un valor porcentual entre 50% y 200%.
BitField[FontStyle] font_style = 0 🔗
Banderas de estilo de fuente.
Peso (grosor) de la fuente. Un valor en el rango 100...999. El peso normal de la fuente es 400 y el peso de la fuente en negrita es 700.
bool force_autohinter = false 🔗
Si se establece en true, el hinting automático es compatible y preferido sobre el hinting incorporado de la fuente. Se utiliza solo en fuentes dinámicas (las fuentes MSDF no admiten hinting).
bool generate_mipmaps = false 🔗
Si se establece en true, se generan mipmaps para las texturas de la fuente.
Modo de hinting de la fuente. Se utiliza solo en fuentes dinámicas.
bool keep_rounding_remainders = true 🔗
Si se establece en true, al alinear los glifos a los límites de los píxeles, los restos de redondeo se acumulan para asegurar una distribución de glifos más uniforme. Este ajuste no tiene efecto si el posicionamiento subpíxel está habilitado.
bool modulate_color_glyphs = false 🔗
If set to true, color modulation is applied when drawing colored glyphs, otherwise it's applied to the monochrome glyphs only.
The width of the range around the shape between the minimum and maximum representable signed distance. If using font outlines, msdf_pixel_range must be set to at least twice the size of the largest font outline. The default msdf_pixel_range value of 16 allows outline sizes up to 8 to look correct.
Source font size used to generate MSDF textures. Higher values allow for more precision, but are slower to render and require more memory. Only increase this value if you notice a visible lack of precision in glyph rendering.
bool multichannel_signed_distance_field = false 🔗
void set_multichannel_signed_distance_field(value: bool)
bool is_multichannel_signed_distance_field()
If set to true, glyphs of all sizes are rendered using single multichannel signed distance field (MSDF) generated from the dynamic font vector data. Since this approach does not rely on rasterizing the font every time its size changes, this allows for resizing the font in real-time without any performance penalty. Text will also not look grainy for Controls that are scaled down (or for Label3Ds viewed from a long distance). As a downside, font hinting is not available with MSDF. The lack of font hinting may result in less crisp and less readable fonts at small sizes.
Note: If using font outlines, msdf_pixel_range must be set to at least twice the size of the largest font outline.
Note: MSDF font rendering does not render glyphs with overlapping shapes correctly. Overlapping shapes are not valid per the OpenType standard, but are still commonly found in many font files, especially those converted by Google Fonts. To avoid issues with overlapping glyphs, consider downloading the font file directly from the type foundry instead of relying on Google Fonts.
Dictionary opentype_feature_overrides = {} 🔗
void set_opentype_feature_overrides(value: Dictionary)
Dictionary get_opentype_feature_overrides()
Sobrescritura del conjunto de características de fuentes OpenType.
If set to a positive value, overrides the oversampling factor of the viewport this font is used in. See Viewport.oversampling. This value doesn't override the oversampling parameter of draw_* methods.
Nombre del estilo de fuente.
SubpixelPositioning subpixel_positioning = 1 🔗
void set_subpixel_positioning(value: SubpixelPositioning)
SubpixelPositioning get_subpixel_positioning()
Font glyph subpixel positioning mode. Subpixel positioning provides shaper text and better kerning for smaller font sizes, at the cost of higher memory usage and lower font rasterization speed. Use TextServer.SUBPIXEL_POSITIONING_AUTO to automatically enable it based on the font size.
Descripciones de Métodos
void clear_cache() 🔗
Elimina todas las entradas de caché de fuentes.
void clear_glyphs(cache_index: int, size: Vector2i) 🔗
Elimina toda la información de glifos renderizados de la entrada de caché.
Nota: Esta función no eliminará las texturas asociadas a los glifos; utiliza remove_texture() para eliminarlas manualmente.
void clear_kerning_map(cache_index: int, size: int) 🔗
Elimina todas las modificaciones de kerning.
void clear_size_cache(cache_index: int) 🔗
Elimina todos los tamaños de fuente de la entrada de caché.
void clear_textures(cache_index: int, size: Vector2i) 🔗
Elimina todas las texturas de la entrada de caché de fuentes.
Nota: Esta función no eliminará los glifos asociados a la textura; utiliza el método remove_glyph para eliminarlos manualmente.
float get_cache_ascent(cache_index: int, size: int) const 🔗
Devuelve el ascenso de la fuente (número de píxeles por encima de la línea de base).
Devuelve el número de entradas de caché de fuentes.
float get_cache_descent(cache_index: int, size: int) const 🔗
Devuelve el descenso de la fuente (número de píxeles por debajo de la línea de base).
float get_cache_scale(cache_index: int, size: int) const 🔗
Devuelve el factor de escala de la fuente de mapa de bits de color.
float get_cache_underline_position(cache_index: int, size: int) const 🔗
Devuelve el desplazamiento de píxeles del subrayado debajo de la línea base.
float get_cache_underline_thickness(cache_index: int, size: int) const 🔗
Devuelve el grosor del subrayado en píxeles.
int get_char_from_glyph_index(size: int, glyph_index: int) const 🔗
Devuelve el código de carácter asociado con glyph_index, o 0 si glyph_index no es válido. Véase get_glyph_index().
float get_embolden(cache_index: int) const 🔗
Returns embolden strength, if is not equal to zero, emboldens the font outlines. Negative values reduce the outline thickness.
float get_extra_baseline_offset(cache_index: int) const 🔗
Devuelve el desplazamiento adicional de la línea base (como una fracción de la altura de la fuente).
int get_extra_spacing(cache_index: int, spacing: SpacingType) const 🔗
Devuelve el espaciado para spacing en píxeles (no relativo al tamaño de fuente).
int get_face_index(cache_index: int) const 🔗
Devuelve un índice de cara activo en la colección TrueType/OpenType.
Vector2 get_glyph_advance(cache_index: int, size: int, glyph: int) const 🔗
Devuelve el avance del glifo (desplazamiento del siguiente glifo).
Nota: El avance de los contornos de los glifos es el mismo que el avance del glifo base y no se guarda.
int get_glyph_index(size: int, char: int, variation_selector: int) const 🔗
Devuelve el índice del glifo de un char, opcionalmente modificado por el variation_selector.
PackedInt32Array get_glyph_list(cache_index: int, size: Vector2i) const 🔗
Devuelve la lista de glifos representados en la entrada de caché.
Vector2 get_glyph_offset(cache_index: int, size: Vector2i, glyph: int) const 🔗
Devuelve el desplazamiento del glifo desde la línea base.
Vector2 get_glyph_size(cache_index: int, size: Vector2i, glyph: int) const 🔗
Devuelve el tamaño del glifo.
int get_glyph_texture_idx(cache_index: int, size: Vector2i, glyph: int) const 🔗
Devuelve el índice de la textura de caché que contiene el glifo.
Rect2 get_glyph_uv_rect(cache_index: int, size: Vector2i, glyph: int) const 🔗
Devuelve el rectángulo en la textura de caché que contiene el glifo.
Vector2 get_kerning(cache_index: int, size: int, glyph_pair: Vector2i) const 🔗
Devuelve el kerning para el par de glifos.
Array[Vector2i] get_kerning_list(cache_index: int, size: int) const 🔗
Devuelve una lista de anulaciones de kerning.
bool get_language_support_override(language: String) const 🔗
Devuelve true si la sobrescritura de soporte está habilitada para el language.
PackedStringArray get_language_support_overrides() const 🔗
Devuelve una lista de anulaciones de soporte de idiomas.
bool get_script_support_override(script: String) const 🔗
Devuelve true si la sobrescritura de soporte está habilitada para el script.
PackedStringArray get_script_support_overrides() const 🔗
Devuelve una lista de anulaciones de compatibilidad de scripts.
Array[Vector2i] get_size_cache_list(cache_index: int) const 🔗
Devuelve una lista de los tamaños de fuente en la caché. Cada tamaño es Vector2i con el tamaño de la fuente y el tamaño del contorno.
int get_texture_count(cache_index: int, size: Vector2i) const 🔗
Devuelve el número de texturas utilizadas por la entrada de caché de fuentes.
Image get_texture_image(cache_index: int, size: Vector2i, texture_index: int) const 🔗
Devuelve una copia de la imagen de textura de caché de fuente.
PackedInt32Array get_texture_offsets(cache_index: int, size: Vector2i, texture_index: int) const 🔗
Devuelve una copia del array que contiene datos de empaquetado de glifos.
Transform2D get_transform(cache_index: int) const 🔗
Devuelve la transformación 2D, aplicada a los contornos de la fuente, que puede utilizarse para inclinar, voltear y rotar los glifos.
Dictionary get_variation_coordinates(cache_index: int) const 🔗
Devuelve las coordenadas de variación para la entrada de caché de fuente especificada. Véase Font.get_supported_variation_list() para más información.
Error load_bitmap_font(path: String) 🔗
Carga una fuente de mapa de bits AngelCode BMFont (.fnt, .font) desde el archivo path.
Advertencia: Este método solo debe usarse en el editor o en los casos en que necesites cargar fuentes externas en tiempo de ejecución, como las fuentes ubicadas en el directorio user://.
Error load_dynamic_font(path: String) 🔗
Carga una fuente dinámica TrueType (.ttf), OpenType (.otf), WOFF (.woff), WOFF2 (.woff2) o Type 1 (.pfb, .pfm) desde el archivo path.
Advertencia: Este método solo debe usarse en el editor o en los casos en que necesites cargar fuentes externas en tiempo de ejecución, como las fuentes ubicadas en el directorio user://.
void remove_cache(cache_index: int) 🔗
Elimina la entrada de caché de fuente especificada.
void remove_glyph(cache_index: int, size: Vector2i, glyph: int) 🔗
Elimina la información del glifo renderizado especificado de la entrada de caché.
Nota: Esta función no eliminará las texturas asociadas con los glifos, usa remove_texture() para eliminarlos manualmente.
void remove_kerning(cache_index: int, size: int, glyph_pair: Vector2i) 🔗
Elimina la sobrescritura de kerning para el par de glifos.
void remove_language_support_override(language: String) 🔗
Elimina la sobrescritura de soporte de idioma.
void remove_script_support_override(script: String) 🔗
Elimina la sobrescritura de soporte de script.
void remove_size_cache(cache_index: int, size: Vector2i) 🔗
Elimina el tamaño de fuente especificado de la entrada de caché.
void remove_texture(cache_index: int, size: Vector2i, texture_index: int) 🔗
Elimina la textura especificada de la entrada de caché.
Nota: Esta función no eliminará los glifos asociados con la textura. Elimínalos manualmente usando remove_glyph().
void render_glyph(cache_index: int, size: Vector2i, index: int) 🔗
Renderiza el glifo especificado en la textura de caché de la fuente.
void render_range(cache_index: int, size: Vector2i, start: int, end: int) 🔗
Representa el rango de caracteres en la textura de caché de fuentes.
void set_cache_ascent(cache_index: int, size: int, ascent: float) 🔗
Establece el ascenso de la fuente (número de píxeles por encima de la línea base).
void set_cache_descent(cache_index: int, size: int, descent: float) 🔗
Establece el descenso de la fuente (número de píxeles por debajo de la línea de base).
void set_cache_scale(cache_index: int, size: int, scale: float) 🔗
Establece el factor de escala de la fuente de mapa de bits de color.
void set_cache_underline_position(cache_index: int, size: int, underline_position: float) 🔗
Establece el desplazamiento en píxeles del subrayado por debajo de la línea de base.
void set_cache_underline_thickness(cache_index: int, size: int, underline_thickness: float) 🔗
Establece el grosor del subrayado en píxeles.
void set_embolden(cache_index: int, strength: float) 🔗
Establece la fuerza del realce. Si no es igual a cero, realza los contornos de la fuente. Los valores negativos reducen el grosor del contorno.
void set_extra_baseline_offset(cache_index: int, baseline_offset: float) 🔗
Establece el desplazamiento extra de la línea de base (como una fracción de la altura de la fuente).
void set_extra_spacing(cache_index: int, spacing: SpacingType, value: int) 🔗
Establece el espaciado para spacing a value en píxeles (no en relación con el tamaño de la fuente).
void set_face_index(cache_index: int, face_index: int) 🔗
Establece un índice de cara activo en la colección TrueType/OpenType.
void set_glyph_advance(cache_index: int, size: int, glyph: int, advance: Vector2) 🔗
Establece el avance del glifo (desplazamiento del siguiente glifo).
Nota: El avance de los contornos de los glifos es el mismo que el avance del glifo base y no se guarda.
void set_glyph_offset(cache_index: int, size: Vector2i, glyph: int, offset: Vector2) 🔗
Establece el desplazamiento del glifo desde la línea de base.
void set_glyph_size(cache_index: int, size: Vector2i, glyph: int, gl_size: Vector2) 🔗
Establece el tamaño del glifo.
void set_glyph_texture_idx(cache_index: int, size: Vector2i, glyph: int, texture_idx: int) 🔗
Establece el índice de la textura de caché que contiene el glifo.
void set_glyph_uv_rect(cache_index: int, size: Vector2i, glyph: int, uv_rect: Rect2) 🔗
Establece el rectángulo en la textura de caché que contiene el glifo.
void set_kerning(cache_index: int, size: int, glyph_pair: Vector2i, kerning: Vector2) 🔗
Establece el kerning para el par de glifos.
void set_language_support_override(language: String, supported: bool) 🔗
Añade una sobrescritura para Font.is_language_supported().
void set_script_support_override(script: String, supported: bool) 🔗
Añade una sobrescritura para Font.is_script_supported().
void set_texture_image(cache_index: int, size: Vector2i, texture_index: int, image: Image) 🔗
Establece la imagen de textura de caché de fuente.
void set_texture_offsets(cache_index: int, size: Vector2i, texture_index: int, offset: PackedInt32Array) 🔗
Establece un array que contiene datos de empaquetado de glifos.
void set_transform(cache_index: int, transform: Transform2D) 🔗
Establece la transformación 2D, aplicada a los contornos de la fuente, que puede utilizarse para inclinar, voltear y rotar los glifos.
void set_variation_coordinates(cache_index: int, variation_coordinates: Dictionary) 🔗
Establece las coordenadas de variación para la entrada de caché de fuente especificada. Véase Font.get_supported_variation_list() para más información.