ソースを参照

Update generator

crobi 10年前
コミット
a925148c25

+ 11
- 18
generator/css/card-size.css ファイルの表示

@@ -12,11 +12,6 @@
12 12
     3) Fill each page with cards, arranged around the center of the page.
13 13
 */
14 14
 
15
-/* Remove page margins */
16
-@page {
17
-    margin: 0;
18
-    padding: 0;
19
-}
20 15
 
21 16
 /* Center all content within a page */
22 17
 .page {
@@ -26,37 +21,36 @@
26 21
     flex-direction: row;
27 22
     flex-wrap: wrap;
28 23
     page-break-after: always;
29
-    padding: 0mm;
24
+    padding: 0;
30 25
 }
31 26
 
32
-/* A4 paper area (minus epsilon for rounding) */
27
+/* A4 paper area */
28
+/* Chrome has problems with page sizes given in metric units. Make the paper area slightly smaller to work around this. */
33 29
 page[size="A4"] {
34
-    width:  209mm; /* full: 210.0mm */
35
-    height: 295mm; /* full: 297.0mm */
30
+    width:  210mm; /* full: 210.0mm */
31
+    height: 296mm; /* full: 297.0mm */
36 32
 }
37 33
 
38
-/* US letter area (minus epsilon for rounding) */
34
+/* US letter area */
39 35
 page[size="Letter"] {
40
-    width:  215mm; /* full: 215.9mm (8.5in) */
41
-    height: 278mm; /* full: 279.4mm (11.0in) */
36
+    width:  8.5in;
37
+    height: 11.0in;
42 38
 }
43 39
 
44 40
 page[size="25x35"] {
45
-    width: 63.6mm;
46
-    height: 89.0mm;
41
+    width: 2.5in;
42
+    height: 3.5in;
47 43
 }
48 44
 
49 45
 /* Default card size */
50 46
 .card {
51 47
     width:2.5in;
52
-    min-width:2.5in;
53 48
     height:3.5in;
54 49
 }
55 50
 
56 51
 /* Bridge card size */
57 52
 .card-size-225x35 {
58 53
     width:2.25in;
59
-    min-width:2.25in;
60 54
     height:3.5in;
61 55
 }
