summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/spark-otf/spark-otf.sty
blob: d756b7e4ada8439e34d2dbbe6b8329445860f311 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
%% $Id: spark-otf.sty 582 2017-09-25 06:27:35Z herbert $
%%
%% This file is distributed under the terms of the LaTeX Project Public
%% License from CTAN archives in directory  macros/latex/base/lppl.txt.
%% Either version 1.3 or, at your option, any later version.
%%
% Copyright 2017 Herbert Voss hvoss@tug.org
%%
\def\spark@version{0.04}
\ProvidesPackage{spark-otf}[%
  2017/09/26 v. \spark@version~(Herbert Voss) Supports spark OpenType for lualatex/xelatex.] 
%
\RequirePackage{ifxetex,ifluatex,xkeyval}
%
\newif\ifspark@usefilenames \spark@usefilenamesfalse
\DeclareOptionX{usefilenames}[true]{\@nameuse{spark@usefilenames#1}}
%
\providecommand\spark@DefaultFeatures{}
\DeclareOptionX{DefaultFeatures}{\def\spark@DefaultFeatures{#1}}

\ProcessOptionsX\relax

\ifxetex\else\ifluatex\else
  \@latex@error{This package can only be used with "XeLaTeX" or "LuaLaTeX"!%
      \MessageBreak "pdfLaTeX" or any other "TeX" version are _not_ possible!}%
\fi\fi
\RequirePackage{fontspec,xparse}

\ifluatex\RequirePackage{luacode}\fi

\newcommand\setSparkColor[2]{%
  \addfontfeatures{UprightFeatures={Color=#1}}#2%
  \addfontfeatures{UprightFeatures={Color=000000}}}

\ifspark@usefilenames
  \typeout {Using file names for the spark font}%
%-----------------------------------------  file names ----------------------------
  \font\sparkBarMedium="file:Spark - Bar - Medium.otf:mode=node;+calt;\spark@DefaultFeatures" 
  \font\sparkBarNarrow="file:Spark - Bar - Narrow.otf:mode=node;+calt;\spark@DefaultFeatures" 
  \font\sparkBarThin="file:Spark - Bar - Thin.otf:mode=node;+calt;\spark@DefaultFeatures" 
%
  \font\sparkDotLine="file:Spark - Dot-line - Medium.otf:mode=node;+calt;\spark@DefaultFeatures" 
%
  \font\sparkDotMedium="file:Spark - Dot - Medium.otf:mode=node;+calt;\spark@DefaultFeatures" 
  \font\sparkDotSmall="file:Spark - Dot - Small.otf:mode=node;+calt;\spark@DefaultFeatures" 
%
\else
  \typeout {Using symbolic names for the spark font}%
%-----------------------------------------  symbolic names ----------------------------
  \newfontface\sparkBarMedium{Spark-BarMedium}[RawFeature=+calt,\spark@DefaultFeatures]
  \newfontface\sparkBarNarrow{Spark-BarNarrow}[RawFeature=+calt,\spark@DefaultFeatures]
  \newfontface\sparkBarThin{Spark-BarThin}[RawFeature=+calt,\spark@DefaultFeatures]
%
  \newfontface\sparkDotLine{Spark-Dot-lineMedium}[RawFeature=+calt,\spark@DefaultFeatures]
%
  \newfontface\sparkDotMedium{Spark-DotMedium}[RawFeature=+calt,\spark@DefaultFeatures]
  \newfontface\sparkDotSmall{Spark-DotSmall}[RawFeature=+calt,\spark@DefaultFeatures]
\fi
%
%
\def\Extend@List{\@ifnextchar!\Extend@List@i\Extend@List@ii}
\def\Extend@List@i!#1,#2\@nil{%
  \def\spark@mark@first{#1}%
  \def\spark@values@i{#1,}%
  \Extend@List@iii#2,!,!\@nil
}
\def\Extend@List@ii#1\@nil{\Extend@List@iii#1,!,!\@nil}
%
\def\Extend@List@iii#1,!#2,!#3\@nil{%
  \ifx\relax#2\relax % no value with !
    \edef\spark@values@i{\spark@values@i#1}%
    \def\spark@mark@last{}%
  \else
    \edef\spark@values@i{\spark@values@i#1,#2}%
    \def\spark@mark@last{#2}%
  \fi
}

\def\check@list@values#1{%
  \def\spark@values@i{}%
  \def\spark@mark@first{}%
  \def\spark@mark@last{}%
  \Extend@List#1\@nil
}

%
\ifluatex
\begin{luacode}
function RelativeValues(v,m)
  local Values = {}  
  for k,x in ipairs(v) do
    Values[k] = x
  end
  table.sort(Values)
  local MaxVal = (Values[#Values])
  for k,x in ipairs(v) do
    Values[k] = math.floor(x/MaxVal*m)
  end
  for i,k in ipairs(Values) do
    tex.sprint(k)
    if (i < #Values) then tex.sprint(",") end
  end
end
\end{luacode}
  \def\spark@line{Line}%       12        3  45 
  \NewDocumentCommand\sparkBar{sO{Medium}O{}mO{}}{{%
    \check@list@values{#4}%
    \IfBooleanTF{#1}%
      {\edef\spark@values@ii{\directlua{RelativeValues({\spark@values@i},99)}}}%
      {\let\spark@values@ii\spark@values@i}%
    \@nameuse{sparkBar#2}#3\spark@mark@first\string{\spark@values@ii\string}\spark@mark@last#5%
  }}
%                              12        3  45
  \NewDocumentCommand\sparkDot{sO{Medium}O{}mO{}}{{%
    \check@list@values{#4}%
    \IfBooleanTF{#1}%
      {\def\spark@arg{#2}%
       \ifx\spark@line\spark@arg \edef\spark@values@ii{\directlua{RelativeValues({\spark@values@i},9)}}%
       \else                     \edef\spark@values@ii{\directlua{RelativeValues({\spark@values@i},100)}}%
       \fi}%
      {\let\spark@values@ii\spark@values@i}%
    \@nameuse{sparkDot#2}\spark@mark@first\string{\spark@values@ii\string}\spark@mark@last%
  }}
\else %% XeLaTeX%              1        2  34
  \NewDocumentCommand\sparkBar{O{Medium}O{}mO{}}{{%
    \check@list@values{#3}%
    \@nameuse{sparkBar#1}\spark@mark@first\string{\spark@values@i\string}\spark@mark@last%
  }}%                          1        2  34 
  \NewDocumentCommand\sparkDot{O{Medium}O{}mO{}}{{%
    \check@list@values{#3}%
    \@nameuse{sparkDot#1}\spark@mark@first\string{\spark@values@i\string}\spark@mark@last%
  }}
\fi
%%
\endinput