Logo Search packages:      
Sourcecode: libpodofo version File versions  Download package

void PoDoFo::NonPublic::PdfTTFWriter::Read ( PdfInputDevice pDevice )

Fills the internal data structures using an existing TrueType font.

Parameters:
pDevicethe TTF is read from this device

Definition at line 132 of file PdfTTFWriter.cpp.

References CreateTag(), PoDoFo::NonPublic::PdfTTFWriter::TTable::data, PoDoFo::ePdfError_InvalidFontFile, PoDoFo::NonPublic::PdfTTFWriter::TTable::length, m_lCMapOffset, m_lGlyphDataOffset, m_tTableDirectory, m_vecTableData, PoDoFo::NonPublic::PdfTTFWriter::TTableDirectory::numTables, PoDoFo::NonPublic::PdfTTFWriter::TTableDirectoryEntry::offset, PODOFO_RAISE_ERROR_INFO, PoDoFo::PdfInputDevice::Read(), ReadHeadTable(), ReadTableDirectory(), ReadTableDirectoryEntry(), PoDoFo::PdfInputDevice::Seek(), PoDoFo::NonPublic::PdfTTFWriter::TTable::tag, and PoDoFo::NonPublic::PdfTTFWriter::TTableDirectoryEntry::tag.

{
    long lHead = -1;
    long lHHea = -1;
    long lLoca = -1;
    long lMaxp = -1;
    long lOs2  = -1;
    long lHmtx = -1;
    long lPost = -1;

    // Read the table directory
    this->ReadTableDirectory( pDevice );

    // read the table of contents
    TVecTableDirectoryEntries vecTables;
    TTableDirectoryEntry      entry;

    vecTables.reserve( m_tTableDirectory.numTables );
    for( int i=0;i<m_tTableDirectory.numTables;i++ ) 
    {
        this->ReadTableDirectoryEntry( pDevice, &entry );

        if( entry.tag == this->CreateTag( 'l', 'o', 'c', 'a' ) ) 
            lLoca = entry.offset;
        else if( entry.tag == this->CreateTag( 'g', 'l', 'y', 'f' ) ) 
            m_lGlyphDataOffset = entry.offset;
        else if( entry.tag == this->CreateTag( 'm', 'a', 'x', 'p' ) ) 
            lMaxp = entry.offset;
        else if( entry.tag == this->CreateTag( 'h', 'e', 'a', 'd' ) ) 
            lHead = entry.offset;
        else if( entry.tag == this->CreateTag( 'c', 'm', 'a', 'p' ) )
            m_lCMapOffset = entry.offset;
        else if( entry.tag == this->CreateTag( 'h', 'h', 'e', 'a' ) )
            lHHea = entry.offset;
        else if( entry.tag == this->CreateTag( 'O', 'S', '/', '2' ) )
            lOs2 = entry.offset;
        else if( entry.tag == this->CreateTag( 'h', 'm', 't', 'x' ) )
            lHmtx = entry.offset;
        else if( entry.tag == this->CreateTag( 'p', 'o', 's', 't' ) )
            lPost = entry.offset;

        vecTables.push_back( entry );
    }

    // check if all required tables have been found
    if( lLoca == -1 ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Table 'loca' not found." ); 
    }
    else if( m_lGlyphDataOffset == -1 ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Table 'glyf' not found." ); 
    }
    else if( lMaxp == -1 ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Table 'maxp' not found." ); 
    }
    else if( lHead == -1 ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Table 'head' not found." ); 
    }
    else if( m_lCMapOffset == -1 ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Table 'cmap' not found." ); 
    }
    else if( lHHea == -1 ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Table 'hhea' not found." ); 
    }
    else if( lOs2 == -1 ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Table 'OS/2' not found." ); 
    }
    else if( lHmtx == -1 ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Table 'hmtx' not found." ); 
    }
    else if( lPost == -1 ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidFontFile, "Table 'post' not found." ); 
    }

    // Read head table
    pDevice->Seek( lHead );
    this->ReadHeadTable( pDevice );

    // Read maxp table
    pDevice->Seek( lMaxp );
    this->ReadMaxpTable( pDevice );

    // Read loca table
    pDevice->Seek( lLoca );
    this->ReadLocaTable( pDevice );

    // Read hhea table
    pDevice->Seek( lHHea );
    this->ReadHHeaTable( pDevice );

    // Read cmap table
    pDevice->Seek( m_lCMapOffset );
    this->ReadCmapTable( pDevice );

    // Read glyf table
    pDevice->Seek( m_lGlyphDataOffset );
    this->ReadGlyfTable( pDevice );

    // Read OS/2 table
    pDevice->Seek( lOs2 );
    this->ReadOs2Table( pDevice );

    // Read hmtx table
    pDevice->Seek( lHmtx );
    this->ReadHmtxTable( pDevice );

    // Read post table
    pDevice->Seek( lPost );
    this->ReadPostTable( pDevice );

    // read the remaining data tables
    TIVecTableDirectoryEntries it = vecTables.begin(); 
    while( it != vecTables.end() ) 
    {
        // skip the 4 tables we have alread read
        if( (*it).tag != this->CreateTag( 'g', 'l', 'y', 'f' ) &&
            (*it).tag != this->CreateTag( 'h', 'e', 'a', 'd' ) &&
            (*it).tag != this->CreateTag( 'l', 'o', 'c', 'a' ) &&
            (*it).tag != this->CreateTag( 'm', 'a', 'x', 'p' ) &&
            (*it).tag != this->CreateTag( 'h', 'h', 'e', 'a' ) &&
            (*it).tag != this->CreateTag( 'c', 'm', 'a', 'p' ) &&
            (*it).tag != this->CreateTag( 'O', 'S', '/', '2' ) &&
            (*it).tag != this->CreateTag( 'n', 'a', 'm', 'e' ) )
        {
            TTable table;
            table.tag    = (*it).tag;
            table.length = (*it).length; 
            table.data   = static_cast<char*>(malloc( sizeof(char) * (*it).length ));
            
            pDevice->Seek( (*it).offset );
            pDevice->Read( table.data, (*it).length ); 
            
            m_vecTableData.push_back( table );
        }

            
        ++it;
    }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index