Revert "Properly write floats in CFX_PSRenderer."
This reverts commit ee77d51f44302fa2dfba90d950bf37e91c5ec236.
Reason for revert: Unlike PDFs, PostScript supports numbers in exponential format.
Original change's description:
> Properly write floats in CFX_PSRenderer.
>
> Use WriteFloat() and friends to write out float, CFX_Matrix, and
> CFX_PointF values properly to a PostScript stream. Move
> cpdf_contentstream_write_utils.* from core/fpdfapi/edit/ to core/fxge/
> to make the layering work correctly.
>
> This fixes a variant of https:://crbug.com/pdfium/937
>
> Change-Id: I58afaeee4161493e0fb5a6103f423e2783a064fd
> Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/63471
> Reviewed-by: Tom Sepez <tsepez@chromium.org>
> Commit-Queue: Lei Zhang <thestig@chromium.org>
TBR=thestig@chromium.org,tsepez@chromium.org
Change-Id: I2d379f2ad344c17d770640efeaa5d5981767fbf8
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/63530
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/edit/BUILD.gn b/core/fpdfapi/edit/BUILD.gn
index 7e2528a..b83b89a 100644
--- a/core/fpdfapi/edit/BUILD.gn
+++ b/core/fpdfapi/edit/BUILD.gn
@@ -7,6 +7,8 @@
source_set("edit") {
sources = [
+ "cpdf_contentstream_write_utils.cpp",
+ "cpdf_contentstream_write_utils.h",
"cpdf_creator.cpp",
"cpdf_creator.h",
"cpdf_pagecontentgenerator.cpp",
@@ -19,6 +21,7 @@
configs += [ "../../../:pdfium_core_config" ]
deps = [
"../../../constants",
+ "../../../third_party:skia_shared",
"../../fxcrt",
"../../fxge",
"../font",
diff --git a/core/fpdfapi/edit/DEPS b/core/fpdfapi/edit/DEPS
new file mode 100644
index 0000000..bcfd0a2
--- /dev/null
+++ b/core/fpdfapi/edit/DEPS
@@ -0,0 +1,5 @@
+specific_include_rules = {
+ "cpdf_contentstream_write_utils.cpp": [
+ '+third_party/skia_shared',
+ ]
+}
diff --git a/core/fxge/cfx_contentstream_write_utils.cpp b/core/fpdfapi/edit/cpdf_contentstream_write_utils.cpp
similarity index 93%
rename from core/fxge/cfx_contentstream_write_utils.cpp
rename to core/fpdfapi/edit/cpdf_contentstream_write_utils.cpp
index f06c039..28165b1 100644
--- a/core/fxge/cfx_contentstream_write_utils.cpp
+++ b/core/fpdfapi/edit/cpdf_contentstream_write_utils.cpp
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/fxge/cfx_contentstream_write_utils.h"
+#include "core/fpdfapi/edit/cpdf_contentstream_write_utils.h"
#include "third_party/skia_shared/SkFloatToDecimal.h"
diff --git a/core/fxge/cfx_contentstream_write_utils.h b/core/fpdfapi/edit/cpdf_contentstream_write_utils.h
similarity index 69%
rename from core/fxge/cfx_contentstream_write_utils.h
rename to core/fpdfapi/edit/cpdf_contentstream_write_utils.h
index 2e94295..3e14c9f 100644
--- a/core/fxge/cfx_contentstream_write_utils.h
+++ b/core/fpdfapi/edit/cpdf_contentstream_write_utils.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CORE_FXGE_CFX_CONTENTSTREAM_WRITE_UTILS_H_
-#define CORE_FXGE_CFX_CONTENTSTREAM_WRITE_UTILS_H_
+#ifndef CORE_FPDFAPI_EDIT_CPDF_CONTENTSTREAM_WRITE_UTILS_H_
+#define CORE_FPDFAPI_EDIT_CPDF_CONTENTSTREAM_WRITE_UTILS_H_
#include <ostream>
@@ -13,4 +13,4 @@
std::ostream& operator<<(std::ostream& ar, const CFX_Matrix& matrix);
std::ostream& operator<<(std::ostream& ar, const CFX_PointF& point);
-#endif // CORE_FXGE_CFX_CONTENTSTREAM_WRITE_UTILS_H_
+#endif // CORE_FPDFAPI_EDIT_CPDF_CONTENTSTREAM_WRITE_UTILS_H_
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index a67697a..c804c05 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -12,6 +12,7 @@
#include <tuple>
#include <utility>
+#include "core/fpdfapi/edit/cpdf_contentstream_write_utils.h"
#include "core/fpdfapi/edit/cpdf_pagecontentmanager.h"
#include "core/fpdfapi/edit/cpdf_stringarchivestream.h"
#include "core/fpdfapi/font/cpdf_truetypefont.h"
@@ -33,7 +34,6 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
-#include "core/fxge/cfx_contentstream_write_utils.h"
#include "core/fxge/render_defines.h"
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn
index ead8abe..ad47e0a 100644
--- a/core/fxge/BUILD.gn
+++ b/core/fxge/BUILD.gn
@@ -22,8 +22,6 @@
"cfx_cliprgn.h",
"cfx_color.cpp",
"cfx_color.h",
- "cfx_contentstream_write_utils.cpp",
- "cfx_contentstream_write_utils.h",
"cfx_defaultrenderdevice.h",
"cfx_face.cpp",
"cfx_face.h",
@@ -121,7 +119,6 @@
]
deps = [
- "../../third_party:skia_shared",
"../fxcrt",
]
diff --git a/core/fxge/DEPS b/core/fxge/DEPS
index f02b93c..6492756 100644
--- a/core/fxge/DEPS
+++ b/core/fxge/DEPS
@@ -1,9 +1,3 @@
include_rules = [
'+third_party/skia/include'
]
-
-specific_include_rules = {
- "cfx_contentstream_write_utils.cpp": [
- '+third_party/skia_shared',
- ]
-}
diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp
index 237c9f8..f9f7de2 100644
--- a/core/fxge/win32/cfx_psrenderer.cpp
+++ b/core/fxge/win32/cfx_psrenderer.cpp
@@ -12,7 +12,6 @@
#include <utility>
#include "core/fxcrt/maybe_owned.h"
-#include "core/fxge/cfx_contentstream_write_utils.h"
#include "core/fxge/cfx_fontcache.h"
#include "core/fxge/cfx_gemodule.h"
#include "core/fxge/cfx_glyphcache.h"
@@ -122,7 +121,7 @@
if (pObject2Device)
pos = pObject2Device->Transform(pos);
- buf << pos;
+ buf << pos.x << " " << pos.y;
switch (type) {
case FXPT_TYPE::MoveTo:
buf << " m ";
@@ -139,7 +138,8 @@
pos1 = pObject2Device->Transform(pos1);
pos2 = pObject2Device->Transform(pos2);
}
- buf << " " << pos1 << " " << pos2 << " c";
+ buf << " " << pos1.x << " " << pos1.y << " " << pos2.x << " " << pos2.y
+ << " c";
if (closing)
buf << " h";
buf << "\n";
@@ -178,7 +178,9 @@
SetGraphState(pGraphState);
std::ostringstream buf;
- buf << "mx Cm [" << *pObject2Device << "]cm ";
+ buf << "mx Cm [" << pObject2Device->a << " " << pObject2Device->b << " "
+ << pObject2Device->c << " " << pObject2Device->d << " "
+ << pObject2Device->e << " " << pObject2Device->f << "]cm ";
WriteToStream(&buf);
OutputPath(pPathData, nullptr);
@@ -209,7 +211,9 @@
SetGraphState(pGraphState);
if (pObject2Device) {
std::ostringstream buf;
- buf << "mx Cm [" << *pObject2Device << "]cm ";
+ buf << "mx Cm [" << pObject2Device->a << " " << pObject2Device->b << " "
+ << pObject2Device->c << " " << pObject2Device->d << " "
+ << pObject2Device->e << " " << pObject2Device->f << "]cm ";
WriteToStream(&buf);
}
}
@@ -250,10 +254,9 @@
if (!m_bGraphStateSet ||
m_CurGraphState.m_DashArray != pGraphState->m_DashArray) {
buf << "[";
- for (float dash : pGraphState->m_DashArray)
- WriteFloat(buf, dash);
- buf << "]";
- WriteFloat(buf, pGraphState->m_DashPhase) << " d\n";
+ for (const auto& dash : pGraphState->m_DashArray)
+ buf << dash << " ";
+ buf << "]" << pGraphState->m_DashPhase << " d\n";
}
if (!m_bGraphStateSet ||
m_CurGraphState.m_LineJoin != pGraphState->m_LineJoin) {
@@ -261,11 +264,11 @@
}
if (!m_bGraphStateSet ||
m_CurGraphState.m_LineWidth != pGraphState->m_LineWidth) {
- WriteFloat(buf, pGraphState->m_LineWidth) << " w\n";
+ buf << pGraphState->m_LineWidth << " w\n";
}
if (!m_bGraphStateSet ||
m_CurGraphState.m_MiterLimit != pGraphState->m_MiterLimit) {
- WriteFloat(buf, pGraphState->m_MiterLimit) << " M\n";
+ buf << pGraphState->m_MiterLimit << " M\n";
}
m_CurGraphState = *pGraphState;
m_bGraphStateSet = true;
@@ -313,7 +316,8 @@
m_pStream->WriteString("q\n");
std::ostringstream buf;
- buf << "[" << matrix << "]cm ";
+ buf << "[" << matrix.a << " " << matrix.b << " " << matrix.c << " "
+ << matrix.d << " " << matrix.e << " " << matrix.f << "]cm ";
int width = pSource->GetWidth();
int height = pSource->GetHeight();
@@ -444,14 +448,13 @@
if (bCMYK != m_bCmykOutput || !m_bColorSet || m_LastColor != color) {
std::ostringstream buf;
if (bCMYK) {
- WriteFloat(buf, FXSYS_GetCValue(color) / 255.0f) << " ";
- WriteFloat(buf, FXSYS_GetMValue(color) / 255.0f) << " ";
- WriteFloat(buf, FXSYS_GetYValue(color) / 255.0f) << " ";
- WriteFloat(buf, FXSYS_GetKValue(color) / 255.0f) << " k\n";
+ buf << FXSYS_GetCValue(color) / 255.0 << " "
+ << FXSYS_GetMValue(color) / 255.0 << " "
+ << FXSYS_GetYValue(color) / 255.0 << " "
+ << FXSYS_GetKValue(color) / 255.0 << " k\n";
} else {
- WriteFloat(buf, FXARGB_R(color) / 255.0f) << " ";
- WriteFloat(buf, FXARGB_G(color) / 255.0f) << " ";
- WriteFloat(buf, FXARGB_B(color) / 255.0f) << " rg\n";
+ buf << FXARGB_R(color) / 255.0 << " " << FXARGB_G(color) / 255.0 << " "
+ << FXARGB_B(color) / 255.0 << " rg\n";
}
if (bCMYK == m_bCmykOutput) {
m_bColorSet = true;
@@ -545,17 +548,18 @@
CFX_PointF point = TransformedPath.GetPoint(p);
switch (TransformedPath.GetType(p)) {
case FXPT_TYPE::MoveTo: {
- buf << point << " m\n";
+ buf << point.x << " " << point.y << " m\n";
break;
}
case FXPT_TYPE::LineTo: {
- buf << point << " l\n";
+ buf << point.x << " " << point.y << " l\n";
break;
}
case FXPT_TYPE::BezierTo: {
CFX_PointF point1 = TransformedPath.GetPoint(p + 1);
CFX_PointF point2 = TransformedPath.GetPoint(p + 2);
- buf << point << " " << point1 << " " << point2 << " c\n";
+ buf << point.x << " " << point.y << " " << point1.x << " " << point1.y
+ << " " << point2.x << " " << point2.y << " c\n";
p += 2;
break;
}
@@ -593,7 +597,9 @@
SetColor(color);
std::ostringstream buf;
- buf << "q[" << mtObject2Device << "]cm\n";
+ buf << "q[" << mtObject2Device.a << " " << mtObject2Device.b << " "
+ << mtObject2Device.c << " " << mtObject2Device.d << " "
+ << mtObject2Device.e << " " << mtObject2Device.f << "]cm\n";
CFX_FontCache* pCache = CFX_GEModule::Get()->GetFontCache();
RetainPtr<CFX_GlyphCache> pGlyphCache = pCache->GetGlyphCache(pFont);
@@ -606,7 +612,7 @@
buf << "/X" << ps_fontnum << " Ff " << font_size << " Fs Sf ";
last_fontnum = ps_fontnum;
}
- buf << pCharPos[i].m_Origin << " m";
+ buf << pCharPos[i].m_Origin.x << " " << pCharPos[i].m_Origin.y << " m";
ByteString hex = ByteString::Format("<%02X>", ps_glyphindex);
buf << hex.AsStringView() << "Tj\n";
}
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index 374e103..424e1b4 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -14,6 +14,7 @@
#include "constants/annotation_common.h"
#include "constants/annotation_flags.h"
#include "constants/page_object.h"
+#include "core/fpdfapi/edit/cpdf_contentstream_write_utils.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/page/cpdf_pageobject.h"
#include "core/fpdfapi/parser/cpdf_array.h"
@@ -25,7 +26,6 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfdoc/cpdf_annot.h"
-#include "core/fxge/cfx_contentstream_write_utils.h"
#include "fpdfsdk/cpdfsdk_helpers.h"
enum FPDF_TYPE { MAX, MIN };
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index 3670533..496b89e 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -11,6 +11,7 @@
#include <vector>
#include "constants/page_object.h"
+#include "core/fpdfapi/edit/cpdf_contentstream_write_utils.h"
#include "core/fpdfapi/page/cpdf_clippath.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/page/cpdf_pageobject.h"
@@ -21,7 +22,6 @@
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
-#include "core/fxge/cfx_contentstream_write_utils.h"
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/render_defines.h"
#include "fpdfsdk/cpdfsdk_helpers.h"
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp
index e5caa5a..fbf3897 100644
--- a/fpdfsdk/fpdf_view_embeddertest.cpp
+++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -1226,11 +1226,9 @@
"q\n"
"Q\n"
"q\n"
- "281 106.700012 m "
- "331 106.700012 l 331 56.700012 l 281 56.700012 l 281 106.700012 l "
- "h W* n\n"
+ "281 106.7 m 331 106.7 l 331 56.7 l 281 56.7 l 281 106.7 l h W* n\n"
"q\n"
- "[49.900002 0 0 -50 281.10001 106.599976]cm 50 50 8[50 0 0 -50 0 "
+ "[49.9 0 0 -50 281.1 106.6]cm 50 50 8[50 0 0 -50 0 "
"50]currentfile/ASCII85Decode filter /DCTDecode filter false 3 "
"colorimage\n"
"s4IA0!\"_al8O`[\\!<<*#!!*'\"s4[N@!!ic5#6k>;#6tJ?#m^kH'FbHY$Odmc'+Yct)"
@@ -1295,9 +1293,9 @@
q
Q
q
-281 106.700012 m 331 106.700012 l 331 56.700012 l 281 56.700012 l 281 106.700012 l h W* n
+281 106.7 m 331 106.7 l 331 56.7 l 281 56.7 l 281 106.7 l h W* n
q
-[49.900002 0 0 -50 281.10001 106.599976]cm 50 50 8[50 0 0 -50 0 50]currentfile/ASCII85Decode filter /FlateDecode filter false 3 colorimage
+[49.9 0 0 -50 281.1 106.6]cm 50 50 8[50 0 0 -50 0 50]currentfile/ASCII85Decode filter /FlateDecode filter false 3 colorimage
Gb"0;0`_7S!5bE%:[N')TE"rlzGQSs[!!*~>
Q
Q