Beispiel #1
0
FX_BOOL CPDF_ScaledRenderBuffer::Initialize(CPDF_RenderContext* pContext,
                                            CFX_RenderDevice* pDevice,
                                            FX_RECT* pRect,
                                            const CPDF_PageObject* pObj,
                                            const CPDF_RenderOptions* pOptions,
                                            int max_dpi) {
  FXSYS_assert(pRect != NULL);
  m_pDevice = pDevice;
  if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_GET_BITS) {
    return TRUE;
  }
  m_pContext = pContext;
  m_Rect = *pRect;
  m_pObject = pObj;
  m_Matrix.TranslateI(-pRect->left, -pRect->top);
  int horz_size = pDevice->GetDeviceCaps(FXDC_HORZ_SIZE);
  int vert_size = pDevice->GetDeviceCaps(FXDC_VERT_SIZE);
  if (horz_size && vert_size && max_dpi) {
    int dpih =
        pDevice->GetDeviceCaps(FXDC_PIXEL_WIDTH) * 254 / (horz_size * 10);
    int dpiv =
        pDevice->GetDeviceCaps(FXDC_PIXEL_HEIGHT) * 254 / (vert_size * 10);
    if (dpih > max_dpi) {
      m_Matrix.Scale((FX_FLOAT)(max_dpi) / dpih, 1.0f);
    }
    if (dpiv > max_dpi) {
      m_Matrix.Scale(1.0f, (FX_FLOAT)(max_dpi) / (FX_FLOAT)dpiv);
    }
  }
  m_pBitmapDevice.reset(new CFX_FxgeDevice);
  FXDIB_Format dibFormat = FXDIB_Rgb;
  int32_t bpp = 24;
  if (m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_ALPHA_OUTPUT) {
    dibFormat = FXDIB_Argb;
    bpp = 32;
  }
  CFX_FloatRect rect;
  int32_t iWidth, iHeight, iPitch;
  while (1) {
    rect = *pRect;
    m_Matrix.TransformRect(rect);
    FX_RECT bitmap_rect = rect.GetOutterRect();
    iWidth = bitmap_rect.Width();
    iHeight = bitmap_rect.Height();
    iPitch = (iWidth * bpp + 31) / 32 * 4;
    if (iWidth * iHeight < 1) {
      return FALSE;
    }
    if (iPitch * iHeight <= _FPDFAPI_IMAGESIZE_LIMIT_ &&
        m_pBitmapDevice->Create(iWidth, iHeight, dibFormat)) {
      break;
    }
    m_Matrix.Scale(0.5f, 0.5f);
  }
  m_pContext->GetBackground(m_pBitmapDevice->GetBitmap(), m_pObject, pOptions,
                            &m_Matrix);
  return TRUE;
}
Beispiel #2
0
FX_RECT CFFL_IFormFiller::GetViewBBox(CPDFSDK_PageView* pPageView,
                                      CPDFSDK_Annot* pAnnot) {
  if (CFFL_FormFiller* pFormFiller = GetFormFiller(pAnnot, FALSE))
    return pFormFiller->GetViewBBox(pPageView, pAnnot);

  ASSERT(pPageView);

  CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
  CFX_FloatRect rcAnnot;
  pPDFAnnot->GetRect(rcAnnot);

  CFX_FloatRect rcWin = CPWL_Utils::InflateRect(rcAnnot, 1);
  return rcWin.GetOutterRect();
}
Beispiel #3
0
void CFX_PSRenderer::SetClip_PathFill(const CFX_PathData* pPathData,
                                      const CFX_AffineMatrix* pObject2Device,
                                      int fill_mode
                                     )
{
    StartRendering();
    OutputPath(pPathData, pObject2Device);
    CFX_FloatRect rect = pPathData->GetBoundingBox();
    if (pObject2Device) {
        rect.Transform(pObject2Device);
    }
    m_ClipBox.Intersect(rect.GetOutterRect());
    if ((fill_mode & 3) == FXFILL_WINDING) {
        OUTPUT_PS("W n\n");
    } else {
        OUTPUT_PS("W* n\n");
    }
}
FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView,
                                     CPDFSDK_Annot* pAnnot) {
  ASSERT(pPageView);
  ASSERT(pAnnot);

  CFX_FloatRect rcAnnot = m_pWidget->GetRect();

  if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) {
    CFX_FloatRect rcWindow = pWnd->GetWindowRect();
    rcAnnot = PWLtoFFL(rcWindow);
  }

  CFX_FloatRect rcWin = rcAnnot;

  CFX_FloatRect rcFocus = GetFocusBox(pPageView);
  if (!rcFocus.IsEmpty())
    rcWin.Union(rcFocus);

  CFX_FloatRect rect = CPWL_Utils::InflateRect(rcWin, 1);

  return rect.GetOutterRect();
}
Beispiel #5
0
void CFX_PSRenderer::SetClip_PathStroke(const CFX_PathData* pPathData,
                                        const CFX_AffineMatrix* pObject2Device,
                                        const CFX_GraphStateData* pGraphState
                                       )
{
    StartRendering();
    SetGraphState(pGraphState);
    if (pObject2Device) {
        CFX_ByteTextBuf buf;
        buf << FX_BSTRC("mx Cm [") << pObject2Device->a << FX_BSTRC(" ") << pObject2Device->b << FX_BSTRC(" ") <<
            pObject2Device->c << FX_BSTRC(" ") << pObject2Device->d << FX_BSTRC(" ") << pObject2Device->e <<
            FX_BSTRC(" ") << pObject2Device->f << FX_BSTRC("]cm ");
        m_pOutput->OutputPS((FX_LPCSTR)buf.GetBuffer(), buf.GetSize());
    }
    OutputPath(pPathData, NULL);
    CFX_FloatRect rect = pPathData->GetBoundingBox(pGraphState->m_LineWidth, pGraphState->m_MiterLimit);
    rect.Transform(pObject2Device);
    m_ClipBox.Intersect(rect.GetOutterRect());
    if (pObject2Device) {
        OUTPUT_PS("strokepath W n sm\n");
    } else {
        OUTPUT_PS("strokepath W n\n");
    }
}
Beispiel #6
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;
}
void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern,
                                    CFX_Matrix* pMatrix,
                                    FX_RECT& clip_rect,
                                    int alpha,
                                    FX_BOOL bAlphaMode) {
  CPDF_Function** pFuncs = pPattern->m_pFunctions;
  int nFuncs = pPattern->m_nFuncs;
  CPDF_Dictionary* pDict = pPattern->m_pShadingObj->GetDict();
  CPDF_ColorSpace* pColorSpace = pPattern->m_pCS;
  if (!pColorSpace) {
    return;
  }
  FX_ARGB background = 0;
  if (!pPattern->m_bShadingObj &&
      pPattern->m_pShadingObj->GetDict()->KeyExist("Background")) {
    CPDF_Array* pBackColor =
        pPattern->m_pShadingObj->GetDict()->GetArray("Background");
    if (pBackColor &&
        pBackColor->GetCount() >= (FX_DWORD)pColorSpace->CountComponents()) {
      CFX_FixedBufGrow<FX_FLOAT, 16> comps(pColorSpace->CountComponents());
      for (int i = 0; i < pColorSpace->CountComponents(); i++) {
        comps[i] = pBackColor->GetNumber(i);
      }
      FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f;
      pColorSpace->GetRGB(comps, R, G, B);
      background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255),
                              (int32_t)(B * 255));
    }
  }
  if (pDict->KeyExist("BBox")) {
    CFX_FloatRect rect = pDict->GetRect("BBox");
    rect.Transform(pMatrix);
    clip_rect.Intersect(rect.GetOutterRect());
  }
  CPDF_DeviceBuffer buffer;
  buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150);
  CFX_Matrix FinalMatrix = *pMatrix;
  FinalMatrix.Concat(*buffer.GetMatrix());
  CFX_DIBitmap* pBitmap = buffer.GetBitmap();
  if (!pBitmap->GetBuffer()) {
    return;
  }
  pBitmap->Clear(background);
  int fill_mode = m_Options.m_Flags;
  switch (pPattern->m_ShadingType) {
    case kInvalidShading:
    case kMaxShading:
      return;
    case kFunctionBasedShading:
      DrawFuncShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, pColorSpace,
                      alpha);
      break;
    case kAxialShading:
      DrawAxialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs,
                       pColorSpace, alpha);
      break;
    case kRadialShading:
      DrawRadialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs,
                        pColorSpace, alpha);
      break;
    case kFreeFormGouraudTriangleMeshShading: {
      DrawFreeGouraudShading(pBitmap, &FinalMatrix,
                             ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs,
                             pColorSpace, alpha);
    } break;
    case kLatticeFormGouraudTriangleMeshShading: {
      DrawLatticeGouraudShading(pBitmap, &FinalMatrix,
                                ToStream(pPattern->m_pShadingObj), pFuncs,
                                nFuncs, pColorSpace, alpha);
    } break;
    case kCoonsPatchMeshShading:
    case kTensorProductPatchMeshShading: {
      DrawCoonPatchMeshes(
          pPattern->m_ShadingType == kTensorProductPatchMeshShading, pBitmap,
          &FinalMatrix, ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs,
          pColorSpace, fill_mode, alpha);
    } break;
  }
  if (bAlphaMode) {
    pBitmap->LoadChannel(FXDIB_Red, pBitmap, FXDIB_Alpha);
  }
  if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) {
    pBitmap->ConvertColorScale(m_Options.m_ForeColor, m_Options.m_BackColor);
  }
  buffer.OutputToDevice();
}