|
Post by marteke on Mar 9, 2015 9:38:17 GMT -8
Hello I tried for several times add a custom font in gameduino2, but I can´t I dont´t Know! Could you please help me how can I add a custom font? thank you so much
|
|
|
Post by jamesbowman on Mar 9, 2015 17:40:27 GMT -8
OK, here is a brief tutorial. First get your font as a TTF, and rename the file so that it has a meaningful name. Here I used "comicsans.ttf". Then run the asset converter like this. The size argument is in pixels, and the default is 12. Here I set the size to 30 to give a nice legible font. $ gd2asset comicsans.ttf,size=30 Assets report ------------- Header file: default_assets.h GD2 RAM used: 60628 Flash used: 8326
The file "default_assets.h" contains the converted font. I created a new Arduino project "fontdemo" and added the assets into a new tab "fontdemo_assets.h": Here is the code for easier pasting into your own project: #include <EEPROM.h> #include <SPI.h> #include <GD2.h> #include "fontdemo_assets.h"
void setup() { GD.begin(0); LOAD_ASSETS(); }
void loop() { GD.ClearColorRGB(0x103000); GD.Clear(); GD.cmd_text(240, 136, COMICSANS_HANDLE, OPT_CENTER, "Hello world in Comic Sans MS"); GD.cmd_button(160, 200, 160, 40, COMICSANS_HANDLE, 0, "Press me!"); GD.swap(); } And here is the result. After LOAD_ASSETS(), the new font is available just like any of the built-in fonts. Any command that takes a font argument (cmd_text, cmd_number, cmd_button, cmd_keys) can use the new font.
|
|
|
Post by marteke on Mar 11, 2015 3:28:46 GMT -8
worked perfectly thank you so much!
|
|
|
Post by brunovr on Jun 13, 2015 8:39:14 GMT -8
Hi Janes,
the conversion of ttf give me an error :
ImportError : The _imagingft C module is not installed
how can i do ? thanks
|
|
|
Post by jamesbowman on Jun 13, 2015 14:17:29 GMT -8
|
|
|
Post by praks1510 on Oct 7, 2015 22:23:19 GMT -8
Where to run the asset converter? Same command prompt where we installed the gameduino2?
|
|
|
Post by jamesbowman on Oct 8, 2015 5:54:19 GMT -8
|
|
|
Post by praks1510 on Oct 8, 2015 21:38:46 GMT -8
I get the following error.
C:\Python27>python\Python27\Scripts\gd2asset The system cannot find the path specified.
C:\Python27>python \Python27\Scripts\gd2asset Traceback (most recent call last): File "\Python27\Scripts\gd2asset", line 4, in <module> __import__('pkg_resources').run_script('gameduino2==0.1.4', 'gd2asset') File "build\bdist.win-amd64\egg\pkg_resources\__init__.py", line 735, in run_s cript File "build\bdist.win-amd64\egg\pkg_resources\__init__.py", line 1659, in run_ script File "C:\Python27\lib\site-packages\gameduino2-0.1.4-py2.7.egg\EGG-INFO\script s\gd2asset", line 3, in <module> __requires__ = 'gameduino2==0.1.4' File "build\bdist.win-amd64\egg\gameduino2\__init__.py", line 2, in <module> File "build\bdist.win-amd64\egg\gameduino2\prep.py", line 10, in <module> ImportError: No module named Image
C:\Python27>
|
|
|
Post by jamesbowman on Oct 9, 2015 11:11:02 GMT -8
|
|
|
Post by JB on Dec 3, 2017 11:12:20 GMT -8
Sorry to kick in this old threat but it somehow fits to the topic.
Is it possible to use only an excerpt of a font (let's say only numbers) to save memory?
|
|
|
Post by jamesbowman on Dec 4, 2017 8:41:21 GMT -8
Good idea. Raised issue #4 against the gd2-asset tool.
|
|
|
Post by jamesbowman on Dec 4, 2017 13:23:00 GMT -8
OK, You can now specify a "topchar" for the ttf encoder, to select only some characters. For example here's the full font encoded, then a couple of partial encodes to save space. $ gd2asset testdata/Hobby-of-night.ttf Assets report ------------- Header file: default_assets.h GD2 RAM used: 7828 Flash used: 2259
$ gd2asset testdata/Hobby-of-night.ttf,topchar=0x39 Assets report ------------- Header file: default_assets.h GD2 RAM used: 1968 Flash used: 639
$ gd2asset testdata/Hobby-of-night.ttf,topchar=0x5a Assets report ------------- Header file: default_assets.h GD2 RAM used: 4280 Flash used: 1502
The latest version is on PyPI, so updating will fetch it: pypi.python.org/pypi/gameduino2/0.2.2
|
|
|
Post by casper on Dec 27, 2017 14:37:03 GMT -8
Hi,
I'd like to display large numbers on the screen (actually small numbers < 1000 but taking lots of pixel space), with font sizes greater than the included ones. So I'd like to create numeric assets for digits 0-9 only, is there a way of specifying the 'botchar' (assuming that I've understood the 'topchar'), to be able to just include a range of characters ?
I couldn't see a way to scale fonts (unlike jpg's) so in the meantime, I've hard coded relative coodinates to draw the lines required to draw each number and added a scale factor to enlarge them which works nicely.
Thanks.
|
|
|
Post by jamesbowman on Dec 27, 2017 17:57:56 GMT -8
|
|
|
Post by MangyDog on Jan 25, 2018 16:56:31 GMT -8
this is probably something stupid im doing... trying to do a font conversion, but I was getting this error
PS C:\> C:\Python27\python Python27\scripts\gd3asset -f hSPEEDassets.gd2 -o hSPEEDassets.h C:\assets\OCRAStd.ttf, size=32, format=L2
Traceback (most recent call last): File "Python27\scripts\gd3asset", line 4, in <module> __import__('pkg_resources').run_script('gameduino2==0.2.2', 'gd3asset') File "C:\Python27\lib\site-packages\pkg_resources\__init__.py", line 750, in run_script self.require(requires)[0].run_script(script_name, ns) File "C:\Python27\lib\site-packages\pkg_resources\__init__.py", line 1534, in run_script exec(script_code, namespace, namespace) File "C:\Python27\lib\site-packages\gameduino2-0.2.2-py2.7.egg\EGG-INFO\scripts\gd3asset", line 152, in <module> File "build\bdist.win32\egg\gameduino2\prep.py", line 613, in make File "C:\Python27\lib\site-packages\gameduino2-0.2.2-py2.7.egg\EGG-INFO\scripts\gd3asset", line 105, in addall File "C:\Python27\lib\site-packages\gameduino2-0.2.2-py2.7.egg\EGG-INFO\scripts\gd3asset", line 59, in ttf File "build\bdist.win32\egg\gameduino2\prep.py", line 332, in load_ttf File "C:\Python27\lib\site-packages\PIL\ImageFont.py", line 218, in truetype return FreeTypeFont(filename, size, index, encoding) File "C:\Python27\lib\site-packages\PIL\ImageFont.py", line 134, in __init__ self.font = core.getfont(file, size, index, encoding) File "C:\Python27\lib\site-packages\PIL\ImageFont.py", line 34, in __getattr__ raise ImportError("The _imagingft C module is not installed") ImportError: The _imagingft C module is not installed
On reading this thread I made sure pil was installed... it was. And with some googling read that I should install Pillow... I tried that and got this error:
PS C:\> C:\Python27\python Python27\scripts\gd3asset -f hSPEEDassets.gd2 -o hSPEEDassets.h C:\assets\OCRAStd.ttf, size=32, format=L2 Traceback (most recent call last): File "Python27\scripts\gd3asset", line 4, in <module> __import__('pkg_resources').run_script('gameduino2==0.2.2', 'gd3asset') File "C:\Python27\lib\site-packages\pkg_resources\__init__.py", line 750, in run_script self.require(requires)[0].run_script(script_name, ns) File "C:\Python27\lib\site-packages\pkg_resources\__init__.py", line 1534, in run_script exec(script_code, namespace, namespace) File "C:\Python27\lib\site-packages\gameduino2-0.2.2-py2.7.egg\EGG-INFO\scripts\gd3asset", line 3, in <module> __requires__ = 'gameduino2==0.2.2' File "build\bdist.win32\egg\gameduino2\__init__.py", line 2, in <module> # The Python Imaging Library. File "build\bdist.win32\egg\gameduino2\prep.py", line 11, in <module> File "C:\Python27\lib\site-packages\PIL\Image.py", line 27, in <module> from . import VERSION, PILLOW_VERSION, _plugins ValueError: Attempted relative import in non-package PS C:\>
|
|