Files
test/source/blender/blenkernel/BKE_vfontdata.hh
Harley Acheson 276eee8f53 BLF: Correct the Showing of VFont Not Found Character
When VFont objects use a custom (non-default) font and reference a
character that is not contained in that font, our intention is to show
placeholder curves that represents "not found". Instead we are
currently showing the ".notdef" glyph if there is one defined inside
the font or blank space if not. This PR fixes that by altering
BLF_character_to_curves so that it returns a boolean success instead of
character advance. This way we can properly distinguish "not found"
from the return of other empty, non-advancing characters.

Pull Request: https://projects.blender.org/blender/blender/pulls/143484
2025-07-30 21:25:18 +02:00

75 lines
2.0 KiB
C++

/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/** \file
* \ingroup bke
* \brief A structure to represent vector fonts,
* and to load them from PostScript fonts.
*/
#include "DNA_listBase.h"
struct GHash;
struct PackedFile;
struct VFont;
/**
* Font metric values explained:
*
* Baseline: Line where the text "rests", used as the origin vertical position for the glyphs.
* Em height: Space most glyphs should fit within.
* Ascent: the recommended distance above the baseline to fit most characters.
* Descent: the recommended distance below the baseline to fit most characters.
*
* We obtain ascent and descent from the font itself (`FT_Face->ascender / face->height`).
* And in some cases it is even the same value as `FT_Face->bbox.yMax / yMin`.
* (font top and bottom respectively).
*
* The `em_ratio` here is relative to `FT_Face->bbox`.
*/
struct VFontData_Metrics {
float scale;
/* Calculated from the font. */
float em_ratio;
float ascend_ratio;
};
struct VFontData {
/**
* A hash that maps `uint -> VChar` (code-points to character outlines).
*
* \note values may be null when the character does not exist in the font.
* This is done to differentiate characters known not to exist from
* characters that have not yet been loaded.
*/
GHash *characters;
char name[128];
VFontData_Metrics metrics;
};
struct VChar {
ListBase nurbsbase;
float width;
};
/**
* Default metrics to use when the font wont load.
*/
void BKE_vfontdata_metrics_get_defaults(VFontData_Metrics *metrics);
/**
* Construct a new #VFontData structure from free-type font data in `pf`.
*
* \param pf: The font data.
* \retval A new #VFontData structure, or NULL if unable to load.
*/
VFontData *BKE_vfontdata_from_freetypefont(PackedFile *pf);
VFontData *BKE_vfontdata_copy(const VFontData *vfont_src, int flag);
VChar *BKE_vfontdata_char_from_freetypefont(VFont *vfont, unsigned int character);
VChar *BKE_vfontdata_char_copy(const VChar *vchar_src);