~ubuntu-branches/ubuntu/lucid/xpdf/lucid-updates

« back to all changes in this revision

Viewing changes to fofi/FoFiType1C.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andy Price
  • Date: 2007-05-17 22:04:33 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517220433-gzcx2lrvllkbl7mr
Tags: 3.02-1ubuntu1
* Merge from Debian unstable (LP: #113365), remaining changes:
  - Added back 09_xpdfrc_manpage.dpatch (LP #71753)
  - Set Ubuntu maintainer

Show diffs side-by-side

added added

removed removed

Lines of Context:
129
129
  return map;
130
130
}
131
131
 
132
 
void FoFiType1C::convertToType1(char **newEncoding, GBool ascii,
 
132
void FoFiType1C::convertToType1(char *psName, char **newEncoding, GBool ascii,
133
133
                                FoFiOutputFunc outputFunc,
134
134
                                void *outputStream) {
 
135
  int psNameLen;
135
136
  Type1CEexecBuf eb;
136
137
  Type1CIndex subrIdx;
137
138
  Type1CIndexVal val;
138
 
  char buf[512];
 
139
  GString *buf;
 
140
  char buf2[256];
139
141
  char **enc;
140
142
  GBool ok;
141
143
  int i;
142
144
 
 
145
  if (psName) {
 
146
    psNameLen = strlen(psName);
 
147
  } else {
 
148
    psName = name->getCString();
 
149
    psNameLen = name->getLength();
 
150
  }
 
151
 
143
152
  // write header and font dictionary, up to encoding
144
153
  ok = gTrue;
145
154
  (*outputFunc)(outputStream, "%!FontType1-1.0: ", 17);
146
 
  (*outputFunc)(outputStream, name->getCString(), name->getLength());
 
155
  (*outputFunc)(outputStream, psName, psNameLen);
147
156
  if (topDict.versionSID != 0) {
148
 
    getString(topDict.versionSID, buf, &ok);
149
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
157
    getString(topDict.versionSID, buf2, &ok);
 
158
    (*outputFunc)(outputStream, buf2, strlen(buf2));
150
159
  }
151
160
  (*outputFunc)(outputStream, "\n", 1);
152
161
  // the dictionary needs room for 12 entries: the following 9, plus
156
165
  (*outputFunc)(outputStream, "/FontInfo 10 dict dup begin\n", 28);
157
166
  if (topDict.versionSID != 0) {
158
167
    (*outputFunc)(outputStream, "/version (", 10);
159
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
168
    (*outputFunc)(outputStream, buf2, strlen(buf2));
160
169
    (*outputFunc)(outputStream, ") readonly def\n", 15);
161
170
  }
162
171
  if (topDict.noticeSID != 0) {
163
 
    getString(topDict.noticeSID, buf, &ok);
 
172
    getString(topDict.noticeSID, buf2, &ok);
164
173
    (*outputFunc)(outputStream, "/Notice (", 9);
165
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
174
    (*outputFunc)(outputStream, buf2, strlen(buf2));
166
175
    (*outputFunc)(outputStream, ") readonly def\n", 15);
167
176
  }
168
177
  if (topDict.copyrightSID != 0) {
169
 
    getString(topDict.copyrightSID, buf, &ok);
 
178
    getString(topDict.copyrightSID, buf2, &ok);
170
179
    (*outputFunc)(outputStream, "/Copyright (", 12);
171
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
180
    (*outputFunc)(outputStream, buf2, strlen(buf2));
172
181
    (*outputFunc)(outputStream, ") readonly def\n", 15);
173
182
  }
174
183
  if (topDict.fullNameSID != 0) {
175
 
    getString(topDict.fullNameSID, buf, &ok);
 
184
    getString(topDict.fullNameSID, buf2, &ok);
176
185
    (*outputFunc)(outputStream, "/FullName (", 11);
177
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
186
    (*outputFunc)(outputStream, buf2, strlen(buf2));
178
187
    (*outputFunc)(outputStream, ") readonly def\n", 15);
179
188
  }
180
189
  if (topDict.familyNameSID != 0) {
181
 
    getString(topDict.familyNameSID, buf, &ok);
 
190
    getString(topDict.familyNameSID, buf2, &ok);
182
191
    (*outputFunc)(outputStream, "/FamilyName (", 13);
183
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
192
    (*outputFunc)(outputStream, buf2, strlen(buf2));
184
193
    (*outputFunc)(outputStream, ") readonly def\n", 15);
185
194
  }
186
195
  if (topDict.weightSID != 0) {
187
 
    getString(topDict.weightSID, buf, &ok);
 
196
    getString(topDict.weightSID, buf2, &ok);
188
197
    (*outputFunc)(outputStream, "/Weight (", 9);
189
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
198
    (*outputFunc)(outputStream, buf2, strlen(buf2));
190
199
    (*outputFunc)(outputStream, ") readonly def\n", 15);
191
200
  }
192
201
  if (topDict.isFixedPitch) {
194
203
  } else {
195
204
    (*outputFunc)(outputStream, "/isFixedPitch false def\n", 24);
196
205
  }
197
 
  sprintf(buf, "/ItalicAngle %g def\n", topDict.italicAngle);
198
 
  (*outputFunc)(outputStream, buf, strlen(buf));
199
 
  sprintf(buf, "/UnderlinePosition %g def\n", topDict.underlinePosition);
200
 
  (*outputFunc)(outputStream, buf, strlen(buf));
201
 
  sprintf(buf, "/UnderlineThickness %g def\n", topDict.underlineThickness);
202
 
  (*outputFunc)(outputStream, buf, strlen(buf));
 
206
  buf = GString::format("/ItalicAngle {0:.4g} def\n", topDict.italicAngle);
 
207
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
208
  delete buf;
 
209
  buf = GString::format("/UnderlinePosition {0:.4g} def\n",
 
210
                        topDict.underlinePosition);
 
211
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
212
  delete buf;
 
213
  buf = GString::format("/UnderlineThickness {0:.4g} def\n",
 
214
                        topDict.underlineThickness);
 
215
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
216
  delete buf;
203
217
  (*outputFunc)(outputStream, "end readonly def\n", 17);
204
218
  (*outputFunc)(outputStream, "/FontName /", 11);
205
 
  (*outputFunc)(outputStream, name->getCString(), name->getLength());
 
219
  (*outputFunc)(outputStream, psName, psNameLen);
206
220
  (*outputFunc)(outputStream, " def\n", 5);
207
 
  sprintf(buf, "/PaintType %d def\n", topDict.paintType);
208
 
  (*outputFunc)(outputStream, buf, strlen(buf));
 
221
  buf = GString::format("/PaintType {0:d} def\n", topDict.paintType);
 
222
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
223
  delete buf;
209
224
  (*outputFunc)(outputStream, "/FontType 1 def\n", 16);
210
 
  sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] readonly def\n",
211
 
          topDict.fontMatrix[0], topDict.fontMatrix[1], topDict.fontMatrix[2],
212
 
          topDict.fontMatrix[3], topDict.fontMatrix[4], topDict.fontMatrix[5]);
213
 
  (*outputFunc)(outputStream, buf, strlen(buf));
214
 
  sprintf(buf, "/FontBBox [%g %g %g %g] readonly def\n",
215
 
          topDict.fontBBox[0], topDict.fontBBox[1],
216
 
          topDict.fontBBox[2], topDict.fontBBox[3]);
217
 
  (*outputFunc)(outputStream, buf, strlen(buf));
218
 
  sprintf(buf, "/StrokeWidth %g def\n", topDict.strokeWidth);
219
 
  (*outputFunc)(outputStream, buf, strlen(buf));
 
225
  buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] readonly def\n",
 
