本文整理汇总了C++中PdfArray类的典型用法代码示例。如果您正苦于以下问题:C++ PdfArray类的具体用法?C++ PdfArray怎么用?C++ PdfArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PdfArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetColor
void PdfAnnotation::SetColor( double r, double g, double b ) {
PdfArray c;
c.push_back( PdfVariant( r ) );
c.push_back( PdfVariant( g ) );
c.push_back( PdfVariant( b ) );
m_pObject->GetDictionary().AddKey( "C", c );
}
示例2: GetWidthArray
void PdfFontMetricsFreetype::GetWidthArray( PdfVariant & var, unsigned int nFirst, unsigned int nLast ) const
{
unsigned int i;
PdfArray list;
if( !m_pFace )
{
PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
}
for( i=nFirst;i<=nLast;i++ )
{
if( i < PODOFO_WIDTH_CACHE_SIZE )
list.push_back( PdfVariant( m_vecWidth[i] ) );
else
{
if( !FT_Load_Char( m_pFace, i, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP ) ) // | FT_LOAD_NO_RENDER
{
//PODOFO_RAISE_ERROR( ePdfError_FreeType );
list.push_back( PdfVariant( 0.0 ) );
continue;
}
list.push_back( PdfVariant( m_pFace->glyph->metrics.horiAdvance * 1000.0 / m_pFace->units_per_EM ) );
}
}
var = PdfVariant( list );
}
示例3: CreateTestTreeCustom
void PagesTreeTest::CreateTestTreeCustom( PoDoFo::PdfMemDocument & rDoc )
{
const int COUNT = PODOFO_TEST_NUM_PAGES / 10;
PdfObject* pRoot = rDoc.GetPagesTree()->GetObject();
PdfArray rootKids;
for(int z=0; z<COUNT; z++)
{
PdfObject* pNode = rDoc.GetObjects().CreateObject("Pages");
PdfArray nodeKids;
for(int i=0; i<COUNT; i++)
{
PdfPage* pPage = new PdfPage( PdfPage::CreateStandardPageSize( ePdfPageSize_A4 ),
&(rDoc.GetObjects()) );
pPage->GetObject()->GetDictionary().AddKey( PODOFO_TEST_PAGE_KEY,
static_cast<long long>(z * COUNT + i) );
//printf("Creating page %i z=%i i=%i\n", z * COUNT + i, z, i );
nodeKids.push_back( pPage->GetObject()->Reference() );
}
pNode->GetDictionary().AddKey( PdfName("Kids"), nodeKids );
pNode->GetDictionary().AddKey( PdfName("Count"), static_cast<long long>(COUNT) );
rootKids.push_back( pNode->Reference() );
}
pRoot->GetDictionary().AddKey( PdfName("Kids"), rootKids );
pRoot->GetDictionary().AddKey( PdfName("Count"), static_cast<long long>(PODOFO_TEST_NUM_PAGES) );
}
示例4: PODOFO_RAISE_ERROR
void PdfSignOutputDevice::AdjustByteRange()
{
if(!m_bBeaconFound) {
PODOFO_RAISE_ERROR( ePdfError_InternalLogic );
}
// Get final position
size_t sFileEnd = GetLength();
PdfArray arr;
arr.push_back( PdfVariant(static_cast<pdf_int64>(0)) );
arr.push_back( PdfVariant(static_cast<pdf_int64>(m_sBeaconPos)) );
arr.push_back( PdfVariant(static_cast<pdf_int64>(m_sBeaconPos+m_pSignatureBeacon->data().size()+2) ) );
arr.push_back( PdfVariant(static_cast<pdf_int64>(sFileEnd-(m_sBeaconPos+m_pSignatureBeacon->data().size()+2)) ) );
std::string sPosition;
PdfVariant(arr).ToString(sPosition, ePdfWriteMode_Compact);
// Fill padding
unsigned int sPosSize = sizeof("[ 0 1234567890 1234567890 1234567890]")-1;
if(sPosition.size()<sPosSize)
{
// drop last ']'
sPosition.resize(sPosition.size()-1);
while(sPosition.size()<(sPosSize-1)) {
sPosition+=' ';
}
sPosition+=']';
}
m_pRealDevice->Seek(m_sBeaconPos-sPosition.size()-9);
m_pRealDevice->Write(sPosition.c_str(), sPosition.size());
}
示例5: PODOFO_RAISE_ERROR
void PdfPagesTree::InsertPagesIntoNode( PdfObject* pParent, const PdfObjectList & rlstParents,
int nIndex, const std::vector<PdfObject*>& vecPages )
{
if( !pParent || !vecPages.size() )
{
PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
}
// 1. Add the reference of the new page to the kids array of pParent
// 2. Increase count of every node in lstParents (which also includes pParent)
// 3. Add Parent key to the page
// 1. Add reference
const PdfArray oldKids = pParent->GetDictionary().GetKey( PdfName("Kids") )->GetArray();
PdfArray newKids;
newKids.reserve( oldKids.GetSize() + vecPages.size() );
bool bIsPushedIn = false;
int i=0;
for (PdfArray::const_iterator it=oldKids.begin(); it!=oldKids.end(); ++it, ++i )
{
if ( !bIsPushedIn && (nIndex < i) ) // Pushing before
{
for (std::vector<PdfObject*>::const_iterator itPages=vecPages.begin(); itPages!=vecPages.end(); ++itPages)
{
newKids.push_back( (*itPages)->Reference() ); // Push all new kids at once
}
bIsPushedIn = true;
}
newKids.push_back( *it ); // Push in the old kids
}
// If new kids are still not pushed in then they may be appending to the end
if ( !bIsPushedIn && ( (nIndex + 1) == static_cast<int>(oldKids.size())) )
{
for (std::vector<PdfObject*>::const_iterator itPages=vecPages.begin(); itPages!=vecPages.end(); ++itPages)
{
newKids.push_back( (*itPages)->Reference() ); // Push all new kids at once
}
bIsPushedIn = true;
}
pParent->GetDictionary().AddKey( PdfName("Kids"), newKids );
// 2. increase count
for ( PdfObjectList::const_reverse_iterator itParents = rlstParents.rbegin(); itParents != rlstParents.rend(); ++itParents )
{
this->ChangePagesCount( *itParents, vecPages.size() );
}
// 3. add parent key to each of the pages
for (std::vector<PdfObject*>::const_iterator itPages=vecPages.begin(); itPages!=vecPages.end(); ++itPages)
{
(*itPages)->GetDictionary().AddKey( PdfName("Parent"), pParent->Reference() );
}
}
示例6: SetTextColor
void PdfOutlineItem::SetTextColor( double r, double g, double b )
{
PdfArray color;
color.push_back( r );
color.push_back( g );
color.push_back( b );
m_pObject->GetDictionary().AddKey( "C", color );
}
示例7: GetBoundingBox
void PdfFontMetricsFreetype::GetBoundingBox( PdfArray & array ) const
{
if( !m_pFace )
{
PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
}
array.Clear();
array.push_back( PdfVariant( m_pFace->bbox.xMin * 1000.0 / m_pFace->units_per_EM ) );
array.push_back( PdfVariant( m_pFace->bbox.yMin * 1000.0 / m_pFace->units_per_EM ) );
array.push_back( PdfVariant( m_pFace->bbox.xMax * 1000.0 / m_pFace->units_per_EM ) );
array.push_back( PdfVariant( m_pFace->bbox.yMax * 1000.0 / m_pFace->units_per_EM ) );
}
示例8: SetBorderStyle
void PdfAnnotation::SetBorderStyle( double dHCorner, double dVCorner, double dWidth, const PdfArray & rStrokeStyle )
{
// TODO : Support for Border style for PDF Vers > 1.0
PdfArray aValues;
aValues.push_back(dHCorner);
aValues.push_back(dVCorner);
aValues.push_back(dWidth);
if( rStrokeStyle.size() )
aValues.push_back(rStrokeStyle);
m_pObject->GetDictionary().AddKey( "Border", aValues );
}
示例9: Init
void PdfStitchingFunction::Init( const PdfFunction::List & rlstFunctions, const PdfArray & rBounds, const PdfArray & rEncode )
{
PdfArray functions;
PdfFunction::List::const_iterator it = rlstFunctions.begin();
functions.reserve( rlstFunctions.size() );
while( it != rlstFunctions.end() )
{
functions.push_back( (*it).GetObject()->Reference() );
++it;
}
this->GetObject()->GetDictionary().AddKey( PdfName("Functions"), functions );
this->GetObject()->GetDictionary().AddKey( PdfName("Bounds"), rBounds );
this->GetObject()->GetDictionary().AddKey( PdfName("Encode"), rEncode );
}
示例10: PdfElement
PdfXObject::PdfXObject( const PdfMemDocument & rDoc, int nPage, PdfDocument* pParent )
: PdfElement( "XObject", pParent ), PdfCanvas()
{
m_rRect = PdfRect();
InitXObject( m_rRect, "XObInd" );
// Implementation note: source document must be different from distination
if ( pParent == reinterpret_cast<const PdfDocument*>(&rDoc) )
{
PODOFO_RAISE_ERROR( ePdfError_InternalLogic );
}
// After filling set correct BBox
m_rRect = pParent->FillXObjectFromDocumentPage( this, rDoc, nPage );
PdfVariant var;
m_rRect.ToVariant( var );
m_pObject->GetDictionary().AddKey( "BBox", var );
PdfArray matrix;
matrix.push_back( PdfVariant( 1LL ) );
matrix.push_back( PdfVariant( 0LL ) );
matrix.push_back( PdfVariant( 0LL ) );
matrix.push_back( PdfVariant( 1LL ) );
if( m_rRect.GetLeft() != 0 )
matrix.push_back( PdfVariant( m_rRect.GetLeft() * (-1.0) ) );
else
matrix.push_back( PdfVariant( 0LL ) );
if( m_rRect.GetBottom() != 0 )
matrix.push_back( PdfVariant( m_rRect.GetBottom() * (-1.0) ) );
else
matrix.push_back( PdfVariant( 0LL ) );
m_pObject->GetDictionary().AddKey( "Matrix", matrix );
}
示例11: tokenizer
void TextExtractor::ExtractText( PdfMemDocument* pDocument, PdfPage* pPage )
{
const char* pszToken = NULL;
PdfVariant var;
EPdfContentsType eType;
PdfContentsTokenizer tokenizer( pPage );
double dCurPosX = 0.0;
double dCurPosY = 0.0;
double dCurFontSize = 0.0;
bool bTextBlock = false;
PdfFont* pCurFont = NULL;
std::stack<PdfVariant> stack;
while( tokenizer.ReadNext( eType, pszToken, var ) )
{
if( eType == ePdfContentsType_Keyword )
{
// support 'l' and 'm' tokens
if( strcmp( pszToken, "l" ) == 0 ||
strcmp( pszToken, "m" ) == 0 )
{
dCurPosX = stack.top().GetReal();
stack.pop();
dCurPosY = stack.top().GetReal();
stack.pop();
}
else if( strcmp( pszToken, "BT" ) == 0 )
{
bTextBlock = true;
// BT does not reset font
// dCurFontSize = 0.0;
// pCurFont = NULL;
}
else if( strcmp( pszToken, "ET" ) == 0 )
{
if( !bTextBlock )
fprintf( stderr, "WARNING: Found ET without BT!\n" );
}
if( bTextBlock )
{
if( strcmp( pszToken, "Tf" ) == 0 )
{
dCurFontSize = stack.top().GetReal();
stack.pop();
PdfName fontName = stack.top().GetName();
PdfObject* pFont = pPage->GetFromResources( PdfName("Font"), fontName );
if( !pFont )
{
PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidHandle, "Cannot create font!" );
}
pCurFont = pDocument->GetFont( pFont );
if( !pCurFont )
{
fprintf( stderr, "WARNING: Unable to create font for object %i %i R\n",
pFont->Reference().ObjectNumber(),
pFont->Reference().GenerationNumber() );
}
}
else if( strcmp( pszToken, "Tj" ) == 0 ||
strcmp( pszToken, "'" ) == 0 )
{
AddTextElement( dCurPosX, dCurPosY, pCurFont, stack.top().GetString() );
stack.pop();
}
else if( strcmp( pszToken, "\"" ) == 0 )
{
AddTextElement( dCurPosX, dCurPosY, pCurFont, stack.top().GetString() );
stack.pop();
stack.pop(); // remove char spacing from stack
stack.pop(); // remove word spacing from stack
}
else if( strcmp( pszToken, "TJ" ) == 0 )
{
PdfArray array = stack.top().GetArray();
stack.pop();
for( int i=0; i<static_cast<int>(array.GetSize()); i++ )
{
if( array[i].IsString() )
AddTextElement( dCurPosX, dCurPosY, pCurFont, array[i].GetString() );
}
}
}
}
else if ( eType == ePdfContentsType_Variant )
{
stack.push( var );
}
else
{
// Impossible; type must be keyword or variant
PODOFO_RAISE_ERROR( ePdfError_InternalLogic );
}
}
}
示例12: PdfFontMetrics
PdfFontMetricsObject::PdfFontMetricsObject( PdfObject* pFont, PdfObject* pDescriptor, const PdfEncoding* const pEncoding )
: PdfFontMetrics( ePdfFontType_Unknown, "", NULL ),
m_pEncoding( pEncoding ), m_dDefWidth(0.0)
{
if( !pDescriptor )
{
PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
}
const PdfName & rSubType = pFont->GetDictionary().GetKey( PdfName::KeySubtype )->GetName();
// OC 15.08.2010 BugFix: /FirstChar /LastChar /Widths are in the Font dictionary and not in the FontDescriptor
if ( rSubType == PdfName("Type1") || rSubType == PdfName("TrueType") ) {
m_sName = pDescriptor->GetIndirectKey( "FontName" )->GetName();
m_bbox = pDescriptor->GetIndirectKey( "FontBBox" )->GetArray();
m_nFirst = static_cast<int>(pFont->GetDictionary().GetKeyAsLong( "FirstChar", 0L ));
m_nLast = static_cast<int>(pFont->GetDictionary().GetKeyAsLong( "LastChar", 0L ));
// OC 15.08.2010 BugFix: GetIndirectKey() instead of GetDictionary().GetKey() and "Widths" instead of "Width"
PdfObject* widths = pFont->GetIndirectKey( "Widths" );
if( widths != NULL )
{
m_width = widths->GetArray();
m_missingWidth = NULL;
}
else
{
widths = pDescriptor->GetDictionary().GetKey( "MissingWidth" );
if( widths == NULL )
{
PODOFO_RAISE_ERROR_INFO( ePdfError_NoObject, "Font object defines neither Widths, nor MissingWidth values!" );
m_missingWidth = widths;
}
}
} else if ( rSubType == PdfName("CIDFontType0") || rSubType == PdfName("CIDFontType2") ) {
PdfObject *pObj = pDescriptor->GetIndirectKey( "FontName" );
if (pObj) {
m_sName = pObj->GetName();
}
pObj = pDescriptor->GetIndirectKey( "FontBBox" );
if (pObj) {
m_bbox = pObj->GetArray();
}
m_nFirst = 0;
m_nLast = 0;
m_dDefWidth = static_cast<double>(pFont->GetDictionary().GetKeyAsLong( "DW", 1000L ));
PdfVariant default_width(m_dDefWidth);
PdfObject * pw = pFont->GetIndirectKey( "W" );
for (int i = m_nFirst; i <= m_nLast; ++i) {
m_width.push_back(default_width);
}
if (pw) {
PdfArray w = pw->GetArray();
int pos = 0;
while (pos < static_cast<int>(w.GetSize())) {
int start = static_cast<int>(w[pos++].GetNumber());
PODOFO_ASSERT (start >= 0);
if (w[pos].IsArray()) {
PdfArray widths = w[pos++].GetArray();
int length = start + static_cast<int>(widths.GetSize());
PODOFO_ASSERT (length >= start);
if (length > static_cast<int>(m_width.GetSize())) {
m_width.resize(length, default_width);
}
for (int i = 0; i < static_cast<int>(widths.GetSize()); ++i) {
m_width[start + i] = widths[i];
}
} else {
int end = static_cast<int>(w[pos++].GetNumber());
int length = start + end;
PODOFO_ASSERT (length >= start);
if (length > static_cast<int>(m_width.GetSize())) {
m_width.resize(length, default_width);
}
pdf_int64 width = w[pos++].GetNumber();
for (int i = start; i <= end; ++i)
m_width[i] = PdfVariant(width);
}
}
}
m_nLast = m_width.GetSize() - 1;
} else {
PODOFO_RAISE_ERROR_INFO( ePdfError_UnsupportedFontFormat, rSubType.GetEscapedName().c_str() );
}
m_nWeight = static_cast<unsigned int>(pDescriptor->GetDictionary().GetKeyAsLong( "FontWeight", 400L ));
m_nItalicAngle = static_cast<int>(pDescriptor->GetDictionary().GetKeyAsLong( "ItalicAngle", 0L ));
m_dPdfAscent = pDescriptor->GetDictionary().GetKeyAsReal( "Ascent", 0.0 );
m_dAscent = m_dPdfAscent / 1000.0;
m_dPdfDescent = pDescriptor->GetDictionary().GetKeyAsReal( "Descent", 0.0 );
m_dDescent = m_dPdfDescent / 1000.0;
m_dLineSpacing = m_dAscent + m_dDescent;
// Try to fine some sensible values
m_dUnderlineThickness = 1.0;
m_dUnderlinePosition = 0.0;
m_dStrikeOutThickness = m_dUnderlinePosition;
//.........这里部分代码省略.........
示例13: Init
void PdfFontCID::Init( bool bEmbed )
{
PdfObject* pDescriptor;
PdfObject* pDescendantFonts;
PdfObject* pCIDSystemInfo;
PdfObject* pUnicode;
PdfVariant var;
PdfArray array;
// The descendant font is a CIDFont:
pDescendantFonts = this->GetObject()->GetOwner()->CreateObject("Font");
pCIDSystemInfo = this->GetObject()->GetOwner()->CreateObject();
pDescriptor = this->GetObject()->GetOwner()->CreateObject("FontDescriptor");
pUnicode = this->GetObject()->GetOwner()->CreateObject(); // The ToUnicode CMap
// Now setting each of the entries of the font
this->GetObject()->GetDictionary().AddKey( PdfName::KeySubtype, PdfName("Type0") );
this->GetObject()->GetDictionary().AddKey( "BaseFont", this->GetBaseFont() );
this->GetObject()->GetDictionary().AddKey( "ToUnicode", pUnicode->Reference() );
// The encoding is here usually a (Predefined) CMap from PdfIdentityEncoding:
m_pEncoding->AddToDictionary( this->GetObject()->GetDictionary() );
// The DecendantFonts, should be an indirect object:
array.push_back( pDescendantFonts->Reference() );
this->GetObject()->GetDictionary().AddKey( "DescendantFonts", array );
// Setting the DescendantFonts paras
// This is a type2 CIDFont, which is also known as TrueType:
pDescendantFonts->GetDictionary().AddKey( PdfName::KeySubtype, PdfName("CIDFontType2") );
// Same base font as the owner font:
pDescendantFonts->GetDictionary().AddKey( "BaseFont", this->GetBaseFont() );
// The CIDSystemInfo, should be an indirect object:
pDescendantFonts->GetDictionary().AddKey( "CIDSystemInfo", pCIDSystemInfo->Reference() );
// The FontDescriptor, should be an indirect object:
pDescendantFonts->GetDictionary().AddKey( "FontDescriptor", pDescriptor->Reference() );
pDescendantFonts->GetDictionary().AddKey( "CIDToGIDMap", PdfName("Identity") );
// Add the width keys
this->CreateWidth( pDescendantFonts );
// Create the ToUnicode CMap
this->CreateCMap( pUnicode );
// Setting the CIDSystemInfo paras:
pCIDSystemInfo->GetDictionary().AddKey( "Registry", PdfString("Adobe") );
pCIDSystemInfo->GetDictionary().AddKey( "Ordering", PdfString("Identity") );
pCIDSystemInfo->GetDictionary().AddKey( "Supplement", PdfVariant(static_cast<pdf_int64>(0LL)) );
// Setting the FontDescriptor paras:
array.Clear();
m_pMetrics->GetBoundingBox( array );
pDescriptor->GetDictionary().AddKey( "FontName", this->GetBaseFont() );
pDescriptor->GetDictionary().AddKey( PdfName::KeyFlags, PdfVariant( static_cast<pdf_int64>(32LL) ) ); // TODO: 0 ????
pDescriptor->GetDictionary().AddKey( "FontBBox", array );
pDescriptor->GetDictionary().AddKey( "ItalicAngle", PdfVariant( static_cast<pdf_int64>(m_pMetrics->GetItalicAngle()) ) );
pDescriptor->GetDictionary().AddKey( "Ascent", m_pMetrics->GetPdfAscent() );
pDescriptor->GetDictionary().AddKey( "Descent", m_pMetrics->GetPdfDescent() );
pDescriptor->GetDictionary().AddKey( "CapHeight", m_pMetrics->GetPdfAscent() ); // m_pMetrics->CapHeight() );
pDescriptor->GetDictionary().AddKey( "StemV", PdfVariant( static_cast<pdf_int64>(1LL) ) ); // m_pMetrics->StemV() );
// Peter Petrov 24 September 2008
m_pDescriptor = pDescriptor;
if( bEmbed )
{
this->EmbedFont( pDescriptor );
m_bWasEmbedded = true;
}
}
示例14: sizeof
void PdfFontCID::CreateWidth( PdfObject* pFontDict ) const
{
const int cAbsoluteMax = 0xffff;
int nFirstChar = m_pEncoding->GetFirstChar();
int nLastChar = m_pEncoding->GetLastChar();
int i;
// Allocate an initialize an array, large enough to
// hold a width value for every possible glyph index
double* pdWidth = static_cast<double*>(malloc( sizeof(double) * cAbsoluteMax ) );
if( !pdWidth )
{
PODOFO_RAISE_ERROR( ePdfError_OutOfMemory );
}
for( i=0;i<cAbsoluteMax;i++ )
pdWidth[i] = 0.0;
// Load the width of all requested glyph indeces
int nMin = 0xffff;
int nMax = 0;
long lGlyph = 0;
for( i=nFirstChar;i<=nLastChar;i++ )
{
lGlyph = m_pMetrics->GetGlyphId( i );
if( lGlyph )
{
nMin = PDF_MIN( static_cast<long>(nMin), lGlyph );
nMax = PDF_MAX( static_cast<long>(nMax), lGlyph );
nMax = PDF_MIN( nMax, cAbsoluteMax );
if( lGlyph < cAbsoluteMax )
pdWidth[lGlyph] = m_pMetrics->GetGlyphWidth( lGlyph );
}
}
if (nMax >= nMin) {
// Now compact the array
std::ostringstream oss;
PdfArray array;
array.reserve( nMax - nMin + 1 );
i = nMin;
double dCurWidth = pdWidth[i];
pdf_int64 lCurIndex = i++;
pdf_int64 lCurLength = 1L;
for( ;i<=nMax;i++ )
{
if( static_cast<int>(pdWidth[i] - dCurWidth) == 0 )
++lCurLength;
else
{
if( lCurLength > 1 )
{
array.push_back( lCurIndex );
pdf_int64 temp = lCurIndex + lCurLength - 1;
array.push_back( temp );
array.push_back( dCurWidth );
}
else
{
if( array.size() && array.back().IsArray() )
{
array.back().GetArray().push_back( dCurWidth );
}
else
{
PdfArray tmp;
tmp.push_back( dCurWidth );
array.push_back( lCurIndex );
array.push_back( tmp );
}
}
lCurIndex = i;
lCurLength = 1L;
dCurWidth = pdWidth[i];
}
}
if (array.size() == 0)
{
array.push_back( lCurIndex = nMin );
array.push_back( lCurIndex = nMax );
array.push_back( dCurWidth );
}
pFontDict->GetDictionary().AddKey( PdfName("W"), array );
}
free( pdWidth );
}
示例15: SetColor
void PdfAnnotation::SetColor( double gray )
{
PdfArray c;
c.push_back( PdfVariant( gray ) );
this->GetObject()->GetDictionary().AddKey( "C", c );
}