write_layers.json

Le fichier JSON de l'exemple « Un seul dessin, et chacun y voit le sien ». Le même plan d'étage sur six calques montrés et cachés un par un : les meubles et les cotes montrés, les notes internes cachées jusqu'à ce qu'on les demande, et un filigrane de brouillon destiné à l'écran et non au papier.

JSON 384 lignes

Ce fichier est une requête : une application l'envoie par le réseau au serveur, qui crée le PDF et le renvoie. Il donne la même page que les versions Rust et Python de cet exemple. Une requête nomme chaque fichier qu'elle emploie, jamais le contenu de ces fichiers ; l'appel porte la requête et les fichiers ensemble. Une police que le serveur détient déjà, comme DejaVuSans, se nomme sans rien y joindre. Envoyez la requête à l'adresse que donne la page de l'API.

La bibliothèque écrit chaque ligne de la page à une hauteur indiquée ; une requête donne plutôt un rectangle à un bloc de mots, si bien que le rectangle de chaque ligne est ici recalculé à partir de cette hauteur. Onze d'entre eux dépassent le plan sous lequel ils se tiennent, sans dommage, parce que la bibliothèque écrit ces lignes sans les couper là où un bloc de mots les couperait au bord de son rectangle. Les murs sont une seule couleur posée une fois du côté de la bibliothèque, un mur extérieur puis une cloison ; dans la requête ce sont deux choses, chacune indiquant cette couleur pour elle-même, et chaque meuble est rempli puis détouré comme deux formes là-bas et tracé une fois puis peint d'un coup ici. Les six calques eux-mêmes, ce que chacun contient, et le filigrane de brouillon qu'un lecteur peut décider de ne pas imprimer sont les mêmes des deux façons, jusqu'à l'ordre dans lequel le panneau les liste.

À quoi sert cet exemple

Le même plan doit atteindre trois personnes : le chantier, avec ses cotes ; le client, sans les notes internes ; l'imprimeur, sans le filigrane de brouillon. Faire trois fichiers, c'est trois fichiers à tenir d'accord, et le jour où l'un est refait et les autres non, quelqu'un construit d'après le mauvais plan.

