write_drawn_letters.json

Le fichier JSON de l'exemple « Des lettres que vous dessinez vous-même ». Une coche, une croix et un tiret dessinés par le programme, ajoutés au document comme une police, et posés au milieu de mots ordinaires.

JSON 149 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.

À quoi sert cet exemple

Un fichier de police contient des lettres dessinées par quelqu'un d'autre. Parfois, ce dont un document a besoin, c'est d'un signe que personne n'a dessiné pour vous : votre logo, la coche de vos fiches qualité, un symbole que votre métier connaît et qu'Unicode ignore. La réponse habituelle est de poser une image à chaque endroit, puis de calculer à la main de combien avancer avant le mot suivant — ce qui se défait le jour où le texte est traduit ou change de taille.

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
{
  "type3_fonts": [
    {
      "name": "marks",
      "matrix": [0.001, 0, 0, 0.001, 0, 0],
      "box": {"llx": 0, "lly": -200, "urx": 1000, "ury": 800},
      "glyphs": [
        {
          "character": "✓",
          "width": 1000,
          "items": [
            {
              "type": "path",
              "segments": [
                {"move_to": {"x": 140, "y": 480}},
                {"line_to": {"x": 390, "y": 230}},
                {"line_to": {"x": 870, "y": 740}}
              ],
              "stroke": {"width": 150, "color": [0.15, 0.55, 0.25]}
            }
          ]
        },
        {
          "character": "✗",
          "width": 1000,
          "items": [
            {
              "type": "path",
              "segments": [
                {"move_to": {"x": 200, "y": 230}},
                {"line_to": {"x": 810, "y": 740}},
                {"move_to": {"x": 810, "y": 230}},
                {"line_to": {"x": 200, "y": 740}}
              ],
              "stroke": {"width": 150, "color": [0.75, 0.15, 0.15]}
            }
          ]
        },
        {
          "character": "–",
          "width": 1000,
          "items": [
            {
              "type": "rect",
              "rect": {"llx": 160, "lly": 400, "urx": 840, "ury": 550},
              "fill": [0.55, 0.55, 0.55]
            }
          ]
        }
      ]
    },
    {
      "name": "shapes",
      "matrix": [0.001, 0, 0, 0.001, 0, 0],
      "box": {"llx": 0, "lly": -200, "urx": 1000, "ury": 800},
      "glyphs": [
        {
          "character": "■",
          "width": 1000,
          "box": {"llx": 200, "lly": 150, "urx": 800, "ury": 750},
          "items": [
            {
              "type": "rect",
              "rect": {"llx": 200, "lly": 150, "urx": 800, "ury": 750},
              "fill": [0]
            }
          ]
        }
      ]
    }
  ],
  "items": [
    {
      "type": "text",
      "rect": {"llx": 72, "lly": 700, "urx": 522, "ury": 760},
      "content": ["Letters you draw yourself"],
      "font": "DejaVuSans",
      "font_size": 18
    },
    {
      "type": "text",
      "rect": {"llx": 72, "lly": 640, "urx": 522, "ury": 724.4},
      "content": [
        "The three marks below are not in any font file. Each one is a drawing this program made, added to the document as a font, and set in a line of text like any other letter. Copy the line out of this file and the marks come back as the characters they stand for."
      ],
      "font": "DejaVuSans",
      "font_size": 10
    },
    {
      "type": "text",
      "rect": {"llx": 72, "lly": 620, "urx": 522, "ury": 662.4},
      "content": ["Marks that paint themselves"],
      "font": "DejaVuSans",
      "font_size": 12
    },
    {
      "type": "text",
      "rect": {"llx": 72, "lly": 600, "urx": 522, "ury": 638},
      "font": "DejaVuSans",
      "font_size": 11,
      "content": [
        {"text": "✓", "font": "marks"},
        {"text": " Invoice sent"},
        {"text": "    "},
        {"text": "✗", "font": "marks"},
        {"text": " Payment received"},
        {"text": "    "},
        {"text": "–", "font": "marks"},
        {"text": " Delivery note"}
      ]
    },
    {
      "type": "text",
      "rect": {"llx": 72, "lly": 560, "urx": 522, "ury": 598.8},
      "content": ["Marks that take the colour around them"],
      "font": "DejaVuSans",
      "font_size": 12
    },
    {
      "type": "text",
      "rect": {"llx": 72, "lly": 540, "urx": 522, "ury": 574.4},
      "font": "DejaVuSans",
      "font_size": 11,
      "content": [
        {"text": "■", "font": "shapes", "color": [0.75, 0.15, 0.15]},
        {"text": " Overdue", "color": [0.75, 0.15, 0.15]}
      ]
    },
    {
      "type": "text",
      "rect": {"llx": 72, "lly": 520, "urx": 522, "ury": 557.2},
      "font": "DejaVuSans",
      "font_size": 11,
      "content": [
        {"text": "■", "font": "shapes", "color": [0.15, 0.35, 0.75]},
        {"text": " Settled", "color": [0.15, 0.35, 0.75]}
      ]
    },
    {
      "type": "text",
      "rect": {"llx": 72, "lly": 460, "urx": 522, "ury": 518},
      "content": [
        "A mark of the first kind carries its own colour, which no font read from a file can do. A mark of the second kind states a shape and nothing else, so the colour of the words it sits among is the colour it comes out in."
      ],
      "font": "DejaVuSans",
      "font_size": 10
    }
  ]
}