ppInt32 CosArrayInsert( PDFCosHandle CosObject, PDFCosHandle NewCosObject, ppUns32 Position ) { if ( !_IsCosArray( CosObject ) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( _CosDoc ( NewCosObject ) != _DOC ) _RAISE ( ErrCosLevel, cleCannotInsertObjectFromOtherDocumentError ); if ( !_CosIsIndirect ( NewCosObject) && _CosParent ( NewCosObject ) ) _RAISE ( ErrCosLevel, cleCannotInsertObjectWithParrentError ); if ( Position >= _CosArrayCount ( CosObject ) ) return CosArrayAppend ( CosObject, NewCosObject ); if ( _CosArrayCount ( CosObject ) == _CosArrayCapacity ( CosObject ) ){ _CosArrayCapacity ( CosObject ) += CalculateDelta ( _CosArrayCapacity ( CosObject ) ); _CosArrayArray ( CosObject ) = ( PDFCosHandle * ) mrealloc ( _LIB, _CosArrayArray ( CosObject ), _CosArrayCapacity ( CosObject ) * sizeof ( PDFCosHandle ) ); }; memmove ( &( _CosArrayItem ( CosObject, Position + 1 ) ), &( _CosArrayItem ( CosObject, Position ) ), ( _CosArrayCount ( CosObject ) - Position ) * sizeof ( PDFCosHandle ) ); if ( _CosIsIndirect ( NewCosObject ) ) NewCosObject = CosNewRef ( _CosDoc( NewCosObject ), _CosObjID ( NewCosObject), _CosObjGeneration ( NewCosObject ) ); _CosArrayItem ( CosObject, Position ) = NewCosObject; _CosArrayCount ( CosObject )++; if ( !_IsCosNull ( NewCosObject ) ) _CosParent ( NewCosObject ) = CO ( CosObject ); return Position; }
TPDFPageRotateAngle PDFPageGetRotateAngle(PDFDocHandle Doc, ppUns32 Page) { PDFCosHandle PO, inh, R; ppInt32 i; if ( !_DOC->Pages ) PDFDocLoadPages ( Doc ); if ( Page >= _DOC->Pages->Size ) _RAISE ( ErrGeneralLevel, gleOutOfBoundError ); PO = ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->PO; if ( _CosGetType ( PO ) != CosDict ) _RAISE ( ErrCosLevel, cleIllegalCosObjectWasFoundError ); inh = ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->Inh; if (_IsCosDict (inh)){ R = _CosDictValueByName ( inh, Rotate ); if ( _CosGetType ( R ) == CosInteger ){ i = _CosIntValue ( R ); if ( i > 360 ) i = i % 360; i = i / 90; return ( TPDFPageRotateAngle ) i; } } R = _CosDictValueByName ( PO, Rotate ); if ( _IsCosInt ( R ) ){ i = _CosIntValue ( R ); if ( i > 360 ) i = i % 360; i = i / 90; return ( TPDFPageRotateAngle ) i; } else return pra0; }
void CosDictGetPair(PDFCosHandle CosObject, ppUns32 Index, ppAtom *Key, PDFCosHandle *Value){ if ( !_IsCosDictOrStream ( CosObject ) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( _IsCosStream ( CosObject ) ) CosObject = _CosStreamAttr ( CosObject ); if ( Index >= _CosDictCount ( CosObject ) ) _RAISE ( ErrCosLevel, cleArrayBoundsError); *Key = _CosDictKey ( CosObject, Index ); *Value = _CosDictValue ( CosObject, Index ); }
char * CosStringGetValue( PDFCosHandle CosObject, ppUns32 *Length ) { if ( !_IsCosString ( CosObject ) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); *Length = _CosStringSize ( CosObject ); return _CosStringValue ( CosObject ); }
SSRecord::SSRecord (SSFileImpPtr filePtr, long offset) : m_FileImpPtr (filePtr), m_Offset(offset), m_pBuffer(NULL), m_Len (0) { int fileLength = m_FileImpPtr->Size (); if (!m_FileImpPtr->Read (offset, &m_Header, sizeof(m_Header))) throw SSException ("could not read record header"); // OPTIMIZE: We do not nead to read all the record payload in advance (esp. for FD records) if (m_Header.size > 0) { if (offset + sizeof(m_Header) + m_Header.size > fileLength) throw SSRecordException ("bad header: length variable exceeds file size"); m_pBuffer = new byte[m_Header.size]; if (!m_FileImpPtr->Read (/*offset + sizeof(m_Header), */ m_pBuffer, m_Header.size)) throw SSException ("could not read record data"); short crc = calc_crc16 (m_pBuffer, m_Header.size); if (m_Header.checksum != (short)crc && m_Header.checksum != 0) { SSRecordException ex("wrong checksum"); Warning (ex.what()); _RAISE (ex); } } m_Len = m_Header.size; }
TKeyValidType PDFDocCheckPassword(PDFDocHandle Doc, char *Password){ TPDFCheckPasword RV; if (!_DOC->Crypted) return kvtOwner; if (_DOC->UnCrypted) _RAISE(ErrFileLevel,fleUncryptedFileError); RV = ULCheckPassword ( & ( _DOC->CryptoInfo ), Password, ( ppInt32 ) strlen ( Password ) ); if (RV == cpCorrupted) PDFRAISE(_LIB,PDFBuildErrCode(ErrFileLevel,fleCorruptedFileError)); if ( RV != cpInvalid ){ _DOC->UnCrypted = true; _DOC->Root=CosGetFromDoc(Doc,_DOC->RootID.ID); if (!_IsCosDict(_DOC->Root)) PDFRAISE(_LIB,PDFBuildErrCode(ErrFileLevel,fleCorruptedTrailerError)); if (_DOC->InfoID.ID) { _DOC->Info=CosGetFromDoc(Doc,_DOC->InfoID.ID); if (!_IsCosDict(_DOC->Info)) _DOC->Info=_CosNull ( Doc ); } } switch (RV){ case cpValidOwner: return kvtOwner; case cpValidUser: return kvtUser; default: return kvtInvalid; } }
_STD_BEGIN _CRTIMP void __cdecl _Nomemory() { // report out of memory static const _XSTD bad_alloc nomem; _RAISE(nomem); }
void PDFPageSetBox(PDFDocHandle Doc, ppUns32 Page, TPDFPageBoxType Type, TPDFRect rect) { PDFCosHandle PO, w; ppReal AllMax, UU; if ( !_DOC->Pages ) PDFDocLoadPages ( Doc ); if (Page >= _DOC->Pages->Size ) _RAISE ( ErrGeneralLevel, gleOutOfBoundError ); AllMax = max(rect.xl,rect.yl); AllMax = max(AllMax, rect.xr); AllMax = max(AllMax, rect.yr); AllMax = _abs(AllMax); if (AllMax > 72*200){ UU = floor( AllMax / (72*200))+1; } else { UU = 1.0; } PO = ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->PO; if (UU == 1.0){ _CosDictRemoveKey(PO, UserUnit); } else { _CosDictAppend(PO, UserUnit, CosRealNew(Doc, false, UU)); } w = CosArrayNew ( Doc, false, 4 ); PDFTRY ( _LIB ){ CosArrayAppend ( w, CosRealNew ( Doc, false, rect.xl / UU ) ); CosArrayAppend ( w, CosRealNew ( Doc, false, rect.yl / UU ) ); CosArrayAppend ( w, CosRealNew ( Doc, false, rect.xr / UU ) ); CosArrayAppend ( w, CosRealNew ( Doc, false, rect.yr / UU ) ); } PDFEXCEPT ( _LIB ){ CosFree ( w ); PDFRERAISE ( _LIB ); }PDFTRYEND ( _LIB ); switch ( Type ){ case pbnMediaBox: if ( _IsCosDict ( ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->Inh ) ) _CosDictRemoveKey ( ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->Inh, MediaBox ); _CosDictAppend ( PO, MediaBox, w ); break; case pbnCropBox: if ( _IsCosDict ( ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->Inh ) ) _CosDictRemoveKey ( ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->Inh, CropBox ); _CosDictAppend ( PO, CropBox, w ); break; case pbnBleedBox: _CosDictAppend ( PO, BleedBox, w ); break; case pbnTrimBox: _CosDictAppend ( PO, TrimBox, w ); break; case pbnArtBox: _CosDictAppend ( PO, ArtBox, w ); break; default: ; } }
ppUns32 PDFPageAddContent(PDFDocHandle Doc, ppUns32 Page) { PDFCosHandle PO, cont, nc, ad, ar; if ( !_DOC->Pages ) PDFDocLoadPages ( Doc ); if ( Page >= _DOC->Pages->Size ) _RAISE ( ErrGeneralLevel, gleOutOfBoundError ); PO = ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->PO; nc = CosStreamNew ( Doc, true, 1 ); _CosDictAppend ( nc, Length, CosIntNew ( Doc, false, 0 ) ); cont = _CosDictValueByName ( PO, Contents ); if ( _CosGetType ( cont ) == CosNull ){ _CosDictAppend ( PO, Contents, nc ); return 0; }; if ( _CosGetType ( cont ) == CosStream ){ ad = _CosDictValueByNameNRF ( PO, Contents ); ar = CosArrayNew ( Doc, false, 2 ); PDFTRY ( _LIB ){ CosArrayAppend ( ar, CosCopy ( Doc, ad ) ); CosArrayAppend ( ar, nc ); } PDFEXCEPT ( _LIB ){ CosFree ( ar ); PDFRERAISE ( _LIB ); } PDFTRYEND ( _LIB ); _CosDictAppend ( PO, Contents, ar ); return 1; };
void PDFDocSetSecurity(PDFDocHandle Doc, ppInt32 Permission, TPDFProtectionType KeyLength, char *UserPassword, char *OwnerPassword){ ppInt32 i; if (!_DOC->UnCrypted) _RAISE(ErrFileLevel,fleCryptedFileError); if (KeyLength >= pt128BitAESProtection) CheckEdition(_LIB, STD); _DOC->UseOldSecurity=false; if (!(_DOC->OPassword)) mfree(_LIB, _DOC->OPassword); if (!(_DOC->UPassword)) mfree(_LIB, _DOC->UPassword); _DOC->OPassword=NULL; _DOC->UPassword=NULL; _DOC->NewCrypted=true; _DOC->NewPermission=Permission; _DOC->nkl=KeyLength; /*if ( KeyLength > pt128BitProtection ) _DOC->nkl= pt128BitProtection;*/ if (OwnerPassword){ i=(ppInt32)strlen(OwnerPassword)+1; _DOC->OPassword= (char *) mmalloc(_LIB,i); memcpy(_DOC->OPassword,OwnerPassword,i); }; if (UserPassword){ i=(ppInt32)strlen(UserPassword)+1; _DOC->UPassword= (char *) mmalloc(_LIB,i); memcpy(_DOC->UPassword,UserPassword,i); }; }
PDFCosHandle PDFPageGetCosObject(PDFDocHandle Doc, ppUns32 Page) { if ( !_DOC->Pages ) PDFDocLoadPages ( Doc ); if ( Page >= _DOC->Pages->Size ) _RAISE ( ErrGeneralLevel, gleOutOfBoundError ); return ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->PO; }
ppInt32 CosDictCount( PDFCosHandle CosObject ) { if ( !_IsCosDictOrStream ( CosObject ) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( _CosGetType ( CosObject ) == CosStream ) CosObject = _CosStreamAttr ( CosObject ); return _CosDictCount ( CosObject ); }
PDFCosHandle CosArrayItemNRF( PDFCosHandle CosObject, ppUns32 Index ) { if ( !_IsCosArray ( CosObject ) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( Index >= _CosArrayCount ( CosObject ) ) return CosNullNew ( _DOC ); return _CosArrayItem( CosObject, Index ); }
ppReal CosNumberGetValue( PDFCosHandle CosObject ) { if ( !_IsCosNumber(CosObject) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( _IsCosInt ( CosObject ) ) return ULIntToReal ( _CosIntValue( CosObject ) ); else return _CosRealValue ( CosObject ); }
ppUns32 PDFPageGetContentCount(PDFDocHandle Doc, ppUns32 Page) { PDFCosHandle PO, cont; if ( !_DOC->Pages ) PDFDocLoadPages ( Doc ); if ( Page >= _DOC->Pages->Size ) _RAISE ( ErrGeneralLevel, gleOutOfBoundError ); PO = ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->PO; cont = _CosDictValueByName ( PO, Contents ); if ( _CosGetType ( cont ) == CosNull ) return 0; else if ( _CosGetType ( cont ) == CosStream ) return 1; else if ( _CosGetType ( cont ) == CosArray ) return _CosArrayCount ( cont ); else _RAISE ( ErrCosLevel, cleIllegalCosObjectWasFoundError ); return 0; }
void CosDictAppend(PDFCosHandle CosObject, ppAtom Key, PDFCosHandle KeyValue ) { ppUns32 i; if ( !_IsCosDictOrStream (CosObject) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( _CosDoc ( KeyValue ) != _DOC ) _RAISE ( ErrCosLevel, cleCannotInsertObjectFromOtherDocumentError ); if ( !_CosIsIndirect ( KeyValue) && _CosParent ( KeyValue ) ) _RAISE ( ErrCosLevel, cleCannotInsertObjectWithParrentError ); if ( _IsCosNull ( KeyValue ) ){ CosDictRemoveKey ( CosObject, Key ); return; } if ( _IsCosStream ( CosObject ) ) CosObject = _CosStreamAttr (CosObject ); /* Check on exists key */ for ( i = 0; i < _CosDictCount ( CosObject ); i++ ) if ( _CosDictKey ( CosObject, i) == Key ){ CosFree( _CosDictValue ( CosObject, i) ); if ( _CosIsIndirect ( KeyValue ) ) KeyValue = CosNewRef ( _CosDoc( KeyValue ), _CosObjID ( KeyValue), _CosObjGeneration ( KeyValue ) ); _CosDictValue ( CosObject, i) = KeyValue; _CosParent ( KeyValue ) = CO ( CosObject ); return; }; if ( _CosDictCount ( CosObject ) == _CosDictCapacity (CosObject) ){ _CosDictCapacity ( CosObject ) += CalculateDelta ( _CosDictCapacity ( CosObject) ); _CosDictArray ( CosObject ) = ( DictElem * ) mrealloc ( _LIB, _CosDictArray ( CosObject ), _CosDictCapacity ( CosObject) * sizeof ( DictElem ) ); } i = _CosDictCount ( CosObject ); _CosDictKey ( CosObject, i) = Key; if ( _CosIsIndirect ( KeyValue ) ) KeyValue = CosNewRef ( _CosDoc( KeyValue ), _CosObjID ( KeyValue), _CosObjGeneration ( KeyValue ) ); _CosDictValue ( CosObject, i) = KeyValue; _CosParent ( KeyValue ) = CO ( CosObject ); _CosDictCount ( CosObject )++; }
void CosStringSetValue( PDFCosHandle CosObject, char *String, ppUns32 Length ) { char *t; if ( ! _IsCosString ( CosObject ) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); t = ( char * ) mmalloc ( _LIB, Length ); memcpy ( t, String, Length ); mfree ( _LIB, _CosStringValue( CosObject ) ); _CosStringValue ( CosObject ) = t; _CosStringSize ( CosObject ) = Length; }
void CosArrayClear( PDFCosHandle CosObject ) { ppUns32 i; if ( !_IsCosArray ( CosObject ) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); for ( i = 0; i < _CosArrayCount ( CosObject ) ; i++ ) CosFree ( _CosArrayItem( CosObject, i ) ); mfree ( _LIB, _CosArrayArray ( CosObject ) ); _CosArrayCapacity ( CosObject ) = 0; _CosArrayArray ( CosObject ) = NULL; _CosArrayCount ( CosObject ) = 0; }
void CosArrayRemove( PDFCosHandle CosObject, ppUns32 Index ) { if ( !_IsCosArray ( CosObject ) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( Index >= _CosArrayCount (CosObject ) ) return; CosFree ( _CosArrayItem( CosObject, Index ) ); memmove ( &( _CosArrayItem( CosObject, Index ) ), &( _CosArrayItem( CosObject, Index + 1 ) ), ( _CosArrayCount (CosObject ) - Index - 1 ) * sizeof ( PDFCosHandle ) ); _CosArrayCount (CosObject )--; }
void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc) { // try to allocate size bytes void *p; while ((p = malloc(size)) == 0) if (_callnewh(size) == 0) { // report no memory static const std::bad_alloc nomem; _RAISE(nomem); } return (p); }
void PDFPageSetRotateAngle(PDFDocHandle Doc, ppUns32 Page, TPDFPageRotateAngle Rotate) { PDFCosHandle PO; ppInt32 i; if ( !_DOC->Pages ) PDFDocLoadPages ( Doc ); if ( Page >= _DOC->Pages->Size ) _RAISE ( ErrGeneralLevel, gleOutOfBoundError ); PO = ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->PO; i = Rotate * 90; _CosDictAppend ( PO, Rotate, CosIntNew ( Doc, false, i ) ); }
PDFCosHandle CosDictValueByNameNRF( PDFCosHandle CosObject, ppAtom Key ) { ppUns32 i; if ( !_IsCosDictOrStream (CosObject) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( _IsCosStream ( CosObject ) ) CosObject = _CosStreamAttr (CosObject ); for ( i = 0; i < _CosDictCount ( CosObject ); i++ ) if ( _CosDictKey ( CosObject, i) == Key ) return _CosDictValue ( CosObject, i); return CosNullNew ( _DOC ); }
PDFCosHandle CosArrayItem( PDFCosHandle CosObject, ppUns32 Index ) { PDFCosHandle obj; PDFID ID; if ( !_IsCosArray ( CosObject ) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( Index >= _CosArrayCount ( CosObject ) ) return CosNullNew ( _DOC ); obj = _CosArrayItem( CosObject, Index ); if ( !_IsCosRef ( obj ) ) return obj; ID = _CosRefValue (obj ); return CosGetFromDoc ( _DOC, ID.ID); }
void PDFPageSetTumbnail( PDFDocHandle Doc, ppUns32 Page, ppUns32 Image ) { PDFCosHandle PO; PPDFDocImageEntry Img; if ( !_DOC->Pages ) PDFDocLoadPages ( Doc ); if ( Page >= _DOC->Pages->Size ) _RAISE ( ErrGeneralLevel, gleOutOfBoundError ); if ( !_DOC->ImageList || Image >= _DOC->ImageList->Size ) PDFRAISE ( _LIB, PDFBuildErrCode ( ErrGeneralLevel, gleOutOfBoundError ) ); PO = ( ( PPDFPageInfo ) _DOC->Pages->FList[Page] )->PO; Img = ( PPDFDocImageEntry ) _DOC->ImageList->FList[Image]; _CosDictAppend( PO, Thumb, Img->Obj); }
void CosDictClear( PDFCosHandle CosObject ) { ppUns32 i; if ( !_IsCosDictOrStream (CosObject) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( _IsCosStream ( CosObject ) ) CosObject = _CosStreamAttr (CosObject ); for ( i = 0; i < _CosDictCount ( CosObject ); i++ ) CosFree ( _CosDictValue ( CosObject, i) ); _CosDictCount ( CosObject ) = 0; _CosDictCapacity ( CosObject ) = 0; chfreez ( _LIB, _CosDictArray ( CosObject ) ); _CosDictArray ( CosObject ) = NULL; }
void CosDictRemoveKey(PDFCosHandle CosObject, ppAtom Key ) { ppUns32 i; if ( !_IsCosDictOrStream (CosObject) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( _IsCosStream ( CosObject ) ) CosObject = _CosStreamAttr (CosObject ); for ( i = 0; i < _CosDictCount ( CosObject ); i++ ) if ( _CosDictKey ( CosObject, i) == Key ){ CosFree ( _CosDictValue ( CosObject, i) ); memmove ( &( _CosDictPair ( CosObject, i ) ), &( _CosDictPair ( CosObject, i + 1 ) ), ( _CosDictCount ( CosObject ) - i - 1 ) * sizeof ( DictElem ) ); _CosDictCount ( CosObject )--; return ; }; }
PDFCosHandle CosDictValueByName( PDFCosHandle CosObject, ppAtom Key ) { ppUns32 i; PDFCosHandle obj; PDFID ID; if ( !_IsCosDictOrStream (CosObject) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); if ( _IsCosStream ( CosObject ) ) CosObject = _CosStreamAttr (CosObject ); for ( i = 0; i < _CosDictCount ( CosObject ); i++ ){ if ( _CosDictKey ( CosObject, i) == Key ){ obj = _CosDictValue ( CosObject, i); if ( !_IsCosRef ( obj ) ) return obj; ID = _CosRefValue( obj ); return CosGetFromDoc ( _DOC, ID.ID); } } return CosNullNew ( _DOC ); }
void CosStreamCheckFilters( PDFCosHandle CosObject ) { PDFCosHandle attr, fl; if ( !_IsCosStream ( CosObject) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); attr = _CosStreamAttr( CosObject ); fl = CosDictValueByName ( attr, GetAtomDoc ( Filter ) ); if ( _IsCosNull (fl) ) fl = CosDictValueByName ( attr, GetAtomDoc ( F ) ); if ( _IsCosArray ( fl ) ){ if (_CosArrayCount ( fl ) ) _CosStreamIsFiltered(CosObject) = true; else _CosStreamIsFiltered(CosObject) = false; return; } if ( _CosGetType ( fl ) == CosName ){ _CosStreamIsFiltered(CosObject) = true; return; } _CosStreamIsFiltered(CosObject) = false; }
PDFCosHandle CosDictToStream( PDFCosHandle CosObject ) { CosObj obj; PDFCosHandle tmp; if ( !_IsCosDict ( CosObject) ) _RAISE ( ErrCosLevel, cleInvalidObjError ); obj = ( CosObj ) mmalloc ( _LIB, sizeof ( TCosObj ) ); obj->Type = CosStream; obj->Doc = _DOC; obj->Data.smv.Filtered = false; obj->Data.smv.Attr = CosObject; obj->IsIndirect = false; obj->ObjInfo.Parent = NULL; SetCO(tmp,obj); PDFTRY ( _LIB ){ obj->Data.smv.Store = ULStreamMemNew ( _LIB, 0 ); } PDFEXCEPT ( _LIB ){ mfree ( _LIB, obj ); PDFRERAISE ( _LIB ); } PDFTRYEND ( _LIB ); return tmp; }
// throw an xlogic void xlogic :: do_raise (void) { _RAISE(*this); }