NickNaso / ghostscript4js

Ghostscript4JS binds the Ghostscript C API to the Node.JS world.
http://www.nacios.it
Apache License 2.0
68 stars 19 forks source link

Create version method #2

Closed NickNaso closed 7 years ago

NickNaso commented 8 years ago

Create the version method that have the responsability to check the actual version of ghostscript. It's important to be sure that the correct version of the ghostsctipt library is loaded.

Base the code as in the reference manual:

typedef struct gsapi_revision_s {
    const char *product;
    const char *copyright;
    long revision;
    long revisiondate;
} gsapi_revision_t;
gsapi_revision_t r;

if (gsapi_revision(&r, sizeof(r)) == 0) {
    if (r.revision < 650)
       printf("Need at least Ghostscript 6.50");
}
else {
    printf("revision structure size is incorrect");
}
NickNaso commented 8 years ago

Please see the issue https://github.com/NickNaso/ghostscript4js/issues/3 to avoid the compilation error.

NickNaso commented 8 years ago

Example for C implementation

#include <stdlib.h>
#include <stdio.h>

#include <ghostscript/gdevdsp.h>
#include <ghostscript/gserrors.h>
#include <ghostscript/iapi.h>
#include <ghostscript/ierrors.h>

int main () { 

gsapi_revision_t r;

if (gsapi_revision(&r, sizeof(r)) == 0) {
    printf("%s", r.product);

    if (r.revision < 650)
       printf("Need at least Ghostscript 6.50");
}
else {
    printf("revision structure size is incorrect");
}
  return 0;
}
NickNaso commented 8 years ago

Example for C++ implementation


#include <iostream>
#include <string>

#include <ghostscript/gdevdsp.h>
#include <ghostscript/gserrors.h>
#include <ghostscript/iapi.h>
#include <ghostscript/ierrors.h>

using namespace std;

int main () { 

   gsapi_revision_t r;
   cout << sizeof(r);
   int res = gsapi_revision(&r, sizeof(r));

   cout << res;
   cout << r.product;

  return 0;
}
NickNaso commented 7 years ago

It will return an objet like this:

{
   product: "-------",
   copyright: "------",
   revision: "------",
   revisiondate: "------"
}
NickNaso commented 7 years ago

Method version implemented