![]() |
Forum Index : Microcontroller and PC projects : PropText for CMM2, simple library for proportional text output
Page 1 of 2 ![]() ![]() |
|||||
Author | Message | ||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi, I have put on my GitHub very simple library for outputting of proportional text. It can be used with either built-in or user fonts on CMM2, simply call text.PROP instead of TEXT command... The best use case can be text adventures (Hi Tom ![]() PropText ![]() Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Hi Jiri, very nice ![]() Best wishes, Tom Edited 2021-07-12 00:24 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
An alternative if you are willing to pre-prepare the font: https://www.thebackshed.com/forum/ViewTopic.php?TID=12021&P=1#145429 Jim VK7JH MMedit |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi Jim, yes, this was also my first thought to extend SimplEd and generate the data for the font. It's nice implementation, but it has (from my point of view) just one plus and more minuses: + speed on init (but it can be also massive improved with CSUB) - can't be used universally for existing fonts - in your implementation with just width, you can't use font as monospaced (TEXT and PRINT commands) when needed (I'm using also offsets...) Right now I would like just improve the initialization speed and to add some PRINT-like SUB, so it can be used more wide... Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Fonts 1 to 7 don't change (potentially dangerous assumption) so perhaps you could pre-measure character width and offset and store those strings in the INC file. Since strings can't be stored in a program with ascii less than 32 (?) or greater than 127, you would need to add an offset to each value. Visit Vegipete's *Mite Library for cool programs. |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
![]() Thanks! I think this is a valuable addition. Regards Michael causality ≠ correlation ≠ coincidence |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi Pete, yes, that's good idea. And for width + offset of built-in fonts is enough 50, so it can be easily put to ASCII. For the potentially dangerous assumption: I will initialise strings with precalculated values, but it can be recalculated with the SUB call anytime later... Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi all, I have updated this library to version 0.02: massive speedup because of precalculation of offsets and widths of built-in fonts (thanks Pete ![]() PRINT like commands: print.PROP(txt$), printLn.PROP(txt$) and wrap.PROP(txt$) all can be mixed with standard PRINT, they use just strings as parameter, last one is word wrapped (can be useful) color.PROP(front%, back%) is like COLOR, but sets parallel intern variables (because I can't read the environment), so use simply this instead of COLOR font.PROP(fnt%) the same for FONT Enjoy! ![]() Edited 2021-07-16 07:36 by jirsoft Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Fonts 1, 6 and 7 can't be changed in a program but the other builtin ones can be substituted. Jim VK7JH MMedit |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
How weird that the wrap.PROP sample resulted in that vertical gap in the text. For your next trick, could you force the printed line of (wrapped) text to be a specific number of pixels wide? Then a column of text would be left AND right justified. Visit Vegipete's *Mite Library for cool programs. |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
Variable-width spaces to right and left justify proportional text--I did that back in 1982--in Fortran. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
I think this is just because of repeated text else it will not happen (hopefully ![]() I can, but I need to study the typography a little bit... When you can fit more words into set space, it's OK, because you can do it by changing of inter-word spaces. When you fit just one word, can be adjusted inter-char spaces and it looks UGLY ![]() Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Added justify.PROP(txt$, txtWidth%, dx%)...full jutified left and right word wrapped proportional text with size txtWidth% written to offset dx% Also added one parameter to print.Prop and printLn.Prop: print.PROP(txt$, addSpace$)...prints proportional txt$ on current position, wraps character to next line, without line feed If the string addSpace$ is not empty, then to N-th SPACE (" ") in txt$ is added PX pixels, where PX=ASC(MID$(addSpace$, N, 1))print.PROP(txt$, addSpace$) Usually when the text will be full justified, should be also possibly hyphenated - this wii bring massive amount of work, which I don't think make sense. So if the word not fit into set space, then is simply printed out (and will be wider), in the code is prepared ERROR for this situation when needed. I'm also not adjust inter-letter space, as I don't like it and inter-word space could be just expanded not compressed (again, when used not so nice and code is much simpler)... Enjoy! ![]() Edited 2021-07-18 00:35 by jirsoft Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Then can be simply called initFont.PROP(font%) for the specific font after the substitution and it will work OK again... Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
Full justified proportional text on the CMM2--a decidedly non-trivial task--nice. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
knivd![]() Regular Member ![]() Joined: 07/09/2014 Location: United KingdomPosts: 72 |
You could have used the drawChar() function from my C interpreter. It is quite simple and natively supports proportional fonts. Available on Github: https://github.com/knivd/C.impl/blob/main/RIDE/graphics.c |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Maybe I'm wrong, but I don't see any intersections between you code and PropText library... Your code is maybe superior to mine, but it simply outputs text in your special formatted font. They are many such routines and they can for sure be easily adapted to MMBasic, but: 1. I need to rewrite it from C (that I hate or at least dislike) 2. Need to use some special fonts The target for PropText library is totally different: 1. use standard fonts on CMM2, without modification. Those fonts could be either taken directly from FW, or edited/imported direct on CMM2 (SimplEd) or converted/download from internet... (FontTweak etc.) 2. calculate offsets and widths from those fonts and use them as proportional ones 3. because the points 1 and 2, you can mix proportional and fixed-size fonts, I'm using TEXT command for outputting one char But anyway thanks for this offer and for your interpreter as whole. For somebody who likes the C-like languages it's very nice and useful work ![]() Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
knivd![]() Regular Member ![]() Joined: 07/09/2014 Location: United KingdomPosts: 72 |
1. use standard fonts on CMM2, without modification. Those fonts could be either taken directly from FW, or edited/imported direct on CMM2 (SimplEd) or converted/download from internet... (FontTweak etc.) Oh, sorry. I must have misunderstood the goal |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi all, PropText library was updated to v0.04. Main news are support for TAB and LF charecters in print.PROP command, because of it printLn.PROP is simpler now and it was added command tab.PROP(t%), where with t% are set TAB positions to every t% pixels. I have added Test2.BAS for test... Enjoy! ![]() Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
Hi all, in v0.05 I have added justifyLine.PROP SUB, that works similary to justify.PROP, but prints out just ONE line and returns in txt$ non printed rest of text. Enjoy! Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
Page 1 of 2 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |