? CHRVEC_2 ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

CHRVEC_2

Submitted
Updated
Author
MZ952
Public Key
53KK33LY
Min. Compat.
All
Rating
6 votes
Description DRAWTEXT StartX, StartY, EndX, EndY, Text string, Color code Fills a rectangular space with vector-drawn text. (Not quite the same as GPUTCHR, which uses scale factors as arguments.) The new key contains the DEF block for drawing text, the vector data of the default font, and the algorithm used to create the vector data. You can use the algorithm to create your own font data to use with this. You can italicize, strike, and underline by introducing [I/]...[/I], [S/]...[/S], and [U/]...[/U] within your text. Example, DRAWTEXT 5,5,60,10,"[U/]Hello, world![/U]",#WHITE. You can also use any combination of strikes, italics, and underlines: DRAWTEXT 5,5,150,10,"[I/][S/][U/]Striked Underlined Italics![U/][/S][/I]",#WHITE. Compared to version 1, version 2 uses an entirely different algorithm to vectorize the text. It draws using a lot less lines and the data loaded into the slot is a lot more compact. It covers all characters up to CHR 65535 and occupies ~0.3 MB. Instructions Running CHRVEC_2 produces the example. You can copy the def block to your own code, but just remember to bring along the global variable CHRVECSLOT and its associated code, as well as CHRVEC.DAT (or your own created .DAT file) to your project folder. Changing CHRVECSLOT changes what slot the data is loaded into.
Categories
Keywords
23 Comment(s) snail_ snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements Could it be possible to tweak the generator to take a font GRP of any size? Primarily I want to try generating a font using the BIG 16x16 font (theoretically it would be higher quality) but all of my hacking of the generator just produces broken output. Clearly both the generator and the draw function rely on the font source being an 8x8 bitmap, which is unexpected. MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Hmm yeah, this would be great. Some things will have to be modified to use BIG font, mainly how the data is encoded. The drawing function can pretty much stay as it is. What I think I'll have to do is introduce a flag for either 8x8 or 16x16 font. I'll be back with an updated key. MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Okay, DF43EKD Let me know if it actually works. I expect things like underlining and striking to be wonky, I'll have to fix those. snail_ snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements For potential future-proofing of whatever weird font or SB implementation there is, you should just store a number in the font that says what the source font width is. It is definitely possible to load a font of a variable size (I managed it in my edit) but I didn't understand the algorithm enough to fix it lol MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Yeah, I'm definitely considering that, variable M x N font size is what I'd like. I've considered writing a whole set of functions in the past that redefined SB's font definitions, externally of course. So, for example, you could proceed linearly with CHR$(I) and never run into a CHR$(1) kind of blank character. I don't understand the logic behind how SmileBASIC assembled their font table, but it all seems so damn needless to me. Anyway, yeah, I don't like being constrained by SB's wonky setup and this CHRVEC thing I made a while ago was a step in that direction. Also, if the thing worked, would you mind making a key to the generated BIG font? (Or does there exist somewhere on this site the GRP BIG font page?) snail_ snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements The CHR$(1)s are just what happens when a unicode character doesn't have an associated glyph in the font (which is actually U+FFFD � REPLACEMENT CHARACTER.) The character encoding is 16 bits (65536 codepoints) but a GRP can only hold 4096 8x8 cells so they just had to shove it all in somehow. Pretty much every undefined character in SB is some weird unicode character they didn't have room for, or a nonprinting/control character. MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Oh that makes sense. Guess I just needed it explained a certain way, haha. Ah well, my point is still that a custom font definition template could be made for custom characters, i.e., not every character needs to be some constant N x N square, but variably M x N, and we could store and use a lot more than 4096 characters in a DATA list. This is a while down the road though because I have no ambition to make it yet. Maybe when SB4 rolls around... MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies There's an typo in the code. I'll update the key later, but if you want to fix it, replace all instances of "1:CHR1" with "1:@CHR1". 12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself I think this is the longest I've ever seen it take for a program to compile in SB (~7 seconds!) MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Wdym? Are you running the O3DS? Takes negligible time for N3DS. 12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself On n3ds it's a lot less (still extremely long, though) MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Yeah, but it's only a one and done sort of thing. I'm surprised it's so long on the O3DS though. Reminds me that I need to do some O3DS testing on my stuff. 12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Why don't you store the data in an actual DAT file? What I would do is create 3 arrays: DATA#[] holds all the data START%[char] is the position in DATA% where that character's data starts LENGTH%[char] is the length of the data for that character (start/length could be a 2D array) (and you could probably multiply all the coordinates by 8, so you can store them as integers instead of floats) MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Because loading the DAT file would take up a lot of space. I think it's like 2M bytes or something. For my purposes, it's extremely impractical. I need every byte of RAM I can get. I guess if you need every PRG slot you can get, you could DIM a bunch of arrays and load them all in the right order. Instead of restoring at a label, the routine could just read the VAR directly. Should be simple to fix if you need it. MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Hmm. Yeah, that could be done. LENGTH% is redundant because the length can be the first value off the stack, which it is. But, because it's impossible to figure out the graphical length of a string of characters (without observing it after the fact), LENGTH% maybe could store the unit length of each character, which you would then add up and multiply by the scale factor to get the graphical length, which would be useful for doing things like fitting the text inside text boxes. Edit: the function could maybe even use that info to backtrack and fill an x,y,u,v space with text. Might be more useful. 12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself (the reason for storing LENGTH% separately is so you can use an integer array and save space) If you really want to save space, you could store each value using 6 bits or something (they seem to all be multiples of 1/8, from 0 to 7.75), by multiplying them by 8 (giving a range of 0 to 62) You could also fit the data on one of the graphics pages, probably MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Ooh yeah, but saving space is only half the problem, really. It's also a trade of fast recall. Restoring at labels and accessing VARs is quick enough, but you also want to access and draw the information relatively quickly. Doing clever bit manipulation takes time, and bitwise operations seem notoriously slow. Also, yeah, the 1/8 thing was handy, but it really doesn't need to be that way. The integer part of the value stores the Y component, and the fractional part the X (X=FracPart*8). Could make them two separate values or just Y*8+X the thing and do X=N MOD 8, Y=N DIV 8. Might actually be faster too, idk. But if you're going the array route, it would be better to DIM an integer array. MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies How do you think the data will fit on the graphics page? GSPOIT calls don't seem too slow. 12Me21 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself I'm sure it's faster to use bitwise operations than it is to calculate the integer/fractional parts of a number. You could use RGBREAD to split an integer into 4 bytes, then split each of those into X and Y (this would use only ~0.2MB of RAM) MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies How do you store it on the graphics page though? The graphics page doesn't care for the alpha channel unless it's 255. I admit I don't know much about the whole color conversion stuff, but it seems that storing on the graphics page is a bit lossy. It stores what looks like 5? bits for each channel, instead of 8. RGBREAD handles the whole 8 bits though, so it seems like a color conversion thing. I'm actually interested in learning this because it opens a door I really hadn't considered. I mean, 512x512 and like what, 6 pages. Holy crap. If I could make a function that could manipulate data on the graphics pages at decent speeds, that would be super useful. MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies I think I'll also publish a second key on this page to the program I used to generate the data, so other fonts and stuff can be used with this. Or just update the key instead. snail_ snail_ QSP Contest 1 Contest Participant I participated in the first SmileBASIC Source QSP Contest! Helper Received for being very helpful around SmileBASIC Source Achievements Amazing Contributor Someone thinks I'm an awesome person who has done so much for the community! Achievements I take it your vectorizing algorithm was to make straight strokes between adjacent pixels and connect the segments where it's more efficient? MZ952 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Drawing I like to draw! Hobbies Reading I like to read books! Hobbies Yeah basically. But, it didn't connect all adjacent segments, because sometimes that would make certain characters appear wonky. I think I let it connect segments up until a junction or something. Edit: oh wait, this one might be the set without the condensing. I think my reasoning was that by condensing I was losing detail on upscaled text. Huh. I see now that there are only a few edge cases to correct for. I might be back with an update.