Font library (Rasterworks)

Discussing libraries simplifying applications development
  • Я сделаль. Библиотека экспортирует две функции. Первая считает количество символов в UTF8Z строке. Вторая рисует текст на 24-битном изображении, размер шрифта произвольный по вертикали и горизонтали, поддерживается жирный, курсив, подчёркнутый, перечёркнутый и полупрозрачность.
    Attachments
    RasterWorks.asm (7.53 KiB)
    Downloaded 305 times
    test.asm (1.27 KiB)
    Downloaded 314 times
  • The program has been tested and works.
    A screenshot with a typical english pangram:
    rasterworks.png
    rasterworks.png (23.9 KiB)
    Viewed 9228 times
    Comments:
    - "Number of characters" as an input to the function - a good idea.
    - Alpha channel support for font color - I don't see the point of it. (But if it can be implemented at minimal cost, so be it.)
    - Parameters: Input of width and height of the font is just weird. Ideally, I just want to input the em height of the font, and let the library worry about it.
    - Size/speed: It seems the library has traded speed for size by using the kernel's internal font. The performance still seems acceptable at this point. (Perhaps at a later time, the system font can be placed in a shared read-only memory by the kernel, so that the library can work directly with the font data.)
    - CountUTF8Z function - It's not what I wanted :) What I really need is a function that will tell me the width (and height) in pixels of a piece of text, so that I know if it will fit where I want to put it.
    - The library does not take into account the width of the canvas (as seen on the screenshot) - This is not a problem for me, it might even improve the performance of the library a bit.
    "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein
  • Char width may be useful if you want to fit the string onto image, but now you can input 0 for auto width.
    About speed. Notice, that sysfunction 4 is optimized for fast draw to the buffer. Also, notice the scope of calculation bacchanalia in the library itself. Especially after I have added the stringWidth function.
    Attachments
    RasterWorks.asm (7.98 KiB)
    Downloaded 306 times
    char width.PNG
    char width.PNG (8.28 KiB)
    Viewed 9204 times
  • Добавил выравнивание по центру или справа с учётом указаной координаты Х (или двух). Сделал автоматическое сужение строки, если она не вписывается в изображение или указаную область. Функция возвращает итоговые ширину символа и координату начала текста.
    Attachments
    RasterWorks.asm (8.89 KiB)
    Downloaded 298 times
  • Pathoswithin wrote:Добавил выравнивание по центру или справа с учётом указаной координаты Х (или двух). Сделал автоматическое сужение строки, если она не вписывается в изображение или указаную область. Функция возвращает итоговые ширину символа и координату начала текста.
    As much as I appreciate your initiative, this is useless for browser.
    End of text is not essentially the same as width of canvas.

    Also, I still have to process all UTF8 bytes manually to count characters, when not using UTF8Z string.
    As mentioned before in another thread, it makes more sense to provide the number of bytes in buffer rather then number of characters (especially when invalid characters are involved.)
    "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein
  • Yes, this will not help with multiline or sharing string between two canvases, but in other cases 01000000 flag should do the trick. I think, this may be useful for fullwindow canvas.
    Should I add UTF8 character count by bytes? Or maybe, till some key char?
  • Currently, the idea of browser is roughly as follows:
    - Parser creates something which looks like DOM tree (https://en.wikipedia.org/wiki/Document_Object_Model).
    - Pre-renderer calculates page width (at least width of the window, but for example a very wide image can cause the page width to increase.)
    - Pre-renderer calculates position of all objects and stores them in DOM tree.
    - Renderer renders (at least) visible part of the page in the off-screen buffer
    - The visible section of page is drawn (from off-screen) buffer to the window.

    All text between two tags is essentially one object. This text may begin for example in the middle of the screen, and continue on the next line at another position.
    My idea here is to let pre-renderer decide what word will get what coordinates (and markup) and store these values in the text object.
    Last edited by hidnplayr on Tue Nov 17, 2015 11:11 pm, edited 1 time in total.
    "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein
  • Sounds like UTF16 is more convenient for separating a string to words. Anyway, should I add more character count options?
  • UTF8 is convenient because it is most used encoding on the web. Converting UTF8 to UTF16 sounds like a useless step.
    BTW, I don't understand your reasoning about this, I'm not talking about 16bits, but characters separated by spaces...

    And yes, I'd appreciate it if you would replace "character count" with "byte count".
    "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein
  • Byte count? Do you mean count characters by number of bytes, or count bytes till specified symbol (0 or else)?
  • the first.
    "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." Albert Einstein
  • Добавил поддержку 32-битного изображения, рассчёт количества символов в UTF-8 строке по количеству байт и тщательную проверку битых символов.
    Attachments
    RasterWorks.asm (9.36 KiB)
    Downloaded 322 times
  • А можно добавить еще функцию подсчета числа символов в строке, при заданных ширине а пикселях и высоте шрифта?
    to infinity and beyond
  • Добавил.
    Залил код. Для использования осталось включить в сборку.
  • Who is online

    Users browsing this forum: No registered users and 3 guests