------------------------------------------------------------------------------
| 2230 | |
| 2231 | //------------------------------------------------------------------------------ |
| 2232 | void vtkPDFContextDevice2D::ApplyTransform() |
| 2233 | { |
| 2234 | // The HPDF API for transform management is lacking. There's no clear way |
| 2235 | // to simply *set* the transform, we can only concatenate multiple transforms |
| 2236 | // together. Nor is there a way to push/pop a matrix stack. So we'll just |
| 2237 | // invert the current transform to unapply it before applying the new one. |
| 2238 | HPDF_TransMatrix oldTrans = HPDF_Page_GetTransMatrix(this->Impl->Page); |
| 2239 | double oldInvTransMat3[9]; |
| 2240 | vtkPDFContextDevice2D::HPDFTransformToMatrix3( |
| 2241 | oldTrans.a, oldTrans.b, oldTrans.c, oldTrans.d, oldTrans.x, oldTrans.y, oldInvTransMat3); |
| 2242 | vtkMatrix3x3::Invert(oldInvTransMat3, oldInvTransMat3); |
| 2243 | |
| 2244 | // Multiply the inverse current transform with the new one: |
| 2245 | double newTransMat3[9]; |
| 2246 | double* mat = this->Matrix->GetMatrix()->GetData(); |
| 2247 | vtkPDFContextDevice2D::Matrix4ToMatrix3(mat, newTransMat3); |
| 2248 | |
| 2249 | vtkMatrix3x3::Multiply3x3(oldInvTransMat3, newTransMat3, newTransMat3); |
| 2250 | |
| 2251 | // Test if the new transform is identity, within tolerance: |
| 2252 | bool isIdentity = true; |
| 2253 | constexpr double tol = 1e-6; |
| 2254 | for (size_t i = 0; i < 3 && isIdentity; ++i) |
| 2255 | { |
| 2256 | for (size_t j = 0; j < 3 && isIdentity; ++j) |
| 2257 | { |
| 2258 | const double val = newTransMat3[i * 3 + j]; |
| 2259 | const double exp = (i == j) ? 1. : 0.; |
| 2260 | if (std::fabs(val - exp) > tol) |
| 2261 | { |
| 2262 | isIdentity = false; |
| 2263 | } |
| 2264 | } |
| 2265 | } |
| 2266 | |
| 2267 | // Do nothing if the transform would have no effect. |
| 2268 | if (isIdentity) |
| 2269 | { |
| 2270 | return; |
| 2271 | } |
| 2272 | |
| 2273 | // Otherwise, write the new transform out. |
| 2274 | float hpdfMat[6]; |
| 2275 | vtkPDFContextDevice2D::Matrix3ToHPDFTransform(newTransMat3, hpdfMat); |
| 2276 | HPDF_Page_Concat( |
| 2277 | this->Impl->Page, hpdfMat[0], hpdfMat[1], hpdfMat[2], hpdfMat[3], hpdfMat[4], hpdfMat[5]); |
| 2278 | } |
| 2279 | |
| 2280 | //------------------------------------------------------------------------------ |
| 2281 | vtkVector2f vtkPDFContextDevice2D::GetUnscaledPenWidth() |
no test coverage detected