Browse Source

More features

developed on gh-pages by accident
crobi 10 years ago
parent
commit
5f2f1797fa

+ 87
- 0
generator/css/card-size.css View File

@@ -0,0 +1,87 @@
1
+/*
2
+    Full page printing CSS
3
+    ======================
4
+
5
+    Since we want precisely specify the card sizes, we must not allow the user to scale the content to fit a sheet of paper.
6
+    We must also make sure the browser does not add randomly sized margins to the page.
7
+
8
+    Instead, we use absolute sizes for all content, such that it fills a sheet of paper:
9
+    1) Remove all page margins (using the @page CSS rule). The borders of the document will be outside of the printable area,
10
+       however, we will cluster all content around the center, so that we won't crop anything.
11
+    2) Fill the document with <page> elements which have an absolute size equal to the full area of the paper.
12
+    3) Fill each page with cards, arranged around the center of the page.
13
+*/
14
+
15
+/* Remove page margins */
16
+@page {
17
+    margin: 0;
18
+    padding: 0;
19
+}
20
+
21
+/* Center all content within a page */
22
+.page {
23
+    display: flex;
24
+    align-content: center;
25
+    justify-content: center;
26
+    flex-direction: row;
27
+    flex-wrap: wrap;
28
+    page-break-after: always;
29
+    padding: 0mm;
30
+}
31
+
32
+/* A4 paper area (minus epsilon for rounding) */
33
+page[size="A4"] {
34
+    width:  209mm; /* full: 210.0mm */
35
+    height: 295mm; /* full: 297.0mm */
36
+}
37
+
38
+/* US letter area (minus epsilon for rounding) */
39
+page[size="Letter"] {
40
+    width:  215mm; /* full: 215.9mm (8.5in) */
41
+    height: 278mm; /* full: 279.4mm (11.0in) */
42
+}
43
+
44
+/* Default card size */
45
+.card {
46
+    width:2.5in;
47
+    min-width:2.5in;
48
+    height:3.5in;
49
+}
50
+
51
+/* Bridge card size */
52
+.card-size-225x35 {
53
+    width:2.25in;
54
+    min-width:2.25in;
55
+    height:3.5in;
56
+}
57
+
58
+/* Poker / Magic card size */
59
+.card-size-25x35 {
60
+    width:2.5in;
61
+    min-width:2.5in;
62
+    height:3.5in;
63
+}
64
+
65
+/* Poker / Magic card size */
66
+.card-size-35x50 {
67
+    width:3.5in;
68
+    min-width:3.5in;
69
+    height:5.0in;
70
+}
71
+
72
+/* Landscape big card */
73
+.card-size-75x50 {
74
+    width:7.5in;
75
+    min-width:7.5in;
76
+    height:5.0in;
77
+}
78
+
79
+.page[size="A4"] .card-size-full3x3 {
80
+    width:69mm;
81
+    height:98mm;
82
+}
83
+
84
+.page[size="Letter"] .card-size-full3x3 {
85
+    width:71mm;
86
+    height:92mm;
87
+}

+ 24
- 15
generator/css/cards.css View File

@@ -1,9 +1,7 @@
1 1
 .card {
2
-    width:66mm;
3
-    min-width:66mm;
4
-    height:95mm;
5 2
     border: 2mm solid;
6 3
     border-radius: 4px;
4
+    box-sizing: border-box;
7 5
     position: relative;
8 6
     display: flex;
9 7
     flex-direction: column;
@@ -101,23 +99,34 @@
101 99
     background-color: inherit;
102 100
     color: white;
103 101
 }
