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

void PoDoFo::PdfPainter::DrawText ( double  dX,
double  dY,
const PdfString sText,
long  lLen 
) [inherited]

Draw a single-line text string on a page using a given font object. You have to call SetFont before calling this function.

Parameters:
dXthe x coordinate
dYthe y coordinate
sTextthe text string which should be printed (is not allowed to be NULL!)
lLendraw only lLen characters of pszText
See also:
SetFont()

Definition at line 623 of file PdfPainter.cpp.

References PoDoFo::PdfPainter::AddToPageResources(), PoDoFo::PdfFont::AddUsedSubsettingGlyphs(), PoDoFo::PdfStream::Append(), PoDoFo::PdfPainter::DrawLine(), PoDoFo::ePdfError_InvalidHandle, PoDoFo::PdfPainter::ExpandTabs(), PoDoFo::PdfFont::GetFontCharSpace(), PoDoFo::PdfFont::GetFontMetrics(), PoDoFo::PdfFont::GetFontScale(), PoDoFo::PdfFont::GetFontSize(), PoDoFo::PdfFont::GetIdentifier(), PoDoFo::PdfName::GetName(), PoDoFo::PdfElement::GetObject(), PoDoFo::PdfFontMetrics::GetStrikeOutPosition(), PoDoFo::PdfFontMetrics::GetStrikeoutThickness(), PoDoFo::PdfString::GetString(), PoDoFo::PdfFontMetrics::GetUnderlinePosition(), PoDoFo::PdfFontMetrics::GetUnderlineThickness(), PoDoFo::PdfString::GetUnicode(), PoDoFo::PdfFont::IsStrikeOut(), PoDoFo::PdfFont::IsSubsetting(), PoDoFo::PdfFont::IsUnderlined(), PoDoFo::PdfString::IsUnicode(), PoDoFo::PdfString::IsValid(), PoDoFo::PdfPainter::m_oss, PoDoFo::PdfPainter::m_pCanvas, PoDoFo::PdfPainter::m_pFont, PoDoFo::PdfPainter::m_pPage, PODOFO_RAISE_ERROR, PODOFO_RAISE_LOGIC_IF, PoDoFo::PdfObject::Reference(), PoDoFo::PdfPainter::Restore(), PoDoFo::PdfPainter::Save(), PoDoFo::PdfPainter::SetCurrentStrokingColor(), PoDoFo::PdfPainter::SetStrokeWidth(), PoDoFo::PdfFontMetrics::StringWidth(), and PoDoFo::PdfFont::WriteStringToStream().

{
    PODOFO_RAISE_LOGIC_IF( !m_pCanvas, "Call SetPage() first before doing drawing operations." );

    if( !m_pFont || !m_pPage || !sText.IsValid() )
    {
        PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    // Peter Petrov 25 September 2008
    //m_pFont->EmbedFont();

    PdfString sString = this->ExpandTabs( sText, lStringLen );
    this->AddToPageResources( m_pFont->GetIdentifier(), m_pFont->GetObject()->Reference(), PdfName("Font") );
    if( m_pFont->IsSubsetting() )
    {
        m_pFont->AddUsedSubsettingGlyphs( sText, lStringLen );
    }

    if( m_pFont->IsUnderlined() || m_pFont->IsStrikeOut())
    {
        this->Save();
        this->SetCurrentStrokingColor();
            
        // Draw underline
        this->SetStrokeWidth( m_pFont->GetFontMetrics()->GetUnderlineThickness() );
        if( m_pFont->IsUnderlined() )
        {
            if (sString.IsUnicode())
                this->DrawLine( dX,
                                dY + m_pFont->GetFontMetrics()->GetUnderlinePosition(),
                                dX + m_pFont->GetFontMetrics()->StringWidth( sString.GetUnicode() ),
                                dY + m_pFont->GetFontMetrics()->GetUnderlinePosition() );
            else
                this->DrawLine( dX,
                                dY + m_pFont->GetFontMetrics()->GetUnderlinePosition(),
                                dX + m_pFont->GetFontMetrics()->StringWidth( sString.GetString() ),
                                dY + m_pFont->GetFontMetrics()->GetUnderlinePosition() );
        }

        // Draw strikeout
        this->SetStrokeWidth( m_pFont->GetFontMetrics()->GetStrikeoutThickness() );
        if( m_pFont->IsStrikeOut() )
        {
            if (sString.IsUnicode())
                this->DrawLine( dX,
                                dY + m_pFont->GetFontMetrics()->GetStrikeOutPosition(),
                                dX + m_pFont->GetFontMetrics()->StringWidth( sString.GetUnicode() ),
                                dY + m_pFont->GetFontMetrics()->GetStrikeOutPosition() );
            else
                this->DrawLine( dX,
                                dY + m_pFont->GetFontMetrics()->GetStrikeOutPosition(),
                                dX + m_pFont->GetFontMetrics()->StringWidth( sString.GetString() ),
                                dY + m_pFont->GetFontMetrics()->GetStrikeOutPosition() );
        }

        this->Restore();
    }
    



    m_oss.str("");
    m_oss << "BT" << std::endl << "/" << m_pFont->GetIdentifier().GetName()
          << " "  << m_pFont->GetFontSize()
          << " Tf" << std::endl;

    //if( m_pFont->GetFontScale() != 100.0F ) - this value is kept between text blocks
    m_oss << m_pFont->GetFontScale() << " Tz" << std::endl;

    //if( m_pFont->GetFontCharSpace() != 0.0F )  - this value is kept between text blocks
    m_oss << m_pFont->GetFontCharSpace() * m_pFont->GetFontSize() / 100.0 << " Tc" << std::endl;

    m_oss << dX << std::endl
          << dY << std::endl << "Td ";

    m_pCanvas->Append( m_oss.str() );
    m_pFont->WriteStringToStream( sString, m_pCanvas );

    /*
    char* pBuffer;
    std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode );
    pFilter->Encode( sString.GetString(), sString.GetLength(), &pBuffer, &lLen );

    m_pCanvas->Append( pBuffer, lLen );
    free( pBuffer );
    */

    m_pCanvas->Append( " Tj\nET\n" );
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index