% !TeX program = LuaLaTeX
% Copyright (C) 2019-2022 Roberto Giacomelli

\documentclass{article}

\usepackage{fontspec}
\setmainfont{Libertinus Serif}

\usepackage[margin=18mm]{geometry}
\usepackage{array}
\usepackage{booktabs}

\newcolumntype{C}{>{\ttfamily}c}
\newcolumntype{L}{>{\ttfamily}l}

\begin{document}
Goal: describe geometrical object like lines and rectangles
mainly for a barcode drawing library.



\section{\texttt{ga} instruction set}

A graphic data specification format called '\texttt{ga}' \emph{graphic alchemy},
or if you want \emph{generic graphic assembler}.

\begin{verbatim}
ga<DIM, UINT> := generic graphic assembler
    <DIM>  := numeric type parameter for dimension, for example f64 or i32
    <UINT> := numeric type parameter for quantity, an unsigned integer, i.e. u8

ga<DIM, UINT> := +Elem<DIM, UINT>

Elem<DIM, UINT> := Code<u8> + Args<DIM, UINT>

Code<u8> := State<u8> | Object<u8> | Fn<u8>
    State<u8>  :=   1 ->  31 -- graphic properties
    Object<u8> :=  32 -> 239 -- graphic objects
    Fn<u8>     := 240 -> 255 -- functions

Args<DIM, UINT> : <x: DIM> | <e: u8> | <n: UINT> | <c: CHARS>
   <x: DIM>    := a dimension value of type DIM
   <e: u8>     := an enumeration value of type u8 (unsigned byte)
   <n: UINT>   := an unsigned integer for multiplicity
   <c: CHARS>  := chars sequence ended with 0
\end{verbatim}



\section{Properties}

Colors, linecap style etc\dots

\noindent\begin{tabular}{CLlL}
\toprule
OpCode & Mnemonic key & Graphic property & Operands\\
\midrule
 1 & pen\_thick & Line thick          &  <w: DIM>\\
 2 & line\_cap\_style & Line cap style &  <e: u8>\\
 3 & line\_join\_style & Line join style &  <e: u8>\\
 8 & color & ... \\
\midrule
29 & enable\_bbox & start to update the bounding box & -\\
30 & disable\_bbox & Stop to check the bounding box & -\\
31 & set\_bbox & Set a bounding box &  <x1: DIM> <y1: DIM> <x2: DIM> <y2: DIM>\\
\bottomrule
\end{tabular}



\section{Objects}

\subsection{Lines}

A segment that starts from point P1 (x1, y1) and ends to P2 (x2, y2).

\noindent\begin{tabular}{CLlL}
\toprule
OpCode & Mnemonic key & Graphic object & Operands\\
\midrule
32 & line  & Line            & <x1: DIM> <y1: DIM> <x2: DIM> <y2: DIM>\\
33 & hline & Horizontal line & <x1: DIM> <x2: DIM> <y: DIM>\\
34 & vline & Vertical line   & <y1: DIM> <y2: DIM> <x: DIM>\\
\midrule
36 & vbar & Vertical bars     & <y1: DIM> <y2: DIM> <b: UINT> <x1: DIM> <t1: DIM> ...\\
37 & hbar & Horizontal bars   & <x1: DIM> <x2: DIM> <b: UINT> <y1: DIM> <t1: DIM> ...\\
\midrule
38 & polyline & Open polyline  & <n: UINT> <x1: DIM> <y1: DIM> <x2: DIM> <y2: DIM> ...\\
39 & c\_polyline & Closed polyline   & <n: UINT> <x1: DIM> <y1: DIM> <x2: DIM> <y2: DIM> ...\\
\bottomrule
\end{tabular}


\subsection{Rectangles}

\noindent\begin{tabular}{CLlL}
\toprule
OpCode & Mnemonic key & Graphic object & Operands\\
\midrule
 48 & rect & Rectangle & <x1: DIM> <y1: DIM> <x2: DIM> <y2: DIM>\\
 49 & f\_rect & Filled rectangle & <x1: DIM> <y1: DIM> <x2: DIM> <y2: DIM>\\
 50 & rect\_size & Rectangle & <x1: DIM> <y1: DIM> <w: DIM> <h: DIM>\\
 51 & f\_rect\_size & Filled rectangle & <x1: DIM> <y1: DIM> <w: DIM> <h: DIM>\\
\bottomrule
\end{tabular}


\subsection{Text}

\noindent\begin{tabular}{CLl}
\toprule
OpCode & Mnemonic key & Graphic object/Operands\\
\midrule
 130 & text         & A text with several glyphs\\
     & & \ttfamily <ax: FLOAT> <ay: FLOAT> <xpos: DIM> <ypos: DIM> <c: CHARS>\\
\midrule
 131 & text\_xspaced & A text with glyphs equally spaced on its vertical axis\\
     & & \ttfamily <x1: DIM> <xgap: DIM> <ay: FLOAT> <ypos: DIM> <c: CHARS>\\
\midrule
 132 & text\_xwidth & Glyphs equally spaced on vertical axis between two x coordinates\\
      & & \ttfamily <ay: FLOAT> <x1: DIM> <x2: DIM> <y: DIM> <c: CHARS>\\
\midrule
     & under design assessment\\
 140 & \_text\_group & Texts on the same baseline \\
     & & \ttfamily <ay: DIM> <y: DIM> <n: UINT> <<xi: DIM> <ai: FLOAT> <ci: CHARS>> \\
\bottomrule
\end{tabular}


\subsection{Function}


\noindent\begin{tabular}{CLlL}
\toprule
OpCode & Mnemonic key & Function & Operands\\
\midrule
 240 & move & Translate objects &  <n: UINT> <dx: DIM> <dy: UINT>\\
 241 & copy & Copy object &  <n: UINT> <c: UINT> <dx1: DIM> <dy1: UINT> ...\\
 242 & and\_copy & Place and copy objects &  <n: UINT> <c: UINT> <dx1: DIM> <dy1: UINT> ...\\
 243 & grid & Copy next \(n\) objects on a grid &  <n: UINT> <col: UINT> <row: UINT> <dx: DIM> <dy: DIM>\\
 244 & sl\_grid\\
 250 & mirror\\
 255 & comment & A string comment &  <s: STRING>\\
\bottomrule
\end{tabular}


\end{document}
