Exemplo n.º 1
0
FX_BOOL CRF_TextPage::ParseTextPage()
{
    if(!m_pRefPage) {
        return FALSE;
    }
    int count = m_pRefPage->m_pReflowed->GetSize();
    if(count < 500) {
        m_pDataList = FX_NEW CRF_CharDataPtrArray(count);
    } else {
        m_pDataList = FX_NEW CRF_CharDataPtrArray(500);
    }
    if (NULL == m_pDataList) {
        return FALSE;
    }
    for(int i = 0; i < count; i++) {
        CRF_Data* pData = (*(m_pRefPage->m_pReflowed))[i];
        if(pData->GetType() == CRF_Data::Text) {
            m_pDataList->Add((CRF_CharData*)pData);
        }
    }
    m_CountBSArray = FX_NEW CFX_CountBSINT32Array(20);
    if(NULL == m_CountBSArray) {
        return FALSE;
    }
    return TRUE;
}
Exemplo n.º 2
0
void CPDF_ProgressiveReflowPageRender::Display(IFX_Pause* pPause)
{
    if (NULL == m_pReflowPage) {
        m_Status = Done;
        return;
    }
    FX_RECT clipBox = m_pFXDevice->GetClipBox();
    int size = m_pReflowPage->m_pReflowed->GetSize();
    if (size < 1 || NULL == m_pDisplayMatrix) {
        m_Status = Done;
        return;
    }
    for(int i = m_CurrNum; i < size; i++) {
        CRF_Data* pData = (*m_pReflowPage->m_pReflowed)[i];
        if(!pData) {
            continue;
        }
        CFX_FloatRect rect (pData->m_PosX, pData->m_PosY + pData->m_Height, pData->m_PosX + pData->m_Width, pData->m_PosY);
        m_pDisplayMatrix->TransformRect(rect);
        if(rect.left > clipBox.right || rect.right < clipBox.left || rect.bottom > clipBox.bottom || rect.top < clipBox.top) {
            continue;
        }
        if(pData->GetType() == CRF_Data::Text) {
            CRF_CharData* pCharData = (CRF_CharData*)pData;
            CPDF_Font* pPDFFont = pCharData->m_pCharState->m_pFont;
            if(pPDFFont->GetFontType() == PDFFONT_TYPE3) {
                continue;
            }
            FX_FLOAT x = pData->m_PosX, y = pData->m_PosY - pCharData->m_pCharState->m_fDescent;
            FXTEXT_CHARPOS charpos ;
            charpos.m_GlyphIndex = pPDFFont->GlyphFromCharCode(pCharData->m_CharCode);
            charpos.m_FontCharWidth = pPDFFont->m_Font.GetGlyphWidth(charpos.m_GlyphIndex);
            charpos.m_OriginX       = x;
            charpos.m_OriginY       = y;
            FX_FLOAT charW = pData->m_Width * 1000 / pData->m_Height;
            if(charW != charpos.m_FontCharWidth) {
                charpos.m_bGlyphAdjust  = TRUE;
                charpos.m_AdjustMatrix[0] = charW / charpos.m_FontCharWidth;
                charpos.m_AdjustMatrix[1] = 0;
                charpos.m_AdjustMatrix[2] = 0;
                charpos.m_AdjustMatrix[3] = 1;
            } else {
                charpos.m_bGlyphAdjust  = FALSE;
            }
            FX_BOOL bRet = FALSE;
            if(m_DisplayColor == -1)
                bRet = m_pFXDevice->DrawNormalText(1, &charpos, &(pPDFFont->m_Font),
                                                   NULL, pCharData->m_pCharState->m_fFontSize,
                                                   m_pDisplayMatrix, pCharData->m_pCharState->m_Color + 0xff000000, FXTEXT_CLEARTYPE);
            else
                bRet = m_pFXDevice->DrawNormalText(1, &charpos, &(pPDFFont->m_Font),
                                                   NULL, pCharData->m_pCharState->m_fFontSize, m_pDisplayMatrix, m_DisplayColor, FXTEXT_CLEARTYPE);
        } else if(pData->GetType() == CRF_Data::Image) {
            CRF_ImageData* pImageData = (CRF_ImageData*)pData;
            if(!pImageData->m_pBitmap) {
                continue;
            }
            int left = 0, top = 0;
            CFX_DIBitmap* pDiBmp = NULL;
            CFX_DIBSource* pDispSource = pImageData->m_pBitmap;
            if(pImageData->m_Matrix.d < 0) {
                CFX_AffineMatrix matrix(pImageData->m_Matrix.a, 0, 0, -pImageData->m_Matrix.d, 0, 0);
                int left, top;
                pDiBmp = pImageData->m_pBitmap->TransformTo(&matrix, left, top);
                pDispSource = pDiBmp;
            }
            if (NULL == pDispSource) {
                continue;
            }
            if (pDispSource->GetFormat() == FXDIB_1bppMask || pDispSource->GetFormat() == FXDIB_8bppMask) {
                m_pFXDevice->StretchBitMask(pDispSource, (int)(rect.left + 0.5), (int)(rect.bottom + 0.5), (int)(rect.Width() + 0.5), (int)(rect.Height() + 0.5), 0xff000000);
            } else {
                m_pFXDevice->StretchDIBits(pDispSource, (int)(rect.left + 0.5), (int)(rect.bottom + 0.5), (int)(rect.Width() + 0.5), (int)(rect.Height() + 0.5));
            }
            if(m_pFXDevice->GetBitmap() && m_pFXDevice->GetBitmap()->GetFormat() == FXDIB_8bppRgb &&
                    m_pFXDevice->GetBitmap()->GetPalette() == NULL) {
                int nPalette = 0;
                switch(m_DitherBits) {
                    case 0:
                        nPalette = 0;
                        break;
                    case 1:
                        nPalette = 2;
                        break;
                    case 2:
                        nPalette = 4;
                        break;
                    case 3:
                        nPalette = 8;
                        break;
                    case 4:
                        nPalette = 16;
                        break;
                    case 5:
                        nPalette = 32;
                        break;
                    case 6:
                        nPalette = 64;
                        break;
                    case 7:
                        nPalette = 128;
                        break;
                    default:
                        nPalette = 256;
                        break;
                }
                if(nPalette >= 2) {
                    FX_ARGB * palette = FX_Alloc(FX_ARGB, nPalette);
                    nPalette --;
                    palette[0] = 0;
                    palette[nPalette] = 255;
                    FX_FLOAT Dither = (FX_FLOAT)255 / (nPalette);
                    for(int i = 1; i < nPalette; i++) {
                        palette[i] = (FX_ARGB)(Dither * i + 0.5);
                    }
                    FX_RECT tmpRect = rect.GetOutterRect();
                    m_pFXDevice->GetBitmap()->DitherFS(palette, nPalette + 1, &tmpRect);
                    FX_Free (palette);
                }
            }
            if(pDiBmp) {
                delete pDiBmp;
            }
        } else if(pData->GetType() == CRF_Data::Path) {
        }
        if(!(i % 10)) {
            if(pPause && pPause->NeedToPauseNow()) {
                i++;
                m_CurrNum = i;
                m_Status = ToBeContinued;
                return;
            }
        }
    }
    m_CurrNum = size;
    m_Status = Done;
}