• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "core/fpdfapi/edit/cpdf_contentstream_write_utils.h"
6 
7 #include <ostream>
8 
9 #include "third_party/skia_shared/SkFloatToDecimal.h"
10 
WriteFloat(std::ostream & stream,float value)11 std::ostream& WriteFloat(std::ostream& stream, float value) {
12   char buffer[pdfium::skia::kMaximumSkFloatToDecimalLength];
13   unsigned size = pdfium::skia::SkFloatToDecimal(value, buffer);
14   stream.write(buffer, size);
15   return stream;
16 }
17 
WriteMatrix(std::ostream & stream,const CFX_Matrix & matrix)18 std::ostream& WriteMatrix(std::ostream& stream, const CFX_Matrix& matrix) {
19   WriteFloat(stream, matrix.a) << " ";
20   WriteFloat(stream, matrix.b) << " ";
21   WriteFloat(stream, matrix.c) << " ";
22   WriteFloat(stream, matrix.d) << " ";
23   WriteFloat(stream, matrix.e) << " ";
24   WriteFloat(stream, matrix.f);
25   return stream;
26 }
27 
WritePoint(std::ostream & stream,const CFX_PointF & point)28 std::ostream& WritePoint(std::ostream& stream, const CFX_PointF& point) {
29   WriteFloat(stream, point.x) << " ";
30   WriteFloat(stream, point.y);
31   return stream;
32 }
33 
WriteRect(std::ostream & stream,const CFX_FloatRect & rect)34 std::ostream& WriteRect(std::ostream& stream, const CFX_FloatRect& rect) {
35   WriteFloat(stream, rect.left) << " ";
36   WriteFloat(stream, rect.bottom) << " ";
37   WriteFloat(stream, rect.Width()) << " ";
38   WriteFloat(stream, rect.Height());
39   return stream;
40 }
41