226
                        topDict.fontMatrix[0], topDict.fontMatrix[1],
 
227
                        topDict.fontMatrix[2], topDict.fontMatrix[3],
 
228
                        topDict.fontMatrix[4], topDict.fontMatrix[5]);
 
229
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
230
  delete buf;
 
231
  buf = GString::format("/FontBBox [{0:.4g} {1:.4g} {2:.4g} {3:.4g}] readonly def\n",
 
232
                        topDict.fontBBox[0], topDict.fontBBox[1],
 
233
                        topDict.fontBBox[2], topDict.fontBBox[3]);
 
234
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
235
  delete buf;
 
236
  buf = GString::format("/StrokeWidth {0:.4g} def\n", topDict.strokeWidth);
 
237
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
238
  delete buf;
220
239
  if (topDict.uniqueID != 0) {
221
 
    sprintf(buf, "/UniqueID %d def\n", topDict.uniqueID);
222
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
240
    buf = GString::format("/UniqueID {0:d} def\n", topDict.uniqueID);
 
241
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
242
    delete buf;
223
243
  }
224
244
 
225
245
  // write the encoding
233
253
    enc = newEncoding ? newEncoding : encoding;
234
254
    for (i = 0; i < 256; ++i) {
235
255
      if (enc[i]) {
236
 
        sprintf(buf, "dup %d /%s put\n", i, enc[i]);
237
 
        (*outputFunc)(outputStream, buf, strlen(buf));
 
256
        buf = GString::format("dup {0:d} /{1:s} put\n", i, enc[i]);
 
257
        (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
258
        delete buf;
238
259
      }
239
260
    }
240
261
    (*outputFunc)(outputStream, "readonly def\n", 13);
261
282
  if (privateDicts[0].nBlueValues) {
262
283
    eexecWrite(&eb, "/BlueValues [");
263
284
    for (i = 0; i < privateDicts[0].nBlueValues; ++i) {
264
 
      sprintf(buf, "%s%d", i > 0 ? " " : "", privateDicts[0].blueValues[i]);
265
 
      eexecWrite(&eb, buf);
 
285
      buf = GString::format("{0:s}{1:d}",
 
286
                            i > 0 ? " " : "", privateDicts[0].blueValues[i]);
 
287
      eexecWrite(&eb, buf->getCString());
 
288
      delete buf;
266
289
    }
267
290
    eexecWrite(&eb, "] def\n");
268
291
  }
269
292
  if (privateDicts[0].nOtherBlues) {
270
293
    eexecWrite(&eb, "/OtherBlues [");
271
294
    for (i = 0; i < privateDicts[0].nOtherBlues; ++i) {
272
 
      sprintf(buf, "%s%d", i > 0 ? " " : "", privateDicts[0].otherBlues[i]);
273
 
      eexecWrite(&eb, buf);
 
295
      buf = GString::format("{0:s}{1:d}",
 
296
                            i > 0 ? " " : "", privateDicts[0].otherBlues[i]);
 
297
      eexecWrite(&eb, buf->getCString());
 
298
      delete buf;
274
299
    }
275
300
    eexecWrite(&eb, "] def\n");
276
301
  }
277
302
  if (privateDicts[0].nFamilyBlues) {
278
303
    eexecWrite(&eb, "/FamilyBlues [");
279
304
    for (i = 0; i < privateDicts[0].nFamilyBlues; ++i) {
280
 
      sprintf(buf, "%s%d", i > 0 ? " " : "", privateDicts[0].familyBlues[i]);
281
 
      eexecWrite(&eb, buf);
 
305
      buf = GString::format("{0:s}{1:d}",
 
306
                            i > 0 ? " " : "", privateDicts[0].familyBlues[i]);
 
307
      eexecWrite(&eb, buf->getCString());
 
308
      delete buf;
282
309
    }
283
310
    eexecWrite(&eb, "] def\n");
284
311
  }
285
312
  if (privateDicts[0].nFamilyOtherBlues) {
286
313
    eexecWrite(&eb, "/FamilyOtherBlues [");
287
314
    for (i = 0; i < privateDicts[0].nFamilyOtherBlues; ++i) {
288
 
      sprintf(buf, "%s%d", i > 0 ? " " : "",
289
 
              privateDicts[0].familyOtherBlues[i]);
290
 
      eexecWrite(&eb, buf);
 
315
      buf = GString::format("{0:s}{1:d}", i > 0 ? " " : "",
 
316
                            privateDicts[0].familyOtherBlues[i]);
 
317
      eexecWrite(&eb, buf->getCString());
 
318
      delete buf;
291
319
    }
292
320
    eexecWrite(&eb, "] def\n");
293
321
  }
294
322
  if (privateDicts[0].blueScale != 0.039625) {
295
 
    sprintf(buf, "/BlueScale %g def\n", privateDicts[0].blueScale);
296
 
    eexecWrite(&eb, buf);
 
323
    buf = GString::format("/BlueScale {0:.4g} def\n",
 
324
                          privateDicts[0].blueScale);
 
325
    eexecWrite(&eb, buf->getCString());
 
326
    delete buf;
297
327
  }
298
328
  if (privateDicts[0].blueShift != 7) {
299
 
    sprintf(buf, "/BlueShift %d def\n", privateDicts[0].blueShift);
300
 
    eexecWrite(&eb, buf);
 
329
    buf = GString::format("/BlueShift {0:d} def\n", privateDicts[0].blueShift);
 
330
    eexecWrite(&eb, buf->getCString());
 
331
    delete buf;
301
332
  }
302
333
  if (privateDicts[0].blueFuzz != 1) {
303
 
    sprintf(buf, "/BlueFuzz %d def\n", privateDicts[0].blueFuzz);
304
 
    eexecWrite(&eb, buf);
 
334
    buf = GString::format("/BlueFuzz {0:d} def\n", privateDicts[0].blueFuzz);
 
335
    eexecWrite(&eb, buf->getCString());
 
336
    delete buf;
305
337
  }
306
338
  if (privateDicts[0].hasStdHW) {
307
 
    sprintf(buf, "/StdHW [%g] def\n", privateDicts[0].stdHW);
308
 
    eexecWrite(&eb, buf);
 
339
    buf = GString::format("/StdHW [{0:.4g}] def\n", privateDicts[0].stdHW);
 
340
    eexecWrite(&eb, buf->getCString());
 
341
    delete buf;
309
342
  }
310
343
  if (privateDicts[0].hasStdVW) {
311
 
    sprintf(buf, "/StdVW [%g] def\n", privateDicts[0].stdVW);
312
 
    eexecWrite(&eb, buf);
 
344
    buf = GString::format("/StdVW [{0:.4g}] def\n", privateDicts[0].stdVW);
 
345
    eexecWrite(&eb, buf->getCString());
 
346
    delete buf;
313
347
  }
314
348
  if (privateDicts[0].nStemSnapH) {
315
349
    eexecWrite(&eb, "/StemSnapH [");
316
350
    for (i = 0; i < privateDicts[0].nStemSnapH; ++i) {
317
 
      sprintf(buf, "%s%g", i > 0 ? " " : "", privateDicts[0].stemSnapH[i]);
318
 
      eexecWrite(&eb, buf);
 
351
      buf = GString::format("{0:s}{1:.4g}",
 
352
                            i > 0 ? " " : "", privateDicts[0].stemSnapH[i]);
 
353
      eexecWrite(&eb, buf->getCString());
 
354
      delete buf;
319
355
    }
320
356
    eexecWrite(&eb, "] def\n");
321
357
  }
322
358
  if (privateDicts[0].nStemSnapV) {
323
359
    eexecWrite(&eb, "/StemSnapV [");
324
360
    for (i = 0; i < privateDicts[0].nStemSnapV; ++i) {
325
 
      sprintf(buf, "%s%g", i > 0 ? " " : "", privateDicts[0].stemSnapV[i]);
326
 
      eexecWrite(&eb, buf);
 
361
      buf = GString::format("{0:s}{1:.4g}",
 
362
                            i > 0 ? " " : "", privateDicts[0].stemSnapV[i]);
 
363
      eexecWrite(&eb, buf->getCString());
 
364
      delete buf;
327
365
    }
328
366
    eexecWrite(&eb, "] def\n");
329
367
  }
330
368
  if (privateDicts[0].hasForceBold) {
331
 
    sprintf(buf, "/ForceBold %s def\n",
332
 
            privateDicts[0].forceBold ? "true" : "false");
333
 
    eexecWrite(&eb, buf);
 
369
    buf = GString::format("/ForceBold {0:s} def\n",
 
370
                          privateDicts[0].forceBold ? "true" : "false");
 
371
    eexecWrite(&eb, buf->getCString());
 
372
    delete buf;
334
373
  }
335
374
  if (privateDicts[0].forceBoldThreshold != 0) {
336
 
    sprintf(buf, "/ForceBoldThreshold %g def\n",
337
 
            privateDicts[0].forceBoldThreshold);
338
 
    eexecWrite(&eb, buf);
 
375
    buf = GString::format("/ForceBoldThreshold {0:.4g} def\n",
 
376
                          privateDicts[0].forceBoldThreshold);
 
377
    eexecWrite(&eb, buf->getCString());
 
378
    delete buf;
339
379
  }
340
380
  if (privateDicts[0].languageGroup != 0) {
341
 
    sprintf(buf, "/LanguageGroup %d def\n", privateDicts[0].languageGroup);
342
 
    eexecWrite(&eb, buf);
 
381
    buf = GString::format("/LanguageGroup {0:d} def\n",
 
382
                          privateDicts[0].languageGroup);
 
383
    eexecWrite(&eb, buf->getCString());
 
384
    delete buf;
343
385
  }
344
386
  if (privateDicts[0].expansionFactor != 0.06) {
345
 
    sprintf(buf, "/ExpansionFactor %g def\n", privateDicts[0].expansionFactor);
346
 
    eexecWrite(&eb, buf);
 
387
    buf = GString::format("/ExpansionFactor {0:.4g} def\n",
 
388
                          privateDicts[0].expansionFactor);
 
389
    eexecWrite(&eb, buf->getCString());
 
390
    delete buf;
347
391
  }
348
392
 
349
393
  // set up subroutines
354
398
  }
