termfont

Display characters with unicode quadrants and halfblock
git clone https://noulin.net/git/termfont.git
Log | Files | Refs

ttf2Twidfont.c (6117B)


      1 #! /usr/bin/env sheepy
      2 /* or direct path to sheepy: #! /usr/local/bin/sheepy */
      3 
      4 /* Libsheepy documentation: https://spartatek.se/libsheepy/ */
      5 #include "libsheepyObject.h"
      6 
      7 int argc; char **argv;
      8 
      9 /* enable/disable logging */
     10 /* #undef pLog */
     11 /* #define pLog(...) */
     12 
     13 int main(int ARGC, char** ARGV) {
     14 
     15   argc = ARGC; argv = ARGV;
     16 
     17   initLibsheepy(ARGV[0]);
     18   setLogMode(LOG_VERBOSE);
     19   //openProgLogFile();
     20   //setLogSymbols(LOG_UTF8);
     21   //disableLibsheepyErrorLogs;
     22 
     23   //char *fontname        = "../WithheldData-wVKz.ttf";
     24   //int fontSize          = 10;
     25   //char *fontname        = "../Warioland4chmc-VApe.ttf";
     26   //int fontSize          = 15;
     27   /* char *fontname        = "../Trs80Coconut-wX5x.ttf"; */
     28   /* int fontSize          = 16; */
     29   /* char *fontname        = "../ThinPixel7-1Yq0.ttf"; */
     30   /* int fontSize          = 20; */
     31   /* char *fontname        = "../TeenyTinyPixls-o2zo.ttf"; */
     32   /* int fontSize          = 7; */
     33   /* char *fontname        = "../SmartPatrolNbpRegular-0LaP.ttf"; */
     34   /* int fontSize          = 16; */
     35   /* char *fontname        = "../ShylockNbpRegular-zjE1.ttf"; */
     36   /* int fontSize          = 16; */
     37   /* char *fontname        = "../PublicPixel-z84yD.ttf"; */
     38   /* int fontSize          = 16; */
     39   /* char *fontname        = "../PressStart2P-vaV7.ttf"; */
     40   /* int fontSize          = 8; */
     41   /* char *fontname        = "../PixgamerRegular-OVD6A.ttf"; */
     42   /* int fontSize          = 16; */
     43   /* char *fontname        = "../PixeloidSans-nR3g1.ttf"; */
     44   /* int fontSize          = 18; */
     45   /* char *fontname        = "../PixeloidSansBold-RpeJo.ttf"; */
     46   /* int fontSize          = 18; */
     47   /* char *fontname        = "../PixelEmulator-xq08.ttf"; */
     48   /* int fontSize          = 21; */
     49   /* char *fontname        = "../OldSchoolAdventures-42j9.ttf"; */
     50   /* int fontSize          = 15; */
     51   /* char *fontname        = "../NineteenNinetySeven-11XB.ttf"; */
     52   /* int fontSize          = 18; */
     53   /* char *fontname        = "../MozartNbp-93Ey.ttf"; */
     54   /* int fontSize          = 16; */
     55   /* char *fontname        = "../Mecha-GXPg.ttf"; */
     56   /* int fontSize          = 16; */
     57   /* char *fontname        = "../MechaCondensed-zmn4.ttf"; */
     58   /* int fontSize          = 16; */
     59   /* char *fontname        = "../MechaCondensedBold-5mpV.ttf"; */
     60   /* int fontSize          = 16; */
     61   /* char *fontname        = "../MechaBold-j7X0.ttf"; */
     62   /* int fontSize          = 16; */
     63   /* char *fontname        = "../LcdSolid-VPzB.ttf"; // bad */
     64   /* int fontSize          = 25; */
     65   /* char *fontname        = "../InkyThinPixels-MlXn.ttf"; */
     66   /* int fontSize          = 16; */
     67   /* char *fontname        = "../GuruMeditationNbp-GynZ.ttf"; */
     68   /* int fontSize          = 16; */
     69   /* char *fontname        = "../GridkingRegular-77vw.ttf"; */
     70   /* int fontSize          = 20; */
     71   /* char *fontname        = "../GreenScreen-OAj3.ttf"; // bad */
     72   /* int fontSize          = 20; */
     73   /* char *fontname        = "../GamegirlClassic-9MVj.ttf"; */
     74   /* int fontSize          = 8; */
     75   /* char *fontname        = "../G7StarForceTtf-OEg6.ttf"; */
     76   /* int fontSize          = 8; */
     77   /* char *fontname        = "../Fspxkayahd70Regular-08Vo.ttf"; // bad too big */
     78   /* int fontSize          = 35; */
     79   /* char *fontname        = "../EditUndoBrk-RwaV.ttf"; // bad too big */
     80   /* int fontSize          = 24; */
     81   /* char *fontname        = "../DeterminationSansWebRegular-369X.ttf"; */
     82   /* int fontSize          = 16; */
     83   /* char *fontname        = "../DeterminationMonoWebRegular-Z5oq.ttf"; */
     84   /* int fontSize          = 16; */
     85   /* char *fontname        = "../ComputerPixel7-mnL2.ttf"; */
     86   /* int fontSize          = 20; */
     87   /* char *fontname        = "../BittypixMonospace-3gAG.ttf"; */
     88   /* int fontSize          = 8; */
     89   /* char *fontname        = "../8801-DKnR.ttf"; */
     90   /* int fontSize          = 16; */
     91   /* char *fontname        = "../MotleyForcesRegular-w1rZ3.ttf"; */
     92   /* int fontSize          = 72; */
     93   /* char *fontname        = "../Calligrapher-JRxaE.ttf"; // bad */
     94   /* int fontSize          = 30; */
     95   /* char *fontname        = "/home/rlp/Downloads/emulators/amstrad/caprice32/release/cap32-linux/caprice32-latest/resources/vera_mono.ttf"; */
     96   /* int fontSize          = 24; */
     97   /* char *fontname        = "/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf"; */
     98   /* int fontSize          = 40; */
     99   char *fontname        = "/usr/share/fonts/opentype/terminus/terminus-normal.otb";
    100   int fontSize          = 8;
    101 
    102   bool asciiEscape[127] = init0Var;
    103   asciiEscape['"']      = yes;
    104   asciiEscape['\\']     = yes;
    105   asciiEscape['`']      = yes;
    106 
    107   rangeFrom(i, 0x21, 127) {
    108     printf("%c\n", i);
    109     if (asciiEscape[i]) {
    110       if (i == '\\')
    111         systemf("convert -background none -fill black -font %s -pointsize %d label:\"\\\\\\%c\" symbol.png", fontname, fontSize/*pointsize*/, i);
    112       else
    113         systemf("convert -background none -fill black -font %s -pointsize %d label:\"\\%c\" symbol.png", fontname, fontSize/*pointsize*/, i);
    114     }
    115     else
    116       systemf("convert -background none -fill black -font %s -pointsize %d label:\"%c\" symbol.png", fontname, fontSize/*pointsize*/, i);
    117 
    118     cleanListP(txtPixels) = execOut("convert symbol.png txt:-");
    119 
    120     // delete first line (not a pixel)
    121     delElemG(&txtPixels, 0);
    122 
    123     u8 pixels[100][100] = init0Var;
    124 
    125     u32 r = 0; // previous x in loop
    126     u32 x = 0;
    127     u32 y = 0;
    128     forEachS(txtPixels, l) {
    129       // 0,0: (0,0,0,0)  #00000000  graya(0,0)
    130 
    131       char *end = findS(l, ":");
    132       *end = 0;
    133       cleanListP(sl) = splitG(l, ',');
    134       r     = x;
    135       x     = parseInt(sl[0]);
    136       u32 t = parseInt(sl[1]);
    137 
    138       if (t == y+1) {
    139         // new line, add @
    140         pixels[y][r+1] = '@';
    141         y = t;
    142       }
    143 
    144       if (hasG(end+1, "(0,0,0,0)")) {
    145         // black pixel
    146         pixels[y][x] = ' ';
    147       }
    148       else {
    149         // white pixel
    150         pixels[y][x] = 'x';
    151       }
    152     }
    153     pixels[y][x+1] = '@';
    154     pixels[y][x+2] = '@';
    155     range(i, y+1) {
    156       puts(pixels[i]);
    157       //printf("%s#\n",pixels[i]);
    158     }
    159   }
    160   rmAll("symbol.png");
    161 }
    162 // vim: set expandtab ts=2 sw=2: