From b5ace0fe467478d11be04649421226e574f4b556 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 13 Jul 2020 21:09:51 +0000 Subject: tikzpackets (13jul20) git-svn-id: svn://tug.org/texlive/trunk@55827 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/tikzpackets/README | 27 ++++ .../doc/latex/tikzpackets/tikzPackets.pdf | Bin 0 -> 65270 bytes .../doc/latex/tikzpackets/tikzPackets.tex | 170 +++++++++++++++++++++ .../tex/latex/tikzpackets/tikzPackets.sty | 138 +++++++++++++++++ Master/tlpkg/bin/tlpkg-ctan-check | 3 +- Master/tlpkg/tlpsrc/collection-pictures.tlpsrc | 1 + Master/tlpkg/tlpsrc/tikzpackets.tlpsrc | 0 7 files changed, 338 insertions(+), 1 deletion(-) create mode 100644 Master/texmf-dist/doc/latex/tikzpackets/README create mode 100644 Master/texmf-dist/doc/latex/tikzpackets/tikzPackets.pdf create mode 100644 Master/texmf-dist/doc/latex/tikzpackets/tikzPackets.tex create mode 100644 Master/texmf-dist/tex/latex/tikzpackets/tikzPackets.sty create mode 100644 Master/tlpkg/tlpsrc/tikzpackets.tlpsrc (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/tikzpackets/README b/Master/texmf-dist/doc/latex/tikzpackets/README new file mode 100644 index 00000000000..9a985463116 --- /dev/null +++ b/Master/texmf-dist/doc/latex/tikzpackets/README @@ -0,0 +1,27 @@ +Package tikzPackets provide command for simple build network packets illustration with tikz. + +Usage example (UDP): + +\begin{tikzpicture} + \packetsInit + \packetsPrintBitScale{31} + + \packetsPutField{16}{Source Port} + \packetsPutField{16}{Destination Port} + \packetsEndLine{0}{} + + \packetsPutField{16}{Length} + \packetsPutField{16}{Checksum} + \packetsEndLine{32}{} + + \packetsPutField[protocolsField, minimum height = 1.5cm]{32}{Data} + \packetsEndLine{64}{} +\end{tikzpicture} + + +Version 1.0 (2020-07-13): first public release + + +Copyright (C) 2020, Robert Ryszard Paciorek + +This is free software distributed under terms of The MIT License. diff --git a/Master/texmf-dist/doc/latex/tikzpackets/tikzPackets.pdf b/Master/texmf-dist/doc/latex/tikzpackets/tikzPackets.pdf new file mode 100644 index 00000000000..7e311747d08 Binary files /dev/null and b/Master/texmf-dist/doc/latex/tikzpackets/tikzPackets.pdf differ diff --git a/Master/texmf-dist/doc/latex/tikzpackets/tikzPackets.tex b/Master/texmf-dist/doc/latex/tikzpackets/tikzPackets.tex new file mode 100644 index 00000000000..585550ebad6 --- /dev/null +++ b/Master/texmf-dist/doc/latex/tikzpackets/tikzPackets.tex @@ -0,0 +1,170 @@ +% Copyright (c) 2020 Robert Ryszard Paciorek +% +% MIT License +% +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +\documentclass[a4paper]{article} + +\usepackage{tikzPackets} +\usepackage{adjustbox,hyperref,fancyvrb-ex,fvextra} + +\oddsidemargin=0pt +\textwidth=430pt + +\topmargin=-30pt +\textheight=662pt + +\newcommand{\pkgLink}[1]{\texttt{\href{https://ctan.org/pkg/#1}{#1}}} + +\fvset{ + breaklines=true, + breakanywhere=true, + breakaftersymbolpre={}, + breakaftersymbolpost={\tiny\ensuremath{\ \lhook\joinrel\rightarrow\ }}, + breakanywheresymbolpre={}, + breakanywheresymbolpost={\tiny\ensuremath{\ \lhook\joinrel\rightarrow\ }} +} + +\begin{document} + +\title{The \texttt{tikzPackets} package} +\author{Robert Ryszard Paciorek } +\date{2020-07-13} +\maketitle + +This package provide command for simple build network packets illustration with \pkgLink{tikz}. +Similar functionality (with tables instead of tikz) provide package \pkgLink{bytefield}. + +\section{Basic Example} + +\begin{CenterExample} +\begin{tikzpicture} + \packetsInit + \packetsBitWidth=4.5mm + \packetsPrintBitScale{31} + + \packetsPutField{16}{Source Port} + \packetsPutField{16}{Destination Port} + \packetsEndLine{0}{} + + \packetsPutField{16}{Length} + \packetsPutField{16}{Checksum} + \packetsEndLine{32}{} + + \packetsPutField[protocolsField, minimum height=1.5cm]{32}{Data} + \packetsEndLine{64}{} +\end{tikzpicture} +\end{CenterExample} + + +\section{Macros description} + +\subsection{packetsInit} + +\Verb$\packetsInit$ is used to initialise \textit{tikzPackets} variables, counters and tikz styles. +Must be used in every \Verb$tikzpicture$ that use \textit{tikzPackets} package commands before any other \textit{tikzPackets} command. + +\subsection{packetsPrintBitScale} + +\Verb$\packetsPrintBitScale$ draw bits scale. It takes one argument: last bit value. + +Formatting of bits scale can be adjust by redefine (after \Verb$\packetsInit$) tikz style \Verb$bitScaleInfo$, redefine \Verb$\packetsBitFont$ or \Verb$\packetsPrintBitNumber$ macro. + +\subsection{packetsPutField} + +\Verb$\packetsPutField$ draw packet field. It takes 4 arguments: +\begin{enumerate} + \item (optional) node style and formatting options + \item number of bits (width of field) + \item (optional) node name for new created node + \item name (text to display) +\end{enumerate} + +\subsection{packetsPrintRangeOnLeft and packetsPrintRangeOnRight} + +\Verb$\packetsPrintRangeOnLeft$ and \Verb$\packetsPrintRangeOnRight$ prints info (start bit number or bits range) on left or right side of current line. +Should be call after call all \Verb$\packetsPutField$ for this line. Both commands takes two arguments: first bit in line and last bit in line, +but \Verb$\packetsPrintRangeOnLeft$ ignore second argument. + +Formatting of printing text can be adjust by redefine \Verb$\packetsBitFont$ macro or redefine \Verb$\packetsPrintRangeOnLeft$ / \Verb$\packetsPrintRangeOnRight$ macros. + +\begin{CenterExample} +\begin{tikzpicture} + \packetsInit + \renewcommand{\packetsBitFont}{\scriptsize} + \packetsPutField{4}{A} \packetsPutField{4}{B} \packetsPutField{4}{C} + \packetsPrintRangeOnLeft{a}{b} + \packetsPrintRangeOnRight{d}{e} +\end{tikzpicture} +\end{CenterExample} + +\subsection{packetsNextLine} + +\Verb$\packetsNextLine$ end current line of field and prepare to start next line of field. It don't have arguments. + +\subsection{packetsEndLine} + +\Verb$\packetsEndLine$ call \Verb$\packetsPrintRangeOnLeft$ and \Verb$\packetsNextLine$. +Arguments are passed to \Verb$\packetsPrintRangeOnLeft$. + +\subsection{packetsLastNode and packetsFirstNodeInLastLine} + +\Verb$\packetsLastNode$ hold name of last added node by \Verb$\packetsPutField$ or \Verb$\packetsPrintBitScale$ (and is used for node positioning in \Verb$\packetsPutField$ and \Verb$\packetsPrintRangeOnRight$ macros). + +\Verb$\packetsFirstNodeInLastLine$ hold name of first node (added by macro \Verb$\packetsPutField$ or \Verb$\packetsPrintBitScale$) in current line (and is used in \Verb$\packetsPutField$ and \Verb$\packetsPrintRangeOnLeft$ for positioning) + +Both can be use for external to reference node adding by these macros (can be captured after add node by \Verb$\edef$) or can be used to start adding nodes by \Verb$\packetsPutField$ relative to some manually added node. + +\begin{CenterExample} +\begin{tikzpicture} + \packetsInit + \packetsPutField{4}{A} + \packetsPutField{4}{B} + + \node[ + align=left, anchor=north west, + text width=7\packetsBitWidth, node font=\footnotesize + ] [] at (\packetsFirstNodeInLastLine.south west) { + Some extra info about this packet. And more more info \ldots + }; +\end{tikzpicture} +\end{CenterExample} + +\section{Styles and dimmensions} + +Width of single bit is set by \Verb$\packetsBitWidth$ and default is 5mm. Default style for node created by \Verb$\packetsPutField$ is \Verb$protocolsField$ and it set line height to 1cm. +Package provide also \Verb$protocolsFieldBase$ style with minimal setting for node style. +Macro \Verb$\packetsBitFont$ define font settings for bits info. +All this change should be done after use \Verb$\packetsInit$. + +\begin{CenterExample} +\begin{tikzpicture} + \packetsInit + \tikzstyle{protocolsField}=[protocolsFieldBase, draw, minimum height = 0.8cm] + \packetsBitWidth=10mm + \renewcommand{\packetsBitFont}{\scriptsize\it} + + \packetsPrintBitScale{7} + \packetsPutField{4}{Long field names} + \packetsPutField{4}{and low rows} +\end{tikzpicture} +\end{CenterExample} + +\end{document} diff --git a/Master/texmf-dist/tex/latex/tikzpackets/tikzPackets.sty b/Master/texmf-dist/tex/latex/tikzpackets/tikzPackets.sty new file mode 100644 index 00000000000..01c8546e3ba --- /dev/null +++ b/Master/texmf-dist/tex/latex/tikzpackets/tikzPackets.sty @@ -0,0 +1,138 @@ +% Copyright (c) 2020 Robert Ryszard Paciorek +% +% MIT License +% +% Permission is hereby granted, free of charge, to any person obtaining a copy +% of this software and associated documentation files (the "Software"), to deal +% in the Software without restriction, including without limitation the rights +% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +% copies of the Software, and to permit persons to whom the Software is +% furnished to do so, subject to the following conditions: +% +% The above copyright notice and this permission notice shall be included in all +% copies or substantial portions of the Software. +% +% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +% SOFTWARE. + +% Version 1.0 (2020-07-13): first public release + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{tikzPackets} + +\RequirePackage{tikz} + +\RequirePackage{xparse} + +% need by \packetsPrintRangeOnRight: +\ifdefined\tcbsetmacrotoheightofnode\else\RequirePackage[skins]{tcolorbox}\fi +\RequirePackage{pbox} + +% +% init counters, etc +% + +\newdimen\packetsBitWidth\packetsBitWidth=5mm +\newcounter{packets@FieldCounter} + +\newcommand{\packetsInit}{ + \let\packetsFirstNodeInLastLine\undefined + \let\packets@ContinueLine\undefined + \setcounter{packets@FieldCounter}{0} + \newcommand{\packetsBitFont}{\tiny} + \packetsBitWidth=5mm + \tikzstyle{protocolsFieldBase}=[ + anchor = north west, outer sep = 0pt % node position <=> position of left upper node corner + ] + \tikzstyle{protocolsField}=[ + protocolsFieldBase, + draw, minimum height = 1cm, + ] + \tikzstyle{bitScaleInfo}=[ + protocolsFieldBase, inner sep = 0pt, + minimum width = \packetsBitWidth, minimum height = 8pt, + node font=\packetsBitFont + ] +} + +% +% print bits numbering +% + + +\newcommand{\packetsPrintBitNumber}[1]{ + \parbox[b][5pt]{\packetsBitWidth}{\hspace{1pt}#1} +} + +\newcommand{\packetsPrintBitScale}[1]{ + \node [bitScaleInfo] (bitScaleInfo_0) {\packetsPrintBitNumber{0}}; + \foreach \n[remember=\n as \lastn (initially 0)] in {1,...,#1} { + \node [bitScaleInfo] (bitScaleInfo_\n) [] at (bitScaleInfo_\lastn.north east) {\packetsPrintBitNumber{\n}}; + \draw[thin] (bitScaleInfo_\n.south west) |- (bitScaleInfo_\n.north west); + } + \draw (bitScaleInfo_0.south west) |- (bitScaleInfo_0.north west); + \draw (bitScaleInfo_#1.south east) |- (bitScaleInfo_#1.north east); + + \def\packetsFirstNodeInLastLine{bitScaleInfo_0} + \def\packetsLastNode{bitScaleInfo_#1} +} + +\newcommand{\packetsPrintRangeOnRight}[3][\packetsLastNode]{ + \tcbsetmacrotoheightofnode{\packets@NodeHeight}{#1} + \node [anchor = south, outer sep = 2pt, inner sep = 0pt, rotate = -90, align=center, node font=\packetsBitFont] [] at (#1.east) {\pbox{\packets@NodeHeight}{#2-#3}}; +} + +\newcommand{\packetsPrintRangeOnLeft}[3][\packetsFirstNodeInLastLine]{ + \node [anchor = east, outer sep = 2pt, inner sep = 0pt, align=center, node font=\packetsBitFont] [] at (#1.west) {#2}; +} + +% +% add protocol fields +% +%\newcommand{\packetsPutField}[3][protocolsField]{ +\NewDocumentCommand{\packetsPutField}{ O{protocolsField} m o m } { + % if provide custom node name, use it + \IfValueTF {#3} { + \edef\packets@NewNodeName{#3} + }{ + % otherwise get new node name and step counter + \edef\packets@NewNodeName{packetsFieldNode_\arabic{packets@FieldCounter}} + \stepcounter{packets@FieldCounter} + } + + % if continue line + \ifdefined\packets@ContinueLine + \node[#1, minimum width=#2\packetsBitWidth] (\packets@NewNodeName) [] at (\packetsLastNode.north east) {#4}; + % if start new line + \else + % if not first line + \ifdefined\packetsFirstNodeInLastLine + \node[#1, minimum width=#2\packetsBitWidth] (\packets@NewNodeName) [] at (\packetsFirstNodeInLastLine.south west) {#4}; + \else + \node[#1, minimum width=#2\packetsBitWidth] (\packets@NewNodeName) {#4}; + \fi + \let\packetsFirstNodeInLastLine\packets@NewNodeName + \def\packets@ContinueLine{true} + \fi + + % remember new node name as \packetsLastNode + \let\packetsLastNode\packets@NewNodeName +} + +% +% finish line of fields +% + +\newcommand{\packetsNextLine}{ + \let\packets@ContinueLine\undefined +} + +\newcommand{\packetsEndLine}[2]{ + \packetsPrintRangeOnLeft{#1}{#2} + \packetsNextLine +} diff --git a/Master/tlpkg/bin/tlpkg-ctan-check b/Master/tlpkg/bin/tlpkg-ctan-check index fbf47e5798c..65d9c5668a4 100755 --- a/Master/tlpkg/bin/tlpkg-ctan-check +++ b/Master/tlpkg/bin/tlpkg-ctan-check @@ -736,7 +736,8 @@ my @TLP_working = qw( tikz-relay tikz-sfc tikz-timing tikz-trackschematic tikz-truchet tikzcodeblocks tikzducks tikzinclude tikzlings tikzmark tikzmarmots tikzorbital - tikzpagenodes tikzpeople tikzpfeile tikzposter tikzscale tikzsymbols + tikzpackets tikzpagenodes tikzpeople tikzpfeile tikzposter + tikzscale tikzsymbols tikztosvg tile-graphic timbreicmc times timetable timing-diagrams tinos tipa tipa-de tipfr titlecaps titlefoot titlepages titlepic titleref titlesec titling diff --git a/Master/tlpkg/tlpsrc/collection-pictures.tlpsrc b/Master/tlpkg/tlpsrc/collection-pictures.tlpsrc index 2cee0cc8818..382cb41e249 100644 --- a/Master/tlpkg/tlpsrc/collection-pictures.tlpsrc +++ b/Master/tlpkg/tlpsrc/collection-pictures.tlpsrc @@ -180,6 +180,7 @@ depend tikzmark depend tikzmarmots depend tikzorbital depend tikzpagenodes +depend tikzpackets depend tikzpfeile depend tikzpeople depend tikzposter diff --git a/Master/tlpkg/tlpsrc/tikzpackets.tlpsrc b/Master/tlpkg/tlpsrc/tikzpackets.tlpsrc new file mode 100644 index 00000000000..e69de29bb2d -- cgit v1.2.3