Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fonts do not render correctly or at all #2

Closed
CHiPs44 opened this issue May 12, 2021 · 11 comments
Closed

Some fonts do not render correctly or at all #2

CHiPs44 opened this issue May 12, 2021 · 11 comments

Comments

@CHiPs44
Copy link

CHiPs44 commented May 12, 2021

I saw that I couldn't render text with the unscii-8-fantasy font in my Pico VGA HAGL HAL, but it worked with X11 font8x13.

To verify it doesn't come from my HAL, I made a little example outputting text to GD HAGL HAL (by duplicating and adapting palette.c):

/*

MIT No Attribution

Copyright (c) 2018-2021 Mika Tuupola

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

-cut-

SPDX-License-Identifier: MIT-0

*/

#include <time.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>

#include "hagl_hal.h"
#include "hagl.h"
#include "external/embedded-fonts/X11/include/font8x13.h"
#include "external/embedded-fonts/X11/include/font10x20.h"
#include "external/embedded-fonts/misc/viznut/include/unscii-8-fantasy.h"

int main()
{
    color_t color1 = hagl_color(128, 255, 255);
    color_t color2 = hagl_color(255, 128, 255);
    color_t color3 = hagl_color(255, 255, 128);
    uint16_t x, y;
    clock_t start, end;
    double time_spent;
    size_t bytes;

    wchar_t *text = L"The Quick Brown Fox Jumps Over The Lazy Dog 0123456789 Times!";

    hagl_init();
    start = clock();

    x = (DISPLAY_WIDTH  / 2) - wcslen(text) * 8 / 2;
    y = (DISPLAY_HEIGHT / 2) - 13 * 4;
    hagl_draw_rectangle(x - 2, y - 2, x + wcslen(text) * 8 + 2, y + 13 + 2, color1);
    hagl_put_text(text, x, y, color1, font8x13);

    x = (DISPLAY_WIDTH  / 2) - wcslen(text) * 10 / 2;
    y = (DISPLAY_HEIGHT / 2) - 20 / 2;
    hagl_draw_rectangle(x - 2, y - 2, x + wcslen(text) * 10 + 2, y + 20 + 2, color2);
    hagl_put_text(text, x, y, color2, font10x20);

    x = (DISPLAY_WIDTH  / 2) - wcslen(text) * 8 / 2;
    y = (DISPLAY_HEIGHT / 2) + 8 * 4;
    hagl_draw_rectangle(x - 2, y - 2, x + wcslen(text) * 8 + 2, y + 8 + 2, color3);
    hagl_put_text(text, x, y, color3, unscii_8_fantasy);

    end = clock();
    time_spent = (double)(end - start) / CLOCKS_PER_SEC;
    bytes = hagl_flush();
    printf("\nGenerated %zu bytes in %g seconds.\n\n", bytes, time_spent);
    hagl_close();

    return 0;
}

The result is below:

  • font8x13 OK
  • font10x20 displays garbage
  • unscii_8_fantasy doesn't show at all

hagl

@tuupola
Copy link
Owner

tuupola commented May 13, 2021

Looking at the automatically generated preview images you are correct the big fonts seem to have problems. However unscii seems to render correctly. I did used a quick and dirty fontx2png command line tool to render them so the problem might be in hagl_put_text() or hagl_put_char(). Will look into this soonish.

@ronangaillard
Copy link

Hi,

Maybe this will fix your issue : tuupola/fontx_tools#1

@tuupola
Copy link
Owner

tuupola commented Oct 18, 2021

At least the patch fixed the automatically generated preview images.

@BobDNA
Copy link

BobDNA commented Oct 28, 2021

Also, all of ISO fonts shifted to the right one byte.
Examples tested on TTGO T-DISPLAY, ESP-IDF 4.3.1, Hagl master, esp_mipi

hagl_put_text(u"ABCD", 0, 0, COLOR_GREEN, font5x7_ISO8859_1); ----> Show "BCDE" on display
hagl_put_text(u"ABCD", 0, 50, COLOR_GREEN, font5x7); -----> Show "ABCD" on display , this is OK.

hagl_put_text(u"ABCD", 0, 0, COLOR_GREEN, font9x18B_ISO8859_1); ----> Show "BCDE" on display
hagl_put_text(u"ABCD", 0, 50, COLOR_GREEN, font9x18); -----> Show "ABCD" on display , this is OK.

@ronangaillard
Copy link

Is this a new issue or did this happen before ?

@BobDNA
Copy link

BobDNA commented Oct 29, 2021

It happened before.

@tuupola
Copy link
Owner

tuupola commented Nov 3, 2021

I just did a quick test with SDL2 and there is off by one error somewhere.

hagl_put_text(L"abcABC", 10, 120, green, font9x18B_ISO8859_1);

displays bcdBCD on screen and

hagl_put_text(L"`ab@AB", 10, 120, green, font9x18B_ISO8859_1);

displays abcABC on screen. Not sure yet whether the problem is how the ISO variants are generated or is it in HAGL rendering code.

@tuupola
Copy link
Owner

tuupola commented Nov 3, 2021

I think it is the bdf2fontx tool. The resulting fnt file seems to miss 0x00 and 0x01 characters. The first character in the fnt file is 0x02 but even that is off by one and it is actually numbered as 0x01.

@tuupola
Copy link
Owner

tuupola commented Nov 3, 2021

Culprit seems to be the following line which causes the off by one error. Will investigate more tomorrow.

https://github.com/tuupola/fontx_tools/blob/master/src/bdf2fontx.c#L283

@tuupola
Copy link
Owner

tuupola commented Nov 8, 2021

The off by one error should be fixed with ISO fonts (see #3). I did not test them all but I did test five random fonts manually and they were ok.

Not to self: I really need to do a proper rewrite of the conversion tools.

@tuupola tuupola closed this as completed May 26, 2022
@CHiPs44
Copy link
Author

CHiPs44 commented Oct 16, 2022

Hello,

I finally took some time to work on the RPi Pico VGA board HAL, and still got no display for unscii font.

So I modernized my test program to make it work with latest HAGL, see https://github.com/CHiPs44/hagl_gd/blob/0e189ddd84861a1a61db5cfa785f697e2c5d5392/example/hagl_font_test.c, and got the same issues.

Mandelbroot & palette work fine on my Ubuntu 22.04 machine, so I'm rather confident with my setup.

hagl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants