]> www.fi.muni.cz Git - evince.git/blobdiff - pdf/xpdf/pdfinfo.cc
Reused eog HIG dialog in GPdf.
[evince.git] / pdf / xpdf / pdfinfo.cc
index ea70afe93d8803a3702de673f08e07b0203b6530..f856a6d41e24b728354cf903a459baf60b113495 100644 (file)
@@ -2,7 +2,7 @@
 //
 // pdfinfo.cc
 //
-// Copyright 1998-2002 Glyph & Cog, LLC
+// Copyright 1998-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
@@ -72,10 +72,14 @@ int main(int argc, char *argv[]) {
   GString *ownerPW, *userPW;
   UnicodeMap *uMap;
   Object info;
-  double w, h;
+  double w, h, wISO, hISO;
   FILE *f;
   GString *metadata;
   GBool ok;
+  int exitCode;
+  int i;
+
+  exitCode = 99;
 
   // parse args
   ok = parseArgs(argDesc, &argc, argv);
@@ -85,7 +89,7 @@ int main(int argc, char *argv[]) {
     if (!printVersion) {
       printUsage("pdfinfo", "<PDF-file>", argDesc);
     }
-    exit(1);
+    goto err0;
   }
   fileName = new GString(argv[1]);
 
@@ -121,6 +125,7 @@ int main(int argc, char *argv[]) {
     delete ownerPW;
   }
   if (!doc->isOk()) {
+    exitCode = 1;
     goto err2;
   }
 
@@ -165,9 +170,18 @@ int main(int argc, char *argv[]) {
     if ((fabs(w - 612) < 0.1 && fabs(h - 792) < 0.1) ||
        (fabs(w - 792) < 0.1 && fabs(h - 612) < 0.1)) {
       printf(" (letter)");
-    } else if ((fabs(w - 595) < 0.1 && fabs(h - 842) < 0.1) ||
-              (fabs(w - 842) < 0.1 && fabs(h - 595) < 0.1)) {
-      printf(" (A4)");
+    } else {
+      hISO = sqrt(sqrt(2)) * 7200 / 2.54;
+      wISO = hISO / sqrt(2);
+      for (i = 0; i <= 6; ++i) {
+       if ((fabs(w - wISO) < 1 && fabs(h - hISO) < 1) ||
+           (fabs(w - hISO) < 1 && fabs(h - wISO) < 1)) {
+         printf(" (A%d)", i);
+         break;
+       }
+       hISO = wISO;
+       wISO /= sqrt(2);
+      }
     }
     printf("\n");
   } 
@@ -179,7 +193,10 @@ int main(int argc, char *argv[]) {
   f = fopen(fileName->getCString(), "rb");
 #endif
   if (f) {
-#if HAVE_FSEEK64
+#if HAVE_FSEEKO
+    fseeko(f, 0, SEEK_END);
+    printf("File size:    %u bytes\n", (Guint)ftello(f));
+#elif HAVE_FSEEK64
     fseek64(f, 0, SEEK_END);
     printf("File size:    %u bytes\n", (Guint)ftell64(f));
 #else
@@ -203,18 +220,21 @@ int main(int argc, char *argv[]) {
     delete metadata;
   }
 
+  exitCode = 0;
+
   // clean up
  err2:
   uMap->decRefCnt();
   delete doc;
  err1:
   delete globalParams;
+ err0:
 
   // check for memory leaks
   Object::memCheck(stderr);
   gMemReport(stderr);
 
-  return 0;
+  return exitCode;
 }
 
 static void printInfoString(Dict *infoDict, char *key, char *text,
@@ -278,8 +298,9 @@ static void printInfoDate(Dict *infoDict, char *key, char *text) {
       tmStruct.tm_wday = -1;
       tmStruct.tm_yday = -1;
       tmStruct.tm_isdst = -1;
-      mktime(&tmStruct); // compute the tm_wday and tm_yday fields
-      if (strftime(buf, sizeof(buf), "%c", &tmStruct)) {
+      // compute the tm_wday and tm_yday fields
+      if (mktime(&tmStruct) != (time_t)-1 &&
+         strftime(buf, sizeof(buf), "%c", &tmStruct)) {
        fputs(buf, stdout);
       } else {
        fputs(s, stdout);