[FXCRT] Rename FXSYS_round to match conventions
Microsoft's C runtime library and POSIX both define round() as the
version for rounding doubles, and roundf() is for rounding float types.
Update the name of FXSYS_round() to FXSYS_roundf() to follow this
convention. This prevents confusion, especially once another round
version for doubles gets added.
Bug: chromium:611744
Change-Id: I54920df07f42ed16e943ca82e5cc36db0378bfa1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/60671
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_type3char.cpp b/core/fpdfapi/font/cpdf_type3char.cpp
index 7d71e8c..3ad9bba 100644
--- a/core/fpdfapi/font/cpdf_type3char.cpp
+++ b/core/fpdfapi/font/cpdf_type3char.cpp
@@ -51,11 +51,11 @@
void CPDF_Type3Char::InitializeFromStreamData(bool bColored,
const float* pData) {
m_bColored = bColored;
- m_Width = FXSYS_round(TextUnitToGlyphUnit(pData[0]));
- m_BBox.left = FXSYS_round(TextUnitToGlyphUnit(pData[2]));
- m_BBox.bottom = FXSYS_round(TextUnitToGlyphUnit(pData[3]));
- m_BBox.right = FXSYS_round(TextUnitToGlyphUnit(pData[4]));
- m_BBox.top = FXSYS_round(TextUnitToGlyphUnit(pData[5]));
+ m_Width = FXSYS_roundf(TextUnitToGlyphUnit(pData[0]));
+ m_BBox.left = FXSYS_roundf(TextUnitToGlyphUnit(pData[2]));
+ m_BBox.bottom = FXSYS_roundf(TextUnitToGlyphUnit(pData[3]));
+ m_BBox.right = FXSYS_roundf(TextUnitToGlyphUnit(pData[4]));
+ m_BBox.top = FXSYS_roundf(TextUnitToGlyphUnit(pData[5]));
}
void CPDF_Type3Char::WillBeDestroyed() {
diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp
index 7e2e59d..eae08ea 100644
--- a/core/fpdfapi/font/cpdf_type3font.cpp
+++ b/core/fpdfapi/font/cpdf_type3font.cpp
@@ -83,7 +83,7 @@
count = std::min(count, kCharLimit - StartChar);
for (size_t i = 0; i < count; i++) {
m_CharWidthL[StartChar + i] =
- FXSYS_round(CPDF_Type3Char::TextUnitToGlyphUnit(
+ FXSYS_roundf(CPDF_Type3Char::TextUnitToGlyphUnit(
pWidthArray->GetNumberAt(i) * xscale));
}
}
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index c20abba..8dba4c2 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -792,9 +792,9 @@
Cal[1] = static_cast<float>(pSrcBuf[1]) / 255;
Cal[2] = static_cast<float>(pSrcBuf[0]) / 255;
GetRGB(Cal, &R, &G, &B);
- pDestBuf[0] = FXSYS_round(B * 255);
- pDestBuf[1] = FXSYS_round(G * 255);
- pDestBuf[2] = FXSYS_round(R * 255);
+ pDestBuf[0] = FXSYS_roundf(B * 255);
+ pDestBuf[1] = FXSYS_roundf(G * 255);
+ pDestBuf[2] = FXSYS_roundf(R * 255);
pSrcBuf += 3;
pDestBuf += 3;
}
diff --git a/core/fpdfapi/page/cpdf_dibbase.cpp b/core/fpdfapi/page/cpdf_dibbase.cpp
index e23fe66..0eed6f5 100644
--- a/core/fpdfapi/page/cpdf_dibbase.cpp
+++ b/core/fpdfapi/page/cpdf_dibbase.cpp
@@ -679,8 +679,8 @@
float G;
float B;
m_pColorSpace->GetRGB(colors.data(), &R, &G, &B);
- m_MatteColor = ArgbEncode(0, FXSYS_round(R * 255), FXSYS_round(G * 255),
- FXSYS_round(B * 255));
+ m_MatteColor = ArgbEncode(0, FXSYS_roundf(R * 255), FXSYS_roundf(G * 255),
+ FXSYS_roundf(B * 255));
}
return StartLoadMaskDIB();
}
@@ -760,14 +760,14 @@
float B = 0.0f;
m_pColorSpace->GetRGB(color_values, &R, &G, &B);
- FX_ARGB argb0 = ArgbEncode(255, FXSYS_round(R * 255), FXSYS_round(G * 255),
- FXSYS_round(B * 255));
+ FX_ARGB argb0 = ArgbEncode(255, FXSYS_roundf(R * 255),
+ FXSYS_roundf(G * 255), FXSYS_roundf(B * 255));
color_values[0] += m_CompData[0].m_DecodeStep;
color_values[1] += m_CompData[0].m_DecodeStep;
color_values[2] += m_CompData[0].m_DecodeStep;
m_pColorSpace->GetRGB(color_values, &R, &G, &B);
- FX_ARGB argb1 = ArgbEncode(255, FXSYS_round(R * 255), FXSYS_round(G * 255),
- FXSYS_round(B * 255));
+ FX_ARGB argb1 = ArgbEncode(255, FXSYS_roundf(R * 255),
+ FXSYS_roundf(G * 255), FXSYS_roundf(B * 255));
if (argb0 != 0xFF000000 || argb1 != 0xFFFFFFFF) {
SetPaletteArgb(0, argb0);
SetPaletteArgb(1, argb1);
@@ -803,8 +803,8 @@
} else {
m_pColorSpace->GetRGB(color_values.data(), &R, &G, &B);
}
- SetPaletteArgb(i, ArgbEncode(255, FXSYS_round(R * 255),
- FXSYS_round(G * 255), FXSYS_round(B * 255)));
+ SetPaletteArgb(i, ArgbEncode(255, FXSYS_roundf(R * 255),
+ FXSYS_roundf(G * 255), FXSYS_roundf(B * 255)));
}
}
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.cpp b/core/fpdfapi/render/cpdf_docrenderdata.cpp
index 59a1365..f49e956 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.cpp
+++ b/core/fpdfapi/render/cpdf_docrenderdata.cpp
@@ -98,7 +98,7 @@
continue;
}
pFuncs[i]->Call(&input, 1, output, &noutput);
- size_t o = FXSYS_round(output[0] * 255);
+ size_t o = FXSYS_roundf(output[0] * 255);
if (o != v)
bIdentity = false;
samples[i][v] = o;
@@ -107,7 +107,7 @@
}
if (pFuncs[0]->CountOutputs() <= kMaxOutputs)
pFuncs[0]->Call(&input, 1, output, &noutput);
- size_t o = FXSYS_round(output[0] * 255);
+ size_t o = FXSYS_roundf(output[0] * 255);
if (o != v)
bIdentity = false;
for (auto& channel : samples)
diff --git a/core/fpdfapi/render/cpdf_imagerenderer.cpp b/core/fpdfapi/render/cpdf_imagerenderer.cpp
index 89e04b4..3277949 100644
--- a/core/fpdfapi/render/cpdf_imagerenderer.cpp
+++ b/core/fpdfapi/render/cpdf_imagerenderer.cpp
@@ -77,7 +77,7 @@
return false;
CPDF_GeneralState& state = m_pImageObject->m_GeneralState;
- m_BitmapAlpha = FXSYS_round(255 * state.GetFillAlpha());
+ m_BitmapAlpha = FXSYS_roundf(255 * state.GetFillAlpha());
m_pDIBBase = m_Loader.GetBitmap();
if (GetRenderOptions().ColorModeIs(CPDF_RenderOptions::kAlpha) &&
!m_Loader.GetMask()) {
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index b73fdff..615b583 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -125,8 +125,8 @@
float B = 0.0f;
pCS->GetRGB(result_array.data(), &R, &G, &B);
shading_steps[i] =
- FXARGB_TODIB(ArgbEncode(alpha, FXSYS_round(R * 255),
- FXSYS_round(G * 255), FXSYS_round(B * 255)));
+ FXARGB_TODIB(ArgbEncode(alpha, FXSYS_roundf(R * 255),
+ FXSYS_roundf(G * 255), FXSYS_roundf(B * 255)));
}
return shading_steps;
}
@@ -1887,7 +1887,7 @@
refTypeCache.insert(std::move(pCache));
- CFX_Point origin(FXSYS_round(matrix.e), FXSYS_round(matrix.f));
+ CFX_Point origin(FXSYS_roundf(matrix.e), FXSYS_roundf(matrix.f));
if (glyphs.empty()) {
FX_SAFE_INT32 left = origin.x;
left += pBitmap->left();
@@ -2114,8 +2114,8 @@
CFX_Matrix matrix = pattern->pattern_to_form() * mtObj2Device;
int alpha =
- FXSYS_round(255 * (bStroke ? pPageObj->m_GeneralState.GetStrokeAlpha()
- : pPageObj->m_GeneralState.GetFillAlpha()));
+ FXSYS_roundf(255 * (bStroke ? pPageObj->m_GeneralState.GetStrokeAlpha()
+ : pPageObj->m_GeneralState.GetFillAlpha()));
DrawShading(pattern, matrix, rect, alpha,
m_Options.ColorModeIs(CPDF_RenderOptions::kAlpha));
}
@@ -2130,7 +2130,7 @@
CFX_Matrix matrix = pShadingObj->matrix() * mtObj2Device;
DrawShading(pShadingObj->pattern(), matrix, rect,
- FXSYS_round(255 * pShadingObj->m_GeneralState.GetFillAlpha()),
+ FXSYS_roundf(255 * pShadingObj->m_GeneralState.GetFillAlpha()),
m_Options.ColorModeIs(CPDF_RenderOptions::kAlpha));
}
@@ -2224,8 +2224,8 @@
pPattern->bbox().top == pPattern->y_step() &&
(mtPattern2Device.IsScaled() || mtPattern2Device.Is90Rotated());
if (bAligned) {
- int orig_x = FXSYS_round(mtPattern2Device.e);
- int orig_y = FXSYS_round(mtPattern2Device.f);
+ int orig_x = FXSYS_roundf(mtPattern2Device.e);
+ int orig_y = FXSYS_roundf(mtPattern2Device.f);
min_col = (clip_box.left - orig_x) / width;
if (clip_box.left < orig_x)
min_col--;
@@ -2277,16 +2277,18 @@
int start_x;
int start_y;
if (bAligned) {
- start_x = FXSYS_round(mtPattern2Device.e) + col * width - clip_box.left;
- start_y = FXSYS_round(mtPattern2Device.f) + row * height - clip_box.top;
+ start_x =
+ FXSYS_roundf(mtPattern2Device.e) + col * width - clip_box.left;
+ start_y =
+ FXSYS_roundf(mtPattern2Device.f) + row * height - clip_box.top;
} else {
CFX_PointF original = mtPattern2Device.Transform(
CFX_PointF(col * pPattern->x_step(), row * pPattern->y_step()));
pdfium::base::CheckedNumeric<int> safeStartX =
- FXSYS_round(original.x + left_offset);
+ FXSYS_roundf(original.x + left_offset);
pdfium::base::CheckedNumeric<int> safeStartY =
- FXSYS_round(original.y + top_offset);
+ FXSYS_roundf(original.y + top_offset);
safeStartX -= clip_box.left;
safeStartY -= clip_box.top;
@@ -2575,7 +2577,7 @@
float input = (float)i / 255.0f;
int nresult;
pFunc->Call(&input, 1, results.data(), &nresult);
- transfers[i] = FXSYS_round(results[0] * 255);
+ transfers[i] = FXSYS_roundf(results[0] * 255);
}
} else {
for (int i = 0; i < 256; i++) {
diff --git a/core/fpdfapi/render/cpdf_type3cache.cpp b/core/fpdfapi/render/cpdf_type3cache.cpp
index 078bec7..41e630b 100644
--- a/core/fpdfapi/render/cpdf_type3cache.cpp
+++ b/core/fpdfapi/render/cpdf_type3cache.cpp
@@ -93,8 +93,8 @@
const CFX_Matrix* pMatrix) {
CPDF_UniqueKeyGen keygen;
keygen.Generate(
- 4, FXSYS_round(pMatrix->a * 10000), FXSYS_round(pMatrix->b * 10000),
- FXSYS_round(pMatrix->c * 10000), FXSYS_round(pMatrix->d * 10000));
+ 4, FXSYS_roundf(pMatrix->a * 10000), FXSYS_roundf(pMatrix->b * 10000),
+ FXSYS_roundf(pMatrix->c * 10000), FXSYS_roundf(pMatrix->d * 10000));
ByteString FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen);
CPDF_Type3GlyphMap* pSizeCache;
auto it = m_SizeMap.find(FaceGlyphsKey);
@@ -152,9 +152,9 @@
FXDIB_ResampleOptions(), nullptr);
top = top_line;
if (image_matrix.a < 0)
- left = FXSYS_round(image_matrix.e + image_matrix.a);
+ left = FXSYS_roundf(image_matrix.e + image_matrix.a);
else
- left = FXSYS_round(image_matrix.e);
+ left = FXSYS_roundf(image_matrix.e);
}
}
if (!pResBitmap)
diff --git a/core/fpdfapi/render/cpdf_type3glyphmap.cpp b/core/fpdfapi/render/cpdf_type3glyphmap.cpp
index 025a41f..b144991 100644
--- a/core/fpdfapi/render/cpdf_type3glyphmap.cpp
+++ b/core/fpdfapi/render/cpdf_type3glyphmap.cpp
@@ -29,7 +29,7 @@
}
if (closest_pos >= 0)
return blues->at(closest_pos);
- int new_pos = FXSYS_round(pos);
+ int new_pos = FXSYS_roundf(pos);
if (blues->size() < kType3MaxBlues)
blues->push_back(new_pos);
return new_pos;
diff --git a/core/fxcodec/progressivedecoder.cpp b/core/fxcodec/progressivedecoder.cpp
index 88a22da..4e755ed 100644
--- a/core/fxcodec/progressivedecoder.cpp
+++ b/core/fxcodec/progressivedecoder.cpp
@@ -73,7 +73,7 @@
if (pixel_weights.m_SrcStart == pixel_weights.m_SrcEnd) {
pixel_weights.m_Weights[0] = 65536;
} else {
- pixel_weights.m_Weights[1] = FXSYS_round(
+ pixel_weights.m_Weights[1] = FXSYS_roundf(
(float)(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) * 65536);
pixel_weights.m_Weights[0] = 65536 - pixel_weights.m_Weights[1];
}
@@ -121,7 +121,7 @@
break;
}
pixel_weights.m_Weights[j - start_i] =
- FXSYS_round((float)(weight * 65536));
+ FXSYS_roundf((float)(weight * 65536));
}
}
}
@@ -139,7 +139,7 @@
int pre_dest_col = 0;
for (int src_col = 0; src_col < src_len; src_col++) {
double dest_col_f = src_col * scale;
- int dest_col = FXSYS_round((float)dest_col_f);
+ int dest_col = FXSYS_roundf((float)dest_col_f);
PixelWeight* pWeight = GetPixelWeight(dest_col);
pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col;
pWeight->m_Weights[0] = 65536;
@@ -161,8 +161,8 @@
pWeight->m_SrcStart = src_col - 1;
pWeight->m_SrcEnd = src_col;
pWeight->m_Weights[0] =
- FXSYS_round((float)(((float)dest_col - (float)dest_col_index) /
- (float)dest_col_len * 65536));
+ FXSYS_roundf((float)(((float)dest_col - (float)dest_col_index) /
+ (float)dest_col_len * 65536));
pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0];
}
pre_dest_col = dest_col;
@@ -171,7 +171,7 @@
}
for (int dest_col = 0; dest_col < dest_len; dest_col++) {
double src_col_f = dest_col / scale;
- int src_col = FXSYS_round((float)src_col_f);
+ int src_col = FXSYS_roundf((float)src_col_f);
PixelWeight* pWeight = GetPixelWeight(dest_col);
pWeight->m_SrcStart = pWeight->m_SrcEnd = src_col;
pWeight->m_Weights[0] = 65536;
@@ -229,7 +229,7 @@
pWeight->m_SrcStart = start_step;
pWeight->m_SrcEnd = end_step;
pWeight->m_Weights[0] =
- FXSYS_round((float)(end_step - dest_row) / (float)length * 65536);
+ FXSYS_roundf((float)(end_step - dest_row) / (float)length * 65536);
pWeight->m_Weights[1] = 65536 - pWeight->m_Weights[0];
}
}
diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp
index 1811aab..1695287 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.cpp
+++ b/core/fxcrt/css/cfx_cssdeclaration.cpp
@@ -122,8 +122,8 @@
return false;
rgb[i] = eNumType == CFX_CSSNumberType::Percent
- ? FXSYS_round(fValue * 2.55f)
- : FXSYS_round(fValue);
+ ? FXSYS_roundf(fValue * 2.55f)
+ : FXSYS_roundf(fValue);
}
*dwColor = ArgbEncode(255, rgb[0], rgb[1], rgb[2]);
return true;
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index c6d5393..398fdff 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -264,8 +264,8 @@
}
FX_RECT CFX_FloatRect::ToRoundedFxRect() const {
- return FX_RECT(FXSYS_round(left), FXSYS_round(top), FXSYS_round(right),
- FXSYS_round(bottom));
+ return FX_RECT(FXSYS_roundf(left), FXSYS_roundf(top), FXSYS_roundf(right),
+ FXSYS_roundf(bottom));
}
FX_RECT CFX_RectF::GetOuterRect() const {
diff --git a/core/fxcrt/fx_string.cpp b/core/fxcrt/fx_string.cpp
index e41757e..590f9c8 100644
--- a/core/fxcrt/fx_string.cpp
+++ b/core/fxcrt/fx_string.cpp
@@ -101,13 +101,13 @@
f = -f;
}
int scale = 1;
- int scaled = FXSYS_round(f);
+ int scaled = FXSYS_roundf(f);
while (scaled < 100000) {
if (scale == 1000000) {
break;
}
scale *= 10;
- scaled = FXSYS_round(f * scale);
+ scaled = FXSYS_roundf(f * scale);
}
if (scaled == 0) {
return 1;
diff --git a/core/fxcrt/fx_system.cpp b/core/fxcrt/fx_system.cpp
index f8a48db..5f162bd 100644
--- a/core/fxcrt/fx_system.cpp
+++ b/core/fxcrt/fx_system.cpp
@@ -88,7 +88,7 @@
} // namespace
-int FXSYS_round(float f) {
+int FXSYS_roundf(float f) {
if (std::isnan(f))
return 0;
if (f < static_cast<float>(std::numeric_limits<int>::min()))
diff --git a/core/fxcrt/fx_system.h b/core/fxcrt/fx_system.h
index 8872c57..e6eace6 100644
--- a/core/fxcrt/fx_system.h
+++ b/core/fxcrt/fx_system.h
@@ -187,7 +187,7 @@
int32_t FXSYS_wtoi(const wchar_t* str);
int64_t FXSYS_atoi64(const char* str);
const char* FXSYS_i64toa(int64_t value, char* str, int radix);
-int FXSYS_round(float f);
+int FXSYS_roundf(float f);
#define FXSYS_sqrt2(a, b) (float)sqrt((a) * (a) + (b) * (b))
#ifdef __cplusplus
} // extern C
diff --git a/core/fxcrt/fx_system_unittest.cpp b/core/fxcrt/fx_system_unittest.cpp
index b28f18e..fd2f96e 100644
--- a/core/fxcrt/fx_system_unittest.cpp
+++ b/core/fxcrt/fx_system_unittest.cpp
@@ -74,23 +74,23 @@
} // namespace
-TEST(fxcrt, FXSYS_round) {
- EXPECT_EQ(0, FXSYS_round(0.0f));
- EXPECT_EQ(0, FXSYS_round(-0.0f));
- EXPECT_EQ(0, FXSYS_round(0.00001f));
- EXPECT_EQ(0, FXSYS_round(-0.00001f));
- EXPECT_EQ(3, FXSYS_round(3.14159f));
- EXPECT_EQ(4, FXSYS_round(3.5f));
+TEST(fxcrt, FXSYS_roundf) {
+ EXPECT_EQ(0, FXSYS_roundf(0.0f));
+ EXPECT_EQ(0, FXSYS_roundf(-0.0f));
+ EXPECT_EQ(0, FXSYS_roundf(0.00001f));
+ EXPECT_EQ(0, FXSYS_roundf(-0.00001f));
+ EXPECT_EQ(3, FXSYS_roundf(3.14159f));
+ EXPECT_EQ(4, FXSYS_roundf(3.5f));
// Check for smallest non-zero float values.
- EXPECT_EQ(0, FXSYS_round(std::numeric_limits<float>::min()));
- EXPECT_EQ(0, FXSYS_round(-std::numeric_limits<float>::min()));
+ EXPECT_EQ(0, FXSYS_roundf(std::numeric_limits<float>::min()));
+ EXPECT_EQ(0, FXSYS_roundf(-std::numeric_limits<float>::min()));
// Function is a wrapper around standard C library function round(), so
// returns the integral value that is nearest to x, with halfway cases
// rounded away from zero.
- EXPECT_EQ(-3, FXSYS_round(-3.14159f));
- EXPECT_EQ(-4, FXSYS_round(-3.5f));
+ EXPECT_EQ(-3, FXSYS_roundf(-3.14159f));
+ EXPECT_EQ(-4, FXSYS_roundf(-3.5f));
// Positive rounding stops at maximum int.
// MAX_INT=0x7FFFFFFF=2147483647=2.147483647e+9
@@ -99,13 +99,13 @@
// Going to next smallest float by minus one from exponent and mantissa of
// all ones yields binary float representation of 0x4EFFFFFF=2.14748352e+9,
// which is 2147483520.
- EXPECT_EQ(2147483520, FXSYS_round(2.14748352e+9f));
+ EXPECT_EQ(2147483520, FXSYS_roundf(2.14748352e+9f));
// Using a slightly larger value, expect to see it be capped at MAX_INT.
- EXPECT_EQ(2147483647, FXSYS_round(2.14748365e+9f));
+ EXPECT_EQ(2147483647, FXSYS_roundf(2.14748365e+9f));
- EXPECT_EQ(2147483647, FXSYS_round(2.14748365e+10f));
- EXPECT_EQ(2147483647, FXSYS_round(std::numeric_limits<float>::max()));
+ EXPECT_EQ(2147483647, FXSYS_roundf(2.14748365e+10f));
+ EXPECT_EQ(2147483647, FXSYS_roundf(std::numeric_limits<float>::max()));
// Negative rounding stops at minimum int.
// MIN_INT=0x80000000=-2147483648,=-2.147483648e+9
@@ -115,13 +115,13 @@
// smallest negative float by minus one from exponent and mantissa of all
// ones yields binary float representation of 0xCEFFFFFF=-2.14748352e+9,
// which is -2147483520.
- EXPECT_EQ(-2147483648, FXSYS_round(-2.147483648e+10f));
- EXPECT_EQ(-2147483648, FXSYS_round(-2.147483648e+9f));
- EXPECT_EQ(-2147483520, FXSYS_round(-2.14748352e+9f));
- EXPECT_EQ(-2147483648, FXSYS_round(-std::numeric_limits<float>::max()));
+ EXPECT_EQ(-2147483648, FXSYS_roundf(-2.147483648e+10f));
+ EXPECT_EQ(-2147483648, FXSYS_roundf(-2.147483648e+9f));
+ EXPECT_EQ(-2147483520, FXSYS_roundf(-2.14748352e+9f));
+ EXPECT_EQ(-2147483648, FXSYS_roundf(-std::numeric_limits<float>::max()));
// NaN should give zero.
- EXPECT_EQ(0, FXSYS_round(NAN));
+ EXPECT_EQ(0, FXSYS_roundf(NAN));
}
TEST(fxcrt, FXSYS_itoa_InvalidRadix) {
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index b431cc2..c2c0ec0 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -918,10 +918,10 @@
glyph.m_fOrigin = text2Device.Transform(charpos.m_Origin);
if (anti_alias < FT_RENDER_MODE_LCD)
- glyph.m_Origin.x = FXSYS_round(glyph.m_fOrigin.x);
+ glyph.m_Origin.x = FXSYS_roundf(glyph.m_fOrigin.x);
else
glyph.m_Origin.x = static_cast<int>(floor(glyph.m_fOrigin.x));
- glyph.m_Origin.y = FXSYS_round(glyph.m_fOrigin.y);
+ glyph.m_Origin.y = FXSYS_roundf(glyph.m_fOrigin.y);
if (charpos.m_bGlyphAdjust) {
CFX_Matrix new_matrix(
diff --git a/core/fxge/dib/cfx_cmyk_to_srgb.cpp b/core/fxge/dib/cfx_cmyk_to_srgb.cpp
index 3441373..d75987c 100644
--- a/core/fxge/dib/cfx_cmyk_to_srgb.cpp
+++ b/core/fxge/dib/cfx_cmyk_to_srgb.cpp
@@ -1725,11 +1725,11 @@
float m,
float y,
float k) {
- // Convert to uint8_t with round-to-nearest. Avoid using FXSYS_round because
+ // Convert to uint8_t with round-to-nearest. Avoid using FXSYS_roundf because
// it is incredibly expensive with VC++ (tested on VC++ 2015) because round()
// is very expensive.
// The 'magic' value of 0.49999997f, the float that precedes 0.5f, was chosen
- // because it gives identical results to FXSYS_round(). Using the constant
+ // because it gives identical results to FXSYS_roundf(). Using the constant
// 0.5f gives different results (1 instead of 0) for one value, 0.0019607842.
// That value is close to the cusp but zero is the correct answer, and
// getting the same answer as before is desirable.
@@ -1740,10 +1740,10 @@
uint8_t y1 = static_cast<int>(y * 255.f + rounding_offset);
uint8_t k1 = static_cast<int>(k * 255.f + rounding_offset);
- ASSERT(c1 == FXSYS_round(c * 255));
- ASSERT(m1 == FXSYS_round(m * 255));
- ASSERT(y1 == FXSYS_round(y * 255));
- ASSERT(k1 == FXSYS_round(k * 255));
+ ASSERT(c1 == FXSYS_roundf(c * 255));
+ ASSERT(m1 == FXSYS_roundf(m * 255));
+ ASSERT(y1 == FXSYS_roundf(y * 255));
+ ASSERT(k1 == FXSYS_roundf(k * 255));
uint8_t r;
uint8_t g;
diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp
index 8de9f0a..2dd8ee1 100644
--- a/core/fxge/dib/cfx_imagetransformer.cpp
+++ b/core/fxge/dib/cfx_imagetransformer.cpp
@@ -155,12 +155,12 @@
class CPDF_FixedMatrix {
public:
explicit CPDF_FixedMatrix(const CFX_Matrix& src)
- : a(FXSYS_round(src.a * kBase)),
- b(FXSYS_round(src.b * kBase)),
- c(FXSYS_round(src.c * kBase)),
- d(FXSYS_round(src.d * kBase)),
- e(FXSYS_round(src.e * kBase)),
- f(FXSYS_round(src.f * kBase)) {}
+ : a(FXSYS_roundf(src.a * kBase)),
+ b(FXSYS_roundf(src.b * kBase)),
+ c(FXSYS_roundf(src.c * kBase)),
+ d(FXSYS_roundf(src.d * kBase)),
+ e(FXSYS_roundf(src.e * kBase)),
+ f(FXSYS_roundf(src.f * kBase)) {}
void Transform(int x, int y, int* x1, int* y1) const {
std::pair<float, float> val = TransformInternal(x, y);
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index 35275dd..95f2c83 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -75,9 +75,9 @@
pixel_weights.m_Weights[0] = 65536;
} else {
pixel_weights.m_Weights[1] =
- FXSYS_round(static_cast<float>(
- src_pos - pixel_weights.m_SrcStart - 1.0f / 2) *
- 65536);
+ FXSYS_roundf(static_cast<float>(
+ src_pos - pixel_weights.m_SrcStart - 1.0f / 2) *
+ 65536);
pixel_weights.m_Weights[0] = 65536 - pixel_weights.m_Weights[1];
}
} else if (options.bInterpolateBicubic) {
@@ -94,7 +94,7 @@
pixel_weights.m_SrcStart = src_min;
}
pixel_weights.m_SrcEnd = std::min(pixel_weights.m_SrcEnd, src_max - 1);
- int weight = FXSYS_round(
+ int weight = FXSYS_roundf(
static_cast<float>(src_pos - pixel_weights.m_SrcStart - 1.0f / 2) *
256);
if (start == end) {
@@ -201,7 +201,7 @@
if (idx >= GetPixelWeightSize())
return false;
- pixel_weights.m_Weights[idx] = FXSYS_round(weight * 65536);
+ pixel_weights.m_Weights[idx] = FXSYS_roundf(weight * 65536);
}
}
return true;
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index 7d57f40..4f20d68 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -132,7 +132,7 @@
if (!pGraphState->m_DashArray.empty()) {
dashes.resize(pGraphState->m_DashArray.size());
for (size_t i = 0; i < pGraphState->m_DashArray.size(); i++) {
- dashes[i] = FXSYS_round(
+ dashes[i] = FXSYS_roundf(
pMatrix ? pMatrix->TransformDistance(pGraphState->m_DashArray[i])
: pGraphState->m_DashArray[i]);
dashes[i] = std::max(dashes[i], 1U);
@@ -158,7 +158,7 @@
if (pMatrix)
pos = pMatrix->Transform(pos);
- CFX_Point screen(FXSYS_round(pos.x), FXSYS_round(pos.y));
+ CFX_Point screen(FXSYS_roundf(pos.x), FXSYS_roundf(pos.y));
FXPT_TYPE point_type = pPoints[i].m_Type;
if (point_type == FXPT_TYPE::MoveTo) {
MoveToEx(hDC, screen.x, screen.y, nullptr);
@@ -176,15 +176,15 @@
if (pMatrix)
pos = pMatrix->Transform(pos);
- lppt[1].x = FXSYS_round(pos.x);
- lppt[1].y = FXSYS_round(pos.y);
+ lppt[1].x = FXSYS_roundf(pos.x);
+ lppt[1].y = FXSYS_roundf(pos.y);
pos = pPoints[i + 2].m_Point;
if (pMatrix)
pos = pMatrix->Transform(pos);
- lppt[2].x = FXSYS_round(pos.x);
- lppt[2].y = FXSYS_round(pos.y);
+ lppt[2].x = FXSYS_roundf(pos.x);
+ lppt[2].y = FXSYS_roundf(pos.y);
PolyBezierTo(hDC, lppt, 3);
i += 2;
}
@@ -946,8 +946,8 @@
}
}
- MoveToEx(m_hDC, FXSYS_round(x1), FXSYS_round(y1), nullptr);
- LineTo(m_hDC, FXSYS_round(x2), FXSYS_round(y2));
+ MoveToEx(m_hDC, FXSYS_roundf(x1), FXSYS_roundf(y1), nullptr);
+ LineTo(m_hDC, FXSYS_roundf(x2), FXSYS_roundf(y2));
}
bool CGdiDeviceDriver::DrawPath(const CFX_PathData* pPathData,
@@ -1125,8 +1125,8 @@
HPEN hPen = CreatePen(PS_SOLID, 1, colorref);
hPen = (HPEN)SelectObject(m_hDC, hPen);
- MoveToEx(m_hDC, FXSYS_round(ptMoveTo.x), FXSYS_round(ptMoveTo.y), nullptr);
- LineTo(m_hDC, FXSYS_round(ptLineTo.x), FXSYS_round(ptLineTo.y));
+ MoveToEx(m_hDC, FXSYS_roundf(ptMoveTo.x), FXSYS_roundf(ptMoveTo.y), nullptr);
+ LineTo(m_hDC, FXSYS_roundf(ptLineTo.x), FXSYS_roundf(ptLineTo.y));
hPen = (HPEN)SelectObject(m_hDC, hPen);
DeleteObject(hPen);
return true;
diff --git a/core/fxge/win32/fx_win32_gdipext.cpp b/core/fxge/win32/fx_win32_gdipext.cpp
index 0b6667b..892c840 100644
--- a/core/fxge/win32/fx_win32_gdipext.cpp
+++ b/core/fxge/win32/fx_win32_gdipext.cpp
@@ -906,9 +906,10 @@
std::tie(v1, v2) = indices.value();
Gdiplus::GpPen* pPen = nullptr;
CallFunc(GdipCreatePen1)(fill_argb, 1.0f, Gdiplus::UnitPixel, &pPen);
- CallFunc(GdipDrawLineI)(
- pGraphics, pPen, FXSYS_round(points[v1].X), FXSYS_round(points[v1].Y),
- FXSYS_round(points[v2].X), FXSYS_round(points[v2].Y));
+ CallFunc(GdipDrawLineI)(pGraphics, pPen, FXSYS_roundf(points[v1].X),
+ FXSYS_roundf(points[v1].Y),
+ FXSYS_roundf(points[v2].X),
+ FXSYS_roundf(points[v2].Y));
CallFunc(GdipDeletePen)(pPen);
return true;
}
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index 9ed2426..be80e83 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -305,7 +305,7 @@
// error for calculating the next spacing value.
float fOriginX = charpos.m_Origin.x * kScaleFactor;
float fPixelSpacing = fOriginX - fPreviousOriginX;
- spacing[i] = FXSYS_round(fPixelSpacing);
+ spacing[i] = FXSYS_roundf(fPixelSpacing);
fPreviousOriginX = fOriginX - (fPixelSpacing - spacing[i]);
wsText += charpos.m_GlyphIndex;
@@ -641,7 +641,7 @@
// preserved in the text location. clrf characters seem to be ignored by
// label printers that use this driver.
float fOffsetY = mtObject2Device.f * kScaleFactor;
- if (m_SetOrigin && FXSYS_round(m_OriginY) != FXSYS_round(fOffsetY)) {
+ if (m_SetOrigin && FXSYS_roundf(m_OriginY) != FXSYS_roundf(fOffsetY)) {
wsText += L"\r\n";
totalLength += 2;
}
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index 0e96a3d..40d58a4 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -790,8 +790,8 @@
if (!pos)
return false;
- *device_x = FXSYS_round(pos->x);
- *device_y = FXSYS_round(pos->y);
+ *device_x = FXSYS_roundf(pos->x);
+ *device_y = FXSYS_roundf(pos->y);
return true;
}
diff --git a/fxjs/xfa/cjx_layoutpseudomodel.cpp b/fxjs/xfa/cjx_layoutpseudomodel.cpp
index 8642ce4..0fdcb5f 100644
--- a/fxjs/xfa/cjx_layoutpseudomodel.cpp
+++ b/fxjs/xfa/cjx_layoutpseudomodel.cpp
@@ -133,7 +133,7 @@
float fValue = measure.ToUnit(eUnit);
return CJS_Result::Success(
- runtime->NewNumber(FXSYS_round(fValue * 1000) / 1000.0f));
+ runtime->NewNumber(FXSYS_roundf(fValue * 1000) / 1000.0f));
}
CJS_Result CJX_LayoutPseudoModel::h(
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 73a730d..e509d15 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -233,8 +233,8 @@
break;
case XFA_AttributeType::Integer:
SetInteger(eAttr,
- FXSYS_round(FXSYS_wcstof(wsValue.unterminated_c_str(),
- wsValue.GetLength(), nullptr)),
+ FXSYS_roundf(FXSYS_wcstof(wsValue.unterminated_c_str(),
+ wsValue.GetLength(), nullptr)),
bNotify);
break;
case XFA_AttributeType::Measure:
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index 39fcf20..5616d8d 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -365,7 +365,7 @@
int32_t* pPieceWidths) {
float fLineStep = (m_fLineSpace > m_fFontSize) ? m_fLineSpace : m_fFontSize;
bool bNeedReload = false;
- int32_t iLineWidth = FXSYS_round(rect.Width() * 20000.0f);
+ int32_t iLineWidth = FXSYS_roundf(rect.Width() * 20000.0f);
int32_t iCount = m_pTxtBreak->CountBreakPieces();
for (int32_t i = 0; i < iCount; i++) {
const CFX_BreakPiece* pPiece = m_pTxtBreak->GetBreakPieceUnstable(i);
diff --git a/xfa/fgas/crt/cfgas_decimal.cpp b/xfa/fgas/crt/cfgas_decimal.cpp
index 701cda8..6a8a759 100644
--- a/xfa/fgas/crt/cfgas_decimal.cpp
+++ b/xfa/fgas/crt/cfgas_decimal.cpp
@@ -280,7 +280,7 @@
newval = fmodf(newval, 1.0f);
}
- plo += FXSYS_round(newval);
+ plo += FXSYS_roundf(newval);
decimal_helper_normalize(phi, pmid, plo);
m_uHi = static_cast<uint32_t>(phi);
m_uMid = static_cast<uint32_t>(pmid);
diff --git a/xfa/fgas/layout/cfx_break.cpp b/xfa/fgas/layout/cfx_break.cpp
index 46a854d..73fafc8 100644
--- a/xfa/fgas/layout/cfx_break.cpp
+++ b/xfa/fgas/layout/cfx_break.cpp
@@ -62,7 +62,7 @@
}
void CFX_Break::SetFontSize(float fFontSize) {
- int32_t iFontSize = FXSYS_round(fFontSize * 20.0f);
+ int32_t iFontSize = FXSYS_roundf(fFontSize * 20.0f);
if (m_iFontSize == iFontSize)
return;
@@ -105,7 +105,7 @@
// in for the RTFBreak code for consistency. If we see issues with tab widths
// we may need to fix this.
m_iTabWidth =
- std::max(FXSYS_round(fTabWidth * kConversionFactor), kMinimumTabWidth);
+ std::max(FXSYS_roundf(fTabWidth * kConversionFactor), kMinimumTabWidth);
}
void CFX_Break::SetDefaultChar(wchar_t wch) {
@@ -128,19 +128,19 @@
}
void CFX_Break::SetLineBreakTolerance(float fTolerance) {
- m_iTolerance = FXSYS_round(fTolerance * kConversionFactor);
+ m_iTolerance = FXSYS_roundf(fTolerance * kConversionFactor);
}
void CFX_Break::SetCharSpace(float fCharSpace) {
- m_iCharSpace = FXSYS_round(fCharSpace * kConversionFactor);
+ m_iCharSpace = FXSYS_roundf(fCharSpace * kConversionFactor);
}
void CFX_Break::SetLineBoundary(float fLineStart, float fLineEnd) {
if (fLineStart > fLineEnd)
return;
- m_iLineStart = FXSYS_round(fLineStart * kConversionFactor);
- m_iLineWidth = FXSYS_round(fLineEnd * kConversionFactor);
+ m_iLineStart = FXSYS_roundf(fLineStart * kConversionFactor);
+ m_iLineWidth = FXSYS_roundf(fLineEnd * kConversionFactor);
m_pCurLine->m_iStart = std::min(m_pCurLine->m_iStart, m_iLineWidth);
m_pCurLine->m_iStart = std::max(m_pCurLine->m_iStart, m_iLineStart);
}
diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp
index 2a09810..72191ce 100644
--- a/xfa/fgas/layout/cfx_rtfbreak.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak.cpp
@@ -31,7 +31,7 @@
CFX_RTFBreak::~CFX_RTFBreak() {}
void CFX_RTFBreak::SetLineStartPos(float fLinePos) {
- int32_t iLinePos = FXSYS_round(fLinePos * kConversionFactor);
+ int32_t iLinePos = FXSYS_roundf(fLinePos * kConversionFactor);
iLinePos = std::min(iLinePos, m_iLineWidth);
iLinePos = std::max(iLinePos, m_iLineStart);
m_pCurLine->m_iStart = iLinePos;
@@ -39,7 +39,7 @@
void CFX_RTFBreak::AddPositionedTab(float fTabPos) {
int32_t iTabPos = std::min(
- FXSYS_round(fTabPos * kConversionFactor) + m_iLineStart, m_iLineWidth);
+ FXSYS_roundf(fTabPos * kConversionFactor) + m_iLineStart, m_iLineWidth);
auto it = std::lower_bound(m_PositionedTabs.begin(), m_PositionedTabs.end(),
iTabPos);
if (it != m_PositionedTabs.end() && *it == iTabPos)
@@ -730,7 +730,7 @@
CFX_RectF rtText(pPiece->rtPiece);
bool bRTLPiece = FX_IsOdd(pPiece->iBidiLevel);
float fFontSize = pPiece->fFontSize;
- int32_t iFontSize = FXSYS_round(fFontSize * 20.0f);
+ int32_t iFontSize = FXSYS_roundf(fFontSize * 20.0f);
if (iFontSize == 0)
return 0;
diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp
index b347ec7..392b422 100644
--- a/xfa/fgas/layout/cfx_txtbreak.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak.cpp
@@ -34,7 +34,7 @@
CFX_TxtBreak::~CFX_TxtBreak() {}
void CFX_TxtBreak::SetLineWidth(float fLineWidth) {
- m_iLineWidth = FXSYS_round(fLineWidth * kConversionFactor);
+ m_iLineWidth = FXSYS_roundf(fLineWidth * kConversionFactor);
ASSERT(m_iLineWidth >= 20000);
}
@@ -45,7 +45,7 @@
}
void CFX_TxtBreak::SetCombWidth(float fCombWidth) {
- m_iCombWidth = FXSYS_round(fCombWidth * kConversionFactor);
+ m_iCombWidth = FXSYS_roundf(fCombWidth * kConversionFactor);
}
void CFX_TxtBreak::AppendChar_Combination(CFX_Char* pCurChar) {
@@ -672,7 +672,7 @@
CFX_RectF rtText(*pTxtRun->pRect);
bool bRTLPiece = (pTxtRun->dwCharStyles & FX_TXTCHARSTYLE_OddBidiLevel) != 0;
float fFontSize = pTxtRun->fFontSize;
- int32_t iFontSize = FXSYS_round(fFontSize * 20.0f);
+ int32_t iFontSize = FXSYS_roundf(fFontSize * 20.0f);
int32_t iAscent = pFont->GetAscent();
int32_t iDescent = pFont->GetDescent();
int32_t iMaxHeight = iAscent - iDescent;
diff --git a/xfa/fwl/cfwl_checkbox.cpp b/xfa/fwl/cfwl_checkbox.cpp
index f3ff43f..1342554 100644
--- a/xfa/fwl/cfwl_checkbox.cpp
+++ b/xfa/fwl/cfwl_checkbox.cpp
@@ -116,9 +116,9 @@
void CFWL_CheckBox::Layout() {
m_pProperties->m_rtWidget.width =
- FXSYS_round(m_pProperties->m_rtWidget.width);
+ FXSYS_roundf(m_pProperties->m_rtWidget.width);
m_pProperties->m_rtWidget.height =
- FXSYS_round(m_pProperties->m_rtWidget.height);
+ FXSYS_roundf(m_pProperties->m_rtWidget.height);
m_rtClient = GetClientRect();
float fTextLeft = m_rtClient.left + m_fBoxHeight;
diff --git a/xfa/fxgraphics/cxfa_graphics.cpp b/xfa/fxgraphics/cxfa_graphics.cpp
index bd8bf28..ff6bac1 100644
--- a/xfa/fxgraphics/cxfa_graphics.cpp
+++ b/xfa/fxgraphics/cxfa_graphics.cpp
@@ -196,8 +196,8 @@
void CXFA_Graphics::SetClipRect(const CFX_RectF& rect) {
m_renderDevice->SetClip_Rect(
- FX_RECT(FXSYS_round(rect.left), FXSYS_round(rect.top),
- FXSYS_round(rect.right()), FXSYS_round(rect.bottom())));
+ FX_RECT(FXSYS_roundf(rect.left), FXSYS_roundf(rect.top),
+ FXSYS_roundf(rect.right()), FXSYS_roundf(rect.bottom())));
}
CFX_RenderDevice* CXFA_Graphics::GetRenderDevice() {