Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) DotMatrix

 

STLQt CreatorLubuntu

 

DotMatrix is a class for creating dot matrix texts.

Technical facts

 

 

 

 

 

 

./CppDotMatrix/CppDotMatrix.pri

 

INCLUDEPATH += \
    ../../Classes/CppDotMatrix

SOURCES += \
    ../../Classes/CppDotMatrix/dotmatrixchar.cpp \
    ../../Classes/CppDotMatrix/dotmatrixstring.cpp \
    ../../Classes/CppDotMatrix/dotmatrixtext.cpp

HEADERS  += \
    ../../Classes/CppDotMatrix/dotmatrixstring.h \
    ../../Classes/CppDotMatrix/dotmatrixchar.h \
    ../../Classes/CppDotMatrix/dotmatrixtext.h

OTHER_FILES += \
    ../../Classes/CppDotMatrix/Licence.txt

 

 

 

 

 

./CppDotMatrix/dotmatrixchar.h

 

#ifndef RIBI_DOTMATRIXCHAR_H
#define RIBI_DOTMATRIXCHAR_H

#include <iosfwd>
#include <string>
#include <vector>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <boost/array.hpp>
#include <boost/checked_delete.hpp>
#include <boost/shared_ptr.hpp>
#pragma GCC diagnostic pop

struct QImage;

namespace ribi {

///DotMatrixChar creates a dot matrix 2D array of a character
struct DotMatrixChar
{
  DotMatrixChar(const char c);

  boost::shared_ptr<QImage> CreateImage() const noexcept;

  ///Read back the character
  char GetChar() const noexcept { return m_c; }

  ///Read if the coordinat is black/high or white/low
  bool GetMatrix(const int x, const int y) const;

  ///Get the matrix height
  int GetMatrixHeight() const noexcept { return 7; }

  ///Get the matrix width
  int GetMatrixWidth() const noexcept { return 5; }

  static std::string GetVersion() noexcept;
  static std::vector<std::string> GetVersionHistory() noexcept;

  private:
  ~DotMatrixChar() noexcept {}
  friend void boost::checked_delete<>(      DotMatrixChar*);
  friend void boost::checked_delete<>(const DotMatrixChar*);
  ///The character
  const char m_c;

  ///The character matrix
  const boost::array<boost::array<int,5> ,7> m_matrix;

