Konversi font dmd ke gfx (c font vertikal ke horizontal)

Metode menyimpanan data font memiliki perbedaan antara vendor library.

Font Library DMD

DMD, DMD2, DMD3 menggunakan font dengan metode vertikal seperti ditunjukkan dalam diagram berikut:

Font library GFX

Font yang dikembangkan oleh adafruit dalam GFX menggunakan metode mendatar seperti diagram berikut :

Untuk keperluan konversi font dari dmd ke gfx bisa dilakukan dengan metode invert.

Coding berikut ditulis dengan bahasa php, jadi harus menggunakan web server seperti xampp:

<? php
$fontHorizontal = "";
$fontVertikal = "";
$tinggi = 0;
$lebar = 0;
$charCount = 0;
if (isset($_GET['konversiKeHorizontal']))
{
  $fontVertikal = $_GET['fontVertikal'];
  $tinggi = $_GET['tinggi'];
  $lebar = $_GET['lebar'];
  $charCount = $_GET['jumlahKarakter'];


  $verticalHex = str_getcsv ($fontVertikal, ',');
  for ($i = 0; $i < sizeof($verticalHex); $i++)
  {
    $verticalByte[$i] = hexDec($verticalHex[$i]);
  }

  for ($cc = 0; $cc < $charCount; $cc++)
  {
    $horizontalByte = array();
    for ($i = 0; $i < ($tinggi*$lebar / 8); $i++)
    {
      array_push($horizontalByte, 0);
    }

    $bit = 0;
    $byte = 0;
    $indexHorizontal = 0;
    $byteMask = 1;

    for ($x = 0; $x < $lebar; $x++)
    {
      for ($y = 0; $y < $tinggi; $y++)
      {
        $x2 = $x;
        $y2 = $y;
        if ($y >= 8)
        {
          $x2 += ((int)($y / 8) * $lebar);
          $y2 = $y % 8;
        }
        $indexVertical = ($x2 * 8) + $y2 + ($cc*$lebar*$tinggi);

        $indexVerticalByte = (int)($indexVertical / 8);
        $indexVerticalBit = $indexVertical % 8;


        $indexHorizontal = ($y * $lebar ) + $x;
        $indexHorizontalByte = (int)($indexHorizontal / 8);
        $indexHorizontalBit = $indexHorizontal % 8;

        $verticalBit = $verticalByte[$indexVerticalByte] & pow(2, $indexVerticalBit);
        if ($verticalBit)
        {
          $horizontalByte[$indexHorizontalByte] |= pow(2, 7 - $indexHorizontalBit);
        }
      }
    }
    for ($i = 0; $i < sizeof($horizontalByte); $i++)
    {
      $fontHorizontal . = "0x";
      if ($horizontalByte[$i] < 0x10)
      {
        $fontHorizontal . = '0';
      }

      $fontHorizontal . = decHex($horizontalByte[$i]);
      $fontHorizontal . = ', ';
    }
    $fontHorizontal . = '&#13;&#10;';
  }
}
?>

<html>
  <head><title>font Invert ( vertical to horizontal) - semesin.com</title>
  </head>
  <body>
    <h4>Konversi font DMD menjadi font GFX</h4><br>
    <a href="https://www.project.semesin.com/">https://www.project.semesin.com/</a>
    <form action = "" method = "get">
      Font vertikal : <br><textarea name = "fontVertikal" rows = "10" cols = "100%"> <? php echo $fontVertikal ?> < / textarea > <br>
      Tinggi : <input type = "text" name = "tinggi" value = "<?php echo $tinggi ?>"><br>
      Lebar : <input type = "text" name = "lebar" value = "<?php echo $lebar; ?>"><br>
      Jumlah : <input type = "text" name = "jumlahKarakter" value = "<?php echo $charCount; ?>"><br>
      <input type = "submit" name = "konversiKeHorizontal" value = "Konversi ke Horizontal">
    </form>
    Font horizontal : <br><textarea rows = "10" cols = "100%"> <? php echo $fontHorizontal ?> < / textarea > <br>
  </body >
</html >

 

tampilan konversi font dmd ke gfx:

Leave a Reply

Your email address will not be published. Required fields are marked *