355
399
 
356
400
  // write the CharStrings
357
 
  sprintf(buf, "2 index /CharStrings %d dict dup begin\n", nGlyphs);
358
 
  eexecWrite(&eb, buf);
 
401
  buf = GString::format("2 index /CharStrings {0:d} dict dup begin\n",
 
402
                        nGlyphs);
 
403
  eexecWrite(&eb, buf->getCString());
 
404
  delete buf;
359
405
  for (i = 0; i < nGlyphs; ++i) {
360
406
    ok = gTrue;
361
407
    getIndexVal(&charStringsIdx, i, &val, &ok);
362
408
    if (ok) {
363
 
      getString(charset[i], buf, &ok);
 
409
      getString(charset[i], buf2, &ok);
364
410
      if (ok) {
365
 
        eexecCvtGlyph(&eb, buf, val.pos, val.len, &subrIdx, &privateDicts[0]);
 
411
        eexecCvtGlyph(&eb, buf2, val.pos, val.len, &subrIdx, &privateDicts[0]);
366
412
      }
367
413
    }
368
414
  }
392
438
  Type1CIndex subrIdx;
393
439
  Type1CIndexVal val;
394
440
  int nCIDs, gdBytes;
395
 
  char buf[512], buf2[512];
 
441
  GString *buf;
 
442
  char buf2[256];
396
443
  GBool ok;
397
444
  int gid, offset, n, i, j, k;
398
445
 
456
503
  (*outputFunc)(outputStream, "/CIDSystemInfo 3 dict dup begin\n", 32);
457
504
  if (topDict.registrySID > 0 && topDict.orderingSID > 0) {
458
505
    ok = gTrue;
459
 
    getString(topDict.registrySID, buf, &ok);
 
506
    getString(topDict.registrySID, buf2, &ok);
460
507
    if (ok) {
461
508
      (*outputFunc)(outputStream, "  /Registry (", 13);
462
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
509
      (*outputFunc)(outputStream, buf2, strlen(buf2));
463
510
      (*outputFunc)(outputStream, ") def\n", 6);
464
511
    }
465
512
    ok = gTrue;
466
 
    getString(topDict.orderingSID, buf, &ok);
 
513
    getString(topDict.orderingSID, buf2, &ok);
467
514
    if (ok) {
468
515
      (*outputFunc)(outputStream, "  /Ordering (", 13);
469
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
516
      (*outputFunc)(outputStream, buf2, strlen(buf2));
470
517
      (*outputFunc)(outputStream, ") def\n", 6);
471
518
    }
472
519
  } else {
473
520
    (*outputFunc)(outputStream, "  /Registry (Adobe) def\n", 24);
474
521
    (*outputFunc)(outputStream, "  /Ordering (Identity) def\n", 27);
475
522
  }
