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

void PoDoFo::NonPublic::PdfTTFWriter::LoadGlyph ( int  nIndex,
long  lOffset,
PdfInputDevice pDevice 
) [private]

Load a glyph from an input device at a certain offset

Parameters:
nIndexthe index of the glyph to load
lOffsetthe offset at which the glyph is located in the file
pDevicethe input device to read from

Definition at line 706 of file PdfTTFWriter.cpp.

References PoDoFo::ePdfError_InvalidFontFile, PoDoFo::ePdfError_OutOfMemory, m_vecGlyphs, PoDoFo::NonPublic::PdfTTFWriter::TGlyphHeader::numberOfContours, PODOFO_RAISE_ERROR, PoDoFo::PdfInputDevice::Read(), ReadSimpleGlyfCoordinates(), PoDoFo::PdfInputDevice::Seek(), SwapShort(), SwapUShort(), PoDoFo::NonPublic::PdfTTFWriter::PdfTTFGlyph::vecFlags, and PoDoFo::NonPublic::PdfTTFWriter::PdfTTFGlyph::vecFlagsOrig.

{
    printf("!!!! Loading glyph %i\n", nIndex );
    PdfTTFGlyph glyph( nIndex );

    pDevice->Seek( lOffset );
    pDevice->Read( reinterpret_cast<char*>(&glyph.m_tHeader), sizeof(TGlyphHeader) );
    if( podofo_is_little_endian() )
        SwapGlyfHeader( &glyph.m_tHeader );

    glyph.SetComposite( glyph.m_tHeader.numberOfContours == -1 );
    printf("Glyph with index %i is %s. (contours) = %i\n", nIndex, glyph.IsComposite() ? "composite" : "simple", glyph.m_tHeader.numberOfContours );

    if( !glyph.IsComposite() )
    {
        // Read the end points
        int            nContours = glyph.m_tHeader.numberOfContours;
        pdf_ttf_ushort nEndPoint;
        
        glyph.vecEndPoints.reserve( nContours );
        while( nContours-- ) 
        {
            READ_TTF_USHORT( nEndPoint );
            
            printf("Reading endpoint: %i\n", nEndPoint );
            glyph.vecEndPoints.push_back( nEndPoint );
        }

        // read instructions 
        pDevice->Read( reinterpret_cast<char*>(&glyph.m_nInstructionLength), sizeof(pdf_ttf_ushort) );
        if( podofo_is_little_endian() )
            SwapUShort( &glyph.m_nInstructionLength );
        
        printf("Reading instructions: %i\n", glyph.m_nInstructionLength );
        if( glyph.m_nInstructionLength ) 
        {
            glyph.m_pInstructions = static_cast<char*>(malloc( glyph.m_nInstructionLength * sizeof(char) ));
            if( !glyph.m_pInstructions ) 
            {
                PODOFO_RAISE_ERROR( ePdfError_OutOfMemory );
            }
            
            pDevice->Read( glyph.m_pInstructions, glyph.m_nInstructionLength );
        }
        
        
        unsigned char  flag;
        unsigned char  repeat;
        int      nPoints = glyph.vecEndPoints.back();

        // read flags
        printf("Reading flags: %i\n", nPoints );
        while( --nPoints >= 0 ) 
        {
            pDevice->Read( reinterpret_cast<char*>(&flag), sizeof(char) );
            glyph.vecFlagsOrig.push_back( flag );
            if( (flag & 0x08) == 0x08 ) // i.e. the next byte tells us how often this flag is to be repeated
            {
                pDevice->Read( reinterpret_cast<char*>(&repeat), sizeof(char) );
                glyph.vecFlagsOrig.push_back( repeat );
                /*
                while( repeat-- )
                    glyph.vecFlags.push_back( flag );
                */
            }
        };


        printf("!!!XXXXXXX\n");
        ReadSimpleGlyfCoordinates( pDevice, glyph.vecFlags, glyph.vecXCoordinates, 0x02, 0x10 );
        printf("!!!YYYYYYY\n");
        ReadSimpleGlyfCoordinates( pDevice, glyph.vecFlags, glyph.vecYCoordinates, 0x04, 0x20 );

        /*
        for( int z=0;z<glyph.vecXCoordinates.size();z++ ) 
        {
            printf("Coordinate %i %i\n", glyph.vecXCoordinates[z], glyph.vecYCoordinates[z] );
        }
        */
    }
    else
    {
        // read a composite glyph

        pdf_ttf_ushort flags;
        do {
            pdf_ttf_ushort glyphIndex;
            
            pDevice->Read( reinterpret_cast<char*>(&flags),      sizeof(pdf_ttf_ushort) );
            pDevice->Read( reinterpret_cast<char*>(&glyphIndex), sizeof(pdf_ttf_ushort) );

            if( podofo_is_little_endian() )
            {
                this->SwapUShort( &flags      );
                this->SwapUShort( &glyphIndex );
            }

            printf("glyphIndex=%i and should be %i\n", glyphIndex, nIndex );
            if( glyphIndex != nIndex )
            {
                PODOFO_RAISE_ERROR( ePdfError_InvalidFontFile );
            }

            if( flags & ARG_1_AND_2_ARE_WORDS ) 
            {
                pDevice->Read( reinterpret_cast<char*>(&glyph.arg1), sizeof(pdf_ttf_short) );
                pDevice->Read( reinterpret_cast<char*>(&glyph.arg2), sizeof(pdf_ttf_short) );
                
                if( podofo_is_little_endian() ) 
                {
                    this->SwapShort( &glyph.arg1 );
                    this->SwapShort( &glyph.arg2 );
                }
            }
            else
            {
                char cArg1;
                char cArg2;
                
                pDevice->Read( &cArg1, sizeof(char) );
                pDevice->Read( &cArg2, sizeof(char) );
                
                glyph.arg1 = cArg1;
                glyph.arg2 = cArg2;
            }
            
//          glyph.xx = glyph.yy = 0x10000L;
            glyph.xx = glyph.yy = 0x00;
            
            if ( flags & WE_HAVE_A_SCALE ) 
            {
                //F2Dot14  scale;    /* Format 2.14 */
                pDevice->Read( reinterpret_cast<char*>(&glyph.xx), sizeof(pdf_ttf_short) );
                if( podofo_is_little_endian() )
                    this->SwapShort( &glyph.xx );
                
                glyph.yy = glyph.xx;
            } 
            else if ( flags & WE_HAVE_AN_X_AND_Y_SCALE ) 
            {
                //F2Dot14  xscale;    /* Format 2.14 */
                //F2Dot14  yscale;    /* Format 2.14 */
                pDevice->Read( reinterpret_cast<char*>(&glyph.xx), sizeof(pdf_ttf_short) );
                pDevice->Read( reinterpret_cast<char*>(&glyph.yy), sizeof(pdf_ttf_short) );
                if( podofo_is_little_endian() )
                {
                    this->SwapShort( &glyph.xx );
                    this->SwapShort( &glyph.yy );
                }
            } 
            else if ( flags & WE_HAVE_A_TWO_BY_TWO ) 
            {
                pDevice->Read( reinterpret_cast<char*>(&glyph.xx), sizeof(pdf_ttf_short) );
                pDevice->Read( reinterpret_cast<char*>(&glyph.yx), sizeof(pdf_ttf_short) );
                pDevice->Read( reinterpret_cast<char*>(&glyph.yy), sizeof(pdf_ttf_short) );
                pDevice->Read( reinterpret_cast<char*>(&glyph.xy), sizeof(pdf_ttf_short) );
                if( podofo_is_little_endian() )
                {
                    this->SwapShort( &glyph.xx );
                    this->SwapShort( &glyph.yx );
                    this->SwapShort( &glyph.yy );
                    this->SwapShort( &glyph.xy );
                }
                
                //F2Dot14  xscale;    /* Format 2.14 */
                //F2Dot14  scale01;   /* Format 2.14 */
                //F2Dot14  scale10;   /* Format 2.14 */
                //F2Dot14  yscale;    /* Format 2.14 */
            }
        }
        while( flags & MORE_COMPONENTS );
           
        if( flags & WE_HAVE_INSTRUCTIONS )
        {
            pDevice->Read( reinterpret_cast<char*>(&glyph.m_nInstructionLength), sizeof(pdf_ttf_ushort) );
            if( podofo_is_little_endian() )
                this->SwapUShort( &glyph.m_nInstructionLength );
            
            if( glyph.m_nInstructionLength ) 
            {
                glyph.m_pInstructions = static_cast<char*>(malloc( glyph.m_nInstructionLength * sizeof(char) ));
                if( !glyph.m_pInstructions ) 
                {
                    PODOFO_RAISE_ERROR( ePdfError_OutOfMemory );
                }
                
                pDevice->Read( glyph.m_pInstructions, glyph.m_nInstructionLength );
            }
        }
    }

    m_vecGlyphs.push_back( glyph );
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index