-
-
Save MaBecker/89a8ec3314f456ccfe397593783ec8b4 to your computer and use it in GitHub Desktop.
Hershey Roman Simple Vector Font test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* jshint esversion: 6 */ | |
var g; | |
var VECTOR_FONT_POLY_SIZE = 22; // size in pixel ? | |
var VECTOR_FONT_POLY_SEPARATOR = 128; | |
var vectorFontOffset = 48; | |
var vectorFontCount = 10; | |
var vectorFontPolys = [ | |
// Character code 48 : 0 | |
6, 21, | |
3, 20, | |
1, 17, | |
0, 12, | |
0, 9, | |
1, 4, | |
3, 1, | |
6, 0, | |
8, 0, | |
11, 1, | |
13, 4, | |
14, 9, | |
14, 12, | |
13, 17, | |
11, 20, | |
8, 21, | |
6, 21 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 49 : 1 | |
0, 5, | |
2, 3, | |
5, 0, | |
5, 21 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 50 : 2 | |
1, 5, | |
1, 4, | |
2, 2, | |
3, 1, | |
5, 0, | |
9, 0, | |
11, 1, | |
12, 2, | |
13, 4, | |
13, 6, | |
12, 8, | |
10, 11, | |
0, 21, | |
13, 21 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 51 : 3 | |
2, 0, | |
13, 0, | |
7, 8, | |
10, 8, | |
12, 9, | |
13, 10, | |
14, 13, | |
14, 15, | |
13, 18, | |
11, 20, | |
8, 21, | |
5, 21, | |
2, 20, | |
1, 19, | |
0, 17 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 52 : 4 | |
10, 0, | |
0, 14, | |
15, 14 | VECTOR_FONT_POLY_SEPARATOR, | |
10, 0, | |
10, 21 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 53 : 5 | |
14, 0, | |
3, 0, | |
2, 9, | |
3, 8, | |
6, 7, | |
9, 7, | |
12, 8, | |
14, 10, | |
15, 13, | |
15, 15, | |
14, 18, | |
12, 20, | |
9, 21, | |
6, 21, | |
3, 20, | |
2, 19, | |
1, 17 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 54 : 6 | |
12, 3, | |
11, 1, | |
8, 0, | |
6, 0, | |
3, 1, | |
1, 4, | |
0, 9, | |
0, 14, | |
1, 18, | |
3, 20, | |
6, 21, | |
7, 21, | |
10, 20, | |
12, 18, | |
13, 15, | |
13, 14, | |
12, 11, | |
10, 9, | |
7, 8, | |
6, 8, | |
3, 9, | |
1, 11, | |
0, 14 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 55 : 7 | |
14, 0, | |
4, 21 | VECTOR_FONT_POLY_SEPARATOR, | |
0, 0, | |
14, 0 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 56 : 8 | |
5, 0, | |
2, 1, | |
1, 3, | |
1, 5, | |
2, 7, | |
4, 8, | |
8, 9, | |
11, 10, | |
13, 12, | |
14, 14, | |
14, 17, | |
13, 19, | |
12, 20, | |
9, 21, | |
5, 21, | |
2, 20, | |
1, 19, | |
0, 17, | |
0, 14, | |
1, 12, | |
3, 10, | |
6, 9, | |
10, 8, | |
12, 7, | |
13, 5, | |
13, 3, | |
12, 1, | |
9, 0, | |
5, 0 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 57 : 9 | |
13, 7, | |
12, 10, | |
10, 12, | |
7, 13, | |
6, 13, | |
3, 12, | |
1, 10, | |
0, 7, | |
0, 6, | |
1, 3, | |
3, 1, | |
6, 0, | |
7, 0, | |
10, 1, | |
12, 3, | |
13, 7, | |
13, 12, | |
12, 17, | |
10, 20, | |
7, 21, | |
5, 21, | |
2, 20, | |
1, 18 | VECTOR_FONT_POLY_SEPARATOR, | |
// Character code 58 : : | |
5, 14, | |
4, 13, | |
5, 12, | |
6, 13, | |
5, 14 | VECTOR_FONT_POLY_SEPARATOR, | |
5, 2, | |
4, 1, | |
5, 0, | |
6, 1, | |
5, 2 | VECTOR_FONT_POLY_SEPARATOR, | |
]; | |
var vectorFonts = [ | |
[15, 17], // 0 | |
[6, 4], // 1 | |
[14, 14], // 2 | |
[15, 15], // 3 | |
[14, 5], // 4 | |
[14, 17], // 5 | |
[13, 23], // 6 | |
[14, 4], // 7 | |
[14, 29], // 8 | |
[14, 23], // 9 | |
[11, 10] // : | |
]; | |
var VECTOR_FONT_MAX_POLY_SIZE = 30; | |
var vector = {}; | |
function graphicsFillVectorChar(x1, y1, size, ch) { | |
if (size<0) return 0; | |
if (ch<vectorFontOffset || ch-vectorFontOffset>=vectorFontCount) return 0; | |
var vertOffset = 0; | |
var i; | |
var fontOffset = ch-vectorFontOffset; | |
for (i=0;i<fontOffset;i++) | |
vertOffset += vectorFonts[i][1]*2; | |
vector.verCount = vectorFonts[i][1]; | |
vector.width = vectorFonts[i][0]; | |
//console.log("offset:",vertOffset,"width:",vector.width, "verCount:",vector.verCount); | |
var verts = new Array(VECTOR_FONT_MAX_POLY_SIZE*2); | |
var idx=0; | |
for (i=0;i<vector.verCount*2;i+=2) { | |
// translate + scale | |
verts[idx+0] = (x1 + (((vectorFontPolys[vertOffset+i+0])&0x7F)*size | |
+ (VECTOR_FONT_POLY_SIZE/2)) / VECTOR_FONT_POLY_SIZE) | 0; | |
verts[idx+1] = (y1 + (((vectorFontPolys[vertOffset+i+1])&0x7F)*size | |
+ (VECTOR_FONT_POLY_SIZE/2)) / VECTOR_FONT_POLY_SIZE) | 0; | |
//console.log(vertOffset+i,verts[idx+0]|0,verts[idx+1]|0); | |
idx += 2; | |
if ( vectorFontPolys[vertOffset+i+1] & VECTOR_FONT_POLY_SEPARATOR ) { | |
// graphicsFillPoly(gfx,idx/2, verts); | |
//console.log(idx, verts.slice(0,idx)); | |
g.drawPoly(verts.slice(0,idx)); | |
dump(); | |
idx=0; | |
} | |
} | |
return (vector.width * size) / ( VECTOR_FONT_POLY_SIZE * 2 ); | |
} | |
function clear() { | |
if (process.env.BOARD === "LINUX") { | |
g.setColor(1).fillRect(0, 0, g.getWidth(), g.getHeight()); | |
g.setColor(0); | |
} | |
else | |
g.clear().setColor(0, 1, 0); | |
} | |
function dump() { | |
if (process.env.BOARD === "LINUX") g.dump(); | |
} | |
if (process.env.BOARD === "LINUX") { | |
g = Graphics.createArrayBuffer(239, 239, 1); | |
clear(); | |
} else { | |
g.clear().setColor(0, 1, 0); | |
} | |
graphicsFillVectorChar(20,20,200,"0".charCodeAt(0)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment