|
Format of Text/String |
RmBeer2
Member #16,660
April 2017
|
This's a design problem that I can't solve. Normally a normal text string is made up of a succession of bytes (characters) until ending with byte 0. What I wanted to do here is add some function bytes that would format the text, which is quite useful for formatting text from a simple string of characters. Then i build this list of bytes that can change the format of the text, this bytes only work from 1 to 8 and 11 to 31: General Format: (byte) Format: (byte) The font with the size, since in Allegro both are defined during the loading of the font, and said loaded font can be assigned in the list as an indexed number. The problem of design here is that byte 1,2,3, and 13, can have byte 0 as the function parameter, and continue reading text, which is no longer compatible with the normal text format, which always ends with 0. How would you design the format in a text? My goal is to maintain a function for each control byte, although Im open to suggestions. EDIT ================ The idea of this is mostly to speed up the process of formatting text during rendering and not render as much from the commands or from the text. So you wouldn't have to process so many fragmented texts either. 🌈🌈🌈 🌟 BlackRook WebSite (Only valid from my installer) 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈 Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024! |
Edgar Reynaldo
Major Reynaldo
May 2007
|
If I was doing it, I would use two strings, one for text and the other for format. Since format is variable length and needs to sometime operate on the same index, I would encode everything in a format string or a special format data type. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
amarillion
Member #940
January 2001
|
Could you take some inspiration from UTF-8 to encode the function parameters? Basically you'd spread out the bits of the function parameters. For example, you could encode 12 bits as: 10xxxxxx 10xxxxxx or 18 bits as 10xxxxxx 10xxxxxx 10xxxxxx. It takes a bit of shuffling, but you'd never end up with a zero in the middle of your string. -- |
torhu
Member #2,727
September 2002
|
What is this going to be used for? If fast rendering is the point, you should probably prerender, or adapt to whatever the rendering needs. Which is probably not going to be about parsing anything, but about commands sent to the graphics API. |
RmBeer2
Member #16,660
April 2017
|
@amarillion : I had already thought about it. I have no problem with UTF-8, it is what I intend to use. Nor would I have problems with byte 1 and 2, only if the high nibble is filled with garbage, but this is not the case for byte 3 (Could it be the case of using byte 0 as a letter and a background in black at some point?). For byte 13, bit 7 could be kept active constantly and use the rest of the bits as index , which would only leave 128 fonts available instead of 256. @torhu : Processing will be noticeably easier when rendering occurs as short as possible while reading the text string. Especially for example if you need to read the text over and over again, for example, render the text in multiple lines in case said box (or window) changes size in real time. EDIT ================== This is probably nonsense, and it is better to use chunked texts in memory to speed up the process, but it may be convenient to have the original string in mixed text format. 🌈🌈🌈 🌟 BlackRook WebSite (Only valid from my installer) 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈 Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024! |
Peter Hull
Member #1,136
March 2001
|
If it were me I would take inspiration from ANSI escape codes
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
I still think mixing formatting and text is a bad idea. As soon as you use your new mixed format it automatically becomes incompatible with every other rendering code out there. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
bamccaig
Member #7,536
July 2006
|
A more precise solution is to bind the buffer length and string length into a struct or object. This requires every write to the buffer to update the string length. And then you can store anything without needing to treat anything magical. I think that bstrlib is considered good? No need to reinvent the wheel. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
RmBeer2
Member #16,660
April 2017
|
@bamccaig : I already thought to use ALLEGRO_USTR. I've been planning on doing the final render for formatted multiline text for a long time, but laziness always wins. 🌈🌈🌈 🌟 BlackRook WebSite (Only valid from my installer) 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈 Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024! |
|