104
-.card-title-big {
105
-    font-size: 6mm;
106
-    line-height: 6mm;
102
+.card-title-16 {
103
+    font-size: 16pt;
104
+    line-height: 6.5mm;
107 105
 }
108
-.card-title-normal {
109
-    font-size: 5mm;
110
-    line-height: 6mm;
106
+.card-title-15 {
107
+    font-size: 15pt;
108
+    line-height: 6.5mm;
111 109
 }
112
-.card-title-small {
113
-    font-size: 4mm;
110
+.card-title-14 {
111
+    font-size: 14pt;
114 112
     line-height: 6.5mm;
115 113
 }
116
-.card-title-tiny {
117
-    font-size: 3.5mm;
118
-    line-height: 6.75mm;
114
+.card-title-13 {
115
+    font-size: 13pt;
116
+    line-height: 7mm;
117
+}
118
+.card-title-12 {
119
+    font-size: 12pt;
120
+    line-height: 7mm;
121
+}
122
+.card-title-11 {
123
+    font-size: 11pt;
124
+    line-height: 7.5mm;
125
+}
126
+.card-title-10 {
127
+    font-size: 10pt;
128
+    line-height: 7.5mm;
119 129
 }
120
-
121 130
 .card-subtitle {
122 131
     height: 18px;
123 132
     line-height: 18px;

+ 30
- 0
generator/css/output.css View File

@@ -0,0 +1,30 @@
1
+.page-background {
2
+  background: rgb(204,204,204); 
3
+}
4
+
5
+body {
6
+    display: flex;
7
+    justify-content:center;
8
+    align-content:center;
9
+}
10
+
11
+.page-preview {
12
+    background: white;
13
+    margin: 0 auto;
14
+    margin-bottom: 16px;
15
+    box-shadow: 0 0 8px rgba(0,0,0,0.5);
16
+}
17
+
18
+@media print {
19
+  .page-preview {
20
+    margin: 0;
21
+    box-shadow: 0;
22
+    background-color: white;
23
+  }
24
+  .page-background {
25
+    margin: 0;
26
+    box-shadow: 0;
27
+    /* Set the background to gray to visualize the page size in the print preview */
28
+    background-color: gray;
29
+  }
30
+}

+ 0
- 51
generator/css/page.css View File

@@ -1,51 +0,0 @@
1
-body {
2
-  background: rgb(204,204,204); 
3
-}
4
-
5
-page[size="A4"] {
6
-    background: white;
7
-    width: 210mm;
8
-    height: 297mm;
9
-    display: block;
10
-    margin: 0 auto;
11
-    margin-bottom: 16px;
12
-    box-shadow: 0 0 8px rgba(0,0,0,0.5);
13
-    display: flex;
14
-    align-content: center;
15
-    justify-content: center;
16
-    flex-direction: row;
17
-    flex-wrap: wrap;
18
-    page-break-after: always;
19
-}
20
-
21
-#output-frame {
22
-    border: 0;
23
-    width: 100%;
24
-}
25
-
26
-@media print {
27
-  body, page[size="A4"] {
28
-    margin: 0;
29
-    box-shadow: 0;
30
-    background-color: white;
31
-  }
32
-  #input-container {
33
-      display: none;
34
-  }
35
-  #output-container {
36
-      margin: 0;
37
-      padding: 0;
38
-  }
39
-}
40
-
41
-.input-button {
42
-    display:block;
43
-    height: 40px;
44
-    font-size: 24px;
45
-    width: 100%;
46
-    margin-bottom: 10px;
47
-}
48
-
49
-.input-data {
50
-    width: 100%;
51
-}

+ 1
- 1
generator/data/card_data_example.js View File

@@ -77,7 +77,7 @@ var card_data_example = [
77 77
         "count": 1,
78 78
         "color": "dimgray",
79 79
         "title": "Shortsword of Very Long Names",
80
-        "title_size": "tiny",
80
+        "title_size": "10",
81 81
         "icon": "crossed-swords",
82 82
         "contents": [
83 83
             "subtitle | Simple melee weapon (10gp)",

+ 89
- 9
generator/generate.html View File

@@ -1,4 +1,4 @@
1
-<!DOCTYPE html>
1
+<!DOCTYPE html>
2 2
 <html lang="en">
3 3
 <head>
4 4
     <title>RPG cards</title>
@@ -24,6 +24,7 @@
24 24
     <!-- CSS -->
25 25
     <link href="css/ui.css" rel="stylesheet" />
26 26
     <link href="css/cards.css" rel="stylesheet" />
27
+    <link href="css/card-size.css" rel="stylesheet" />
27 28
     <link href="css/icons.css" rel="stylesheet" />
28 29
     <link href="css/custom-icons.css" rel="stylesheet" />
29 30
     <!-- Fonts -->
@@ -81,6 +82,41 @@
81 82
                     </div>
82 83
                     <span class="help-block">Generated cards open in a new tab or window.</span>
83 84
                 </form>
85
+                <h3>Sizes</h3>
86
+                <form role="form" class="form-horizontal">
87
+                    <div class="form-group">
88
+                        <label for="page-size" class="col-sm-4 control-label">Page</label>
89
+                        <div class="col-sm-8">
90
+                            <select class="form-control" id="page-size" data-option="page_size">
91
+                                <option value="A4" selected>A4</option>
92
+                                <option value="Letter">US letter</option>
93
+                            </select>
94
+                        </div>
95
+                    </div>
96
+                    <div class="form-group">
97
+                        <label for="card-size" class="col-sm-4 control-label">Card</label>
98
+                        <div class="col-sm-8">
99
+                            <select class="form-control" id="card-size" data-option="card_size">
100
+                                <option value="225x35">2.25&quot; x 3.5&quot; (Bridge)</option>
101
+                                <option value="25x35" selected>2.5&quot; x 3.5&quot; (Poker)</option>
102
+                                <option value="35x50">3.5&quot; x 5.0&quot;</option>
103
+                                <option value="75x50">7.5&quot; x 5.0&quot;</option>
104
+                            </select>
105
+                        </div>
106
+                    </div>
107
+                    <div class="form-group">
108
+                        <label for="card-size" class="col-sm-4 control-label">Cards/page</label>
109
+                        <div class="col-sm-3">
110
+                            <input type="text" id="page-rows" class="form-control" data-option="page_rows" value="3">
111
+                        </div>
112
+                        <div class="col-sm-2">
113
+                            <p class="form-control-static">x</p>
114
+                        </div>
115
+                        <div class="col-sm-3">
116
+                            <input type="text" id="page-columns" class="form-control" data-option="page_columns" value="3">
117
+                        </div>
118
+                    </div>
119
+                </form>
84 120
                 <h3>Default values</h3>
85 121
                 <form role="form" class="form-horizontal">
86 122
                     <div class="form-group">
@@ -117,10 +153,13 @@
117 153
                         <label for="default-title-size" class="col-sm-2 control-label">Title</label>
118 154
                         <div class="col-sm-10">
119 155
                             <select class="form-control" id="default-title-size">
120
-                                <option value="big">big font</option>
121
-                                <option value="normal" selected>normal font</option>
122
-                                <option value="small">small font</option>
123
-                                <option value="tiny">tiny font</option>
156
+                                <option value="16">16pt font</option>
157
+                                <option value="15">15pt font</option>
158
+                                <option value="14">14pt font</option>
159
+                                <option value="13" selected>13pt font</option>
160
+                                <option value="12">12pt font</option>
161
+                                <option value="11">11pt font</option>
162
+                                <option value="10">10pt font</option>
124 163
                             </select>
125 164
                         </div>
126 165
                     </div>
@@ -175,10 +214,25 @@
175 214
                             <input type="text" id="card-title" class="form-control" placeholder="Title">
176 215
                         </div>
177 216
                     </div>
217
+                    <div class="form-group">
218
+                        <label for="card-title-size" class="col-sm-2 control-label">Title</label>
219
+                        <div class="col-sm-10">
220
+                            <select class="form-control" id="card-title-size" data-property="title_size">
221
+                                <option value="" selected>default font</option>
222
+                                <option value="16">16pt font</option>
223
+                                <option value="15">15pt font</option>
224
+                                <option value="14">14pt font</option>
225
+                                <option value="13">13pt font</option>
226
+                                <option value="12">12pt font</option>
227
+                                <option value="11">11pt font</option>
228
+                                <option value="10">10pt font</option>
229
+                            </select>
230
+                        </div>
231
+                    </div>
178 232
                     <div class="form-group">
179 233
                         <label for="card-count" class="col-sm-2 control-label">Count</label>
180 234
                         <div class="col-sm-10">
181
-                            <input type="number" id="card-count" class="form-control" placeholder="Count" data-property="count">
235
+                            <input type="number" id="card-count" class="form-control" placeholder="Count" data-property="count" value="1">
182 236
                         </div>
183 237
                     </div>
184 238
                     <div class="form-group">
@@ -188,7 +242,7 @@
188 242
                                 <span class="input-group-btn">
189 243
                                     <button class="btn btn-default icon-select-button" type="button">Search</button>
190 244
                                 </span>
191
-                                <input type="text" id="card-icon" class="form-control icon-list" placeholder="Icon name (default icon if empty)" data-property="icon">
245
+                                <input type="text" id="card-icon" class="form-control icon-list" placeholder="Default icon" data-property="icon">
192 246
                             </div>
193 247
                         </div>
194 248
                     </div>
@@ -199,7 +253,7 @@
199 253
                                 <span class="input-group-btn">
200 254
                                     <button class="btn btn-default icon-select-button" type="button">Search</button>
201 255
                                 </span>
202
-                                <input type="text" id="card-icon-back" class="form-control icon-list" placeholder="Icon name (same as front if empty)" data-property="icon_back">
256
+                                <input type="text" id="card-icon-back" class="form-control icon-list" placeholder="Same as front" data-property="icon_back">
203 257
                             </div>
204 258
                         </div>
205 259
                     </div>
@@ -208,7 +262,7 @@
208 262
                         <div class="col-sm-10">
209 263
                             <div class="input-group">
210 264
                                 <select id="card_color_selector" class="colorselector-data"></select>
211
-                                <input type="text" id="card-color" class="form-control" placeholder="Card color (default color if empty)" data-property="color">
265
+                                <input type="text" id="card-color" class="form-control" placeholder="Default color" data-property="color">
212 266
                             </div>
213 267
                         </div>
214 268
                     </div>
@@ -227,5 +281,31 @@
227 281
             </div>
228 282
         </div>
229 283
     </div>
284
+    <!-- Modal -->
285
+    <div class="modal" id="print-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
286
+        <div class="modal-dialog">
287
+            <div class="modal-content">
288
+                <div class="modal-header">
289
+                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
290
+                    <h4 class="modal-title" id="myModalLabel">Printing generated cards</h4>
291
+                </div>
292
+                <div class="modal-body">
293
+                    <ul>
294
+                        <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>
295
+                        <li>Make sure to use the correct paper size (same as in the editor).</li>
296
+                        <li>Enable double sided printing (flip on long edge).</li>
297
+                        <li>Do not scale the document to fit the page.</li>
298
+                        <li>
299
+                            Some printers are not very precise (pages print slightly shifted or rotated) and the cards will not line up with the card backs.
300
+                            If this is the case, there's nothing you can do. Try a different printer or print single-sided.
301
+                        </li>
302
+                    </ul>
303
+                </div>
304
+                <div class="modal-footer">
305
+                    <button type="button" class="btn btn-default" data-dismiss="modal">Ok, got it</button>
306
+                </div>
307
+            </div>
308
+        </div>
309
+    </div>
230 310
 </body>
231 311
 </html>

+ 11
- 10
generator/js/cards.js View File

@@ -5,10 +5,11 @@ function card_default_options() {
5 5
     return {
6 6
         default_color: "black",
7 7
         default_icon: "ace",
8
-        default_title_size: "normal",
8
+        default_title_size: "13",
9 9
         page_size: "A4",
10 10
         page_rows: 3,
11 11
         page_columns: 3,
12
+        card_size: "25x35",
12 13
         icon_inline: true
13 14
     }
14 15
 }
@@ -191,7 +192,7 @@ function card_generate_front(data, options) {
191 192
     var style_color = card_generate_color_style(color, options);
192 193
 
193 194
     var result = "";
194
-    result += '<div class="card" ' + style_color + '>';
195
+    result += '<div class="card card-size-' + options.card_size + '" ' + style_color + '>';
195 196
     result += card_element_icon(data, options);
196 197
     result += card_element_title(data, options);
197 198
     result += card_generate_contents(data.contents, data, options);
@@ -207,7 +208,7 @@ function card_generate_back(data, options) {
207 208
     var icon = card_data_icon_back(data, options);
208 209
 
209 210
     var result = "";
210
-    result += '<div class="card" ' + style_color + '>';
211
+    result += '<div class="card card-size-' + options.card_size + '" ' + style_color + '>';
211 212
     result += '  <div class="card-back" ' + style_gradient + '>';
212 213
     result += '    <div class="card-back-inner">';
213 214
     result += '      <div class="card-back-icon icon-' + icon + '" ' + style_color + '></div>';
@@ -222,7 +223,7 @@ function card_generate_empty(count, options) {
222 223
     var style_color = card_generate_color_style("white");
223 224
 
224 225
     var result = "";
225
-    result += '<div class="card" ' + style_color + '>';
226
+    result += '<div class="card card-size-' + options.card_size + '" ' + style_color + '>';
226 227
     result += '</div>';
227 228
 
228 229
     return card_repeat(result, count);
@@ -262,11 +263,11 @@ function cards_pages_flip_left_right(cards, rows, cols) {
262 263
     return result;
263 264
 }
264 265
 
265
-function card_pages_add_padding(cards, rows, cols) {
266
-    var cards_per_page = rows * cols;
266
+function card_pages_add_padding(cards, options) {
267
+    var cards_per_page = options.page_rows * options.page_columns;
267 268
     var last_page_cards = cards.length % cards_per_page;
268 269
     if (last_page_cards !== 0) {
269
-        return cards.concat(card_generate_empty(cards_per_page - last_page_cards));
270
+        return cards.concat(card_generate_empty(cards_per_page - last_page_cards, options));
270 271
     } else {
271 272
         return cards;
272 273
     }
@@ -277,7 +278,7 @@ function card_pages_wrap(pages, options) {
277 278
 
278 279
     var result = "";
279 280
     for (var i = 0; i < pages.length; ++i) {
280
-        result += '<page size="' + size + '">\n';
281
+        result += '<page class="page page-preview" size="' + size + '">\n';
281 282
         result += pages[i].join("\n");
282 283
         result += '</page>\n';
283 284
     }
@@ -301,8 +302,8 @@ function card_pages_generate_html(card_data, options) {
301 302
     });
302 303
 
303 304
     // Add padding cards so that the last page is full of cards
304
-    front_cards = card_pages_add_padding(front_cards, rows, cols);
305
-    back_cards = card_pages_add_padding(back_cards, rows, cols);
305
+    front_cards = card_pages_add_padding(front_cards, options);
306
+    back_cards = card_pages_add_padding(back_cards, options);
306 307
 
307 308
     // Split cards to pages
308 309
     var front_pages = card_pages_split(front_cards, rows, cols);

+ 21
- 0
generator/js/ui.js View File

@@ -33,6 +33,7 @@ function merge(left, right, compare) {
33 33
     return result;
34 34
 }
35 35
 
36
+var ui_generate_modal_shown = false;
36 37
 function ui_generate() {
37 38
     // Generate output HTML
38 39
     var card_html = card_pages_generate_html(card_data, card_options);
@@ -41,6 +42,11 @@ function ui_generate() {
41 42
     // Use a separate window to avoid CSS conflicts
42 43
     var tab = window.open("output.html", 'rpg-cards-output');
43 44
 
45
+    if (ui_generate_modal_shown == false) {
46
+        $("#print-modal").modal('show');
47
+        ui_generate_modal_shown = true;
48
+    }
49
+
44 50
     // Send the generated HTML to the new window
45 51
     // Use a delay to give the new window time to set up a message listener
46 52
     setTimeout(function () { tab.postMessage(card_html, '*') }, 100);
@@ -148,6 +154,7 @@ function ui_update_selected_card() {
148 154
     var card = ui_selected_card();
149 155
     if (card) {
150 156
         $("#card-title").val(card.title);
157
+        $("#card-title-size").val(card.title_size);
151 158
         $("#card-count").val(card.count);
152 159
         $("#card-icon").val(card.icon);
153 160
         $("#card-icon-back").val(card.icon_back);
@@ -209,6 +216,14 @@ function ui_set_default_color(color) {
209 216
     ui_render_selected_card();
210 217
 }
211 218
 
219
+function ui_change_option() {
220
+    var property = $(this).attr("data-option");
221
+    var value = $(this).val();
222
+    card_options[property] = value;
223
+    ui_render_selected_card();
224
+
225
+}
226
+
212 227
 function ui_change_card_title() {
213 228
     var title = $("#card-title").val();
214 229
     var card = ui_selected_card();
@@ -360,12 +375,18 @@ $(document).ready(function () {
360 375
     $("#selected-card").change(ui_update_selected_card);
361 376
 
362 377
     $("#card-title").change(ui_change_card_title);
378
+    $("#card-title-size").change(ui_change_card_property);
363 379
     $("#card-icon").change(ui_change_card_property);
364 380
     $("#card-count").change(ui_change_card_property);
365 381
     $("#card-icon-back").change(ui_change_card_property);
366 382
     $("#card-color").change(ui_change_card_color);
367 383
     $("#card-contents").change(ui_change_card_contents);
368 384
 
385
+    $("#page-size").change(ui_change_option);
386
+    $("#page-rows").change(ui_change_option);
387
+    $("#page-columns").change(ui_change_option);
388
+    $("#card-size").change(ui_change_option);
389
+
369 390
     $("#default-color").change(ui_change_default_color);
370 391
     $("#default-icon").change(ui_change_default_icon);
371 392
     $("#default-title-size").change(ui_change_default_title_size);

+ 3
- 2
generator/output.html View File

@@ -5,14 +5,15 @@
5 5
     <!-- Javascript -->
6 6
     <script type="text/javascript" src="js/output.js"></script>
7 7
     <!-- CSS -->
8
-    <link rel=" stylesheet" type="text/css" href="css/page.css">
8
+    <link rel=" stylesheet" type="text/css" href="css/output.css">
9 9
     <link rel="stylesheet" type="text/css" href="css/cards.css">
10
+    <link rel="stylesheet" type="text/css" href="css/card-size.css">
10 11
     <link rel="stylesheet" type="text/css" href="css/icons.css">
11 12
     <link rel="stylesheet" type="text/css" href="css/custom-icons.css">
12 13
     <!-- Fonts -->
13 14
     <link href='https://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
14 15
     <link href='https://fonts.googleapis.com/css?family=Lora:700' rel='stylesheet' type='text/css'>
15 16
 </head>
16
-<body>
17
+<body class="page-background">
17 18
 </body>
18 19
 </html>

Loading…
Cancel
Save