Skip to content

Commit

Permalink
Merge pull request #35 from EagleoutIce/34-add-a-classic-option
Browse files Browse the repository at this point in the history
New `classic` option
  • Loading branch information
EagleoutIce authored Sep 24, 2024
2 parents d2c0cd2 + e72d381 commit 747f5b1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .latexmkrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@default_files = ('qr-example.tex', 'fancyqr-doc.tex');
@default_files = ('qr-minimal.tex', 'qr-example.tex', 'fancyqr-doc.tex');
$pdf_mode = 1;
$pdf_update_method = 1;
$out_dir = 'build';
Expand Down
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[<img src="https://github.com/EagleoutIce/fancyqr/blob/gh-pages/preview-1.png?raw=true" width="600"/>](qr-example.tex)

A simple package to create fancy qr-codes with the help of the [`qrcode`][qrcode]-package.
You may use `\fancyqr` just like the normal `\qrcode` (`\fancyqr[<qr-options>]{<url>}`). See the [documentation](https://media.githubusercontent.com/media/EagleoutIce/fancyqr/gh-pages/build/fancyqr-doc.pdf).
You may use `\fancyqr` just like the normal `\qrcode` (`\fancyqr[<qr-options>]{<url>}`). See the [documentation](https://media.githubusercontent.com/media/EagleoutIce/fancyqr/gh-pages/build/fancyqr-doc.pdf). If you just want to create a simple qr-code, please refer to the [minimal example](qr-minimal.tex).

*fancyqr* is actively developed by *Florian Sihler* (contact me at: <[email protected]>) under the [GPLv3 License](LICENSE). I am very happy about every contribution (see [CONTRIBUTING.md](CONTRIBUTING.md)). You can find it on CTAN (<https://www.ctan.org/pkg/fancyqr>).

Expand All @@ -14,26 +14,27 @@ At the moment, there are six other styles (`flat`, `frame`, `blobs`, `glitch`, a

There are the following extra qr-options (you can set all of them with `\fancyqrset{<keys>}`):

| Option | Type | Default | Explanation |
| ----------------- | ----------- | :------: | --------------------------------------------------------------------------------------------- |
| `color` | color | | Disables the `gradient` and sets the qr color accordingly. |
| `gradient angle` | angle | `135` | Change the gradient angle. |
| `gradient` | boolean | true | Toggle the color gradient |
| `image` | LaTeX | | Automatically center an image.[^1] |
| `image padding` | number | | Additionally hide blocks (x & y) around the image. |
| `image x padding` | number | `0` | Additionally hide blocks (x) around the image. |
| `image y padding` | number | `0` | Additionally hide blocks (y) around the image. |
| `l color` | color | `purple` | Set the top left gradient color. |
| `left color` | color | | Alias for `l color`. |
| `level` | L/M/Q/H | `M` | [`qrcode`][qrcode] option affecting error correction (low, medium, quartile, high). |
| `padding` | flag | | [`qrcode`][qrcode] option adding sufficient additional space around the QR code. |
| `r color` | color | `teal` | Set the bottom right gradient color. |
| `random color` | colors | | Allow to set a random color pool to pick from. |
| `right color` | color | | Alias for `r color`. |
| `size` | length | | Alias for [`qrcode`'s][qrcode] `height` option. |
| `tight` | flag | | [`qrcode`][qrcode] option adding no additional space around the QR code. |
| `version` | [0..40] ∈ ℕ | `0` | [`qrcode`][qrcode] option affecting the size (tries to be as small as possible). |
| `width` | length | | Alias for [`qrcode`'s][qrcode] `height` option. |
| Option | Type | Default | Explanation |
| ----------------- | ----------- | :------: | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `classic` | boolean | `false` | Use the classic qr-code style (black with flat rectangles, this loads the `flat` style). |
| `color` | color | | Disables the `gradient` and sets the qr color accordingly. |
| `gradient angle` | angle | `135` | Change the gradient angle. |
| `gradient` | boolean | true | Toggle the color gradient |
| `image` | LaTeX | | Automatically center an image (you have to care for the size and maybe adjust the `version` and `level` to keep the qr-code readable).[^1] |
| `image padding` | number | | Additionally hide blocks (x & y) around the image. |
| `image x padding` | number | `0` | Additionally hide blocks (x) around the image. |
| `image y padding` | number | `0` | Additionally hide blocks (y) around the image. |
| `l color` | color | `purple` | Set the top left gradient color. |
| `left color` | color | | Alias for `l color`. |
| `level` | L/M/Q/H | `M` | [`qrcode`][qrcode] option affecting error correction (low, medium, quartile, high). |
| `padding` | flag | | [`qrcode`][qrcode] option adding sufficient additional space around the qr-code. |
| `r color` | color | `teal` | Set the bottom right gradient color. |
| `random color` | colors | | Allow to set a random color pool to pick from. |
| `right color` | color | | Alias for `r color`. |
| `size` | length | | Alias for [`qrcode`'s][qrcode] `height` option. |
| `tight` | flag | | [`qrcode`][qrcode] option adding no additional space around the qr-code. |
| `version` | [0..40] ∈ ℕ | `0` | [`qrcode`][qrcode] option affecting the size (tries to be as small as possible). |
| `width` | length | | Alias for [`qrcode`'s][qrcode] `height` option. |

The defaults are set like this:

Expand Down
9 changes: 5 additions & 4 deletions fancyqr-doc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
\maketitle


\texttt{fancyqr} is a simple package to create fancy qr codes with the help of the \textit{\href{https://www.ctan.org/pkg/qrcode}{qrcode}}-package.
\texttt{fancyqr} is a simple package to create fancy qr-codes with the help of the \textit{\href{https://www.ctan.org/pkg/qrcode}{qrcode}}-package.
You can use the |\fancyqr|-macro just like the normal |\qrcode|.\footnote{\ltx{\\fancyqr[<qr-options>]\{<url>\}}}

If you do want to hide a center square (e.g, because you want to embed an image) you can use |\FancyQrDoNotPrintSquare{<x>}{<y>}| to hide a rectangle with radius x and y set from the center. If you choose this option, the default |\FancyQrRoundCut| that rounds cut corners can be changed with |\FancyQrHardCut|.
Expand All @@ -66,22 +66,23 @@
\toprule
\multicolumn{1}{l}{Option} & Type & \multicolumn{1}{c}{Default} & Explanation \\
\midrule
classic & boolean & false & Use the classic qr-code style (black with flat rectangles, this loads the |flat| style). \\
color & color & & Disables the |gradient| and sets the color accordingly. \\
gradient & boolean & true & Toggle the color gradient \\
gradient angle & angle & 135 & Change the gradient angle. \\
image & \LaTeX & & Automatically center an image.\footnote{The package will automatically calculate the required \ltx{\\FancyQrDoNotPrintSquare} (you have to make sure that the qr code still has enough information to be readable). Therefore, the image will not scale with the qr code.} \\
image & \LaTeX & & Automatically center an image (you have to care for the size and maybe adjust the |version| and |level| to keep the qr-code readable).\footnote{The package will automatically calculate the required \ltx{\\FancyQrDoNotPrintSquare} (you have to make sure that the qr-code still has enough information to be readable). Therefore, the image will not scale with the qr-code.} \\
image padding & number & & Additionally hide blocks (x \& y) around the image. \\
image x padding & number & 0 & Additionally hide blocks (x) around the image. \\
image y padding & number & 0 & Additionally hide blocks (y) around the image. \\
l color & color & purple & Set the top left gradient color. \\
left color & color & & Alias for |l color|. \\
level & L/M/Q/H & M & |qrcode| option affecting error correction (low, medium, quartile, high). \\
padding & flag & & |qrcode| option adding sufficient additional space around the QR code. \\
padding & flag & & |qrcode| option adding sufficient additional space around the qr-code. \\
r color & color & teal & Set the bottom right gradient color. \\
random color & colors & & Allow to set a random color pool to pick from. \\
right color & color & & Alias for |r color|. \\
size & length & & Alias for |qrcode|'s |height| option. \\
tight & flag & & |qrcode| option adding no additional space around the QR code. \\
tight & flag & & |qrcode| option adding no additional space around the qr-code. \\
version & \([0..40] \in \mathbb{N}\) & 0 & |qrcode| option affecting the size (tries to be as small as possible). \\
width & length & & Alias for |qrcode|'s |height| option. \\
\bottomrule
Expand Down
2 changes: 1 addition & 1 deletion fancyqr-style-dots.code
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\def\fancyqr@dots@circle{\put(.5,.5){\circle*{\@ne}}}
\def\fancyqr@dots@circle{\put(.5,.5){\circle*{\@ne}}}%
% .
\newpattern0000{\fancyqr@dots@circle}%
% | | - -
Expand Down
20 changes: 16 additions & 4 deletions fancyqr.sty
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
\long\def\qr@newpattern#1#2#3#4#5{%
\expandafter\def\csname qcc#1#2#3#4\endcsname{% scaling happens implicitly by the unitlength
\put(\the\j,\the\numexpr\@max@y-\the\i){%
\advance\unitlength by \fancyqr@edge@compensate
\advance\unitlength by\fancyqr@edge@compensate\relax
#5%
}}%
}
Expand Down Expand Up @@ -100,11 +100,13 @@
\def\@fancy@qr@default@name{default}

\def\FancyQrLoad#1{%
\protected@edef\fancyqr@loaded@style{#1}%
\def\fancyqr@rounded@rect@close{\fillpath}%
\let\@tmp\newpattern\let\newpattern\qr@newpattern\@bsphack\def\@@tmp{#1}\ifx\@@tmp\@fancy@qr@default@name\FancyQrLoadDefault\else
\let\@tmp\newpattern\let\newpattern\qr@newpattern\@bsphack\def\@@tmp{#1}%
\ifx\@@tmp\@fancy@qr@default@name\FancyQrLoadDefault\else
\expandafter\edef\csname pingu@lib@#1@atcode\endcsname{\the\catcode`\@}%
\catcode`\@=11\relax
\input{fancyqr-style-#1.code}
\input{fancyqr-style-#1.code}%
\catcode`\@=\csname pingu@lib@#1@atcode\endcsname
\fi\@esphack\let\newpattern\@tmp\let\@tmp\relax}

Expand Down Expand Up @@ -151,7 +153,7 @@
\let\qr@black@fixed\qr@black \let\qr@white@fixed\qr@white
\let\qr@black@format\qr@black \let\qr@white@format\qr@white
%Set module size
\qr@modulesize=\qr@desiredheight
\qr@modulesize=\qr@desiredheight\relax
\divide\qr@modulesize by \qr@size\relax
\unitlength=\dimexpr\qr@modulesize\relax % will be re-set in placement
\if@fancyqr@image@% image is in \fancyqr@imgbox
Expand Down Expand Up @@ -262,6 +264,15 @@
\define@key{fancyqr}{random color}{\@fancyqr@randomcolor@true\def\@fancyqr@random@colors{#1}}
\define@key{fancyqr}{width}{\setkeys{qr}{height=#1}}
\define@key{fancyqr}{size}{\setkeys{qr}{height=#1}}
% \fancyqr@loaded@style
\def\fancyqr@flat@style{flat}
\define@boolkey{fancyqr}[@fancyqr@]{classic}[true]{} % if@fancyqr@classic
\def\fancyqr@classic{%
\ifx\fancyqr@loaded@style\fancyqr@flat@style\else\FancyQrLoad{\fancyqr@flat@style}\fi
\setkeys{fancyqr}{%
gradient=false,color=black,l color=black,r color=black%
}%
}

\def\fancyqrset#1{\setkeys{qr,fancyqr}{#1}}
\fancyqrset{image padding=0,gradient=true,gradient angle=135,r color=teal,l color=purple}
Expand All @@ -274,6 +285,7 @@
\newcommand\@@fancyqr[1][]{\begingroup\@fancyqr@init
\ifqr@starinvoked\qr@hyperlinkfalse\fi
\setkeys{qr,fancyqr}{#1}%
\if@fancyqr@classic\fancyqr@classic\fi%
\if@fancyqr@randomcolor@%
\ifcsname pgfmathdeclarerandomlist\endcsname\else
\PackageError{fancyqr}{Random colors requested but pgfmath not loaded}{Please load pgfmath if you want this}\fi
Expand Down
12 changes: 12 additions & 0 deletions qr-minimal.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\documentclass{article}

\usepackage{fancyqr}

\usepackage[active,tightpage]{preview}
\setlength\PreviewBorder{0pt}

\begin{document}
\preview
\fancyqr[classic,padding]{https://github.com/EagleoutIce/fancyqr}
\endpreview
\end{document}

0 comments on commit 747f5b1

Please sign in to comment.