476
 
  sprintf(buf, "  /Supplement %d def\n", topDict.supplement);
477
 
  (*outputFunc)(outputStream, buf, strlen(buf));
 
523
  buf = GString::format("  /Supplement {0:d} def\n", topDict.supplement);
 
524
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
525
  delete buf;
478
526
  (*outputFunc)(outputStream, "end def\n", 8);
479
527
  if (topDict.hasFontMatrix) {
480
 
    sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] def\n",
481
 
            topDict.fontMatrix[0], topDict.fontMatrix[1],
482
 
            topDict.fontMatrix[2], topDict.fontMatrix[3],
483
 
            topDict.fontMatrix[4], topDict.fontMatrix[5]);
484
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
528
    buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n",
 
529
                          topDict.fontMatrix[0], topDict.fontMatrix[1],
 
530
                          topDict.fontMatrix[2], topDict.fontMatrix[3],
 
531
                          topDict.fontMatrix[4], topDict.fontMatrix[5]);
 
532
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
533
    delete buf;
485
534
  } else if (privateDicts[0].hasFontMatrix) {
486
535
    (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
487
536
  } else {
488
537
    (*outputFunc)(outputStream,
489
538
                  "/FontMatrix [0.001 0 0 0.001 0 0] def\n", 38);
490
539
  }
491
 
  sprintf(buf, "/FontBBox [%g %g %g %g] def\n",
492
 
          topDict.fontBBox[0], topDict.fontBBox[1],
493
 
          topDict.fontBBox[2], topDict.fontBBox[3]);
494
 
  (*outputFunc)(outputStream, buf, strlen(buf));
 
540
  buf = GString::format("/FontBBox [{0:.4g} {1:.4g} {2:.4g} {3:.4g}] def\n",
 
541
                        topDict.fontBBox[0], topDict.fontBBox[1],
 
542
                        topDict.fontBBox[2], topDict.fontBBox[3]);
 
543
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
544
  delete buf;
495
545
  (*outputFunc)(outputStream, "/FontInfo 1 dict dup begin\n", 27);
496
546
  (*outputFunc)(outputStream, "  /FSType 8 def\n", 16);
497
547
  (*outputFunc)(outputStream, "end def\n", 8);
498
548
 
499
549
  // CIDFont-specific entries
500
 
  sprintf(buf, "/CIDCount %d def\n", nCIDs);
501
 
  (*outputFunc)(outputStream, buf, strlen(buf));
 
550
  buf = GString::format("/CIDCount {0:d} def\n", nCIDs);
 
551
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
552
  delete buf;
502
553
  (*outputFunc)(outputStream, "/FDBytes 1 def\n", 15);
503
 
  sprintf(buf, "/GDBytes %d def\n", gdBytes);
504
 
  (*outputFunc)(outputStream, buf, strlen(buf));
 
554
  buf = GString::format("/GDBytes {0:d} def\n", gdBytes);
 
555
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
556
  delete buf;
505
557
  (*outputFunc)(outputStream, "/CIDMapOffset 0 def\n", 20);
506
558
  if (topDict.paintType != 0) {
507
 
    sprintf(buf, "/PaintType %d def\n", topDict.paintType);
508
 
    (*outputFunc)(outputStream, buf, strlen(buf));
509
 
    sprintf(buf, "/StrokeWidth %g def\n", topDict.strokeWidth);
510
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
559
    buf = GString::format("/PaintType {0:d} def\n", topDict.paintType);
 
560
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
561
    delete buf;
 
562
    buf = GString::format("/StrokeWidth {0:.4g} def\n", topDict.strokeWidth);
 
563
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
564
    delete buf;
511
565
  }
512
566
 
513
567
  // FDArray entry
514
 
  sprintf(buf, "/FDArray %d array\n", nFDs);
515
 
  (*outputFunc)(outputStream, buf, strlen(buf));
 
568
  buf = GString::format("/FDArray {0:d} array\n", nFDs);
 
569
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
570
  delete buf;
516
571
  for (i = 0; i < nFDs; ++i) {
517
 
    sprintf(buf, "dup %d 10 dict begin\n", i);
518
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
572
    buf = GString::format("dup {0:d} 10 dict begin\n", i);
 
573
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
574
    delete buf;
519
575
    (*outputFunc)(outputStream, "/FontType 1 def\n", 16);
520
576
    if (privateDicts[i].hasFontMatrix) {
521
 
      sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] def\n",
522
 
              privateDicts[i].fontMatrix[0],
523
 
              privateDicts[i].fontMatrix[1],
524
 
              privateDicts[i].fontMatrix[2],
525
 
              privateDicts[i].fontMatrix[3],
526
 
              privateDicts[i].fontMatrix[4],
527
 
              privateDicts[i].fontMatrix[5]);
528
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
577
      buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n",
 
578
                            privateDicts[i].fontMatrix[0],
 
579
                            privateDicts[i].fontMatrix[1],
 
580
                            privateDicts[i].fontMatrix[2],
 
581
                            privateDicts[i].fontMatrix[3],
 
582
                            privateDicts[i].fontMatrix[4],
 
583
                            privateDicts[i].fontMatrix[5]);
 
584
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
585
      delete buf;