62 56
 .card-size-225x35 .card-back-icon {
@@ -67,7 +61,6 @@ page[size="25x35"] {
67 61
 /* Poker / Magic card size */
68 62
 .card-size-25x35 {
69 63
     width:2.5in;
70
-    min-width:2.5in;
71 64
     height:3.5in;
72 65
 }
73 66
 .card-size-25x35 .card-back-icon {
@@ -89,7 +82,6 @@ page[size="25x35"] {
89 82
 /* Landscape big card */
90 83
 .card-size-75x50 {
91 84
     width:7.5in;
92
-    min-width:7.5in;
93 85
     height:5.0in;
94 86
 }
95 87
 .card-size-75x50 .card-back-icon {
@@ -97,6 +89,7 @@ page[size="25x35"] {
97 89
     height: 2in;
98 90
 }
99 91
 
92
+/* Card sizes that fill out the entire sheet of paper (minimal margins) */
100 93
 .page[size="A4"] .card-size-full3x3 {
101 94
     width:69mm;
102 95
     height:98mm;

+ 8
- 1
generator/css/cards.css ファイルの表示

@@ -26,7 +26,7 @@
26 26
     background-color: white;
27 27
     border-radius: 4mm;
28 28
     border-color: inherit;
29
-    margin: 1mm;
29
+    margin: 3mm;
30 30
     flex: 1;
31 31
     display: flex;
32 32
 }
@@ -193,6 +193,13 @@
193 193
     margin-bottom: 0.3em;
194 194
 }
195 195
 
196
+.card-box {
197
+    display: inline;
198
+    height: 10mm;
199
+    width: 10mm;
200
+    margin-right: 0.3em;
201
+}
202
+
196 203
 .card-bullet-line {
197 204
     font-size: inherit;
198 205
     color: black;

+ 4
- 0
generator/css/output.css ファイルの表示

@@ -18,11 +18,15 @@ body {
18 18
 @media print {
19 19
   .page-preview {
20 20
     margin: 0;
21
+    padding: 0;
22
+    border: 0;
21 23
     box-shadow: 0;
22 24
     background-color: white;
23 25
   }
24 26
   .page-background {
25 27
     margin: 0;
28
+    padding: 0;
29
+    border: 0;
26 30
     box-shadow: 0;
27 31
     /* Set the background to gray to visualize the page size in the print preview */
28 32
     background-color: gray;

+ 2
- 1
generator/data/card_data_example.js ファイルの表示

@@ -109,7 +109,8 @@ var card_data_example = [
109 109
             "bullet | magic missile, 1st level (1 charge)",
110 110
             "bullet | magic missile, 2nd level (2 charges)",
111 111
             "bullet | magic missile, 3rd level (3 charges)",
112
-            "fill | 3"
112
+            "fill | 3",
113
+            "boxes | 7 | 2.5"
113 114
         ]
114 115
     },
115 116
     {

+ 28
- 8
generator/generate.html ファイルの表示

@@ -82,12 +82,12 @@
82 82
                             <button type="button" class="btn btn-success btn-block" id="button-generate">Generate</button>
83 83
                         </div>
84 84
                     </div>
85
-                    <span class="help-block">Generated cards open in a new tab or window.</span>
85
+                    <!--<span class="help-block">Generated cards open in a new tab or window.</span>-->
86 86
                 </form>
87
-                <h3>Sizes</h3>
87
+                <h3>Page settings</h3>
88 88
                 <form role="form" class="form-horizontal">
89 89
                     <div class="form-group">
90
-                        <label for="page-size" class="col-sm-4 control-label">Page</label>
90
+                        <label for="page-size" class="col-sm-4 control-label">Page Size</label>
91 91
                         <div class="col-sm-8">
92 92
                             <select class="form-control" id="page-size" data-option="page_size">
93 93
                                 <option value="A4" selected>A4</option>
@@ -97,7 +97,7 @@
97 97
                         </div>
98 98
                     </div>
99 99
                     <div class="form-group">
100
-                        <label for="card-size" class="col-sm-4 control-label">Card</label>
100
+                        <label for="card-size" class="col-sm-4 control-label">Card Size</label>
101 101
                         <div class="col-sm-8">
102 102
                             <select class="form-control" id="card-size" data-option="card_size">
103 103
                                 <option value="225x35">2.25&quot; x 3.5&quot; (Bridge)</option>
@@ -129,6 +129,24 @@
129 129
                             </select>
130 130
                         </div>
131 131
                     </div>
132
+                    <div class="form-group">
133
+                        <label for="foreground-color" class="col-sm-4 control-label">Front color</label>
134
+                        <div class="col-sm-8">
135
+                            <div class="input-group">
136
+                                <select id="foreground_color_selector" class="colorselector-data"></select>
137
+                                <input type="text" id="foreground-color" class="form-control" placeholder="Front page color" data-property="color" value="white">
138
+                            </div>
139
+                        </div>
140
+                    </div>
141
+                    <div class="form-group">
142
+                        <label for="background-color" class="col-sm-4 control-label">Back color</label>
143
+                        <div class="col-sm-8">
144
+                            <div class="input-group">
145
+                                <select id="background_color_selector" class="colorselector-data"></select>
146
+                                <input type="text" id="background-color" class="form-control" placeholder="Back page color" data-property="color" value="white">
147
+                            </div>
148
+                        </div>
149
+                    </div>
132 150
                 </form>
133 151
                 <h3>Default values</h3>
134 152
                 <form role="form" class="form-horizontal">
@@ -304,13 +322,15 @@
304 322
                 </div>
305 323
                 <div class="modal-body">
306 324
                     <ul>
307
-                        <li>The generated cards open in a new tab or window. If you don't see any new tab or window, check your popup blocker.</li>
308
-                        <li>Make sure to use the correct paper size (same as in the editor).</li>
325
+                        <li>The generated cards open in a new tab or window. If you don't see any new tab or window, check your popup and script blockers. If that does not help, try disabling all addons.</li>
326
+                        <li>Make sure your printer uses the correct paper size (same as in the editor).</li>
309 327
                         <li>Enable double sided printing (flip on long edge).</li>
310
-                        <li>Do not scale the document to fit the page.</li>
328
+                        <li>Do not scale the document to fit the page. Print at original size.</li>
311 329
                         <li>
312 330
                             Some printers are not very precise (pages print slightly shifted or rotated) and the cards will not line up with the card backs.
313
-                            If this is the case, there's nothing you can do. Try a different printer or print single-sided.
331
+                            If this is the case, there's not much you can do.
332
+                            Try making the page background the same color as the cards, so that you won't get any white edges on the card.
333
+                            If that does not help, try a different printer or print single-sided.
314 334
                         </li>
315 335
                     </ul>
316 336
                 </div>

+ 55
- 4
generator/js/cards.js ファイルの表示

@@ -3,6 +3,8 @@
3 3
 // ============================================================================
4 4
 function card_default_options() {
5 5
     return {
6
+        foreground_color: "white",
7
+        background_color: "white",
6 8
         default_color: "black",
7 9
         default_icon: "ace",
8 10
         default_title_size: "13",
@@ -11,6 +13,7 @@ function card_default_options() {
11 13
         page_columns: 3,
12 14
         card_arrangement: "doublesided",
13 15
         card_size: "25x35",
16
+        card_count: null,
14 17
         icon_inline: true
15 18
     }
16 19
 }
@@ -89,6 +92,25 @@ function card_element_ruler(params, card_data, options) {
89 92
     return result;
90 93
 }
91 94
 
95
+function card_element_boxes(params, card_data, options) {
96
+    var color = card_data_color_front(card_data, options);
97
+    var fill = ' fill="none"';
98
+    var stroke = ' stroke="' + color + '"';
99
+    var count = params[0] || 1;
100
+    var size = params[1] || 3;
101
+    var style = 'style="width:' + size + 'em;height:' + size + 'em"';
102
+
103
+    var result = "";
104
+    result += '<div class="card-element card-description-line">';
105
+    for (var i = 0; i < count; ++i) {
106
+        result += '<svg class="card-box" height="100" width="100" viewbox="0 0 100 100" preserveaspectratio="none" xmlns="http://www.w3.org/2000/svg" ' + style + '>';
107
+        result += '    <rect x="5" y="5" width="90" height="90" ' + fill + stroke + ' style="stroke-width:10">';
108
+        result += '</svg>';
109
+    }
110
+    result += '</div>';
111
+    return result;
112
+}
113
+
92 114
 function card_element_property(params, card_data, options) {
93 115
     var result = "";
94 116
     result += '<div class="card-element card-property-line">';
@@ -147,6 +169,7 @@ var card_element_generators = {
147 169
     property: card_element_property,
148 170
     rule: card_element_ruler,
149 171
     ruler: card_element_ruler,
172
+    boxes: card_element_boxes,
150 173
     description: card_element_description,
151 174
     text: card_element_text,
152 175
     bullet: card_element_bullet,
@@ -300,7 +323,9 @@ function card_pages_wrap(pages, options) {
300 323
     for (var i = 0; i < pages.length; ++i) {
301 324
         var style = "";
302 325
         if ((options.card_arrangement == "doublesided") &&  (i % 2 == 1)) {
303
-            style += 'style="background-color:'+options.default_color+'"';
326
+            style += 'style="background-color:' + options.background_color + '"';
327
+        } else {
328
+            style += 'style="background-color:' + options.foreground_color + '"';
304 329
         }
305 330
         result += '<page class="page page-preview" size="' + size + '" ' + style + '>\n';
306 331
         result += pages[i].join("\n");
@@ -309,6 +334,28 @@ function card_pages_wrap(pages, options) {
309 334
     return result;
310 335
 }
311 336
 
337
+function card_pages_generate_style(options) {
338
+    var size = "a4";
339
+    switch (options.page_size) {
340
+        case "A3": size = "A3 portrait"; break;
341
+        case "A4": size = "210mm 297mm"; break;
342
+        case "A5": size = "A5 portrait"; break;
343
+        case "Letter": size = "letter portrait"; break;
344
+        case "25x35": size = "2.5in 3.5in"; break;
345
+        default: size = "auto";
346
+    }
347
+
348
+    var result = "";
349
+    result += "<style>\n";
350
+    result += "@page {\n";
351
+    result += "    margin: 0;\n";
352
+    result += "    size:" + size + ";\n";
353
+    result += "    -webkit-print-color-adjust: exact;\n";
354
+    result += "}\n";
355
+    result += "</style>\n";
356
+    return result;
357
+}
358
+
312 359
 function card_pages_generate_html(card_data, options) {
313 360
     options = options || card_default_options();
314 361
     var rows = options.page_rows || 3;
@@ -318,7 +365,7 @@ function card_pages_generate_html(card_data, options) {
318 365
     var front_cards = [];
319 366
     var back_cards = [];
320 367
     card_data.forEach(function (data) {
321
-        var count = data.count || 1;
368
+        var count = options.card_count || data.count || 1;
322 369
         var front = card_generate_front(data, options);
323 370
         var back = card_generate_back(data, options);
324 371
         front_cards = front_cards.concat(card_repeat(front, count));
@@ -351,8 +398,12 @@ function card_pages_generate_html(card_data, options) {
351 398
         pages = card_pages_split(cards, rows, cols);
352 399
     }
353 400
 
354
-    // Wrap all pages in a <page> element
355
-    return card_pages_wrap(pages, options);
401
+    // Wrap all pages in a <page> element and add CSS for the page size
402
+    var result = "";
403
+    result += card_pages_generate_style(options);
404
+    result += card_pages_wrap(pages, options);
405
+
406
+    return result;
356 407
 }
357 408
 
358 409
 function card_pages_insert_into(card_data, container) {

+ 27
- 1
generator/js/ui.js ファイルの表示

@@ -35,6 +35,11 @@ function merge(left, right, compare) {
35 35
 
36 36
 var ui_generate_modal_shown = false;
37 37
 function ui_generate() {
38
+    if (card_data.length == 0) {
39
+        alert("Your deck is empty. Please define some cards first, or load the sample deck.");
40
+        return;
41
+    }
42
+
38 43
     // Generate output HTML
39 44
     var card_html = card_pages_generate_html(card_data, card_options);
40 45
 
@@ -49,7 +54,7 @@ function ui_generate() {
49 54
 
50 55
     // Send the generated HTML to the new window
51 56
     // Use a delay to give the new window time to set up a message listener
52
-    setTimeout(function () { tab.postMessage(card_html, '*') }, 100);
57
+    setTimeout(function () { tab.postMessage(card_html, '*') }, 500);
53 58
 }
54 59
 
55 60
 function ui_load_sample() {
@@ -209,6 +214,18 @@ function ui_setup_color_selector() {
209 214
             ui_set_card_color(value);
210 215
         }
211 216
     });
217
+    $('#foreground_color_selector').colorselector({
218
+        callback: function (value, color, title) {
219
+            $("#foreground-color").val(title);
220
+            ui_set_foreground_color(value);
221
+        }
222
+    });
223
+    $('#background_color_selector').colorselector({
224
+        callback: function (value, color, title) {
225
+            $("#background-color").val(title);
226
+            ui_set_background_color(value);
227
+        }
228
+    });
212 229
 
213 230
     // Styling
214 231
     $(".dropdown-colorselector").addClass("input-group-addon color-input-addon");
@@ -219,6 +236,14 @@ function ui_set_default_color(color) {
219 236
     ui_render_selected_card();
220 237
 }
221 238
 
239
+function ui_set_foreground_color(color) {
240
+    card_options.foreground_color = color;
241
+}
242
+
243
+function ui_set_background_color(color) {
244
+    card_options.background_color = color;
245
+}
246
+
222 247
 function ui_change_option() {
223 248
     var property = $(this).attr("data-option");
224 249
     var value = $(this).val();
@@ -390,6 +415,7 @@ $(document).ready(function () {
390 415
     $("#page-columns").change(ui_change_option);
391 416
     $("#card-arrangement").change(ui_change_option);
392 417
     $("#card-size").change(ui_change_option);
418
+    $("#background-color").change(ui_change_option);
393 419
 
394 420
     $("#default-color").change(ui_change_default_color);
395 421
     $("#default-icon").change(ui_change_default_icon);

読み込み中…
キャンセル
保存