|
@@ -7,6 +7,10 @@ module.exports = function(theme) {
|
7
|
7
|
right = ifNumeric(theme.captionRight, theme.width),
|
8
|
8
|
bottom = ifNumeric(theme.captionBottom, null),
|
9
|
9
|
top = ifNumeric(theme.captionTop, null),
|
|
10
|
+ citationLeft = ifNumeric(theme.citationLeft, 0),
|
|
11
|
+ citationRight = ifNumeric(theme.citationRight, theme.width),
|
|
12
|
+ citationBottom = ifNumeric(theme.citationBottom, null),
|
|
13
|
+ citationTop = ifNumeric(theme.citationTop, null),
|
10
|
14
|
labelLeft = ifNumeric(theme.labelLeft, 0),
|
11
|
15
|
labelRight = ifNumeric(theme.labelRight, theme.width),
|
12
|
16
|
labelBottom = ifNumeric(theme.labelBottom, null),
|
|
@@ -23,6 +27,7 @@ module.exports = function(theme) {
|
23
|
27
|
}
|
24
|
28
|
|
25
|
29
|
var captionWidth = right - left,
|
|
30
|
+ citationWidth = citationRight - citationLeft;
|
26
|
31
|
labelWidth = labelRight - labelLeft;
|
27
|
32
|
|
28
|
33
|
return function(context, caption, type) {
|
|
@@ -98,6 +103,74 @@ module.exports = function(theme) {
|
98
|
103
|
} // end if caption
|
99
|
104
|
|
100
|
105
|
|
|
106
|
+ if (type === 'citation') {
|
|
107
|
+ var lines = [[]],
|
|
108
|
+ maxWidth = 0,
|
|
109
|
+ words = smartquotes(caption + "").trim().replace(/\s\s+/g, " \n").split(/ /g);
|
|
110
|
+
|
|
111
|
+ context.font = theme.citationFont;
|
|
112
|
+ context.textBaseline = "top";
|
|
113
|
+ context.textAlign = theme.citationAlign || "center";
|
|
114
|
+
|
|
115
|
+ // Check whether each word exceeds the width limit
|
|
116
|
+ // Wrap onto next line as needed
|
|
117
|
+ words.forEach(function(word,i){
|
|
118
|
+
|
|
119
|
+ var width = context.measureText(lines[lines.length - 1].concat([word]).join(" ")).width;
|
|
120
|
+
|
|
121
|
+ if (word[0] === "\n" || (lines[lines.length - 1].length && width > citationWidth)) {
|
|
122
|
+
|
|
123
|
+ word = word.trim();
|
|
124
|
+ lines.push([word]);
|
|
125
|
+ width = context.measureText(word).width;
|
|
126
|
+
|
|
127
|
+ } else {
|
|
128
|
+
|
|
129
|
+ word = (i === 0) ? '— ' + word : word;
|
|
130
|
+ lines[lines.length - 1].push(word);
|
|
131
|
+
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ maxWidth = Math.max(maxWidth,width);
|
|
135
|
+
|
|
136
|
+ });
|
|
137
|
+
|
|
138
|
+ var totalHeight = lines.length * theme.citationLineHeight + (lines.length - 1) * theme.citationLineSpacing;
|
|
139
|
+
|
|
140
|
+ // horizontal alignment
|
|
141
|
+ var x = theme.citationAlign === "left" ? left : theme.citationAlign === "right" ? right : (left + right) / 2;
|
|
142
|
+
|
|
143
|
+ // Vertical alignment
|
|
144
|
+ var y;
|
|
145
|
+
|
|
146
|
+ if (citationTop !== null && citationBottom !== null) {
|
|
147
|
+ // Vertical center
|
|
148
|
+ y = (citationBottom + citationTop - totalHeight) / 2;
|
|
149
|
+ } else if (citationBottom !== null) {
|
|
150
|
+ // Vertical align bottom
|
|
151
|
+ y = citationBottom - totalHeight;
|
|
152
|
+ } else {
|
|
153
|
+ // Vertical align top
|
|
154
|
+ y = citationTop;
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ // draw citation
|
|
158
|
+ context.fillStyle = theme.citationColor;
|
|
159
|
+ lines.forEach(function(line, i){
|
|
160
|
+
|
|
161
|
+ // negative indentation for opening em dash
|
|
162
|
+ var indented_x = (x + 50);
|
|
163
|
+
|
|
164
|
+ if (i === 0 && /^—/.test(line[0])) {
|
|
165
|
+ context.fillText(line.join(" "), x, y + i * (theme.citationLineHeight + theme.citationLineSpacing));
|
|
166
|
+ }
|
|
167
|
+ else {
|
|
168
|
+ context.fillText(line.join(" "), indented_x, y + i * (theme.citationLineHeight + theme.citationLineSpacing));
|
|
169
|
+ }
|
|
170
|
+ });
|
|
171
|
+ } // end if citation
|
|
172
|
+
|
|
173
|
+
|
101
|
174
|
if (type === 'label' && caption != 'None') {
|
102
|
175
|
var lines = [[]],
|
103
|
176
|
maxWidth = 0,
|