C++ API Interface (litePDF.cpp)

    1 /*
    2  * (c) 2013-2017 http://www.litePDF.cz
    3  *
    4  * This software is provided by the litePDF project ``as is'' and any
    5  * expressed or implied warranties, including, but not limited to, the
    6  * implied warranties of merchantability and fitness for a particular
    7  * purpose are disclaimed. In no event shall the litePDF project or
    8  * its contributors be liable for any direct, indirect, incidental,
    9  * special, exemplary, or consequential damages (including, but
   10  * not limited to, procurement of substitute goods or services;
   11  * loss of use, data, or profits; or business interruption)
   12  * however caused and on any theory of liability, whether in contract,
   13  * strict liability, or tort (including negligence or otherwise)
   14  * arising in any way out of the use of this software, even if advised
   15  * of the possibility of such damage.
   16  * 
   17  * Permission is granted to anyone to use this software for any purpose,
   18  * including commercial applications, and to alter it and redistribute it
   19  * freely. The origin of this software must not be misrepresented; you must
   20  * not claim that you wrote the original software. If you use this software
   21  * in a product, an acknowledgment in the product documentation would be
   22  * appreciated but is not required.
   23  */
   24 
   25 //---------------------------------------------------------------------------
   26 #include <windows.h>
   27 #include <stdio.h>
   28 #include <string>
   29 
   30 #include "litePDF.h"
   31 
   32 // link to version.lib, due to checkAPIVersion()
   33 #ifdef _MSC_VER
   34 #pragma comment (lib, "version.lib")
   35 #else // _MSC_VER
   36 #ifdef _BORLANDC
   37 #pragma link "version.lib"
   38 #endif // _BORLANDC
   39 #endif // _MSC_VER
   40 
   41 namespace litePDF {
   42 
   43 const char *LitePDFAuthorizationKey = NULL;
   44 
   45 #define ThrowIfFail(_expr) do {                                                \
   46       if (!(_expr)) {                                                          \
   47          std::string ttmsg;                                                    \
   48          ttmsg = std::string(_func) + ": Assertion '" + (#_expr) + "' failed"; \
   49          throw TLitePDFException(ERROR_INVALID_PARAMETER, ttmsg.c_str());      \
   50       }                                                                        \
   51    } while (false)
   52 
   53 #define ThrowMessageIfFail(_expr, _msg) do {                                   \
   54       if (!(_expr)) {                                                          \
   55          std::string ttmsg = std::string(_func) + ": " + (_msg);               \
   56          throw TLitePDFException(ERROR_INVALID_PARAMETER, ttmsg.c_str());      \
   57       }                                                                        \
   58    } while (false)
   59 
   60 #define ThrowLastErrorIfFail(_expr) do {                                       \
   61       if (!(_expr)) {                                                          \
   62          std::string ttmsg = std::string("Failed to call '") + (_func) + "'";  \
   63          const char *msg = getLastErrorMessage();                              \
   64          if (!msg) {                                                           \
   65             msg = ttmsg.c_str();                                               \
   66          }                                                                     \
   67          throw TLitePDFException(getLastErrorCode(), msg);                     \
   68       }                                                                        \
   69    } while (false)
   70 
   71 #define InitFunc(_ret,_name,_params)                  \
   72    freeLastError();                                   \
   73    typedef _ret (__stdcall FAR *LP ## _name) _params; \
   74    LP ## _name func;                                  \
   75                                                       \
   76    func = (LP ## _name) GetProc(# _name);
   77 
   78 #define FreePtr(_ptr) do { if ((_ptr)) { free((_ptr)); (_ptr) = NULL; } } while (0)
   79 
   80 //---------------------------------------------------------------------------
   81 
   82 TLitePDFException::TLitePDFException(DWORD pCode, const char *pMsg)
   83 {
   84    code = pCode;
   85    if (pMsg) {
   86       msg = strdup(pMsg);
   87    } else {
   88       msg = NULL;
   89    }
   90 }
   91 //---------------------------------------------------------------------------
   92 
   93 TLitePDFException::TLitePDFException(const TLitePDFException &src)
   94 {
   95    code = src.getCode();
   96    if (src.getMessage()) {
   97       msg = strdup(src.getMessage());
   98    } else {
   99       msg = NULL;
  100    }
  101 }
  102 //---------------------------------------------------------------------------
  103 
  104 TLitePDFException::~TLitePDFException()
  105 {
  106    FreePtr(msg);
  107 }
  108 //---------------------------------------------------------------------------
  109 
  110 DWORD TLitePDFException::getCode(void) const
  111 {
  112    return code;
  113 }
  114 //---------------------------------------------------------------------------
  115 
  116 const char *TLitePDFException::getMessage(void) const
  117 {
  118    return msg;
  119 }
  120 //---------------------------------------------------------------------------
  121 
  122 TLitePDF::TLitePDF()
  123 {
  124    lib = NULL;
  125    context = NULL;
  126    lastErrorCode = 0;
  127    lastErrorMessage = NULL;
  128    onError = NULL;
  129    onErrorUserData = NULL;
  130 }
  131 //---------------------------------------------------------------------------
  132 
  133 TLitePDF::~TLitePDF()
  134 {
  135    unloadLibrary();
  136 
  137    FreePtr(lastErrorMessage);
  138 }
  139 //---------------------------------------------------------------------------
  140 
  141 FARPROC TLitePDF::GetProc(const char *pProcIdent)
  142 {
  143    const char *_func = "TLitePDF::GetProc";
  144 
  145    ensureLibraryLoaded(_func);
  146 
  147    ThrowIfFail(pProcIdent != NULL);
  148    ThrowIfFail(lib != NULL);
  149 
  150    FARPROC res = NULL;
  151    res = GetProcAddress(lib, pProcIdent);
  152 
  153    char err[1024];
  154    sprintf(err, "Proc '%s' not found", pProcIdent);
  155 
  156    ThrowMessageIfFail(res != NULL, err);
  157 
  158    return res;
  159 }
  160 //---------------------------------------------------------------------------
  161 
  162 void TLitePDF::setOnError(MLitePDFErrorEvent pOnError,
  163                           void *pOnErrorUserData)
  164 {
  165    onError = pOnError;
  166    onErrorUserData = pOnErrorUserData;
  167 }
  168 //---------------------------------------------------------------------------
  169 
  170 DWORD TLitePDF::getLastErrorCode(void) const
  171 {
  172    return lastErrorCode;
  173 }
  174 //---------------------------------------------------------------------------
  175 
  176 const char *TLitePDF::getLastErrorMessage(void) const
  177 {
  178    return lastErrorMessage;
  179 }
  180 //---------------------------------------------------------------------------
  181 
  182 void TLitePDF::freeLastError(void)
  183 {
  184    FreePtr(lastErrorMessage);
  185    lastErrorCode = 0;
  186 }
  187 //---------------------------------------------------------------------------
  188 
  189 void TLitePDF::setLastError(DWORD code,
  190                             const char *msg)
  191 {
  192    freeLastError();
  193 
  194    lastErrorCode = code;
  195    if (msg) {
  196       lastErrorMessage = strdup (msg);
  197    }
  198 }
  199 //---------------------------------------------------------------------------
  200 
  201 bool TLitePDF::checkAPIVersion(unsigned int major,
  202                                unsigned int minor)
  203 {
  204    if (!lib) {
  205       return false;
  206    }
  207 
  208    char fileName[2048 + 1];
  209    DWORD fileNameLen = GetModuleFileNameA(lib, fileName, 2048);
  210    if (!fileNameLen) {
  211       return false;
  212    }
  213    fileName[fileNameLen] = 0;
  214 
  215    bool apiIsOK = false;
  216    DWORD dwVerHnd;
  217    DWORD dwVerInfoSize;
  218 
  219    dwVerInfoSize = GetFileVersionInfoSizeA(fileName, &dwVerHnd);
  220   
  221    if (dwVerInfoSize) {
  222       HANDLE  hMem;
  223       LPVOID  lpvMem;
  224 
  225       hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  226       lpvMem = GlobalLock(hMem);
  227 
  228       VS_FIXEDFILEINFO *VersionInfo = NULL;
  229       if (GetFileVersionInfoA(fileName, dwVerHnd, dwVerInfoSize, lpvMem)) {
  230          UINT cchVer;
  231          BOOL fRet = VerQueryValueA(lpvMem, "\\", (void **)&VersionInfo, &cchVer);
  232 
  233          if (fRet && cchVer) {
  234             apiIsOK = ((VersionInfo->dwFileVersionMS >> 16) & 0xFFFF) == major &&
  235                        (VersionInfo->dwFileVersionMS & 0xFFFF) == minor;
  236          }
  237  
  238          GlobalUnlock(hMem);
  239          GlobalFree(hMem);
  240       }
  241    }
  242 
  243    return apiIsOK;
  244 }
  245 //---------------------------------------------------------------------------
  246 
  247 void TLitePDF::ensureLibraryLoaded(const char *_func)
  248 {
  249    if (lib) {
  250       return;
  251    }
  252 
  253    ThrowIfFail(lib == NULL);
  254    ThrowIfFail(context == NULL);
  255 
  256    #ifdef UNICODE
  257    lib = LoadLibraryW(L"litePDF.dll");
  258    #else
  259    lib = LoadLibraryA("litePDF.dll");
  260    #endif // UNICODE
  261    ThrowMessageIfFail (lib != NULL, "Failed to open litePDF.dll");
  262 
  263    if (!checkAPIVersion(LitePDF_API_Major, LitePDF_API_Minor)) {
  264       FreeLibrary (lib);
  265       lib = NULL;
  266 
  267       std::string ttmsg = std::string(_func) + ": " + "This LitePDF class is not designed for API version of litePDF.dll";
  268       throw TLitePDFException(ERROR_INVALID_DLL, ttmsg.c_str());
  269    }
  270 
  271    typedef void (__stdcall * litePDFErrorCB)(unsigned int code, const char *msg, void *user_data);
  272 
  273    InitFunc(void *, litePDF_CreateContext, (const char *authKey, litePDFErrorCB on_error, void *on_error_user_data));
  274 
  275    context = func (LitePDFAuthorizationKey, litePDFError, this);
  276 
  277    if (!context) {
  278       FreeLibrary (lib);
  279       lib = NULL;
  280       ThrowMessageIfFail (context != NULL, "Failed to create context");
  281    }
  282 }
  283 //---------------------------------------------------------------------------
  284 
  285 void TLitePDF::unloadLibrary(void)
  286 {
  287    if (lib && context) {
  288       try {
  289          InitFunc(void, litePDF_FreeContext, (void *context));
  290          func(context);
  291       } catch(...) {
  292       }
  293       FreeLibrary(lib);
  294    }
  295 
  296    context = NULL;
  297    lib = NULL;
  298 }
  299 //---------------------------------------------------------------------------
  300 
  301 void TLitePDF::SetUnit(TLitePDFUnit unitValue)
  302 {
  303    const char *_func = "TLitePDF::SetUnit";
  304 
  305    ensureLibraryLoaded(_func);
  306 
  307    ThrowIfFail(lib != NULL);
  308 
  309    InitFunc(BOOL, litePDF_SetUnit, (void *pctx, unsigned int unitValue));
  310 
  311    ThrowLastErrorIfFail(func(context, (unsigned int) unitValue));
  312 }
  313 //---------------------------------------------------------------------------
  314 
  315 TLitePDFUnit TLitePDF::GetUnit(void)
  316 {
  317    const char *_func = "TLitePDF::GetUnit";
  318 
  319    ensureLibraryLoaded(_func);
  320 
  321    ThrowIfFail(lib != NULL);
  322 
  323    InitFunc(unsigned int, litePDF_GetUnit, (void *pctx));
  324 
  325    TLitePDFUnit currentUnit = (TLitePDFUnit) func(context);
  326 
  327    ThrowLastErrorIfFail(currentUnit > LitePDFUnit_Unknown && currentUnit <= LitePDFUnit_1000th_inch);
  328 
  329    return currentUnit;
  330 }
  331 //---------------------------------------------------------------------------
  332 
  333 double TLitePDF::MMToUnitEx(TLitePDFUnit useUnit,
  334                             double mmValue) const
  335 {
  336    double ratio = 1.0;
  337 
  338    switch(useUnit) {
  339    case LitePDFUnit_mm:
  340       ratio = 1.0;
  341       break;
  342    case LitePDFUnit_10th_mm:
  343       ratio = 10.0;
  344       break;
  345    case LitePDFUnit_100th_mm:
  346       ratio = 100.0;
  347       break;
  348    case LitePDFUnit_1000th_mm:
  349       ratio = 1000.0;
  350       break;
  351    case LitePDFUnit_inch:
  352       ratio = 1.0 / 25.4;
  353       break;
  354    case LitePDFUnit_10th_inch:
  355       ratio = 10.0 / 25.4;
  356       break;
  357    case LitePDFUnit_100th_inch:
  358       ratio = 100.0 / 25.4;
  359       break;
  360    case LitePDFUnit_1000th_inch:
  361       ratio = 1000.0 / 25.4;
  362       break;
  363    case LitePDFUnit_Unknown:
  364       break;
  365    }
  366 
  367    return mmValue * ratio;
  368 }
  369 //---------------------------------------------------------------------------
  370 
  371 double TLitePDF::UnitToMMEx(TLitePDFUnit useUnit,
  372                             double unitValue) const
  373 {
  374    double ratio = 1.0;
  375 
  376    switch(useUnit) {
  377    case LitePDFUnit_mm:
  378       ratio = 1.0;
  379       break;
  380    case LitePDFUnit_10th_mm:
  381       ratio = 1.0 / 10.0;
  382       break;
  383    case LitePDFUnit_100th_mm:
  384       ratio = 1.0 / 100.0;
  385       break;
  386    case LitePDFUnit_1000th_mm:
  387       ratio = 1.0 / 1000.0;
  388       break;
  389    case LitePDFUnit_inch:
  390       ratio = 25.4;
  391       break;
  392    case LitePDFUnit_10th_inch:
  393       ratio = 25.4 / 10.0;
  394       break;
  395    case LitePDFUnit_100th_inch:
  396       ratio = 25.4 / 100.0;
  397       break;
  398    case LitePDFUnit_1000th_inch:
  399       ratio = 25.4 / 1000.0;
  400       break;
  401    case LitePDFUnit_Unknown:
  402       break;
  403    }
  404 
  405    return unitValue * ratio;
  406 }
  407 //---------------------------------------------------------------------------
  408 
  409 double TLitePDF::InchToUnitEx(TLitePDFUnit useUnit,
  410                               double inchValue) const
  411 {
  412    double ratio = 1.0;
  413 
  414    switch(useUnit) {
  415    case LitePDFUnit_mm:
  416       ratio = 25.4;
  417       break;
  418    case LitePDFUnit_10th_mm:
  419       ratio = 10.0 * 25.4;
  420       break;
  421    case LitePDFUnit_100th_mm:
  422       ratio = 100.0 * 25.4;
  423       break;
  424    case LitePDFUnit_1000th_mm:
  425       ratio = 1000.0 * 25.4;
  426       break;
  427    case LitePDFUnit_inch:
  428       ratio = 1.0;
  429       break;
  430    case LitePDFUnit_10th_inch:
  431       ratio = 10.0;
  432       break;
  433    case LitePDFUnit_100th_inch:
  434       ratio = 100.0;
  435       break;
  436    case LitePDFUnit_1000th_inch:
  437       ratio = 1000.0;
  438       break;
  439    case LitePDFUnit_Unknown:
  440       break;
  441    }
  442 
  443    return inchValue * ratio;
  444 }
  445 //---------------------------------------------------------------------------
  446 
  447 double TLitePDF::UnitToInchEx(TLitePDFUnit useUnit,
  448                               double unitValue) const
  449 {
  450    double ratio = 1.0;
  451 
  452    switch(useUnit) {
  453    case LitePDFUnit_mm:
  454       ratio = 1.0 / 25.4;
  455       break;
  456    case LitePDFUnit_10th_mm:
  457       ratio = 1.0 / (25.4 * 10.0);
  458       break;
  459    case LitePDFUnit_100th_mm:
  460       ratio = 1.0 / (25.4 * 100.0);
  461       break;
  462    case LitePDFUnit_1000th_mm:
  463       ratio = 1.0 / (25.4 * 1000.0);
  464       break;
  465    case LitePDFUnit_inch:
  466       ratio = 1.0;
  467       break;
  468    case LitePDFUnit_10th_inch:
  469       ratio = 1.0 / 10.0;
  470       break;
  471    case LitePDFUnit_100th_inch:
  472       ratio = 1.0 / 100.0;
  473       break;
  474    case LitePDFUnit_1000th_inch:
  475       ratio = 1.0 / 1000.0;
  476       break;
  477    case LitePDFUnit_Unknown:
  478       break;
  479    }
  480 
  481    return unitValue * ratio;
  482 }
  483 //---------------------------------------------------------------------------
  484 
  485 double TLitePDF::MMToUnit(double mmValue)
  486 {
  487    return MMToUnitEx(GetUnit(), mmValue);
  488 }
  489 //---------------------------------------------------------------------------
  490 
  491 double TLitePDF::UnitToMM(double unitValue)
  492 {
  493    return UnitToMMEx(GetUnit(), unitValue);
  494 }
  495 //---------------------------------------------------------------------------
  496 
  497 double TLitePDF::InchToUnit(double inchValue)
  498 {
  499    return InchToUnitEx(GetUnit(), inchValue);
  500 }
  501 //---------------------------------------------------------------------------
  502 
  503 double TLitePDF::UnitToInch(double unitValue)
  504 {
  505    return UnitToInchEx(GetUnit(), unitValue);
  506 }
  507 //---------------------------------------------------------------------------
  508 
  509 void __stdcall TLitePDF::litePDFError(unsigned int code,
  510                                       const char *msg,
  511                                       void *user_data)
  512 {
  513    const char *_func = "TLitePDF::litePDFError";
  514    TLitePDF *lpdf;
  515 
  516    ThrowIfFail(user_data != NULL);
  517 
  518    lpdf = (TLitePDF *) user_data;
  519    lpdf->setLastError(code, msg);
  520    if (lpdf->onError) {
  521       lpdf->onError(code, msg, lpdf->onErrorUserData);
  522    }
  523 }
  524 //---------------------------------------------------------------------------
  525 
  526 void TLitePDF::PrepareEncryption(const char *userPassword,
  527                                  const char *ownerPassword,
  528                                  unsigned int permissions,
  529                                  unsigned int algorithm)
  530 {
  531    const char *_func = "TLitePDF::PrepareEncryption";
  532 
  533    ensureLibraryLoaded(_func);
  534 
  535    ThrowIfFail(lib != NULL);
  536 
  537    InitFunc(BOOL, litePDF_PrepareEncryption, (void *pctx, const char *userPassword, const char *ownerPassword, unsigned int permissions, unsigned int algorithm));
  538 
  539    ThrowLastErrorIfFail(func(context, userPassword, ownerPassword, permissions, algorithm));
  540 }
  541 //---------------------------------------------------------------------------
  542 
  543 void TLitePDF::CreateFileDocument(const char *fileName)
  544 {
  545    const char *_func = "TLitePDF::CreateFileDocument";
  546 
  547    ensureLibraryLoaded(_func);
  548 
  549    ThrowIfFail(lib != NULL);
  550 
  551    InitFunc(BOOL, litePDF_CreateFileDocument, (void *pctx, const char *fileName));
  552 
  553    ThrowLastErrorIfFail(func(context, fileName));
  554 }
  555 //---------------------------------------------------------------------------
  556 
  557 void TLitePDF::CreateFileDocumentW(const wchar_t *fileName)
  558 {
  559    const char *_func = "TLitePDF::CreateFileDocumentW";
  560 
  561    ensureLibraryLoaded(_func);
  562 
  563    ThrowIfFail(lib != NULL);
  564 
  565    InitFunc(BOOL, litePDF_CreateFileDocumentW, (void *pctx, const wchar_t *fileName));
  566 
  567    ThrowLastErrorIfFail(func(context, fileName));
  568 }
  569 //---------------------------------------------------------------------------
  570 
  571 void TLitePDF::CreateMemDocument(void)
  572 {
  573    const char *_func = "TLitePDF::CreateMemDocument";
  574 
  575    ensureLibraryLoaded(_func);
  576 
  577    ThrowIfFail(lib != NULL);
  578 
  579    InitFunc(BOOL, litePDF_CreateMemDocument, (void *pctx));
  580 
  581    ThrowLastErrorIfFail(func(context));
  582 }
  583 //---------------------------------------------------------------------------
  584 
  585 void TLitePDF::LoadFromFile(const char *fileName,
  586                             const char *password,
  587                             bool loadCompletely,
  588                             bool forUpdate)
  589 {
  590    const char *_func = "TLitePDF::LoadFromFile";
  591 
  592    ensureLibraryLoaded(_func);
  593 
  594    ThrowIfFail(lib != NULL);
  595    ThrowIfFail(fileName != NULL);
  596 
  597    InitFunc(BOOL, litePDF_LoadFromFile, (void *pctx, const char *fileName, const char *password, BOOL loadCompletely, BOOL forUpdate));
  598 
  599    ThrowLastErrorIfFail(func(context, fileName, password, loadCompletely ? TRUE : FALSE, forUpdate ? TRUE : FALSE));
  600 }
  601 //---------------------------------------------------------------------------
  602 
  603 void TLitePDF::LoadFromFileW(const wchar_t *fileName,
  604                              const char *password,
  605                              bool loadCompletely,
  606                              bool forUpdate)
  607 {
  608    const char *_func = "TLitePDF::LoadFromFileW";
  609 
  610    ensureLibraryLoaded(_func);
  611 
  612    ThrowIfFail(lib != NULL);
  613    ThrowIfFail(fileName != NULL);
  614 
  615    InitFunc(BOOL, litePDF_LoadFromFileW, (void *pctx, const wchar_t *fileName, const char *password, BOOL loadCompletely, BOOL forUpdate));
  616 
  617    ThrowLastErrorIfFail(func(context, fileName, password, loadCompletely ? TRUE : FALSE, forUpdate ? TRUE : FALSE));
  618 }
  619 //---------------------------------------------------------------------------
  620 
  621 void TLitePDF::LoadFromData(const BYTE *data,
  622                             unsigned int dataLength,
  623                             const char *password,
  624                             bool forUpdate)
  625 {
  626    const char *_func = "TLitePDF::LoadFromData";
  627 
  628    ensureLibraryLoaded(_func);
  629 
  630    ThrowIfFail(lib != NULL);
  631    ThrowIfFail(data != NULL);
  632 
  633    InitFunc(BOOL, litePDF_LoadFromData, (void *pctx, const BYTE *data, unsigned int dataLength, const char *password, BOOL forUpdate));
  634 
  635    ThrowLastErrorIfFail(func(context, data, dataLength, password, forUpdate ? TRUE : FALSE));
  636 }
  637 //---------------------------------------------------------------------------
  638 
  639 void TLitePDF::SaveToFile(const char *fileName)
  640 {
  641    const char *_func = "TLitePDF::SaveToFile";
  642 
  643    ensureLibraryLoaded(_func);
  644 
  645    ThrowIfFail(lib != NULL);
  646    ThrowIfFail(fileName != NULL);
  647 
  648    InitFunc(BOOL, litePDF_SaveToFile, (void *pctx, const char *fileName));
  649 
  650    ThrowLastErrorIfFail(func(context, fileName));
  651 }
  652 //---------------------------------------------------------------------------
  653 
  654 void TLitePDF::SaveToFileW(const wchar_t *fileName)
  655 {
  656    const char *_func = "TLitePDF::SaveToFileW";
  657 
  658    ensureLibraryLoaded(_func);
  659 
  660    ThrowIfFail(lib != NULL);
  661    ThrowIfFail(fileName != NULL);
  662 
  663    InitFunc(BOOL, litePDF_SaveToFileW, (void *pctx, const wchar_t *fileName));
  664 
  665    ThrowLastErrorIfFail(func(context, fileName));
  666 }
  667 //---------------------------------------------------------------------------
  668 
  669 bool TLitePDF::SaveToData(BYTE *data,
  670                           unsigned int *dataLength)
  671 {
  672    const char *_func = "TLitePDF::SaveToData";
  673 
  674    ensureLibraryLoaded(_func);
  675 
  676    ThrowIfFail(lib != NULL);
  677    ThrowIfFail(dataLength != NULL);
  678 
  679    InitFunc(BOOL, litePDF_SaveToData, (void *pctx, BYTE *data, unsigned int *dataLength));
  680 
  681    BOOL succeeded = func(context, data, dataLength);
  682 
  683    return succeeded ? true : false;
  684 }
  685 //---------------------------------------------------------------------------
  686 
  687 void TLitePDF::Close(void)
  688 {
  689    const char *_func = "TLitePDF::Close";
  690 
  691    ensureLibraryLoaded(_func);
  692 
  693    ThrowIfFail(lib != NULL);
  694 
  695    InitFunc(void, litePDF_Close, (void *pctx));
  696 
  697    func(context);
  698 }
  699 //---------------------------------------------------------------------------
  700 
  701 unsigned int TLitePDF::GetPageCount(void)
  702 {
  703    const char *_func = "TLitePDF::GetPageCount";
  704 
  705    ensureLibraryLoaded(_func);
  706 
  707    ThrowIfFail(lib != NULL);
  708 
  709    InitFunc(BOOL, litePDF_GetPageCount, (void *pctx, unsigned int *pageCount));
  710 
  711    unsigned int pageCount = 0;
  712    ThrowLastErrorIfFail(func(context, &pageCount));
  713 
  714    return pageCount;
  715 }
  716 //---------------------------------------------------------------------------
  717 
  718 void TLitePDF::GetPageSize(unsigned int pageIndex,
  719                            unsigned int *width_u,
  720                            unsigned int *height_u)
  721 {
  722    const char *_func = "TLitePDF::GetPageSize";
  723 
  724    ensureLibraryLoaded(_func);
  725 
  726    ThrowIfFail(lib != NULL);
  727    ThrowIfFail(width_u != NULL);
  728    ThrowIfFail(height_u != NULL);
  729 
  730    InitFunc(BOOL, litePDF_GetPageSize, (void *pctx, unsigned int pageIndex, unsigned int *width_u, unsigned int *height_u));
  731 
  732    ThrowLastErrorIfFail(func(context, pageIndex, width_u, height_u));
  733 }
  734 //---------------------------------------------------------------------------
  735 
  736 HDC TLitePDF::AddPage(unsigned int width_u,
  737                       unsigned int height_u,
  738                       unsigned int width_px,
  739                       unsigned int height_px,
  740                       unsigned int drawFlags)
  741 {
  742    const char *_func = "TLitePDF::AddPage";
  743 
  744    ensureLibraryLoaded(_func);
  745 
  746    ThrowIfFail(lib != NULL);
  747 
  748    InitFunc(HDC, litePDF_AddPage, (void *pctx, unsigned int width_u, unsigned int height_u, unsigned int width_px, unsigned int height_px, unsigned int drawFlags));
  749 
  750    HDC res = func (context, width_u, height_u, width_px, height_px, drawFlags);
  751    ThrowLastErrorIfFail(res != NULL);
  752 
  753    return res;
  754 }
  755 //---------------------------------------------------------------------------
  756 
  757 HDC TLitePDF::InsertPage(unsigned int pageIndex,
  758                          unsigned int width_u,
  759                          unsigned int height_u,
  760                          unsigned int width_px,
  761                          unsigned int height_px,
  762                          unsigned int drawFlags)
  763 {
  764    const char *_func = "TLitePDF::InsertPage";
  765 
  766    ensureLibraryLoaded(_func);
  767 
  768    ThrowIfFail(lib != NULL);
  769 
  770    InitFunc(HDC, litePDF_InsertPage, (void *pctx, unsigned int pageIndex, unsigned int width_u, unsigned int height_u, unsigned int width_px, unsigned int height_px, unsigned int drawFlags));
  771 
  772    HDC res = func(context, pageIndex, width_u, height_u, width_px, height_px, drawFlags);
  773    ThrowLastErrorIfFail(res != NULL);
  774 
  775    return res;
  776 }
  777 //---------------------------------------------------------------------------
  778 
  779 HDC TLitePDF::UpdatePage(unsigned int pageIndex,
  780                          unsigned int width_px,
  781                          unsigned int height_px,
  782                          unsigned int drawFlags)
  783 {
  784    const char *_func = "TLitePDF::UpdatePage";
  785 
  786    ensureLibraryLoaded(_func);
  787 
  788    ThrowIfFail(lib != NULL);
  789 
  790    InitFunc(HDC, litePDF_UpdatePage, (void *pctx, unsigned int pageIndex, unsigned int width_px, unsigned int height_px, unsigned int drawFlags));
  791 
  792    HDC res = func(context, pageIndex, width_px, height_px, drawFlags);
  793    ThrowLastErrorIfFail(res != NULL);
  794 
  795    return res;
  796 }
  797 //---------------------------------------------------------------------------
  798 
  799 void TLitePDF::FinishPage(HDC hDC)
  800 {
  801    const char *_func = "TLitePDF::FinishPage";
  802 
  803    ensureLibraryLoaded(_func);
  804 
  805    ThrowIfFail(lib != NULL);
  806    ThrowIfFail(hDC != NULL);
  807 
  808    InitFunc(BOOL, litePDF_FinishPage, (void *pctx, HDC hDC));
  809 
  810    ThrowLastErrorIfFail(func(context, hDC));
  811 }
  812 //---------------------------------------------------------------------------
  813 
  814 HDC TLitePDF::AddResource(unsigned int width_u,
  815                           unsigned int height_u,
  816                           unsigned int width_px,
  817                           unsigned int height_px,
  818                           unsigned int drawFlags)
  819 {
  820    const char *_func = "TLitePDF::AddResource";
  821 
  822    ensureLibraryLoaded(_func);
  823 
  824    ThrowIfFail(lib != NULL);
  825 
  826    InitFunc(HDC, litePDF_AddResource, (void *pctx, unsigned int width_u, unsigned int height_u, unsigned int width_px, unsigned int height_px, unsigned int drawFlags));
  827 
  828    HDC res = func(context, width_u, height_u, width_px, height_px, drawFlags);
  829    ThrowLastErrorIfFail(res != NULL);
  830 
  831    return res;
  832 }
  833 //---------------------------------------------------------------------------
  834 
  835 unsigned int TLitePDF::FinishResource(HDC hDC)
  836 {
  837    const char *_func = "TLitePDF::FinishResource";
  838 
  839    ensureLibraryLoaded(_func);
  840 
  841    ThrowIfFail(lib != NULL);
  842    ThrowIfFail(hDC != NULL);
  843 
  844    InitFunc(unsigned int, litePDF_FinishResource, (void *pctx, HDC hDC));
  845 
  846    unsigned int resourceID = func(context, hDC);
  847    ThrowLastErrorIfFail(resourceID != 0);
  848 
  849    return resourceID;
  850 }
  851 //---------------------------------------------------------------------------
  852 
  853 void TLitePDF::DeletePage(unsigned int pageIndex)
  854 {
  855    const char *_func = "TLitePDF::DeletePage";
  856 
  857    ensureLibraryLoaded(_func);
  858 
  859    ThrowIfFail(lib != NULL);
  860 
  861    InitFunc(BOOL, litePDF_DeletePage, (void *pctx, unsigned int pageIndex));
  862 
  863    ThrowLastErrorIfFail(func(context, pageIndex));
  864 }
  865 //---------------------------------------------------------------------------
  866 
  867 void TLitePDF::AddPagesFrom(litePDF::TLitePDF *from,
  868                             unsigned int pageIndex,
  869                             unsigned int pageCount)
  870 {
  871    const char *_func = "TLitePDF::AddPagesFrom";
  872 
  873    ensureLibraryLoaded(_func);
  874 
  875    ThrowIfFail(lib != NULL);
  876    ThrowIfFail(from != NULL);
  877    ThrowIfFail(from != this);
  878    ThrowIfFail(from->context != NULL);
  879 
  880    InitFunc(BOOL, litePDF_AddPagesFrom, (void *pctx, void *pctx_from, unsigned int pageIndex, unsigned int pageCount));
  881 
  882    ThrowLastErrorIfFail(func(context, from->context, pageIndex, pageCount));
  883 }
  884 //---------------------------------------------------------------------------
  885 
  886 void TLitePDF::InsertPageFrom(unsigned int pageIndexTo,
  887                               litePDF::TLitePDF *from,
  888                               unsigned int pageIndexFrom)
  889 {
  890    const char *_func = "TLitePDF::InsertPageFrom";
  891 
  892    ensureLibraryLoaded(_func);
  893 
  894    ThrowIfFail(lib != NULL);
  895    ThrowIfFail(from != NULL);
  896    ThrowIfFail(from != this);
  897    ThrowIfFail(from->context != NULL);
  898 
  899    InitFunc(BOOL, litePDF_InsertPageFrom, (void *pctx, unsigned int pageIndexTo, void *pctx_from, unsigned int pageIndexFrom));
  900 
  901    ThrowLastErrorIfFail(func(context, pageIndexTo, from->context, pageIndexFrom));
  902 }
  903 //---------------------------------------------------------------------------
  904 
  905 unsigned int TLitePDF::AddPageFromAsResource(litePDF::TLitePDF *from,
  906                                              unsigned int pageIndex,
  907                                              bool useTrimBox)
  908 {
  909    const char *_func = "TLitePDF::AddPageFromAsResource";
  910 
  911    ensureLibraryLoaded(_func);
  912 
  913    ThrowIfFail(lib != NULL);
  914    ThrowIfFail(from != NULL);
  915    ThrowIfFail(from != this);
  916    ThrowIfFail(from->context != NULL);
  917 
  918    InitFunc(unsigned int, litePDF_AddPageFromAsResource, (void *pctx, void *pctx_from, unsigned int pageIndex, BOOL useTrimBox));
  919 
  920    unsigned int resourceID = func(context, from->context, pageIndex, useTrimBox ? TRUE : FALSE);
  921    ThrowLastErrorIfFail(resourceID != 0);
  922 
  923    return resourceID;
  924 }
  925 //---------------------------------------------------------------------------
  926 
  927 unsigned int TLitePDF::PageToResource(unsigned int pageIndex)
  928 {
  929    const char *_func = "TLitePDF::PageToResource";
  930 
  931    ensureLibraryLoaded(_func);
  932 
  933    ThrowIfFail(lib != NULL);
  934 
  935    InitFunc(unsigned int, litePDF_PageToResource, (void *pctx, unsigned int pageIndex));
  936 
  937    unsigned int resourceID = func(context, pageIndex);
  938    ThrowLastErrorIfFail(resourceID != 0);
  939 
  940    return resourceID;
  941 }
  942 //---------------------------------------------------------------------------
  943 
  944 void TLitePDF::GetResourceSize(unsigned int resourceID,
  945                                unsigned int *width_u,
  946                                unsigned int *height_u)
  947 {
  948    const char *_func = "TLitePDF::GetResourceSize";
  949 
  950    ensureLibraryLoaded(_func);
  951 
  952    ThrowIfFail(lib != NULL);
  953    ThrowIfFail(width_u != NULL);
  954    ThrowIfFail(height_u != NULL);
  955 
  956    InitFunc(BOOL, litePDF_GetResourceSize, (void *pctx, unsigned int resourceID, unsigned int *width_u, unsigned int *height_u));
  957 
  958    ThrowLastErrorIfFail(func(context, resourceID, width_u, height_u));
  959 }
  960 //---------------------------------------------------------------------------
  961 
  962 void TLitePDF::DrawResource(unsigned int resourceID,
  963                             unsigned int pageIndex,
  964                             TLitePDFUnit unitValue,
  965                             int x,
  966                             int y,
  967                             int scaleX,
  968                             int scaleY)
  969 {
  970    const char *_func = "TLitePDF::DrawResource";
  971 
  972    ensureLibraryLoaded(_func);
  973 
  974    ThrowIfFail(lib != NULL);
  975 
  976    InitFunc(BOOL, litePDF_DrawResource, (void *pctx, unsigned int resourceID, unsigned int unitValue, unsigned int pageIndex, int x, int y, int scaleX, int scaleY));
  977 
  978    ThrowLastErrorIfFail(func(context, resourceID, pageIndex, (unsigned int) unitValue, x, y, scaleX, scaleY));
  979 }
  980 //---------------------------------------------------------------------------
  981 
  982 void TLitePDF::DrawResourceWithMatrix(unsigned int resourceID,
  983                                       unsigned int pageIndex,
  984                                       double a,
  985                                       double b,
  986                                       double c,
  987                                       double d,
  988                                       double e,
  989                                       double f)
  990 {
  991    const char *_func = "TLitePDF::DrawResourceWithMatrix";
  992 
  993    ensureLibraryLoaded(_func);
  994 
  995    ThrowIfFail(lib != NULL);
  996 
  997    InitFunc(BOOL, litePDF_DrawResourceWithMatrix, (void *pctx, unsigned int resourceID, unsigned int pageIndex, int a, int b, int c, int d, int e, int f));
  998 
  999    int i_a = a * 1000.0, i_b = b * 1000.0, i_c = c * 1000.0, i_d = d * 1000.0, i_e = e * 1000.0, i_f = f * 1000.0;
 1000 
 1001    ThrowLastErrorIfFail(func(context, resourceID, pageIndex, i_a, i_b, i_c, i_d, i_e, i_f));
 1002 }
 1003 //---------------------------------------------------------------------------
 1004 
 1005 void TLitePDF::SetDocumentInfo(const char *name,
 1006                                const wchar_t *value)
 1007 {
 1008    const char *_func = "TLitePDF::SetDocumentInfo";
 1009 
 1010    ensureLibraryLoaded(_func);
 1011 
 1012    ThrowIfFail(lib != NULL);
 1013    ThrowIfFail(name != NULL);
 1014    ThrowIfFail(value != NULL);
 1015 
 1016    InitFunc(BOOL, litePDF_SetDocumentInfo, (void *pctx, const char *name, const wchar_t *value));
 1017 
 1018    ThrowLastErrorIfFail(func(context, name, value));
 1019 }
 1020 //---------------------------------------------------------------------------
 1021 
 1022 bool TLitePDF::GetDocumentInfoExists(const char *name)
 1023 {
 1024    const char *_func = "TLitePDF::GetDocumentInfoExists";
 1025 
 1026    ensureLibraryLoaded(_func);
 1027 
 1028    ThrowIfFail(lib != NULL);
 1029    ThrowIfFail(name != NULL);
 1030 
 1031    InitFunc(BOOL, litePDF_GetDocumentInfoExists, (void *pctx, const char *name, BOOL *pExists));
 1032 
 1033    BOOL exists = FALSE;
 1034 
 1035    ThrowLastErrorIfFail(func(context, name, &exists));
 1036 
 1037    return exists ? true : false;
 1038 }
 1039 //---------------------------------------------------------------------------
 1040 
 1041 std::wstring TLitePDF::GetDocumentInfo(const char *name)
 1042 {
 1043    const char *_func = "TLitePDF::GetDocumentInfo";
 1044 
 1045    ensureLibraryLoaded(_func);
 1046 
 1047    ThrowIfFail(lib != NULL);
 1048    ThrowIfFail(name != NULL);
 1049 
 1050    InitFunc(BOOL, litePDF_GetDocumentInfo, (void *pctx, const char *name, wchar_t *value, unsigned int *valueLength));
 1051 
 1052    unsigned int valueLength = 0;
 1053    ThrowLastErrorIfFail(func(context, name, NULL, &valueLength));
 1054 
 1055    wchar_t *buff = (wchar_t *) malloc(sizeof(wchar_t) * (valueLength + 1));
 1056    ThrowMessageIfFail(buff != NULL, "Out of memory!");
 1057 
 1058    std::wstring value;
 1059 
 1060    if (func(context, name, buff, &valueLength)) {
 1061       buff[valueLength] = 0;
 1062       value = buff;
 1063       free (buff);
 1064    } else {
 1065       free (buff);
 1066 
 1067       // always false
 1068       ThrowLastErrorIfFail(buff == NULL);
 1069    }
 1070 
 1071    return value;
 1072 }
 1073 //---------------------------------------------------------------------------
 1074 
 1075 bool TLitePDF::GetDocumentIsSigned(void)
 1076 {
 1077    const char *_func = "TLitePDF::GetDocumentIsSigned";
 1078 
 1079    ensureLibraryLoaded(_func);
 1080 
 1081    ThrowIfFail(lib != NULL);
 1082 
 1083    InitFunc(BOOL, litePDF_GetDocumentIsSigned, (void *pctx, BOOL *pIsSigned));
 1084 
 1085    BOOL isSigned = FALSE;
 1086 
 1087    ThrowLastErrorIfFail(func(context, &isSigned));
 1088 
 1089    return isSigned ? true : false;
 1090 }
 1091 //---------------------------------------------------------------------------
 1092 
 1093 unsigned int TLitePDF::GetSignatureCount(void)
 1094 {
 1095    const char *_func = "TLitePDF::GetSignatureCount";
 1096 
 1097    ensureLibraryLoaded(_func);
 1098 
 1099    ThrowIfFail(lib != NULL);
 1100 
 1101    InitFunc(BOOL, litePDF_GetSignatureCount, (void *pctx, unsigned int *pCount));
 1102 
 1103    unsigned int count = 0;
 1104 
 1105    ThrowLastErrorIfFail(func(context, &count));
 1106 
 1107    return count;
 1108 }
 1109 //---------------------------------------------------------------------------
 1110 
 1111 std::string TLitePDF::GetSignatureName(unsigned int index)
 1112 {
 1113    const char *_func = "TLitePDF::GetSignatureName";
 1114 
 1115    ensureLibraryLoaded(_func);
 1116 
 1117    ThrowIfFail(lib != NULL);
 1118 
 1119    InitFunc(BOOL, litePDF_GetSignatureName, (void *pctx, unsigned int index, char *name, unsigned int *nameLength));
 1120 
 1121    unsigned int nameLength = 0;
 1122    ThrowLastErrorIfFail(func(context, index, NULL, &nameLength));
 1123 
 1124    nameLength++;
 1125 
 1126    char *buff = (char *) malloc(sizeof(char) * (nameLength));
 1127    ThrowMessageIfFail(buff != NULL, "Out of memory!");
 1128 
 1129    std::string name;
 1130 
 1131    if (func(context, index, buff, &nameLength)) {
 1132       buff[nameLength] = 0;
 1133       name = buff;
 1134       free (buff);
 1135    } else {
 1136       free (buff);
 1137 
 1138       // always false
 1139       ThrowLastErrorIfFail(buff == NULL);
 1140    }
 1141 
 1142    return name;
 1143 }
 1144 //---------------------------------------------------------------------------
 1145 
 1146 unsigned int TLitePDF::CreateSignature(const char *name,
 1147                                        unsigned int annotationPageIndex,
 1148                                        int annotationX_u,
 1149                                        int annotationY_u,
 1150                                        int annotationWidth_u,
 1151                                        int annotationHeight_u,
 1152                                        unsigned int annotationFlags)
 1153 {
 1154    const char *_func = "TLitePDF::CreateSignature";
 1155 
 1156    ensureLibraryLoaded(_func);
 1157 
 1158    ThrowIfFail(lib != NULL);
 1159    ThrowIfFail(name != NULL);
 1160 
 1161    InitFunc(BOOL, litePDF_CreateSignature, (void *pctx,
 1162                                             const char *name,
 1163                                             unsigned int annotationPageIndex,
 1164                                             int annotationX_u,
 1165                                             int annotationY_u,
 1166                                             int annotationWidth_u,
 1167                                             int annotationHeight_u,
 1168                                             unsigned int annotationFlags,
 1169                                             unsigned int *pAddedIndex));
 1170 
 1171    unsigned int addedIndex = -1;
 1172 
 1173    ThrowLastErrorIfFail(func(context,
 1174       name,
 1175       annotationPageIndex,
 1176       annotationX_u,
 1177       annotationY_u,
 1178       annotationWidth_u,
 1179       annotationHeight_u,
 1180       annotationFlags,
 1181       &addedIndex));
 1182 
 1183    return addedIndex;
 1184 }
 1185 //---------------------------------------------------------------------------
 1186 
 1187 bool TLitePDF::GetSignatureHasData(unsigned int index)
 1188 {
 1189    const char *_func = "TLitePDF::GetSignatureHasData";
 1190 
 1191    ensureLibraryLoaded(_func);
 1192 
 1193    ThrowIfFail(lib != NULL);
 1194 
 1195    InitFunc(BOOL, litePDF_GetSignatureHasData, (void *pctx, unsigned int index, BOOL *pHasData));
 1196 
 1197    BOOL hasData = FALSE;
 1198 
 1199    ThrowLastErrorIfFail(func(context, index, &hasData));
 1200 
 1201    return hasData ? true : false;
 1202 }
 1203 //---------------------------------------------------------------------------
 1204 
 1205 bool TLitePDF::GetSignatureData(unsigned int index,
 1206                                 BYTE *data,
 1207                                 unsigned int *dataLength)
 1208 {
 1209    const char *_func = "TLitePDF::GetSignatureData";
 1210 
 1211    ensureLibraryLoaded(_func);
 1212 
 1213    ThrowIfFail(lib != NULL);
 1214    ThrowIfFail(dataLength != NULL);
 1215 
 1216    InitFunc(BOOL, litePDF_GetSignatureData, (void *pctx, unsigned int index, BYTE *data, unsigned int *dataLength));
 1217 
 1218    BOOL succeeded = func(context, index, data, dataLength);
 1219 
 1220    return succeeded ? true : false;
 1221 }
 1222 //---------------------------------------------------------------------------
 1223 
 1224 bool TLitePDF::GetSignatureRanges(unsigned int index,
 1225                                   unsigned __int64 *pRangesArray,
 1226                                   unsigned int *pRangesArrayLength)
 1227 {
 1228    const char *_func = "TLitePDF::GetSignatureRanges";
 1229 
 1230    ensureLibraryLoaded(_func);
 1231 
 1232    ThrowIfFail(lib != NULL);
 1233    ThrowIfFail(pRangesArrayLength != NULL);
 1234 
 1235    InitFunc(BOOL, litePDF_GetSignatureRanges, (void *pctx, unsigned int index, unsigned __int64 *pRangesArray, unsigned int *pRangesArrayLength));
 1236 
 1237    BOOL succeeded = func(context, index, pRangesArray, pRangesArrayLength);
 1238 
 1239    return succeeded ? true : false;
 1240 }
 1241 //---------------------------------------------------------------------------
 1242 
 1243 void TLitePDF::SetSignatureDate(unsigned int index,
 1244                                 __int64 dateOfSign)
 1245 {
 1246    const char *_func = "TLitePDF::SetSignatureDate";
 1247 
 1248    ensureLibraryLoaded(_func);
 1249 
 1250    ThrowIfFail(lib != NULL);
 1251 
 1252    InitFunc(BOOL, litePDF_SetSignatureDate, (void *pctx, unsigned int index, __int64 dateOfSign));
 1253 
 1254    ThrowLastErrorIfFail(func(context, index, dateOfSign));
 1255 }
 1256 //---------------------------------------------------------------------------
 1257 
 1258 __int64 TLitePDF::GetSignatureDate(unsigned int index)
 1259 {
 1260    const char *_func = "TLitePDF::GetSignatureDate";
 1261 
 1262    ensureLibraryLoaded(_func);
 1263 
 1264    ThrowIfFail(lib != NULL);
 1265 
 1266    InitFunc(BOOL, litePDF_GetSignatureDate, (void *pctx, unsigned int index, __int64 *pDateOfSign));
 1267 
 1268    __int64 dateOfSign = 0;
 1269 
 1270    ThrowLastErrorIfFail(func(context, index, &dateOfSign));
 1271 
 1272    return dateOfSign;
 1273 }
 1274 //---------------------------------------------------------------------------
 1275 
 1276 void TLitePDF::SetSignatureReason(unsigned int index,
 1277                                   const wchar_t *reason)
 1278 {
 1279    const char *_func = "TLitePDF::SetSignatureReason";
 1280 
 1281    ensureLibraryLoaded(_func);
 1282 
 1283    ThrowIfFail(lib != NULL);
 1284 
 1285    InitFunc(BOOL, litePDF_SetSignatureReason, (void *pctx, unsigned int index, const wchar_t *reason));
 1286 
 1287    ThrowLastErrorIfFail(func(context, index, reason));
 1288 }
 1289 //---------------------------------------------------------------------------
 1290 
 1291 std::wstring TLitePDF::GetSignatureReason(unsigned int index)
 1292 {
 1293    const char *_func = "TLitePDF::GetSignatureReason";
 1294 
 1295    ensureLibraryLoaded(_func);
 1296 
 1297    ThrowIfFail(lib != NULL);
 1298 
 1299    InitFunc(BOOL, litePDF_GetSignatureReason, (void *pctx, unsigned int index, wchar_t *value, unsigned int *valueLength));
 1300 
 1301    unsigned int valueLength = 0;
 1302    ThrowLastErrorIfFail(func(context, index, NULL, &valueLength));
 1303 
 1304    valueLength++;
 1305 
 1306    wchar_t *buff = (wchar_t *) malloc(sizeof(wchar_t) * (valueLength));
 1307    ThrowMessageIfFail(buff != NULL, "Out of memory!");
 1308 
 1309    std::wstring value;
 1310 
 1311    if (func(context, index, buff, &valueLength)) {
 1312       buff[valueLength] = 0;
 1313       value = buff;
 1314       free (buff);
 1315    } else {
 1316       free (buff);
 1317 
 1318       // always false
 1319       ThrowLastErrorIfFail(buff == NULL);
 1320    }
 1321 
 1322    return value;
 1323 }
 1324 //---------------------------------------------------------------------------
 1325 
 1326 void TLitePDF::SetSignatureLocation(unsigned int index,
 1327                                     const wchar_t *location)
 1328 {
 1329    const char *_func = "TLitePDF::SetSignatureLocation";
 1330 
 1331    ensureLibraryLoaded(_func);
 1332 
 1333    ThrowIfFail(lib != NULL);
 1334 
 1335    InitFunc(BOOL, litePDF_SetSignatureLocation, (void *pctx, unsigned int index, const wchar_t *location));
 1336 
 1337    ThrowLastErrorIfFail(func(context, index, location));
 1338 }
 1339 //---------------------------------------------------------------------------
 1340 
 1341 std::wstring TLitePDF::GetSignatureLocation(unsigned int index)
 1342 {
 1343    const char *_func = "TLitePDF::GetSignatureLocation";
 1344 
 1345    ensureLibraryLoaded(_func);
 1346 
 1347    ThrowIfFail(lib != NULL);
 1348 
 1349    InitFunc(BOOL, litePDF_GetSignatureLocation, (void *pctx, unsigned int index, wchar_t *value, unsigned int *valueLength));
 1350 
 1351    unsigned int valueLength = 0;
 1352    ThrowLastErrorIfFail(func(context, index, NULL, &valueLength));
 1353 
 1354    valueLength++;
 1355 
 1356    wchar_t *buff = (wchar_t *) malloc(sizeof(wchar_t) * (valueLength));
 1357    ThrowMessageIfFail(buff != NULL, "Out of memory!");
 1358 
 1359    std::wstring value;
 1360 
 1361    if (func(context, index, buff, &valueLength)) {
 1362       buff[valueLength] = 0;
 1363       value = buff;
 1364       free (buff);
 1365    } else {
 1366       free (buff);
 1367 
 1368       // always false
 1369       ThrowLastErrorIfFail(buff == NULL);
 1370    }
 1371 
 1372    return value;
 1373 }
 1374 //---------------------------------------------------------------------------
 1375 
 1376 void TLitePDF::SetSignatureCreator(unsigned int index,
 1377                                    const char *creator)
 1378 {
 1379    const char *_func = "TLitePDF::SetSignatureCreator";
 1380 
 1381    ensureLibraryLoaded(_func);
 1382 
 1383    ThrowIfFail(lib != NULL);
 1384 
 1385    InitFunc(BOOL, litePDF_SetSignatureCreator, (void *pctx, unsigned int index, const char *creator));
 1386 
 1387    ThrowLastErrorIfFail(func(context, index, creator));
 1388 }
 1389 //---------------------------------------------------------------------------
 1390 
 1391 std::string TLitePDF::GetSignatureCreator(unsigned int index)
 1392 {
 1393    const char *_func = "TLitePDF::GetSignatureCreator";
 1394 
 1395    ensureLibraryLoaded(_func);
 1396 
 1397    ThrowIfFail(lib != NULL);
 1398 
 1399    InitFunc(BOOL, litePDF_GetSignatureCreator, (void *pctx, unsigned int index, char *value, unsigned int *valueLength));
 1400 
 1401    unsigned int valueLength = 0;
 1402    ThrowLastErrorIfFail(func(context, index, NULL, &valueLength));
 1403 
 1404    valueLength++;
 1405 
 1406    char *buff = (char *) malloc(sizeof(char) * (valueLength));
 1407    ThrowMessageIfFail(buff != NULL, "Out of memory!");
 1408 
 1409    std::string value;
 1410 
 1411    if (func(context, index, buff, &valueLength)) {
 1412       buff[valueLength] = 0;
 1413       value = buff;
 1414       free (buff);
 1415    } else {
 1416       free (buff);
 1417 
 1418       // always false
 1419       ThrowLastErrorIfFail(buff == NULL);
 1420    }
 1421 
 1422    return value;
 1423 }
 1424 //---------------------------------------------------------------------------
 1425 
 1426 void TLitePDF::SetSignatureAppearance(unsigned int index,
 1427                                       TLitePDFAppearance appearanceType,
 1428                                       unsigned int resourceID,
 1429                                       int offsetX_u,
 1430                                       int offsetY_u)
 1431 {
 1432    const char *_func = "TLitePDF::SetSignatureAppearance";
 1433 
 1434    ensureLibraryLoaded(_func);
 1435 
 1436    ThrowIfFail(lib != NULL);
 1437 
 1438    InitFunc(BOOL, litePDF_SetSignatureAppearance, (void *pctx,
 1439                                                    unsigned int index,
 1440                                                    unsigned int appearanceType,
 1441                                                    unsigned int resourceID,
 1442                                                    int offsetX_u,
 1443                                                    int offsetY_u));
 1444 
 1445    unsigned int apType;
 1446 
 1447    if (appearanceType == LitePDFAppearance_Rollover) {
 1448       apType = 1;
 1449    } else if (appearanceType == LitePDFAppearance_Down) {
 1450       apType = 2;
 1451    } else { // LitePDFAppearance_Normal
 1452       apType = 0;
 1453    }
 1454 
 1455    ThrowLastErrorIfFail(func(context, index, apType, resourceID, offsetX_u, offsetY_u));
 1456 }
 1457 //---------------------------------------------------------------------------
 1458 
 1459 void TLitePDF::SetSignatureSize(unsigned int requestBytes)
 1460 {
 1461    const char *_func = "TLitePDF::SetSignatureSize";
 1462 
 1463    ensureLibraryLoaded(_func);
 1464 
 1465    ThrowIfFail(lib != NULL);
 1466 
 1467    InitFunc(BOOL, litePDF_SetSignatureSize, (void *pctx, unsigned int requestBytes));
 1468 
 1469    ThrowLastErrorIfFail(func(context, requestBytes));
 1470 }
 1471 //---------------------------------------------------------------------------
 1472 
 1473 void TLitePDF::AddSignerPFX(const BYTE *pfxData,
 1474                             unsigned int pfxDataLength,
 1475                             const char *pfxPassword)
 1476 {
 1477    const char *_func = "TLitePDF::AddSignerPFX";
 1478 
 1479    ensureLibraryLoaded(_func);
 1480 
 1481    ThrowIfFail(lib != NULL);
 1482 
 1483    InitFunc(BOOL, litePDF_AddSignerPFX, (void *pctx,
 1484                                          const BYTE *pfxData,
 1485                                          unsigned int pfxDataLength,
 1486                                          const char *pfxPassword));
 1487 
 1488    ThrowLastErrorIfFail(func(context, pfxData, pfxDataLength, pfxPassword));
 1489 }
 1490 //---------------------------------------------------------------------------
 1491 
 1492 void TLitePDF::AddSignerPEM(const BYTE *pemData,
 1493                             unsigned int pemDataLength,
 1494                             const BYTE *pkeyData,
 1495                             unsigned int pkeyDataLength,
 1496                             const char *pkeyPassword)
 1497 {
 1498    const char *_func = "TLitePDF::AddSignerPEM";
 1499 
 1500    ensureLibraryLoaded(_func);
 1501 
 1502    ThrowIfFail(lib != NULL);
 1503 
 1504    InitFunc(BOOL, litePDF_AddSignerPEM, (void *pctx,
 1505                                          const BYTE *pemData,
 1506                                          unsigned int pemDataLength,
 1507                                          const BYTE *pkeyData,
 1508                                          unsigned int pkeyDataLength,
 1509                                          const char *pkeyPassword));
 1510 
 1511    ThrowLastErrorIfFail(func(context, pemData, pemDataLength, pkeyData, pkeyDataLength, pkeyPassword));
 1512 }
 1513 //---------------------------------------------------------------------------
 1514 
 1515 void TLitePDF::SaveToFileWithSign(const char *fileName,
 1516                                   unsigned int signatureIndex)
 1517 {
 1518    const char *_func = "TLitePDF::SaveToFileWithSign";
 1519 
 1520    ensureLibraryLoaded(_func);
 1521 
 1522    ThrowIfFail(lib != NULL);
 1523    ThrowIfFail(fileName != NULL);
 1524 
 1525    InitFunc(BOOL, litePDF_SaveToFileWithSign, (void *pctx,
 1526                                                const char *fileName,
 1527                                                unsigned int signatureIndex));
 1528 
 1529    ThrowLastErrorIfFail(func(context, fileName, signatureIndex));
 1530 }
 1531 //---------------------------------------------------------------------------
 1532 
 1533 void TLitePDF::SaveToFileWithSignW(const wchar_t *fileName,
 1534                                    unsigned int signatureIndex)
 1535 {
 1536    const char *_func = "TLitePDF::SaveToFileWithSignW";
 1537 
 1538    ensureLibraryLoaded(_func);
 1539 
 1540    ThrowIfFail(lib != NULL);
 1541    ThrowIfFail(fileName != NULL);
 1542 
 1543    InitFunc(BOOL, litePDF_SaveToFileWithSignW, (void *pctx,
 1544                                                 const wchar_t *fileName,
 1545                                                 unsigned int signatureIndex));
 1546 
 1547    ThrowLastErrorIfFail(func(context, fileName, signatureIndex));
 1548 }
 1549 //---------------------------------------------------------------------------
 1550 
 1551 bool TLitePDF::SaveToDataWithSign(unsigned int signatureIndex,
 1552                                   BYTE *data,
 1553                                   unsigned int *dataLength)
 1554 {
 1555    const char *_func = "TLitePDF::SaveToDataWithSign";
 1556 
 1557    ensureLibraryLoaded(_func);
 1558 
 1559    ThrowIfFail(lib != NULL);
 1560    ThrowIfFail(dataLength != NULL);
 1561 
 1562    InitFunc(BOOL, litePDF_SaveToDataWithSign, (void *pctx,
 1563                                                unsigned int signatureIndex,
 1564                                                BYTE *data,
 1565                                                unsigned int *dataLength));
 1566 
 1567    BOOL succeeded = func(context, signatureIndex, data, dataLength);
 1568 
 1569    return succeeded ? true : false;
 1570 }
 1571 //---------------------------------------------------------------------------
 1572 
 1573 void TLitePDF::SaveToFileWithSignManual(const char *fileName,
 1574                                         unsigned int signatureIndex,
 1575                                         TLitePDFAppendSignatureDataFunc appendSignatureData,
 1576                                         void *append_user_data,
 1577                                         TLitePDFFinishSignatureFunc finishSignature,
 1578                                         void *finish_user_data)
 1579 {
 1580    const char *_func = "TLitePDF::SaveToFileWithSignManual";
 1581 
 1582    ensureLibraryLoaded(_func);
 1583 
 1584    ThrowIfFail(lib != NULL);
 1585    ThrowIfFail(fileName != NULL);
 1586    ThrowIfFail(appendSignatureData != NULL);
 1587    ThrowIfFail(finishSignature != NULL);
 1588 
 1589    InitFunc(BOOL, litePDF_SaveToFileWithSignManual, (void *pctx,
 1590                                                      const char *fileName,
 1591                                                      unsigned int signatureIndex,
 1592                                                      TLitePDFAppendSignatureDataFunc appendSignatureData,
 1593                                                      void *append_user_data,
 1594                                                      TLitePDFFinishSignatureFunc finishSignature,
 1595                                                      void *finish_user_data));
 1596 
 1597    ThrowLastErrorIfFail(func(context,
 1598       fileName,
 1599       signatureIndex,
 1600       appendSignatureData,
 1601       append_user_data,
 1602       finishSignature,
 1603       finish_user_data));
 1604 }
 1605 //---------------------------------------------------------------------------
 1606 
 1607 void TLitePDF::SaveToFileWithSignManualW(const wchar_t *fileName,
 1608                                          unsigned int signatureIndex,
 1609                                          TLitePDFAppendSignatureDataFunc appendSignatureData,
 1610                                          void *append_user_data,
 1611                                          TLitePDFFinishSignatureFunc finishSignature,
 1612                                          void *finish_user_data)
 1613 {
 1614    const char *_func = "TLitePDF::SaveToFileWithSignManualW";
 1615 
 1616    ensureLibraryLoaded(_func);
 1617 
 1618    ThrowIfFail(lib != NULL);
 1619    ThrowIfFail(fileName != NULL);
 1620    ThrowIfFail(appendSignatureData != NULL);
 1621    ThrowIfFail(finishSignature != NULL);
 1622 
 1623    InitFunc(BOOL, litePDF_SaveToFileWithSignManualW, (void *pctx,
 1624                                                       const wchar_t *fileName,
 1625                                                       unsigned int signatureIndex,
 1626                                                       TLitePDFAppendSignatureDataFunc appendSignatureData,
 1627                                                       void *append_user_data,
 1628                                                       TLitePDFFinishSignatureFunc finishSignature,
 1629                                                       void *finish_user_data));
 1630 
 1631    ThrowLastErrorIfFail(func(context,
 1632       fileName,
 1633       signatureIndex,
 1634       appendSignatureData,
 1635       append_user_data,
 1636       finishSignature,
 1637       finish_user_data));
 1638 }
 1639 //---------------------------------------------------------------------------
 1640 
 1641 bool TLitePDF::SaveToDataWithSignManual(unsigned int signatureIndex,
 1642                                         TLitePDFAppendSignatureDataFunc appendSignatureData,
 1643                                         void *append_user_data,
 1644                                         TLitePDFFinishSignatureFunc finishSignature,
 1645                                         void *finish_user_data,
 1646                                         BYTE *data,
 1647                                         unsigned int *dataLength)
 1648 {
 1649    const char *_func = "TLitePDF::SaveToDataWithSignManual";
 1650 
 1651    ensureLibraryLoaded(_func);
 1652 
 1653    ThrowIfFail(lib != NULL);
 1654    ThrowIfFail(appendSignatureData != NULL);
 1655    ThrowIfFail(finishSignature != NULL);
 1656    ThrowIfFail(dataLength != NULL);
 1657 
 1658    InitFunc(BOOL, litePDF_SaveToDataWithSignManual, (void *pctx,
 1659                                                      unsigned int signatureIndex,
 1660                                                      TLitePDFAppendSignatureDataFunc appendSignatureData,
 1661                                                      void *append_user_data,
 1662                                                      TLitePDFFinishSignatureFunc finishSignature,
 1663                                                      void *finish_user_data,
 1664                                                      BYTE *data,
 1665                                                      unsigned int *dataLength));
 1666 
 1667    BOOL succeeded = func(context,
 1668       signatureIndex,
 1669       appendSignatureData,
 1670       append_user_data,
 1671       finishSignature,
 1672       finish_user_data,
 1673       data,
 1674       dataLength);
 1675 
 1676    return succeeded ? true : false;
 1677 }
 1678 //---------------------------------------------------------------------------
 1679 
 1680 void TLitePDF::EmbedFile(const char *fileName)
 1681 {
 1682    const char *_func = "TLitePDF::EmbedFile";
 1683 
 1684    ensureLibraryLoaded(_func);
 1685 
 1686    ThrowIfFail(lib != NULL);
 1687    ThrowIfFail(fileName != NULL);
 1688 
 1689    InitFunc(BOOL, litePDF_EmbedFile, (void *pctx, const char *fileName));
 1690 
 1691    ThrowLastErrorIfFail(func(context, fileName));
 1692 }
 1693 //---------------------------------------------------------------------------
 1694 
 1695 void TLitePDF::EmbedFileW(const wchar_t *fileName)
 1696 {
 1697    const char *_func = "TLitePDF::EmbedFileW";
 1698 
 1699    ensureLibraryLoaded(_func);
 1700 
 1701    ThrowIfFail(lib != NULL);
 1702    ThrowIfFail(fileName != NULL);
 1703 
 1704    InitFunc(BOOL, litePDF_EmbedFileW, (void *pctx, const wchar_t *fileName));
 1705 
 1706    ThrowLastErrorIfFail(func(context, fileName));
 1707 }
 1708 //---------------------------------------------------------------------------
 1709 
 1710 void TLitePDF::EmbedData(const char *fileName,
 1711                          const BYTE *data,
 1712                          unsigned int dataLength)
 1713 {
 1714    const char *_func = "TLitePDF::EmbedData";
 1715 
 1716    ensureLibraryLoaded(_func);
 1717 
 1718    ThrowIfFail(lib != NULL);
 1719    ThrowIfFail(data != NULL);
 1720 
 1721    InitFunc(BOOL, litePDF_EmbedData, (void *pctx, const char *fileName, const BYTE *data, unsigned int dataLength));
 1722 
 1723    ThrowLastErrorIfFail(func(context, fileName, data, dataLength));
 1724 }
 1725 //---------------------------------------------------------------------------
 1726 
 1727 void TLitePDF::EmbedDataW(const wchar_t *fileName,
 1728                           const BYTE *data,
 1729                           unsigned int dataLength)
 1730 {
 1731    const char *_func = "TLitePDF::EmbedDataW";
 1732 
 1733    ensureLibraryLoaded(_func);
 1734 
 1735    ThrowIfFail(lib != NULL);
 1736    ThrowIfFail(data != NULL);
 1737 
 1738    InitFunc(BOOL, litePDF_EmbedDataW, (void *pctx, const wchar_t *fileName, const BYTE *data, unsigned int dataLength));
 1739 
 1740    ThrowLastErrorIfFail(func(context, fileName, data, dataLength));
 1741 }
 1742 //---------------------------------------------------------------------------
 1743 
 1744 int TLitePDF::GetEmbeddedFileCount(void)
 1745 {
 1746    const char *_func = "TLitePDF::GetEmbeddedFileCount";
 1747 
 1748    ensureLibraryLoaded(_func);
 1749 
 1750    ThrowIfFail(lib != NULL);
 1751 
 1752    InitFunc(INT, litePDF_GetEmbeddedFileCount, (void *pctx));
 1753 
 1754    return func(context);
 1755 }
 1756 //---------------------------------------------------------------------------
 1757 
 1758 std::string TLitePDF::GetEmbeddedFileName(unsigned int index)
 1759 {
 1760    const char *_func = "TLitePDF::GetEmbeddedFileName";
 1761 
 1762    ensureLibraryLoaded(_func);
 1763 
 1764    ThrowIfFail(lib != NULL);
 1765 
 1766    InitFunc(BOOL, litePDF_GetEmbeddedFileName, (void *pctx, unsigned int index, char *fileName, unsigned int *fileNameLength));
 1767 
 1768    unsigned int fileNameLength = 0;
 1769    ThrowLastErrorIfFail(func(context, index, NULL, &fileNameLength));
 1770 
 1771    fileNameLength++;
 1772 
 1773    char *buff = (char *) malloc(sizeof(char) * (fileNameLength));
 1774    ThrowMessageIfFail(buff != NULL, "Out of memory!");
 1775 
 1776    std::string fileName;
 1777 
 1778    if (func(context, index, buff, &fileNameLength)) {
 1779       buff[fileNameLength] = 0;
 1780       fileName = buff;
 1781       free (buff);
 1782    } else {
 1783       free (buff);
 1784 
 1785       // always false
 1786       ThrowLastErrorIfFail(buff == NULL);
 1787    }
 1788 
 1789    return fileName;
 1790 }
 1791 //---------------------------------------------------------------------------
 1792 
 1793 std::wstring TLitePDF::GetEmbeddedFileNameW(unsigned int index)
 1794 {
 1795    const char *_func = "TLitePDF::GetEmbeddedFileNameW";
 1796 
 1797    ensureLibraryLoaded(_func);
 1798 
 1799    ThrowIfFail(lib != NULL);
 1800 
 1801    InitFunc(BOOL, litePDF_GetEmbeddedFileNameW, (void *pctx, unsigned int index, wchar_t *fileName, unsigned int *fileNameLength));
 1802 
 1803    unsigned int fileNameLength = 0;
 1804    ThrowLastErrorIfFail(func(context, index, NULL, &fileNameLength));
 1805 
 1806    fileNameLength++;
 1807 
 1808    wchar_t *buff = (wchar_t *) malloc(sizeof(wchar_t) * (fileNameLength));
 1809    ThrowMessageIfFail(buff != NULL, "Out of memory!");
 1810 
 1811    std::wstring fileName;
 1812 
 1813    if (func(context, index, buff, &fileNameLength)) {
 1814       buff[fileNameLength] = 0;
 1815       fileName = buff;
 1816       free (buff);
 1817    } else {
 1818       free (buff);
 1819 
 1820       // always false
 1821       ThrowLastErrorIfFail(buff == NULL);
 1822    }
 1823 
 1824    return fileName;
 1825 }
 1826 //---------------------------------------------------------------------------
 1827 
 1828 bool TLitePDF::GetEmbeddedFileData(unsigned int index,
 1829                                    BYTE *data,
 1830                                    unsigned int *dataLength)
 1831 {
 1832    const char *_func = "TLitePDF::GetEmbeddedFileData";
 1833 
 1834    ensureLibraryLoaded(_func);
 1835 
 1836    ThrowIfFail(lib != NULL);
 1837    ThrowIfFail(dataLength != NULL);
 1838 
 1839    InitFunc(BOOL, litePDF_GetEmbeddedFileData, (void *pctx, unsigned int index, BYTE *data, unsigned int *dataLength));
 1840 
 1841    BOOL succeeded = func(context, index, data, dataLength);
 1842 
 1843    return succeeded ? true : false;
 1844 }
 1845 //---------------------------------------------------------------------------
 1846 
 1847 void *TLitePDF::GetPoDoFoDocument(void)
 1848 {
 1849    const char *_func = "TLitePDF::GetPoDoFoDocument";
 1850 
 1851    ensureLibraryLoaded(_func);
 1852 
 1853    ThrowIfFail(lib != NULL);
 1854 
 1855    InitFunc(void *, litePDF_GetPoDoFoDocument, (void *pctx));
 1856 
 1857    void *podofoDocument = func(context);
 1858 
 1859    ThrowLastErrorIfFail(podofoDocument != NULL);
 1860 
 1861    return podofoDocument;
 1862 }
 1863 //---------------------------------------------------------------------------
 1864 
 1865 void TLitePDF::DrawDebugPage(const char *filename)
 1866 {
 1867    const char *_func = "TLitePDF::DrawDebugPage";
 1868 
 1869    ensureLibraryLoaded(_func);
 1870 
 1871    ThrowIfFail(lib != NULL);
 1872    ThrowIfFail(filename != NULL);
 1873 
 1874    InitFunc(BOOL, litePDF_DrawDebugPage, (void *pctx, const char *filename));
 1875 
 1876    ThrowLastErrorIfFail(func(context, filename));
 1877 }
 1878 //---------------------------------------------------------------------------
 1879 
 1880 void TLitePDF::CreateLinkAnnotation(unsigned int annotationPageIndex,
 1881                                     int annotationX_u,
 1882                                     int annotationY_u,
 1883                                     int annotationWidth_u,
 1884                                     int annotationHeight_u,
 1885                                     unsigned int annotationFlags,
 1886                                     unsigned int annotationResourceID,
 1887                                     unsigned int destinationPageIndex,
 1888                                     unsigned int destinationX_u,
 1889                                     unsigned int destinationY_u,
 1890                                     const wchar_t *destinationDescription)
 1891 {
 1892    const char *_func = "TLitePDF::CreateLinkAnnotation";
 1893 
 1894    ensureLibraryLoaded(_func);
 1895 
 1896    ThrowIfFail(lib != NULL);
 1897 
 1898    InitFunc(BOOL, litePDF_CreateLinkAnnotation, (void *pctx,
 1899                                                  unsigned int annotationPageIndex,
 1900                                                  int annotationX_u,
 1901                                                  int annotationY_u,
 1902                                                  int annotationWidth_u,
 1903                                                  int annotationHeight_u,
 1904                                                  unsigned int annotationFlags,
 1905                                                  unsigned int annotationResourceID,
 1906                                                  unsigned int destinationPageIndex,
 1907                                                  unsigned int destinationX_u,
 1908                                                  unsigned int destinationY_u,
 1909                                                  const wchar_t *destinationDescription));
 1910 
 1911    ThrowLastErrorIfFail(func(context,
 1912                              annotationPageIndex,
 1913                              annotationX_u,
 1914                              annotationY_u,
 1915                              annotationWidth_u,
 1916                              annotationHeight_u,
 1917                              annotationFlags,
 1918                              annotationResourceID,
 1919                              destinationPageIndex,
 1920                              destinationX_u,
 1921                              destinationY_u,
 1922                              destinationDescription));
 1923 }
 1924 //---------------------------------------------------------------------------
 1925 
 1926 unsigned int TLitePDF::CreateBookmarkRoot(const wchar_t *title,
 1927                                           unsigned int flags,
 1928                                           COLORREF titleColor,
 1929                                           unsigned int destinationPageIndex,
 1930                                           unsigned int destinationX_u,
 1931                                           unsigned int destinationY_u)
 1932 {
 1933    const char *_func = "TLitePDF::CreateBookmarkRoot";
 1934 
 1935    ensureLibraryLoaded(_func);
 1936 
 1937    ThrowIfFail(lib != NULL);
 1938    ThrowIfFail(title != NULL);
 1939 
 1940    InitFunc(unsigned int, litePDF_CreateBookmarkRoot, (void *pctx,
 1941                                                        const wchar_t *title,
 1942                                                        unsigned int flags,
 1943                                                        unsigned char titleColor_red,
 1944                                                        unsigned char titleColor_green,
 1945                                                        unsigned char titleColor_blue,
 1946                                                        unsigned int destinationPageIndex,
 1947                                                        unsigned int destinationX_u,
 1948                                                        unsigned int destinationY_u));
 1949 
 1950    unsigned int resourceID = func(context,
 1951                                   title,
 1952                                   flags,
 1953                                   GetRValue(titleColor),
 1954                                   GetGValue(titleColor),
 1955                                   GetBValue(titleColor),
 1956                                   destinationPageIndex,
 1957                                   destinationX_u,
 1958                                   destinationY_u);
 1959    ThrowLastErrorIfFail(resourceID != 0);
 1960 
 1961    return resourceID;
 1962 }
 1963 //---------------------------------------------------------------------------
 1964 
 1965 unsigned int TLitePDF::CreateBookmarkChild(unsigned int parentBookmarkID,
 1966                                            const wchar_t *title,
 1967                                            unsigned int flags,
 1968                                            COLORREF titleColor,
 1969                                            unsigned int destinationPageIndex,
 1970                                            unsigned int destinationX_u,
 1971                                            unsigned int destinationY_u)
 1972 {
 1973    const char *_func = "TLitePDF::CreateBookmarkChild";
 1974 
 1975    ensureLibraryLoaded(_func);
 1976 
 1977    ThrowIfFail(lib != NULL);
 1978    ThrowIfFail(title != NULL);
 1979 
 1980    InitFunc(unsigned int, litePDF_CreateBookmarkChild, (void *pctx,
 1981                                                         unsigned int parentBookmarkID,
 1982                                                         const wchar_t *title,
 1983                                                         unsigned int flags,
 1984                                                         unsigned char titleColor_red,
 1985                                                         unsigned char titleColor_green,
 1986                                                         unsigned char titleColor_blue,
 1987                                                         unsigned int destinationPageIndex,
 1988                                                         unsigned int destinationX_u,
 1989                                                         unsigned int destinationY_u));
 1990 
 1991    unsigned int resourceID = func(context,
 1992                                   parentBookmarkID,
 1993                                   title,
 1994                                   flags,
 1995                                   GetRValue(titleColor),
 1996                                   GetGValue(titleColor),
 1997                                   GetBValue(titleColor),
 1998                                   destinationPageIndex,
 1999                                   destinationX_u,
 2000                                   destinationY_u);
 2001    ThrowLastErrorIfFail(resourceID != 0);
 2002 
 2003    return resourceID;
 2004 }
 2005 //---------------------------------------------------------------------------
 2006 
 2007 unsigned int TLitePDF::CreateBookmarkSibling(unsigned int previousBookmarkID,
 2008                                              const wchar_t *title,
 2009                                              unsigned int flags,
 2010                                              COLORREF titleColor,
 2011                                              unsigned int destinationPageIndex,
 2012                                              unsigned int destinationX_u,
 2013                                              unsigned int destinationY_u)
 2014 {
 2015    const char *_func = "TLitePDF::CreateBookmarkSibling";
 2016 
 2017    ensureLibraryLoaded(_func);
 2018 
 2019    ThrowIfFail(lib != NULL);
 2020    ThrowIfFail(title != NULL);
 2021 
 2022    InitFunc(unsigned int, litePDF_CreateBookmarkSibling, (void *pctx,
 2023                                                           unsigned int previousBookmarkID,
 2024                                                           const wchar_t *title,
 2025                                                           unsigned int flags,
 2026                                                           unsigned char titleColor_red,
 2027                                                           unsigned char titleColor_green,
 2028                                                           unsigned char titleColor_blue,
 2029                                                           unsigned int destinationPageIndex,
 2030                                                           unsigned int destinationX_u,
 2031                                                           unsigned int destinationY_u));
 2032 
 2033    unsigned int resourceID = func(context,
 2034                                   previousBookmarkID,
 2035                                   title,
 2036                                   flags,
 2037                                   GetRValue(titleColor),
 2038                                   GetGValue(titleColor),
 2039                                   GetBValue(titleColor),
 2040                                   destinationPageIndex,
 2041                                   destinationX_u,
 2042                                   destinationY_u);
 2043    ThrowLastErrorIfFail(resourceID != 0);
 2044 
 2045    return resourceID;
 2046 }
 2047 //---------------------------------------------------------------------------
 2048 
 2049 #undef ThrowIfFail
 2050 #undef ThrowMessageIfFail
 2051 #undef ThrowLastErrorIfFail
 2052 
 2053 }; //namespace litePDF
TOPlist