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/fx_coordinates.h"
18#include "core/fxcrt/fx_safe_types.h"
19#include "core/fxge/cfx_glyphbitmap.h"
20#include "core/fxge/dib/cfx_dibitmap.h"
21#include "core/fxge/dib/fx_dib.h"
25bool IsScanLine1bpp(
const uint8_t* pBuf,
int width) {
27 for (
int i = 0; i < size; i++) {
31 return (width % 8) && (pBuf[width / 8] & (0xff << (8 - width % 8)));
34bool IsScanLine8bpp(
const uint8_t* pBuf,
int width) {
35 for (
int i = 0; i < width; i++) {
42bool IsScanLineBpp(
int bpp,
const uint8_t* pBuf,
int width) {
44 return IsScanLine1bpp(pBuf, width);
47 return IsScanLine8bpp(pBuf, width);
50int DetectFirstScan(
const RetainPtr<CFX_DIBitmap>& pBitmap) {
51 const int height = pBitmap->GetHeight();
52 const int width = pBitmap->GetWidth();
53 const int bpp = pBitmap->GetBPP();
54 for (
int line = 0; line < height; ++line) {
55 const uint8_t* pBuf = pBitmap->GetScanline(line).data();
56 if (IsScanLineBpp(bpp, pBuf, width))
62int DetectLastScan(
const RetainPtr<CFX_DIBitmap>& pBitmap) {
63 const int height = pBitmap->GetHeight();
64 const int bpp = pBitmap->GetBPP();
65 const int width = pBitmap->GetWidth();
66 for (
int line = height - 1; line >= 0; --line) {
67 const uint8_t* pBuf = pBitmap->GetScanline(line).data();
68 if (IsScanLineBpp(bpp, pBuf, width))
76CPDF_Type3Cache::CPDF_Type3Cache(CPDF_Type3Font* pFont) : m_pFont(pFont) {}
83 FXSYS_roundf(mtMatrix.a * 10000),
84 FXSYS_roundf(mtMatrix.b * 10000),
85 FXSYS_roundf(mtMatrix.c * 10000),
86 FXSYS_roundf(mtMatrix.d * 10000),
89 auto it = m_SizeMap.find(keygen);
90 if (it == m_SizeMap.end()) {
92 pSizeCache = pNew.get();
93 m_SizeMap[keygen] = std::move(pNew);
95 pSizeCache = it->second.get();
101 std::unique_ptr<CFX_GlyphBitmap> pNewBitmap =
102 RenderGlyph(pSizeCache, charcode, mtMatrix);
104 pSizeCache->SetBitmap(charcode,
std::move(pNewBitmap));
108std::unique_ptr<CFX_GlyphBitmap> CPDF_Type3Cache::RenderGlyph(
116 RetainPtr<CFX_DIBitmap> pBitmap = pChar->GetBitmap();
126 if (fabs(image_matrix
.b) < fabs(image_matrix
.a) / 100 &&
127 fabs(image_matrix
.c) < fabs(image_matrix
.d) / 100) {
128 int top_line = DetectFirstScan(pBitmap);
129 int bottom_line = DetectLastScan(pBitmap);
130 if (top_line == 0 && bottom_line == pBitmap->GetHeight() - 1) {
131 float top_y = image_matrix
.d + image_matrix
.f;
132 float bottom_y = image_matrix
.f;
133 bool bFlipped = top_y > bottom_y;
135 std::swap(top_y, bottom_y);
137 FX_SAFE_INT32 safe_height = bFlipped ? top_line : bottom_line;
138 safe_height -= bFlipped ? bottom_line : top_line;
139 if (!safe_height.IsValid())
142 pResBitmap = pBitmap->StretchTo(
static_cast<
int>(image_matrix
.a),
143 safe_height.ValueOrDie(),
146 if (image_matrix
.a < 0)
153 pResBitmap = pBitmap->TransformTo(image_matrix, &left, &top);
158 pGlyph->GetBitmap()->TakeOver(
std::move(pResBitmap));
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
CFX_Matrix operator*(const CFX_Matrix &right) const
~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)
int FXSYS_roundf(float f)