  ///Obtain a y-x ordered matrix of a character
  ///Returns a matrix with zeroes of the character is not found
  ///Dot-matrix characters are
  ///size 5 (width) x 7 (height) pixels, excluding empty spacer pixels
  ///size 6 (width) x 8 (height) pixels, including empty spacer pixels
  static boost::array<boost::array<int,5> ,7> GetChar(const char c) noexcept;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

std::ostream& operator<<(std::ostream& os, const DotMatrixChar& m);

} //~namespace ribi

#endif // RIBI_DOTMATRIXCHAR_H

 

 

 

 

 

./CppDotMatrix/dotmatrixchar.cpp

 

#include "dotmatrixchar.h"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <cassert>

#include <QImage>

#include "testtimer.h"
#include "trace.h"
#pragma GCC diagnostic pop

ribi::DotMatrixChar::DotMatrixChar(const char c)
  : m_c(c),
    m_matrix(GetChar(c))
{
  assert(!m_matrix.empty());
  assert(GetMatrixHeight() == static_cast<int>(m_matrix.size()));
  assert(GetMatrixWidth()  == static_cast<int>(m_matrix[0].size()));
}

boost::shared_ptr<QImage> ribi::DotMatrixChar::CreateImage() const noexcept
{
  const int height = GetMatrixHeight();
  const int width  = GetMatrixWidth();
  const boost::shared_ptr<QImage> image {
    new QImage(width,height,QImage::Format_RGB32)
  };

  for (int y=0; y!=height; ++y)
  {
    for (int x=0; x!=width; ++x)
    {
      const bool b = GetMatrix(x,y);
      const QRgb color( b ? qRgb(0,0,0) : qRgb(255,255,255) );
      image->setPixel(x,y,color);
    }
  }
  return image;
}

boost::array<boost::array<int,5> ,7> ribi::DotMatrixChar::GetChar(const char c) noexcept
{
  //Create a 5 (width) x 7 (height) 2D array
  boost::array<boost::array<int,5> ,7> v;

  switch(c)
  {
    //Note: indices are y-x-ordered!
    case ' ':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '!':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case '"':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 0; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 0; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '#':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 0; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 0; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 1; v[4][2] = 1; v[4][3] = 1; v[4][4] = 1;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 1; v[6][4] = 0;
      break;
    case '$':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 1; v[1][3] = 1; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 1; v[5][2] = 1; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case '%':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 1; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 1; v[6][4] = 1;
      break;
    case '&':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 0; v[6][4] = 1;
      break;
    case '\'':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '(':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 1; v[6][4] = 0;
      break;
    case ')':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '*':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '+':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case ',':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '-':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '.':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case '/':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '0':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case '1':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case '2':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 1;
      break;
    case '3':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 1;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case '4':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 1; v[4][2] = 1; v[4][3] = 1; v[4][4] = 1;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 1; v[6][4] = 0;
      break;
    case '5':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case '6':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case '7':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 1;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '8':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case '9':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;

    case ':':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case ';':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case '<':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 1; v[6][4] = 0;
      break;
    case '=':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 1; v[5][2] = 1; v[5][3] = 1; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '>':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '?':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case '@':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 1; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;

    case 'A':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'B':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'C':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'D':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'E':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 1;
      break;
    case 'F':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'G':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 1; v[3][3] = 1; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 1;
      break;
    case 'H':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'I':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'J':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'K':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'L':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 1;
      break;
    case 'M':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 1; v[1][2] = 0; v[1][3] = 1; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'N':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 1; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 1; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'O':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'P':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'Q':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'R':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'S':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 1; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'T':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 1;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'U':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'V':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'W':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'X':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'Y':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'Z':
      v[0][0] = 1; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 1;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 1;
      break;
    case '[':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case ']':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case '^':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 0; v[1][3] = 1; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '_':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 1;
      break;
    case '`':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'a':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 1; v[4][3] = 1; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 1;
      break;
    case 'b':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'c':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'd':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 1;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 1;
      break;
    case 'e':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 1; v[4][2] = 1; v[4][3] = 1; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'f':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 0; v[1][3] = 0; v[1][4] = 1;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'g':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 1; v[1][3] = 1; v[1][4] = 1;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 1; v[4][3] = 1; v[4][4] = 1;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'h':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'i':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'j':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'k':
      v[0][0] = 1; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 1; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'l':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'm':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 1; v[2][2] = 0; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'n':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'o':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'p':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 1; v[4][2] = 1; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'q':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 1; v[4][3] = 1; v[4][4] = 1;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'r':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case 's':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 1; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 't':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 1; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 1; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'u':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 0; v[5][3] = 1; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'v':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case 'w':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 1; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 1;
      v[5][0] = 1; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'x':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 1; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 1;
      break;
    case 'y':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 1;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 1; v[4][2] = 1; v[4][3] = 1; v[4][4] = 1;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 0;
      break;
    case 'z':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 1; v[2][1] = 1; v[2][2] = 1; v[2][3] = 1; v[2][4] = 1;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 1; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 1; v[6][1] = 1; v[6][2] = 1; v[6][3] = 1; v[6][4] = 1;
      break;
    case '{':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 1; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 1; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 1; v[6][4] = 0;
      break;
    case '|':
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 1; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 1; v[6][3] = 0; v[6][4] = 0;
      break;
    case '}':
      v[0][0] = 0; v[0][1] = 1; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 1; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 1; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 1; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 1; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 1; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 1; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '\\': //Own addition
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 1; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 1;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    case '~': //Own addition
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 1; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 1; v[3][1] = 0; v[3][2] = 1; v[3][3] = 0; v[3][4] = 1;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 1; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
    default:
      v[0][0] = 0; v[0][1] = 0; v[0][2] = 0; v[0][3] = 0; v[0][4] = 0;
      v[1][0] = 0; v[1][1] = 0; v[1][2] = 0; v[1][3] = 0; v[1][4] = 0;
      v[2][0] = 0; v[2][1] = 0; v[2][2] = 0; v[2][3] = 0; v[2][4] = 0;
      v[3][0] = 0; v[3][1] = 0; v[3][2] = 0; v[3][3] = 0; v[3][4] = 0;
      v[4][0] = 0; v[4][1] = 0; v[4][2] = 0; v[4][3] = 0; v[4][4] = 0;
      v[5][0] = 0; v[5][1] = 0; v[5][2] = 0; v[5][3] = 0; v[5][4] = 0;
      v[6][0] = 0; v[6][1] = 0; v[6][2] = 0; v[6][3] = 0; v[6][4] = 0;
      break;
  }
  return v;
}

bool ribi::DotMatrixChar::GetMatrix(const int x, const int y) const
{
  assert(!m_matrix.empty());
  assert(GetMatrixHeight() == static_cast<int>(m_matrix.size()));
  assert(GetMatrixWidth()  == static_cast<int>(m_matrix[0].size()));
  assert(x >= 0);
  assert(x < GetMatrixWidth());
  assert(y >= 0);
  assert(y < GetMatrixHeight());
  return m_matrix[y][x];
}

std::string ribi::DotMatrixChar::GetVersion() noexcept
{
  return "1.1";
}

std::vector<std::string> ribi::DotMatrixChar::GetVersionHistory() noexcept
{
  return {
    "201x-xx-xx: Version 1.0: initial version",
    "2014-02-27: Version 1.1: started versioning"
  };
}

#ifndef NDEBUG
void ribi::DotMatrixChar::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
}
#endif

