summaryrefslogtreecommitdiff
path: root/macros/unicodetex/latex/lilyglyphs/tex/core/genericAccess.inp
blob: 095dd2de64a82778f181694cb7c17323709d7692 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                        %
%      This file is part of the 'lilyglyphs' LaTeX package.              %
%                                ==========                              %
%                                                                        %
%              https://github.com/openlilylib/lilyglyphs                 %
%               http://www.openlilylib.org/lilyglyphs                    %
%                                                                        %
%  Copyright 2012-2013 Urs Liska and others, ul@openlilylib.org          %
%                                                                        %
%  'lilyglyphs' is free software: you can redistribute it and/or modify  %
%  it under the terms of the LaTeX Project Public License, either        %
%  version 1.3 of this license or (at your option) any later version.    %
%  You may find the latest version of this license at                    %
%               http://www.latex-project.org/lppl.txt                    %
%  more information on                                                   %
%               http://latex-project.org/lppl/                           %
%  and version 1.3 or later is part of all distributions of LaTeX        %
%  version 2005/12/01 or later.                                          %
%                                                                        %
%  This work has the LPPL maintenance status 'maintained'.               %
%  The Current Maintainer of this work is Urs Liska (see above).         %
%                                                                        %
%  This work consists of the files listed in the file 'manifest.txt'     %
%  which can be found in the 'license' directory.                        %
%                                                                        %
%  This program is distributed in the hope that it will be useful,       %
%  but WITHOUT ANY WARRANTY; without even the implied warranty of        %
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  %
%                                                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file is part of the lilyglyphs package    %
% and defines the generic printing functionality %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is the internal command that actually prints the glyph(s)%
% Users aren't intended to use it directly                      %
% #1 are key-value options
% #2 the content to be printed
\newcommand*{\lilyPrint}[2][]{%
	% interpret optional argument
	\interpretLilyOptions{#1}%
	% print the glyph in a raisebox
	\raisebox{\lilyEffectiveRaise ex}{%
		{\fontspec[Scale=\lilyEffectiveScale]{emmentaler-\lilyOpticalSuffix.otf}#2}%
	}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Helper functions for \lilyPrintImage below

% Calculate the (point) ratio between the current font size
% and the size of \normalsize fonts.
% This is used to scale the output of \lilyPrintImage
% as images aren't scaled automatically with font size commands.
\makeatletter
\newcommand*{\currentFontRatio}{%
	% store point size of current font
	\xdef\currentFontSize{\f@size}%
	{%
		% Temporarily switch to normal size
		\normalsize%
		% and store normal point size
		\xdef\normalFontSize{\f@size}%
	}%
	% Calculate ratio and store the value
	\pgfmathsetmacro{\getCurrentFontRatio}{%
		\currentFontSize / \normalFontSize}%
}
\makeatother

% Apply the scaling factor that is necessary to
% accomodate the current font size.
% The accumulated scaling factor of the other sources
% is taken into account through \lilyEffectiveScale.
\newcommand*{\lilyScaleImage}{%
	\currentFontRatio%
	\pgfmathsetmacro{\lilyImageEffectiveScale}{%
		\lilyEffectiveScale * \getCurrentFontRatio}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load 'glyph' from an image (preferrably PDF).                 %
% Used for items that are created using LilyPond itself         %
% Users aren't intended to use it directly                      %
% #1 are key-value options
% #2 the content to be printed
\newcommand*{\lilyPrintImage}[2][]{%
	% interpret optional argument
	\interpretLilyOptions{#1}%
	% determine scaling factor to accomodate the current font size 
	% (as images don't scale automatically with the font)
	\lilyScaleImage%
	% Print the image in a raisebox
	\raisebox{\lilyEffectiveRaise ex}{%
		\includegraphics[scale=\lilyImageEffectiveScale]{#2.pdf}%
	}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Generic command(s) to select a LilyPond Glyph %
% These shouldn't be used by end users but      %
% for designing predefined commands.            %
% They select a glyph by a specific method and  %
% return the #2 to be passed to \lilyPrint      %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Determine the glyph by its OpenType glyphName

\usepackage{ifluatex,ifxetex}

\ifluatex
\usepackage{luaotfload,luacode} 
\begin{luacode}
documentdata = documentdata or { }

local stringformat = string.format
local texsprint = tex.sprint
local slot_of_name = luaotfload.aux.slot_of_name

documentdata.fontchar = function (chr)
local chr = slot_of_name(font.current(), chr, false)
if chr and type(chr) == "number" then
texsprint
(stringformat ([[\char"%X"]], chr))
end
end
\end{luacode}

\def\lilyGetGlyph#1{\directlua{documentdata.fontchar "#1"}}
\fi

\ifxetex
\newcommand*{\lilyGetGlyph}[1]{\XeTeXglyph\XeTeXglyphindex"#1" }
\fi

% Determine the glyph by its OpenType character number
% (these may change with new versions of the fonts!)
\newcommand*{\lilyGetGlyphByNumber}[1]{\char"#1 }


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Generic commands to print glyphs that aren't %
% covered by predefined commands yet.          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Print a glyph by its glyph name. %
% Glyph names have to be looked up %
% in the docs.                     %

\newcommand*{\lilyGlyph}[2][]{%
	% set defaults
	\setkeys{lilyDesignOptions}{scale=1,raise=0}%
	\lilyPrint[#1]{\lilyGetGlyph{#2}}%
}	

% Determine the glyph by its Unicode number 
% (works for those glyphs that reside in 'standard' places)
\newcommand*{\lilyGlyphByNumber}[2][]{%
	% set defaults
	\setkeys{lilyDesignOptions}{scale=1,raise=0}%
	\lilyPrint[#1]{\lilyGetGlyphByNumber{#2}}%
}

% Don't 'determine' glyph positions but just use plain text.
% This works for dynamics letters, numbers and + - . ,
\newcommand*{\lilyText}[2][]{%
	% set defaults
	\setkeys{lilyDesignOptions}{scale=1,raise=0}%
	\lilyPrint[#1]{#2}%
}

% Load 'glyph' from an image (preferrably PDF).
% Used for items that are created using LilyPond itself.
\newcommand*{\lilyImage}[2][]{%
	% set defaults
	\setkeys{lilyDesignOptions}{scale=1, raise=0}%
	% interpret optional argument
	\interpretLilyOptions{#1}%
	\raisebox{\lilyEffectiveRaise ex}{%
		\includegraphics[scale=\lilyEffectiveScale]{#2}%
	}%
}