예제 #1
0
void PdfInfo::SetTrapped(const PdfName & sTrapped)
{
	if((sTrapped.GetEscapedName() == "True" ) || (sTrapped.GetEscapedName() == "False" ))
		this->GetObject()->GetDictionary().AddKey( "Trapped", sTrapped );
	else
		this->GetObject()->GetDictionary().AddKey( "Trapped", PdfName( "Unknown" ) );
}
예제 #2
0
PdfAction::PdfAction( EPdfAction eAction, PdfDocument* pParent )
    : PdfElement( "Action", pParent ), m_eType( eAction )
{
    const PdfName type = PdfName( TypeNameForIndex( eAction, s_names, s_lNumActions ) );

    if( !type.GetLength() )
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    this->GetObject()->GetDictionary().AddKey( "S", type );
}
예제 #3
0
bool PdfDictionary::HasKey( const PdfName & key ) const
{
    if( !key.GetLength() )
        return false;
    
    return ( m_mapKeys.find( key ) != m_mapKeys.end() );
}
예제 #4
0
EPdfFilter PdfFilterFactory::FilterNameToType( const PdfName & name, bool bSupportShortNames )
{
    int i = 0;

    while( aszFilters[i] )
    {
        if( name == aszFilters[i] )
            return static_cast<EPdfFilter>(i);
        
        ++i;
    }

    if( bSupportShortNames )
    {
        i = 0;
        while( aszShortFilters[i] )
        {
            if( name == aszShortFilters[i] )
                return static_cast<EPdfFilter>(i);
            
            ++i;
        }        
    }

    PODOFO_RAISE_ERROR_INFO( ePdfError_UnsupportedFilter, name.GetName().c_str() );
}
예제 #5
0
void NameTest::testParseAndWrite()
{
    const char* pszData = "/#E5#8A#A8#E6#80#81#E8#BF#9E#E6#8E#A5#E7#BA#BF";
    PdfTokenizer tokenizer(pszData, strlen(pszData));
    

    const char*   pszToken;
    EPdfTokenType eType;
    bool bGotToken = tokenizer.GetNextToken( pszToken, &eType );

    CPPUNIT_ASSERT_EQUAL( bGotToken, true );
    CPPUNIT_ASSERT_EQUAL( eType, ePdfTokenType_Delimiter );

    bGotToken = tokenizer.GetNextToken( pszToken, &eType );

    CPPUNIT_ASSERT_EQUAL( bGotToken, true );
    CPPUNIT_ASSERT_EQUAL( eType, ePdfTokenType_Token );

    // Test with const char* constructor
    PdfName name = PdfName::FromEscaped( pszToken );
    PdfVariant var( name );
    std::string str;
    var.ToString( str );
    
    CPPUNIT_ASSERT_EQUAL( str == pszData, true );
    // str.c_str() + 1 <- ignore leading slash 
    CPPUNIT_ASSERT_EQUAL( name.GetEscapedName() == (str.c_str() + 1), true );

    // Test with std::string constructor
    std::string sToken = pszToken;
    PdfName name2 = PdfName::FromEscaped( sToken );
    PdfVariant var2( name );
    std::string str2;
    var.ToString( str2 );

    CPPUNIT_ASSERT_EQUAL( str2 == pszData, true );
    // str.c_str() + 1 <- ignore leading slash 
    CPPUNIT_ASSERT_EQUAL( name2.GetEscapedName() == (str2.c_str() + 1), true );
}
예제 #6
0
void PdfDictionary::Write( PdfOutputDevice* pDevice, const PdfEncrypt* pEncrypt, const PdfName & keyStop ) const
{
    TCIKeyMap     itKeys;

    pDevice->Print( "<<\n" );

    itKeys     = m_mapKeys.begin();

    if( keyStop != PdfName::KeyNull && keyStop.GetLength() && keyStop == PdfName::KeyType )
        return;

    if( this->HasKey( PdfName::KeyType ) ) 
    {
        // Type has to be the first key in any dictionary
        pDevice->Print( "/Type " );
        this->GetKey( PdfName::KeyType )->Write( pDevice, pEncrypt );
        pDevice->Print( "\n" );
    }

    while( itKeys != m_mapKeys.end() )
    {
        if( (*itKeys).first != PdfName::KeyType )
        {
            if( keyStop != PdfName::KeyNull && keyStop.GetLength() && (*itKeys).first == keyStop )
                return;

            (*itKeys).first.Write( pDevice );
            pDevice->Write( " ", 1 ); // write a separator
            (*itKeys).second->Write( pDevice, pEncrypt );
            pDevice->Write( "\n", 1 );
        }
        
        ++itKeys;
    }

    pDevice->Print( ">>" );
}
예제 #7
0
void NameTest::TestFromEscape( const char* pszName1, const char* pszName2 ) 
{
    PdfName name = PdfName::FromEscaped( pszName1, strlen( pszName1 ) );

    CPPUNIT_ASSERT_EQUAL( name.GetName() == pszName2, true  );
}