Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenfont/intern/blf_internal_types.h')
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h92
1 files changed, 84 insertions, 8 deletions
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 23dc2fda38c..62bce36dda0 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -10,6 +10,78 @@
#include "GPU_texture.h"
#include "GPU_vertex_buffer.h"
+/* -------------------------------------------------------------------- */
+/** \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`. */
+
+/* FIXME(@campbellbarton): Follow rounding from Blender 3.1x and older.
+ * This is what users will expect and changing this creates wider spaced text.
+ * Use this macro to communicate that rounding should be used, using floor is to avoid
+ * user visible changes, which can be reviewed and handled separately. */
+#define USE_LEGACY_SPACING
+
+#define FT_PIX_FLOOR(x) ((x) & ~63)
+#define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32)
+#define FT_PIX_CEIL(x) ((x) + 63)
+
+#ifdef USE_LEGACY_SPACING
+# define FT_PIX_DEFAULT_ROUNDING(x) FT_PIX_FLOOR(x)
+#else
+# define FT_PIX_DEFAULT_ROUNDING(x) FT_PIX_ROUND(x)
+#endif
+
+BLI_INLINE int ft_pix_to_int(ft_pix v)
+{
+#ifdef USE_LEGACY_SPACING
+ return (int)(v >> 6);
+#else
+ return (int)(FT_PIX_DEFAULT_ROUNDING(v) >> 6);
+#endif
+}
+
+BLI_INLINE int ft_pix_to_int_floor(ft_pix v)
+{
+ return (int)(v >> 6); /* No need for explicit floor as the bits are removed when shifting. */
+}
+
+BLI_INLINE int ft_pix_to_int_ceil(ft_pix v)
+{
+ return (int)(FT_PIX_CEIL(v) >> 6);
+}
+
+BLI_INLINE ft_pix ft_pix_from_int(int v)
+{
+ return v * 64;
+}
+
+BLI_INLINE ft_pix ft_pix_from_float(float v)
+{
+ return lroundf(v * 64.0f);
+}
+
+BLI_INLINE ft_pix ft_pix_round_advance(ft_pix v, ft_pix step)
+{
+ /* See #USE_LEGACY_SPACING, rounding logic could change here. */
+ return FT_PIX_DEFAULT_ROUNDING(v) + FT_PIX_DEFAULT_ROUNDING(step);
+}
+
+#undef FT_PIX_ROUND
+#undef FT_PIX_CEIL
+#undef FT_PIX_DEFAULT_ROUNDING
+
+/** \} */
+
#define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */
/* Number of characters in GlyphCacheBLF.glyph_ascii_table. */
@@ -28,7 +100,7 @@ typedef struct BatchBLF {
struct GPUVertBufRaw pos_step, col_step, offset_step, glyph_size_step;
unsigned int pos_loc, col_loc, offset_loc, glyph_size_loc;
unsigned int glyph_len;
- float ofs[2]; /* copy of font->pos */
+ int ofs[2]; /* copy of font->pos */
float mat[4][4]; /* previous call modelmatrix. */
bool enabled, active, simple_shader;
struct GlyphCacheBLF *glyph_cache;
@@ -86,12 +158,16 @@ typedef struct GlyphBLF {
FT_UInt idx;
/* glyph box. */
- rctf box;
+ ft_pix box_xmin;
+ ft_pix box_xmax;
+ ft_pix box_ymin;
+ ft_pix box_ymax;
+
+ ft_pix advance_x;
- /* advance size. */
- float advance;
- /* avoid conversion to int while drawing */
- int advance_i;
+ /* The difference in bearings when hinting is active, zero otherwise. */
+ ft_pix lsb_delta;
+ ft_pix rsb_delta;
/* position inside the texture where this glyph is store. */
int offset;
@@ -154,7 +230,7 @@ typedef struct FontBLF {
float aspect[3];
/* initial position for draw the text. */
- float pos[3];
+ int pos[3];
/* angle in radians. */
float angle;
@@ -183,7 +259,7 @@ typedef struct FontBLF {
float m[16];
/* clipping rectangle. */
- rctf clip_rec;
+ rcti clip_rec;
/* the width to wrap the text, see BLF_WORD_WRAP */
int wrap_width;