Add font and preliminary tests
This commit is contained in:
parent
3e01230ea5
commit
dc7fb4c1bf
13
CMakeLists.txt
Normal file
13
CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
project(lcd-screenshot LANGUAGES C)
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(CAIRO REQUIRED cairo)
|
||||
|
||||
|
||||
include_directories(${CAIRO_INCLUDE_DIRS} "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
aux_source_directory("src" SOURCES)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME} ${CAIRO_LIBRARIES})
|
16
include/lcd-screenshot/hd44780-font.h
Normal file
16
include/lcd-screenshot/hd44780-font.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef _HD44780_FONT_H_
|
||||
#define _HD44780_FONT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* HD44780 5x7 pixel font data
|
||||
* http://eleif.net/HD44780.html
|
||||
* Array offset from ASCII code is decimal 32 (hex 20), i.e. the first element with index 0 is SPACE (' ')
|
||||
*/
|
||||
|
||||
#define HD44780_FONT_HEIGHT (7)
|
||||
#define HD44780_FONT_WIDTH (5)
|
||||
|
||||
const uint8_t *hd44780_font_get_character_raw(char c);
|
||||
|
||||
#endif /* _HD44780_FONT_H_ */
|
218
src/hd44780-font.c
Normal file
218
src/hd44780-font.c
Normal file
@ -0,0 +1,218 @@
|
||||
|
||||
#include <lcd-screenshot/hd44780-font.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* HD44780 5x7 pixel font data
|
||||
* http://eleif.net/HD44780.html
|
||||
* Array offset from ASCII code is decimal 32 (hex 20), i.e. the first element with index 0 is SPACE (' ')
|
||||
*/
|
||||
|
||||
#define TABLE_OFFSET (0x20)
|
||||
|
||||
const uint8_t hd44780_font[192][7] = {
|
||||
{ 0, 0, 0, 0, 0, 0, 0, }, // { 0} ' '
|
||||
{ 4, 4, 4, 4, 0, 0, 4, }, // { 1} '!'
|
||||
{ 10, 10, 10, 0, 0, 0, 0, }, // { 2} '"'
|
||||
{ 10, 10, 31, 10, 31, 10, 10, }, // { 3} '#'
|
||||
{ 4, 15, 20, 14, 5, 30, 4, }, // { 4} '$'
|
||||
{ 24, 25, 2, 4, 8, 19, 3, }, // { 5} '%'
|
||||
{ 12, 18, 20, 8, 21, 18, 13, }, // { 6} '&'
|
||||
{ 12, 4, 8, 0, 0, 0, 0, }, // { 7} '''
|
||||
{ 2, 4, 8, 8, 8, 4, 2, }, // { 8} '('
|
||||
{ 8, 4, 2, 2, 2, 4, 8, }, // { 9} ')'
|
||||
{ 0, 4, 21, 14, 21, 4, 0, }, // {10} '*'
|
||||
{ 0, 4, 4, 31, 4, 4, 0, }, // {11} '+'
|
||||
{ 0, 0, 0, 0, 12, 4, 8, }, // {12} ','
|
||||
{ 0, 0, 0, 31, 0, 0, 0, }, // {13} '-'
|
||||
{ 0, 0, 0, 0, 0, 12, 12, }, // {14} '.'
|
||||
{ 0, 1, 2, 4, 8, 16, 0, }, // {15} '/'
|
||||
{ 14, 17, 19, 21, 25, 17, 14, }, // {16} '0'
|
||||
{ 4, 12, 4, 4, 4, 4, 14, }, // {17} '1'
|
||||
{ 14, 17, 1, 2, 4, 8, 31, }, // {18} '2'
|
||||
{ 31, 2, 4, 2, 1, 17, 14, }, // {19} '3'
|
||||
{ 2, 6, 10, 18, 31, 2, 2, }, // {20} '4'
|
||||
{ 31, 16, 30, 1, 1, 17, 14, }, // {21} '5'
|
||||
{ 6, 8, 16, 30, 17, 17, 14, }, // {22} '6'
|
||||
{ 31, 17, 1, 2, 4, 4, 4, }, // {23} '7'
|
||||
{ 14, 17, 17, 14, 17, 17, 14, }, // {24} '8'
|
||||
{ 14, 17, 17, 15, 1, 2, 12, }, // {25} '9'
|
||||
{ 0, 12, 12, 0, 12, 12, 0, }, // {26} ':'
|
||||
{ 0, 12, 12, 0, 12, 4, 8, }, // {27} ';'
|
||||
{ 2, 4, 8, 16, 8, 4, 2, }, // {28} '<'
|
||||
{ 0, 0, 31, 0, 31, 0, 0, }, // {29} '='
|
||||
{ 8, 4, 2, 1, 2, 4, 8, }, // {30} '>'
|
||||
{ 14, 17, 1, 2, 4, 0, 4, }, // {31} '?'
|
||||
{ 14, 17, 1, 13, 21, 21, 14, }, // {32} '@'
|
||||
{ 14, 17, 17, 17, 31, 17, 17, }, // {33} 'A'
|
||||
{ 30, 17, 17, 30, 17, 17, 30, }, // {34} 'B'
|
||||
{ 14, 17, 16, 16, 16, 17, 14, }, // {35} 'C'
|
||||
{ 28, 18, 17, 17, 17, 18, 28, }, // {36} 'D'
|
||||
{ 31, 16, 16, 30, 16, 16, 31, }, // {37} 'E'
|
||||
{ 31, 16, 16, 30, 16, 16, 16, }, // {38} 'F'
|
||||
{ 14, 17, 16, 23, 17, 17, 15, }, // {39} 'G'
|
||||
{ 17, 17, 17, 31, 17, 17, 17, }, // {40} 'H'
|
||||
{ 14, 4, 4, 4, 4, 4, 14, }, // {41} 'I'
|
||||
{ 7, 2, 2, 2, 2, 18, 12, }, // {42} 'J'
|
||||
{ 17, 18, 20, 24, 20, 18, 17, }, // {43} 'K'
|
||||
{ 16, 16, 16, 16, 16, 16, 31, }, // {44} 'L'
|
||||
{ 17, 27, 21, 21, 17, 17, 17, }, // {45} 'M'
|
||||
{ 17, 17, 25, 21, 19, 17, 17, }, // {46} 'N'
|
||||
{ 14, 17, 17, 17, 17, 17, 14, }, // {47} 'O'
|
||||
{ 30, 17, 17, 30, 16, 16, 16, }, // {48} 'P'
|
||||
{ 14, 17, 17, 17, 21, 18, 13, }, // {49} 'Q'
|
||||
{ 30, 17, 17, 30, 20, 18, 17, }, // {50} 'R'
|
||||
{ 15, 16, 16, 14, 1, 1, 30, }, // {51} 'S'
|
||||
{ 31, 4, 4, 4, 4, 4, 4, }, // {52} 'T'
|
||||
{ 17, 17, 17, 17, 17, 17, 14, }, // {53} 'U'
|
||||
{ 17, 17, 17, 17, 17, 10, 4, }, // {54} 'V'
|
||||
{ 17, 17, 17, 21, 21, 21, 10, }, // {55} 'W'
|
||||
{ 17, 17, 10, 4, 10, 17, 17, }, // {56} 'X'
|
||||
{ 17, 17, 17, 10, 4, 4, 4, }, // {57} 'Y'
|
||||
{ 31, 1, 2, 4, 8, 16, 31, }, // {58} 'Z'
|
||||
{ 28, 16, 16, 16, 16, 16, 28, }, // {59} '{'
|
||||
{ 17, 10, 31, 4, 31, 4, 4, }, // {60} '\'
|
||||
{ 14, 2, 2, 2, 2, 2, 14, }, // {61} '}'
|
||||
{ 4, 10, 17, 0, 0, 0, 0, }, // {62} '^'
|
||||
{ 0, 0, 0, 0, 0, 0, 31, }, // {63} '_'
|
||||
{ 8, 4, 2, 0, 0, 0, 0, }, // {64} '`'
|
||||
{ 0, 0, 14, 1, 15, 17, 15, }, // {65} 'a'
|
||||
{ 16, 16, 22, 25, 17, 17, 30, }, // {66} 'b'
|
||||
{ 0, 0, 14, 16, 16, 17, 14, }, // {67} 'c'
|
||||
{ 1, 1, 13, 19, 17, 17, 15, }, // {68} 'd'
|
||||
{ 0, 0, 14, 17, 31, 16, 14, }, // {69} 'e'
|
||||
{ 6, 9, 8, 28, 8, 8, 8, }, // {70} 'f'
|
||||
{ 0, 15, 17, 17, 15, 1, 14, }, // {71} 'g'
|
||||
{ 16, 16, 22, 25, 17, 17, 17, }, // {72} 'h'
|
||||
{ 4, 0, 12, 4, 4, 4, 14, }, // {73} 'i'
|
||||
{ 2, 0, 6, 2, 2, 18, 12, }, // {74} 'j'
|
||||
{ 16, 16, 18, 20, 24, 20, 18, }, // {75} 'k'
|
||||
{ 12, 4, 4, 4, 4, 4, 14, }, // {76} 'l'
|
||||
{ 0, 0, 26, 21, 21, 17, 17, }, // {77} 'm'
|
||||
{ 0, 0, 22, 25, 17, 17, 17, }, // {78} 'n'
|
||||
{ 0, 0, 14, 17, 17, 17, 14, }, // {79} 'o'
|
||||
{ 0, 0, 30, 17, 30, 16, 16, }, // {80} 'p'
|
||||
{ 0, 0, 13, 19, 15, 1, 1, }, // {81} 'q'
|
||||
{ 0, 0, 22, 25, 16, 16, 16, }, // {82} 'r'
|
||||
{ 0, 0, 14, 16, 14, 1, 30, }, // {83} 's'
|
||||
{ 8, 8, 28, 8, 8, 9, 6, }, // {84} 't'
|
||||
{ 0, 0, 17, 17, 17, 19, 13, }, // {85} 'u'
|
||||
{ 0, 0, 17, 17, 17, 10, 4, }, // {86} 'v'
|
||||
{ 0, 0, 17, 21, 21, 21, 10, }, // {87} 'w'
|
||||
{ 0, 0, 17, 10, 4, 10, 17, }, // {88} 'x'
|
||||
{ 0, 0, 17, 17, 15, 1, 14, }, // {89} 'y'
|
||||
{ 0, 0, 31, 2, 4, 8, 31, }, // {90} 'z'
|
||||
{ 2, 4, 4, 8, 4, 4, 2, }, // {91} '{'
|
||||
{ 4, 4, 4, 4, 4, 4, 4, }, // {92} '|'
|
||||
{ 8, 4, 4, 2, 4, 4, 8, }, // {93} '}'
|
||||
{ 0, 4, 2, 31, 2, 4, 0, }, // {94} '~'
|
||||
{ 0, 4, 8, 31, 8, 4, 0, }, // {95} ''
|
||||
{ 0, 0, 0, 0, 0, 0, 0, }, // {96} ''
|
||||
{ 4, 4, 4, 4, 0, 0, 4, }, // {97} ''
|
||||
{ 10, 10, 10, 0, 0, 0, 0, }, // {98} ''
|
||||
{ 10, 10, 31, 10, 31, 10, 10, }, // {99} ''
|
||||
{ 4, 15, 20, 14, 5, 30, 4, }, // {100} ''
|
||||
{ 24, 25, 2, 4, 8, 19, 3, }, // {101} '
'
|
||||
{ 12, 18, 20, 8, 21, 18, 13, }, // {102} ''
|
||||
{ 12, 4, 8, 0, 0, 0, 0, }, // {103} ''
|
||||
{ 2, 4, 8, 8, 8, 4, 2, }, // {104} ''
|
||||
{ 8, 4, 2, 2, 2, 4, 8, }, // {105} ''
|
||||
{ 0, 4, 21, 14, 21, 4, 0, }, // {106} ''
|
||||
{ 0, 4, 4, 31, 4, 4, 0, }, // {107} ''
|
||||
{ 0, 0, 0, 0, 12, 4, 8, }, // {108} ''
|
||||
{ 0, 0, 0, 31, 0, 0, 0, }, // {109} ''
|
||||
{ 0, 0, 0, 0, 0, 12, 12, }, // {110} ''
|
||||
{ 0, 1, 2, 4, 8, 16, 0, }, // {111} ''
|
||||
{ 14, 17, 19, 21, 25, 17, 14, }, // {112} ''
|
||||
{ 4, 12, 4, 4, 4, 4, 14, }, // {113} ''
|
||||
{ 14, 17, 1, 2, 4, 8, 31, }, // {114} ''
|
||||
{ 31, 2, 4, 2, 1, 17, 14, }, // {115} ''
|
||||
{ 2, 6, 10, 18, 31, 2, 2, }, // {116} ''
|
||||
{ 31, 16, 30, 1, 1, 17, 14, }, // {117} ''
|
||||
{ 6, 8, 16, 30, 17, 17, 14, }, // {118} ''
|
||||
{ 31, 17, 1, 2, 4, 4, 4, }, // {119} ''
|
||||
{ 14, 17, 17, 14, 17, 17, 14, }, // {120} ''
|
||||
{ 14, 17, 17, 15, 1, 2, 12, }, // {121} ''
|
||||
{ 0, 12, 12, 0, 12, 12, 0, }, // {122} ''
|
||||
{ 0, 12, 12, 0, 12, 4, 8, }, // {123} ''
|
||||
{ 2, 4, 8, 16, 8, 4, 2, }, // {124} ''
|
||||
{ 0, 0, 31, 0, 31, 0, 0, }, // {125} ''
|
||||
{ 8, 4, 2, 1, 2, 4, 8, }, // {126} ''
|
||||
{ 14, 17, 1, 2, 4, 0, 4, }, // {127} ''
|
||||
{ 14, 17, 1, 13, 21, 21, 14, }, // {128} ' '
|
||||
{ 14, 17, 17, 17, 31, 17, 17, }, // {129} '¡'
|
||||
{ 30, 17, 17, 30, 17, 17, 30, }, // {130} '¢'
|
||||
{ 14, 17, 16, 16, 16, 17, 14, }, // {131} '£'
|
||||
{ 28, 18, 17, 17, 17, 18, 28, }, // {132} '¤'
|
||||
{ 31, 16, 16, 30, 16, 16, 31, }, // {133} '¥'
|
||||
{ 31, 16, 16, 30, 16, 16, 16, }, // {134} '¦'
|
||||
{ 14, 17, 16, 23, 17, 17, 15, }, // {135} '§'
|
||||
{ 17, 17, 17, 31, 17, 17, 17, }, // {136} '¨'
|
||||
{ 14, 4, 4, 4, 4, 4, 14, }, // {137} '©'
|
||||
{ 7, 2, 2, 2, 2, 18, 12, }, // {138} 'ª'
|
||||
{ 17, 18, 20, 24, 20, 18, 17, }, // {139} '«'
|
||||
{ 16, 16, 16, 16, 16, 16, 31, }, // {140} '¬'
|
||||
{ 17, 27, 21, 21, 17, 17, 17, }, // {141} ''
|
||||
{ 17, 17, 25, 21, 19, 17, 17, }, // {142} '®'
|
||||
{ 14, 17, 17, 17, 17, 17, 14, }, // {143} '¯'
|
||||
{ 30, 17, 17, 30, 16, 16, 16, }, // {144} '°'
|
||||
{ 14, 17, 17, 17, 21, 18, 13, }, // {145} '±'
|
||||
{ 30, 17, 17, 30, 20, 18, 17, }, // {146} '²'
|
||||
{ 15, 16, 16, 14, 1, 1, 30, }, // {147} '³'
|
||||
{ 31, 4, 4, 4, 4, 4, 4, }, // {148} '´'
|
||||
{ 17, 17, 17, 17, 17, 17, 14, }, // {149} 'µ'
|
||||
{ 17, 17, 17, 17, 17, 10, 4, }, // {150} '¶'
|
||||
{ 17, 17, 17, 21, 21, 21, 10, }, // {151} '·'
|
||||
{ 17, 17, 10, 4, 10, 17, 17, }, // {152} '¸'
|
||||
{ 17, 17, 17, 10, 4, 4, 4, }, // {153} '¹'
|
||||
{ 31, 1, 2, 4, 8, 16, 31, }, // {154} 'º'
|
||||
{ 28, 16, 16, 16, 16, 16, 28, }, // {155} '»'
|
||||
{ 17, 10, 31, 4, 31, 4, 4, }, // {156} '¼'
|
||||
{ 14, 2, 2, 2, 2, 2, 14, }, // {157} '½'
|
||||
{ 4, 10, 17, 0, 0, 0, 0, }, // {158} '¾'
|
||||
{ 0, 0, 0, 0, 0, 0, 31, }, // {159} '¿'
|
||||
{ 8, 4, 2, 0, 0, 0, 0, }, // {160} 'À'
|
||||
{ 0, 0, 14, 1, 15, 17, 15, }, // {161} 'Á'
|
||||
{ 16, 16, 22, 25, 17, 17, 30, }, // {162} 'Â'
|
||||
{ 0, 0, 14, 16, 16, 17, 14, }, // {163} 'Ã'
|
||||
{ 1, 1, 13, 19, 17, 17, 15, }, // {164} 'Ä'
|
||||
{ 0, 0, 14, 17, 31, 16, 14, }, // {165} 'Å'
|
||||
{ 6, 9, 8, 28, 8, 8, 8, }, // {166} 'Æ'
|
||||
{ 0, 15, 17, 17, 15, 1, 14, }, // {167} 'Ç'
|
||||
{ 16, 16, 22, 25, 17, 17, 17, }, // {168} 'È'
|
||||
{ 4, 0, 12, 4, 4, 4, 14, }, // {169} 'É'
|
||||
{ 2, 0, 6, 2, 2, 18, 12, }, // {170} 'Ê'
|
||||
{ 16, 16, 18, 20, 24, 20, 18, }, // {171} 'Ë'
|
||||
{ 12, 4, 4, 4, 4, 4, 14, }, // {172} 'Ì'
|
||||
{ 0, 0, 26, 21, 21, 17, 17, }, // {173} 'Í'
|
||||
{ 0, 0, 22, 25, 17, 17, 17, }, // {174} 'Î'
|
||||
{ 0, 0, 14, 17, 17, 17, 14, }, // {175} 'Ï'
|
||||
{ 0, 0, 30, 17, 30, 16, 16, }, // {176} 'Ð'
|
||||
{ 0, 0, 13, 19, 15, 1, 1, }, // {177} 'Ñ'
|
||||
{ 0, 0, 22, 25, 16, 16, 16, }, // {178} 'Ò'
|
||||
{ 0, 0, 14, 16, 14, 1, 30, }, // {179} 'Ó'
|
||||
{ 8, 8, 28, 8, 8, 9, 6, }, // {180} 'Ô'
|
||||
{ 0, 0, 17, 17, 17, 19, 13, }, // {181} 'Õ'
|
||||
{ 0, 0, 17, 17, 17, 10, 4, }, // {182} 'Ö'
|
||||
{ 0, 0, 17, 21, 21, 21, 10, }, // {183} '×'
|
||||
{ 0, 0, 17, 10, 4, 10, 17, }, // {184} 'Ø'
|
||||
{ 0, 0, 17, 17, 15, 1, 14, }, // {185} 'Ù'
|
||||
{ 0, 0, 31, 2, 4, 8, 31, }, // {186} 'Ú'
|
||||
{ 2, 4, 4, 8, 4, 4, 2, }, // {187} 'Û'
|
||||
{ 4, 4, 4, 4, 4, 4, 4, }, // {188} 'Ü'
|
||||
{ 8, 4, 4, 2, 4, 4, 8, }, // {189} 'Ý'
|
||||
{ 0, 4, 2, 31, 2, 4, 0, }, // {190} 'Þ'
|
||||
{ 0, 4, 8, 31, 8, 4, 0, } // {191} 'ß'
|
||||
};
|
||||
|
||||
|
||||
const uint8_t *hd44780_font_get_character_raw(char c)
|
||||
{
|
||||
int idx;
|
||||
|
||||
idx = (int)((uint8_t)c);
|
||||
idx -= TABLE_OFFSET;
|
||||
if (idx < 0 || idx > 191)
|
||||
return NULL;
|
||||
|
||||
return &hd44780_font[idx][0];
|
||||
}
|
24
src/main.c
Normal file
24
src/main.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
#include <cairo.h>
|
||||
#include <cairo-pdf.h>
|
||||
#include <cairo-svg.h>
|
||||
#include <lcd-screenshot/hd44780-font.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
|
||||
|
||||
surface = cairo_svg_surface_create ("out.svg", 120, 120);
|
||||
cr = cairo_create (surface);
|
||||
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||
cairo_rectangle (cr, 0.25, 0.25, 100, 60);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_show_page(cr);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(surface);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user