From cf6f69cdc9ea4d0cc7f1fb86e724a31b1e61926b Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Sun, 8 Nov 2015 16:40:32 -0800 Subject: [PATCH 1/4] Fix the calculation of the input image shift when using subpixel regions. Includes some more tests which had incorrect results before and now work fine. --- stb_image_resize.h | 20 ++++++++++---------- tests/resample_test.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/stb_image_resize.h b/stb_image_resize.h index 4ce7ddb..fde37d8 100644 --- a/stb_image_resize.h +++ b/stb_image_resize.h @@ -1004,31 +1004,31 @@ stbir__inline static int stbir__edge_wrap(stbir_edge edge, int n, int max) } // What input pixels contribute to this output pixel? -static void stbir__calculate_sample_range_upsample(int n, float out_filter_radius, float scale_ratio, float out_shift, int* in_first_pixel, int* in_last_pixel, float* in_center_of_out) +static void stbir__calculate_sample_range_upsample(int n, float out_filter_radius, float scale_ratio, float in_shift, int* in_first_pixel, int* in_last_pixel, float* in_center_of_out) { float out_pixel_center = (float)n + 0.5f; float out_pixel_influence_lowerbound = out_pixel_center - out_filter_radius; float out_pixel_influence_upperbound = out_pixel_center + out_filter_radius; - float in_pixel_influence_lowerbound = (out_pixel_influence_lowerbound + out_shift) / scale_ratio; - float in_pixel_influence_upperbound = (out_pixel_influence_upperbound + out_shift) / scale_ratio; + float in_pixel_influence_lowerbound = out_pixel_influence_lowerbound / scale_ratio + in_shift; + float in_pixel_influence_upperbound = out_pixel_influence_upperbound / scale_ratio + in_shift; - *in_center_of_out = (out_pixel_center + out_shift) / scale_ratio; + *in_center_of_out = out_pixel_center / scale_ratio + in_shift; *in_first_pixel = (int)(floor(in_pixel_influence_lowerbound + 0.5)); *in_last_pixel = (int)(floor(in_pixel_influence_upperbound - 0.5)); } // What output pixels does this input pixel contribute to? -static void stbir__calculate_sample_range_downsample(int n, float in_pixels_radius, float scale_ratio, float out_shift, int* out_first_pixel, int* out_last_pixel, float* out_center_of_in) +static void stbir__calculate_sample_range_downsample(int n, float in_pixels_radius, float scale_ratio, float in_shift, int* out_first_pixel, int* out_last_pixel, float* out_center_of_in) { float in_pixel_center = (float)n + 0.5f; float in_pixel_influence_lowerbound = in_pixel_center - in_pixels_radius; float in_pixel_influence_upperbound = in_pixel_center + in_pixels_radius; - float out_pixel_influence_lowerbound = in_pixel_influence_lowerbound * scale_ratio - out_shift; - float out_pixel_influence_upperbound = in_pixel_influence_upperbound * scale_ratio - out_shift; + float out_pixel_influence_lowerbound = (in_pixel_influence_lowerbound - in_shift) * scale_ratio; + float out_pixel_influence_upperbound = (in_pixel_influence_upperbound - in_shift) * scale_ratio; - *out_center_of_in = in_pixel_center * scale_ratio - out_shift; + *out_center_of_in = (in_pixel_center - in_shift) * scale_ratio; *out_first_pixel = (int)(floor(out_pixel_influence_lowerbound + 0.5)); *out_last_pixel = (int)(floor(out_pixel_influence_upperbound - 0.5)); } @@ -2229,8 +2229,8 @@ static void stbir__calculate_transform(stbir__info *info, float s0, float t0, fl info->horizontal_scale = ((float)info->output_w / info->input_w) / (s1 - s0); info->vertical_scale = ((float)info->output_h / info->input_h) / (t1 - t0); - info->horizontal_shift = s0 * info->input_w / (s1 - s0); - info->vertical_shift = t0 * info->input_h / (t1 - t0); + info->horizontal_shift = s0 * info->input_w; + info->vertical_shift = t0 * info->input_h; } } diff --git a/tests/resample_test.cpp b/tests/resample_test.cpp index c42df7b..3bd3402 100644 --- a/tests/resample_test.cpp +++ b/tests/resample_test.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #if defined(_WIN32) && _MSC_VER > 1200 #define STBIR_ASSERT(x) \ @@ -356,6 +357,30 @@ void test_subpixel(const char* file, float width_percent, float height_percent, free(output_data); } +void test_subpixel_really(const char* file, float width_percent, float height_percent, float s0, float t0, float s1, float t1) +{ + int w, h, n; + unsigned char* input_data = stbi_load(file, &w, &h, &n, 0); + + if (input_data == NULL) + return; + + int new_w = (int)(w * width_percent); + int new_h = (int)(h * height_percent); + + unsigned char* output_data = (unsigned char*)malloc(new_w * new_h * n * sizeof(unsigned char)); + + stbir_resize_region(input_data, w, h, 0, output_data, new_w, new_h, 0, STBIR_TYPE_UINT8, n, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_BOX, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, s0, t0, s1, t1); + + stbi_image_free(input_data); + + char output[200]; + sprintf(output, "test-output/subpixel-really-%d-%d-%f-%f-%f-%f-%s", new_w, new_h, s0, t0, s1, t1, file); + stbi_write_png(output, new_w, new_h, n, output_data, 0); + + free(output_data); +} + unsigned int* pixel(unsigned int* buffer, int x, int y, int c, int w, int n) { return &buffer[y*w*n + x*n + c]; @@ -880,6 +905,19 @@ void test_suite(int argc, char **argv) stbir_resize(image88, 8, 8, 0, output88, 16, 4, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_BOX, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context); stbir_resize(image88, 8, 8, 0, output88, 16, 4, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_BOX, STBIR_COLORSPACE_SRGB, &g_context); + int res = 10; + for (int i = 0; i < res; i++) + { + float t = (float)i/res / 2; + test_subpixel_really(barbara, 0.5f, 0.5f, t, t, t+0.5f, t+0.5f); + } + + for (int i = 0; i < res; i++) + { + float t = (float)i/res / 2; + test_subpixel_really(barbara, 2, 2, t, t, t+0.5f, t+0.5f); + } + for (i = 0; i < 10; i++) test_subpixel(barbara, 0.5f, 0.5f, (float)i / 10, 1); From a1ef3a1060a819aa48fd3fbf7547f0839fda4938 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Tue, 10 Nov 2015 11:25:59 -0800 Subject: [PATCH 2/4] Fix the calculation of the input image shift when using subpixel regions --- stb_image_resize.h | 4 +- tests/resample_test.cpp | 100 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/stb_image_resize.h b/stb_image_resize.h index 4ce7ddb..f7ce8f1 100644 --- a/stb_image_resize.h +++ b/stb_image_resize.h @@ -2229,8 +2229,8 @@ static void stbir__calculate_transform(stbir__info *info, float s0, float t0, fl info->horizontal_scale = ((float)info->output_w / info->input_w) / (s1 - s0); info->vertical_scale = ((float)info->output_h / info->input_h) / (t1 - t0); - info->horizontal_shift = s0 * info->input_w / (s1 - s0); - info->vertical_shift = t0 * info->input_h / (t1 - t0); + info->horizontal_shift = s0 * info->output_w / (s1 - s0); + info->vertical_shift = t0 * info->output_h / (t1 - t0); } } diff --git a/tests/resample_test.cpp b/tests/resample_test.cpp index c42df7b..86b7e5d 100644 --- a/tests/resample_test.cpp +++ b/tests/resample_test.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #if defined(_WIN32) && _MSC_VER > 1200 #define STBIR_ASSERT(x) \ @@ -356,6 +357,54 @@ void test_subpixel(const char* file, float width_percent, float height_percent, free(output_data); } +void test_subpixel_region(const char* file, float width_percent, float height_percent, float s0, float t0, float s1, float t1) +{ + int w, h, n; + unsigned char* input_data = stbi_load(file, &w, &h, &n, 0); + + if (input_data == NULL) + return; + + int new_w = (int)(w * width_percent); + int new_h = (int)(h * height_percent); + + unsigned char* output_data = (unsigned char*)malloc(new_w * new_h * n * sizeof(unsigned char)); + + stbir_resize_region(input_data, w, h, 0, output_data, new_w, new_h, 0, STBIR_TYPE_UINT8, n, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_BOX, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, s0, t0, s1, t1); + + stbi_image_free(input_data); + + char output[200]; + sprintf(output, "test-output/subpixel-region-%d-%d-%f-%f-%f-%f-%s", new_w, new_h, s0, t0, s1, t1, file); + stbi_write_png(output, new_w, new_h, n, output_data, 0); + + free(output_data); +} + +void test_subpixel_command(const char* file, float width_percent, float height_percent, float x_scale, float y_scale, float x_offset, float y_offset) +{ + int w, h, n; + unsigned char* input_data = stbi_load(file, &w, &h, &n, 0); + + if (input_data == NULL) + return; + + int new_w = (int)(w * width_percent); + int new_h = (int)(h * height_percent); + + unsigned char* output_data = (unsigned char*)malloc(new_w * new_h * n * sizeof(unsigned char)); + + stbir_resize_subpixel(input_data, w, h, 0, output_data, new_w, new_h, 0, STBIR_TYPE_UINT8, n, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_BOX, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, x_scale, y_scale, x_offset, y_offset); + + stbi_image_free(input_data); + + char output[200]; + sprintf(output, "test-output/subpixel-command-%d-%d-%f-%f-%f-%f-%s", new_w, new_h, x_scale, y_scale, x_offset, y_offset, file); + stbi_write_png(output, new_w, new_h, n, output_data, 0); + + free(output_data); +} + unsigned int* pixel(unsigned int* buffer, int x, int y, int c, int w, int n) { return &buffer[y*w*n + x*n + c]; @@ -880,6 +929,55 @@ void test_suite(int argc, char **argv) stbir_resize(image88, 8, 8, 0, output88, 16, 4, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_BOX, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context); stbir_resize(image88, 8, 8, 0, output88, 16, 4, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_BOX, STBIR_COLORSPACE_SRGB, &g_context); + int barbara_width, barbara_height, barbara_channels; + stbi_image_free(stbi_load(barbara, &barbara_width, &barbara_height, &barbara_channels, 0)); + + int res = 10; + // Downscaling + for (int i = 0; i <= res; i++) + { + float t = (float)i/res; + float scale = 0.5; + float out_scale = 2.0/3; + float x_shift = (barbara_width*out_scale - barbara_width*scale) * t; + float y_shift = (barbara_height*out_scale - barbara_height*scale) * t; + + test_subpixel_command(barbara, scale, scale, out_scale, out_scale, x_shift, y_shift); + } + + // Upscaling + for (int i = 0; i <= res; i++) + { + float t = (float)i/res; + float scale = 2; + float out_scale = 3; + float x_shift = (barbara_width*out_scale - barbara_width*scale) * t; + float y_shift = (barbara_height*out_scale - barbara_height*scale) * t; + + test_subpixel_command(barbara, scale, scale, out_scale, out_scale, x_shift, y_shift); + } + + // Downscaling + for (int i = 0; i <= res; i++) + { + float t = (float)i/res / 2; + test_subpixel_region(barbara, 0.25f, 0.25f, t, t, t+0.5f, t+0.5f); + } + + // No scaling + for (int i = 0; i <= res; i++) + { + float t = (float)i/res / 2; + test_subpixel_region(barbara, 0.5f, 0.5f, t, t, t+0.5f, t+0.5f); + } + + // Upscaling + for (int i = 0; i <= res; i++) + { + float t = (float)i/res / 2; + test_subpixel_region(barbara, 1, 1, t, t, t+0.5f, t+0.5f); + } + for (i = 0; i < 10; i++) test_subpixel(barbara, 0.5f, 0.5f, (float)i / 10, 1); From 831b2d2fa63ee50ceee2d7d59c2face439f17670 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Tue, 10 Nov 2015 13:41:53 -0800 Subject: [PATCH 3/4] Fix a merge gone wrong, add some more test cases. --- stb_image_resize.h | 16 ++++++++-------- tests/resample_test.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/stb_image_resize.h b/stb_image_resize.h index 518380b..f7ce8f1 100644 --- a/stb_image_resize.h +++ b/stb_image_resize.h @@ -1004,31 +1004,31 @@ stbir__inline static int stbir__edge_wrap(stbir_edge edge, int n, int max) } // What input pixels contribute to this output pixel? -static void stbir__calculate_sample_range_upsample(int n, float out_filter_radius, float scale_ratio, float in_shift, int* in_first_pixel, int* in_last_pixel, float* in_center_of_out) +static void stbir__calculate_sample_range_upsample(int n, float out_filter_radius, float scale_ratio, float out_shift, int* in_first_pixel, int* in_last_pixel, float* in_center_of_out) { float out_pixel_center = (float)n + 0.5f; float out_pixel_influence_lowerbound = out_pixel_center - out_filter_radius; float out_pixel_influence_upperbound = out_pixel_center + out_filter_radius; - float in_pixel_influence_lowerbound = out_pixel_influence_lowerbound / scale_ratio + in_shift; - float in_pixel_influence_upperbound = out_pixel_influence_upperbound / scale_ratio + in_shift; + float in_pixel_influence_lowerbound = (out_pixel_influence_lowerbound + out_shift) / scale_ratio; + float in_pixel_influence_upperbound = (out_pixel_influence_upperbound + out_shift) / scale_ratio; - *in_center_of_out = out_pixel_center / scale_ratio + in_shift; + *in_center_of_out = (out_pixel_center + out_shift) / scale_ratio; *in_first_pixel = (int)(floor(in_pixel_influence_lowerbound + 0.5)); *in_last_pixel = (int)(floor(in_pixel_influence_upperbound - 0.5)); } // What output pixels does this input pixel contribute to? -static void stbir__calculate_sample_range_downsample(int n, float in_pixels_radius, float scale_ratio, float in_shift, int* out_first_pixel, int* out_last_pixel, float* out_center_of_in) +static void stbir__calculate_sample_range_downsample(int n, float in_pixels_radius, float scale_ratio, float out_shift, int* out_first_pixel, int* out_last_pixel, float* out_center_of_in) { float in_pixel_center = (float)n + 0.5f; float in_pixel_influence_lowerbound = in_pixel_center - in_pixels_radius; float in_pixel_influence_upperbound = in_pixel_center + in_pixels_radius; - float out_pixel_influence_lowerbound = (in_pixel_influence_lowerbound - in_shift) * scale_ratio; - float out_pixel_influence_upperbound = (in_pixel_influence_upperbound - in_shift) * scale_ratio; + float out_pixel_influence_lowerbound = in_pixel_influence_lowerbound * scale_ratio - out_shift; + float out_pixel_influence_upperbound = in_pixel_influence_upperbound * scale_ratio - out_shift; - *out_center_of_in = (in_pixel_center - in_shift) * scale_ratio; + *out_center_of_in = in_pixel_center * scale_ratio - out_shift; *out_first_pixel = (int)(floor(out_pixel_influence_lowerbound + 0.5)); *out_last_pixel = (int)(floor(out_pixel_influence_upperbound - 0.5)); } diff --git a/tests/resample_test.cpp b/tests/resample_test.cpp index 86b7e5d..e04962b 100644 --- a/tests/resample_test.cpp +++ b/tests/resample_test.cpp @@ -510,6 +510,18 @@ void test_subpixel_1() STBIR_ASSERT(output_data[y * 16 + x + 8] == output_right[y * 8 + x]); } } + + stbir_resize_subpixel(image, 8, 8, 0, output_left, 8, 16, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, 2, 2, 0, 0); + stbir_resize_subpixel(image, 8, 8, 0, output_right, 8, 16, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, 2, 2, 8, 0); + + for (int x = 0; x < 8; x++) + { + for (int y = 0; y < 16; y++) + { + STBIR_ASSERT(output_data[y * 16 + x] == output_left[y * 8 + x]); + STBIR_ASSERT(output_data[y * 16 + x + 8] == output_right[y * 8 + x]); + } + } } // test that replicating an image and using a subtile of it produces same results as wraparound @@ -547,6 +559,14 @@ void test_subpixel_2() for (int y = 0; y < 16; y++) STBIR_ASSERT(output_data_1[y * 16 + x] == output_data_2[y * 16 + x]); }} + + stbir_resize_subpixel(large_image, 32, 32, 0, output_data_2, 16, 16, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_WRAP, STBIR_EDGE_WRAP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_SRGB, &g_context, 2, 2, 16, 16); + + {for (int x = 0; x < 16; x++) + { + for (int y = 0; y < 16; y++) + STBIR_ASSERT(output_data_1[y * 16 + x] == output_data_2[y * 16 + x]); + }} } // test that 0,0,1,1 subpixel produces same result as no-rect @@ -570,6 +590,14 @@ void test_subpixel_3() for (int y = 0; y < 32; y++) STBIR_ASSERT(output_data_1[y * 32 + x] == output_data_2[y * 32 + x]); } + + stbir_resize_subpixel(image, 8, 8, 0, output_data_1, 32, 32, 0, STBIR_TYPE_UINT8, 1, 0, STBIR_ALPHA_CHANNEL_NONE, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_CATMULLROM, STBIR_FILTER_CATMULLROM, STBIR_COLORSPACE_LINEAR, NULL, 4, 4, 0, 0); + + for (int x = 0; x < 32; x++) + { + for (int y = 0; y < 32; y++) + STBIR_ASSERT(output_data_1[y * 32 + x] == output_data_2[y * 32 + x]); + } } // test that 1:1 resample using s,t=0,0,1,1 with bilinear produces original image @@ -586,6 +614,9 @@ void test_subpixel_4() stbir_resize_region(image, 8, 8, 0, output, 8, 8, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_TRIANGLE, STBIR_FILTER_TRIANGLE, STBIR_COLORSPACE_LINEAR, &g_context, 0, 0, 1, 1); STBIR_ASSERT(memcmp(image, output, 8 * 8) == 0); + + stbir_resize_subpixel(image, 8, 8, 0, output, 8, 8, 0, STBIR_TYPE_UINT8, 1, STBIR_ALPHA_CHANNEL_NONE, 0, STBIR_EDGE_CLAMP, STBIR_EDGE_CLAMP, STBIR_FILTER_TRIANGLE, STBIR_FILTER_TRIANGLE, STBIR_COLORSPACE_LINEAR, &g_context, 1, 1, 0, 0); + STBIR_ASSERT(memcmp(image, output, 8 * 8) == 0); } static unsigned int image88_int[8][8]; From 5e2d0fd777964e05ac4c8a466b6f507dda6a4483 Mon Sep 17 00:00:00 2001 From: Jorge Rodriguez Date: Tue, 9 Feb 2016 19:40:18 -0800 Subject: [PATCH 4/4] Add support for obtaining the entire kerning table from a font all at once, for use in rendering packed textures offline. --- stb_truetype.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/stb_truetype.h b/stb_truetype.h index bfb1841..ac85727 100644 --- a/stb_truetype.h +++ b/stb_truetype.h @@ -706,6 +706,18 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1); // as above, but takes one or more glyph indices for greater efficiency +typedef struct stbtt_kerningentry +{ + int glyph1; // use stbtt_FindGlyphIndex + int glyph2; + int advance; +} stbtt_kerningentry; + +STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info); +STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length); +// Retrieves a complete list of all of the kerning pairs provided by the font +// stbtt_GetKerningTable never writes more than table_length entries and returns how many entries it did write. +// The table will be sorted by (a.glyph1 == b.glyph1)?(a.glyph2 < b.glyph2):(a.glyph1 < b.glyph1) ////////////////////////////////////////////////////////////////////////////// // @@ -1478,6 +1490,48 @@ STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_inde } } +STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info) +{ + stbtt_uint8 *data = info->data + info->kern; + + // we only look at the first table. it must be 'horizontal' and format 0. + if (!info->kern) + return 0; + if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 + return 0; + if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format + return 0; + + return ttUSHORT(data+10); +} + +STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length) +{ + stbtt_uint8 *data = info->data + info->kern; + int k, length; + + // we only look at the first table. it must be 'horizontal' and format 0. + if (!info->kern) + return 0; + if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 + return 0; + if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format + return 0; + + length = ttUSHORT(data+10); + if (table_length < length) + length = table_length; + + for (k = 0; k < length; k++) + { + table[k].glyph1 = ttUSHORT(data+18+(k*6)); + table[k].glyph2 = ttUSHORT(data+20+(k*6)); + table[k].advance = ttSHORT(data+22+(k*6)); + } + + return length; +} + STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) { stbtt_uint8 *data = info->data + info->kern;