Commit e2593e2efe140d47870b0c511cbf5160db080edd
1 parent
07f40bd2
Move QPDFMatrix into the public API
Showing
4 changed files
with
57 additions
and
5 deletions
ChangeLog
| 1 | 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 | 7 | * QUtil::double_to_string: trim trailing zeroes by default, and |
| 4 | 8 | add option to not trim trailing zeroes. This causes a syntactic |
| 5 | 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 | 22 | #ifndef QPDFMATRIX_HH |
| 2 | 23 | #define QPDFMATRIX_HH |
| 3 | 24 | |
| ... | ... | @@ -5,6 +26,15 @@ |
| 5 | 26 | #include <qpdf/DLL.h> |
| 6 | 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 | 38 | class QPDFMatrix |
| 9 | 39 | { |
| 10 | 40 | public: |
| ... | ... | @@ -16,27 +46,39 @@ class QPDFMatrix |
| 16 | 46 | QPDF_DLL |
| 17 | 47 | QPDFMatrix(QPDFObjectHandle::Matrix const&); |
| 18 | 48 | |
| 49 | + // Returns the six values separated by spaces as real numbers with | |
| 50 | + // trimmed zeroes. | |
| 19 | 51 | QPDF_DLL |
| 20 | 52 | std::string unparse() const; |
| 21 | 53 | |
| 22 | 54 | QPDF_DLL |
| 23 | 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 | 58 | QPDF_DLL |
| 28 | 59 | void concat(QPDFMatrix const& other); |
| 60 | + | |
| 61 | + // Same as concat(sx, 0, 0, sy, 0, 0) | |
| 29 | 62 | QPDF_DLL |
| 30 | 63 | void scale(double sx, double sy); |
| 64 | + | |
| 65 | + // Same as concat(1, 0, 0, 1, tx, ty); | |
| 31 | 66 | QPDF_DLL |
| 32 | 67 | void translate(double tx, double ty); |
| 68 | + | |
| 33 | 69 | // Any value other than 90, 180, or 270 is ignored |
| 34 | 70 | QPDF_DLL |
| 35 | 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 | 76 | QPDF_DLL |
| 38 | 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 | 82 | QPDF_DLL |
| 41 | 83 | QPDFObjectHandle::Rectangle transformRectangle( |
| 42 | 84 | QPDFObjectHandle::Rectangle r); | ... | ... |
libqpdf/QPDFMatrix.cc
| ... | ... | @@ -118,9 +118,6 @@ QPDFMatrix::transform(double x, double y, double& xp, double& yp) |
| 118 | 118 | QPDFObjectHandle::Rectangle |
| 119 | 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 | 121 | std::vector<double> tx(4); |
| 125 | 122 | std::vector<double> ty(4); |
| 126 | 123 | transform(r.llx, r.lly, tx.at(0), ty.at(0)); | ... | ... |
manual/qpdf-manual.xml
| ... | ... | @@ -5220,6 +5220,15 @@ print "\n"; |
| 5220 | 5220 | rotations. |
| 5221 | 5221 | </para> |
| 5222 | 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 | 5232 | </itemizedlist> |
| 5224 | 5233 | </listitem> |
| 5225 | 5234 | <listitem> | ... | ... |