Bladeren bron

Update generator

crobi 10 jaren geleden
bovenliggende
commit
a925148c25

+ 11
- 18
generator/css/card-size.css Bestand weergeven

12
     3) Fill each page with cards, arranged around the center of the page.
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
 /* Center all content within a page */
16
 /* Center all content within a page */
22
 .page {
17
 .page {
26
     flex-direction: row;
21
     flex-direction: row;
27
     flex-wrap: wrap;
22
     flex-wrap: wrap;
28
     page-break-after: always;
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
 page[size="A4"] {
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
 page[size="Letter"] {
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
 page[size="25x35"] {
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
 /* Default card size */
45
 /* Default card size */
50
 .card {
46
 .card {
51
     width:2.5in;
47
     width:2.5in;
52
-    min-width:2.5in;
53
     height:3.5in;
48
     height:3.5in;
54
 }
49
 }
55
 
50
 
56
 /* Bridge card size */
51
 /* Bridge card size */
57
 .card-size-225x35 {
52
 .card-size-225x35 {
58
     width:2.25in;
53
     width:2.25in;
59
-    min-width:2.25in;
60
     height:3.5in;
54
     height:3.5in;
61
 }
55
 }
62
 .card-size-225x35 .card-back-icon {
56
 .card-size-225x35 .card-back-icon {
67
 /* Poker / Magic card size */
61
 /* Poker / Magic card size */
68
 .card-size-25x35 {
62
 .card-size-25x35 {
69
     width:2.5in;
63
     width:2.5in;
70
-    min-width:2.5in;
71
     height:3.5in;
64
     height:3.5in;
72
 }
65
 }
73
 .card-size-25x35 .card-back-icon {
66
 .card-size-25x35 .card-back-icon {
89
 /* Landscape big card */
82
 /* Landscape big card */
90
 .card-size-75x50 {
83
 .card-size-75x50 {
91
     width:7.5in;
84
     width:7.5in;
92
-    min-width:7.5in;
93
     height:5.0in;
85
     height:5.0in;
94
 }
86
 }
95
 .card-size-75x50 .card-back-icon {
87
 .card-size-75x50 .card-back-icon {
97
     height: 2in;
89
     height: 2in;
98
 }
90
 }
99
 
91
 
92
+/* Card sizes that fill out the entire sheet of paper (minimal margins) */
100
 .page[size="A4"] .card-size-full3x3 {
93
 .page[size="A4"] .card-size-full3x3 {
101
     width:69mm;
94
     width:69mm;
102
     height:98mm;
95
     height:98mm;

+ 8
- 1
generator/css/cards.css Bestand weergeven

26
     background-color: white;
26
     background-color: white;
27
     border-radius: 4mm;
27
     border-radius: 4mm;
28
     border-color: inherit;
28
     border-color: inherit;
29
-    margin: 1mm;
29
+    margin: 3mm;
30
     flex: 1;
30
     flex: 1;
31
     display: flex;
31
     display: flex;
32
 }
32
 }
193
     margin-bottom: 0.3em;
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
 .card-bullet-line {
203
 .card-bullet-line {
197
     font-size: inherit;
204
     font-size: inherit;
198
     color: black;
205
     color: black;

+ 4
- 0
generator/css/output.css Bestand weergeven

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

+ 2
- 1
generator/data/card_data_example.js Bestand weergeven

109
             "bullet | magic missile, 1st level (1 charge)",
109
             "bullet | magic missile, 1st level (1 charge)",
110
             "bullet | magic missile, 2nd level (2 charges)",
110
             "bullet | magic missile, 2nd level (2 charges)",
111
             "bullet | magic missile, 3rd level (3 charges)",
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 Bestand weergeven

82
                             <button type="button" class="btn btn-success btn-block" id="button-generate">Generate</button>
82
                             <button type="button" class="btn btn-success btn-block" id="button-generate">Generate</button>
83
                         </div>
83
                         </div>
84
                     </div>
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
                 </form>
86
                 </form>
87
-                <h3>Sizes</h3>
87
+                <h3>Page settings</h3>
88
                 <form role="form" class="form-horizontal">
88
                 <form role="form" class="form-horizontal">
89
                     <div class="form-group">
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
                         <div class="col-sm-8">
91
                         <div class="col-sm-8">
92
                             <select class="form-control" id="page-size" data-option="page_size">
92
                             <select class="form-control" id="page-size" data-option="page_size">
93
                                 <option value="A4" selected>A4</option>
93
                                 <option value="A4" selected>A4</option>
97
                         </div>
97
                         </div>
98
                     </div>
98
                     </div>
99
                     <div class="form-group">
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
                         <div class="col-sm-8">
101
                         <div class="col-sm-8">
102
                             <select class="form-control" id="card-size" data-option="card_size">
102
                             <select class="form-control" id="card-size" data-option="card_size">
103
                                 <option value="225x35">2.25&quot; x 3.5&quot; (Bridge)</option>
103
                                 <option value="225x35">2.25&quot; x 3.5&quot; (Bridge)</option>
129
                             </select>
129
                             </select>
130
                         </div>
130
                         </div>
131
                     </div>
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
                 </form>
150
                 </form>
133
                 <h3>Default values</h3>
151
                 <h3>Default values</h3>
134
                 <form role="form" class="form-horizontal">
152
                 <form role="form" class="form-horizontal">
304
                 </div>
322
                 </div>
305
                 <div class="modal-body">
323
                 <div class="modal-body">
306
                     <ul>
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
                         <li>Enable double sided printing (flip on long edge).</li>
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
                         <li>
329
                         <li>
312
                             Some printers are not very precise (pages print slightly shifted or rotated) and the cards will not line up with the card backs.
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
                         </li>
334
                         </li>
315
                     </ul>
335
                     </ul>
316
                 </div>
336
                 </div>

+ 55
- 4
generator/js/cards.js Bestand weergeven

3
 // ============================================================================
3
 // ============================================================================
4
 function card_default_options() {
4
 function card_default_options() {
5
     return {
5
     return {
6
+        foreground_color: "white",
7
+        background_color: "white",
6
         default_color: "black",
8
         default_color: "black",
7
         default_icon: "ace",
9
         default_icon: "ace",
8
         default_title_size: "13",
10
         default_title_size: "13",
11
         page_columns: 3,
13
         page_columns: 3,
12
         card_arrangement: "doublesided",
14
         card_arrangement: "doublesided",
13
         card_size: "25x35",
15
         card_size: "25x35",
16
+        card_count: null,
14
         icon_inline: true
17
         icon_inline: true
15
     }
18
     }
16
 }
19
 }
89
     return result;
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
 function card_element_property(params, card_data, options) {
114
 function card_element_property(params, card_data, options) {
93
     var result = "";
115
     var result = "";
94
     result += '<div class="card-element card-property-line">';
116
     result += '<div class="card-element card-property-line">';
147
     property: card_element_property,
169
     property: card_element_property,
148
     rule: card_element_ruler,
170
     rule: card_element_ruler,
149
     ruler: card_element_ruler,
171
     ruler: card_element_ruler,
172
+    boxes: card_element_boxes,
150
     description: card_element_description,
173
     description: card_element_description,
151
     text: card_element_text,
174
     text: card_element_text,
152
     bullet: card_element_bullet,
175
     bullet: card_element_bullet,
300
     for (var i = 0; i < pages.length; ++i) {
323
     for (var i = 0; i < pages.length; ++i) {
301
         var style = "";
324
         var style = "";
302
         if ((options.card_arrangement == "doublesided") &&  (i % 2 == 1)) {
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
         result += '<page class="page page-preview" size="' + size + '" ' + style + '>\n';
330
         result += '<page class="page page-preview" size="' + size + '" ' + style + '>\n';
306
         result += pages[i].join("\n");
331
         result += pages[i].join("\n");
309
     return result;
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
 function card_pages_generate_html(card_data, options) {
359
 function card_pages_generate_html(card_data, options) {
313
     options = options || card_default_options();
360
     options = options || card_default_options();
314
     var rows = options.page_rows || 3;
361
     var rows = options.page_rows || 3;
318
     var front_cards = [];
365
     var front_cards = [];
319
     var back_cards = [];
366
     var back_cards = [];
320
     card_data.forEach(function (data) {
367
     card_data.forEach(function (data) {
321
-        var count = data.count || 1;
368
+        var count = options.card_count || data.count || 1;
322
         var front = card_generate_front(data, options);
369
         var front = card_generate_front(data, options);
323
         var back = card_generate_back(data, options);
370
         var back = card_generate_back(data, options);
324
         front_cards = front_cards.concat(card_repeat(front, count));
371
         front_cards = front_cards.concat(card_repeat(front, count));
351
         pages = card_pages_split(cards, rows, cols);
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
 function card_pages_insert_into(card_data, container) {
409
 function card_pages_insert_into(card_data, container) {

+ 27
- 1
generator/js/ui.js Bestand weergeven

35
 
35
 
36
 var ui_generate_modal_shown = false;
36
 var ui_generate_modal_shown = false;
37
 function ui_generate() {
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
     // Generate output HTML
43
     // Generate output HTML
39
     var card_html = card_pages_generate_html(card_data, card_options);
44
     var card_html = card_pages_generate_html(card_data, card_options);
40
 
45
 
49
 
54
 
50
     // Send the generated HTML to the new window
55
     // Send the generated HTML to the new window
51
     // Use a delay to give the new window time to set up a message listener
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
 function ui_load_sample() {
60
 function ui_load_sample() {
209
             ui_set_card_color(value);
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
     // Styling
230
     // Styling
214
     $(".dropdown-colorselector").addClass("input-group-addon color-input-addon");
231
     $(".dropdown-colorselector").addClass("input-group-addon color-input-addon");
219
     ui_render_selected_card();
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
 function ui_change_option() {
247
 function ui_change_option() {
223
     var property = $(this).attr("data-option");
248
     var property = $(this).attr("data-option");
224
     var value = $(this).val();
249
     var value = $(this).val();
390
     $("#page-columns").change(ui_change_option);
415
     $("#page-columns").change(ui_change_option);
391
     $("#card-arrangement").change(ui_change_option);
416
     $("#card-arrangement").change(ui_change_option);
392
     $("#card-size").change(ui_change_option);
417
     $("#card-size").change(ui_change_option);
418
+    $("#background-color").change(ui_change_option);
393
 
419
 
394
     $("#default-color").change(ui_change_default_color);
420
     $("#default-color").change(ui_change_default_color);
395
     $("#default-icon").change(ui_change_default_icon);
421
     $("#default-icon").change(ui_change_default_icon);

Laden…
Annuleren
Opslaan