Page 7 of 7

Re: Font library (Rasterworks)

Posted: Sun Sep 27, 2020 5:04 pm
by maxcodehack
Допустим есть код

Code: Select all

	char* text = "HELLO!";
void *buf = malloc(768*256*3 * sizeof(char));
	*((int*)buf) = 768;
	*((int*)buf+1) = 256;
	memset((char*)buf+8, (char)-1, 768*256*3);
	int len = countUTF8Z(text, -1);
	drawText(buf, 0, 0, text, len, 0xFFFF0000, 0x08031428);
Он работает, но фон белый
И где тут заполняется буфер цветом?
Если он тут не заполняется, как его тогда вообще заполнить?
PS это Си

Re: Font library (Rasterworks)

Posted: Sun Sep 27, 2020 6:18 pm
by dunkaist
maxcodehack wrote:И где тут заполняется буфер цветом?

Code: Select all

memset((char*)buf+8, (char)-1, 768*256*3);
BTW, this memset writes beyond the buffer. Check the length.

Re: Font library (Rasterworks)

Posted: Sun Sep 27, 2020 6:23 pm
by maxcodehack
I need to write
memset((char*)buf+8, (char)-1, 768*256*3 - sizeof(char));
?
I get this code from C_Layer

Re: Font library (Rasterworks)

Posted: Sun Sep 27, 2020 7:01 pm
by dunkaist
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.

Re: Font library (Rasterworks)

Posted: Sun Sep 27, 2020 7:07 pm
by maxcodehack
I get this code from C_Layer

Re: Font library (Rasterworks)

Posted: Sun Sep 27, 2020 8:46 pm
by dunkaist
  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.

Re: Rasterworks

Posted: Sat May 13, 2023 8:05 pm
by qullarwee
Pathoswithin wrote: Mon Nov 16, 2015 1:34 pm Добавил выравнивание по центру или справа с учётом указаной координаты Х (или двух). Сделал автоматическое сужение строки, если она не вписывается в изображение или указаную область. Функция возвращает итоговые ширину символа и координату начала текста.
Или я чего-то не понимаю, или... Буфер заканчивается ровно перед скроллбаром, но RasterWorks все равно сужает символ, хотя он туда бы влез.
mar.png
mar.png (1.4 KiB)
Viewed 12649 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);
Спасибо.

Re: Font library (Rasterworks)

Posted: Sun May 14, 2023 6:50 pm
by Pathoswithin
Так падажжи...
Что выдаёт render_style_mask?
И... << 48 это же сдвиг на 48? Там всего 32 бита.

Re: Font library (Rasterworks)

Posted: Sun May 14, 2023 7:58 pm
by qullarwee
Упс.. Должно быть так:

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);

Re: Font library (Rasterworks)

Posted: Mon May 15, 2023 6:13 pm
by Pathoswithin
Глянул код. Действительно, ширина строки рассчитывается на символ больше. А вот почему я так сделал уже не помню...
Может, из-за курсива.

Re: Font library (Rasterworks)

Posted: Tue May 16, 2023 10:42 am
by qullarwee
Так и оставите, или поменяете потом как нибудь?

Re: Font library (Rasterworks)

Posted: Tue May 16, 2023 5:20 pm
by Pathoswithin
Да оставлю пожалуй, раз зачем-то сделал. Иначе как минимум курсив будет вылазить с другой стороны, а то и падать с ошибкой. Ничего не мешает выводить на экран не всю ширину буфера.