7#include "core/fpdfapi/render/cpdf_type3cache.h"
14#include "core/fpdfapi/font/cpdf_type3char.h"
15#include "core/fpdfapi/font/cpdf_type3font.h"
16#include "core/fpdfapi/render/cpdf_type3glyphmap.h"
17#include "core/fxcrt/compiler_specific.h"
18#include "core/fxcrt/fx_coordinates.h"
19#include "core/fxcrt/fx_safe_types.h"
20#include "core/fxge/cfx_glyphbitmap.h"
21#include "core/fxge/dib/cfx_dibitmap.h"
22#include "core/fxge/dib/fx_dib.h"
26bool IsScanLine1bpp(
const uint8_t* pBuf,
int width) {
28 for (
int i = 0; i < size; i++) {
34 (
UNSAFE_TODO(pBuf[width / 8]) & (0xff << (8 - width % 8)));
37bool IsScanLine8bpp(
const uint8_t* pBuf,
int width) {
38 for (
int i = 0; i < width; i++) {
46bool IsScanLineBpp(
int bpp,
const uint8_t* pBuf,
int width) {
48 return IsScanLine1bpp(pBuf, width);
51 return IsScanLine8bpp(pBuf, width);
54int DetectFirstScan(
const RetainPtr<CFX_DIBitmap>& pBitmap) {
55 const int height = pBitmap->GetHeight();
56 const int width = pBitmap->GetWidth();
57 const int bpp = pBitmap->GetBPP();
58 for (
int line = 0; line < height; ++line) {
59 const uint8_t* pBuf = pBitmap->GetScanline(line).data();
60 if (IsScanLineBpp(bpp, pBuf, width))
66int DetectLastScan(
const RetainPtr<CFX_DIBitmap>& pBitmap) {
67 const int height = pBitmap->GetHeight();
68 const int bpp = pBitmap->GetBPP();
69 const int width = pBitmap->GetWidth();
70 for (
int line = height - 1; line >= 0; --line) {
71 const uint8_t* pBuf = pBitmap->GetScanline(line).data();
72 if (IsScanLineBpp(bpp, pBuf, width))
80CPDF_Type3Cache::CPDF_Type3Cache(CPDF_Type3Font* pFont) : m_pFont(pFont) {}
87 FXSYS_roundf(mtMatrix.a * 10000),
88 FXSYS_roundf(mtMatrix.b * 10000),
89 FXSYS_roundf(mtMatrix.c * 10000),
90 FXSYS_roundf(mtMatrix.d * 10000),
93 auto it = m_SizeMap.find(keygen);
94 if (it == m_SizeMap.end()) {
96 pSizeCache = pNew.get();
97 m_SizeMap[keygen] = std::move(pNew);
99 pSizeCache = it->second.get();
105 std::unique_ptr<CFX_GlyphBitmap> pNewBitmap =
106 RenderGlyph(pSizeCache, charcode, mtMatrix);
108 pSizeCache->SetBitmap(charcode,
std::move(pNewBitmap));
112std::unique_ptr<CFX_GlyphBitmap> CPDF_Type3Cache::RenderGlyph(
120 RetainPtr<CFX_DIBitmap> pBitmap = pChar->GetBitmap();
130 if (fabs(image_matrix
.b) < fabs(image_matrix
.a) / 100 &&
131 fabs(image_matrix
.c) < fabs(image_matrix
.d) / 100) {
132 int top_line = DetectFirstScan(pBitmap);
133 int bottom_line = DetectLastScan(pBitmap);
134 if (top_line == 0 && bottom_line == pBitmap->GetHeight() - 1) {
135 float top_y = image_matrix
.d + image_matrix
.f;
136 float bottom_y = image_matrix
.f;
137 bool bFlipped = top_y > bottom_y;
139 std::swap(top_y, bottom_y);
141 FX_SAFE_INT32 safe_height = bFlipped ? top_line : bottom_line;
142 safe_height -= bFlipped ? bottom_line : top_line;
143 if (!safe_height.IsValid())
146 pResBitmap = pBitmap->StretchTo(
static_cast<
int>(image_matrix
.a),
147 safe_height.ValueOrDie(),
150 if (image_matrix
.a < 0)
157 pResBitmap = pBitmap->TransformTo(image_matrix, &left, &top);
162 pGlyph->GetBitmap()->TakeOver(
std::move(pResBitmap));
CFX_Matrix operator*(const CFX_Matrix &right) const
constexpr CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
~CPDF_Type3Cache() override
const CFX_GlyphBitmap * LoadGlyph(uint32_t charcode, const CFX_Matrix &mtMatrix)
const CFX_Matrix & matrix() const
const CFX_GlyphBitmap * GetBitmap(uint32_t charcode) const
std::pair< int, int > AdjustBlue(float top, float bottom)
pdfium::CheckedNumeric< int32_t > FX_SAFE_INT32
int FXSYS_roundf(float f)