Hi All

I have made some more improvements to  DrawMultiLineText() function of 
PdfPainter class.

Current behavior is roughly as follows:  We will calculate the top of the 
topmost each line based on vertical alignment. We will calculate the 
coordinates for baseline by subtracting Ascent metric of the font.

There is slight improvement to be made. Currently we are not considering 
LineGap when we calculate the baseline,(or we are keeping whole line gap  below 
the font)

After testing various cases with Word processing applications like Word and 
Libreoffice and WPF outputs and comparing them with PoDoFo output , I have 
observed that there is small discrepancy ,which is especially significant for 
large fonts with large line gap values.

The fix is to keep half linegap on top also.
Current behavior : BaseLine= Top-Ascent
Improved behaviour : BaseLine = Top -Ascent -LineGap/2

After this podofo matches very well with other application

It is not possible for me to generate a unified diff against latest revision now

I have attached the relevant function

I have also attached a diff against  revision 1767. This has both above 
mentioned fix, and improvement to GetMultiLineTextAsLines as function also( 
This was sent before also but  not yet committed).

Regards
Ali


::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------

The contents of this e-mail and any attachment(s) are confidential and intended 
for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information 
could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in 
transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on 
the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the 
author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, 
dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written 
consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please 
delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and 
other defects.

----------------------------------------------------------------------------------------------------------------------------------------------------
void PdfPainter::DrawMultiLineText( double dX, double dY, double dWidth, double 
dHeight, const PdfString & rsText, 
                                    EPdfAlignment eAlignment, 
EPdfVerticalAlignment eVertical, bool bClip )
{
    PODOFO_RAISE_LOGIC_IF( !m_pCanvas, "Call SetPage() first before doing 
drawing operations." );

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

    // Peter Petrov 25 September 2008
    //m_pFont->EmbedFont();
    
    if( dWidth <= 0.0 || dHeight <= 0.0 ) // nonsense arguments
        return;

    this->Save();
    if( bClip ) 
    {
        this->SetClipRect( dX, dY, dWidth, dHeight );
    }

    PdfString   sString  = this->ExpandTabs( rsText, 
rsText.GetCharacterLength() );

        std::vector<PdfString> vecLines = GetMultiLineTextAsLines(dWidth, 
sString);
        double dLineGap = m_pFont->GetFontMetrics()->GetLineSpacing() - 
m_pFont->GetFontMetrics()->GetAscent() + 
m_pFont->GetFontMetrics()->GetDescent();
    // Do vertical alignment
    switch( eVertical ) 
    {
        default:
            case ePdfVerticalAlignment_Top:
            dY += dHeight; break;
        case ePdfVerticalAlignment_Bottom:
            dY += m_pFont->GetFontMetrics()->GetLineSpacing() * 
vecLines.size(); break;
        case ePdfVerticalAlignment_Center:
            dY += (dHeight - 
                   ((dHeight - (m_pFont->GetFontMetrics()->GetLineSpacing() * 
vecLines.size()))/2.0)); 
            break;
    }
        
        dY -= (m_pFont->GetFontMetrics()->GetAscent() + dLineGap / (2.0));

    std::vector<PdfString>::const_iterator it = vecLines.begin();
    while( it != vecLines.end() )
    {
                
        if( (*it).GetCharacterLength() )
            this->DrawTextAligned( dX, dY, dWidth, *it, eAlignment );
        dY -= m_pFont->GetFontMetrics()->GetLineSpacing();
        ++it;
    }
    this->Restore();
}

Attachment: PdfPainter.diff
Description: PdfPainter.diff

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to