src/gui/painting/qprintengine_pdf.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   929 }
   929 }
   930 
   930 
   931 void QPdfEnginePrivate::writeInfo()
   931 void QPdfEnginePrivate::writeInfo()
   932 {
   932 {
   933     info = addXrefEntry(-1);
   933     info = addXrefEntry(-1);
   934 
   934     xprintf("<<\n/Title ");
   935     // The 'text string' type in PDF is encoded either as PDFDocEncoding, or
   935     printString(title);
   936     // Unicode UTF-16 with a Unicode byte order mark as the first character
   936     xprintf("\n/Creator ");
   937     // (0xfeff), with the high-order byte first.
   937     printString(creator);
   938     QByteArray array("<<\n/Title (\xfe\xff");
   938     xprintf("\n/Producer ");
   939     const ushort *utf16Title = title.utf16();
   939     printString(QString::fromLatin1("Qt " QT_VERSION_STR " (C) 2010 Nokia Corporation and/or its subsidiary(-ies)"));
   940     for (int i=0; i < title.size(); ++i) {
       
   941         array.append((*(utf16Title + i)) >> 8);
       
   942         array.append((*(utf16Title + i)) & 0xff);
       
   943     }
       
   944     array.append(")\n/Creator (\xfe\xff");
       
   945     const ushort *utf16Creator = creator.utf16();
       
   946     for (int i=0; i < creator.size(); ++i) {
       
   947         array.append((*(utf16Creator + i)) >> 8);
       
   948         array.append((*(utf16Creator + i)) & 0xff);
       
   949     }
       
   950     array.append(")\n/Producer (Qt " QT_VERSION_STR " (C) 2010 Nokia Corporation and/or its subsidiary(-ies))\n");
       
   951     write(array);
       
   952 
       
   953     QDateTime now = QDateTime::currentDateTime().toUTC();
   940     QDateTime now = QDateTime::currentDateTime().toUTC();
   954     QTime t = now.time();
   941     QTime t = now.time();
   955     QDate d = now.date();
   942     QDate d = now.date();
   956     xprintf("/CreationDate (D:%d%02d%02d%02d%02d%02d)\n",
   943     xprintf("\n/CreationDate (D:%d%02d%02d%02d%02d%02d)\n",
   957             d.year(),
   944             d.year(),
   958             d.month(),
   945             d.month(),
   959             d.day(),
   946             d.day(),
   960             t.hour(),
   947             t.hour(),
   961             t.minute(),
   948             t.minute(),
  1228         xprintf("%d 0 obj\n",object);
  1215         xprintf("%d 0 obj\n",object);
  1229 
  1216 
  1230     return object;
  1217     return object;
  1231 }
  1218 }
  1232 
  1219 
       
  1220 void QPdfEnginePrivate::printString(const QString &string) {
       
  1221     // The 'text string' type in PDF is encoded either as PDFDocEncoding, or
       
  1222     // Unicode UTF-16 with a Unicode byte order mark as the first character
       
  1223     // (0xfeff), with the high-order byte first.
       
  1224     QByteArray array("(\xfe\xff");
       
  1225     const ushort *utf16 = string.utf16();
       
  1226     
       
  1227     for (int i=0; i < string.size(); ++i) {
       
  1228         char part[2] = {char((*(utf16 + i)) >> 8), char((*(utf16 + i)) & 0xff)};
       
  1229         for(int j=0; j < 2; ++j) {
       
  1230             if (part[j] == '(' || part[j] == ')' || part[j] == '\\')
       
  1231                 array.append('\\');
       
  1232             array.append(part[j]);
       
  1233         }
       
  1234     }
       
  1235     array.append(")");
       
  1236     write(array);
       
  1237 }
       
  1238 
  1233 QT_END_NAMESPACE
  1239 QT_END_NAMESPACE
  1234 
  1240 
  1235 #endif // QT_NO_PRINTER
  1241 #endif // QT_NO_PRINTER