From 4bed2af0c049bf499dcdb1327a47d40b4c0db92d Mon Sep 17 00:00:00 2001 From: npm Date: Fri, 2 Dec 2016 14:01:36 -0800 Subject: Rename fpdf_render_image and fpdf_render_text Review-Url: https://codereview.chromium.org/2551593002 --- core/fpdfapi/render/cpdf_dibtransferfunc.cpp | 178 ++++++++++++++++++++++ core/fpdfapi/render/cpdf_dibtransferfunc.h | 37 +++++ core/fpdfapi/render/cpdf_textrenderer.cpp | 187 +++++++++++++++++++++++ core/fpdfapi/render/cpdf_transferfunc.cpp | 2 +- core/fpdfapi/render/fpdf_render_image.cpp | 214 --------------------------- core/fpdfapi/render/fpdf_render_text.cpp | 211 -------------------------- core/fpdfapi/render/render_int.h | 30 ++-- 7 files changed, 413 insertions(+), 446 deletions(-) create mode 100644 core/fpdfapi/render/cpdf_dibtransferfunc.cpp create mode 100644 core/fpdfapi/render/cpdf_dibtransferfunc.h create mode 100644 core/fpdfapi/render/cpdf_textrenderer.cpp delete mode 100644 core/fpdfapi/render/fpdf_render_image.cpp delete mode 100644 core/fpdfapi/render/fpdf_render_text.cpp (limited to 'core') diff --git a/core/fpdfapi/render/cpdf_dibtransferfunc.cpp b/core/fpdfapi/render/cpdf_dibtransferfunc.cpp new file mode 100644 index 0000000000..41575fc8c2 --- /dev/null +++ b/core/fpdfapi/render/cpdf_dibtransferfunc.cpp @@ -0,0 +1,178 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/render/cpdf_dibtransferfunc.h" + +#include + +#include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/render/cpdf_transferfunc.h" + +CPDF_DIBTransferFunc::CPDF_DIBTransferFunc( + const CPDF_TransferFunc* pTransferFunc) { + m_RampR = pTransferFunc->m_Samples; + m_RampG = &pTransferFunc->m_Samples[256]; + m_RampB = &pTransferFunc->m_Samples[512]; +} + +CPDF_DIBTransferFunc::~CPDF_DIBTransferFunc() {} + +FXDIB_Format CPDF_DIBTransferFunc::GetDestFormat() { + if (m_pSrc->IsAlphaMask()) + return FXDIB_8bppMask; + +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + return (m_pSrc->HasAlpha()) ? FXDIB_Argb : FXDIB_Rgb32; +#else + return (m_pSrc->HasAlpha()) ? FXDIB_Argb : FXDIB_Rgb; +#endif +} + +FX_ARGB* CPDF_DIBTransferFunc::GetDestPalette() { + return nullptr; +} + +void CPDF_DIBTransferFunc::TranslateScanline( + const uint8_t* src_buf, + std::vector* dest_buf) const { + bool bSkip = false; + switch (m_pSrc->GetFormat()) { + case FXDIB_1bppRgb: { + int r0 = m_RampR[0]; + int g0 = m_RampG[0]; + int b0 = m_RampB[0]; + int r1 = m_RampR[255]; + int g1 = m_RampG[255]; + int b1 = m_RampB[255]; + int index = 0; + for (int i = 0; i < m_Width; i++) { + if (src_buf[i / 8] & (1 << (7 - i % 8))) { + (*dest_buf)[index++] = b1; + (*dest_buf)[index++] = g1; + (*dest_buf)[index++] = r1; + } else { + (*dest_buf)[index++] = b0; + (*dest_buf)[index++] = g0; + (*dest_buf)[index++] = r0; + } +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + index++; +#endif + } + break; + } + case FXDIB_1bppMask: { + int m0 = m_RampR[0]; + int m1 = m_RampR[255]; + int index = 0; + for (int i = 0; i < m_Width; i++) { + if (src_buf[i / 8] & (1 << (7 - i % 8))) + (*dest_buf)[index++] = m1; + else + (*dest_buf)[index++] = m0; + } + break; + } + case FXDIB_8bppRgb: { + FX_ARGB* pPal = m_pSrc->GetPalette(); + int index = 0; + for (int i = 0; i < m_Width; i++) { + if (pPal) { + FX_ARGB src_argb = pPal[*src_buf]; + (*dest_buf)[index++] = m_RampB[FXARGB_R(src_argb)]; + (*dest_buf)[index++] = m_RampG[FXARGB_G(src_argb)]; + (*dest_buf)[index++] = m_RampR[FXARGB_B(src_argb)]; + } else { + uint32_t src_byte = *src_buf; + (*dest_buf)[index++] = m_RampB[src_byte]; + (*dest_buf)[index++] = m_RampG[src_byte]; + (*dest_buf)[index++] = m_RampR[src_byte]; + } + src_buf++; +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + index++; +#endif + } + break; + } + case FXDIB_8bppMask: { + int index = 0; + for (int i = 0; i < m_Width; i++) + (*dest_buf)[index++] = m_RampR[*(src_buf++)]; + break; + } + case FXDIB_Rgb: { + int index = 0; + for (int i = 0; i < m_Width; i++) { + (*dest_buf)[index++] = m_RampB[*(src_buf++)]; + (*dest_buf)[index++] = m_RampG[*(src_buf++)]; + (*dest_buf)[index++] = m_RampR[*(src_buf++)]; +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + index++; +#endif + } + break; + } + case FXDIB_Rgb32: + bSkip = true; + case FXDIB_Argb: { + int index = 0; + for (int i = 0; i < m_Width; i++) { + (*dest_buf)[index++] = m_RampB[*(src_buf++)]; + (*dest_buf)[index++] = m_RampG[*(src_buf++)]; + (*dest_buf)[index++] = m_RampR[*(src_buf++)]; + if (!bSkip) { + (*dest_buf)[index++] = *src_buf; +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + } else { + index++; +#endif + } + src_buf++; + } + break; + } + default: + break; + } +} + +void CPDF_DIBTransferFunc::TranslateDownSamples(uint8_t* dest_buf, + const uint8_t* src_buf, + int pixels, + int Bpp) const { + if (Bpp == 8) { + for (int i = 0; i < pixels; i++) + *dest_buf++ = m_RampR[*(src_buf++)]; + } else if (Bpp == 24) { + for (int i = 0; i < pixels; i++) { + *dest_buf++ = m_RampB[*(src_buf++)]; + *dest_buf++ = m_RampG[*(src_buf++)]; + *dest_buf++ = m_RampR[*(src_buf++)]; + } + } else { +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + if (!m_pSrc->HasAlpha()) { + for (int i = 0; i < pixels; i++) { + *dest_buf++ = m_RampB[*(src_buf++)]; + *dest_buf++ = m_RampG[*(src_buf++)]; + *dest_buf++ = m_RampR[*(src_buf++)]; + dest_buf++; + src_buf++; + } + } else { +#endif + for (int i = 0; i < pixels; i++) { + *dest_buf++ = m_RampB[*(src_buf++)]; + *dest_buf++ = m_RampG[*(src_buf++)]; + *dest_buf++ = m_RampR[*(src_buf++)]; + *dest_buf++ = *(src_buf++); + } +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + } +#endif + } +} diff --git a/core/fpdfapi/render/cpdf_dibtransferfunc.h b/core/fpdfapi/render/cpdf_dibtransferfunc.h new file mode 100644 index 0000000000..d290c00d8a --- /dev/null +++ b/core/fpdfapi/render/cpdf_dibtransferfunc.h @@ -0,0 +1,37 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFAPI_RENDER_CPDF_DIBTRANSFERFUNC_H_ +#define CORE_FPDFAPI_RENDER_CPDF_DIBTRANSFERFUNC_H_ + +#include + +#include "core/fxge/fx_dib.h" + +class CPDF_TransferFunc; + +class CPDF_DIBTransferFunc : public CFX_FilteredDIB { + public: + explicit CPDF_DIBTransferFunc(const CPDF_TransferFunc* pTransferFunc); + ~CPDF_DIBTransferFunc() override; + + // CFX_FilteredDIB + FXDIB_Format GetDestFormat() override; + FX_ARGB* GetDestPalette() override; + void TranslateScanline(const uint8_t* src_buf, + std::vector* dest_buf) const override; + void TranslateDownSamples(uint8_t* dest_buf, + const uint8_t* src_buf, + int pixels, + int Bpp) const override; + + private: + const uint8_t* m_RampR; + const uint8_t* m_RampG; + const uint8_t* m_RampB; +}; + +#endif // CORE_FPDFAPI_RENDER_CPDF_DIBTRANSFERFUNC_H_ diff --git a/core/fpdfapi/render/cpdf_textrenderer.cpp b/core/fpdfapi/render/cpdf_textrenderer.cpp new file mode 100644 index 0000000000..9cb8ce933e --- /dev/null +++ b/core/fpdfapi/render/cpdf_textrenderer.cpp @@ -0,0 +1,187 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfapi/render/cpdf_textrenderer.h" + +#include + +#include "core/fpdfapi/font/cpdf_font.h" +#include "core/fpdfapi/render/cpdf_charposlist.h" +#include "core/fpdfapi/render/cpdf_renderoptions.h" +#include "core/fxge/cfx_graphstatedata.h" +#include "core/fxge/cfx_pathdata.h" +#include "core/fxge/cfx_renderdevice.h" + +// static +bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice, + int nChars, + uint32_t* pCharCodes, + FX_FLOAT* pCharPos, + CPDF_Font* pFont, + FX_FLOAT font_size, + const CFX_Matrix* pText2User, + const CFX_Matrix* pUser2Device, + const CFX_GraphStateData* pGraphState, + FX_ARGB fill_argb, + FX_ARGB stroke_argb, + CFX_PathData* pClippingPath, + int nFlag) { + CPDF_CharPosList CharPosList; + CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); + if (CharPosList.m_nChars == 0) + return true; + + bool bDraw = true; + int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; + uint32_t startIndex = 0; + for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { + int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; + if (fontPosition == curFontPosition) + continue; + auto* font = fontPosition == -1 + ? &pFont->m_Font + : pFont->m_FontFallbacks[fontPosition].get(); + if (!pDevice->DrawTextPath(i - startIndex, + CharPosList.m_pCharPos + startIndex, font, + font_size, pText2User, pUser2Device, pGraphState, + fill_argb, stroke_argb, pClippingPath, nFlag)) { + bDraw = false; + } + fontPosition = curFontPosition; + startIndex = i; + } + auto* font = fontPosition == -1 ? &pFont->m_Font + : pFont->m_FontFallbacks[fontPosition].get(); + if (!pDevice->DrawTextPath(CharPosList.m_nChars - startIndex, + CharPosList.m_pCharPos + startIndex, font, + font_size, pText2User, pUser2Device, pGraphState, + fill_argb, stroke_argb, pClippingPath, nFlag)) { + bDraw = false; + } + return bDraw; +} + +// static +void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, + FX_FLOAT origin_x, + FX_FLOAT origin_y, + CPDF_Font* pFont, + FX_FLOAT font_size, + const CFX_Matrix* pMatrix, + const CFX_ByteString& str, + FX_ARGB fill_argb, + FX_ARGB stroke_argb, + const CFX_GraphStateData* pGraphState, + const CPDF_RenderOptions* pOptions) { + if (pFont->IsType3Font()) + return; + + int nChars = pFont->CountChar(str.c_str(), str.GetLength()); + if (nChars <= 0) + return; + + int offset = 0; + uint32_t* pCharCodes; + FX_FLOAT* pCharPos; + std::vector codes; + std::vector positions; + if (nChars == 1) { + pCharCodes = reinterpret_cast( + pFont->GetNextChar(str.c_str(), str.GetLength(), offset)); + pCharPos = nullptr; + } else { + codes.resize(nChars); + positions.resize(nChars - 1); + FX_FLOAT cur_pos = 0; + for (int i = 0; i < nChars; i++) { + codes[i] = pFont->GetNextChar(str.c_str(), str.GetLength(), offset); + if (i) + positions[i - 1] = cur_pos; + cur_pos += pFont->GetCharWidthF(codes[i]) * font_size / 1000; + } + pCharCodes = codes.data(); + pCharPos = positions.data(); + } + CFX_Matrix matrix; + if (pMatrix) + matrix = *pMatrix; + + matrix.e = origin_x; + matrix.f = origin_y; + + if (stroke_argb == 0) { + DrawNormalText(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size, + &matrix, fill_argb, pOptions); + } else { + DrawTextPath(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size, + &matrix, nullptr, pGraphState, fill_argb, stroke_argb, nullptr, + 0); + } +} + +// static +bool CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice, + int nChars, + uint32_t* pCharCodes, + FX_FLOAT* pCharPos, + CPDF_Font* pFont, + FX_FLOAT font_size, + const CFX_Matrix* pText2Device, + FX_ARGB fill_argb, + const CPDF_RenderOptions* pOptions) { + CPDF_CharPosList CharPosList; + CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); + if (CharPosList.m_nChars == 0) + return true; + int FXGE_flags = 0; + if (pOptions) { + uint32_t dwFlags = pOptions->m_Flags; + if (dwFlags & RENDER_CLEARTYPE) { + FXGE_flags |= FXTEXT_CLEARTYPE; + if (dwFlags & RENDER_BGR_STRIPE) + FXGE_flags |= FXTEXT_BGR_STRIPE; + } + if (dwFlags & RENDER_NOTEXTSMOOTH) + FXGE_flags |= FXTEXT_NOSMOOTH; + if (dwFlags & RENDER_PRINTGRAPHICTEXT) + FXGE_flags |= FXTEXT_PRINTGRAPHICTEXT; + if (dwFlags & RENDER_NO_NATIVETEXT) + FXGE_flags |= FXTEXT_NO_NATIVETEXT; + if (dwFlags & RENDER_PRINTIMAGETEXT) + FXGE_flags |= FXTEXT_PRINTIMAGETEXT; + } else { + FXGE_flags = FXTEXT_CLEARTYPE; + } + if (pFont->IsCIDFont()) + FXGE_flags |= FXFONT_CIDFONT; + bool bDraw = true; + int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; + uint32_t startIndex = 0; + for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { + int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; + if (fontPosition == curFontPosition) + continue; + auto* font = fontPosition == -1 + ? &pFont->m_Font + : pFont->m_FontFallbacks[fontPosition].get(); + if (!pDevice->DrawNormalText( + i - startIndex, CharPosList.m_pCharPos + startIndex, font, + font_size, pText2Device, fill_argb, FXGE_flags)) { + bDraw = false; + } + fontPosition = curFontPosition; + startIndex = i; + } + auto* font = fontPosition == -1 ? &pFont->m_Font + : pFont->m_FontFallbacks[fontPosition].get(); + if (!pDevice->DrawNormalText(CharPosList.m_nChars - startIndex, + CharPosList.m_pCharPos + startIndex, font, + font_size, pText2Device, fill_argb, + FXGE_flags)) { + bDraw = false; + } + return bDraw; +} diff --git a/core/fpdfapi/render/cpdf_transferfunc.cpp b/core/fpdfapi/render/cpdf_transferfunc.cpp index a2cee3992d..be4836d20a 100644 --- a/core/fpdfapi/render/cpdf_transferfunc.cpp +++ b/core/fpdfapi/render/cpdf_transferfunc.cpp @@ -7,7 +7,7 @@ #include "core/fpdfapi/render/cpdf_transferfunc.h" #include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fpdfapi/render/render_int.h" +#include "core/fpdfapi/render/cpdf_dibtransferfunc.h" CPDF_TransferFunc::CPDF_TransferFunc(CPDF_Document* pDoc) : m_pPDFDoc(pDoc) {} diff --git a/core/fpdfapi/render/fpdf_render_image.cpp b/core/fpdfapi/render/fpdf_render_image.cpp deleted file mode 100644 index da5eda2020..0000000000 --- a/core/fpdfapi/render/fpdf_render_image.cpp +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfapi/render/render_int.h" - -#include -#include -#include - -#include "core/fpdfapi/page/cpdf_docpagedata.h" -#include "core/fpdfapi/page/cpdf_form.h" -#include "core/fpdfapi/page/cpdf_image.h" -#include "core/fpdfapi/page/cpdf_imageobject.h" -#include "core/fpdfapi/page/cpdf_page.h" -#include "core/fpdfapi/page/cpdf_shadingpattern.h" -#include "core/fpdfapi/page/cpdf_tilingpattern.h" -#include "core/fpdfapi/page/pageint.h" -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fpdfapi/render/cpdf_pagerendercache.h" -#include "core/fpdfapi/render/cpdf_rendercontext.h" -#include "core/fpdfapi/render/cpdf_renderoptions.h" -#include "core/fpdfapi/render/cpdf_renderstatus.h" -#include "core/fpdfapi/render/cpdf_transferfunc.h" -#include "core/fpdfdoc/cpdf_occontext.h" -#include "core/fxcodec/fx_codec.h" -#include "core/fxcrt/fx_safe_types.h" -#include "core/fxge/cfx_fxgedevice.h" -#include "core/fxge/cfx_pathdata.h" - -#ifdef _SKIA_SUPPORT_ -#include "core/fxge/skia/fx_skia_device.h" -#endif - -CPDF_DIBTransferFunc::~CPDF_DIBTransferFunc() {} - -FXDIB_Format CPDF_DIBTransferFunc::GetDestFormat() { - if (m_pSrc->IsAlphaMask()) { - return FXDIB_8bppMask; - } -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - return (m_pSrc->HasAlpha()) ? FXDIB_Argb : FXDIB_Rgb32; -#else - return (m_pSrc->HasAlpha()) ? FXDIB_Argb : FXDIB_Rgb; -#endif -} - -FX_ARGB* CPDF_DIBTransferFunc::GetDestPalette() { - return nullptr; -} - -CPDF_DIBTransferFunc::CPDF_DIBTransferFunc( - const CPDF_TransferFunc* pTransferFunc) { - m_RampR = pTransferFunc->m_Samples; - m_RampG = &pTransferFunc->m_Samples[256]; - m_RampB = &pTransferFunc->m_Samples[512]; -} - -void CPDF_DIBTransferFunc::TranslateScanline( - const uint8_t* src_buf, - std::vector* dest_buf) const { - bool bSkip = false; - switch (m_pSrc->GetFormat()) { - case FXDIB_1bppRgb: { - int r0 = m_RampR[0]; - int g0 = m_RampG[0]; - int b0 = m_RampB[0]; - int r1 = m_RampR[255]; - int g1 = m_RampG[255]; - int b1 = m_RampB[255]; - int index = 0; - for (int i = 0; i < m_Width; i++) { - if (src_buf[i / 8] & (1 << (7 - i % 8))) { - (*dest_buf)[index++] = b1; - (*dest_buf)[index++] = g1; - (*dest_buf)[index++] = r1; - } else { - (*dest_buf)[index++] = b0; - (*dest_buf)[index++] = g0; - (*dest_buf)[index++] = r0; - } -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - index++; -#endif - } - break; - } - case FXDIB_1bppMask: { - int m0 = m_RampR[0]; - int m1 = m_RampR[255]; - int index = 0; - for (int i = 0; i < m_Width; i++) { - if (src_buf[i / 8] & (1 << (7 - i % 8))) - (*dest_buf)[index++] = m1; - else - (*dest_buf)[index++] = m0; - } - break; - } - case FXDIB_8bppRgb: { - FX_ARGB* pPal = m_pSrc->GetPalette(); - int index = 0; - for (int i = 0; i < m_Width; i++) { - if (pPal) { - FX_ARGB src_argb = pPal[*src_buf]; - (*dest_buf)[index++] = m_RampB[FXARGB_R(src_argb)]; - (*dest_buf)[index++] = m_RampG[FXARGB_G(src_argb)]; - (*dest_buf)[index++] = m_RampR[FXARGB_B(src_argb)]; - } else { - uint32_t src_byte = *src_buf; - (*dest_buf)[index++] = m_RampB[src_byte]; - (*dest_buf)[index++] = m_RampG[src_byte]; - (*dest_buf)[index++] = m_RampR[src_byte]; - } - src_buf++; -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - index++; -#endif - } - break; - } - case FXDIB_8bppMask: { - int index = 0; - for (int i = 0; i < m_Width; i++) { - (*dest_buf)[index++] = m_RampR[*(src_buf++)]; - } - break; - } - case FXDIB_Rgb: { - int index = 0; - for (int i = 0; i < m_Width; i++) { - (*dest_buf)[index++] = m_RampB[*(src_buf++)]; - (*dest_buf)[index++] = m_RampG[*(src_buf++)]; - (*dest_buf)[index++] = m_RampR[*(src_buf++)]; -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - index++; -#endif - } - break; - } - case FXDIB_Rgb32: - bSkip = true; - case FXDIB_Argb: { - int index = 0; - for (int i = 0; i < m_Width; i++) { - (*dest_buf)[index++] = m_RampB[*(src_buf++)]; - (*dest_buf)[index++] = m_RampG[*(src_buf++)]; - (*dest_buf)[index++] = m_RampR[*(src_buf++)]; - if (!bSkip) { - (*dest_buf)[index++] = *src_buf; -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - } else { - index++; -#endif - } - src_buf++; - } - break; - } - default: - break; - } -} - -void CPDF_DIBTransferFunc::TranslateDownSamples(uint8_t* dest_buf, - const uint8_t* src_buf, - int pixels, - int Bpp) const { - if (Bpp == 8) { - for (int i = 0; i < pixels; i++) { - *dest_buf++ = m_RampR[*(src_buf++)]; - } - } else if (Bpp == 24) { - for (int i = 0; i < pixels; i++) { - *dest_buf++ = m_RampB[*(src_buf++)]; - *dest_buf++ = m_RampG[*(src_buf++)]; - *dest_buf++ = m_RampR[*(src_buf++)]; - } - } else { -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - if (!m_pSrc->HasAlpha()) { - for (int i = 0; i < pixels; i++) { - *dest_buf++ = m_RampB[*(src_buf++)]; - *dest_buf++ = m_RampG[*(src_buf++)]; - *dest_buf++ = m_RampR[*(src_buf++)]; - dest_buf++; - src_buf++; - } - } else { -#endif - for (int i = 0; i < pixels; i++) { - *dest_buf++ = m_RampB[*(src_buf++)]; - *dest_buf++ = m_RampG[*(src_buf++)]; - *dest_buf++ = m_RampR[*(src_buf++)]; - *dest_buf++ = *(src_buf++); - } -#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - } -#endif - } -} - -CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( - const uint8_t* src_buf, - uint32_t src_size, - int width, - int height, - int nComps, - int bpc, - const CPDF_Dictionary* pParams); diff --git a/core/fpdfapi/render/fpdf_render_text.cpp b/core/fpdfapi/render/fpdf_render_text.cpp deleted file mode 100644 index 1a749bcd21..0000000000 --- a/core/fpdfapi/render/fpdf_render_text.cpp +++ /dev/null @@ -1,211 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fpdfapi/render/render_int.h" - -#include - -#include "core/fpdfapi/font/cpdf_cidfont.h" -#include "core/fpdfapi/font/cpdf_font.h" -#include "core/fpdfapi/font/cpdf_type3char.h" -#include "core/fpdfapi/font/cpdf_type3font.h" -#include "core/fpdfapi/page/cpdf_docpagedata.h" -#include "core/fpdfapi/page/cpdf_form.h" -#include "core/fpdfapi/page/cpdf_imageobject.h" -#include "core/fpdfapi/page/cpdf_pageobject.h" -#include "core/fpdfapi/page/cpdf_pathobject.h" -#include "core/fpdfapi/page/cpdf_textobject.h" -#include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fpdfapi/render/cpdf_charposlist.h" -#include "core/fpdfapi/render/cpdf_docrenderdata.h" -#include "core/fpdfapi/render/cpdf_renderoptions.h" -#include "core/fpdfapi/render/cpdf_renderstatus.h" -#include "core/fpdfapi/render/cpdf_textrenderer.h" -#include "core/fpdfapi/render/cpdf_type3cache.h" -#include "core/fxge/cfx_facecache.h" -#include "core/fxge/cfx_fxgedevice.h" -#include "core/fxge/cfx_gemodule.h" -#include "core/fxge/cfx_graphstatedata.h" -#include "core/fxge/cfx_pathdata.h" -#include "core/fxge/cfx_renderdevice.h" -#include "third_party/base/numerics/safe_math.h" - -// static -bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice, - int nChars, - uint32_t* pCharCodes, - FX_FLOAT* pCharPos, - CPDF_Font* pFont, - FX_FLOAT font_size, - const CFX_Matrix* pText2User, - const CFX_Matrix* pUser2Device, - const CFX_GraphStateData* pGraphState, - FX_ARGB fill_argb, - FX_ARGB stroke_argb, - CFX_PathData* pClippingPath, - int nFlag) { - CPDF_CharPosList CharPosList; - CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); - if (CharPosList.m_nChars == 0) - return true; - bool bDraw = true; - int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; - uint32_t startIndex = 0; - for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { - int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; - if (fontPosition == curFontPosition) - continue; - auto* font = fontPosition == -1 - ? &pFont->m_Font - : pFont->m_FontFallbacks[fontPosition].get(); - if (!pDevice->DrawTextPath(i - startIndex, - CharPosList.m_pCharPos + startIndex, font, - font_size, pText2User, pUser2Device, pGraphState, - fill_argb, stroke_argb, pClippingPath, nFlag)) { - bDraw = false; - } - fontPosition = curFontPosition; - startIndex = i; - } - auto* font = fontPosition == -1 ? &pFont->m_Font - : pFont->m_FontFallbacks[fontPosition].get(); - if (!pDevice->DrawTextPath(CharPosList.m_nChars - startIndex, - CharPosList.m_pCharPos + startIndex, font, - font_size, pText2User, pUser2Device, pGraphState, - fill_argb, stroke_argb, pClippingPath, nFlag)) { - bDraw = false; - } - return bDraw; -} - -// static -void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, - FX_FLOAT origin_x, - FX_FLOAT origin_y, - CPDF_Font* pFont, - FX_FLOAT font_size, - const CFX_Matrix* pMatrix, - const CFX_ByteString& str, - FX_ARGB fill_argb, - FX_ARGB stroke_argb, - const CFX_GraphStateData* pGraphState, - const CPDF_RenderOptions* pOptions) { - if (pFont->IsType3Font()) - return; - - int nChars = pFont->CountChar(str.c_str(), str.GetLength()); - if (nChars <= 0) - return; - - int offset = 0; - uint32_t* pCharCodes; - FX_FLOAT* pCharPos; - std::vector codes; - std::vector positions; - if (nChars == 1) { - pCharCodes = reinterpret_cast( - pFont->GetNextChar(str.c_str(), str.GetLength(), offset)); - pCharPos = nullptr; - } else { - codes.resize(nChars); - positions.resize(nChars - 1); - FX_FLOAT cur_pos = 0; - for (int i = 0; i < nChars; i++) { - codes[i] = pFont->GetNextChar(str.c_str(), str.GetLength(), offset); - if (i) - positions[i - 1] = cur_pos; - cur_pos += pFont->GetCharWidthF(codes[i]) * font_size / 1000; - } - pCharCodes = codes.data(); - pCharPos = positions.data(); - } - CFX_Matrix matrix; - if (pMatrix) - matrix = *pMatrix; - - matrix.e = origin_x; - matrix.f = origin_y; - - if (stroke_argb == 0) { - DrawNormalText(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size, - &matrix, fill_argb, pOptions); - } else { - DrawTextPath(pDevice, nChars, pCharCodes, pCharPos, pFont, font_size, - &matrix, nullptr, pGraphState, fill_argb, stroke_argb, nullptr, - 0); - } -} - -// static -bool CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice, - int nChars, - uint32_t* pCharCodes, - FX_FLOAT* pCharPos, - CPDF_Font* pFont, - FX_FLOAT font_size, - const CFX_Matrix* pText2Device, - FX_ARGB fill_argb, - const CPDF_RenderOptions* pOptions) { - CPDF_CharPosList CharPosList; - CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); - if (CharPosList.m_nChars == 0) - return true; - int FXGE_flags = 0; - if (pOptions) { - uint32_t dwFlags = pOptions->m_Flags; - if (dwFlags & RENDER_CLEARTYPE) { - FXGE_flags |= FXTEXT_CLEARTYPE; - if (dwFlags & RENDER_BGR_STRIPE) { - FXGE_flags |= FXTEXT_BGR_STRIPE; - } - } - if (dwFlags & RENDER_NOTEXTSMOOTH) { - FXGE_flags |= FXTEXT_NOSMOOTH; - } - if (dwFlags & RENDER_PRINTGRAPHICTEXT) { - FXGE_flags |= FXTEXT_PRINTGRAPHICTEXT; - } - if (dwFlags & RENDER_NO_NATIVETEXT) { - FXGE_flags |= FXTEXT_NO_NATIVETEXT; - } - if (dwFlags & RENDER_PRINTIMAGETEXT) { - FXGE_flags |= FXTEXT_PRINTIMAGETEXT; - } - } else { - FXGE_flags = FXTEXT_CLEARTYPE; - } - if (pFont->IsCIDFont()) { - FXGE_flags |= FXFONT_CIDFONT; - } - bool bDraw = true; - int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; - uint32_t startIndex = 0; - for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { - int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; - if (fontPosition == curFontPosition) - continue; - auto* font = fontPosition == -1 - ? &pFont->m_Font - : pFont->m_FontFallbacks[fontPosition].get(); - if (!pDevice->DrawNormalText( - i - startIndex, CharPosList.m_pCharPos + startIndex, font, - font_size, pText2Device, fill_argb, FXGE_flags)) { - bDraw = false; - } - fontPosition = curFontPosition; - startIndex = i; - } - auto* font = fontPosition == -1 ? &pFont->m_Font - : pFont->m_FontFallbacks[fontPosition].get(); - if (!pDevice->DrawNormalText(CharPosList.m_nChars - startIndex, - CharPosList.m_pCharPos + startIndex, font, - font_size, pText2Device, fill_argb, - FXGE_flags)) { - bDraw = false; - } - return bDraw; -} diff --git a/core/fpdfapi/render/render_int.h b/core/fpdfapi/render/render_int.h index ca827368bc..5d04fa77bb 100644 --- a/core/fpdfapi/render/render_int.h +++ b/core/fpdfapi/render/render_int.h @@ -56,6 +56,8 @@ typedef struct { int m_ColorKeyMax; } DIB_COMP_DATA; +#define FPDF_HUGE_IMAGE_SIZE 60000000 + class CPDF_DIBSource : public CFX_DIBSource { public: CPDF_DIBSource(); @@ -173,25 +175,13 @@ class CPDF_DIBSource : public CFX_DIBSource { int m_Status; }; -#define FPDF_HUGE_IMAGE_SIZE 60000000 -class CPDF_DIBTransferFunc : public CFX_FilteredDIB { - public: - explicit CPDF_DIBTransferFunc(const CPDF_TransferFunc* pTransferFunc); - ~CPDF_DIBTransferFunc() override; - - // CFX_FilteredDIB - FXDIB_Format GetDestFormat() override; - FX_ARGB* GetDestPalette() override; - void TranslateScanline(const uint8_t* src_buf, - std::vector* dest_buf) const override; - void TranslateDownSamples(uint8_t* dest_buf, - const uint8_t* src_buf, - int pixels, - int Bpp) const override; - - const uint8_t* m_RampR; - const uint8_t* m_RampG; - const uint8_t* m_RampB; -}; +CCodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder( + const uint8_t* src_buf, + uint32_t src_size, + int width, + int height, + int nComps, + int bpc, + const CPDF_Dictionary* pParams); #endif // CORE_FPDFAPI_RENDER_RENDER_INT_H_ -- cgit v1.2.3