Font library (Rasterworks)

Discussing libraries simplifying applications development
  • maxcodehack wrote:И где тут заполняется буфер цветом?

    Code: Select all

    memset((char*)buf+8, (char)-1, 768*256*3);
    BTW, this memset writes beyond the buffer. Check the length.
  • I need to write
    memset((char*)buf+8, (char)-1, 768*256*3 - sizeof(char));
    ?
    I get this code from C_Layer
    Last edited by maxcodehack on Sun Sep 27, 2020 7:52 pm, edited 2 times in total.
  • What is the address of the last byte you allocate via malloc?
    What is the address of the last byte you write to via memset?
    maxcodehack wrote:sizeof(char)
    You can read about sizeof(char) in the C standard draft, 6.5.3.4 The sizeof operator.
  • I get this code from C_Layer
    1. A pixel color is coded as one or more channels.
    2. Each color channel is coded separately according to its depth.
    3. The number of channels and their ordering and depth are collectively called pixel format.
    4. The most common pixel formats have 8-bit channels, e.g. Red, Green, Blue. Hence for such pixel formats one channel occupies one byte.
    5. There is no single standartized way to name pixel formats, e.g. RGB, RGB888, true color and 24bit may refer to the same format.
    6. A convenient way to write colors in text is hex, one of binary-to-text encodings.
    7. Description of drawText function (part of RasterWorks) mentions two pixel formats accepted: 24bpp and 32bpp (bpp -- bits per pixel).
    8. You define the format to use in the last argument of the function, it's 24bpp in your example.
    9. What KolibriOS expects to be 24bpp can be found in description of sf7, it's BBGGRRBBGGRRBBGGRR...
    10. I.e. a byte describing Blue component of the first pixel, a byte describing Green component of the first pixel, a byte describing Red component of the first pixel. Then data of the second and other pixels go.
    11. White color in 24bpp pixel format is Red=255, Green=255, Blue=255. Or, using shorter hex notation, 0xFFFFFF.
    12. (char)-1 in your example is a byte with value 0xFF in hex, read why.
    13. So, the background color in your example is white because memset writes many 0xFF's, which are interpreted as 0xFFFFFF triplets, which mean white pixels.
    14. Description of drawText function says that the first argument is a pointer to the structure of three fields: xSize, ySize, picture.
    15. To allocate enough memory for this structure, calculate its size, which is the sum of the sizes of its fields. It's not always the case, but this time you are lucky.
  • Pathoswithin wrote: Mon Nov 16, 2015 1:34 pm Добавил выравнивание по центру или справа с учётом указаной координаты Х (или двух). Сделал автоматическое сужение строки, если она не вписывается в изображение или указаную область. Функция возвращает итоговые ширину символа и координату начала текста.
    Или я чего-то не понимаю, или... Буфер заканчивается ровно перед скроллбаром, но RasterWorks все равно сужает символ, хотя он туда бы влез.
    mar.png
    mar.png (1.4 KiB)
    Viewed 9866 times
    Код если что такой:

    Code: Select all

    drawText(buf, pen->pos.x, pen->pos.y, text, len, pen->color | 0xFF000000, (render_style_mask(pen) << 48) | 0x030000 | (pen->font_size.x << 16) | pen->font_size.y);
    
    Спасибо.
  • Так падажжи...
    Что выдаёт render_style_mask?
    И... << 48 это же сдвиг на 48? Там всего 32 бита.
  • Упс.. Должно быть так:

    Code: Select all

    drawText(buf, pen->pos.x, pen->pos.y, text, len, pen->color | 0xFF000000, (render_style_mask(pen) << 24) | 0x030000 | (pen->font_size.x << 8) | pen->font_size.y);
    
    Но ошибка не пропала.

    render_style_mask выдает маску стиля (bold, italic):

    Code: Select all

    return pen->style.bold | (pen->style.italic << 1);
    
  • Глянул код. Действительно, ширина строки рассчитывается на символ больше. А вот почему я так сделал уже не помню...
    Может, из-за курсива.
  • Так и оставите, или поменяете потом как нибудь?
  • Да оставлю пожалуй, раз зачем-то сделал. Иначе как минимум курсив будет вылазить с другой стороны, а то и падать с ошибкой. Ничего не мешает выводить на экран не всю ширину буфера.
  • Who is online

    Users browsing this forum: No registered users and 6 guests