Commit e2593e2efe140d47870b0c511cbf5160db080edd

Authored by Jay Berkenbilt
1 parent 07f40bd2

Move QPDFMatrix into the public API

ChangeLog
1 2021-02-12 Jay Berkenbilt <ejb@ql.org> 1 2021-02-12 Jay Berkenbilt <ejb@ql.org>
2 2
  3 + * Move formerly internal QPDFMatrix class to the public API. This
  4 + class provides convenience methods for working with transformation
  5 + matrices.
  6 +
3 * QUtil::double_to_string: trim trailing zeroes by default, and 7 * QUtil::double_to_string: trim trailing zeroes by default, and
4 add option to not trim trailing zeroes. This causes a syntactic 8 add option to not trim trailing zeroes. This causes a syntactic
5 but semantically preserving change in output when doubles are 9 but semantically preserving change in output when doubles are
libqpdf/qpdf/QPDFMatrix.hh renamed to include/qpdf/QPDFMatrix.hh
  1 +// Copyright (c) 2005-2021 Jay Berkenbilt
  2 +//
  3 +// This file is part of qpdf.
  4 +//
  5 +// Licensed under the Apache License, Version 2.0 (the "License");
  6 +// you may not use this file except in compliance with the License.
  7 +// You may obtain a copy of the License at
  8 +//
  9 +// http://www.apache.org/licenses/LICENSE-2.0
  10 +//
  11 +// Unless required by applicable law or agreed to in writing, software
  12 +// distributed under the License is distributed on an "AS IS" BASIS,
  13 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 +// See the License for the specific language governing permissions and
  15 +// limitations under the License.
  16 +//
  17 +// Versions of qpdf prior to version 7 were released under the terms
  18 +// of version 2.0 of the Artistic License. At your option, you may
  19 +// continue to consider qpdf to be licensed under those terms. Please
  20 +// see the manual for additional information.
  21 +
1 #ifndef QPDFMATRIX_HH 22 #ifndef QPDFMATRIX_HH
2 #define QPDFMATRIX_HH 23 #define QPDFMATRIX_HH
3 24
@@ -5,6 +26,15 @@ @@ -5,6 +26,15 @@
5 #include <qpdf/DLL.h> 26 #include <qpdf/DLL.h>
6 #include <string> 27 #include <string>
7 28
  29 +// This class represents a PDF transformation matrix using a tuple
  30 +// such that
  31 +//
  32 +// ┌ ┐
  33 +// │ a b 0 │
  34 +// (a, b, c, d, e, f) = │ c d 0 │
  35 +// │ e f 1 │
  36 +// └ ┘
  37 +
8 class QPDFMatrix 38 class QPDFMatrix
9 { 39 {
10 public: 40 public:
@@ -16,27 +46,39 @@ class QPDFMatrix @@ -16,27 +46,39 @@ class QPDFMatrix
16 QPDF_DLL 46 QPDF_DLL
17 QPDFMatrix(QPDFObjectHandle::Matrix const&); 47 QPDFMatrix(QPDFObjectHandle::Matrix const&);
18 48
  49 + // Returns the six values separated by spaces as real numbers with
  50 + // trimmed zeroes.
19 QPDF_DLL 51 QPDF_DLL
20 std::string unparse() const; 52 std::string unparse() const;
21 53
22 QPDF_DLL 54 QPDF_DLL
23 QPDFObjectHandle::Matrix getAsMatrix() const; 55 QPDFObjectHandle::Matrix getAsMatrix() const;
24 56
25 - // This is not part of the public API. Just provide the methods we  
26 - // need as we need them. 57 + // Replace this with other * this
27 QPDF_DLL 58 QPDF_DLL
28 void concat(QPDFMatrix const& other); 59 void concat(QPDFMatrix const& other);
  60 +
  61 + // Same as concat(sx, 0, 0, sy, 0, 0)
29 QPDF_DLL 62 QPDF_DLL
30 void scale(double sx, double sy); 63 void scale(double sx, double sy);
  64 +
  65 + // Same as concat(1, 0, 0, 1, tx, ty);
31 QPDF_DLL 66 QPDF_DLL
32 void translate(double tx, double ty); 67 void translate(double tx, double ty);
  68 +
33 // Any value other than 90, 180, or 270 is ignored 69 // Any value other than 90, 180, or 270 is ignored
34 QPDF_DLL 70 QPDF_DLL
35 void rotatex90(int angle); 71 void rotatex90(int angle);
36 72
  73 + // Transform a point. The underlying operation is to take
  74 + // [x y 1] * this
  75 + // and take the first and second rows of the result as xp and yp.
37 QPDF_DLL 76 QPDF_DLL
38 void transform(double x, double y, double& xp, double& yp); 77 void transform(double x, double y, double& xp, double& yp);
39 78
  79 + // Transform a rectangle by creating a new rectangle that tightly
  80 + // bounds the polygon resulting from transforming the four
  81 + // corners.
40 QPDF_DLL 82 QPDF_DLL
41 QPDFObjectHandle::Rectangle transformRectangle( 83 QPDFObjectHandle::Rectangle transformRectangle(
42 QPDFObjectHandle::Rectangle r); 84 QPDFObjectHandle::Rectangle r);
libqpdf/QPDFMatrix.cc
@@ -118,9 +118,6 @@ QPDFMatrix::transform(double x, double y, double&amp; xp, double&amp; yp) @@ -118,9 +118,6 @@ QPDFMatrix::transform(double x, double y, double&amp; xp, double&amp; yp)
118 QPDFObjectHandle::Rectangle 118 QPDFObjectHandle::Rectangle
119 QPDFMatrix::transformRectangle(QPDFObjectHandle::Rectangle r) 119 QPDFMatrix::transformRectangle(QPDFObjectHandle::Rectangle r)
120 { 120 {
121 - // Transform a rectangle by creating a new rectangle the tightly  
122 - // bounds the polygon resulting from transforming the four  
123 - // corners.  
124 std::vector<double> tx(4); 121 std::vector<double> tx(4);
125 std::vector<double> ty(4); 122 std::vector<double> ty(4);
126 transform(r.llx, r.lly, tx.at(0), ty.at(0)); 123 transform(r.llx, r.lly, tx.at(0), ty.at(0));
manual/qpdf-manual.xml
@@ -5220,6 +5220,15 @@ print &quot;\n&quot;; @@ -5220,6 +5220,15 @@ print &quot;\n&quot;;
5220 rotations. 5220 rotations.
5221 </para> 5221 </para>
5222 </listitem> 5222 </listitem>
  5223 + <listitem>
  5224 + <para>
  5225 + The <classname>QPDFMatrix</classname> class, formerly a
  5226 + private, internal class, has been added to the public API.
  5227 + See <filename>include/qpdf/QPDFMatrix.hh</filename> for
  5228 + details. This class is for working with transformation
  5229 + matrices.
  5230 + </para>
  5231 + </listitem>
5223 </itemizedlist> 5232 </itemizedlist>
5224 </listitem> 5233 </listitem>
5225 <listitem> 5234 <listitem>