diff --git a/README.md b/README.md index 4d0f3cf..e45244e 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ Layout options are set as options to the `\documentclass`, e.g.: - `fill` or `nofill`: fill empty space between icon and text, default: `fill` - `qrfirst` or `textfirst`: switch position of QR-Code and text block, default: `qrfirst` - `https` or `www`: should links in the hints be prefixed with `https://` or `www.`, default: `https` +- `countryformat=`: how to format the country in address. Values: `auto` (default: inline with mdash if <4 chars and city/zip exists), `inline` (always inline with mdash), `below` (always separate line) - `qreclevel=`: QR error correction level `L` (~7%), `M` (~15%), `Q` (~25%), or `H` (~30%), default: `Q`. Use `H` when `photoinqr=true`. - `photoinqr` or `nophotoinqr`: place photo in the center of the QR code (`photoinqr`) instead of next to the name, default: `nophotoinqr`. **Requires `qreclevel=H` for reliable scanning**. - `qrlogoscale=`: photo size in QR code as percentage of QR width (0-100), default: `25` (25% width = 6.25% area). Recommended values: Level H: 25-30%, Level Q: 20%, Level M: 15%, Level L: 10%. Higher values may reduce scannability. @@ -133,7 +134,7 @@ See this example_ - `\city`: name of the address location - `\region`: region of the address - `\zip`: zip code of the address -- `\country`: full name of country of the address in the language of the card +- `\country`: full name of country of the address in the language of the card (short codes like `CH`, `USA`, `D` are automatically placed inline with mdash before city/zip, longer names on separate line) - `\phone`: your phone number, the phone is marked as mobile, so to be used for voice and text (SMS) - `\email`: your email address - `\jabber`: your [jabber] or xmpp chat address diff --git a/businesscard-qrcode.cls b/businesscard-qrcode.cls index e73d6b8..c1957b2 100644 --- a/businesscard-qrcode.cls +++ b/businesscard-qrcode.cls @@ -42,6 +42,7 @@ \DeclareComplementaryOption{textfirst}{qrfirst} \DeclareBoolOption[true]{https} \DeclareComplementaryOption{www}{https} +\DeclareStringOption[auto]{countryformat} % auto: <4 chars inline with mdash, >=4 separate line; inline: always inline; below: always separate line \DeclareDefaultOption{\@unknownoptionerror} \ProcessKeyvalOptions* @@ -68,6 +69,7 @@ \RequirePackage{fontawesome} \RequirePackage[final]{qrcode} \RequirePackage{etoolbox} +\RequirePackage{xstring} % for string length checking \RequirePackage{DejaVuSans} \RequirePackage[T1]{fontenc} \RequirePackage{wrapfig} @@ -145,7 +147,6 @@ \newcommand\cond[1]{\ifcsdef{#1}{\exec{#1}}{}} \newcommand\heightscale{\dimexpr\textheight-\ifcsempty{name}{0em}{2em}-\ifcsdef{Xpgpfingerprint}{2em}{0em}-\ifcsdef{Xadditionalnames}{2em}{0em}\relax} - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % name - assemble full name from the parts, such as Xgivennames and Xfamilynames \newcommand\name{\ifexists{Xhonoricprefix}{\Xhonoricprefix\ }\ifexists{Xgivennames}{\Xgivennames\ }\ifexists{Xfamilynames}{\Xfamilynames}\ifexists{Xhonoricsuffix}{\ \Xhonoricsuffix}} @@ -192,6 +193,38 @@ FN:\name\ifexists{Xadditionalnames}{\ifcsempty{name}{} { }\Xadditionalnames}\BCQ END:VCARD\BCQ@nl} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% formatcountry - format country based on length and options +\newcommand\formatcountry{% + \ifcsdef{Xcountry}{% + \def\BCQ@shouldinline{false}% + % Check countryformat option + \ifdefstring{\BCQ@countryformat}{inline}{% + \def\BCQ@shouldinline{true}% + }{% + \ifdefstring{\BCQ@countryformat}{below}{% + \def\BCQ@shouldinline{false}% + }{% + % auto mode: check length + \StrLen{\Xcountry}[\BCQ@countrylen]% + \ifnum\BCQ@countrylen<4\relax% + % Short country code AND city/zip exists → inline + \ifboolexpr{test {\ifcsdef{Xcity}} or test {\ifcsdef{Xzip}}}{% + \def\BCQ@shouldinline{true}% + }{}% + \fi% + }% + }% + % Output country + \ifdefstring{\BCQ@shouldinline}{true}{% + \Xcountry\ \textemdash\ % + }{% + \Xcountry + + }% + }{}% +} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % address - the address as shown in the textbox \newcommand\address{ @@ -202,9 +235,9 @@ END:VCARD\BCQ@nl} \cond{Xstreet} - \cond{Xzip} \cond{Xcity} + \formatcountry\cond{Xzip} \cond{Xcity} - \cond{Xregion} \cond{Xcountry} + \cond{Xregion} } diff --git a/examples/john-doe-hongkong.pdf b/examples/john-doe-hongkong.pdf index fa47414..0ea3ce1 100644 Binary files a/examples/john-doe-hongkong.pdf and b/examples/john-doe-hongkong.pdf differ diff --git a/examples/photo-in-qr-example.pdf b/examples/photo-in-qr-example.pdf index 542223a..04867df 100644 Binary files a/examples/photo-in-qr-example.pdf and b/examples/photo-in-qr-example.pdf differ diff --git a/examples/test-country-short.pdf b/examples/test-country-short.pdf new file mode 100644 index 0000000..9dc35af Binary files /dev/null and b/examples/test-country-short.pdf differ diff --git a/examples/test-country-short.tex b/examples/test-country-short.tex new file mode 100644 index 0000000..f0247ad --- /dev/null +++ b/examples/test-country-short.tex @@ -0,0 +1,16 @@ +% !TeX program = xelatex +\documentclass{businesscard-qrcode} + +\type{home} +\givennames{Max} +\familynames{Muster} +\street{Beispielstrasse\ 42} +\city{Winterthur} +\zip{8400} +\country{CH} +\phone{+41 52 123 45 67} +\email{max@example.ch} + +\begin{document} + \drawcard +\end{document}