-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I overwrite a character with another character, using a transparent font #335
Comments
Nice questions. Let me try to clarify some things. First: the availability of special glyphs is not related or restricted to transparent fonts. It is more "accidently" that i did this for t fonts only. The second point is: u8g2_font_6x10_mf also exists as a transparent version: u8g2_font_6x10_tf as you can see here: https://github.com/olikraus/u8g2/wiki/fntgrpx11#6x10 And now, third: There is NO DIFFERENCE between transparent and none-transparent fonts. It is more a kind of a "suits better" for none-transparency. Or with other words: If you want to use transparent fonts, you can use ALL fonts (whether they are marked as t or m does not matter). The transparency of fonts is ONLY defined via the setFontMode(1) command.
So this will do a similar effect like the XBM Bitmap example. |
Thanks for the quick reply. Yes, after more testing I see what you mean, sort of, although, I do not want transparency. I will need to do some more testing to verify. However, there is an immediate bug, when using Using the code below, and a different font, to better illustrate the issue:
If you use
|
I am not quite sure about your problem. Just use the "m" (or "h") version of the font. In fact the only purpose of the "m" font is to avoid the artefacts which had been described by you under 2. ah, but wait, now you want Greek Omega, which is only avilable as transparent font. But you need the none-transparent version. Got it. Can you tell me the font name and the unicode glyph range you require as "m" (or "h") version of the font? I can provide information how to generate these fonts by yourself. |
Hmmm... I still don't fully understand why the transparent fonts draw partially correctly below the ascent line, but not above. I guess I need to examine the font files more closely, when I get time. But yes, I can use a "m" font and After going through all of the font reference pages, I have found a suitable font, Related to making my own font, but going slightly off -topic for a moment... I would like to be able to print an omega as part of a string, in order to display resistance. However, I don't seem to be able to just print the Omega symbol using
I seem to have to use
Is that true? Why is that? Is it because the character code is greater than 255 (or 128) and the print statement can't use high code numbers? I would like to be able to If I can not use Is the method to create a font not in the reference guide already? Also, is there a programmatical way of converting the transparent "t" files to non-transparent "m" or "h" files? If I could automate this process, then that would be great. Or would you not be interested in generating them and adding them to U8g2? It would be nice if all fonts had both transparent and non-transparent versions available. Looking at the symbols fonts, these are the transparent fonts that include an Omega: From Unifont
From X11:
From Old School PC Fonts (v2.1.x):
From NBP:
From cu12:
|
Yes, excatly, you tell me the font style (e.g. u8g2_font_6x12) and i will generate the corresponding u8g2_font_6x12_m_symbols font (note the "m" inside). The point is this: If i generate u8g2_font_6x12_m_symbols then it willl for sure include the omega, but maybe it will also include other chars which are not required for you, wasting space in your controller. So the question is: Is there a specific set of glyphs which you need in your application? You can tell me a list of glyph ranges (unicode positions). Of course i can just create u8g2_font_6x12_m_symbols if you are fine with this.
Yes, this will work, because drawGlyph expects the unicode number.
Assuming you have enable UTF-8 for print, this will still not work, because print (and drawStr()) will expect UTF-8 encoding. For the snowman code 0x2126, the corresponding UTF-8 sequence is E2 84 A6,
EDIT: drawStr() will not work as mentioned above, instead use drawUTF8() You can use this page to convert the unicode number to the UTF-8 sequence: However the question is, why do you make things so complicated? Arduino IDE and most other editors support UTF-8. So any given char is automatically converted to UTF-8. Moreover the c-compiler also interprets UTF-8 correctly, so you can simply write in the Arduino IDE lcd.print("Ω"); Provided, that the Ω is present in the current font, this will be printing the omega as expected on the GLCD. Ok, maybe because U8g2 is the only library which supports UTF-8, so it might be surprising that things are that simple, but actually i spent a lot of time to implement the UTF-8 decoding algorithms and all that unicode handling. I am happy that you ask, but acutally, things should appear to be simple for the user of u8g2.
No, but it is mentioned in the FAQ (https://github.com/olikraus/u8g2/blob/master/doc/faq.txt#L173). Actually i did not found time to do a proper documentation for this.
No, it is part of the conversion process. Actually there is one source, from which the different variants are generated. For example there is 6x10.bdf: It includes everything. From that single bdf file, the u8g2 fonts are generated. It is actually a commandline option of "bdfconv" which decides for type "t" or "m" or "h" fonts. 6x10.bdf --> bdfconv "some commandline options" --> u8g2_font_6x12_m_symbols The purpose of the commandline options is to:
It is already fully automatic. All the pages in the u8g2 wiki and all the fonts are generated .
Agree, but currently the font file is already 11MB big. I guess it would exceed 20MB if I provide the m file also for each of the fonts. In fact i was waiting for user feedbacks on this. And still I would only generate the full m font for selected fonts which you could tell me. |
Many thanks for the links and info. Very very interesting. Regarding the specific glyph set, that is very kind of you to offer - In addition to the usual roman letters and numbers, I only need degree (°) and Ohm (Ω). However, I am not pressed for memory space (yet), so a full char set is fine. Although this might change when I move the code from an Arduino Mega 2560 to a Micro or Nano - I haven't had time to check this yet. However, I think that once I have spent some time understanding the font files I should be able to make my own (cut down) font/glyph set, or easier still, use The reason I resorted to printing character codes is that I had already tried printing the character. Using the IDE on a MacBookPro, running OSX 10.8.5, I can't print the Ω as one would expect. In the following code, this line
outputs
Using your suggestion, I still can't make it work. This line:
just outputs
I really can't see what I am missing, or where I am going wrong. This is the code:
FWIW, I would suggest supplying the fonts as separate downloadable files, or one big font bundle, which needs to downloaded in addition to U8g2. That would seem to be the best compromise. That way, at least the fonts are up on github, and users can still have access to the files if they need them, or are font addicts. Also, even if all of the fonts are bundled together, in one repository, a user would still be able to access the particular font file that they require and either download only that file, or copy and paste the respective code. I assume that the font file size only matters on the host PC/Mac, and that the entire font file is not loaded on to the microcontroller? Only the fonts used by the compiler are uploaded to the microcontroller? If that is the case, then I would have said that the font size, or overall U8g2 lib size is irrelevant, as PCs these days generally have terabytes of disk space and most people have fast ADSL download connections. However, to support users with low spec machines and slow connections, you could either offer:
|
My mistake, I was wrong with one of my statements above. drawStr() is the WRONG function for this. You have to use drawUTF8(). However print() should work as expected (because you have called enableUTF8Print()).
Yes exactly. This is one of the nice features of the Arduino IDE beeing already there since the initial version of the Arduino IDE: It configures the gcc/g++ in such a way, that unused code and data are thrown out automatically. So it does not matter if U8g2 comes with several 100MB of font data. Only those fonts which are refered in your c-code are downloaded to your controller. This makes it also very easy for the user: No additional download or font configuration is required. I also do not care much about occupied space on the hard disk of a host PC. The only topic is the fact that the compiler has to compile that 11MB file, which now takes around 5 seconds or so. So adding all the additional m fonts will probably increase this to 10 seconds. Well, still not a big issue... but a notable delay in the Arduino IDE. |
ToDo Generate m variants of some of the symbol fonts From Unifont
From X11:
Any other fonts required? |
Thank you, using
works fine. Also, Thank you ever so much for all of your help, I have been pulling my hair out since Monday about all of this. It has been a bit of a blocking issue... I can now continue with the rest of the project, GhettoVaper. Regarding the fonts, that should be fine for the moment, thanks, although I noticed that Thanks again. |
add all mentioned fonts from above as m or h version. |
this should be implemented, closing... |
Looks like the previous number is not cleared. Probably a programming error. Difficult to tell without more code. |
I used this loop to display the data. u8g2.firstPage(); And it works with the smaller fonts as I said before. It seem to be only an issue with the 22 and 29 font size. However I will post the code later. Thank you in advance. |
Remember: You must not change any value within the above while loop: temperature = measure_temperature();
u8g2.firstPage();
do {
/* draw value of variable 'temperature' */
} while ( u8g2.nextPage() ); This means you MUST measure the temperature outside of the loop. See also here: https://github.com/olikraus/u8glib/wiki/tpictureloop |
Ok, 😁 I think this is the main misstage I have done. Tomorrow I have some time to change the code and test it. However, for the smaller fonts it is no problem to meassure the temperature inside the loop. I try to understand this behaviour, maybe smaller fonts are displayed faster and thus the artefact of the bigger fonts are not visible? |
It depends whether the value on the display crosses a page boundary. The upper page will display the old the lower page the new value, which then will not fit together |
Hi Oli, your advice solved the problem and I understand now more how this buffer system works. Thank you very much. |
Let's say I am using a transparent font, such as
u8g2_font_unifont_t_symbols
. IsetFontMode(0)
, so not transparent. When I overwrite another character that is already on the screen, the background of the current character, or glyph, is not cleared, and so the previous character shows through...I basically want the same effect as is shown for
drawXBM()
, as is shown in the reference guide undersetBitmapMode()
, whensetBitmapMode(0)
is used, i.e. no transparency and the new character obliterates whatever was behind it. If I use a non-transparent font such as,u8g2_font_6x10_mf
, then I get the effect that I desire.Is this possible when using a transparent font? If so, how?
There are certain glyphs that I need, such as Omega (
Ω
) which are not available in non-transparent fonts, such asu8g2_font_6x10_mf
, and which are only available in some transparent fonts, such asu8g2_font_unifont_t_symbols
. I can not find a non-transparent version ofu8g2_font_unifont_t_symbols
, but I need to be able to overwrite the previous character.Why? Because I don't really want to have to
clearBuffer()
and redraw the screen again for scratch, I just want to quickly overwrite a portion text, that is already on the screen.Example code:
The text was updated successfully, but these errors were encountered: