aboutsummaryrefslogtreecommitdiffstats
path: root/Lessons/Lesson_52/create_font_data.html
diff options
context:
space:
mode:
authorKonstantin Aladyshev <aladyshev22@gmail.com>2021-11-08 18:28:16 +0300
committerKonstantin Aladyshev <aladyshev22@gmail.com>2021-11-08 19:02:59 +0300
commit4e07e8ed4c1971b4c69e94e1141ffe8be8399828 (patch)
tree1a5452434ce1b6dd0b33acc15e2ef28247d2a42f /Lessons/Lesson_52/create_font_data.html
parente87ae15d5615801111b2179f5a2969b27df75295 (diff)
downloadUEFI-Lessons-4e07e8ed4c1971b4c69e94e1141ffe8be8399828.tar.gz
UEFI-Lessons-4e07e8ed4c1971b4c69e94e1141ffe8be8399828.tar.bz2
UEFI-Lessons-4e07e8ed4c1971b4c69e94e1141ffe8be8399828.zip
Add lesson 52
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'Lessons/Lesson_52/create_font_data.html')
-rw-r--r--Lessons/Lesson_52/create_font_data.html100
1 files changed, 100 insertions, 0 deletions
diff --git a/Lessons/Lesson_52/create_font_data.html b/Lessons/Lesson_52/create_font_data.html
new file mode 100644
index 0000000..b00b7ca
--- /dev/null
+++ b/Lessons/Lesson_52/create_font_data.html
@@ -0,0 +1,100 @@
+<html>
+ <head>
+ <style>
+ @font-face {
+ font-family: "AST";
+ src: url(web_ast_premiumexec.woff) format('woff');
+ }
+ </style>
+ </head>
+ <body>
+ <canvas id="canvas" width="32" height="32"></canvas>
+ <script type="text/javascript">
+ function decimalToHex(d, padding) {
+ var hex = Number(d).toString(16);
+ padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
+
+ while (hex.length < padding) {
+ hex = "0" + hex;
+ }
+
+ return hex;
+ }
+
+ function UnicodeToGlyphs(unicode_start_code, unicode_end_code) {
+ const threshold = 100; // `A` threshold to count data as a black pixel
+ const FW = 16;
+ const FH = 19;
+ const left_glyph_start_column = 0;
+ const left_glyph_end_column = FW/2 - 1;
+ const right_glyph_start_column = FW/2;
+ const right_glyph_end_column = FW - 1;
+
+ const canvas = document.getElementById('canvas');
+ canvas.width *= window.devicePixelRatio
+ canvas.height *= window.devicePixelRatio
+ canvas.style.width = 32
+ canvas.style.height = 32
+ const ctx = canvas.getContext('2d');
+ ctx.strokeRect(0, 0, FW, FH);
+ ctx.font = "19px AST"
+ ctx.fillstyle='#00f';
+
+ var wide_glyphs_str="EFI_WIDE_GLYPH gSimpleFontWideGlyphData[] = {<BR>";
+ var narrow_glyphs_str="EFI_NARROW_GLYPH gSimpleFontNarrowGlyphData[] = {<BR>";
+ for(i=unicode_start_code; i<=unicode_end_code; i++){
+ wide_glyph = false;
+ ctx.clearRect(0, 0, FW, FH);
+ ctx.fillText(String.fromCharCode(i), 0, 0 + FW-1);
+ var bitmapimg = ctx.getImageData(0, 0, FW, FH);
+ var bitmap = bitmapimg.data;
+ var left_glyph = " ";
+ var right_glyph = " ";
+ for (row=0; row<FH; row++){
+ left_row = 0;
+ for (col=left_glyph_start_column; col<=left_glyph_end_column; col++){
+ left_row <<= 1
+ if (bitmap[row*FW*4 + col*4 + 3] > threshold)
+ left_row |= 1;
+ }
+ left_glyph += "0x" + decimalToHex(left_row);
+
+ right_row = 0;
+ for (col=right_glyph_start_column; col<=right_glyph_end_column; col++){
+ right_row <<= 1
+ if(bitmap[row*FW*4 + col*4 + 3] > threshold) {
+ wide_glyph = true;
+ right_row |= 1;
+ }
+ }
+ right_glyph += "0x" + decimalToHex(right_row);
+
+ if (row < (FH-1)) {
+ left_glyph += ",";
+ right_glyph += ",";
+ }
+ }
+ if (wide_glyph)
+ wide_glyphs_str += "{ 0x" + decimalToHex(i) + ", 0x00, " + "{" + left_glyph + "}, {" + right_glyph + "}, {0x00,0x00,0x00}}," + "<BR>";
+ else
+ narrow_glyphs_str += "{ 0x" + decimalToHex(i) + ", 0x00, " + "{" + left_glyph + "}},"+ "<BR>";
+ }
+ narrow_glyphs_str += "};<BR>"
+ narrow_glyphs_str += "UINT32 gSimpleFontNarrowBytes = sizeof(gSimpleFontNarrowGlyphData);<BR>"
+ wide_glyphs_str += "{ 0x00, 0x00, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}" + "<BR>"
+ wide_glyphs_str += "};<BR>"
+ wide_glyphs_str += "UINT32 gSimpleFontWideBytes = sizeof(gSimpleFontWideGlyphData);<BR>"
+ return wide_glyphs_str + "<BR>" + narrow_glyphs_str;
+ }
+
+ const unicode_start_code = 0x0400;
+ const unicode_end_code = 0x045F;
+ var f = new FontFace('AST', 'url(web_ast_premiumexec.woff)');
+ f.load().then(function() {
+ document.write(UnicodeToGlyphs(unicode_start_code, unicode_end_code));
+ })
+ </script>
+ </body>
+</html>
+
+