├── unifont.cpp
├── redist
├── PressStart2P.ttf
├── FONTLOG.txt
├── LICENSE.txt
├── ttf2mono.cc
└── stb_truetype.h
├── .travis.yml
├── LICENSE
├── README.md
├── sample.cc
└── unifont.hpp
/unifont.cpp:
--------------------------------------------------------------------------------
1 | #include "unifont.hpp"
2 |
--------------------------------------------------------------------------------
/redist/PressStart2P.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/r-lyeh-archived/unifont/HEAD/redist/PressStart2P.ttf
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: cpp
2 | sudo: required
3 |
4 | compiler:
5 | - clang
6 | - gcc
7 |
8 | install:
9 | - wget --quiet -O - https://raw.githubusercontent.com/r-lyeh/depot/master/travis.pre.sh | bash -x
10 |
11 | script:
12 | - wget --quiet -O - https://raw.githubusercontent.com/r-lyeh/depot/master/travis.build.sh | bash -x
13 | - wget --quiet -O - https://raw.githubusercontent.com/r-lyeh/depot/master/travis.run.sh | bash -x
14 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015 r-lyeh (https://github.com/r-lyeh)
2 |
3 | This software is provided 'as-is', without any express or implied
4 | warranty. In no event will the authors be held liable for any damages
5 | arising from the use of this software.
6 |
7 | Permission is granted to anyone to use this software for any purpose,
8 | including commercial applications, and to alter it and redistribute it
9 | freely, subject to the following restrictions:
10 |
11 | 1. The origin of this software must not be misrepresented; you must not
12 | claim that you wrote the original software. If you use this software
13 | in a product, an acknowledgment in the product documentation would be
14 | appreciated but is not required.
15 | 2. Altered source versions must be plainly marked as such, and must not be
16 | misrepresented as being the original software.
17 | 3. This notice may not be removed or altered from any source distribution.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | unifont
2 | =======
3 |
4 | - Unifont is a compact and embeddable terminal 1-bpp font library (C++11).
5 | - Unifont is handy. It supports most european/greek/cyrillic unicode codepoints.
6 | - Unifont is tiny (~400 LOC), header-only, portable and cross-platform.
7 | - Unifont is aimed to gamedev and debugging sessions.
8 | - Unifont is zlib/libpng licensed.
9 |
10 | ## api
11 | - Instance an `unifont(color *framebuffer, unsigned width, color (*make_rgba)(r,g,b,a))` class.
12 | - While using an unifont class, the external framebuffer must point to a valid memory address.
13 | - Then use following methods as desired:
14 | ```c++
15 | render_string(x,y,style,const char* utf8);
16 | render_string(x,y,style,const char* utf8, const color &c);
17 | render_string(x,y,style,const char* utf8, const color* gradient8x8);
18 | render_string(x,y,style,const vector &codepoints);
19 | render_string(x,y,style,const vector &codepoints, const color &c);
20 | render_string(x,y,style,const vector &codepoints, const color* gradient8x8);
21 | ```
22 | - Style is an `enum { NORMAL, INVERT, SHADOW, RETRO }` flag mask.
23 | - All methods return an `struct { unsigned w, h; }` dimensions rectangle.
24 | - For a more detailed sample check [sample.cc file](sample.cc).
25 |
26 | ## preview
27 | 
28 |
29 | ## notes
30 | - To replace embedded built-in font see [ttf2mono.cc source code](redist/ttf2mono.cc)
31 | - Sample requires [libspot](https://github.com/r-lyeh/spot) to compile.
32 |
33 | ## licenses
34 | - [Unifont](https://github.com/r-lyeh/unifont), zlib/libpng licensed.
35 | - [PressStart2P.ttf v2.14](http://www.zone38.net/font/) by Cody "CodeMan38" Boisclair (SIL Open Font License).
36 | - [UTF-8 dfa decoder](http://bjoern.hoehrmann.de/utf-8/decoder/dfa/) by Bjoern Hoehrmann (MIT license).
37 | - Gradient retro style mask taken from [DoDonPachi arcade](http://en.wikipedia.org/wiki/DoDonPachi).
38 |
39 | ## changelog
40 | - v1.0.0 (2015/05/05)
41 | - initial revision
42 |
--------------------------------------------------------------------------------
/redist/FONTLOG.txt:
--------------------------------------------------------------------------------
1 | FONTLOG for the Press Start 2P fonts
2 |
3 | This file provides detailed information on the Press Start 2P Font Software.
4 | This information should be distributed along with the Press Start 2P fonts
5 | and any derivative works.
6 |
7 |
8 | Basic Font Information
9 |
10 | Press Start 2P is a bitmap font based on the font design from 1980s Namco
11 | arcade games. Although the design of uppercase letters and digits dates
12 | back to Atari's "Sprint" (1977), the specific glyph forms in this TrueType
13 | conversion are based on those from "Return of Ishtar" (1986), one of the
14 | first games to include and regularly use lowercase as well as uppercase
15 | letters in its screen font.
16 |
17 | Unlike the original font from the "Return of Ishtar" ROM, Press Start 2P
18 | includes a wide variety of non-ASCII Unicode characters for pan-European
19 | use, including Greek and Cyrillic.
20 |
21 |
22 | ChangeLog
23 |
24 | 1 November 2012 (Cody Boisclair) Press Start 2P version 2.14
25 | - Add necessary flags for Windows to recognize as a valid Greek/Cyrillic font
26 | - Change line gap to zero to match version on Google Web Fonts
27 |
28 | 15 June 2011 (Cody Boisclair) Press Start 2P version 2.13
29 | - Correct accent marks on U+00D9 Ù and U+00DA Ú
30 |
31 | 13 June 2011 (Cody Boisclair) Press Start 2P version 2.12
32 | - Correct glyph for underscore _
33 | - Move glyphs for Greek iota one pixel to left
34 | - Fix 'notdef' glyph, whose encoding was broken during last update
35 |
36 | 13 June 2011 (Cody Boisclair) Press Start 2P version 2.11
37 | - Retrace characters from bitmaps to fix glyph width bug
38 | - Add glyphs for Spacing Modifier Letters
39 | - Move U+201E „ one pixel to left, U+201A ‚ one pixel to right
40 |
41 | 13 June 2011 (Cody Boisclair) Press Start 2P version 2.10
42 | - Add Greek and Cyrillic alphabets.
43 | - Redesign U+0138 ĸ to match shape of Greek kappa
44 | - Correct glyph shape for grave accent `
45 | - Move U+00B7 · down one row to appear more centered
46 | - Modify FONTLOG description to reflect Greek & Cyrillic addition
47 |
48 | 13 June 2011 (Cody Boisclair) Press Start 2P version 2.01
49 | - Correct glyph for @; improve glyphs for © and ® based on original @.
50 |
51 | 12 June 2011 (Cody Boisclair) Press Start 2P version 2.0
52 | - Initial public release.
53 |
54 |
55 | Acknowledgements
56 |
57 | If you make modifications be sure to add your name (N), email (E),
58 | web-address (if you have one) (W) and description (D).
59 | This list is in alphabetical order.
60 |
61 | N: Cody Boisclair ("CodeMan38")
62 | E: cody@zone38.net
63 | W: http://zone38.net/font/
64 | D: Conversion of glyphs to TrueType; creation of non-ASCII glyphs
65 |
66 | N: "QTQ"
67 | E: [unknown]
68 | W: http://www22.atpages.jp/nbgifan/namco.html
69 | D: Original extraction of glyph bitmaps
--------------------------------------------------------------------------------
/sample.cc:
--------------------------------------------------------------------------------
1 | // sample requires libspot (https://github.com/r-lyeh/spot)
2 | // file must be saved with utf-8 encoding
3 | // r-lyeh, public domain
4 |
5 | #include "unifont.hpp"
6 |
7 | #if !defined(USE_LIBSPOT)
8 |
9 | int main() {
10 |
11 | }
12 |
13 | #else
14 |
15 | #include "spot/spot.hpp"
16 | #include "spot/samples/cimg.hpp"
17 |
18 | spot::pixel make_rgba( uint8_t r, uint8_t g, uint8_t b, uint8_t a ) {
19 | return spot::rgba(r,g,b,a);
20 | }
21 |
22 | int main() {
23 | spot::texture img(600, 600);
24 | for( unsigned y = 0; y < 600; ++y ) {
25 | for( unsigned x = 0; x < 600; ++x ) {
26 | img.at( x, y ) = spot::hsla( ( (x+y) % 255 ) / 255.0, (x+y) / 600.0, (x+y) / 1200.0, 1 );
27 | }
28 | }
29 |
30 | unifont font( &img[0], img.w, &make_rgba );
31 |
32 | // styles
33 | int normal = font.NORMAL;
34 | int invert = font.INVERT;
35 | int shadow = font.SHADOW;
36 | int retro = font.RETRO;
37 |
38 | // coord
39 | int ox = 10, oy = 10;
40 |
41 | oy += font.render_string( ox, oy, 0|2, "ee: õueaiaäär" ).h;
42 | oy += font.render_string( ox, oy, 0|2, "es: ¡¿Cómo que por qué se escribe cigüeña?!" ).h;
43 | oy += font.render_string( ox, oy, 0|2, "fi: Vesihiisi sihisi hississä." ).h;
44 | oy += font.render_string( ox, oy, 0|2, "fr: D'où êtes-vous ? Ça va? Allô? Pouvez-vous répéter, s'il vous plaît?" ).h;
45 | oy += font.render_string( ox, oy, 0|2, "ge: ბაყაყი წყალში ყიყინებს (unsupported)" ).h;
46 | oy += font.render_string( ox, oy, 0|2, "gr: Χάρηκα για την γνωρημία. Η αθασιά της Αϊσές αν έχει αθάσια, ας έχει" ).h;
47 | oy += font.render_string( ox, oy, 0|2, "hr: Cvrči cvrči cvrčak na čvoru crne smrče" ).h;
48 | oy += font.render_string( ox, oy, 0|2, "is: Ég get etið gler án þess að meiða mig" ).h;
49 | oy += font.render_string( ox, oy, 0|2, "pl: Słucham. Dzięki. Skąd jesteś?" ).h;
50 | oy += font.render_string( ox, oy, 0|2, "ro: Mulţumesc! Însănătoșire grabnică! Îți doresc." ).h;
51 | oy += font.render_string( ox, oy, 0|2, "ru: Будем здоровы!" ).h;
52 | oy += font.render_string( ox, oy, 0|2, "**: (unsupported) أَلَمٌ أَلَمَّ أَلَمْ أُلِمَّ بِدَائِهِ ... إِنْ آنَ آنٌ آنَ آنُ أَوَانِهِ" ).h;
53 |
54 | oy += font.render_string( ox, oy, 0, "+-------------------------------------+" ).h;
55 | oy += font.render_string( ox, oy, 0, "| HELLO WORLD!! $01234567.89# abc ABC |X" ).h;
56 | oy += font.render_string( ox, oy, 0, "+-------------------------------------+X" ).h;
57 | oy += font.render_string( ox, oy, 0, " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ).h;
58 |
59 | oy += font.render_string( ox, oy, 0, "yellow: color test without shadow", make_rgba(255,255,0,255) ).h;
60 | oy += font.render_string( ox, oy, 0|shadow, "cherry: color test with shadow", make_rgba(222,49,99,255) ).h;
61 |
62 | oy += font.render_string( ox, oy, normal, "style: plain" ).h;
63 | oy += font.render_string( ox, oy, invert, "style: invert" ).h;
64 | oy += font.render_string( ox, oy, shadow, "style: shadow" ).h;
65 | oy += font.render_string( ox, oy, retro, "style: retro" ).h;
66 | oy += font.render_string( ox, oy, retro|shadow, "style: retro+shadow" ).h;
67 | auto A = make_rgba(255,255,255,255), B = make_rgba(0,255,255,255), C = make_rgba(0,128,255,255), D = make_rgba(40,80,255,255);
68 | decltype(A) gradient[] = {
69 | A,A,A,A,A,A,A,A,
70 | A,A,A,A,A,A,A,A,
71 | B,B,B,B,B,B,B,B,
72 | B,B,B,B,B,B,B,B,
73 | C,C,C,C,C,C,C,C,
74 | C,C,C,C,C,C,C,C,
75 | D,D,D,D,D,D,D,D,
76 | D,D,D,D,D,D,D,D,
77 | };
78 | oy += font.render_string( ox, oy, shadow, "style: custom gradient fill", gradient ).h;
79 |
80 | oy += font.render_glyphs( ox, oy, shadow ).h;
81 |
82 | img.copy( 0, 0, 380, 520 ).save_as_png("unifont.png");
83 | display( img, "mono fonts preview" );
84 | }
85 |
86 | #endif
87 |
88 |
--------------------------------------------------------------------------------
/redist/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011, Cody "CodeMan38" Boisclair (cody@zone38.net),
2 | with Reserved Font Name "Press Start".
3 |
4 | This Font Software is licensed under the SIL Open Font License, Version 1.1.
5 | This license is copied below, and is also available with a FAQ at:
6 | http://scripts.sil.org/OFL
7 |
8 |
9 | -----------------------------------------------------------
10 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
11 | -----------------------------------------------------------
12 |
13 | PREAMBLE
14 | The goals of the Open Font License (OFL) are to stimulate worldwide
15 | development of collaborative font projects, to support the font creation
16 | efforts of academic and linguistic communities, and to provide a free and
17 | open framework in which fonts may be shared and improved in partnership
18 | with others.
19 |
20 | The OFL allows the licensed fonts to be used, studied, modified and
21 | redistributed freely as long as they are not sold by themselves. The
22 | fonts, including any derivative works, can be bundled, embedded,
23 | redistributed and/or sold with any software provided that any reserved
24 | names are not used by derivative works. The fonts and derivatives,
25 | however, cannot be released under any other type of license. The
26 | requirement for fonts to remain under this license does not apply
27 | to any document created using the fonts or their derivatives.
28 |
29 | DEFINITIONS
30 | "Font Software" refers to the set of files released by the Copyright
31 | Holder(s) under this license and clearly marked as such. This may
32 | include source files, build scripts and documentation.
33 |
34 | "Reserved Font Name" refers to any names specified as such after the
35 | copyright statement(s).
36 |
37 | "Original Version" refers to the collection of Font Software components as
38 | distributed by the Copyright Holder(s).
39 |
40 | "Modified Version" refers to any derivative made by adding to, deleting,
41 | or substituting -- in part or in whole -- any of the components of the
42 | Original Version, by changing formats or by porting the Font Software to a
43 | new environment.
44 |
45 | "Author" refers to any designer, engineer, programmer, technical
46 | writer or other person who contributed to the Font Software.
47 |
48 | PERMISSION & CONDITIONS
49 | Permission is hereby granted, free of charge, to any person obtaining
50 | a copy of the Font Software, to use, study, copy, merge, embed, modify,
51 | redistribute, and sell modified and unmodified copies of the Font
52 | Software, subject to the following conditions:
53 |
54 | 1) Neither the Font Software nor any of its individual components,
55 | in Original or Modified Versions, may be sold by itself.
56 |
57 | 2) Original or Modified Versions of the Font Software may be bundled,
58 | redistributed and/or sold with any software, provided that each copy
59 | contains the above copyright notice and this license. These can be
60 | included either as stand-alone text files, human-readable headers or
61 | in the appropriate machine-readable metadata fields within text or
62 | binary files as long as those fields can be easily viewed by the user.
63 |
64 | 3) No Modified Version of the Font Software may use the Reserved Font
65 | Name(s) unless explicit written permission is granted by the corresponding
66 | Copyright Holder. This restriction only applies to the primary font name as
67 | presented to the users.
68 |
69 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
70 | Software shall not be used to promote, endorse or advertise any
71 | Modified Version, except to acknowledge the contribution(s) of the
72 | Copyright Holder(s) and the Author(s) or with their explicit written
73 | permission.
74 |
75 | 5) The Font Software, modified or unmodified, in part or in whole,
76 | must be distributed entirely under this license, and must not be
77 | distributed under any other license. The requirement for fonts to
78 | remain under this license does not apply to any document created
79 | using the Font Software.
80 |
81 | TERMINATION
82 | This license becomes null and void if any of the above conditions are
83 | not met.
84 |
85 | DISCLAIMER
86 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
87 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
88 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
89 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
90 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
91 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
92 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
93 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
94 | OTHER DEALINGS IN THE FONT SOFTWARE.
--------------------------------------------------------------------------------
/redist/ttf2mono.cc:
--------------------------------------------------------------------------------
1 | // ttf2mono font converter, dirty hack :)
2 | // r-lyeh, public domain
3 |
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include