Make DrawTextPath() use CFX_FillRenderOptions struct as a parameter.
To avoid bitwise operations on an integer which represents fill options,
replace integer parameter |nFlag| with struct CFX_FillRenderOptions
|fill_options| for CFX_RenderDevice::DrawTextPath() and
CPDF_TextRenderer::DrawTextPath().
Meanwhile, change the return type for GetFillOptionsForDrawTextPath() to
CFX_FillRenderOptions since it helps generate |fill_options| for
CPDF_TextRenderer::DrawTextPath().
Bug: pdfium:1531
Change-Id: I2e059862e91e1bbccf10219d956e2c29c21b63ab
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/71011
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Hui Yingst <nigi@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 1cb7ebb..dbc5258 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -95,19 +95,20 @@
return fill_options;
}
-int GetFillOptionsForDrawTextPath(const CPDF_RenderOptions::Options& options,
- const CPDF_TextObject* text_obj,
- bool is_stroke,
- bool is_fill) {
- int fill_options = 0;
+CFX_FillRenderOptions GetFillOptionsForDrawTextPath(
+ const CPDF_RenderOptions::Options& options,
+ const CPDF_TextObject* text_obj,
+ bool is_stroke,
+ bool is_fill) {
+ CFX_FillRenderOptions fill_options;
if (is_stroke && is_fill) {
- fill_options |= FX_FILL_STROKE;
- fill_options |= FX_STROKE_TEXT_MODE;
+ fill_options.stroke = true;
+ fill_options.stroke_text_mode = true;
}
if (text_obj->m_GeneralState.GetStrokeAdjust())
- fill_options |= FX_STROKE_ADJUST;
+ fill_options.adjust_stroke = true;
if (options.bNoTextSmooth)
- fill_options |= FXFILL_NOPATHSMOOTH;
+ fill_options.aliased_path = true;
return fill_options;
}
@@ -673,7 +674,7 @@
textobj->m_TextState.GetFont().Get(),
textobj->m_TextState.GetFontSize(), textobj->GetTextMatrix(),
&new_matrix, textobj->m_GraphState.GetObject(), 0xffffffff, 0,
- nullptr, 0);
+ nullptr, CFX_FillRenderOptions());
}
}
CPDF_RenderStatus bitmap_render(m_pContext.Get(), &bitmap_device);
diff --git a/core/fpdfapi/render/cpdf_textrenderer.cpp b/core/fpdfapi/render/cpdf_textrenderer.cpp
index 24c0e5b..b89eea8 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.cpp
+++ b/core/fpdfapi/render/cpdf_textrenderer.cpp
@@ -48,18 +48,19 @@
} // namespace
// static
-bool CPDF_TextRenderer::DrawTextPath(CFX_RenderDevice* pDevice,
- pdfium::span<const uint32_t> char_codes,
- pdfium::span<const float> char_pos,
- CPDF_Font* pFont,
- float font_size,
- const CFX_Matrix& mtText2User,
- const CFX_Matrix* pUser2Device,
- const CFX_GraphStateData* pGraphState,
- FX_ARGB fill_argb,
- FX_ARGB stroke_argb,
- CFX_PathData* pClippingPath,
- int nFlag) {
+bool CPDF_TextRenderer::DrawTextPath(
+ CFX_RenderDevice* pDevice,
+ pdfium::span<const uint32_t> char_codes,
+ pdfium::span<const float> char_pos,
+ CPDF_Font* pFont,
+ float font_size,
+ const CFX_Matrix& mtText2User,
+ const CFX_Matrix* pUser2Device,
+ const CFX_GraphStateData* pGraphState,
+ FX_ARGB fill_argb,
+ FX_ARGB stroke_argb,
+ CFX_PathData* pClippingPath,
+ const CFX_FillRenderOptions& fill_options) {
std::vector<TextCharPos> pos =
GetCharPosList(char_codes, char_pos, pFont, font_size);
if (pos.empty())
@@ -77,7 +78,7 @@
if (!pDevice->DrawTextPath(i - startIndex, &pos[startIndex], font,
font_size, mtText2User, pUser2Device,
pGraphState, fill_argb, stroke_argb,
- pClippingPath, nFlag)) {
+ pClippingPath, fill_options)) {
bDraw = false;
}
fontPosition = curFontPosition;
@@ -86,7 +87,8 @@
CFX_Font* font = GetFont(pFont, fontPosition);
if (!pDevice->DrawTextPath(pos.size() - startIndex, &pos[startIndex], font,
font_size, mtText2User, pUser2Device, pGraphState,
- fill_argb, stroke_argb, pClippingPath, nFlag)) {
+ fill_argb, stroke_argb, pClippingPath,
+ fill_options)) {
bDraw = false;
}
return bDraw;
diff --git a/core/fpdfapi/render/cpdf_textrenderer.h b/core/fpdfapi/render/cpdf_textrenderer.h
index 3e78431..799a526 100644
--- a/core/fpdfapi/render/cpdf_textrenderer.h
+++ b/core/fpdfapi/render/cpdf_textrenderer.h
@@ -18,6 +18,7 @@
class CFX_PathData;
class CPDF_RenderOptions;
class CPDF_Font;
+struct CFX_FillRenderOptions;
class CPDF_TextRenderer {
public:
@@ -42,7 +43,7 @@
FX_ARGB fill_argb,
FX_ARGB stroke_argb,
CFX_PathData* pClippingPath,
- int nFlag);
+ const CFX_FillRenderOptions& fill_options);
static bool DrawNormalText(CFX_RenderDevice* pDevice,
pdfium::span<const uint32_t> char_codes,
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index 82cec48..6e23dde 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -903,9 +903,11 @@
if (fabs(char2device.a) + fabs(char2device.b) > 50 * 1.0f ||
GetDeviceType() == DeviceType::kPrinter) {
if (pFont->GetFaceRec()) {
- int nPathFlags = is_text_smooth ? 0 : FXFILL_NOPATHSMOOTH;
+ CFX_FillRenderOptions path_options;
+ path_options.aliased_path = !is_text_smooth;
return DrawTextPath(nChars, pCharPos, pFont, font_size, mtText2Device,
- nullptr, nullptr, fill_color, 0, nullptr, nPathFlags);
+ nullptr, nullptr, fill_color, 0, nullptr,
+ path_options);
}
}
int anti_alias = FT_RENDER_MODE_MONO;
@@ -1069,7 +1071,7 @@
uint32_t fill_color,
FX_ARGB stroke_color,
CFX_PathData* pClippingPath,
- int nFlag) {
+ const CFX_FillRenderOptions& fill_options) {
for (int iChar = 0; iChar < nChars; ++iChar) {
const TextCharPos& charpos = pCharPos[iChar];
CFX_Matrix matrix;
@@ -1090,13 +1092,12 @@
CFX_PathData TransformedPath(*pPath);
TransformedPath.Transform(matrix);
if (fill_color || stroke_color) {
- CFX_FillRenderOptions fill_options =
- GetFillOptionsFromIntegerFlags(nFlag);
+ CFX_FillRenderOptions options(fill_options);
if (fill_color)
- fill_options.fill_type = CFX_FillRenderOptions::FillType::kWinding;
- fill_options.text_mode = true;
+ options.fill_type = CFX_FillRenderOptions::FillType::kWinding;
+ options.text_mode = true;
if (!DrawPathWithBlend(&TransformedPath, pUser2Device, pGraphState,
- fill_color, stroke_color, fill_options,
+ fill_color, stroke_color, options,
BlendMode::kNormal)) {
return false;
}
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index 33edfb8..da49838 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -172,7 +172,7 @@
uint32_t fill_color,
uint32_t stroke_color,
CFX_PathData* pClippingPath,
- int nFlag);
+ const CFX_FillRenderOptions& fill_options);
void DrawFillRect(const CFX_Matrix* pUser2Device,
const CFX_FloatRect& rect,