std::ostream& ribi::operator<<(std::ostream& os, const DotMatrixChar& m)
{
  const int height = m.GetMatrixHeight();
  const int width   = m.GetMatrixWidth();
  for (int y=0; y!=height; ++y)
  {
    for (int x=0; x!=width; ++x)
    {
      os << m.GetMatrix(x,y);
    }
    if (y + 1 != height) os << '\n';
  }
  return os;
}

 

 

 

 

 

./CppDotMatrix/dotmatrixstring.h

 

#ifndef RIBI_DOTMATRIXSTRING_H
#define RIBI_DOTMATRIXSTRING_H

#include <string>
#include <vector>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <boost/shared_ptr.hpp>
#pragma GCC diagnostic pop

struct QImage;

namespace ribi {

struct DotMatrixChar;

///DotMatrixString creates a dot matrix 2D array of a string
struct DotMatrixString
{
  ///Give it a std::string and a spacing (number of pixels) between the characters
  DotMatrixString(const std::string& s = "", const int spacing = 0);

  boost::shared_ptr<QImage> CreateImage() const noexcept;

  ///Read back the string
  std::string GetString() const noexcept;

  ///Read if the coordinat is black/high or white/low
  bool GetMatrix(const int x, const int y) const noexcept;

  ///Get the matrix height
  int GetMatrixHeight() const noexcept;

  ///Get the matrix width
  int GetMatrixWidth() const noexcept;

  static std::string GetVersion() noexcept;
  static std::vector<std::string> GetVersionHistory() noexcept;

  private:
  const int m_spacing;
  const std::vector<boost::shared_ptr<const DotMatrixChar>> m_v;

  static std::vector<boost::shared_ptr<const DotMatrixChar>>
    CreateDotMatrixChars(const std::string& s) noexcept;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

std::ostream& operator<<(std::ostream& os, const DotMatrixString& m) noexcept;

} //~namespace ribi

#endif // RIBI_DOTMATRIXSTRING_H

 

 

 

 

 

./CppDotMatrix/dotmatrixstring.cpp

 

#include "dotmatrixstring.h"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"

#include <QImage>

#include "dotmatrixchar.h"
#include "testtimer.h"
#include "trace.h"
#pragma GCC diagnostic pop

ribi::DotMatrixString::DotMatrixString(const std::string& s,
  const int spacing)
  : m_spacing(spacing),
    m_v{CreateDotMatrixChars(s)}
{
  #ifndef NDEBUG
  Test();
  #endif
  assert(m_spacing >= 0);
  assert(GetString() == s);
}

std::vector<boost::shared_ptr<const ribi::DotMatrixChar>>
  ribi::DotMatrixString::CreateDotMatrixChars(const std::string& s) noexcept
{
  std::vector<boost::shared_ptr<const DotMatrixChar>> v;
  for (const char c: s)
  {
    boost::shared_ptr<const DotMatrixChar> p {
      new DotMatrixChar(c)
    };
    assert(p);
    v.push_back(p);
  }
  return v;
}

boost::shared_ptr<QImage> ribi::DotMatrixString::CreateImage() const noexcept
{
  const int height = GetMatrixHeight();
  const int width  = GetMatrixWidth();
  const boost::shared_ptr<QImage> image {
    new QImage(width,height,QImage::Format_RGB32)
  };

  for (int y=0; y!=height; ++y)
  {
    for (int x=0; x!=width; ++x)
    {
      const bool b = GetMatrix(x,y);
      const QRgb color( b ? qRgb(0,0,0) : qRgb(255,255,255) );
      image->setPixel(x,y,color);
    }
  }
  return image;
}


std::string ribi::DotMatrixString::GetString() const noexcept
{
  std::string s;
  for (const auto& c: m_v) { s += c->GetChar(); }
  return s;
}

bool ribi::DotMatrixString::GetMatrix(const int x, const int y) const noexcept
{
  assert(x >= 0);
  assert(x < GetMatrixWidth());
  assert(y >= 0);
  if (!(y < GetMatrixHeight()))
  {
    TRACE("BREAK");
  }
  assert(y < GetMatrixHeight());
  assert(!m_v.empty());
  assert(m_v[0]);
  const int char_width = m_v[0]->GetMatrixWidth() + m_spacing;
  const int char_index = x / char_width;
  const int char_x     = x % char_width;
  assert(char_index < static_cast<int>(m_v.size()));
  assert(m_v[char_index]);
  const boost::shared_ptr<const DotMatrixChar> m = m_v[char_index];
  if ( char_x >= m->GetMatrixWidth()
    ||      y >= m->GetMatrixHeight())
  {
    //In spacing
    return false;
  }
  return m->GetMatrix(char_x,y);

}

int ribi::DotMatrixString::GetMatrixHeight() const noexcept
{
  if (m_v.empty()) return 0;
  return m_v[0]->GetMatrixHeight() + m_spacing;
}

int ribi::DotMatrixString::GetMatrixWidth() const noexcept
{
  if (m_v.empty()) return 0;
  const int n_chars = static_cast<int>(m_v.size());
  assert(m_v[0]);
  const int char_width = m_v[0]->GetMatrixWidth() + m_spacing;
  return n_chars * char_width;
}

std::string ribi::DotMatrixString::GetVersion() noexcept
{
  return "1.1";
}

std::vector<std::string> ribi::DotMatrixString::GetVersionHistory() noexcept
{
  return {
    "201x-xx-xx: Version 1.0: initial version",
    "2014-02-27: Version 1.1: started versioning"
  };
}

#ifndef NDEBUG
void ribi::DotMatrixString::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  const std::string text = "Hello world";
  const int spacing = 1;
  const boost::shared_ptr<const ribi::DotMatrixString> m {
    new ribi::DotMatrixString(text,spacing)
  };
  std::stringstream s;
  s << *m;
  assert(!s.str().empty());
}
#endif

