2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2008 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2009-01-29 06:19:27 +01:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup blf
|
2011-02-27 21:42:42 +01:00
|
|
|
*/
|
|
|
|
|
2012-02-17 19:59:41 +01:00
|
|
|
#pragma once
|
2009-01-29 06:19:27 +01:00
|
|
|
|
2024-02-19 03:34:36 +01:00
|
|
|
#include <mutex>
|
|
|
|
|
2024-02-21 18:17:21 +01:00
|
|
|
#include "BLI_map.hh"
|
2024-02-19 03:34:36 +01:00
|
|
|
#include "BLI_vector.hh"
|
|
|
|
|
2018-06-22 02:35:37 +02:00
|
|
|
#include "GPU_texture.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "GPU_vertex_buffer.h"
|
2018-03-30 19:16:14 +02:00
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
struct ColorManagedDisplay;
|
|
|
|
struct FontBLF;
|
|
|
|
struct GPUBatch;
|
|
|
|
struct GPUVertBuf;
|
|
|
|
struct GPUVertBufRaw;
|
|
|
|
|
2022-07-07 21:59:16 +02:00
|
|
|
#include FT_MULTIPLE_MASTERS_H /* Variable font support. */
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Maximum variation axes per font. */
|
|
|
|
#define BLF_VARIATIONS_MAX 16
|
2022-07-07 21:59:16 +02:00
|
|
|
|
|
|
|
#define MAKE_DVAR_TAG(a, b, c, d) \
|
2024-02-13 21:34:32 +01:00
|
|
|
((uint32_t(a) << 24u) | (uint32_t(b) << 16u) | (uint32_t(c) << 8u) | (uint32_t(d)))
|
2022-07-07 21:59:16 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
#define BLF_VARIATION_AXIS_WEIGHT MAKE_DVAR_TAG('w', 'g', 'h', 't') /* 'wght' weight axis. */
|
|
|
|
#define BLF_VARIATION_AXIS_SLANT MAKE_DVAR_TAG('s', 'l', 'n', 't') /* 'slnt' slant axis. */
|
|
|
|
#define BLF_VARIATION_AXIS_WIDTH MAKE_DVAR_TAG('w', 'd', 't', 'h') /* 'wdth' width axis. */
|
|
|
|
#define BLF_VARIATION_AXIS_SPACING MAKE_DVAR_TAG('s', 'p', 'a', 'c') /* 'spac' spacing axis. */
|
|
|
|
#define BLF_VARIATION_AXIS_OPTSIZE MAKE_DVAR_TAG('o', 'p', 's', 'z') /* 'opsz' optical size. */
|
2022-07-07 21:59:16 +02:00
|
|
|
|
2022-04-05 12:10:55 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Sub-Pixel Offset & Utilities
|
|
|
|
*
|
|
|
|
* Free-type uses fixed point precision for sub-pixel offsets.
|
|
|
|
* Utility functions here avoid exposing the details in the BLF API.
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is an internal type that represents sub-pixel positioning,
|
|
|
|
* users of this type are to use `ft_pix_*` functions to keep scaling/rounding in one place.
|
|
|
|
*/
|
|
|
|
typedef int32_t ft_pix;
|
|
|
|
|
|
|
|
/* Macros copied from `include/freetype/internal/ftobjs.h`. */
|
|
|
|
|
|
|
|
#define FT_PIX_FLOOR(x) ((x) & ~63)
|
|
|
|
#define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32)
|
|
|
|
#define FT_PIX_CEIL(x) ((x) + 63)
|
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
inline int ft_pix_to_int(ft_pix v)
|
2022-04-05 12:10:55 +02:00
|
|
|
{
|
2024-02-13 21:34:32 +01:00
|
|
|
return int(v >> 6);
|
2022-04-05 12:10:55 +02:00
|
|
|
}
|
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
inline int ft_pix_to_int_floor(ft_pix v)
|
2022-04-05 12:10:55 +02:00
|
|
|
{
|
2024-02-13 21:34:32 +01:00
|
|
|
return int(v >> 6); /* No need for explicit floor as the bits are removed when shifting. */
|
2022-04-05 12:10:55 +02:00
|
|
|
}
|
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
inline int ft_pix_to_int_ceil(ft_pix v)
|
2022-04-05 12:10:55 +02:00
|
|
|
{
|
2024-02-13 21:34:32 +01:00
|
|
|
return int(FT_PIX_CEIL(v) >> 6);
|
2022-04-05 12:10:55 +02:00
|
|
|
}
|
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
inline ft_pix ft_pix_from_int(int v)
|
2022-04-05 12:10:55 +02:00
|
|
|
{
|
|
|
|
return v * 64;
|
|
|
|
}
|
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
inline ft_pix ft_pix_from_float(float v)
|
2022-04-05 12:10:55 +02:00
|
|
|
{
|
|
|
|
return lroundf(v * 64.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
2018-03-31 13:09:03 +02:00
|
|
|
#define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */
|
2018-03-30 19:16:14 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Number of characters in #KerningCacheBLF.table. */
|
2021-08-13 23:31:10 +02:00
|
|
|
#define KERNING_CACHE_TABLE_SIZE 128
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** A value in the kerning cache that indicates it is not yet set. */
|
2021-08-21 02:48:42 +02:00
|
|
|
#define KERNING_ENTRY_UNSET INT_MAX
|
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
struct BatchBLF {
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Can only batch glyph from the same font. */
|
2024-02-13 21:34:32 +01:00
|
|
|
FontBLF *font;
|
|
|
|
GPUBatch *batch;
|
|
|
|
GPUVertBuf *verts;
|
|
|
|
GPUVertBufRaw pos_step, col_step, offset_step, glyph_size_step, glyph_comp_len_step,
|
2023-11-30 22:17:30 +01:00
|
|
|
glyph_mode_step;
|
2023-12-01 02:07:57 +01:00
|
|
|
unsigned int pos_loc, col_loc, offset_loc, glyph_size_loc, glyph_comp_len_loc, glyph_mode_loc;
|
2018-03-31 13:09:03 +02:00
|
|
|
unsigned int glyph_len;
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Copy of `font->pos`. */
|
|
|
|
int ofs[2];
|
|
|
|
/* Previous call `modelmatrix`. */
|
|
|
|
float mat[4][4];
|
2018-03-30 22:50:17 +02:00
|
|
|
bool enabled, active, simple_shader;
|
2024-02-13 21:34:32 +01:00
|
|
|
GlyphCacheBLF *glyph_cache;
|
|
|
|
};
|
2018-03-30 19:16:14 +02:00
|
|
|
|
|
|
|
extern BatchBLF g_batch;
|
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
struct KerningCacheBLF {
|
2021-08-16 06:13:53 +02:00
|
|
|
/**
|
|
|
|
* Cache a ascii glyph pairs. Only store the x offset we are interested in,
|
|
|
|
* instead of the full #FT_Vector since it's not used for drawing at the moment.
|
|
|
|
*/
|
|
|
|
int ascii_table[KERNING_CACHE_TABLE_SIZE][KERNING_CACHE_TABLE_SIZE];
|
2024-02-13 21:34:32 +01:00
|
|
|
};
|
2018-03-31 15:24:10 +02:00
|
|
|
|
2024-02-21 18:17:21 +01:00
|
|
|
struct GlyphCacheKey {
|
|
|
|
uint charcode;
|
|
|
|
uint8_t subpixel;
|
|
|
|
friend bool operator==(const GlyphCacheKey &a, const GlyphCacheKey &b)
|
|
|
|
{
|
|
|
|
return a.charcode == b.charcode && a.subpixel == b.subpixel;
|
|
|
|
}
|
|
|
|
uint64_t hash() const
|
|
|
|
{
|
|
|
|
return blender::get_default_hash(charcode, subpixel);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
struct GlyphCacheBLF {
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Font size. */
|
2021-11-13 18:39:18 +01:00
|
|
|
float size;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2023-10-21 00:28:28 +02:00
|
|
|
int char_weight;
|
2022-07-07 21:59:16 +02:00
|
|
|
float char_slant;
|
|
|
|
float char_width;
|
|
|
|
float char_spacing;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2020-06-06 00:39:17 +02:00
|
|
|
bool bold;
|
|
|
|
bool italic;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Column width when printing monospaced. */
|
2022-02-05 02:49:21 +01:00
|
|
|
int fixed_width;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** The glyphs. */
|
2024-02-21 18:17:21 +01:00
|
|
|
blender::Map<GlyphCacheKey, std::unique_ptr<GlyphBLF>> glyphs;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Texture array, to draw the glyphs. */
|
BLF: Optimize text rendering and caching
The current code allocates and transfers a lot of memory to the GPU,
but only a small portion of this memory is actually used.
In addition, the code calls many costly gl operations during the
caching process.
This commit significantly reduce the amount of memory by allocating
and transferring a flat array without pads to the GPU.
It also calls as little as possible the gl operations during the cache.
This code also simulate a billinear filter `GL_LINEAR` using a 1D texture.
**Average drawing time:**
|before:|0.00003184 sec
|now:|0.00001943 sec
|fac:|1.6385156675048407
**5 worst times:**
|before:|[0.001075, 0.001433, 0.002143, 0.002915, 0.003242]
|now:|[0.00094, 0.000993, 0.001502, 0.002284, 0.002328]
Differential Revision: https://developer.blender.org/D6886
2020-02-23 21:30:27 +01:00
|
|
|
GPUTexture *texture;
|
|
|
|
char *bitmap_result;
|
|
|
|
int bitmap_len;
|
|
|
|
int bitmap_len_landed;
|
|
|
|
int bitmap_len_alloc;
|
2024-02-19 03:34:36 +01:00
|
|
|
|
|
|
|
~GlyphCacheBLF();
|
2024-02-13 21:34:32 +01:00
|
|
|
};
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
struct GlyphBLF {
|
2022-08-19 06:10:06 +02:00
|
|
|
/** The character, as UTF-32. */
|
2009-08-06 22:06:02 +02:00
|
|
|
unsigned int c;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Freetype2 index, to speed-up the search. */
|
2009-08-18 21:26:53 +02:00
|
|
|
FT_UInt idx;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Glyph bounding-box. */
|
2022-04-05 12:10:55 +02:00
|
|
|
ft_pix box_xmin;
|
|
|
|
ft_pix box_xmax;
|
|
|
|
ft_pix box_ymin;
|
|
|
|
ft_pix box_ymax;
|
|
|
|
|
|
|
|
ft_pix advance_x;
|
2023-09-21 22:43:17 +02:00
|
|
|
uint8_t subpixel;
|
2009-08-06 22:06:02 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** The difference in bearings when hinting is active, zero otherwise. */
|
2022-04-05 12:10:55 +02:00
|
|
|
ft_pix lsb_delta;
|
|
|
|
ft_pix rsb_delta;
|
2009-08-06 22:06:02 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Position inside the texture where this glyph is store. */
|
BLF: Optimize text rendering and caching
The current code allocates and transfers a lot of memory to the GPU,
but only a small portion of this memory is actually used.
In addition, the code calls many costly gl operations during the
caching process.
This commit significantly reduce the amount of memory by allocating
and transferring a flat array without pads to the GPU.
It also calls as little as possible the gl operations during the cache.
This code also simulate a billinear filter `GL_LINEAR` using a 1D texture.
**Average drawing time:**
|before:|0.00003184 sec
|now:|0.00001943 sec
|fac:|1.6385156675048407
**5 worst times:**
|before:|[0.001075, 0.001433, 0.002143, 0.002915, 0.003242]
|now:|[0.00094, 0.000993, 0.001502, 0.002284, 0.002328]
Differential Revision: https://developer.blender.org/D6886
2020-02-23 21:30:27 +01:00
|
|
|
int offset;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/**
|
|
|
|
* Bitmap data, from freetype. Take care that this
|
2009-08-06 22:51:41 +02:00
|
|
|
* can be NULL.
|
|
|
|
*/
|
|
|
|
unsigned char *bitmap;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Glyph width and height. */
|
2020-05-03 09:55:39 +02:00
|
|
|
int dims[2];
|
2009-08-18 21:26:53 +02:00
|
|
|
int pitch;
|
2023-11-30 22:17:30 +01:00
|
|
|
int depth;
|
|
|
|
|
|
|
|
/** Render mode (FT_Render_Mode). */
|
|
|
|
int render_mode;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2020-05-03 09:55:39 +02:00
|
|
|
/**
|
|
|
|
* X and Y bearing of the glyph.
|
2023-06-21 03:28:58 +02:00
|
|
|
* The X bearing is from the origin to the glyph left bounding-box edge.
|
2009-02-09 08:15:22 +01:00
|
|
|
* The Y bearing is from the baseline to the top of the glyph edge.
|
|
|
|
*/
|
2020-05-03 09:55:39 +02:00
|
|
|
int pos[2];
|
2009-08-06 22:51:41 +02:00
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
GlyphCacheBLF *glyph_cache;
|
2024-02-21 18:17:21 +01:00
|
|
|
|
|
|
|
~GlyphBLF();
|
2024-02-13 21:34:32 +01:00
|
|
|
};
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
struct FontBufInfoBLF {
|
2022-08-19 06:10:06 +02:00
|
|
|
/** For draw to buffer, always set this to NULL after finish! */
|
2012-08-13 00:18:20 +02:00
|
|
|
float *fbuf;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** The same but unsigned char. */
|
2012-08-13 00:18:20 +02:00
|
|
|
unsigned char *cbuf;
|
|
|
|
|
2020-05-03 09:55:39 +02:00
|
|
|
/** Buffer size, keep signed so comparisons with negative values work. */
|
|
|
|
int dims[2];
|
2012-08-13 00:18:20 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Number of channels. */
|
2012-08-13 00:18:20 +02:00
|
|
|
int ch;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Display device used for color management. */
|
2024-02-13 21:34:32 +01:00
|
|
|
ColorManagedDisplay *display;
|
2012-08-13 00:18:20 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** The color, the alphas is get from the glyph! (color is sRGB space). */
|
2015-09-18 12:10:26 +02:00
|
|
|
float col_init[4];
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Cached conversion from 'col_init'. */
|
2015-09-18 12:10:26 +02:00
|
|
|
unsigned char col_char[4];
|
|
|
|
float col_float[4];
|
2024-02-13 21:34:32 +01:00
|
|
|
};
|
2015-09-18 12:10:26 +02:00
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
struct FontMetrics {
|
2023-10-22 03:54:57 +02:00
|
|
|
/** Indicate that these values have been properly loaded. */
|
|
|
|
bool valid;
|
FontBLF: Store Sizes, Styles, and Other Metrics
When loading a font, gather metrics and other information that can help
use it more correctly. Default weight and slant, X-height, cap height,
locations for underline, strike-through, subscripts, etc. Family and
style flags, etc.
Pull Request: https://projects.blender.org/blender/blender/pulls/113432
2023-10-14 02:43:48 +02:00
|
|
|
/** This font's default weight, 100-900, 400 is normal. */
|
|
|
|
short weight;
|
|
|
|
/** This font's default width, 1 is normal, 2 is twice as wide. */
|
|
|
|
float width;
|
|
|
|
/** This font's slant in clockwise degrees, 0 being upright. */
|
|
|
|
float slant;
|
|
|
|
/** This font's default spacing, 1 is normal. */
|
|
|
|
float spacing;
|
|
|
|
|
|
|
|
/** Number of font units in an EM square. 2048, 1024, 1000 are typical. */
|
|
|
|
short units_per_EM; /* */
|
|
|
|
/** Design classification from OS/2 sFamilyClass. */
|
|
|
|
short family_class;
|
|
|
|
/** Style classification from OS/2 fsSelection. */
|
|
|
|
short selection_flags;
|
|
|
|
/** Total number of glyphs in the font. */
|
|
|
|
int num_glyphs;
|
|
|
|
/** Minimum Unicode index, typically 0x0020. */
|
|
|
|
short first_charindex;
|
|
|
|
/** Maximum Unicode index, or 0xFFFF if greater than. */
|
|
|
|
short last_charindex;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Positive number of font units from baseline to top of typical capitals. Can be slightly more
|
|
|
|
* than cap height when head serifs, terminals, or apexes extend above cap line. */
|
|
|
|
short ascender;
|
2023-10-14 04:49:50 +02:00
|
|
|
/** Negative (!) number of font units from baseline to bottom of letters like `gjpqy`. */
|
FontBLF: Store Sizes, Styles, and Other Metrics
When loading a font, gather metrics and other information that can help
use it more correctly. Default weight and slant, X-height, cap height,
locations for underline, strike-through, subscripts, etc. Family and
style flags, etc.
Pull Request: https://projects.blender.org/blender/blender/pulls/113432
2023-10-14 02:43:48 +02:00
|
|
|
short descender;
|
|
|
|
/** Positive number of font units between consecutive baselines. */
|
|
|
|
short line_height;
|
|
|
|
/** Font units from baseline to lowercase mean line, typically to top of "x". */
|
|
|
|
short x_height;
|
|
|
|
/** Font units from baseline to top of capital letters, specifically "H". */
|
|
|
|
short cap_height;
|
2023-10-14 04:49:50 +02:00
|
|
|
/** Ratio width to height of lowercase "O". Reliable indication of font proportion. */
|
FontBLF: Store Sizes, Styles, and Other Metrics
When loading a font, gather metrics and other information that can help
use it more correctly. Default weight and slant, X-height, cap height,
locations for underline, strike-through, subscripts, etc. Family and
style flags, etc.
Pull Request: https://projects.blender.org/blender/blender/pulls/113432
2023-10-14 02:43:48 +02:00
|
|
|
float o_proportion;
|
|
|
|
/** Font unit maximum horizontal advance for all glyphs in font. Can help with wrapping. */
|
|
|
|
short max_advance_width;
|
|
|
|
/** As above but only for vertical layout fonts, otherwise is set to line_height value. */
|
|
|
|
short max_advance_height;
|
|
|
|
|
|
|
|
/** Negative (!) number of font units below baseline to center (!) of underlining stem. */
|
|
|
|
short underline_position;
|
|
|
|
/** thickness of the underline in font units. */
|
|
|
|
short underline_thickness;
|
|
|
|
/** Positive number of font units above baseline to the top (!) of strikeout stroke. */
|
|
|
|
short strikeout_position;
|
|
|
|
/** thickness of the strikeout line in font units. */
|
|
|
|
short strikeout_thickness;
|
|
|
|
/** EM size font units of recommended subscript letters. */
|
|
|
|
short subscript_size;
|
|
|
|
/** Horizontal offset before first subscript character, typically 0. */
|
|
|
|
short subscript_xoffset;
|
2023-10-14 04:49:50 +02:00
|
|
|
/** Positive number of font units above baseline for subscript characters. */
|
FontBLF: Store Sizes, Styles, and Other Metrics
When loading a font, gather metrics and other information that can help
use it more correctly. Default weight and slant, X-height, cap height,
locations for underline, strike-through, subscripts, etc. Family and
style flags, etc.
Pull Request: https://projects.blender.org/blender/blender/pulls/113432
2023-10-14 02:43:48 +02:00
|
|
|
short subscript_yoffset;
|
|
|
|
/** EM size font units of recommended superscript letters. */
|
|
|
|
short superscript_size;
|
|
|
|
/** Horizontal offset before first superscript character, typically 0. */
|
|
|
|
short superscript_xoffset;
|
2023-10-14 04:49:50 +02:00
|
|
|
/** Positive (!) number of font units below baseline for subscript characters. */
|
FontBLF: Store Sizes, Styles, and Other Metrics
When loading a font, gather metrics and other information that can help
use it more correctly. Default weight and slant, X-height, cap height,
locations for underline, strike-through, subscripts, etc. Family and
style flags, etc.
Pull Request: https://projects.blender.org/blender/blender/pulls/113432
2023-10-14 02:43:48 +02:00
|
|
|
short superscript_yoffset;
|
2024-02-13 21:34:32 +01:00
|
|
|
};
|
FontBLF: Store Sizes, Styles, and Other Metrics
When loading a font, gather metrics and other information that can help
use it more correctly. Default weight and slant, X-height, cap height,
locations for underline, strike-through, subscripts, etc. Family and
style flags, etc.
Pull Request: https://projects.blender.org/blender/blender/pulls/113432
2023-10-14 02:43:48 +02:00
|
|
|
|
2024-02-13 21:34:32 +01:00
|
|
|
struct FontBLF {
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Full path to font file or NULL if from memory. */
|
2022-03-24 06:33:32 +01:00
|
|
|
char *filepath;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Pointer to in-memory font, or NULL if from file. */
|
2022-07-29 02:50:34 +02:00
|
|
|
void *mem;
|
|
|
|
size_t mem_size;
|
2023-05-03 07:57:37 +02:00
|
|
|
/** Handle for in-memory fonts to avoid loading them multiple times. */
|
|
|
|
char *mem_name;
|
2022-07-29 02:50:34 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/**
|
|
|
|
* Copied from the SFNT OS/2 table. Bit flags for unicode blocks and ranges
|
2022-06-17 19:30:34 +02:00
|
|
|
* considered "functional". Cached here because face might not always exist.
|
2022-08-19 06:10:06 +02:00
|
|
|
* See: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ur
|
|
|
|
*/
|
|
|
|
uint unicode_ranges[4];
|
2022-06-17 19:30:34 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Number of times this font was loaded. */
|
|
|
|
unsigned int reference_count;
|
|
|
|
|
|
|
|
/** Aspect ratio or scale. */
|
Change the BLF_aspect function to handle 3d text.
This is need to properly handle 3d text (dalai work on GE), before
the BLF_aspect only take one argument, and the result was a call to:
glScalef(aspect, aspect, 1.0)
Now the three value are store in the font (x, y and z) and also
need to be enable using BLF_enable(BLF_ASPECT).
By default all the code that don't have BLF_ASPECT enable work with
a scale of 1.0 (so nothing change to the current UI).
I also remove all the call of BLF_aspect(fontid, 1.0) found in
the editors, because is disable by default, so no need any more.
Campbell the only thing to check is the python api, right now
I modify the api to from:
BLF_aspect(fontid, aspect)
to:
BLF_aspect(fontid, aspect, aspect, 1.0)
This is to avoid break the api, but now you need add the BLF_ASPECT
option to the function py_blf_enable and in some point change
py_blf_aspect to take 3 arguments.
2010-12-09 23:27:55 +01:00
|
|
|
float aspect[3];
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Initial position for draw the text. */
|
2022-04-13 04:45:41 +02:00
|
|
|
int pos[3];
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Angle in radians. */
|
2009-02-19 17:39:36 +01:00
|
|
|
float angle;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2016-10-16 17:28:12 +02:00
|
|
|
#if 0 /* BLF_BLUR_ENABLE */
|
2009-04-10 16:27:29 +02:00
|
|
|
/* blur: 3 or 5 large kernel */
|
|
|
|
int blur;
|
2016-10-16 01:40:41 +02:00
|
|
|
#endif
|
2009-06-23 18:27:35 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Shadow level. */
|
2009-06-23 18:27:35 +02:00
|
|
|
int shadow;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** And shadow offset. */
|
2009-06-23 18:27:35 +02:00
|
|
|
int shadow_x;
|
|
|
|
int shadow_y;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Shadow color. */
|
2016-10-16 08:08:16 +02:00
|
|
|
unsigned char shadow_color[4];
|
2011-09-17 12:45:20 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Main text color. */
|
2016-10-16 08:08:16 +02:00
|
|
|
unsigned char color[4];
|
2011-09-17 12:45:20 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/**
|
|
|
|
* Multiplied this matrix with the current one before draw the text!
|
2023-10-12 07:10:01 +02:00
|
|
|
* see #blf_draw_gpu__start.
|
2010-12-09 05:36:58 +01:00
|
|
|
*/
|
2015-12-14 03:19:45 +01:00
|
|
|
float m[16];
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Clipping rectangle. */
|
2022-04-13 04:45:41 +02:00
|
|
|
rcti clip_rec;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** The width to wrap the text, see #BLF_WORD_WRAP. */
|
2015-09-18 12:10:26 +02:00
|
|
|
int wrap_width;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Font size. */
|
2021-11-13 18:39:18 +01:00
|
|
|
float size;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2023-03-09 00:39:49 +01:00
|
|
|
/** Axes data for Adobe MM, TrueType GX, or OpenType variation fonts. */
|
2022-07-07 21:59:16 +02:00
|
|
|
FT_MM_Var *variations;
|
|
|
|
|
2023-10-21 00:28:28 +02:00
|
|
|
/** Character variations. */
|
|
|
|
int char_weight; /* 100 - 900, 400 = normal. */
|
|
|
|
float char_slant; /* Slant in clockwise degrees. 0.0 = upright. */
|
|
|
|
float char_width; /* Factor of normal character width. 1.0 = normal. */
|
2023-12-07 02:15:45 +01:00
|
|
|
float char_spacing; /* Factor of normal character spacing. 0.0 = normal. */
|
2022-07-07 21:59:16 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Max texture size. */
|
2018-03-31 13:40:23 +02:00
|
|
|
int tex_size_max;
|
2009-02-09 08:15:22 +01:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Font options. */
|
2009-02-20 06:42:44 +01:00
|
|
|
int flags;
|
|
|
|
|
2022-05-06 09:56:59 +02:00
|
|
|
/**
|
|
|
|
* List of glyph caches (#GlyphCacheBLF) for this font for size, DPI, bold, italic.
|
2019-09-14 02:22:42 +02:00
|
|
|
* Use blf_glyph_cache_acquire(font) and blf_glyph_cache_release(font) to access cache!
|
|
|
|
*/
|
2024-02-19 03:34:36 +01:00
|
|
|
blender::Vector<std::unique_ptr<GlyphCacheBLF>> cache;
|
2009-03-02 06:20:48 +01:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Cache of unscaled kerning values. Will be NULL if font does not have kerning. */
|
2018-03-31 15:24:10 +02:00
|
|
|
KerningCacheBLF *kerning_cache;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Freetype2 lib handle. */
|
2011-02-19 14:43:22 +01:00
|
|
|
FT_Library ft_lib;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Freetype2 face. */
|
2009-05-08 21:47:40 +02:00
|
|
|
FT_Face face;
|
2009-08-18 21:26:53 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Point to face->size or to cache's size. */
|
2022-08-04 22:05:19 +02:00
|
|
|
FT_Size ft_size;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Copy of the font->face->face_flags, in case we don't have a face loaded. */
|
2022-08-04 22:05:19 +02:00
|
|
|
FT_Long face_flags;
|
|
|
|
|
2023-10-14 04:49:50 +02:00
|
|
|
/** Details about the font's design and style and sizes (in un-sized font units). */
|
FontBLF: Store Sizes, Styles, and Other Metrics
When loading a font, gather metrics and other information that can help
use it more correctly. Default weight and slant, X-height, cap height,
locations for underline, strike-through, subscripts, etc. Family and
style flags, etc.
Pull Request: https://projects.blender.org/blender/blender/pulls/113432
2023-10-14 02:43:48 +02:00
|
|
|
FontMetrics metrics;
|
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Data for buffer usage (drawing into a texture buffer) */
|
2012-08-13 00:18:20 +02:00
|
|
|
FontBufInfoBLF buf_info;
|
2019-09-14 02:22:42 +02:00
|
|
|
|
2022-08-19 06:10:06 +02:00
|
|
|
/** Mutex lock for glyph cache. */
|
2024-02-19 03:34:36 +01:00
|
|
|
std::mutex glyph_cache_mutex;
|
2024-02-13 21:34:32 +01:00
|
|
|
};
|