Graphviz 12.0.1~dev.20240715.2254
Loading...
Searching...
No Matches
textspan_lut.c File Reference
#include <assert.h>
#include <cgraph/agxbuf.h>
#include <cgraph/gv_ctype.h>
#include <common/render.h>
#include <common/textspan_lut.h>
#include <common/types.h>
#include <common/utils.h>
#include <ctype.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for textspan_lut.c:

Go to the source code of this file.

Data Structures

struct  FontFamilyMetrics
 

Functions

static bool font_name_equal_permissive (const char *a, const char *b)
 
static bool font_in_list_permissive (const char *value, const char **list)
 
static const struct FontFamilyMetricsget_metrics_for_font_family (const char *font_name)
 
static const short * get_metrics_for_font_variant (const struct FontFamilyMetrics *family_metrics, bool bold, bool italic)
 
static unsigned short estimate_character_width_canonical (const short variant_metrics[128], unsigned character)
 
double estimate_text_width_1pt (const char *font_name, const char *text, bool bold, bool italic)
 

Variables

static const struct FontFamilyMetrics all_font_metrics []
 
static const size_t all_font_metrics_len
 

Function Documentation

◆ estimate_character_width_canonical()

static unsigned short estimate_character_width_canonical ( const short  variant_metrics[128],
unsigned  character 
)
static
Returns
the width of the character in (units_per_em * 1) points.

Definition at line 801 of file textspan_lut.c.

References agwarningf().

Referenced by estimate_text_width_1pt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ estimate_text_width_1pt()

double estimate_text_width_1pt ( const char *  font_name,
const char *  text,
bool  bold,
bool  italic 
)
Parameters
texta single line of ASCII text which should contain no control characters.
Returns
The estimated width of text in 1 point. A value is always returned, falling back to Times-Roman metrics if there is no hard-coded lookup table for the given font_name.

Definition at line 830 of file textspan_lut.c.

References estimate_character_width_canonical(), FontFamilyMetrics::font_name, get_metrics_for_font_family(), get_metrics_for_font_variant(), and FontFamilyMetrics::units_per_em.

Referenced by estimate_textspan_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ font_in_list_permissive()

static bool font_in_list_permissive ( const char *  value,
const char **  list 
)
static

Checks whether a font name is in a list of font names, ignoring case and special characters.

E.g. "Times-Roman" and "TimesNewRoman" are both in {"times", "timesroman", "timesnewroman", NULL}, but "Arial" is not.

Definition at line 751 of file textspan_lut.c.

References font_name_equal_permissive(), and NULL.

Referenced by get_metrics_for_font_family().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ font_name_equal_permissive()

static bool font_name_equal_permissive ( const char *  a,
const char *  b 
)
static

Compares two font names for equality, ignoring case and all characters except ASCII letters

E.g. "timesroman", "Times-Roman", "times ROMAN", "times_roman" and "tim8esroman" are all considered equal to each other, but not equal to "Times New Roman".

Definition at line 711 of file textspan_lut.c.

References gv_isalpha().

Referenced by font_in_list_permissive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_metrics_for_font_family()

static const struct FontFamilyMetrics * get_metrics_for_font_family ( const char *  font_name)
static

Definition at line 765 of file textspan_lut.c.

References agwarningf(), agxbfree(), agxbprint(), agxbuse(), all_font_metrics, all_font_metrics_len, emit_once(), font_in_list_permissive(), FontFamilyMetrics::font_name, and get_metrics_for_font_family().

Referenced by estimate_text_width_1pt(), and get_metrics_for_font_family().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_metrics_for_font_variant()

static const short * get_metrics_for_font_variant ( const struct FontFamilyMetrics family_metrics,
bool  bold,
bool  italic 
)
static

Definition at line 785 of file textspan_lut.c.

References FontFamilyMetrics::widths_bold, FontFamilyMetrics::widths_bold_italic, FontFamilyMetrics::widths_italic, and FontFamilyMetrics::widths_regular.

Referenced by estimate_text_width_1pt().

Here is the caller graph for this function:

Variable Documentation

◆ all_font_metrics

const struct FontFamilyMetrics all_font_metrics[]
static

Definition at line 34 of file textspan_lut.c.

Referenced by get_metrics_for_font_family().

◆ all_font_metrics_len

const size_t all_font_metrics_len
static
Initial value:
=
sizeof(all_font_metrics) / sizeof(all_font_metrics[0])
static const struct FontFamilyMetrics all_font_metrics[]

Definition at line 702 of file textspan_lut.c.

Referenced by get_metrics_for_font_family().