529
586
    } else {
530
587
      (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
531
588
    }
532
 
    sprintf(buf, "/PaintType %d def\n", topDict.paintType);
533
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
589
    buf = GString::format("/PaintType {0:d} def\n", topDict.paintType);
 
590
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
591
    delete buf;
534
592
    (*outputFunc)(outputStream, "/Private 32 dict begin\n", 23);
535
593
    if (privateDicts[i].nBlueValues) {
536
594
      (*outputFunc)(outputStream, "/BlueValues [", 13);
537
595
      for (j = 0; j < privateDicts[i].nBlueValues; ++j) {
538
 
        sprintf(buf, "%s%d", j > 0 ? " " : "", privateDicts[i].blueValues[j]);
539
 
        (*outputFunc)(outputStream, buf, strlen(buf));
 
596
        buf = GString::format("{0:s}{1:d}",
 
597
                              j > 0 ? " " : "", privateDicts[i].blueValues[j]);
 
598
        (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
599
        delete buf;
540
600
      }
541
601
      (*outputFunc)(outputStream, "] def\n", 6);
542
602
    }
543
603
    if (privateDicts[i].nOtherBlues) {
544
604
      (*outputFunc)(outputStream, "/OtherBlues [", 13);
545
605
      for (j = 0; j < privateDicts[i].nOtherBlues; ++j) {
546
 
        sprintf(buf, "%s%d", j > 0 ? " " : "", privateDicts[i].otherBlues[j]);
547
 
        (*outputFunc)(outputStream, buf, strlen(buf));
 
606
        buf = GString::format("{0:s}{1:d}",
 
607
                              j > 0 ? " " : "", privateDicts[i].otherBlues[j]);
 
608
        (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
609
        delete buf;
548
610
      }
549
611
      (*outputFunc)(outputStream, "] def\n", 6);
550
612
    }
551
613
    if (privateDicts[i].nFamilyBlues) {
552
614
      (*outputFunc)(outputStream, "/FamilyBlues [", 14);
553
615
      for (j = 0; j < privateDicts[i].nFamilyBlues; ++j) {
554
 
        sprintf(buf, "%s%d", j > 0 ? " " : "", privateDicts[i].familyBlues[j]);
555
 
        (*outputFunc)(outputStream, buf, strlen(buf));
 
616
        buf = GString::format("{0:s}{1:d}",
 
617
                              j > 0 ? " " : "",
 
618
                              privateDicts[i].familyBlues[j]);
 
619
        (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
620
        delete buf;
556
621
      }
557
622
      (*outputFunc)(outputStream, "] def\n", 6);
558
623
    }
559
624
    if (privateDicts[i].nFamilyOtherBlues) {
560
625
      (*outputFunc)(outputStream, "/FamilyOtherBlues [", 19);
561
626
      for (j = 0; j < privateDicts[i].nFamilyOtherBlues; ++j) {
562
 
        sprintf(buf, "%s%d", j > 0 ? " " : "",
563
 
                privateDicts[i].familyOtherBlues[j]);
564
 
        (*outputFunc)(outputStream, buf, strlen(buf));
 
627
        buf = GString::format("{0:s}{1:d}", j > 0 ? " " : "",
 
628
                              privateDicts[i].familyOtherBlues[j]);
 
629
        (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
630
        delete buf;
565
631
      }
566
632
      (*outputFunc)(outputStream, "] def\n", 6);
567
633
    }
568
634
    if (privateDicts[i].blueScale != 0.039625) {
569
 
      sprintf(buf, "/BlueScale %g def\n", privateDicts[i].blueScale);
570
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
635
      buf = GString::format("/BlueScale {0:.4g} def\n",
 
636
                            privateDicts[i].blueScale);
 
637
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
638
      delete buf;
571
639
    }
572
640
    if (privateDicts[i].blueShift != 7) {
573
 
      sprintf(buf, "/BlueShift %d def\n", privateDicts[i].blueShift);
574
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
641
      buf = GString::format("/BlueShift {0:d} def\n",
 
642
                            privateDicts[i].blueShift);
 
643
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
644
      delete buf;
575
645
    }
576
646
    if (privateDicts[i].blueFuzz != 1) {
577
 
      sprintf(buf, "/BlueFuzz %d def\n", privateDicts[i].blueFuzz);
578
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
647
      buf = GString::format("/BlueFuzz {0:d} def\n", privateDicts[i].blueFuzz);
 
648
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
649
      delete buf;
579
650
    }
580
651
    if (privateDicts[i].hasStdHW) {
581
 
      sprintf(buf, "/StdHW [%g] def\n", privateDicts[i].stdHW);
582
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
652
      buf = GString::format("/StdHW [{0:.4g}] def\n", privateDicts[i].stdHW);
 
653
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
654
      delete buf;
583
655
    }
584
656
    if (privateDicts[i].hasStdVW) {
585
 
      sprintf(buf, "/StdVW [%g] def\n", privateDicts[i].stdVW);
586
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
657
      buf = GString::format("/StdVW [{0:.4g}] def\n", privateDicts[i].stdVW);
 
658
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
659
      delete buf;
587
660
    }
588
661
    if (privateDicts[i].nStemSnapH) {
589
662
      (*outputFunc)(outputStream, "/StemSnapH [", 12);
590
663
      for (j = 0; j < privateDicts[i].nStemSnapH; ++j) {
591
 
        sprintf(buf, "%s%g", j > 0 ? " " : "", privateDicts[i].stemSnapH[j]);
592
 
        (*outputFunc)(outputStream, buf, strlen(buf));
 
664
        buf = GString::format("{0:s}{1:.4g}",
 
665
                              j > 0 ? " " : "", privateDicts[i].stemSnapH[j]);
 
666
        (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
667
        delete buf;
593
668
      }
594
669
      (*outputFunc)(outputStream, "] def\n", 6);
595
670
    }
596
671
    if (privateDicts[i].nStemSnapV) {
597
672
      (*outputFunc)(outputStream, "/StemSnapV [", 12);
598
673
      for (j = 0; j < privateDicts[i].nStemSnapV; ++j) {
599
 
        sprintf(buf, "%s%g", j > 0 ? " " : "", privateDicts[i].stemSnapV[j]);
600
 
        (*outputFunc)(outputStream, buf, strlen(buf));
 
674
        buf = GString::format("{0:s}{1:.4g}",
 
675
                              j > 0 ? " " : "", privateDicts[i].stemSnapV[j]);
 
676
        (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
677
        delete buf;
601
678
      }
602
679
      (*outputFunc)(outputStream, "] def\n", 6);
603
680
    }
604
681
    if (privateDicts[i].hasForceBold) {
605
 
      sprintf(buf, "/ForceBold %s def\n",
606
 
              privateDicts[i].forceBold ? "true" : "false");
607
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
682
      buf = GString::format("/ForceBold {0:s} def\n",
 
683
                            privateDicts[i].forceBold ? "true" : "false");
 
684
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
685
      delete buf;
608
686
    }
609
687
    if (privateDicts[i].forceBoldThreshold != 0) {
610
 
      sprintf(buf, "/ForceBoldThreshold %g def\n",
611
 
              privateDicts[i].forceBoldThreshold);
612
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
688
      buf = GString::format("/ForceBoldThreshold {0:.4g} def\n",
 
689
                            privateDicts[i].forceBoldThreshold);
 
690
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
691
      delete buf;
613
692
    }
614
693
    if (privateDicts[i].languageGroup != 0) {
615
 
      sprintf(buf, "/LanguageGroup %d def\n", privateDicts[i].languageGroup);
616
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
694
      buf = GString::format("/LanguageGroup {0:d} def\n",
 
695
                            privateDicts[i].languageGroup);
 
696
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
697
      delete buf;
617
698
    }
618
699
    if (privateDicts[i].expansionFactor != 0.06) {
619
 
      sprintf(buf, "/ExpansionFactor %g def\n",
620
 
              privateDicts[i].expansionFactor);
621
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
700
      buf = GString::format("/ExpansionFactor {0:.4g} def\n",
 
701
                            privateDicts[i].expansionFactor);
 
702
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
703
      delete buf;
622
704
    }
623
705
    (*outputFunc)(outputStream, "currentdict end def\n", 20);
624
706
    (*outputFunc)(outputStream, "currentdict end put\n", 20);
627
709
 
628
710
  // start the binary section
629
711
  offset = (nCIDs + 1) * (1 + gdBytes);
630
 
  sprintf(buf, "(Hex) %d StartData\n",
631
 
          offset + charStrings->getLength());
632
 
  (*outputFunc)(outputStream, buf, strlen(buf));
 
712
  buf = GString::format("(Hex) {0:d} StartData\n",
 
713
                        offset + charStrings->getLength());
 
714
  (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
715
  delete buf;
633
716
 
634
717
  // write the charstring offset (CIDMap) table
635
718
  for (i = 0; i <= nCIDs; i += 6) {
636
719
    for (j = 0; j < 6 && i+j <= nCIDs; ++j) {
637
720
      if (i+j < nCIDs && cidMap[i+j] >= 0) {
638
 
        buf[0] = (char)fdSelect[cidMap[i+j]];
 
721
        buf2[0] = (char)fdSelect[cidMap[i+j]];
639
722
      } else {
640
 
        buf[0] = (char)0;
 
723
        buf2[0] = (char)0;
641
724
      }
642
725
      n = offset + charStringOffsets[i+j];
643
726
      for (k = gdBytes; k >= 1; --k) {
644
 
        buf[k] = (char)(n & 0xff);
 
727
        buf2[k] = (char)(n & 0xff);
645
728
        n >>= 8;
646
729
      }
647
730
      for (k = 0; k <= gdBytes; ++k) {
648
 
        sprintf(buf2, "%02x", buf[k] & 0xff);
649
 
        (*outputFunc)(outputStream, buf2, 2);
 
731
        buf = GString::format("{0:02x}", buf2[k] & 0xff);
 
732
        (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
733
        delete buf;
650
734
      }
651
735
    }
652
736
    (*outputFunc)(outputStream, "\n", 1);
656
740
  n = charStrings->getLength();
657
741
  for (i = 0; i < n; i += 32) {
658
742
    for (j = 0; j < 32 && i+j < n; ++j) {
659
 
      sprintf(buf, "%02x", charStrings->getChar(i+j) & 0xff);
660
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
743
      buf = GString::format("{0:02x}", charStrings->getChar(i+j) & 0xff);
 
744
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
745
      delete buf;
661
746
    }
662
747
    if (i + 32 >= n) {
663
748
      (*outputFunc)(outputStream, ">", 1);
677
762
  Type1CIndex subrIdx;
678
763
  Type1CIndexVal val;
679
764
  int nCIDs;
680
 
  char buf[512];
 
765
  GString *buf;
681
766
  Type1CEexecBuf eb;
682
767
  GBool ok;
683
768
  int fd, i, j, k;
702
787
 
703
788
    //~ this assumes that all CIDs in this block have the same FD --
704
789
    //~ to handle multiple FDs correctly, need to somehow divide the
705
 
    //~ font up by FD
 
790
    //~ font up by FD; as a kludge we ignore CID 0, which is .notdef
706
791
    fd = 0;
707
 
    for (j = 0; j < 256 && i+j < nCIDs; ++j) {
 
792
    for (j = i==0 ? 1 : 0; j < 256 && i+j < nCIDs; ++j) {
708
793
      if (cidMap[i+j] >= 0) {
709
794
        fd = fdSelect[cidMap[i+j]];
710
795
        break;
715
800
    (*outputFunc)(outputStream, "16 dict begin\n", 14);
716
801
    (*outputFunc)(outputStream, "/FontName /", 11);
717
802
    (*outputFunc)(outputStream, psName, strlen(psName));
718
 
    sprintf(buf, "_%02x def\n", i >> 8);
719
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
803
    buf = GString::format("_{0:02x} def\n", i >> 8);
 
804
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
805
    delete buf;
720
806
    (*outputFunc)(outputStream, "/FontType 1 def\n", 16);
721
807
    if (privateDicts[fd].hasFontMatrix) {
722
 
      sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] def\n",
723
 
              privateDicts[fd].fontMatrix[0],
724
 
              privateDicts[fd].fontMatrix[1],
725
 
              privateDicts[fd].fontMatrix[2],
726
 
              privateDicts[fd].fontMatrix[3],
727
 
              privateDicts[fd].fontMatrix[4],
728
 
              privateDicts[fd].fontMatrix[5]);
729
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
808
      buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n",
 
809
                            privateDicts[fd].fontMatrix[0],
 
810
                            privateDicts[fd].fontMatrix[1],
 
811
                            privateDicts[fd].fontMatrix[2],
 
812
                            privateDicts[fd].fontMatrix[3],
 
813
                            privateDicts[fd].fontMatrix[4],
 
814
                            privateDicts[fd].fontMatrix[5]);
 
815
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
816
      delete buf;
730
817
    } else if (topDict.hasFontMatrix) {
731
818
      (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
732
819
    } else {
733
820
      (*outputFunc)(outputStream,
734
821
                    "/FontMatrix [0.001 0 0 0.001 0 0] def\n", 38);
735
822
    }
736
 
    sprintf(buf, "/FontBBox [%g %g %g %g] def\n",
737
 
            topDict.fontBBox[0], topDict.fontBBox[1],
738
 
            topDict.fontBBox[2], topDict.fontBBox[3]);
739
 
    (*outputFunc)(outputStream, buf, strlen(buf));
740
 
    sprintf(buf, "/PaintType %d def\n", topDict.paintType);
741
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
823
    buf = GString::format("/FontBBox [{0:.4g} {1:.4g} {2:.4g} {3:.4g}] def\n",
 
824
                          topDict.fontBBox[0], topDict.fontBBox[1],
 
825
                          topDict.fontBBox[2], topDict.fontBBox[3]);
 
826
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
827
    delete buf;
 
828
    buf = GString::format("/PaintType {0:d} def\n", topDict.paintType);
 
829
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
830
    delete buf;
742
831
    if (topDict.paintType != 0) {
743
 
      sprintf(buf, "/StrokeWidth %g def\n", topDict.strokeWidth);
744
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
832
      buf = GString::format("/StrokeWidth {0:.4g} def\n", topDict.strokeWidth);
 
833
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
834
      delete buf;
745
835
    }
746
836
    (*outputFunc)(outputStream, "/Encoding 256 array\n", 20);
747
837
    for (j = 0; j < 256 && i+j < nCIDs; ++j) {
748
 
      sprintf(buf, "dup %d /c%02x put\n", j, j);
749
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
838
      buf = GString::format("dup {0:d} /c{1:02x} put\n", j, j);
 
839
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
840
      delete buf;
750
841
    }
751
842
    if (j < 256) {
752
 
      sprintf(buf, "%d 1 255 { 1 index exch /.notdef put } for\n", j);
753
 
      (*outputFunc)(outputStream, buf, strlen(buf));
 
843
      buf = GString::format("{0:d} 1 255 {{ 1 index exch /.notdef put }} for\n",
 
844
                            j);
 
845
      (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
846
      delete buf;
754
847
    }
755
848
    (*outputFunc)(outputStream, "readonly def\n", 13);
756
849
    (*outputFunc)(outputStream, "currentdict end\n", 16);
775
868
    if (privateDicts[fd].nBlueValues) {
776
869
      eexecWrite(&eb, "/BlueValues [");
777
870
      for (k = 0; k < privateDicts[fd].nBlueValues; ++k) {
778
 
        sprintf(buf, "%s%d", k > 0 ? " " : "", privateDicts[fd].blueValues[k]);
779
 
        eexecWrite(&eb, buf);
 
871
        buf = GString::format("{0:s}{1:d}",
 
872
                              k > 0 ? " " : "",
 
873
                              privateDicts[fd].blueValues[k]);
 
874
        eexecWrite(&eb, buf->getCString());
 
875
        delete buf;
780
876
      }
781
877
      eexecWrite(&eb, "] def\n");
782
878
    }
783
879
    if (privateDicts[fd].nOtherBlues) {
784
880
      eexecWrite(&eb, "/OtherBlues [");
785
881
      for (k = 0; k < privateDicts[fd].nOtherBlues; ++k) {
786
 
        sprintf(buf, "%s%d", k > 0 ? " " : "", privateDicts[fd].otherBlues[k]);
787
 
        eexecWrite(&eb, buf);
 
882
        buf = GString::format("{0:s}{1:d}",
 
883
                              k > 0 ? " " : "",
 
884
                              privateDicts[fd].otherBlues[k]);
 
885
        eexecWrite(&eb, buf->getCString());
 
886
        delete buf;
788
887
      }
789
888
      eexecWrite(&eb, "] def\n");
790
889
    }
791
890
    if (privateDicts[fd].nFamilyBlues) {
792
891
      eexecWrite(&eb, "/FamilyBlues [");
793
892
      for (k = 0; k < privateDicts[fd].nFamilyBlues; ++k) {
794
 
        sprintf(buf, "%s%d", k > 0 ? " " : "",
795
 
                privateDicts[fd].familyBlues[k]);
796
 
        eexecWrite(&eb, buf);
 
893
        buf = GString::format("{0:s}{1:d}", k > 0 ? " " : "",
 
894
                              privateDicts[fd].familyBlues[k]);
 
895
        eexecWrite(&eb, buf->getCString());
 
896
        delete buf;
797
897
      }
798
898
      eexecWrite(&eb, "] def\n");
799
899
    }
800
900
    if (privateDicts[fd].nFamilyOtherBlues) {
801
901
      eexecWrite(&eb, "/FamilyOtherBlues [");
802
902
      for (k = 0; k < privateDicts[fd].nFamilyOtherBlues; ++k) {
803
 
        sprintf(buf, "%s%d", k > 0 ? " " : "",
804
 
                privateDicts[fd].familyOtherBlues[k]);
805
 
        eexecWrite(&eb, buf);
 
903
        buf = GString::format("{0:s}{1:d}", k > 0 ? " " : "",
 
904
                              privateDicts[fd].familyOtherBlues[k]);
 
905
        eexecWrite(&eb, buf->getCString());
 
906
        delete buf;
806
907
      }
807
908
      eexecWrite(&eb, "] def\n");
808
909
    }
809
910
    if (privateDicts[fd].blueScale != 0.039625) {
810
 
      sprintf(buf, "/BlueScale %g def\n", privateDicts[fd].blueScale);
811
 
      eexecWrite(&eb, buf);
 
911
      buf = GString::format("/BlueScale {0:.4g} def\n",
 
912
                            privateDicts[fd].blueScale);
 
913
      eexecWrite(&eb, buf->getCString());
 
914
      delete buf;
812
915
    }
813
916
    if (privateDicts[fd].blueShift != 7) {
814
 
      sprintf(buf, "/BlueShift %d def\n", privateDicts[fd].blueShift);
815
 
      eexecWrite(&eb, buf);
 
917
      buf = GString::format("/BlueShift {0:d} def\n",
 
918
                            privateDicts[fd].blueShift);
 
919
      eexecWrite(&eb, buf->getCString());
 
920
      delete buf;
816
921
    }
817
922
    if (privateDicts[fd].blueFuzz != 1) {
818
 
      sprintf(buf, "/BlueFuzz %d def\n", privateDicts[fd].blueFuzz);
819
 
      eexecWrite(&eb, buf);
 
923
      buf = GString::format("/BlueFuzz {0:d} def\n",
 
924
                            privateDicts[fd].blueFuzz);
 
925
      eexecWrite(&eb, buf->getCString());
 
926
      delete buf;
820
927
    }
821
928
    if (privateDicts[fd].hasStdHW) {
822
 
      sprintf(buf, "/StdHW [%g] def\n", privateDicts[fd].stdHW);
823
 
      eexecWrite(&eb, buf);
 
929
      buf = GString::format("/StdHW [{0:.4g}] def\n", privateDicts[fd].stdHW);
 
930
      eexecWrite(&eb, buf->getCString());
 
931
      delete buf;
824
932
    }
825
933
    if (privateDicts[fd].hasStdVW) {
826
 
      sprintf(buf, "/StdVW [%g] def\n", privateDicts[fd].stdVW);
827
 
      eexecWrite(&eb, buf);
 
934
      buf = GString::format("/StdVW [{0:.4g}] def\n", privateDicts[fd].stdVW);
 
935
      eexecWrite(&eb, buf->getCString());
 
936
      delete buf;
828
937
    }
829
938
    if (privateDicts[fd].nStemSnapH) {
830
939
      eexecWrite(&eb, "/StemSnapH [");
831
940
      for (k = 0; k < privateDicts[fd].nStemSnapH; ++k) {
832
 
        sprintf(buf, "%s%g", k > 0 ? " " : "", privateDicts[fd].stemSnapH[k]);
833
 
        eexecWrite(&eb, buf);
 
941
        buf = GString::format("{0:s}{1:.4g}",
 
942
                              k > 0 ? " " : "", privateDicts[fd].stemSnapH[k]);
 
943
        eexecWrite(&eb, buf->getCString());
 
944
        delete buf;
834
945
      }
835
946
      eexecWrite(&eb, "] def\n");
836
947
    }
837
948
    if (privateDicts[fd].nStemSnapV) {
838
949
      eexecWrite(&eb, "/StemSnapV [");
839
950
      for (k = 0; k < privateDicts[fd].nStemSnapV; ++k) {
840
 
        sprintf(buf, "%s%g", k > 0 ? " " : "", privateDicts[fd].stemSnapV[k]);
841
 
        eexecWrite(&eb, buf);
 
951
        buf = GString::format("{0:s}{1:.4g}",
 
952
                              k > 0 ? " " : "", privateDicts[fd].stemSnapV[k]);
 
953
        eexecWrite(&eb, buf->getCString());
 
954
        delete buf;
842
955
      }
843
956
      eexecWrite(&eb, "] def\n");
844
957
    }
845
958
    if (privateDicts[fd].hasForceBold) {
846
 
      sprintf(buf, "/ForceBold %s def\n",
847
 
              privateDicts[fd].forceBold ? "true" : "false");
848
 
      eexecWrite(&eb, buf);
 
959
      buf = GString::format("/ForceBold {0:s} def\n",
 
960
                            privateDicts[fd].forceBold ? "true" : "false");
 
961
      eexecWrite(&eb, buf->getCString());
 
962
      delete buf;
849
963
    }
850
964
    if (privateDicts[fd].forceBoldThreshold != 0) {
851
 
      sprintf(buf, "/ForceBoldThreshold %g def\n",
852
 
              privateDicts[fd].forceBoldThreshold);
853
 
      eexecWrite(&eb, buf);
 
965
      buf = GString::format("/ForceBoldThreshold {0:.4g} def\n",
 
966
                            privateDicts[fd].forceBoldThreshold);
 
967
      eexecWrite(&eb, buf->getCString());
 
968
      delete buf;
854
969
    }
855
970
    if (privateDicts[fd].languageGroup != 0) {
856
 
      sprintf(buf, "/LanguageGroup %d def\n", privateDicts[fd].languageGroup);
857
 
      eexecWrite(&eb, buf);
 
971
      buf = GString::format("/LanguageGroup {0:d} def\n",
 
972
                            privateDicts[fd].languageGroup);
 
973
      eexecWrite(&eb, buf->getCString());
 
974
      delete buf;
858
975
    }
859
976
    if (privateDicts[fd].expansionFactor != 0.06) {
860
 
      sprintf(buf, "/ExpansionFactor %g def\n",
861
 
              privateDicts[fd].expansionFactor);
862
 
      eexecWrite(&eb, buf);
 
977
      buf = GString::format("/ExpansionFactor {0:.4g} def\n",
 
978
                            privateDicts[fd].expansionFactor);
 
979
      eexecWrite(&eb, buf->getCString());
 
980
      delete buf;
863
981
    }
864
982
 
865
983
    // set up the subroutines
870
988
    }
871
989
 
872
990
    // start the CharStrings
873
 
    sprintf(buf, "2 index /CharStrings 256 dict dup begin\n");
874
 
    eexecWrite(&eb, buf);
 
991
    eexecWrite(&eb, "2 index /CharStrings 256 dict dup begin\n");
875
992
 
876
993
    // write the .notdef CharString
877
994
    ok = gTrue;
887
1004
        ok = gTrue;
888
1005
        getIndexVal(&charStringsIdx, cidMap[i+j], &val, &ok);
889
1006
        if (ok) {
890
 
          sprintf(buf, "c%02x", j);
891
 
          eexecCvtGlyph(&eb, buf, val.pos, val.len,
 
1007
          buf = GString::format("c{0:02x}", j);
 
1008
          eexecCvtGlyph(&eb, buf->getCString(), val.pos, val.len,
892
1009
                        &subrIdx, &privateDicts[fd]);
 
1010
          delete buf;
893
1011
        }
894
1012
      }
895
1013
    }
917
1035
  (*outputFunc)(outputStream, " def\n", 5);
918
1036
  (*outputFunc)(outputStream, "/FontType 0 def\n", 16);
919
1037
  if (topDict.hasFontMatrix) {
920
 
    sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] def\n",
921
 
            topDict.fontMatrix[0], topDict.fontMatrix[1],
922
 
            topDict.fontMatrix[2], topDict.fontMatrix[3],
923
 
            topDict.fontMatrix[4], topDict.fontMatrix[5]);
924
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
1038
    buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n",
 
1039
                          topDict.fontMatrix[0], topDict.fontMatrix[1],
 
1040
                          topDict.fontMatrix[2], topDict.fontMatrix[3],
 
1041
                          topDict.fontMatrix[4], topDict.fontMatrix[5]);
 
1042
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
1043
    delete buf;
925
1044
  } else {
926
1045
    (*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
927
1046
  }
928
1047
  (*outputFunc)(outputStream, "/FMapType 2 def\n", 16);
929
1048
  (*outputFunc)(outputStream, "/Encoding [\n", 12);
930
1049
  for (i = 0; i < nCIDs; i += 256) {
931
 
    sprintf(buf, "%d\n", i >> 8);
932
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
1050
    buf = GString::format("{0:d}\n", i >> 8);
 
1051
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
1052
    delete buf;
933
1053
  }
934
1054
  (*outputFunc)(outputStream, "] def\n", 6);
935
1055
  (*outputFunc)(outputStream, "/FDepVector [\n", 14);
936
1056
  for (i = 0; i < nCIDs; i += 256) {
937
1057
    (*outputFunc)(outputStream, "/", 1);
938
1058
    (*outputFunc)(outputStream, psName, strlen(psName));
939
 
    sprintf(buf, "_%02x findfont\n", i >> 8);
940
 
    (*outputFunc)(outputStream, buf, strlen(buf));
 
1059
    buf = GString::format("_{0:02x} findfont\n", i >> 8);
 
1060
    (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
 
1061
    delete buf;
941
1062
  }
942
1063
  (*outputFunc)(outputStream, "] def\n", 6);
943
1064
  (*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
949
1070
                               int offset, int nBytes,
950
1071
                               Type1CIndex *subrIdx,
951
1072
                               Type1CPrivateDict *pDict) {
952
 
  char buf[512];
 
1073
  GString *buf;
953
1074
  GString *charBuf;
954
1075
 
955
1076
  // generate the charstring
956
1077
  charBuf = new GString();
957
1078
  cvtGlyph(offset, nBytes, charBuf, subrIdx, pDict, gTrue);
958
1079
 
959
 
  sprintf(buf, "/%s %d RD ", glyphName, charBuf->getLength());
960
 
  eexecWrite(eb, buf);
 
1080
  buf = GString::format("/{0:s} {1:d} RD ", glyphName, charBuf->getLength());
 
1081
  eexecWrite(eb, buf->getCString());
 
1082
  delete buf;
961
1083
  eexecWriteCharstring(eb, (Guchar *)charBuf->getCString(),
962
1084
                       charBuf->getLength());
963
1085
  eexecWrite(eb, " ND\n");