Ce que montre cet exemple

  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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
{
  "layers": [
    {
      "name": "Furniture",
      "made_by": { "application": "Plan Studio", "work": "technical" }
    },
    { "name": "Dimensions" },
    { "name": "Notes", "visible": false },
    {
      "name": "Draft",
      "on_screen": true,
      "printed": false,
      "purpose": "watermark"
    },
    { "name": "Grid", "visible": false, "intent": "design" },
    { "name": "Crop marks", "purpose": "printers_marks" }
  ],
  "drawings": [
    {
      "name": "chair",
      "layer": "Furniture",
      "box": { "llx": 0.0, "lly": 0.0, "urx": 14.0, "ury": 10.0 },
      "items": [
        {
          "type": "rect",
          "rect": { "llx": 0.5, "lly": 0.5, "urx": 13.5, "ury": 9.5 },
          "fill": [0.85, 0.88, 0.93],
          "stroke": { "width": 1.0, "color": [0.35, 0.45, 0.6] }
        }
      ]
    }
  ],
  "items": [
    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 750.0, "urx": 560.0, "ury": 768.0 },
      "content": ["One plan, six layers"],
      "font": "DejaVuSans",
      "font_size": 15.0
    },
    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 730.0, "urx": 590.0, "ury": 742.0 },
      "content": [
        "The walls are always there. Everything else is a layer the reader can show and hide."
      ],
      "font": "DejaVuSans",
      "font_size": 10.0,
      "color": [0.35, 0.35, 0.35]
    },

    {
      "type": "rect",
      "rect": { "llx": 80.0, "lly": 380.0, "urx": 515.0, "ury": 700.0 },
      "stroke": { "width": 3.0, "color": [0.15, 0.15, 0.15] }
    },
    {
      "type": "line",
      "from": { "x": 345.0, "y": 380.0 },
      "to": { "x": 345.0, "y": 570.0 },
      "stroke": { "width": 3.0, "color": [0.15, 0.15, 0.15] }
    },

    {
      "type": "path",
      "segments": [
        { "move_to": { "x": 109.0, "y": 380.0 } },
        { "line_to": { "x": 109.0, "y": 700.0 } },
        { "move_to": { "x": 138.0, "y": 380.0 } },
        { "line_to": { "x": 138.0, "y": 700.0 } },
        { "move_to": { "x": 167.0, "y": 380.0 } },
        { "line_to": { "x": 167.0, "y": 700.0 } },
        { "move_to": { "x": 196.0, "y": 380.0 } },
        { "line_to": { "x": 196.0, "y": 700.0 } },
        { "move_to": { "x": 225.0, "y": 380.0 } },
        { "line_to": { "x": 225.0, "y": 700.0 } },
        { "move_to": { "x": 254.0, "y": 380.0 } },
        { "line_to": { "x": 254.0, "y": 700.0 } },
        { "move_to": { "x": 283.0, "y": 380.0 } },
        { "line_to": { "x": 283.0, "y": 700.0 } },
        { "move_to": { "x": 312.0, "y": 380.0 } },
        { "line_to": { "x": 312.0, "y": 700.0 } },
        { "move_to": { "x": 341.0, "y": 380.0 } },
        { "line_to": { "x": 341.0, "y": 700.0 } },
        { "move_to": { "x": 370.0, "y": 380.0 } },
        { "line_to": { "x": 370.0, "y": 700.0 } },
        { "move_to": { "x": 399.0, "y": 380.0 } },
        { "line_to": { "x": 399.0, "y": 700.0 } },
        { "move_to": { "x": 428.0, "y": 380.0 } },
        { "line_to": { "x": 428.0, "y": 700.0 } },
        { "move_to": { "x": 457.0, "y": 380.0 } },
        { "line_to": { "x": 457.0, "y": 700.0 } },
        { "move_to": { "x": 486.0, "y": 380.0 } },
        { "line_to": { "x": 486.0, "y": 700.0 } },
        { "move_to": { "x": 80.0, "y": 412.0 } },
        { "line_to": { "x": 515.0, "y": 412.0 } },
        { "move_to": { "x": 80.0, "y": 444.0 } },
        { "line_to": { "x": 515.0, "y": 444.0 } },
        { "move_to": { "x": 80.0, "y": 476.0 } },
        { "line_to": { "x": 515.0, "y": 476.0 } },
        { "move_to": { "x": 80.0, "y": 508.0 } },
        { "line_to": { "x": 515.0, "y": 508.0 } },
        { "move_to": { "x": 80.0, "y": 540.0 } },
        { "line_to": { "x": 515.0, "y": 540.0 } },
        { "move_to": { "x": 80.0, "y": 572.0 } },
        { "line_to": { "x": 515.0, "y": 572.0 } },
        { "move_to": { "x": 80.0, "y": 604.0 } },
        { "line_to": { "x": 515.0, "y": 604.0 } },
        { "move_to": { "x": 80.0, "y": 636.0 } },
        { "line_to": { "x": 515.0, "y": 636.0 } },
        { "move_to": { "x": 80.0, "y": 668.0 } },
        { "line_to": { "x": 515.0, "y": 668.0 } }
      ],
      "stroke": { "width": 0.3, "color": [0.55, 0.75, 0.9] },
      "layer": "Grid"
    },

    {
      "type": "rect",
      "rect": { "llx": 120.0, "lly": 590.0, "urx": 240.0, "ury": 660.0 },
      "fill": [0.85, 0.88, 0.93],
      "stroke": { "width": 1.0, "color": [0.35, 0.45, 0.6] },
      "layer": "Furniture"
    },
    {
      "type": "rect",
      "rect": { "llx": 380.0, "lly": 570.0, "urx": 470.0, "ury": 680.0 },
      "fill": [0.85, 0.88, 0.93],
      "stroke": { "width": 1.0, "color": [0.35, 0.45, 0.6] },
      "layer": "Furniture"
    },
    {
      "type": "rect",
      "rect": { "llx": 370.0, "lly": 410.0, "urx": 480.0, "ury": 450.0 },
      "fill": [0.85, 0.88, 0.93],
      "stroke": { "width": 1.0, "color": [0.35, 0.45, 0.6] },
      "layer": "Furniture"
    },

    {
      "type": "drawing",
      "drawing": "chair",
      "x": 140.0,
      "y": 662.0
    },
    {
      "type": "drawing",
      "drawing": "chair",
      "x": 173.0,
      "y": 662.0
    },
    {
      "type": "drawing",
      "drawing": "chair",
      "x": 206.0,
      "y": 662.0
    },
    {
      "type": "drawing",
      "drawing": "chair",
      "x": 140.0,
      "y": 578.0
    },
    {
      "type": "drawing",
      "drawing": "chair",
      "x": 173.0,
      "y": 578.0
    },
    {
      "type": "drawing",
      "drawing": "chair",
      "x": 206.0,
      "y": 578.0
    },

    {
      "type": "path",
      "segments": [
        { "move_to": { "x": 80.0, "y": 354.0 } },
        { "line_to": { "x": 515.0, "y": 354.0 } },
        { "move_to": { "x": 80.0, "y": 349.0 } },
        { "line_to": { "x": 80.0, "y": 359.0 } },
        { "move_to": { "x": 515.0, "y": 349.0 } },
        { "line_to": { "x": 515.0, "y": 359.0 } },
        { "move_to": { "x": 34.0, "y": 380.0 } },
        { "line_to": { "x": 34.0, "y": 700.0 } },
        { "move_to": { "x": 29.0, "y": 380.0 } },
        { "line_to": { "x": 39.0, "y": 380.0 } },
        { "move_to": { "x": 29.0, "y": 700.0 } },
        { "line_to": { "x": 39.0, "y": 700.0 } }
      ],
      "stroke": { "width": 0.8, "color": [0.2, 0.5, 0.35] },
      "layer": "Dimensions"
    },
    {
      "type": "text",
      "rect": { "llx": 279.5, "lly": 362.0, "urx": 360.0, "ury": 372.8 },
      "content": ["7.25 m"],
      "font": "DejaVuSans",
      "font_size": 9.0,
      "color": [0.2, 0.5, 0.35],
      "layer": "Dimensions"
    },
    {
      "type": "text",
      "rect": { "llx": 40.0, "lly": 540.0, "urx": 120.0, "ury": 550.8 },
      "content": ["5.00 m"],
      "font": "DejaVuSans",
      "font_size": 9.0,
      "color": [0.2, 0.5, 0.35],
      "layer": "Dimensions"
    },

    {
      "type": "text",
      "rect": { "llx": 124.0, "lly": 570.0, "urx": 340.0, "ury": 579.6 },
      "content": ["Table seats six."],
      "font": "DejaVuSans",
      "font_size": 8.0,
      "color": [0.7, 0.25, 0.1],
      "layer": "Notes"
    },
    {
      "type": "text",
      "rect": { "llx": 372.0, "lly": 552.0, "urx": 590.0, "ury": 561.6 },
      "content": ["Bed against the party wall."],
      "font": "DejaVuSans",
      "font_size": 8.0,
      "color": [0.7, 0.25, 0.1],
      "layer": "Notes"
    },
    {
      "type": "text",
      "rect": { "llx": 372.0, "lly": 396.0, "urx": 590.0, "ury": 405.6 },
      "content": ["Counter, waste under."],
      "font": "DejaVuSans",
      "font_size": 8.0,
      "color": [0.7, 0.25, 0.1],
      "layer": "Notes"
    },

    {
      "type": "stamp",
      "rect": { "llx": 80.0, "lly": 380.0, "urx": 515.0, "ury": 700.0 },
      "content": "DRAFT",
      "font": "DejaVuSans",
      "slant": "up",
      "color": [0.8, 0.3, 0.3],
      "layer": "Draft"
    },

    {
      "type": "path",
      "segments": [
        { "move_to": { "x": 30.0, "y": 36.0 } },
        { "line_to": { "x": 12.0, "y": 36.0 } },
        { "move_to": { "x": 36.0, "y": 30.0 } },
        { "line_to": { "x": 36.0, "y": 12.0 } },
        { "move_to": { "x": 565.0, "y": 36.0 } },
        { "line_to": { "x": 583.0, "y": 36.0 } },
        { "move_to": { "x": 559.0, "y": 30.0 } },
        { "line_to": { "x": 559.0, "y": 12.0 } },
        { "move_to": { "x": 30.0, "y": 806.0 } },
        { "line_to": { "x": 12.0, "y": 806.0 } },
        { "move_to": { "x": 36.0, "y": 812.0 } },
        { "line_to": { "x": 36.0, "y": 830.0 } },
        { "move_to": { "x": 565.0, "y": 806.0 } },
        { "line_to": { "x": 583.0, "y": 806.0 } },
        { "move_to": { "x": 559.0, "y": 812.0 } },
        { "line_to": { "x": 559.0, "y": 830.0 } }
      ],
      "stroke": { "width": 0.5, "color": [0.0, 0.0, 0.0] },
      "layer": "Crop marks"
    },

    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 300.0, "urx": 165.0, "ury": 312.0 },
      "content": ["Furniture"],
      "font": "DejaVuSans",
      "font_size": 10.0
    },
    {
      "type": "text",
      "rect": { "llx": 170.0, "lly": 300.0, "urx": 590.0, "ury": 312.0 },
      "content": ["shown; turn it off and the rooms stand empty, chairs too"],
      "font": "DejaVuSans",
      "font_size": 10.0,
      "color": [0.35, 0.35, 0.35]
    },
    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 282.0, "urx": 165.0, "ury": 294.0 },
      "content": ["Dimensions"],
      "font": "DejaVuSans",
      "font_size": 10.0
    },
    {
      "type": "text",
      "rect": { "llx": 170.0, "lly": 282.0, "urx": 590.0, "ury": 294.0 },
      "content": ["shown; the distances around the plan"],
      "font": "DejaVuSans",
      "font_size": 10.0,
      "color": [0.35, 0.35, 0.35]
    },
    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 264.0, "urx": 165.0, "ury": 276.0 },
      "content": ["Notes"],
      "font": "DejaVuSans",
      "font_size": 10.0
    },
    {
      "type": "text",
      "rect": { "llx": 170.0, "lly": 264.0, "urx": 590.0, "ury": 276.0 },
      "content": ["hidden; turn it on to read them"],
      "font": "DejaVuSans",
      "font_size": 10.0,
      "color": [0.35, 0.35, 0.35]
    },
    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 246.0, "urx": 165.0, "ury": 258.0 },
      "content": ["Draft"],
      "font": "DejaVuSans",
      "font_size": 10.0
    },
    {
      "type": "text",
      "rect": { "llx": 170.0, "lly": 246.0, "urx": 590.0, "ury": 258.0 },
      "content": ["shown on screen, never printed; the file calls it a watermark"],
      "font": "DejaVuSans",
      "font_size": 10.0,
      "color": [0.35, 0.35, 0.35]
    },
    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 228.0, "urx": 165.0, "ury": 240.0 },
      "content": ["Grid"],
      "font": "DejaVuSans",
      "font_size": 10.0
    },
    {
      "type": "text",
      "rect": { "llx": 170.0, "lly": 228.0, "urx": 590.0, "ury": 240.0 },
      "content": ["hidden; an aid for whoever drew the plan, not part of it"],
      "font": "DejaVuSans",
      "font_size": 10.0,
      "color": [0.35, 0.35, 0.35]
    },
    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 210.0, "urx": 165.0, "ury": 222.0 },
      "content": ["Crop marks"],
      "font": "DejaVuSans",
      "font_size": 10.0
    },
    {
      "type": "text",
      "rect": { "llx": 170.0, "lly": 210.0, "urx": 590.0, "ury": 222.0 },
      "content": ["shown; the file calls them printer's marks"],
      "font": "DejaVuSans",
      "font_size": 10.0,
      "color": [0.35, 0.35, 0.35]
    },
    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 180.0, "urx": 590.0, "ury": 192.0 },
      "content": ["The draft mark carries its own answer for the printer, so nothing has to"],
      "font": "DejaVuSans",
      "font_size": 10.0,
      "color": [0.35, 0.35, 0.35]
    },
    {
      "type": "text",
      "rect": { "llx": 80.0, "lly": 166.0, "urx": 590.0, "ury": 178.0 },
      "content": ["be switched off before the page is printed."],
      "font": "DejaVuSans",
      "font_size": 10.0,
      "color": [0.35, 0.35, 0.35]
    }
  ]
}