std::ostream& ribi::operator<<(std::ostream& os, const DotMatrixString& m) noexcept
{
  const int height  = m.GetMatrixHeight();
  const int width   = m.GetMatrixWidth();
  for (int y=0; y!=height; ++y)
  {
    for (int x=0; x!=width; ++x)
    {
      os << m.GetMatrix(x,y);
    }
    if (y + 1 != height) os << '\n';
  }
  return os;
}

 

 

 

 

 

./CppDotMatrix/dotmatrixtext.h

 

#ifndef RIBI_DOTMATRIXTEXT_H
#define RIBI_DOTMATRIXTEXT_H

#include <string>
#include <vector>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include <boost/shared_ptr.hpp>
#pragma GCC diagnostic pop

struct QImage;

namespace ribi {

struct DotMatrixString;

///DotMatrixString creates a dot matrix 2D array of a string
struct DotMatrixText
{
  enum class ColorSystem { normal, inverted };
  ///Give it a std::string and a spacing (number of pixels) between the characters
  DotMatrixText(
    const std::vector<std::string>& s,
    const int spacing,
    const ColorSystem color_system = ColorSystem::normal);

  boost::shared_ptr<QImage> CreateImage() const noexcept;

  ///Read back the string
  std::vector<std::string> GetText() const noexcept;

  ///Read if the coordinat is black/high or white/low
  bool GetMatrix(const int x, const int y) const noexcept;

  ///Get the matrix height
  int GetMatrixHeight() const noexcept;

  ///Get the matrix width
  int GetMatrixWidth() const noexcept;

  static std::string GetVersion() noexcept;
  static std::vector<std::string> GetVersionHistory() noexcept;

  private:
  const ColorSystem m_color_system;
  const int m_spacing;
  const std::vector<boost::shared_ptr<const DotMatrixString>> m_v;

