Render a monospaced bitmap font from image

1

Input is in this format:

image fontwidth fontheight rowwidth xoffset yoffset xgap ygap non-existent charstart thetextitself

thetextitself: The text that should be rendered from the image.

image: The image filename. Implementation may vary; it could be either the filename from your computer, an image URL, or something else, as long as it's possible to use any picture.

fontwidth, fontheight: self explanatory

rowwidth: How many characters a row of characters contains in the image?

xoffset: The starting x coordinate of the character table.

yoffset: The starting y coordinate of the character table.

xgap: The horizontal gap between characters.

ygap: The vertical gap between characters.

non-existent: The character code for the character rendered if the character is (fully or partially) outside the image, hexadecimal of any length.

charstart: The hexadecimal first character any length.

thetextitself: The text to render. The previous parameters are used to find the characters. It's at the end, so that any space included doesn't clash with the next parameter.

So, the appropriate input for this image https://i.imgur.com/0gZQ1eQ.png would be:

https://i.imgur.com/0gZQ1eQ.png 7 11 8 3 5 2 1 00000000 00000 <Test>

which would render as https://i.imgur.com/FxskU9Q.png. The exact pixel colors are preserved.

Word wrapping is not needed, but if you use word wrapping, there must be at least 16 characters of horizontal space.

-10 bytes if the code renders tabs (U+0009) correctly (jumps to the next position divisible by 8).

-10 bytes if the code renders Microsoft Windows newlines (U+000D000A) correctly (extends the output image height and jumps to the beginning of the last line).

-10 bytes if the code interprets the combining and zero–width characters as zero–width, but combining characters overlapping their glyph to the next (or the previous; I don't know how Unicode combining characters work) character.

The code must support Unicode characters up to U+FFFF. If the code allows for characters above, -10 bytes.

It's code-golf, so the lowest code size wins.

Piotr Grochowski

Posted 2018-04-15T06:20:59.220

Reputation: 17

Question was closed 2018-04-15T11:55:07.493

5You may want to get rid of the bonuses - effectively, you're asking people to make 2^4 different programs and only post the shortest. – Sanchises – 2018-04-15T07:36:23.117

What are the units for fontwidth, xoffset xgap etc? Are there any bounds on their range? If not, how should text be displayed with e.g. fondwith=2 and fontheight=100? – Laikoni – 2018-04-15T08:02:12.610

The units are in pixels, and there should be no bounds on their range, aside from limitations like the fact that a byte can only go up to 255. – Piotr Grochowski – 2018-04-15T08:33:16.703

Embedding is done. – Piotr Grochowski – 2018-04-15T08:35:22.313

This needs more clarification. 1 Get rid of the bonuses please. See Sanchises' comment above. 2 Which image formats must be supported? – user202729 – 2018-04-16T05:52:36.980

One of the following formats must be supported: bmp, png. – Piotr Grochowski – 2018-04-16T17:00:11.967

No answers