// Copyright 2019 The PDFium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "core/fpdfapi/edit/cpdf_contentstream_write_utils.h" #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <ostream> #include "core/fxcrt/compiler_specific.h" #include "core/fxcrt/span.h" namespace { constexpr unsigned kMaximumSkFloatToDecimalLength = …; // Return pow(10.0, e), optimized for common cases. double pow10(int e) { … } // SkFloatToDecimal // // Convert a float into a decimal string. // // The resulting string will be in the form `[-]?([0-9]*\.)?[0-9]+` (It does // not use scientific notation.) and `sscanf(output, "%f", &x)` will return // the original value if the value is finite. This function accepts all // possible input values. // // INFINITY and -INFINITY are rounded to FLT_MAX and -FLT_MAX. // // NAN values are converted to 0. // // This function will always add a terminating '\0' to the output. // // @param value Any floating-point number // @param output The buffer to write the string into. Must be non-null. // // @return strlen(output) // // Write a string into output, including a terminating '\0' (for // unit testing). Return strlen(output) (for SkWStream::write) The // resulting string will be in the form /[-]?([0-9]*.)?[0-9]+/ and // sscanf(output, "%f", &x) will return the original value iff the // value is finite. This function accepts all possible input values. // // Motivation: "PDF does not support [numbers] in exponential format // (such as 6.02e23)." Otherwise, this function would rely on a // sprintf-type function from the standard library. unsigned SkFloatToDecimal( float value, pdfium::span<char, kMaximumSkFloatToDecimalLength> output) { … } } // namespace std::ostream& WriteFloat(std::ostream& stream, float value) { … } std::ostream& WriteMatrix(std::ostream& stream, const CFX_Matrix& matrix) { … } std::ostream& WritePoint(std::ostream& stream, const CFX_PointF& point) { … } std::ostream& WriteRect(std::ostream& stream, const CFX_FloatRect& rect) { … }