Make CFX_TextRenderOptions construction constexpr.
CFX_TextRenderOptions can be constructed at compile time instead of
runtime. In turn, CBC_OneDimWriter::GetTextRenderOptions() also becomes
constexpr.
By making CFX_TextRenderOptions constexpr, cfx_textrenderoptions.cpp is
no longer required. LcdOptions() also becomes trivial, so get rid of it
as well.
Change-Id: Iae7024fba988bf7118053e1ec46ad520eb690fab
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/73110
Reviewed-by: Hui Yingst <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn
index 3a9ebe0..46ea2d6 100644
--- a/core/fxge/BUILD.gn
+++ b/core/fxge/BUILD.gn
@@ -55,7 +55,6 @@
"cfx_renderdevice.h",
"cfx_substfont.cpp",
"cfx_substfont.h",
- "cfx_textrenderoptions.cpp",
"cfx_textrenderoptions.h",
"cfx_unicodeencoding.cpp",
"cfx_unicodeencoding.h",
diff --git a/core/fxge/cfx_textrenderoptions.cpp b/core/fxge/cfx_textrenderoptions.cpp
deleted file mode 100644
index 6d63aeb..0000000
--- a/core/fxge/cfx_textrenderoptions.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2020 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.
-
-#include "core/fxge/cfx_textrenderoptions.h"
-
-#include "third_party/base/no_destructor.h"
-
-// static
-const CFX_TextRenderOptions& CFX_TextRenderOptions::LcdOptions() {
- static pdfium::base::NoDestructor<CFX_TextRenderOptions> instance(kLcd);
- return *instance;
-}
-
-CFX_TextRenderOptions::CFX_TextRenderOptions() = default;
-
-CFX_TextRenderOptions::CFX_TextRenderOptions(AliasingType type)
- : aliasing_type(type) {}
-
-CFX_TextRenderOptions::CFX_TextRenderOptions(
- const CFX_TextRenderOptions& other) = default;
diff --git a/core/fxge/cfx_textrenderoptions.h b/core/fxge/cfx_textrenderoptions.h
index 64136d4..b216b97 100644
--- a/core/fxge/cfx_textrenderoptions.h
+++ b/core/fxge/cfx_textrenderoptions.h
@@ -20,11 +20,10 @@
kLcd,
};
- static const CFX_TextRenderOptions& LcdOptions();
-
- CFX_TextRenderOptions();
- explicit CFX_TextRenderOptions(AliasingType type);
- CFX_TextRenderOptions(const CFX_TextRenderOptions& other);
+ constexpr CFX_TextRenderOptions() = default;
+ constexpr explicit CFX_TextRenderOptions(AliasingType type)
+ : aliasing_type(type) {}
+ constexpr CFX_TextRenderOptions(const CFX_TextRenderOptions& other) = default;
// Indicates whether anti-aliasing is enabled.
bool IsSmooth() const {
diff --git a/core/fxge/skia/fx_skia_device_embeddertest.cpp b/core/fxge/skia/fx_skia_device_embeddertest.cpp
index f35588d..136bb6b 100644
--- a/core/fxge/skia/fx_skia_device_embeddertest.cpp
+++ b/core/fxge/skia/fx_skia_device_embeddertest.cpp
@@ -59,7 +59,7 @@
CFX_Matrix matrix2;
matrix2.Translate(1, 0);
CFX_GraphStateData graphState;
- CFX_TextRenderOptions text_options;
+ static constexpr CFX_TextRenderOptions kTextOptions;
if (state.m_save == State::Save::kYes)
driver->SaveState();
if (state.m_clip != State::Clip::kNo)
@@ -70,7 +70,7 @@
BlendMode::kNormal);
} else if (state.m_graphic == State::Graphic::kText) {
driver->DrawDeviceText(SK_ARRAY_COUNT(charPos), charPos, &font, matrix,
- fontSize, 0xFF445566, text_options);
+ fontSize, 0xFF445566, kTextOptions);
}
if (state.m_save == State::Save::kYes)
driver->RestoreState(true);
@@ -94,7 +94,7 @@
BlendMode::kNormal);
} else if (state.m_graphic == State::Graphic::kText) {
driver->DrawDeviceText(SK_ARRAY_COUNT(charPos), charPos, &font, matrix2,
- fontSize, 0xFF445566, text_options);
+ fontSize, 0xFF445566, kTextOptions);
}
if (state.m_save == State::Save::kYes)
driver->RestoreState(false);
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index 5f5c26d..1e2b2a5 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -33,17 +33,11 @@
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/cfx_renderdevice.h"
-#include "core/fxge/cfx_textrenderoptions.h"
#include "core/fxge/cfx_unicodeencodingex.h"
#include "core/fxge/text_char_pos.h"
#include "fxbarcode/BC_Writer.h"
// static
-const CFX_TextRenderOptions& CBC_OneDimWriter::GetTextRenderOptions() {
- return CFX_TextRenderOptions::LcdOptions();
-}
-
-// static
bool CBC_OneDimWriter::HasValidContentSize(WideStringView contents) {
// Limit the size of 1D barcodes. Typical 1D barcodes are short so this should
// be sufficient for most use cases.
diff --git a/fxbarcode/oned/BC_OneDimWriter.h b/fxbarcode/oned/BC_OneDimWriter.h
index 0f58556..32664a0 100644
--- a/fxbarcode/oned/BC_OneDimWriter.h
+++ b/fxbarcode/oned/BC_OneDimWriter.h
@@ -11,6 +11,7 @@
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "core/fxge/cfx_textrenderoptions.h"
#include "fxbarcode/BC_Library.h"
#include "fxbarcode/BC_Writer.h"
#include "fxbarcode/utils.h"
@@ -19,11 +20,12 @@
class CFX_PathData;
class CFX_RenderDevice;
class TextCharPos;
-struct CFX_TextRenderOptions;
class CBC_OneDimWriter : public CBC_Writer {
public:
- static const CFX_TextRenderOptions& GetTextRenderOptions();
+ static constexpr CFX_TextRenderOptions GetTextRenderOptions() {
+ return CFX_TextRenderOptions(CFX_TextRenderOptions::kLcd);
+ }
static bool HasValidContentSize(WideStringView contents);
CBC_OneDimWriter();
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index e01d3bf..25e3d4b 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -70,7 +70,7 @@
RetainPtr<CFGAS_GEFont> pCurFont;
TextCharPos* pCurCP = nullptr;
int32_t iCurCount = 0;
- const CFX_TextRenderOptions& options = CFX_TextRenderOptions::LcdOptions();
+ static constexpr CFX_TextRenderOptions kOptions(CFX_TextRenderOptions::kLcd);
for (auto& pos : pCharPos) {
RetainPtr<CFGAS_GEFont> pSTFont =
pFont->GetSubstFont(static_cast<int32_t>(pos.m_GlyphIndex));
@@ -90,7 +90,7 @@
#endif
device->DrawNormalText(iCurCount, pCurCP, font, -fFontSize, matrix,
- color, options);
+ color, kOptions);
}
pCurFont = pSTFont;
pCurCP = &pos;
@@ -113,7 +113,7 @@
#endif
bRet = device->DrawNormalText(iCurCount, pCurCP, font, -fFontSize, matrix,
- color, options);
+ color, kOptions);
}
#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
device->Flush(false);