Skip to content

Commit

Permalink
fixup! feat(pandagl): calculate baseline position based on Ascender a…
Browse files Browse the repository at this point in the history
…nd BBox
  • Loading branch information
lc-soft committed Feb 11, 2024
1 parent 93f68dc commit 7644829
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
12 changes: 12 additions & 0 deletions lib/pandagl/src/font/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ int pd_canvas_mix_font_bitmap(pd_canvas_t *graph, pd_pos_t pos,
pd_canvas_t write_slot;
pd_rect_t r_rect, w_rect;

if (pos.x > 0) {
printf("pos.x\n");
}
if (pos.y > 0) {
printf("pos.y=%d\n", pos.y);
}
if (pos.x > (int)graph->width) {
printf("width\n");
}
if (pos.y > (int)graph->height) {
printf("height=%u\n", graph->height);
}
if (pos.x > (int)graph->width || pos.y > (int)graph->height) {
return -2;
}
Expand Down
31 changes: 12 additions & 19 deletions lib/pandagl/src/font/inconsolata.c
Original file line number Diff line number Diff line change
Expand Up @@ -7593,18 +7593,19 @@ int pd_render_inconsolata_font_bitmap(pd_font_bitmap_t *bmp, unsigned ch, int si
if (size < 12) {
return -1;
}
bmp->metrics.hori_advance = (int)(size / 2.0 + 0.5);
bmp->metrics.vert_advance = size;
bmp->metrics.bbox_width = bmp->metrics.hori_advance;
bmp->metrics.bbox_height = size;
bmp->metrics.ascender = size * 4 / 5;
bmp->rows = size;
bmp->width = bmp->metrics.hori_advance;
bmp->buffer = calloc(bmp->rows*bmp->width, sizeof(uint8_t));
bmp->pitch = bmp->width;
bmp->top = size * 4 / 5;
bmp->left = 0;
/* 不在范围内的字符都用框框表示 */
if (ch < ' ' || ch > '~' || size > 18) {
bmp->metrics.hori_advance = (int)(size / 2.0 + 0.5);
bmp->metrics.vert_advance = size;
bmp->metrics.bbox_height = size;
bmp->metrics.bbox_width = bmp->metrics.hori_advance;
bmp->rows = size;
bmp->width = bmp->metrics.hori_advance;
bmp->buffer = calloc(bmp->rows * bmp->width, 1);
bmp->pitch = bmp->width;
bmp->top = size * 4 / 5;
bmp->left = 0;
j = (bmp->rows - 1) * bmp->width;
for (i = 0; i < bmp->width; ++i, ++j) {
bmp->buffer[i] = 255;
Expand All @@ -7623,12 +7624,6 @@ int pd_render_inconsolata_font_bitmap(pd_font_bitmap_t *bmp, unsigned ch, int si
}
/* 空格就直接填充空白 */
if (ch == ' ') {
bmp->metrics.hori_advance = (int)(size / 2.0 + 0.5);
bmp->metrics.vert_advance = size;
bmp->rows = size;
bmp->width = bmp->metrics.hori_advance;
bmp->buffer = calloc(bmp->rows*bmp->width, 1);
bmp->pitch = bmp->width;
bmp->top = 0;
bmp->left = 0;
return 0;
Expand All @@ -7638,8 +7633,6 @@ int pd_render_inconsolata_font_bitmap(pd_font_bitmap_t *bmp, unsigned ch, int si
*bmp = pd_inconsolata_font_bitmap_info[i][j];
j = *(ptr = (int*)&bmp->buffer);
byte_ptr = &pd_inconsolata_font_bitmap[i][j];
size = sizeof(unsigned char)*bmp->width*bmp->rows;
bmp->buffer = (uint8_t*)malloc(size);
memcpy(bmp->buffer, byte_ptr, size);
memcpy(bmp->buffer, byte_ptr, sizeof(uint8_t)*bmp->width*bmp->rows);
return 0;
}
2 changes: 1 addition & 1 deletion tests/run_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

int main(int argc, char **argv)
{
logger_set_level(LOGGER_LEVEL_ERROR);
logger_set_level(LOGGER_LEVEL_ALL);
ctest_describe("test settings", test_settings);
ctest_describe("test thread", test_thread);
ctest_describe("test font load", test_font_load);
Expand Down
1 change: 1 addition & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ target("lcui_tests")
table.insert(argv, "valgrind")
table.insert(argv, "--leak-check=full")
table.insert(argv, "--error-exitcode=42")
table.insert(argv, "--num-callers=20")
table.insert(argv, target:targetfile())
os.execv("sudo", argv)
end
Expand Down

0 comments on commit 7644829

Please sign in to comment.