203 static const uchar gamma[256] = {
204 0, 5, 9, 11, 14, 16, 19, 21, 23, 25, 26, 28, 30, 32, 34, 35, 37, 38,
205 40, 41, 43, 44, 46, 47, 49, 50, 52, 53, 54, 56, 57, 58, 60, 61, 62, 64,
206 65, 66, 67, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85,
207 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
208 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
209 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139,
210 140, 141, 142, 143, 143, 144, 145, 146, 147, 148, 149, 150, 151, 151, 152, 153, 154, 155,
211 156, 157, 157, 158, 159, 160, 161, 162, 163, 163, 164, 165, 166, 167, 168, 168, 169, 170,
212 171, 172, 173, 173, 174, 175, 176, 177, 178, 178, 179, 180, 181, 182, 182, 183, 184, 185,
213 186, 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 194, 195, 196, 197, 198, 198, 199,
214 200, 201, 201, 202, 203, 204, 205, 205, 206, 207, 208, 208, 209, 210, 211, 211, 212, 213,
215 214, 214, 215, 216, 217, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226,
216 227, 228, 229, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 239,
217 240, 241, 242, 242, 243, 244, 244, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252,
230 std::unique_ptr<GlyphBLF> g = std::make_unique<GlyphBLF>();
232 g->idx = glyph_index;
233 g->advance_x = (
ft_pix)glyph->advance.x;
234 g->subpixel = subpixel;
237 FT_Outline_Get_CBox(&(glyph->outline), &bbox);
238 g->box_xmin = (
ft_pix)bbox.xMin;
239 g->box_xmax = (
ft_pix)bbox.xMax;
240 g->box_ymin = (
ft_pix)bbox.yMin;
241 g->box_ymax = (
ft_pix)bbox.yMax;
244 g->lsb_delta = (
ft_pix)glyph->lsb_delta;
245 g->rsb_delta = (
ft_pix)glyph->rsb_delta;
247 if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
249 g->pos[0] = glyph->bitmap_left;
250 g->pos[1] = glyph->bitmap_top;
251 g->dims[0] =
int(glyph->bitmap.width);
252 g->dims[1] =
int(glyph->bitmap.rows);
253 g->pitch = glyph->bitmap.pitch;
256 switch (glyph->bitmap.pixel_mode) {
257 case FT_PIXEL_MODE_LCD:
261 case FT_PIXEL_MODE_LCD_V:
266 case FT_PIXEL_MODE_BGRA:
271 const int buffer_size = g->dims[0] * g->dims[1] * g->num_channels;
272 g->bitmap =
static_cast<uchar *
>(
MEM_mallocN(
size_t(buffer_size),
"glyph bitmap"));
274 if (
ELEM(glyph->bitmap.pixel_mode,
277 FT_PIXEL_MODE_GRAY4))
280 const char scale = char(255 / (glyph->bitmap.num_grays - 1));
281 for (
int i = 0; i < buffer_size; i++) {
282#ifdef BLF_GAMMA_CORRECT_GLYPHS
286 g->bitmap[i] = glyph->bitmap.buffer[i] * scale;
290 else if (glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
292 for (
size_t y = 0; y < size_t(g->dims[1]); y++) {
293 for (
size_t x = 0; x < size_t(g->dims[0]); x++) {
294 size_t offs_in = (y * size_t(glyph->bitmap.pitch)) + (x *
size_t(g->num_channels));
295 size_t offs_out = (y * size_t(g->dims[0]) * size_t(g->num_channels)) +
296 (x *
size_t(g->num_channels));
297 g->bitmap[offs_out + 0] = glyph->bitmap.buffer[offs_in + 2];
298 g->bitmap[offs_out + 1] = glyph->bitmap.buffer[offs_in + 1];
299 g->bitmap[offs_out + 2] = glyph->bitmap.buffer[offs_in + 0];
303 else if (glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
305 for (
size_t y = 0; y < size_t(g->dims[1]); y++) {
306 for (
size_t x = 0; x < size_t(g->dims[0]); x++) {
307 size_t offs_in = (y * size_t(glyph->bitmap.pitch) * size_t(g->num_channels)) + x;
308 size_t offs_out = (y * size_t(g->dims[0]) * size_t(g->num_channels)) +
309 (x *
size_t(g->num_channels));
310 g->bitmap[offs_out + 2] = glyph->bitmap.buffer[offs_in];
311 g->bitmap[offs_out + 1] = glyph->bitmap.buffer[offs_in + size_t(glyph->bitmap.pitch)];
312 g->bitmap[offs_out + 0] = glyph->bitmap.buffer[offs_in + size_t(glyph->bitmap.pitch) +
313 size_t(glyph->bitmap.pitch)];
317 else if (glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) {
319 for (
size_t y = 0; y < size_t(g->dims[1]); y++) {
320 for (
size_t x = 0; x < size_t(g->dims[0]); x++) {
321 size_t offs_in = (y * size_t(g->pitch)) + (x *
size_t(g->num_channels));
322 size_t offs_out = (y * size_t(g->dims[0]) * size_t(g->num_channels)) +
323 (x *
size_t(g->num_channels));
324 g->bitmap[offs_out + 0] = glyph->bitmap.buffer[offs_in + 2];
325 g->bitmap[offs_out + 1] = glyph->bitmap.buffer[offs_in + 1];
326 g->bitmap[offs_out + 2] = glyph->bitmap.buffer[offs_in + 0];
327 g->bitmap[offs_out + 3] = glyph->bitmap.buffer[offs_in + 3];
332 memcpy(g->bitmap, glyph->bitmap.buffer,
size_t(buffer_size));
1285 FT_UInt glyph_index,
1291 if (glyph_font != settings_font) {
1306 weight_target = std::min(weight_target + 300.0f, 900.0f);
1308 float slant_target = settings_font->
char_slant;
1310 slant_target = std::min(slant_target + 8.0f, 15.0f);
1312 float width_target = settings_font->
char_width;
1333 FT_GlyphSlot glyph =
blf_glyph_load(glyph_font, glyph_index, outline_only);
1347 if (weight != weight_target) {
1350 if (slant != slant_target) {
1353 if (width != width_target) {
1356 if (spacing != spacing_target) {
1364 FT_Outline_Translate(&glyph->outline, (FT_Pos)subpixel, 0);
1680 const float eps = 0.0001f;
1681 const float eps_sq =
eps *
eps;
1685 int j, k,
l, l_first = 0;
1691 int *onpoints =
static_cast<int *
>(
1692 MEM_callocN(
size_t(ftoutline.n_contours) *
sizeof(
int),
"onpoints"));
1695 for (j = 0, contour_prev = -1; j < ftoutline.n_contours; j++) {
1696 const int n = ftoutline.contours[j] - contour_prev;
1697 contour_prev = ftoutline.contours[j];
1699 for (k = 0; k < n; k++) {
1700 l = (j > 0) ? (k + ftoutline.contours[j - 1] + 1) : k;
1705 if (ftoutline.tags[
l] == FT_Curve_Tag_On) {
1710 const int l_next = (k < n - 1) ? (
l + 1) : l_first;
1711 if (ftoutline.tags[
l] == FT_Curve_Tag_Conic &&
1712 ftoutline.tags[l_next] == FT_Curve_Tag_Conic)
1721 for (j = 0, contour_prev = -1; j < ftoutline.n_contours; j++) {
1722 const int n = ftoutline.contours[j] - contour_prev;
1723 contour_prev = ftoutline.contours[j];
1732 nu->
pntsu = onpoints[j];
1738 for (k = 0; k < n; k++) {
1739 l = (j > 0) ? (k + ftoutline.contours[j - 1] + 1) : k;
1746 const int l_next = (k < n - 1) ? (
l + 1) : l_first;
1747 if (ftoutline.tags[
l] == FT_Curve_Tag_Conic &&
1748 ftoutline.tags[l_next] == FT_Curve_Tag_Conic)
1750 dx =
float(ftoutline.points[
l].x + ftoutline.points[l_next].x) * scale / 2.0f;
1751 dy =
float(ftoutline.points[
l].y + ftoutline.points[l_next].y) * scale / 2.0f;
1754 bezt->
vec[0][0] = (dx + (2.0f *
float(ftoutline.points[
l].x)) * scale) / 3.0f;
1755 bezt->
vec[0][1] = (dy + (2.0f *
float(ftoutline.points[
l].y)) * scale) / 3.0f;
1758 bezt->
vec[1][0] = dx;
1759 bezt->
vec[1][1] = dy;
1762 bezt->
vec[2][0] = (dx + (2.0f *
float(ftoutline.points[l_next].x)) * scale) / 3.0f;
1763 bezt->
vec[2][1] = (dy + (2.0f *
float(ftoutline.points[l_next].y)) * scale) / 3.0f;
1772 if (ftoutline.tags[
l] == FT_Curve_Tag_On) {
1773 const int l_prev = (k > 0) ? (
l - 1) : ftoutline.contours[j];
1774 const int l_next = (k < n - 1) ? (
l + 1) : l_first;
1777 if (ftoutline.tags[l_prev] == FT_Curve_Tag_Cubic) {
1778 bezt->
vec[0][0] =
float(ftoutline.points[l_prev].x) * scale;
1779 bezt->
vec[0][1] =
float(ftoutline.points[l_prev].y) * scale;
1782 else if (ftoutline.tags[l_prev] == FT_Curve_Tag_Conic) {
1783 bezt->
vec[0][0] = (
float(ftoutline.points[
l].x) +
1784 (2.0f *
float(ftoutline.points[l_prev].x))) *
1786 bezt->
vec[0][1] = (
float(ftoutline.points[
l].y) +
1787 (2.0f *
float(ftoutline.points[l_prev].y))) *
1792 bezt->
vec[0][0] =
float(ftoutline.points[
l].x) * scale -
1793 (
float(ftoutline.points[
l].x) -
float(ftoutline.points[l_prev].x)) *
1795 bezt->
vec[0][1] =
float(ftoutline.points[
l].y) * scale -
1796 (
float(ftoutline.points[
l].y) -
float(ftoutline.points[l_prev].y)) *
1802 bezt->
vec[1][0] =
float(ftoutline.points[
l].x) * scale;
1803 bezt->
vec[1][1] =
float(ftoutline.points[
l].y) * scale;
1806 if (ftoutline.tags[l_next] == FT_Curve_Tag_Cubic) {
1807 bezt->
vec[2][0] =
float(ftoutline.points[l_next].x) * scale;
1808 bezt->
vec[2][1] =
float(ftoutline.points[l_next].y) * scale;
1811 else if (ftoutline.tags[l_next] == FT_Curve_Tag_Conic) {
1812 bezt->
vec[2][0] = (
float(ftoutline.points[
l].x) +
1813 (2.0f *
float(ftoutline.points[l_next].x))) *
1815 bezt->
vec[2][1] = (
float(ftoutline.points[
l].y) +
1816 (2.0f *
float(ftoutline.points[l_next].y))) *
1821 bezt->
vec[2][0] =
float(ftoutline.points[
l].x) * scale -
1822 (
float(ftoutline.points[
l].x) -
float(ftoutline.points[l_next].x)) *
1824 bezt->
vec[2][1] =
float(ftoutline.points[
l].y) * scale -
1825 (
float(ftoutline.points[
l].y) -
float(ftoutline.points[l_next].y)) *
1838 (0.001f * 0.001f)) &&
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)