  static std::vector<boost::shared_ptr<const DotMatrixString>>
    CreateDotMatrixText(const std::vector<std::string>& s, const int spacing) noexcept;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

std::ostream& operator<<(std::ostream& os, const DotMatrixText& m) noexcept;

} //~namespace ribi


#endif // RIBI_DOTMATRIXTEXT_H

 

 

 

 

 

./CppDotMatrix/dotmatrixtext.cpp

 

#include "dotmatrixtext.h"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include "dotmatrixstring.h"

#include <cassert>

#include <QImage>

#include "dotmatrixchar.h"
#include "testtimer.h"
#include "trace.h"
#pragma GCC diagnostic pop

ribi::DotMatrixText::DotMatrixText(
  const std::vector<std::string>& s,
  const int spacing,
  const ColorSystem color_system
)
  : m_color_system(color_system),
    m_spacing(spacing),
    m_v{CreateDotMatrixText(s,spacing)}
{
  assert(m_spacing >= 0);
  assert(GetText() == s);
}

std::vector<boost::shared_ptr<const ribi::DotMatrixString>>
  ribi::DotMatrixText::CreateDotMatrixText(
    const std::vector<std::string>& text,
    const int spacing
  ) noexcept
{
  std::vector<boost::shared_ptr<const DotMatrixString>> v;
  for (const std::string line: text)
  {
    boost::shared_ptr<const DotMatrixString> s {
      new DotMatrixString(line,spacing)
    };
    assert(s);
    v.push_back(s);
  }
  return v;
}

boost::shared_ptr<QImage> ribi::DotMatrixText::CreateImage() const noexcept
{
  const int total_height = GetMatrixHeight();
  const int line_height  = m_v[0]->GetMatrixHeight() + m_spacing;
  const int total_width  = GetMatrixWidth();
  const boost::shared_ptr<QImage> image {
    new QImage(total_width,total_height,QImage::Format_RGB32)
  };
  int offset = 0;
  for (const auto& v: m_v)
  {
    const int height = line_height;
    const int width  = total_width;
    for (int y=0; y!=height; ++y)
    {
      for (int x=0; x!=width; ++x)
      {
        const bool matrix_color
          = y < v->GetMatrixHeight()
          && x < v->GetMatrixWidth()
          && v->GetMatrix(x,y);
        const bool final_color {
            m_color_system == ColorSystem::normal
          ?  matrix_color
          : !matrix_color
        };
        const QRgb color( final_color ? qRgb(0,0,0) : qRgb(255,255,255) );
        image->setPixel(x,offset + y,color);
      }
    }

    offset += height;
  }
  return image;
}

std::vector<std::string> ribi::DotMatrixText::GetText() const noexcept
{
  std::vector<std::string> s;
  for (const auto& c: m_v) { s.push_back(c->GetString()); }
  return s;
}

bool ribi::DotMatrixText::GetMatrix(const int x, const int y) const noexcept
{
  assert(x >= 0);
  assert(x < GetMatrixWidth());
  assert(y >= 0);
  assert(y < GetMatrixHeight());
  assert(!m_v.empty());
  assert(m_v[0]);
  const int char_width  = m_v[0]->GetMatrixWidth()  + m_spacing;
  const int char_height = m_v[0]->GetMatrixHeight() + m_spacing;
  const int line_index = y / char_height;
  const int char_x     = x % char_width;
  const int char_y     = y % char_height;
  assert(line_index < static_cast<int>(m_v.size()));
  assert(m_v[line_index]);
  if (char_y >= m_v[line_index]->GetMatrixHeight()) return false;
  return m_v[line_index]->GetMatrix(char_x,char_y);
}

int ribi::DotMatrixText::GetMatrixHeight() const noexcept
{
  if (m_v.empty()) return 0;
  return (m_v[0]->GetMatrixHeight() + m_spacing) * static_cast<int>(m_v.size());
}

int ribi::DotMatrixText::GetMatrixWidth() const noexcept
{
  if (m_v.empty()) return 0;
  return (*std::max_element(m_v.begin(),m_v.end(),
    [](const boost::shared_ptr<const DotMatrixString>& lhs, const boost::shared_ptr<const DotMatrixString>& rhs)
    {
      assert(lhs);
      assert(rhs);
      return lhs->GetMatrixWidth() < rhs->GetMatrixWidth();
    }
  ))->GetMatrixWidth();
}

std::string ribi::DotMatrixText::GetVersion() noexcept
{
  return "1.1";
}

std::vector<std::string> ribi::DotMatrixText::GetVersionHistory() noexcept
{
  return {
    "201x-xx-xx: Version 1.0: initial version",
    "2014-02-27: Version 1.1: started versioning"
  };
}

#ifndef NDEBUG
void ribi::DotMatrixText::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
}
#endif


std::ostream& ribi::operator<<(std::ostream& os, const DotMatrixText& m) noexcept
{
  const int height  = m.GetMatrixHeight();
  const int width   = m.GetMatrixWidth();
  for (int y=0; y!=height; ++y)
  {
    for (int x=0; x!=width; ++x)
    {
      os << m.GetMatrix(x,y);
    }
    if (y + 1 != height) os << '\n';
  }
  return os;
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml