John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 7 | #ifndef PUBLIC_FPDF_TRANSFORMPAGE_H_ |
| 8 | #define PUBLIC_FPDF_TRANSFORMPAGE_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Dan Sinclair | 85c8e7f | 2016-11-21 13:50:32 -0500 | [diff] [blame] | 10 | // NOLINTNEXTLINE(build/include) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 11 | #include "fpdfview.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 12 | |
Tom Sepez | cf22eb8 | 2015-05-12 17:28:08 -0700 | [diff] [blame] | 13 | #ifdef __cplusplus |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | /** |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 18 | * Set "MediaBox" entry to the page dictionary. |
| 19 | * |
| 20 | * page - Handle to a page. |
| 21 | * left - The left of the rectangle. |
| 22 | * bottom - The bottom of the rectangle. |
| 23 | * right - The right of the rectangle. |
| 24 | * top - The top of the rectangle. |
| 25 | */ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 26 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetMediaBox(FPDF_PAGE page, |
| 27 | float left, |
| 28 | float bottom, |
| 29 | float right, |
| 30 | float top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 33 | * Set "CropBox" entry to the page dictionary. |
| 34 | * |
| 35 | * page - Handle to a page. |
| 36 | * left - The left of the rectangle. |
| 37 | * bottom - The bottom of the rectangle. |
| 38 | * right - The right of the rectangle. |
| 39 | * top - The top of the rectangle. |
| 40 | */ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 41 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetCropBox(FPDF_PAGE page, |
| 42 | float left, |
| 43 | float bottom, |
| 44 | float right, |
| 45 | float top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 47 | /** |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 48 | * Set "BleedBox" entry to the page dictionary. |
| 49 | * |
| 50 | * page - Handle to a page. |
| 51 | * left - The left of the rectangle. |
| 52 | * bottom - The bottom of the rectangle. |
| 53 | * right - The right of the rectangle. |
| 54 | * top - The top of the rectangle. |
| 55 | */ |
| 56 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetBleedBox(FPDF_PAGE page, |
| 57 | float left, |
| 58 | float bottom, |
| 59 | float right, |
| 60 | float top); |
| 61 | |
| 62 | /** |
| 63 | * Set "TrimBox" entry to the page dictionary. |
| 64 | * |
| 65 | * page - Handle to a page. |
| 66 | * left - The left of the rectangle. |
| 67 | * bottom - The bottom of the rectangle. |
| 68 | * right - The right of the rectangle. |
| 69 | * top - The top of the rectangle. |
| 70 | */ |
| 71 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetTrimBox(FPDF_PAGE page, |
| 72 | float left, |
| 73 | float bottom, |
| 74 | float right, |
| 75 | float top); |
| 76 | |
| 77 | /** |
xlou | c7f66ed | 2018-10-11 21:15:18 +0000 | [diff] [blame] | 78 | * Set "ArtBox" entry to the page dictionary. |
| 79 | * |
| 80 | * page - Handle to a page. |
| 81 | * left - The left of the rectangle. |
| 82 | * bottom - The bottom of the rectangle. |
| 83 | * right - The right of the rectangle. |
| 84 | * top - The top of the rectangle. |
| 85 | */ |
| 86 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_SetArtBox(FPDF_PAGE page, |
| 87 | float left, |
| 88 | float bottom, |
| 89 | float right, |
| 90 | float top); |
| 91 | |
| 92 | /** |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 93 | * Get "MediaBox" entry from the page dictionary. |
| 94 | * |
| 95 | * page - Handle to a page. |
| 96 | * left - Pointer to a float value receiving the left of the rectangle. |
| 97 | * bottom - Pointer to a float value receiving the bottom of the rectangle. |
| 98 | * right - Pointer to a float value receiving the right of the rectangle. |
| 99 | * top - Pointer to a float value receiving the top of the rectangle. |
| 100 | * |
| 101 | * On success, return true and write to the out parameters. Otherwise return |
| 102 | * false and leave the out parameters unmodified. |
| 103 | */ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 104 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetMediaBox(FPDF_PAGE page, |
| 105 | float* left, |
| 106 | float* bottom, |
| 107 | float* right, |
| 108 | float* top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 109 | |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 110 | /** |
| 111 | * Get "CropBox" entry from the page dictionary. |
| 112 | * |
| 113 | * page - Handle to a page. |
| 114 | * left - Pointer to a float value receiving the left of the rectangle. |
| 115 | * bottom - Pointer to a float value receiving the bottom of the rectangle. |
| 116 | * right - Pointer to a float value receiving the right of the rectangle. |
| 117 | * top - Pointer to a float value receiving the top of the rectangle. |
| 118 | * |
| 119 | * On success, return true and write to the out parameters. Otherwise return |
| 120 | * false and leave the out parameters unmodified. |
| 121 | */ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 122 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetCropBox(FPDF_PAGE page, |
| 123 | float* left, |
| 124 | float* bottom, |
| 125 | float* right, |
| 126 | float* top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
xlou | 618edef | 2018-10-12 23:37:41 +0000 | [diff] [blame] | 129 | * Get "BleedBox" entry from the page dictionary. |
| 130 | * |
| 131 | * page - Handle to a page. |
| 132 | * left - Pointer to a float value receiving the left of the rectangle. |
| 133 | * bottom - Pointer to a float value receiving the bottom of the rectangle. |
| 134 | * right - Pointer to a float value receiving the right of the rectangle. |
| 135 | * top - Pointer to a float value receiving the top of the rectangle. |
| 136 | * |
| 137 | * On success, return true and write to the out parameters. Otherwise return |
| 138 | * false and leave the out parameters unmodified. |
| 139 | */ |
| 140 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetBleedBox(FPDF_PAGE page, |
| 141 | float* left, |
| 142 | float* bottom, |
| 143 | float* right, |
| 144 | float* top); |
| 145 | |
| 146 | /** |
| 147 | * Get "TrimBox" entry from the page dictionary. |
| 148 | * |
| 149 | * page - Handle to a page. |
| 150 | * left - Pointer to a float value receiving the left of the rectangle. |
| 151 | * bottom - Pointer to a float value receiving the bottom of the rectangle. |
| 152 | * right - Pointer to a float value receiving the right of the rectangle. |
| 153 | * top - Pointer to a float value receiving the top of the rectangle. |
| 154 | * |
| 155 | * On success, return true and write to the out parameters. Otherwise return |
| 156 | * false and leave the out parameters unmodified. |
| 157 | */ |
| 158 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetTrimBox(FPDF_PAGE page, |
| 159 | float* left, |
| 160 | float* bottom, |
| 161 | float* right, |
| 162 | float* top); |
| 163 | |
| 164 | /** |
xlou | c7f66ed | 2018-10-11 21:15:18 +0000 | [diff] [blame] | 165 | * Get "ArtBox" entry from the page dictionary. |
| 166 | * |
| 167 | * page - Handle to a page. |
| 168 | * left - Pointer to a float value receiving the left of the rectangle. |
| 169 | * bottom - Pointer to a float value receiving the bottom of the rectangle. |
| 170 | * right - Pointer to a float value receiving the right of the rectangle. |
| 171 | * top - Pointer to a float value receiving the top of the rectangle. |
| 172 | * |
| 173 | * On success, return true and write to the out parameters. Otherwise return |
| 174 | * false and leave the out parameters unmodified. |
| 175 | */ |
| 176 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GetArtBox(FPDF_PAGE page, |
| 177 | float* left, |
| 178 | float* bottom, |
| 179 | float* right, |
| 180 | float* top); |
| 181 | |
| 182 | /** |
Shirleen Lou | 07b4727 | 2017-11-18 00:13:45 +0000 | [diff] [blame] | 183 | * Apply transforms to |page|. |
| 184 | * |
| 185 | * If |matrix| is provided it will be applied to transform the page. |
| 186 | * If |clipRect| is provided it will be used to clip the resulting page. |
| 187 | * If neither |matrix| or |clipRect| are provided this method returns |false|. |
| 188 | * Returns |true| if transforms are applied. |
| 189 | * |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 190 | * This function will transform the whole page, and would take effect to all the |
| 191 | * objects in the page. |
| 192 | * |
| 193 | * page - Page handle. |
| 194 | * matrix - Transform matrix. |
| 195 | * clipRect - Clipping rectangle. |
Shirleen Lou | 07b4727 | 2017-11-18 00:13:45 +0000 | [diff] [blame] | 196 | */ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 197 | FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV |
| 198 | FPDFPage_TransFormWithClip(FPDF_PAGE page, |
Lei Zhang | 970fcfe | 2018-12-20 19:51:18 +0000 | [diff] [blame] | 199 | const FS_MATRIX* matrix, |
| 200 | const FS_RECTF* clipRect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 201 | |
| 202 | /** |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 203 | * Transform (scale, rotate, shear, move) the clip path of page object. |
| 204 | * page_object - Handle to a page object. Returned by |
| 205 | * FPDFPageObj_NewImageObj(). |
| 206 | * |
| 207 | * a - The coefficient "a" of the matrix. |
| 208 | * b - The coefficient "b" of the matrix. |
| 209 | * c - The coefficient "c" of the matrix. |
| 210 | * d - The coefficient "d" of the matrix. |
| 211 | * e - The coefficient "e" of the matrix. |
| 212 | * f - The coefficient "f" of the matrix. |
| 213 | */ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 214 | FPDF_EXPORT void FPDF_CALLCONV |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 215 | FPDFPageObj_TransformClipPath(FPDF_PAGEOBJECT page_object, |
| 216 | double a, |
| 217 | double b, |
| 218 | double c, |
| 219 | double d, |
| 220 | double e, |
| 221 | double f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 222 | |
Miklos Vajna | 45501f3 | 2019-07-30 07:41:02 +0000 | [diff] [blame] | 223 | // Experimental API. |
| 224 | // Get the clip path of the page object. |
| 225 | // |
| 226 | // page object - Handle to a page object. Returned by e.g. |
| 227 | // FPDFPage_GetObject(). |
| 228 | // |
| 229 | // Caller does not take ownership of the returned FPDF_CLIPPATH. Instead, it |
| 230 | // remains valid until FPDF_ClosePage() is called for the page containing |
| 231 | // page_object. |
| 232 | FPDF_EXPORT FPDF_CLIPPATH FPDF_CALLCONV |
| 233 | FPDFPageObj_GetClipPath(FPDF_PAGEOBJECT page_object); |
| 234 | |
| 235 | // Experimental API. |
| 236 | // Get number of paths inside |clip_path|. |
| 237 | // |
| 238 | // clip_path - handle to a clip_path. |
| 239 | // |
| 240 | // Returns the number of objects in |clip_path| or -1 on failure. |
| 241 | FPDF_EXPORT int FPDF_CALLCONV FPDFClipPath_CountPaths(FPDF_CLIPPATH clip_path); |
| 242 | |
| 243 | // Experimental API. |
| 244 | // Get number of segments inside one path of |clip_path|. |
| 245 | // |
| 246 | // clip_path - handle to a clip_path. |
| 247 | // path_index - index into the array of paths of the clip path. |
| 248 | // |
| 249 | // Returns the number of segments or -1 on failure. |
| 250 | FPDF_EXPORT int FPDF_CALLCONV |
| 251 | FPDFClipPath_CountPathSegments(FPDF_CLIPPATH clip_path, int path_index); |
| 252 | |
| 253 | // Experimental API. |
| 254 | // Get segment in one specific path of |clip_path| at index. |
| 255 | // |
| 256 | // clip_path - handle to a clip_path. |
| 257 | // path_index - the index of a path. |
| 258 | // segment_index - the index of a segment. |
| 259 | // |
| 260 | // Returns the handle to the segment, or NULL on failure. The caller does not |
| 261 | // take ownership of the returned FPDF_CLIPPATH. Instead, it remains valid until |
| 262 | // FPDF_ClosePage() is called for the page containing page_object. |
| 263 | FPDF_EXPORT FPDF_PATHSEGMENT FPDF_CALLCONV |
| 264 | FPDFClipPath_GetPathSegment(FPDF_CLIPPATH clip_path, |
| 265 | int path_index, |
| 266 | int segment_index); |
| 267 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 268 | /** |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 269 | * Create a new clip path, with a rectangle inserted. |
| 270 | * |
Lei Zhang | 51948ab | 2018-10-09 22:03:30 +0000 | [diff] [blame] | 271 | * Caller takes ownership of the returned FPDF_CLIPPATH. It should be freed with |
| 272 | * FPDF_DestroyClipPath(). |
| 273 | * |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 274 | * left - The left of the clip box. |
| 275 | * bottom - The bottom of the clip box. |
| 276 | * right - The right of the clip box. |
| 277 | * top - The top of the clip box. |
| 278 | */ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 279 | FPDF_EXPORT FPDF_CLIPPATH FPDF_CALLCONV FPDF_CreateClipPath(float left, |
| 280 | float bottom, |
| 281 | float right, |
| 282 | float top); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 283 | |
| 284 | /** |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 285 | * Destroy the clip path. |
| 286 | * |
Lei Zhang | 51948ab | 2018-10-09 22:03:30 +0000 | [diff] [blame] | 287 | * clipPath - A handle to the clip path. It will be invalid after this call. |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 288 | */ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 289 | FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyClipPath(FPDF_CLIPPATH clipPath); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 290 | |
| 291 | /** |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 292 | * Clip the page content, the page content that outside the clipping region |
| 293 | * become invisible. |
| 294 | * |
| 295 | * A clip path will be inserted before the page content stream or content array. |
| 296 | * In this way, the page content will be clipped by this clip path. |
| 297 | * |
| 298 | * page - A page handle. |
Lei Zhang | 51948ab | 2018-10-09 22:03:30 +0000 | [diff] [blame] | 299 | * clipPath - A handle to the clip path. (Does not take ownership.) |
Lei Zhang | f958f35 | 2018-06-08 18:02:45 +0000 | [diff] [blame] | 300 | */ |
Dan Sinclair | 00d2ad1 | 2017-08-10 14:13:02 -0400 | [diff] [blame] | 301 | FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page, |
| 302 | FPDF_CLIPPATH clipPath); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 303 | |
Tom Sepez | cf22eb8 | 2015-05-12 17:28:08 -0700 | [diff] [blame] | 304 | #ifdef __cplusplus |
| 305 | } |
| 306 | #endif |
| 307 | |
Tom Sepez | 9857e20 | 2015-05-13 17:09:26 -0700 | [diff] [blame] | 308 | #endif // PUBLIC_FPDF_TRANSFORMPAGE_H_ |