├── Draw.cpp ├── Draw.h ├── Draw_Tiling.cpp ├── LICENSE.md ├── Pattern.cpp ├── Pattern.h ├── Pattern_Strings.cpp ├── Pattern_Strings.h ├── README.md ├── animations ├── animation 1.gif ├── animation 2.gif ├── animation 3.gif ├── animation 4.gif ├── animation 5.gif ├── animation 6.gif ├── animation 7.gif └── animation 8.gif ├── cairo ├── cairo.dll ├── include │ ├── cairo-deprecated.h │ ├── cairo-features.h │ ├── cairo-ft.h │ ├── cairo-gobject.h │ ├── cairo-pdf.h │ ├── cairo-ps.h │ ├── cairo-script-interpreter.h │ ├── cairo-script.h │ ├── cairo-svg.h │ ├── cairo-tee.h │ ├── cairo-version.h │ ├── cairo-win32.h │ └── cairo.h └── lib │ ├── cairo.lib │ ├── pixman-1.lib │ └── temp └── color-static-lib ├── Color.cpp ├── Color.h ├── framework.h ├── pch.cpp └── pch.h /Draw.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2021 Nithisha Nantha Kumar 2 | // This code is licensed under MIT license (see LICENSE.md for details) 3 | 4 | #include "Draw.h" 5 | 6 | point draw::solve_equation(equation& eq1, equation& eq2) { 7 | // Refer to: http://www.mathnstuff.com/math/algebra/adeterm.htm 8 | point solution; 9 | solution.x = ((eq1.c * eq2.b) - (eq1.b * eq2.c)) / 10 | ((eq1.a * eq2.b) - (eq1.b * eq2.a)); 11 | solution.y = ((eq1.a * eq2.c) - (eq1.c * eq2.a)) / 12 | ((eq1.a * eq2.b) - (eq1.b * eq2.a)); 13 | return solution; 14 | } 15 | 16 | equation draw::construct_equation_from_pts(point& pt1, point& pt2) { 17 | // (y - y1) / (y2 - y1) = (x - x1) / (x2 - x1) is used 18 | // to calculate the equation joining two points with 19 | // coordinates (x1, y1) and (x2, y2). When rearranged to 20 | // ax + by = c form: 21 | equation eq; 22 | eq.a = 1 / (pt2.x - pt1.x); 23 | eq.b = -1 / (pt2.y - pt1.y); 24 | eq.c = (pt1.x / (pt2.x - pt1.x)) - (pt1.y / (pt2.y - pt1.y)); 25 | return eq; 26 | } 27 | 28 | point draw::rotatePoint(point& original, point& rotateAbt, double angleInRadians) { 29 | // Refer to: https://tinyurl.com/58pm4x98 30 | point rotatedPoint; 31 | rotatedPoint.x = cos(angleInRadians) * (original.x - rotateAbt.x) 32 | - sin(angleInRadians) * (original.y - rotateAbt.y) + rotateAbt.x; 33 | rotatedPoint.y = sin(angleInRadians) * (original.x - rotateAbt.x) 34 | + cos(angleInRadians) * (original.y - rotateAbt.y) + rotateAbt.y; 35 | return rotatedPoint; 36 | } 37 | 38 | bool draw::isCollinear(equation& eq1, equation& eq2) { 39 | 40 | // 2 lines are collinear if their slopes (-a/b) 41 | // & their y-intercepts are = 42 | // 2 lines are parallel if their slopes are 43 | // = but y-intercepts are != 44 | // We aren't comparing y-intercepts as the lines 45 | // cannot be parallel & thus only check slope equality. 46 | 47 | // To prevent division of infinity 48 | if (isinf(eq2.a) && !isinf(eq2.b) && isinf(eq1.a) && !isinf(eq1.b)) { 49 | return true; 50 | } 51 | 52 | // Casting to float to reduce precision from double for almost collinear lines. 53 | return fabs(float(-eq2.a / eq2.b) - float(-eq1.a / eq1.b)) < 0.0001; 54 | } 55 | 56 | bool draw::isHorizontal(equation& eq) { 57 | // Slope of a horizontal line (-a/b) is 0. 58 | return (-eq.a / eq.b) == 0; 59 | } 60 | 61 | bool draw::isVertical(equation& eq) { 62 | // Slope of a vertical line (-a/b) is infinity. 63 | return isinf(-eq.a / eq.b); 64 | } 65 | 66 | point draw::move_along_line(point& v1, point& v2, point midPoint, 67 | double distance) { 68 | // Refer to: https://tinyurl.com/fxescdja 69 | point pt; 70 | pt.x = v2.x - v1.x; 71 | pt.y = v2.y - v1.y; 72 | double magnitude = sqrt((pt.x * pt.x) + (pt.y * pt.y)); 73 | // normalize vector 74 | pt.x /= magnitude; 75 | pt.y /= magnitude; 76 | midPoint.x += (distance * pt.x); 77 | midPoint.y += (distance * pt.y); 78 | return midPoint; 79 | } 80 | 81 | point draw::findIntersection(point& eq1pt1, point& eq1pt2, 82 | point& eq2pt1, point& eq2pt2) { 83 | point solution; 84 | equation eq1 = construct_equation_from_pts(eq1pt1, eq1pt2); 85 | equation eq2 = construct_equation_from_pts(eq2pt1, eq2pt2); 86 | 87 | if (isCollinear(eq1, eq2)) { 88 | solution.x = eq1pt2.x; 89 | solution.y = eq1pt2.y; 90 | } 91 | else if (isHorizontal(eq1) && isVertical(eq2)) { 92 | solution.x = eq2pt2.x; 93 | solution.y = eq1pt2.y; 94 | } 95 | else if (isVertical(eq1) && isHorizontal(eq2)) { 96 | solution.x = eq1pt2.x; 97 | solution.y = eq2pt2.y; 98 | } 99 | else if (!isHorizontal(eq1) && isVertical(eq2)) { 100 | solution.x = eq2pt2.x; 101 | solution.y = ((-eq1.a / eq1.b) * eq2pt2.x) + (eq1.c / eq1.b); 102 | } 103 | else if (isVertical(eq1) && !isHorizontal(eq2)) { 104 | solution.x = eq1pt2.x; 105 | solution.y = ((-eq2.a / eq2.b) * eq1pt2.x) + (eq2.c / eq2.b); 106 | } 107 | else if (!isVertical(eq2) && isHorizontal(eq1)) { 108 | solution.x = ((-eq2.b / eq2.a) * (eq1pt2.y)) + (eq2.c / eq2.a); 109 | solution.y = eq1pt2.y; 110 | } 111 | else if (!isVertical(eq1) && isHorizontal(eq2)) { 112 | solution.x = ((-eq1.b / eq1.a) * (eq2pt2.y)) + (eq1.c / eq1.a); 113 | solution.y = eq2pt2.y; 114 | } 115 | else { 116 | solution = solve_equation(eq1, eq2); 117 | } 118 | 119 | return solution; 120 | } 121 | 122 | void draw::calculate_center_vertices(int numSides) { 123 | vertices.clear(); 124 | // Finding coordinates of the polygon's vertices. 125 | double radius = sideLength / (2 * sin(PF_PI / numSides)); 126 | for (int i = 0; i < numSides; i++) { 127 | point vertex; 128 | vertex.x = center.x + radius * cos((PF_PI / 2) + 129 | PF_PI / numSides * (1 + 2 * i)); 130 | vertex.y = center.y + radius * sin((PF_PI / 2) + 131 | PF_PI / numSides * (1 + 2 * i)); 132 | vertices.push_back(vertex); 133 | } 134 | sort_vertices(); 135 | } 136 | 137 | void draw::calculate_midpoints(int numSides) { 138 | midpoints.clear(); 139 | point lastVertex; 140 | 141 | // Midpoint of two points with coordinates (x1, y1) and 142 | // (x2, y2) is ((x1 + x2) / 2, (y1 + y2) / 2). 143 | 144 | // Calculating midpoints of each side of the polygon: 145 | 146 | for (int i = 0; i < numSides - 1; i++) { 147 | point vertex; 148 | if (mode == 1) { 149 | vertex.x = (vertices[i].x + vertices[i + 1].x) / 2.0; 150 | vertex.y = (vertices[i].y + vertices[i + 1].y) / 2.0; 151 | } 152 | else if (mode == 2) { 153 | vertex.x = (centerPolygonVertices[i].x + 154 | centerPolygonVertices[i + 1].x) / 2.0; 155 | vertex.y = (centerPolygonVertices[i].y + 156 | centerPolygonVertices[i + 1].y) / 2.0; 157 | } 158 | else { 159 | vertex.x = (originPolygonVertices[i].x + 160 | originPolygonVertices[i + 1].x) / 2.0; 161 | vertex.y = (originPolygonVertices[i].y + 162 | originPolygonVertices[i + 1].y) / 2.0; 163 | } 164 | midpoints.push_back(vertex); 165 | } 166 | if (mode == 1) { 167 | lastVertex.x = (vertices[0].x + vertices[numSides - 1].x) / 2.0; 168 | lastVertex.y = (vertices[0].y + vertices[numSides - 1].y) / 2.0; 169 | } 170 | else if (mode == 2) { 171 | lastVertex.x = (centerPolygonVertices[0].x + 172 | centerPolygonVertices[numSides - 1].x) / 2.0; 173 | lastVertex.y = (centerPolygonVertices[0].y + 174 | centerPolygonVertices[numSides - 1].y) / 2.0; 175 | } 176 | else { 177 | lastVertex.x = (originPolygonVertices[0].x + 178 | originPolygonVertices[numSides - 1].x) / 2.0; 179 | lastVertex.y = (originPolygonVertices[0].y + 180 | originPolygonVertices[numSides - 1].y) / 2.0; 181 | } 182 | midpoints.push_back(lastVertex); 183 | } 184 | 185 | void draw::draw_ngon_star(int numSides) { 186 | 187 | point lastVertex, solution, eq1pt1, 188 | eq1pt2, eq2pt1, eq2pt2; 189 | 190 | // Delta factors: 191 | int df1, df2, df3, df4; 192 | 193 | // Moves rays away from the midpoint. 194 | if (deltaMode == DELTA_AWAY) { 195 | df1 = 1; 196 | df2 = df3 = df4 = -1; 197 | } 198 | // Moves rays towards the midpoint. 199 | else { 200 | df1 = -1; 201 | df2 = df3 = df4 = 1; 202 | } 203 | 204 | calculate_midpoints(numSides); 205 | 206 | for (int i = 0; i < numSides - 1; i++) { 207 | 208 | // A vertex adjacent to the midpoint of 209 | // a polygon's side is rotated by the given angle. 210 | // An equation of a line is formed with this rotated 211 | // vertex and the midpoint adjacent to it. 212 | // Another equation of a line is formed with the 213 | // same rotated vertex and the second midpoint 214 | // adjacent to it. 215 | // The intersection point of both of these lines are 216 | // then calculated. 217 | 218 | eq1pt1 = midpoints[i]; 219 | eq2pt1 = midpoints[i + 1]; 220 | 221 | if (mode == 1) { 222 | eq1pt2 = rotatePoint(vertices[i + 1], midpoints[i], 223 | -angleInDegrees * PF_PI / 180); 224 | eq2pt2 = rotatePoint(vertices[i + 1], midpoints[i + 1], 225 | angleInDegrees * PF_PI / 180); 226 | eq1pt1 = move_along_line(vertices[i], vertices[i + 1], eq1pt1, 227 | df1 * delta / 2.0); 228 | eq2pt1 = move_along_line(vertices[i + 1], eq2pt1, eq2pt1, 229 | df2 * delta / 2.0); 230 | } 231 | else if (mode == 2) { 232 | eq1pt2 = rotatePoint(centerPolygonVertices[i + 1], midpoints[i], 233 | -angleInDegrees * PF_PI / 180); 234 | eq2pt2 = rotatePoint(centerPolygonVertices[i + 1], midpoints[i + 1], 235 | angleInDegrees * PF_PI / 180); 236 | eq1pt1 = move_along_line(centerPolygonVertices[i], 237 | centerPolygonVertices[i + 1], eq1pt1, 238 | df1 * delta / 2.0); 239 | eq2pt1 = move_along_line(centerPolygonVertices[i + 1], eq2pt1, eq2pt1, 240 | df2 * delta / 2.0); 241 | } 242 | else { 243 | eq1pt2 = rotatePoint(originPolygonVertices[i + 1], midpoints[i], 244 | -angleInDegrees * PF_PI / 180); 245 | eq2pt2 = rotatePoint(originPolygonVertices[i + 1], midpoints[i + 1], 246 | angleInDegrees * PF_PI / 180); 247 | eq1pt1 = move_along_line(originPolygonVertices[i], 248 | originPolygonVertices[i + 1], eq1pt1, 249 | df1 * delta / 2.0); 250 | eq2pt1 = move_along_line(originPolygonVertices[i + 1], eq2pt1, eq2pt1, 251 | df2 * delta / 2.0); 252 | } 253 | 254 | solution = findIntersection(eq1pt1, eq1pt2, eq2pt1, eq2pt2); 255 | 256 | cairo_move_to(cr, eq1pt1.x, eq1pt1.y); 257 | cairo_line_to(cr, solution.x, solution.y); 258 | cairo_move_to(cr, eq2pt1.x, eq2pt1.y); 259 | cairo_line_to(cr, solution.x, solution.y); 260 | cairo_identity_matrix(cr); 261 | } 262 | 263 | eq1pt1 = midpoints[numSides - 1]; 264 | eq2pt1 = midpoints[0]; 265 | 266 | if (mode == 1) { 267 | 268 | eq1pt2 = rotatePoint(vertices[0], midpoints[numSides - 1], 269 | -angleInDegrees * PF_PI / 180); 270 | eq2pt2 = rotatePoint(vertices[0], midpoints[0], 271 | angleInDegrees * PF_PI / 180); 272 | eq1pt1 = move_along_line(vertices[0], vertices[numSides - 1], eq1pt1, 273 | df3 * delta / 2.0); 274 | eq2pt1 = move_along_line(vertices[0], eq2pt1, eq2pt1, 275 | df4 * delta / 2.0); 276 | } 277 | else if (mode == 2) { 278 | 279 | eq1pt2 = rotatePoint(centerPolygonVertices[0], midpoints[numSides - 1], 280 | -angleInDegrees * PF_PI / 180); 281 | eq2pt2 = rotatePoint(centerPolygonVertices[0], midpoints[0], 282 | angleInDegrees * PF_PI / 180); 283 | eq1pt1 = move_along_line(centerPolygonVertices[0], 284 | centerPolygonVertices[numSides - 1], eq1pt1, 285 | df3 * delta / 2.0); 286 | eq2pt1 = move_along_line(centerPolygonVertices[0], eq2pt1, eq2pt1, 287 | df4 * delta / 2.0); 288 | } 289 | else { 290 | 291 | eq1pt2 = rotatePoint(originPolygonVertices[0], midpoints[numSides - 1], 292 | -angleInDegrees * PF_PI / 180); 293 | eq2pt2 = rotatePoint(originPolygonVertices[0], midpoints[0], 294 | angleInDegrees * PF_PI / 180); 295 | 296 | eq1pt1 = move_along_line(originPolygonVertices[0], 297 | originPolygonVertices[numSides - 1], eq1pt1, 298 | df3 * delta / 2.0); 299 | eq2pt1 = move_along_line(originPolygonVertices[0], eq2pt1, eq2pt1, 300 | df4 * delta / 2.0); 301 | } 302 | 303 | solution = findIntersection(eq1pt1, eq1pt2, eq2pt1, eq2pt2); 304 | 305 | cairo_move_to(cr, eq1pt1.x, eq1pt1.y); 306 | cairo_line_to(cr, solution.x, solution.y); 307 | cairo_move_to(cr, eq2pt1.x, eq2pt1.y); 308 | cairo_line_to(cr, solution.x, solution.y); 309 | 310 | set_pattern_properties(); 311 | cairo_stroke_preserve(cr); 312 | } 313 | 314 | void draw::draw_shape() { 315 | if (!hideTiling) { 316 | if (mode == 1) { 317 | cairo_move_to(cr, vertices[0].x, vertices[0].y); 318 | 319 | for (int i = 1; i < int(vertices.size()); i++) { 320 | cairo_line_to(cr, vertices[i].x, vertices[i].y); 321 | } 322 | cairo_line_to(cr, vertices[0].x, vertices[0].y); 323 | } 324 | else if (mode == 2) { 325 | cairo_move_to(cr, centerPolygonVertices[0].x, centerPolygonVertices[0].y); 326 | 327 | for (int i = 1; i < int(centerPolygonVertices.size()); i++) { 328 | cairo_line_to(cr, centerPolygonVertices[i].x, centerPolygonVertices[i].y); 329 | } 330 | cairo_line_to(cr, centerPolygonVertices[0].x, centerPolygonVertices[0].y); 331 | } 332 | else { 333 | cairo_move_to(cr, originPolygonVertices[0].x, originPolygonVertices[0].y); 334 | 335 | for (int i = 1; i < int(originPolygonVertices.size()); i++) { 336 | cairo_line_to(cr, originPolygonVertices[i].x, originPolygonVertices[i].y); 337 | } 338 | cairo_line_to(cr, originPolygonVertices[0].x, originPolygonVertices[0].y); 339 | } 340 | cairo_stroke_preserve(cr); 341 | } 342 | } 343 | 344 | void draw::draw_ngon(int numSides) { 345 | 346 | calculate_center_vertices(numSides); 347 | 348 | if (!hideTiling) { 349 | draw_shape(); 350 | } 351 | 352 | } 353 | 354 | void draw::set_pattern_properties() { 355 | cairo_set_source_rgba(cr, patternColor.red / 255.0, 356 | patternColor.green / 255.0, 357 | patternColor.blue / 255.0, 1.0); 358 | cairo_set_line_width(cr, patternWidth); 359 | } 360 | 361 | 362 | void draw::set_bg_color() 363 | { cairo_set_source_rgba(cr, bgColor.red / 255.0, 364 | bgColor.green / 255.0, 365 | bgColor.blue / 255.0, 1.0); 366 | cairo_rectangle(cr, 0, 0, double(output->width), double(output->height)); 367 | cairo_stroke_preserve(cr); 368 | cairo_fill(cr); 369 | } 370 | 371 | double draw::findApothem(double radius) { 372 | // The apothem is a line segment that connects 373 | // the midpoint of a polygon's side to the 374 | // center of the polygon. 375 | // It is perpendicular to the side it emerges 376 | // from and bisects the same. 377 | // A right angled triangle is formed by the 378 | // radius of the polygon (hypotenuse), half 379 | // the side length of the polygon (base) 380 | // and the apothem (height). 381 | // We apply pythogoras theorem in this triangle 382 | // to find the length of the apothem. 383 | return sqrt(pow(radius, 2) - pow(sideLength / 2.0, 2)); 384 | } 385 | 386 | point draw::findCenter(point& v0, point& v1, int numSides, 387 | int numSidesCenter, int side) { 388 | 389 | double radius = sideLength / (2.0 * (sin(PF_PI / numSides))); 390 | int factor = 1; 391 | 392 | if (side < numSidesCenter / 2 || side == numSidesCenter) { 393 | factor = -1; 394 | } 395 | 396 | // Find midpoint of line joining v0 and v1: 397 | point midPoint; 398 | midPoint.x = (v0.x + v1.x) / 2.0; 399 | midPoint.y = (v0.y + v1.y) / 2.0; 400 | 401 | equation eq = construct_equation_from_pts(v0, v1); 402 | 403 | // We find a point that is the apothem length away 404 | // from the midpoint of the polygon's side, which is the 405 | // center of the polygon. 406 | 407 | if (isHorizontal(eq)) { 408 | midPoint.y += findApothem(radius) * factor; 409 | } 410 | else if (isVertical(eq)) { 411 | midPoint.x += findApothem(radius) * factor; 412 | } 413 | else { 414 | 415 | // Calculate slope of the side: 416 | double sideSlope = (v1.y - v0.y) / (v1.x - v0.x); 417 | 418 | // The apothem is perpendicular to the side so its slope would be 419 | // the -ve reciprocal of the slope of the side it emerges from. 420 | double apothemSlope = -1 / sideSlope; 421 | 422 | // Refer to: https://tinyurl.com/4pfbcb4j 423 | 424 | midPoint.x += findApothem(radius) * 425 | sqrt(1 / (1 + pow(apothemSlope, 2))) * factor; 426 | midPoint.y += apothemSlope * findApothem(radius) * 427 | sqrt(1 / (1 + pow(apothemSlope, 2))) * factor; 428 | } 429 | 430 | return midPoint; 431 | } 432 | 433 | void draw::calculate_vertices_known(point v0, point v1, int numSides, 434 | int numSidesCenter, int side) { 435 | center = findCenter(v0, v1, numSides, numSidesCenter, side); 436 | if (mode == 1) { 437 | vertices.clear(); 438 | vertices.push_back(v0); 439 | vertices.push_back(v1); 440 | } 441 | else if (mode == 2) { 442 | centerPolygonVertices.clear(); 443 | centerPolygonVertices.push_back(v0); 444 | centerPolygonVertices.push_back(v1); 445 | } 446 | else { 447 | originPolygonVertices.clear(); 448 | originPolygonVertices.push_back(v0); 449 | originPolygonVertices.push_back(v1); 450 | } 451 | 452 | // Refer to: https://tinyurl.com/mwkruy 453 | double r = sqrt(pow((v0.x - center.x), 2) + pow((v0.y - center.y), 2)); 454 | double a = atan2((v0.y - center.y), (v0.x - center.x)); 455 | for (int i = 2; i < numSides; i++) { 456 | point vertex; 457 | vertex.x = center.x + r * cos(a + 2 * PF_PI * i / numSides); 458 | vertex.y = center.y + r * sin(a + 2 * PF_PI * i / numSides); 459 | if (mode == 1) { 460 | vertices.push_back(vertex); 461 | } 462 | else if (mode == 2) { 463 | centerPolygonVertices.push_back(vertex); 464 | } 465 | else { 466 | originPolygonVertices.push_back(vertex); 467 | } 468 | } 469 | sort_vertices(); 470 | } 471 | 472 | void draw::sort_vertices() { 473 | 474 | std::map verticeAngle; 475 | 476 | // Refer to: https://tinyurl.com/6aa5hsbf 477 | 478 | if (mode == 1) { 479 | for (int i = 0; i < int(vertices.size()); i++) { 480 | verticeAngle[atan2(vertices[i].x - center.x, 481 | vertices[i].y - center.y)] = vertices[i]; 482 | } 483 | vertices.clear(); 484 | } 485 | else if (mode == 2) { 486 | for (int i = 0; i < int(centerPolygonVertices.size()); i++) { 487 | verticeAngle[atan2(centerPolygonVertices[i].x - center.x, 488 | centerPolygonVertices[i].y - center.y)] = centerPolygonVertices[i]; 489 | } 490 | centerPolygonVertices.clear(); 491 | } 492 | else { 493 | for (int i = 0; i < int(originPolygonVertices.size()); i++) { 494 | verticeAngle[atan2(originPolygonVertices[i].x - center.x, 495 | originPolygonVertices[i].y - center.y)] = originPolygonVertices[i]; 496 | } 497 | originPolygonVertices.clear(); 498 | } 499 | 500 | for (std::map::iterator it = verticeAngle.begin(); 501 | it != verticeAngle.end(); it++) { 502 | 503 | if (mode == 1) { 504 | vertices.push_back(it->second); 505 | } 506 | else if (mode == 2) { 507 | centerPolygonVertices.push_back(it->second); 508 | } 509 | else { 510 | originPolygonVertices.push_back(it->second); 511 | } 512 | } 513 | } 514 | 515 | bool draw::attach_shape(int numSidesShapeToAttach, int numSidesCenter, 516 | int side) { 517 | 518 | if (mode == 1) { 519 | 520 | if (side == numSidesCenter) { 521 | 522 | calculate_vertices_known(vertices[numSidesCenter - 1], 523 | vertices[0], 524 | numSidesShapeToAttach, numSidesCenter, side); 525 | } 526 | else if (side != numSidesCenter) { 527 | 528 | calculate_vertices_known(vertices[side - 1], 529 | vertices[side], 530 | numSidesShapeToAttach, numSidesCenter, side); 531 | } 532 | } 533 | else if (mode == 2) { 534 | 535 | if (side == numSidesCenter) { 536 | 537 | calculate_vertices_known(centerPolygonVertices[numSidesCenter - 1], 538 | centerPolygonVertices[0], 539 | numSidesShapeToAttach, numSidesCenter, side); 540 | } 541 | else if (side != numSidesCenter) { 542 | 543 | calculate_vertices_known(centerPolygonVertices[side - 1], 544 | centerPolygonVertices[side], 545 | numSidesShapeToAttach, numSidesCenter, side); 546 | } 547 | } 548 | else { 549 | 550 | if (side == numSidesCenter) { 551 | 552 | calculate_vertices_known(originPolygonVertices[numSidesCenter - 1], 553 | originPolygonVertices[0], 554 | numSidesShapeToAttach, numSidesCenter, side); 555 | } 556 | else if (side != numSidesCenter) { 557 | 558 | calculate_vertices_known(originPolygonVertices[side - 1], 559 | originPolygonVertices[side], 560 | numSidesShapeToAttach, numSidesCenter, side); 561 | } 562 | 563 | } 564 | 565 | // Indicates to stop attaching shapes when all vertices of the polygon to be 566 | // attached are outside the output. 567 | if (!areVerticesBounded()) { 568 | return false; 569 | } 570 | 571 | if (!hideTiling) { 572 | draw_shape(); 573 | } 574 | return true; 575 | } 576 | 577 | bool draw::isWithinBounds(point& pt) { 578 | return (pt.x > 0 && pt.x < double(output->width)) 579 | && (pt.y > 0 && pt.y < double(output->height)); 580 | } 581 | 582 | bool draw::areVerticesBounded() { 583 | bool indicator = false; 584 | if (mode == 1) { 585 | for (int i = 0; i < int(vertices.size()); i++) { 586 | if (isWithinBounds(vertices[i])) { 587 | indicator = true; 588 | break; 589 | } 590 | } 591 | } 592 | else if (mode == 2) { 593 | for (int i = 0; i < int(centerPolygonVertices.size()); i++) { 594 | if (isWithinBounds(centerPolygonVertices[i])) { 595 | indicator = true; 596 | break; 597 | } 598 | } 599 | 600 | } 601 | else { 602 | for (int i = 0; i < int(originPolygonVertices.size()); i++) { 603 | if (isWithinBounds(originPolygonVertices[i])) { 604 | indicator = true; 605 | break; 606 | } 607 | } 608 | } 609 | return indicator; 610 | } 611 | 612 | 613 | int draw::find_vertex_from_center_ngon(int index) { 614 | 615 | for (int i = 0; i < int(centerPolygonVertices.size()); i++) { 616 | 617 | // Find the position of the point at index from centerPolygon 618 | // in centerPolygonVertices: 619 | if (centerPolygonVertices[i].x == centerPolygon[index].x && 620 | centerPolygonVertices[i].y == centerPolygon[index].y) { 621 | int position; 622 | 623 | // Position of point before the the one 624 | // at index in centerPolygon is stored. 625 | if (i == 0) { 626 | position = int(centerPolygonVertices.size()) - 1; 627 | } 628 | else { 629 | position = i - 1; 630 | } 631 | 632 | point temp = centerPolygonVertices[position]; 633 | 634 | for (int j = 0; j < int(centerPolygon.size()); j++) { 635 | // If centerPolygon contains the point temp, then 636 | // return the position of the point after the point 637 | // from centerPolygon at index. 638 | if (temp.x == centerPolygon[j].x && temp.y == centerPolygon[j].y) { 639 | return i + 1; 640 | } 641 | } 642 | 643 | // Otherwise, return the position of the point before the point 644 | // from centerPolygon at index. 645 | return position; 646 | 647 | } 648 | } 649 | return -1; 650 | } 651 | 652 | void draw::pattern() { 653 | if (outputMode == MODE_CENTERED) { 654 | draw_ngon(numSidesCenterMode); 655 | draw_ngon_star(numSidesCenterMode); 656 | } 657 | else if (outputMode == MODE_MULTIPLE) { 658 | if (tilingChoice == TILING_666) { 659 | regular_tiling(6); 660 | } 661 | else if (tilingChoice == TILING_444) { 662 | regular_tiling(4); 663 | } 664 | else if (tilingChoice == TILING_488) { 665 | four_eight_eight(); 666 | } 667 | else if (tilingChoice == TILING_31212) { 668 | three_twelve_twelve(); 669 | } 670 | else if (tilingChoice == TILING_4612) { 671 | four_six_twelve(); 672 | } 673 | } 674 | } 675 | 676 | 677 | 678 | 679 | 680 | -------------------------------------------------------------------------------- /Draw.h: -------------------------------------------------------------------------------- 1 | // (c) 2021 Nithisha Nantha Kumar 2 | // This code is licensed under MIT license (see LICENSE.md for details) 3 | 4 | #pragma once 5 | 6 | #ifndef Draw_H 7 | #define Draw_H 8 | 9 | #include "Pattern.h" 10 | #include 11 | #include 12 | 13 | struct point { 14 | double x; 15 | double y; 16 | }; 17 | 18 | // stores an equation in ax + by = c form 19 | struct equation { 20 | double a; 21 | double b; 22 | double c; 23 | }; 24 | 25 | 26 | class draw { 27 | 28 | private: 29 | 30 | std::vector vertices; 31 | // Stores vertices of the current polygon to which 32 | // other polygons have to be attached 33 | std::vector centerPolygon; 34 | std::vector centerPolygonVertices; 35 | // Stores vertices of the polygon drawn in the center of 36 | // the output (first polygon in tiling) 37 | std::vector originPolygon; 38 | std::vector originPolygonVertices; 39 | std::vector midpoints; 40 | point center; 41 | cairo_t* cr; 42 | PF_LayerDef* output; 43 | // Mode can take values of 1, 2, 3. 44 | // When mode == 1, calculated vertices 45 | // are stored in the vertices vector. 46 | // Similarly, when mode == 2, calculated 47 | // vertices are stored in centerPolygonVertices 48 | // and when mode == 3, vertices are stored in 49 | // originPolygonVertices. 50 | int mode; 51 | 52 | /*Parameter Values*/ 53 | double sideLength; 54 | bool hideTiling; 55 | PF_Pixel bgColor; 56 | PF_Pixel patternColor; 57 | double patternWidth; 58 | int deltaMode; 59 | double delta; 60 | double angleInDegrees; 61 | int numSidesCenterMode; 62 | int outputMode; 63 | int tilingChoice; 64 | 65 | //REQUIRES: non-parallel, non-horizontal, non-vertical & non-collinear 66 | // linear equations of 2 lines. 67 | //EFFECTS: returns the intersection point of both lines by solving 68 | // the equation using determinants. 69 | point solve_equation(equation& eq1, equation& eq2); 70 | 71 | //EFFECTS: returns an equation in ax + by = c form from 72 | // the two points. 73 | equation construct_equation_from_pts(point& pt1, point& pt2); 74 | 75 | //REQUIRES: angle in radians 76 | //EFFECTS: returns a point rotated about another point by the given angle. 77 | point rotatePoint(point& original, point& rotateAbt, double angleInRadians); 78 | 79 | //REQUIRES: 2 linear equations representing non-parallel lines. 80 | //EFFECTS: returns true if the two lines are collinear & false otherwise. 81 | bool isCollinear(equation& eq1, equation& eq2); 82 | 83 | //EFFECTS: returns true if the line formed by 2 points is 84 | // horizontal and false otherwise. 85 | bool isHorizontal(equation& eq); 86 | 87 | //EFFECTS: returns true if the line formed by 2 points is 88 | // vertical and false otherwise. 89 | bool isVertical(equation& eq); 90 | 91 | //EFFECTS: returns midPoint moved by a distance delta 92 | // along the line formed by v1 and v2. 93 | point move_along_line(point& v1, point& v2, 94 | point midPoint, double distance); 95 | 96 | //REQUIRES: the lines formed by each of the two points 97 | // should not be parallel. 98 | //EFFECTS: returns the intersection point of two lines. 99 | point findIntersection(point& eq1pt1, point& eq1pt2, 100 | point& eq2pt1, point& eq2pt2); 101 | 102 | //REQUIRES: numSides is an integer greater than 2. 103 | //MODIFIES: vertices 104 | //EFFECTS: calculates the coordinates of a polygon's vertices 105 | // given the default center of the polygon & stores it 106 | // in vertices. 107 | void calculate_center_vertices(int numSides); 108 | 109 | 110 | //REQUIRES: numSides is an integer greater than 2. 111 | //MODIFIES: midpoints 112 | //EFFECTS: calculates the midpoints of each of the sides 113 | // of the polygon & stores it in midpoints. 114 | void calculate_midpoints(int numSides); 115 | 116 | //REQUIRES: numSides is an integer greater than 2. 117 | //MODIFIES: cr, midpoints 118 | //EFFECTS: implements the Hankin's polygons-in-contact algorithm. 119 | // Refer to: https://dl.acm.org/doi/pdf/10.5555/1089508.1089538 120 | // https://www.youtube.com/watch?v=ld4gpQnaziU 121 | void draw_ngon_star(int numSides); 122 | 123 | //REQUIRES: numSides >= 3 124 | //MODIFIES: cr, vertices 125 | //EFFECTS: calculates vertices of the polygon with the default center 126 | // & draws it. 127 | void draw_ngon(int numSides); 128 | 129 | //MODIFIES: cr 130 | //EFFECTS: draws a polygon in the current mode when tiling is not hidden. 131 | void draw_shape(); 132 | 133 | //EFFECTS: returns the length of the polygon's apothem given the 134 | // polygon's radius. 135 | double findApothem(double radius); 136 | 137 | //REQUIRES: numSides >= 3, numSidesCenter >= 3, 138 | // 1 <= side <= numSidesCenter 139 | //EFFECTS: returns the center of the polygon to be attached to another 140 | // polygon which is referred to as the center polygon. 141 | point findCenter(point& v0, point& v1, int numSides, 142 | int numSidesCenter, int side); 143 | 144 | //REQUIRES: numSides >= 3, numSidesCenter >= 3, 145 | // 1 <= side <= numSidesCenter 146 | //MODIFIES: vertices, centerPolygonVertices, originPolygonVertices 147 | //EFFECTS: calculates the rest of the vertices of a polygon 148 | // with 2 known vertices. 149 | void calculate_vertices_known(point v0, point v1, int numSides, 150 | int numSidesCenter, int side); 151 | 152 | //MODIFIES: vertices, centerPolygonVertices, originPolygonVertices 153 | //EFFECTS: sorts the vertices of the polygon in counter-clockwise order. 154 | void sort_vertices(); 155 | 156 | //REQUIRES: numSidesShapeToAttach >= 3, numSidesCenter >= 3, 157 | // 1 <= side <= numSidesCenter 158 | //MODIFIES: vertices, centerPolygonVertices, originPolygonVertices, cr 159 | //EFFECTS: attaches a polygon to the given side of another polygon 160 | // which is referred to as the center polygon. 161 | /**This function only works for sides of the center polygon whose apothem 162 | is not vertical and not horizontal**/ 163 | bool attach_shape(int numSidesShapeToAttach, int numSidesCenter, 164 | int side); 165 | 166 | //EFFECTS: returns true if the given point is within the bounds of the output 167 | // & false otherwise. 168 | bool isWithinBounds(point& pt); 169 | 170 | //EFFECTS: returns true if at least one point is within the bounds 171 | // of the output in vertices, centerPolygonVertices, or 172 | // originPolygonVertices & false otherwise. 173 | bool areVerticesBounded(); 174 | 175 | //REQUIRES: valid index of point in centerPolygon (this point should 176 | // be a vertex of the current polygon that is to be attached to 177 | // the centerPolygon), 178 | // centerPolygon to contain vertices of a polygon to which 179 | // the current polygon is to be attached, 180 | // centerPolygonVertices to contain vertices of a polygon already 181 | // attached to the centerPolygon & located adjacent to the current 182 | // polygon that is now to be attached to the centerPolygon. 183 | //EFFECTS: returns the position of the next vertex (in counter-clockwise 184 | // order) of the current polygon to be attached to the centerPolygon 185 | // from centerPolygonVertices. 186 | /**This function is useful to calculate the vertices of a polygon that is to 187 | be attached to a side of the centerPolygon whose apothem is vertical 188 | or horizontal. It finds vertices of the current polygon from the existing 189 | vertices of its adjacent polygons.**/ 190 | int find_vertex_from_center_ngon(int index); 191 | 192 | //REQUIRES: numSides = 4 || numSides = 6 193 | //MODIFIES: cr, vertices, originPolygonVertices, 194 | // originPolygon, centerPolygon, 195 | // centerPolygonVertices, midpoints 196 | //EFFECTS: implements Hankin's Polygons-in-contact algorithm in 197 | // 4.4.4 or 6.6.6 tiling. 198 | void regular_tiling(int numSides); 199 | 200 | 201 | //MODIFIES: cr, vertices, originPolygonVertices, 202 | // originPolygon, centerPolygon, 203 | // centerPolygonVertices, midpoints 204 | //EFFECTS: implements Hankin's Polygons-in-contact algorithm in 4.8.8 tiling. 205 | void four_eight_eight(); 206 | 207 | 208 | //MODIFIES: cr, vertices, originPolygonVertices, 209 | // originPolygon, centerPolygon, 210 | // centerPolygonVertices, midpoints 211 | //EFFECTS: executes an inner loop for implementing Hankin's 212 | // polygons-in-contact algorithm in 4.6.12 tiling . 213 | void four_six_twelve_inner_loop(bool left = true); 214 | 215 | 216 | //MODIFIES: cr, vertices, originPolygonVertices, 217 | // originPolygon, centerPolygon, 218 | // centerPolygonVertices, midpoints 219 | //EFFECTS: implements Hankin's Polygons-in-contact algorithm in 4.6.12 tiling. 220 | void four_six_twelve(); 221 | 222 | //MODIFIES: cr, vertices, originPolygonVertices, 223 | // originPolygon, centerPolygon, 224 | // centerPolygonVertices, midpoints 225 | //EFFECTS: implements Hankin's Polygons-in-contact algorithm in 3.12.12 tiling. 226 | void three_twelve_twelve(); 227 | 228 | //MODIFIES: cr 229 | //EFFECTS: sets pattern properties based on selected parameters. 230 | void set_pattern_properties(); 231 | 232 | //MODIFIES: cr 233 | //EFFECTS: sets the background color of the composition 234 | // based on selected parameters. 235 | void set_bg_color(); 236 | 237 | public: 238 | 239 | draw(cairo_t* cr_in, PF_LayerDef* output_in, PF_ParamDef* params[]) 240 | : cr(cr_in), output(output_in) { 241 | center.x = double(output->width) * 0.5; 242 | center.y = double(output->height) * 0.5; 243 | outputMode = params[Pattern_CHOOSEMODE]->u.pd.value; 244 | tilingChoice = params[Pattern_CHOOSETILING]->u.pd.value; 245 | sideLength = params[Pattern_SIDELENGTH]->u.fs_d.value; 246 | hideTiling = params[Pattern_HIDETILINGCHKBOX]->u.bd.value; 247 | bgColor = params[Pattern_BGCOLOR]->u.cd.value; 248 | set_bg_color(); 249 | patternColor = params[Pattern_PATTERNCOLOR]->u.cd.value; 250 | patternWidth = params[Pattern_PATTERNWIDTH]->u.fs_d.value; 251 | deltaMode = params[Pattern_CHOOSEDELTA]->u.pd.value; 252 | delta = params[DELTA_ID]->u.fs_d.value; 253 | angleInDegrees = params[ANGLE_ID]->u.fs_d.value; 254 | numSidesCenterMode = params[Pattern_NUMSIDES]->u.fs_d.value; 255 | mode = 1; 256 | } 257 | 258 | void pattern(); 259 | }; 260 | #endif // Draw_H -------------------------------------------------------------------------------- /Draw_Tiling.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2021 Nithisha Nantha Kumar 2 | // This code is licensed under MIT license (see LICENSE.md for details) 3 | 4 | 5 | #include "Draw.h" 6 | 7 | 8 | /* All tiling functions start by drawing a polygon at the center of the output. 9 | This is the originPolygon. 10 | 1st and 2nd while loop: Polygons are attached to the left and right side 11 | of the origin polygon. 12 | 3rd while loop: polygons are attached diagonally upward to the originPolygon. 13 | Each polygon attached is the centerPolygon. The inner loops 14 | attach shapes to the left and right sides of the centerPolygon. 15 | The 4th while loop performs the same functions as the 3rd but attaches polygons 16 | diagonally downward to the originPolygon. 17 | */ 18 | 19 | void draw::regular_tiling(int numSides) { 20 | // represents sides to attach shapes to 21 | int a, b, c, d; 22 | 23 | if (numSides == 6) { 24 | // hexagonal tiling 25 | a = 2, b = 5, c = 1, d = 4; 26 | } 27 | else { 28 | // square tiling 29 | a = 1, b = 3, c = 2, d = 4; 30 | } 31 | 32 | draw_ngon(numSides); 33 | draw_ngon_star(numSides); 34 | originPolygon = vertices; 35 | originPolygonVertices = vertices; 36 | 37 | while (attach_shape(numSides, numSides, a)) { 38 | draw_ngon_star(numSides); 39 | } 40 | mode = 3; 41 | while (attach_shape(numSides, numSides, b)) { 42 | draw_ngon_star(numSides); 43 | } 44 | 45 | originPolygonVertices = originPolygon; 46 | 47 | while (attach_shape(numSides, numSides, c)) { 48 | draw_ngon_star(numSides); 49 | mode = 2; 50 | centerPolygonVertices = originPolygonVertices; 51 | while (attach_shape(numSides, numSides, a)) { 52 | draw_ngon_star(numSides); 53 | } 54 | centerPolygonVertices = originPolygonVertices; 55 | while (attach_shape(numSides, numSides, b)) { 56 | draw_ngon_star(numSides); 57 | } 58 | mode = 3; 59 | } 60 | 61 | originPolygonVertices = originPolygon; 62 | 63 | while (attach_shape(numSides, numSides, d)) { 64 | draw_ngon_star(numSides); 65 | mode = 2; 66 | centerPolygonVertices = originPolygonVertices; 67 | while (attach_shape(numSides, numSides, a)) { 68 | draw_ngon_star(numSides); 69 | } 70 | centerPolygonVertices = originPolygonVertices; 71 | while (attach_shape(numSides, numSides, b)) { 72 | draw_ngon_star(numSides); 73 | } 74 | mode = 3; 75 | } 76 | 77 | mode = 1; 78 | } 79 | 80 | 81 | void draw::four_eight_eight() { 82 | draw_ngon(8); 83 | draw_ngon_star(8); 84 | originPolygon = vertices; 85 | attach_shape(4, 8, 2); 86 | draw_ngon_star(4); 87 | vertices = originPolygon; 88 | attach_shape(8, 8, 3); 89 | draw_ngon_star(8); 90 | centerPolygon = vertices; 91 | attach_shape(4, 8, 2); 92 | draw_ngon_star(4); 93 | vertices = centerPolygon; 94 | 95 | while (attach_shape(8, 8, 3)) { 96 | draw_ngon_star(8); 97 | originPolygonVertices = vertices; 98 | mode = 3; 99 | attach_shape(4, 8, 2); 100 | draw_ngon_star(4); 101 | mode = 1; 102 | } 103 | vertices = centerPolygon; 104 | 105 | while (attach_shape(8, 8, 1)) { 106 | draw_ngon_star(8); 107 | centerPolygon = vertices; 108 | centerPolygonVertices = vertices; 109 | mode = 3; 110 | originPolygonVertices = vertices; 111 | attach_shape(4, 8, 2); 112 | draw_ngon_star(4); 113 | mode = 2; 114 | while (attach_shape(8, 8, 3)) { 115 | draw_ngon_star(8); 116 | originPolygonVertices = centerPolygonVertices; 117 | mode = 3; 118 | attach_shape(4, 8, 2); 119 | draw_ngon_star(4); 120 | mode = 2; 121 | } 122 | centerPolygonVertices = centerPolygon; 123 | mode = 2; 124 | while (attach_shape(8, 8, 7)) { 125 | draw_ngon_star(8); 126 | originPolygonVertices = centerPolygonVertices; 127 | mode = 3; 128 | attach_shape(4, 8, 2); 129 | draw_ngon_star(4); 130 | mode = 2; 131 | } 132 | mode = 1; 133 | } 134 | 135 | mode = 1; 136 | vertices = originPolygon; 137 | attach_shape(8, 8, 7); 138 | draw_ngon_star(8); 139 | centerPolygon = vertices; 140 | attach_shape(4, 8, 2); 141 | draw_ngon_star(4); 142 | vertices = centerPolygon; 143 | 144 | while (attach_shape(8, 8, 7)) { 145 | draw_ngon_star(8); 146 | originPolygonVertices = vertices; 147 | mode = 3; 148 | attach_shape(4, 8, 2); 149 | draw_ngon_star(4); 150 | mode = 1; 151 | } 152 | vertices = centerPolygon; 153 | while (attach_shape(8, 8, 5)) { 154 | draw_ngon_star(8); 155 | centerPolygon = vertices; 156 | centerPolygonVertices = vertices; 157 | mode = 3; 158 | originPolygonVertices = vertices; 159 | attach_shape(4, 8, 2); 160 | draw_ngon_star(4); 161 | mode = 2; 162 | while (attach_shape(8, 8, 3)) { 163 | draw_ngon_star(8); 164 | originPolygonVertices = centerPolygonVertices; 165 | mode = 3; 166 | attach_shape(4, 8, 2); 167 | draw_ngon_star(4); 168 | mode = 2; 169 | } 170 | centerPolygonVertices = centerPolygon; 171 | mode = 2; 172 | while (attach_shape(8, 8, 7)) { 173 | draw_ngon_star(8); 174 | originPolygonVertices = centerPolygonVertices; 175 | mode = 3; 176 | attach_shape(4, 8, 2); 177 | draw_ngon_star(4); 178 | mode = 2; 179 | } 180 | attach_shape(4, 8, 2); 181 | draw_ngon_star(4); 182 | mode = 1; 183 | } 184 | } 185 | 186 | void draw::four_six_twelve_inner_loop(bool left) { 187 | 188 | bool attachShapeValue = true; 189 | int counter = 0; 190 | // represents sides to attach shapes to 191 | int a, b; 192 | 193 | // implements right loop 194 | if (!left) { 195 | a = 1, b = 4; 196 | } 197 | // implements left loop 198 | else { 199 | a = 3, b = 10; 200 | } 201 | 202 | while (counter < 2) { 203 | attachShapeValue = attach_shape(12, 4, a); 204 | originPolygonVertices.clear(); 205 | draw_ngon_star(12); 206 | centerPolygon = vertices; 207 | centerPolygonVertices = vertices; 208 | mode = 2; 209 | originPolygonVertices.push_back(centerPolygonVertices[0]); 210 | originPolygonVertices.push_back(centerPolygonVertices[11]); 211 | centerPolygonVertices = centerPolygon; 212 | attach_shape(6, 12, 11); 213 | draw_ngon_star(6); 214 | originPolygonVertices.push_back( 215 | centerPolygonVertices[find_vertex_from_center_ngon(11)]); 216 | centerPolygonVertices = centerPolygon; 217 | attach_shape(6, 12, 1); 218 | draw_ngon_star(6); 219 | originPolygonVertices.push_back( 220 | centerPolygonVertices[find_vertex_from_center_ngon(0)]); 221 | centerPolygonVertices = centerPolygon; 222 | attach_shape(4, 12, 2); 223 | draw_ngon_star(4); 224 | mode = 1; 225 | attach_shape(4, 12, b); 226 | draw_ngon_star(4); 227 | mode = 3; 228 | draw_shape(); 229 | draw_ngon_star(4); 230 | mode = 1; 231 | if (!attachShapeValue) { 232 | counter++; 233 | } 234 | 235 | } 236 | 237 | 238 | } 239 | 240 | void draw::four_six_twelve() { 241 | draw_ngon(12); 242 | draw_ngon_star(12); 243 | originPolygon = vertices; 244 | attach_shape(4, 12, 12); 245 | draw_ngon_star(4); 246 | vertices = originPolygon; 247 | attach_shape(6, 12, 1); 248 | draw_ngon_star(6); 249 | vertices = originPolygon; 250 | attach_shape(6, 12, 11); 251 | draw_ngon_star(6); 252 | vertices = originPolygon; 253 | 254 | attach_shape(4, 12, 10); 255 | draw_ngon_star(4); 256 | four_six_twelve_inner_loop(false); 257 | vertices = originPolygon; 258 | 259 | attach_shape(4, 12, 4); 260 | draw_ngon_star(4); 261 | four_six_twelve_inner_loop(); 262 | 263 | vertices = originPolygon; 264 | std::vector temp; 265 | 266 | while (attach_shape(4, 12, 2)) { 267 | draw_ngon_star(4); 268 | attach_shape(12, 4, 1); 269 | draw_ngon_star(12); 270 | originPolygonVertices.clear(); 271 | temp = vertices; 272 | centerPolygonVertices = temp; 273 | centerPolygon = temp; 274 | mode = 2; 275 | originPolygonVertices.push_back(centerPolygonVertices[0]); 276 | originPolygonVertices.push_back(centerPolygonVertices[11]); 277 | centerPolygonVertices = temp; 278 | attach_shape(6, 12, 11); 279 | draw_ngon_star(6); 280 | originPolygonVertices.push_back( 281 | centerPolygonVertices[find_vertex_from_center_ngon(11)]); 282 | centerPolygonVertices = temp; 283 | attach_shape(6, 12, 1); 284 | draw_ngon_star(6); 285 | originPolygonVertices.push_back( 286 | centerPolygonVertices[find_vertex_from_center_ngon(0)]); 287 | mode = 3; 288 | draw_shape(); 289 | draw_ngon_star(4); 290 | vertices = temp; 291 | mode = 1; 292 | attach_shape(4, 12, 10); 293 | draw_ngon_star(4); 294 | four_six_twelve_inner_loop(false); 295 | vertices = temp; 296 | attach_shape(4, 12, 4); 297 | draw_ngon_star(4); 298 | four_six_twelve_inner_loop(); 299 | 300 | vertices = temp; 301 | } 302 | 303 | vertices = originPolygon; 304 | while (attach_shape(4, 12, 8)) { 305 | draw_ngon_star(4); 306 | attach_shape(12, 4, 3); 307 | draw_ngon_star(12); 308 | originPolygonVertices.clear(); 309 | temp = vertices; 310 | centerPolygonVertices = temp; 311 | centerPolygon = temp; 312 | mode = 2; 313 | originPolygonVertices.push_back(centerPolygonVertices[0]); 314 | originPolygonVertices.push_back(centerPolygonVertices[11]); 315 | centerPolygonVertices = temp; 316 | attach_shape(6, 12, 11); 317 | draw_ngon_star(6); 318 | originPolygonVertices.push_back( 319 | centerPolygonVertices[find_vertex_from_center_ngon(11)]); 320 | centerPolygonVertices = temp; 321 | attach_shape(6, 12, 1); 322 | draw_ngon_star(6); 323 | originPolygonVertices.push_back( 324 | centerPolygonVertices[find_vertex_from_center_ngon(0)]); 325 | mode = 3; 326 | draw_shape(); 327 | draw_ngon_star(4); 328 | vertices = temp; 329 | mode = 1; 330 | attach_shape(4, 12, 10); 331 | draw_ngon_star(4); 332 | four_six_twelve_inner_loop(false); 333 | vertices = temp; 334 | attach_shape(4, 12, 4); 335 | draw_ngon_star(4); 336 | four_six_twelve_inner_loop(); 337 | vertices = temp; 338 | } 339 | } 340 | 341 | void draw::three_twelve_twelve() { 342 | 343 | draw_ngon(12); 344 | draw_ngon_star(12); 345 | originPolygon = vertices; 346 | attach_shape(3, 12, 1); 347 | draw_ngon_star(3); 348 | vertices = originPolygon; 349 | attach_shape(3, 12, 11); 350 | draw_ngon_star(3); 351 | vertices = originPolygon; 352 | std::vector temp; 353 | 354 | while (attach_shape(12, 12, 10)) { 355 | draw_ngon_star(12); 356 | centerPolygon = vertices; 357 | centerPolygonVertices = vertices; 358 | mode = 2; 359 | attach_shape(3, 12, 1); 360 | draw_ngon_star(3); 361 | centerPolygonVertices = centerPolygon; 362 | attach_shape(3, 12, 11); 363 | draw_ngon_star(3); 364 | mode = 1; 365 | } 366 | vertices = originPolygon; 367 | while (attach_shape(12, 12, 4)) { 368 | draw_ngon_star(12); 369 | centerPolygon = vertices; 370 | centerPolygonVertices = vertices; 371 | mode = 2; 372 | attach_shape(3, 12, 1); 373 | draw_ngon_star(3); 374 | centerPolygonVertices = centerPolygon; 375 | attach_shape(3, 12, 11); 376 | draw_ngon_star(3); 377 | mode = 1; 378 | } 379 | 380 | vertices = originPolygon; 381 | 382 | while (attach_shape(12, 12, 2)) { 383 | draw_ngon_star(12); 384 | centerPolygon = vertices; 385 | centerPolygonVertices = vertices; 386 | mode = 2; 387 | attach_shape(3, 12, 1); 388 | draw_ngon_star(3); 389 | centerPolygonVertices = centerPolygon; 390 | attach_shape(3, 12, 11); 391 | draw_ngon_star(3); 392 | centerPolygonVertices = centerPolygon; 393 | while (attach_shape(12, 12, 10)) { 394 | draw_ngon_star(12); 395 | temp = centerPolygonVertices; 396 | attach_shape(3, 12, 1); 397 | draw_ngon_star(3); 398 | centerPolygonVertices = temp; 399 | attach_shape(3, 12, 11); 400 | draw_ngon_star(3); 401 | centerPolygonVertices = temp; 402 | } 403 | vertices = centerPolygon; 404 | while (attach_shape(12, 12, 4)) { 405 | draw_ngon_star(12); 406 | temp = centerPolygonVertices; 407 | attach_shape(3, 12, 1); 408 | draw_ngon_star(3); 409 | centerPolygonVertices = temp; 410 | attach_shape(3, 12, 11); 411 | draw_ngon_star(3); 412 | centerPolygonVertices = temp; 413 | } 414 | mode = 1; 415 | } 416 | 417 | vertices = originPolygon; 418 | 419 | while (attach_shape(12, 12, 8)) { 420 | draw_ngon_star(12); 421 | centerPolygon = vertices; 422 | centerPolygonVertices = vertices; 423 | mode = 2; 424 | attach_shape(3, 12, 1); 425 | draw_ngon_star(3); 426 | centerPolygonVertices = centerPolygon; 427 | attach_shape(3, 12, 11); 428 | draw_ngon_star(3); 429 | centerPolygonVertices = centerPolygon; 430 | while (attach_shape(12, 12, 10)) { 431 | draw_ngon_star(12); 432 | temp = centerPolygonVertices; 433 | attach_shape(3, 12, 1); 434 | draw_ngon_star(3); 435 | centerPolygonVertices = temp; 436 | attach_shape(3, 12, 11); 437 | draw_ngon_star(3); 438 | centerPolygonVertices = temp; 439 | } 440 | vertices = centerPolygon; 441 | while (attach_shape(12, 12, 4)) { 442 | draw_ngon_star(12); 443 | temp = centerPolygonVertices; 444 | attach_shape(3, 12, 1); 445 | draw_ngon_star(3); 446 | centerPolygonVertices = temp; 447 | attach_shape(3, 12, 11); 448 | draw_ngon_star(3); 449 | centerPolygonVertices = temp; 450 | } 451 | mode = 1; 452 | } 453 | 454 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | As per clause 2.1 a) of the Adobe After Effects CS6 SDK license agreement (https://www.adobe.com/devnet/aftereffects/sdk/cs6_eula.html), 2 | since the following files contain modified Adobe After Effects SDK code - they're subject to copyright by Adobe Systems Incorporated. 3 | 1. Pattern.h 4 | 2. Pattern.cpp 5 | 3. Pattern_Strings.h 6 | 4. Pattern_Strings.cpp 7 | 8 | However, the files below are licensed under the MIT license. 9 | 10 | Draw.h, Draw.cpp, Draw_Tiling.cpp, Color.cpp, Color.h 11 | 12 | Copyright © 2021 Nithisha Nantha Kumar 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files 15 | (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, 16 | publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 17 | subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 23 | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 24 | THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /Pattern.cpp: -------------------------------------------------------------------------------- 1 | /*******************************************************************/ 2 | /* */ 3 | /* ADOBE CONFIDENTIAL */ 4 | /* _ _ _ _ _ _ _ _ _ _ _ _ _ */ 5 | /* */ 6 | /* Copyright 2007 Adobe Systems Incorporated */ 7 | /* All Rights Reserved. */ 8 | /* */ 9 | /* NOTICE: All information contained herein is, and remains the */ 10 | /* property of Adobe Systems Incorporated and its suppliers, if */ 11 | /* any. The intellectual and technical concepts contained */ 12 | /* herein are proprietary to Adobe Systems Incorporated and its */ 13 | /* suppliers and may be covered by U.S. and Foreign Patents, */ 14 | /* patents in process, and are protected by trade secret or */ 15 | /* copyright law. Dissemination of this information or */ 16 | /* reproduction of this material is strictly forbidden unless */ 17 | /* prior written permission is obtained from Adobe Systems */ 18 | /* Incorporated. */ 19 | /* */ 20 | /*******************************************************************/ 21 | 22 | #include "Draw.h" 23 | #include "Color.h" 24 | 25 | static PF_Err 26 | About ( 27 | PF_InData *in_data, 28 | PF_OutData *out_data, 29 | PF_ParamDef *params[], 30 | PF_LayerDef *output ) 31 | { 32 | AEGP_SuiteHandler suites(in_data->pica_basicP); 33 | 34 | suites.ANSICallbacksSuite1()->sprintf( out_data->return_msg, 35 | "%s v%d.%d\r%s", 36 | STR(StrID_Name), 37 | MAJOR_VERSION, 38 | MINOR_VERSION, 39 | STR(StrID_Description)); 40 | return PF_Err_NONE; 41 | } 42 | 43 | static PF_Err 44 | GlobalSetup ( 45 | PF_InData *in_data, 46 | PF_OutData *out_data, 47 | PF_ParamDef *params[], 48 | PF_LayerDef *output ) 49 | { 50 | out_data->my_version = PF_VERSION( MAJOR_VERSION, 51 | MINOR_VERSION, 52 | BUG_VERSION, 53 | STAGE_VERSION, 54 | BUILD_VERSION); 55 | 56 | out_data->out_flags = PF_OutFlag_DEEP_COLOR_AWARE; // just 16bpc, not 32bpc 57 | 58 | return PF_Err_NONE; 59 | } 60 | 61 | static PF_Err 62 | ParamsSetup ( 63 | PF_InData *in_data, 64 | PF_OutData *out_data, 65 | PF_ParamDef *params[], 66 | PF_LayerDef *output ) 67 | { 68 | PF_Err err = PF_Err_NONE; 69 | PF_ParamDef def; 70 | 71 | AEFX_CLR_STRUCT(def); 72 | 73 | 74 | // Calling function from the Color static 75 | // library to generate a color combination through 76 | // machine learning. 77 | color ob; 78 | vector color_combo = ob.generate_color_combo(); 79 | 80 | // Background Color: 81 | PF_ADD_COLOR(STR(StrID_BgColor_Param_Name), 82 | color_combo[1].red, 83 | color_combo[1].green, 84 | color_combo[1].blue, 85 | BGCOLOR_ID); 86 | 87 | AEFX_CLR_STRUCT(def); 88 | 89 | // Choose Mode: 90 | PF_ADD_POPUPX(STR(StrID_ChooseMode_Param_Name), 91 | MODE_SIZE, MODE_MULTIPLE, 92 | STR(StrID_ModeChoices_Param_Name), 93 | PF_ParamFlag_SUPERVISE, 94 | CHOOSEMODE_ID); 95 | 96 | AEFX_CLR_STRUCT(def); 97 | 98 | // Choose type of tiling in multiple mode: 99 | PF_ADD_POPUPX(STR(StrID_ChooseTiling_Param_Name), 100 | TILING_SIZE, TILING_666, 101 | STR(StrID_TilingChoices_Param_Name), 102 | 0, 103 | CHOOSETILING_ID); 104 | 105 | AEFX_CLR_STRUCT(def) 106 | 107 | // Side Length: 108 | PF_ADD_FLOAT_SLIDERX(STR(StrID_SideLength_Param_Name), 109 | Pattern_SIDELENGTH_MIN, 110 | Pattern_SIDELENGTH_MAX, 111 | Pattern_SIDELENGTH_MIN, 112 | Pattern_SIDELENGTH_MAX, 113 | Pattern_SIDELENGTH_DFLT, 114 | PF_Precision_THOUSANDTHS, 115 | 0, 116 | PF_PUI_INVISIBLE, 117 | SIDELENGTH_ID); 118 | 119 | AEFX_CLR_STRUCT(def); 120 | 121 | // Number of sides: 122 | PF_ADD_FLOAT_SLIDERX(STR(StrID_NumberofSides_Param_Name), 123 | Pattern_NUMSIDES_MIN, 124 | Pattern_NUMSIDES_MAX, 125 | Pattern_NUMSIDES_MIN, 126 | Pattern_NUMSIDES_MAX, 127 | Pattern_NUMSIDES_DFLT, 128 | PF_Precision_INTEGER, 129 | 0, 130 | 0, 131 | NUMSIDES_ID); 132 | 133 | AEFX_CLR_STRUCT(def); 134 | 135 | // Choose angle: 136 | PF_ADD_FLOAT_SLIDERX(STR(StrID_Angle_Param_Name), 137 | Pattern_ANGLE_MIN, 138 | Pattern_ANGLE_MAX, 139 | Pattern_ANGLE_MIN, 140 | Pattern_ANGLE_MAX, 141 | Pattern_ANGLE_DFLT, 142 | PF_Precision_THOUSANDTHS, 143 | 0, 144 | 0, 145 | ANGLE_ID); 146 | 147 | AEFX_CLR_STRUCT(def); 148 | 149 | // Choose delta mode: 150 | PF_ADD_POPUPX(STR(StrID_ChooseDelta_Param_Name), 151 | DELTA_SIZE, DELTA_TOWARDS, 152 | STR(StrID_DeltaChoices_Param_Name), 153 | 0, 154 | CHOOSEDELTA_ID); 155 | 156 | // Choose delta value: 157 | PF_ADD_FLOAT_SLIDERX(STR(StrID_Delta_Param_Name), 158 | Pattern_DELTA_MIN, 159 | Pattern_DELTA_MAX, 160 | Pattern_DELTA_MIN, 161 | Pattern_DELTA_MAX, 162 | Pattern_DELTA_DFLT, 163 | PF_Precision_THOUSANDTHS, 164 | 0, 165 | 0, 166 | DELTA_ID); 167 | 168 | 169 | AEFX_CLR_STRUCT(def); 170 | 171 | // Hide Tiling: 172 | PF_ADD_CHECKBOXX(STR(StrID_HideTiling_Param_Name), 173 | true, 0, HIDETILINGCHKBOX_ID); 174 | 175 | AEFX_CLR_STRUCT(def); 176 | 177 | // Choose Line Stroke Color: 178 | PF_ADD_COLOR(STR(StrID_LineColor_Param_Name), color_combo[0].red, 179 | color_combo[0].green, color_combo[0].blue, LINECOLOR_ID); 180 | 181 | AEFX_CLR_STRUCT(def); 182 | 183 | // Choose Line Stroke Width: 184 | PF_ADD_FLOAT_SLIDERX(STR(StrID_LineWidth_Param_Name), 185 | Pattern_STROKE_MIN, 186 | Pattern_STROKE_MAX, 187 | Pattern_STROKE_MIN, 188 | Pattern_STROKE_MAX, 189 | Pattern_STROKE_DFLT, 190 | PF_Precision_HUNDREDTHS, 191 | 0, 192 | 0, 193 | LINEWIDTH_ID); 194 | 195 | 196 | out_data->num_params = Pattern_NUM_PARAMS; 197 | 198 | return err; 199 | } 200 | 201 | static PF_Err 202 | MakeParamCopy( 203 | PF_ParamDef* actual[], /* >> */ 204 | PF_ParamDef copy[]) /* << */ 205 | { 206 | for (A_short iS = 0; iS < Pattern_NUM_PARAMS; ++iS) { 207 | AEFX_CLR_STRUCT(copy[iS]); // clean params are important! 208 | } 209 | 210 | copy[Pattern_INPUT] = *actual[Pattern_INPUT]; 211 | copy[Pattern_BGCOLOR] = *actual[Pattern_BGCOLOR]; 212 | copy[Pattern_CHOOSEMODE] = *actual[Pattern_CHOOSEMODE]; 213 | copy[Pattern_CHOOSETILING] = *actual[Pattern_CHOOSETILING]; 214 | copy[Pattern_SIDELENGTH] = *actual[Pattern_SIDELENGTH]; 215 | copy[Pattern_NUMSIDES] = *actual[Pattern_NUMSIDES]; 216 | copy[Pattern_ANGLE] = *actual[Pattern_ANGLE]; 217 | copy[Pattern_CHOOSEDELTA] = *actual[Pattern_CHOOSEDELTA]; 218 | copy[Pattern_DELTA] = *actual[Pattern_DELTA]; 219 | copy[Pattern_HIDETILINGCHKBOX] = *actual[Pattern_HIDETILINGCHKBOX]; 220 | copy[Pattern_PATTERNCOLOR] = *actual[Pattern_PATTERNCOLOR]; 221 | copy[Pattern_PATTERNWIDTH] = *actual[Pattern_PATTERNWIDTH]; 222 | 223 | return PF_Err_NONE; 224 | 225 | } 226 | 227 | static PF_Err 228 | UpdateParameterUI( 229 | PF_InData* in_data, 230 | PF_OutData* out_data, 231 | PF_ParamDef* params[], 232 | PF_LayerDef* output) 233 | { PF_Err err = PF_Err_NONE; 234 | AEGP_StreamRefH SideLength_streamH = NULL, numSides_streamH = NULL, 235 | Tiling_streamH = NULL; 236 | AEGP_SuiteHandler suites(in_data->pica_basicP); 237 | AEGP_EffectRefH meH = NULL; 238 | 239 | // Copying parameters before changing their state: 240 | PF_ParamDef param_copy[Pattern_NUM_PARAMS]; 241 | ERR(MakeParamCopy(params, param_copy)); 242 | 243 | 244 | if (params[Pattern_CHOOSEMODE]->u.pd.value == MODE_CENTERED) { 245 | 246 | ERR(suites.PFInterfaceSuite1()->AEGP_GetNewEffectForEffect(NULL, 247 | in_data->effect_ref, &meH)); 248 | 249 | // Unhide number of sides: 250 | ERR(suites.StreamSuite2()->AEGP_GetNewEffectStreamByIndex(NULL, meH, 251 | Pattern_NUMSIDES, &numSides_streamH)); 252 | ERR(suites.DynamicStreamSuite2()->AEGP_SetDynamicStreamFlag(numSides_streamH, 253 | AEGP_DynStreamFlag_HIDDEN, FALSE, FALSE)); 254 | 255 | // Hide tiling choices: 256 | ERR(suites.StreamSuite2()->AEGP_GetNewEffectStreamByIndex(NULL, meH, 257 | Pattern_CHOOSETILING, &Tiling_streamH)); 258 | ERR(suites.DynamicStreamSuite2()->AEGP_SetDynamicStreamFlag(Tiling_streamH, 259 | AEGP_DynStreamFlag_HIDDEN, FALSE, TRUE)); 260 | } 261 | 262 | if (params[Pattern_CHOOSEMODE]->u.pd.value == MODE_MULTIPLE) { 263 | 264 | ERR(suites.PFInterfaceSuite1()->AEGP_GetNewEffectForEffect(NULL, 265 | in_data->effect_ref, &meH)); 266 | 267 | // Hide number of sides: 268 | ERR(suites.StreamSuite2()->AEGP_GetNewEffectStreamByIndex(NULL, meH, 269 | Pattern_NUMSIDES, &numSides_streamH)); 270 | ERR(suites.DynamicStreamSuite2()->AEGP_SetDynamicStreamFlag(numSides_streamH, 271 | AEGP_DynStreamFlag_HIDDEN, FALSE, TRUE)); 272 | // Unhide tiling choices: 273 | ERR(suites.StreamSuite2()->AEGP_GetNewEffectStreamByIndex(NULL, meH, 274 | Pattern_CHOOSETILING, &Tiling_streamH)); 275 | ERR(suites.DynamicStreamSuite2()->AEGP_SetDynamicStreamFlag(Tiling_streamH, 276 | AEGP_DynStreamFlag_HIDDEN, FALSE, FALSE)); 277 | 278 | } 279 | 280 | return err; 281 | } 282 | 283 | 284 | // The functions below translate cairo graphics to AE renderable form: 285 | 286 | PF_Pixel* sampleIntegral8(PF_EffectWorld& def, int x, int y) 287 | { 288 | return (PF_Pixel*)((char*)def.data + (y * def.rowbytes) 289 | + (x * sizeof(PF_Pixel))); 290 | } 291 | 292 | PF_Err cairoCopy8(void* refcon, A_long threadInd, A_long itemNum, 293 | A_long iterTotal) 294 | { 295 | cairoRefcon* data = (cairoRefcon*)refcon; 296 | int i = itemNum; 297 | PF_Err err = PF_Err_NONE; 298 | uint32_t* rowP; 299 | PF_Pixel8* worldPtr = sampleIntegral8(data->output, 0, i); 300 | rowP = (uint32_t*)(data->data + i * data->stride); 301 | for (int x = 0; x < data->output.width; x++) { 302 | worldPtr->alpha = rowP[x] >> 24; 303 | if (worldPtr->alpha) 304 | { 305 | worldPtr->red = rowP[x] >> 16; 306 | worldPtr->green = rowP[x] >> 8; 307 | worldPtr->blue = rowP[x] >> 0; 308 | } 309 | worldPtr++; 310 | } 311 | 312 | return err; 313 | } 314 | 315 | 316 | static PF_Err 317 | Render ( 318 | PF_InData *in_data, 319 | PF_OutData *out_data, 320 | PF_ParamDef *params[], 321 | PF_LayerDef *output ) 322 | { 323 | PF_Err err = PF_Err_NONE; 324 | AEGP_SuiteHandler suites(in_data->pica_basicP); 325 | PF_FILL(NULL, NULL, output); 326 | 327 | cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 328 | output->width, output->height); 329 | cairo_t* cr = cairo_create(surface); 330 | 331 | draw ob(cr, output, params); 332 | ob.pattern(); 333 | 334 | cairoRefcon crefcon; 335 | AEFX_CLR_STRUCT(crefcon); 336 | crefcon.data = cairo_image_surface_get_data(surface); 337 | crefcon.stride = cairo_image_surface_get_stride(surface); 338 | crefcon.output = *output; 339 | ERR(suites.IterateSuite1()->AEGP_IterateGeneric(output->height, 340 | &crefcon, cairoCopy8)); 341 | return err; 342 | } 343 | 344 | 345 | extern "C" DllExport 346 | PF_Err PluginDataEntryFunction( 347 | PF_PluginDataPtr inPtr, 348 | PF_PluginDataCB inPluginDataCallBackPtr, 349 | SPBasicSuite* inSPBasicSuitePtr, 350 | const char* inHostName, 351 | const char* inHostVersion) 352 | { 353 | PF_Err result = PF_Err_INVALID_CALLBACK; 354 | 355 | result = PF_REGISTER_EFFECT( 356 | inPtr, 357 | inPluginDataCallBackPtr, 358 | "Pattern", // Name 359 | "ADBE Pattern", // Match Name 360 | "Motion Graphics Plug-ins", // Category 361 | AE_RESERVED_INFO); // Reserved Info 362 | 363 | return result; 364 | } 365 | 366 | 367 | PF_Err 368 | EffectMain( 369 | PF_Cmd cmd, 370 | PF_InData *in_data, 371 | PF_OutData *out_data, 372 | PF_ParamDef *params[], 373 | PF_LayerDef *output, 374 | void *extra) 375 | { 376 | PF_Err err = PF_Err_NONE; 377 | 378 | try { 379 | switch (cmd) { 380 | case PF_Cmd_ABOUT: 381 | 382 | err = About(in_data, 383 | out_data, 384 | params, 385 | output); 386 | break; 387 | 388 | case PF_Cmd_GLOBAL_SETUP: 389 | 390 | err = GlobalSetup( in_data, 391 | out_data, 392 | params, 393 | output); 394 | break; 395 | 396 | case PF_Cmd_PARAMS_SETUP: 397 | 398 | err = ParamsSetup( in_data, 399 | out_data, 400 | params, 401 | output); 402 | break; 403 | 404 | case PF_Cmd_RENDER: 405 | 406 | err = Render( in_data, 407 | out_data, 408 | params, 409 | output); 410 | break; 411 | 412 | case PF_Cmd_UPDATE_PARAMS_UI: 413 | err = UpdateParameterUI(in_data, 414 | out_data, 415 | params, 416 | output); 417 | break; 418 | 419 | default: 420 | break; 421 | 422 | } 423 | } 424 | catch(PF_Err &thrown_err){ 425 | err = thrown_err; 426 | } 427 | return err; 428 | } 429 | 430 | -------------------------------------------------------------------------------- /Pattern.h: -------------------------------------------------------------------------------- 1 | /*******************************************************************/ 2 | /* */ 3 | /* ADOBE CONFIDENTIAL */ 4 | /* _ _ _ _ _ _ _ _ _ _ _ _ _ */ 5 | /* */ 6 | /* Copyright 2007 Adobe Systems Incorporated */ 7 | /* All Rights Reserved. */ 8 | /* */ 9 | /* NOTICE: All information contained herein is, and remains the */ 10 | /* property of Adobe Systems Incorporated and its suppliers, if */ 11 | /* any. The intellectual and technical concepts contained */ 12 | /* herein are proprietary to Adobe Systems Incorporated and its */ 13 | /* suppliers and may be covered by U.S. and Foreign Patents, */ 14 | /* patents in process, and are protected by trade secret or */ 15 | /* copyright law. Dissemination of this information or */ 16 | /* reproduction of this material is strictly forbidden unless */ 17 | /* prior written permission is obtained from Adobe Systems */ 18 | /* Incorporated. */ 19 | /* */ 20 | /*******************************************************************/ 21 | 22 | #pragma once 23 | 24 | #ifndef Pattern_H 25 | #define Pattern_H 26 | 27 | typedef unsigned char u_char; 28 | typedef unsigned short u_short; 29 | typedef unsigned short u_int16; 30 | typedef unsigned long u_long; 31 | typedef short int int16; 32 | #define PF_TABLE_BITS 12 33 | #define PF_TABLE_SZ_16 4096 34 | 35 | #define PF_DEEP_COLOR_AWARE 1 // make sure we get 16bpc pixels; 36 | // AE_Effect.h checks for this. 37 | 38 | #include "AEConfig.h" 39 | 40 | #ifdef AE_OS_WIN 41 | typedef unsigned short PixelType; 42 | #include 43 | #endif 44 | 45 | #include "entry.h" 46 | #include "AE_Effect.h" 47 | #include "AE_EffectCB.h" 48 | #include "AE_Macros.h" 49 | #include "Param_Utils.h" 50 | #include "AE_EffectCBSuites.h" 51 | #include "String_Utils.h" 52 | #include "AE_GeneralPlug.h" 53 | #include "AEFX_ChannelDepthTpl.h" 54 | #include "AEGP_SuiteHandler.h" 55 | #define CAIRO_WIN32_STATIC_BUILD 56 | #include "cairo.h" 57 | #include "Pattern_Strings.h" 58 | 59 | /* Versioning information */ 60 | 61 | #define MAJOR_VERSION 1 62 | #define MINOR_VERSION 0 63 | #define BUG_VERSION 0 64 | #define STAGE_VERSION PF_Stage_DEVELOP 65 | #define BUILD_VERSION 1 66 | 67 | 68 | /* Parameter defaults */ 69 | 70 | #define Pattern_ANGLE_MIN 0 71 | #define Pattern_ANGLE_MAX 90 72 | #define Pattern_ANGLE_DFLT 60 73 | #define Pattern_DELTA_DFLT 0 74 | #define Pattern_DELTA_MIN 0 75 | #define Pattern_DELTA_MAX 200 76 | #define Pattern_STROKE_MIN 1 77 | #define Pattern_STROKE_MAX 10 78 | #define Pattern_STROKE_DFLT 3 79 | #define Pattern_SIDELENGTH_MIN 60 80 | #define Pattern_SIDELENGTH_MAX 235 81 | #define Pattern_SIDELENGTH_DFLT 120 82 | #define Pattern_NUMSIDES_MIN 3 83 | #define Pattern_NUMSIDES_MAX 45 84 | #define Pattern_NUMSIDES_DFLT 6 85 | 86 | enum { 87 | TILING_666 = 1, 88 | TILING_FILLER1, 89 | TILING_444, 90 | TILING_FILLER2, 91 | TILING_488, 92 | TILING_FILLER3, 93 | TILING_31212, 94 | TILING_FILLER4, 95 | TILING_4612, 96 | TILING_SIZE = TILING_4612 97 | }; 98 | 99 | enum { 100 | MODE_CENTERED = 1, 101 | MODE_FILLER1, 102 | MODE_MULTIPLE, 103 | MODE_SIZE = MODE_MULTIPLE 104 | }; 105 | 106 | enum { 107 | DELTA_TOWARDS = 1, 108 | DELTA_FILLER1, 109 | DELTA_AWAY, 110 | DELTA_SIZE = DELTA_AWAY 111 | }; 112 | 113 | enum { 114 | Pattern_INPUT = 0, 115 | Pattern_BGCOLOR, 116 | Pattern_CHOOSEMODE, 117 | Pattern_CHOOSETILING, 118 | Pattern_SIDELENGTH, 119 | Pattern_NUMSIDES, 120 | Pattern_ANGLE, 121 | Pattern_CHOOSEDELTA, 122 | Pattern_DELTA, 123 | Pattern_HIDETILINGCHKBOX, 124 | Pattern_PATTERNCOLOR, 125 | Pattern_PATTERNWIDTH, 126 | Pattern_NUM_PARAMS 127 | }; 128 | 129 | enum { 130 | BGCOLOR_ID = 1, 131 | CHOOSEMODE_ID, 132 | CHOOSETILING_ID, 133 | SIDELENGTH_ID, 134 | NUMSIDES_ID, 135 | ANGLE_ID, 136 | CHOOSEDELTA_ID, 137 | DELTA_ID, 138 | HIDETILINGCHKBOX_ID, 139 | LINECOLOR_ID, 140 | LINEWIDTH_ID, 141 | }; 142 | 143 | // Struct to store cairo data in AE renderable form: 144 | struct cairoRefcon { 145 | PF_EffectWorld output; 146 | unsigned char* data; 147 | int stride; 148 | }; 149 | 150 | 151 | 152 | extern "C" { 153 | 154 | DllExport 155 | PF_Err 156 | EffectMain( 157 | PF_Cmd cmd, 158 | PF_InData *in_data, 159 | PF_OutData *out_data, 160 | PF_ParamDef *params[], 161 | PF_LayerDef *output, 162 | void *extra); 163 | 164 | } 165 | 166 | #endif // Pattern_H -------------------------------------------------------------------------------- /Pattern_Strings.cpp: -------------------------------------------------------------------------------- 1 | /*******************************************************************/ 2 | /* */ 3 | /* ADOBE CONFIDENTIAL */ 4 | /* _ _ _ _ _ _ _ _ _ _ _ _ _ */ 5 | /* */ 6 | /* Copyright 2007 Adobe Systems Incorporated */ 7 | /* All Rights Reserved. */ 8 | /* */ 9 | /* NOTICE: All information contained herein is, and remains the */ 10 | /* property of Adobe Systems Incorporated and its suppliers, if */ 11 | /* any. The intellectual and technical concepts contained */ 12 | /* herein are proprietary to Adobe Systems Incorporated and its */ 13 | /* suppliers and may be covered by U.S. and Foreign Patents, */ 14 | /* patents in process, and are protected by trade secret or */ 15 | /* copyright law. Dissemination of this information or */ 16 | /* reproduction of this material is strictly forbidden unless */ 17 | /* prior written permission is obtained from Adobe Systems */ 18 | /* Incorporated. */ 19 | /* */ 20 | /*******************************************************************/ 21 | 22 | #include "Pattern.h" 23 | 24 | struct TableString { 25 | A_u_long index; 26 | A_char str[256]; 27 | }; 28 | 29 | 30 | 31 | TableString g_strs[StrID_NUMTYPES] = { 32 | StrID_NONE, "", 33 | StrID_Name, "Pattern", 34 | StrID_Description, "Creates Islamic Star Pattern Animations from Polygons in Contact", 35 | StrID_BgColor_Param_Name, "Background Color", 36 | StrID_ChooseMode_Param_Name, "Mode", 37 | StrID_ModeChoices_Param_Name, "Centered |" 38 | "(-|" 39 | "Multiple ", 40 | StrID_ChooseTiling_Param_Name, "Tiling", 41 | StrID_TilingChoices_Param_Name, "6.6.6 |" 42 | "(-|" 43 | "4.4.4 |" 44 | "(-|" 45 | "4.8.8 |" 46 | "(-|" 47 | "3.12.12 |" 48 | "(-|" 49 | "4.6.12 |", 50 | StrID_SideLength_Param_Name, "Side Length", 51 | StrID_NumberofSides_Param_Name, "Number of Sides", 52 | StrID_Angle_Param_Name, "Angle (Degrees)", 53 | StrID_ChooseDelta_Param_Name, "Delta Mode", 54 | StrID_DeltaChoices_Param_Name, "Towards |" 55 | "(-|" 56 | "Away ", 57 | StrID_Delta_Param_Name, "Delta", 58 | StrID_HideTiling_Param_Name, "Hide Tiling", 59 | StrID_TColorChkBox_Param_Name, "Show Tiling Background", 60 | StrID_TBgColor_Param_Name, "Tiling Background Color", 61 | StrID_LineColor_Param_Name, "Pattern Color", 62 | StrID_LineWidth_Param_Name, "Pattern Weight", 63 | }; 64 | 65 | 66 | char *GetStringPtr(int strNum) 67 | { 68 | return g_strs[strNum].str; 69 | } 70 | -------------------------------------------------------------------------------- /Pattern_Strings.h: -------------------------------------------------------------------------------- 1 | /*******************************************************************/ 2 | /* */ 3 | /* ADOBE CONFIDENTIAL */ 4 | /* _ _ _ _ _ _ _ _ _ _ _ _ _ */ 5 | /* */ 6 | /* Copyright 2007 Adobe Systems Incorporated */ 7 | /* All Rights Reserved. */ 8 | /* */ 9 | /* NOTICE: All information contained herein is, and remains the */ 10 | /* property of Adobe Systems Incorporated and its suppliers, if */ 11 | /* any. The intellectual and technical concepts contained */ 12 | /* herein are proprietary to Adobe Systems Incorporated and its */ 13 | /* suppliers and may be covered by U.S. and Foreign Patents, */ 14 | /* patents in process, and are protected by trade secret or */ 15 | /* copyright law. Dissemination of this information or */ 16 | /* reproduction of this material is strictly forbidden unless */ 17 | /* prior written permission is obtained from Adobe Systems */ 18 | /* Incorporated. */ 19 | /* */ 20 | /*******************************************************************/ 21 | 22 | #pragma once 23 | 24 | typedef enum { 25 | StrID_NONE, 26 | StrID_Name, 27 | StrID_Description, 28 | StrID_BgColor_Param_Name, 29 | StrID_ChooseMode_Param_Name, 30 | StrID_ModeChoices_Param_Name, 31 | StrID_ChooseTiling_Param_Name, 32 | StrID_TilingChoices_Param_Name, 33 | StrID_SideLength_Param_Name, 34 | StrID_NumberofSides_Param_Name, 35 | StrID_Angle_Param_Name, 36 | StrID_ChooseDelta_Param_Name, 37 | StrID_DeltaChoices_Param_Name, 38 | StrID_Delta_Param_Name, 39 | StrID_HideTiling_Param_Name, 40 | StrID_TColorChkBox_Param_Name, 41 | StrID_TBgColor_Param_Name, 42 | StrID_LineColor_Param_Name, 43 | StrID_LineWidth_Param_Name, 44 | StrID_NUMTYPES 45 | } StrIDType; 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pattern 2 | Winner of the Adobe Digital Edge Awards 2023 in Engineering, Pattern is an Adobe After Effects plugin that creates Islamic star pattern-style animations using Hankin's polygons-in-contact algorithm. Colors for animations are generated from 3 | a dataset of images (illustrated by professional artists at Kurzgesagt) through k-means clustering. This plugin's algorithm is inspired by the techniques proposed in the University of Waterloo's research paper "Islamic Star Patterns from Polygons in Contact" by Craig S. Kaplan (https://dl.acm.org/doi/pdf/10.5555/1089508.1089538). 4 | 5 | See LICENSE.md for license details. Watch Pattern in action: https://youtu.be/4MxbwQsuseU 6 | 7 | Brief explanation of how Pattern's algorithm works: https://artsengine.engin.umich.edu/science_as_art/pattern/ 8 | 9 | ![Alt Text](https://github.com/nithishakumar/Pattern-After-Effects-Plugin/blob/main/animations/animation%201.gif) 10 | 11 | ![Alt Text](https://github.com/nithishakumar/Pattern-After-Effects-Plugin/blob/main/animations/animation%208.gif) 12 | 13 | ![Alt Text](https://github.com/nithishakumar/Pattern-After-Effects-Plugin/blob/main/animations/animation%202.gif) 14 | 15 | ![Alt Text](https://github.com/nithishakumar/Pattern-After-Effects-Plugin/blob/main/animations/animation%203.gif) 16 | 17 | # Building Pattern on Windows 18 | 19 | 1. Follow this tutorial to set up the After Effects SDK files on Visual Studio: https://www.youtube.com/watch?v=gilpHirsXQA 20 | 21 | Make sure to rename everything to "Pattern". In PatterPiPL.r, change the category to "Motion Graphics Plugins" before compiling. 22 | 2. Follow this tutorial to link your project to the Cairo graphics library: https://www.youtube.com/watch?v=oAVWwBA2K0U 23 | 24 | Everything you need is in the "cairo" folder of this repository. 25 | 3. Copy the cairo.dll file from the cairo folder of this repository to the "Support files" folder of where Adobe After Effects is installed in your computer 26 | (C:\Program Files\Adobe\Adobe After Effects 2021\Support Files). 27 | 4. Install OpenCV 3.4.15 from this link: https://opencv.org/releases/. Extract it to a folder you prefer. I recommend your D drive. 28 | 29 | Refer to "option 1" in this tutorial if you need any help along the way: https://www.youtube.com/watch?v=eDGSkdeV8YI 30 | 5. Create a new project in Visual Studio, choose Static Library (.lib) in C++, and place it in the same folder as Pattern. Name it "Color". 31 | 6. Make sure to change the configuration of the static library project to x64 from x86: 32 | 33 | ![image](https://user-images.githubusercontent.com/73742037/131928290-43f029dd-4664-464e-a667-45537e956981.png) 34 | 35 | 7. Link OpenCV to your static library by adding the path to "include" and "lib" in your OpenCV folder under "Include Directories" and "Library Directories" of this project: 36 | 37 | ![image](https://user-images.githubusercontent.com/73742037/131928183-cc8f2460-4463-458e-a5b2-896720664aef.png) 38 | 39 | 8. Now add the code from Color.h and Color.cpp to the Color static library. 40 | 9. Download the Image Dataset from this link: https://www.kaggle.com/nithishakumar/pattern-plugin-image-dataset and place it in the same folder as the Pattern plugin. DO NOT RENAME ANY OF THE IMAGES! 41 | 10. Copy the path to the ImageDataset and assign this value to the path string in Color.cpp: 42 | 43 | ![image](https://user-images.githubusercontent.com/73742037/131933620-cf4940bb-1aa9-4012-a6ce-3ce73d4d92a7.png) 44 | 45 | 11. Link OpenCV to your Pattern plugin by adding the same paths to "include" and "lib" in the OpenCV folder under "Include Directories" and "Library Directories" of your Pattern project. 46 | 12. Include the path to your Color static library folder under "Include Directories" in Pattern. 47 | 13. Include the path to color static library folder << x64 << Debug under "Library Directories" in Pattern. 48 | 14. Under Linker << Input << Additional Dependencies, add Color.lib and opencv_world3415d.lib to Pattern: 49 | 50 | ![image](https://user-images.githubusercontent.com/73742037/131928785-24106084-5601-4038-884b-53f7e1b44c41.png) 51 | 52 | 15. Replace the code in Pattern.cpp and Pattern.h to the one from this repository. 53 | 16. Add Draw.h, Draw.cpp, Draw_Tiling.cpp to Pattern.sln. 54 | 17. Run Visual Studio as administrator and build the plugin by clicking on "Local Windows Debugger". You can find the plugin at Effect << Motion Graphics Plugins. 55 | -------------------------------------------------------------------------------- /animations/animation 1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/animations/animation 1.gif -------------------------------------------------------------------------------- /animations/animation 2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/animations/animation 2.gif -------------------------------------------------------------------------------- /animations/animation 3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/animations/animation 3.gif -------------------------------------------------------------------------------- /animations/animation 4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/animations/animation 4.gif -------------------------------------------------------------------------------- /animations/animation 5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/animations/animation 5.gif -------------------------------------------------------------------------------- /animations/animation 6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/animations/animation 6.gif -------------------------------------------------------------------------------- /animations/animation 7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/animations/animation 7.gif -------------------------------------------------------------------------------- /animations/animation 8.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/animations/animation 8.gif -------------------------------------------------------------------------------- /cairo/cairo.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/cairo/cairo.dll -------------------------------------------------------------------------------- /cairo/include/cairo-deprecated.h: -------------------------------------------------------------------------------- 1 | /* cairo - a vector graphics library with display and print output 2 | * 3 | * Copyright © 2006 Red Hat, Inc. 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it either under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation 8 | * (the "LGPL") or, at your option, under the terms of the Mozilla 9 | * Public License Version 1.1 (the "MPL"). If you do not alter this 10 | * notice, a recipient may use your version of this file under either 11 | * the MPL or the LGPL. 12 | * 13 | * You should have received a copy of the LGPL along with this library 14 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 16 | * You should have received a copy of the MPL along with this library 17 | * in the file COPYING-MPL-1.1 18 | * 19 | * The contents of this file are subject to the Mozilla Public License 20 | * Version 1.1 (the "License"); you may not use this file except in 21 | * compliance with the License. You may obtain a copy of the License at 22 | * http://www.mozilla.org/MPL/ 23 | * 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 25 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 26 | * the specific language governing rights and limitations. 27 | * 28 | * The Original Code is the cairo graphics library. 29 | * 30 | * The Initial Developer of the Original Code is Red Hat, Inc. 31 | * 32 | * Contributor(s): 33 | * Carl D. Worth 34 | */ 35 | 36 | #ifndef CAIRO_DEPRECATED_H 37 | #define CAIRO_DEPRECATED_H 38 | 39 | #define CAIRO_FONT_TYPE_ATSUI CAIRO_FONT_TYPE_QUARTZ 40 | 41 | /* Obsolete functions. These definitions exist to coerce the compiler 42 | * into providing a little bit of guidance with its error 43 | * messages. The idea is to help users port their old code without 44 | * having to dig through lots of documentation. 45 | * 46 | * The first set of REPLACED_BY functions is for functions whose names 47 | * have just been changed. So fixing these up is mechanical, (and 48 | * automated by means of the cairo/util/cairo-api-update script. 49 | * 50 | * The second set of DEPRECATED_BY functions is for functions where 51 | * the replacement is used in a different way, (ie. different 52 | * arguments, multiple functions instead of one, etc). Fixing these up 53 | * will require a bit more work on the user's part, (and hopefully we 54 | * can get cairo-api-update to find these and print some guiding 55 | * information). 56 | */ 57 | #define cairo_current_font_extents cairo_current_font_extents_REPLACED_BY_cairo_font_extents 58 | #define cairo_get_font_extents cairo_get_font_extents_REPLACED_BY_cairo_font_extents 59 | #define cairo_current_operator cairo_current_operator_REPLACED_BY_cairo_get_operator 60 | #define cairo_current_tolerance cairo_current_tolerance_REPLACED_BY_cairo_get_tolerance 61 | #define cairo_current_point cairo_current_point_REPLACED_BY_cairo_get_current_point 62 | #define cairo_current_fill_rule cairo_current_fill_rule_REPLACED_BY_cairo_get_fill_rule 63 | #define cairo_current_line_width cairo_current_line_width_REPLACED_BY_cairo_get_line_width 64 | #define cairo_current_line_cap cairo_current_line_cap_REPLACED_BY_cairo_get_line_cap 65 | #define cairo_current_line_join cairo_current_line_join_REPLACED_BY_cairo_get_line_join 66 | #define cairo_current_miter_limit cairo_current_miter_limit_REPLACED_BY_cairo_get_miter_limit 67 | #define cairo_current_matrix cairo_current_matrix_REPLACED_BY_cairo_get_matrix 68 | #define cairo_current_target_surface cairo_current_target_surface_REPLACED_BY_cairo_get_target 69 | #define cairo_get_status cairo_get_status_REPLACED_BY_cairo_status 70 | #define cairo_concat_matrix cairo_concat_matrix_REPLACED_BY_cairo_transform 71 | #define cairo_scale_font cairo_scale_font_REPLACED_BY_cairo_set_font_size 72 | #define cairo_select_font cairo_select_font_REPLACED_BY_cairo_select_font_face 73 | #define cairo_transform_font cairo_transform_font_REPLACED_BY_cairo_set_font_matrix 74 | #define cairo_transform_point cairo_transform_point_REPLACED_BY_cairo_user_to_device 75 | #define cairo_transform_distance cairo_transform_distance_REPLACED_BY_cairo_user_to_device_distance 76 | #define cairo_inverse_transform_point cairo_inverse_transform_point_REPLACED_BY_cairo_device_to_user 77 | #define cairo_inverse_transform_distance cairo_inverse_transform_distance_REPLACED_BY_cairo_device_to_user_distance 78 | #define cairo_init_clip cairo_init_clip_REPLACED_BY_cairo_reset_clip 79 | #define cairo_surface_create_for_image cairo_surface_create_for_image_REPLACED_BY_cairo_image_surface_create_for_data 80 | #define cairo_default_matrix cairo_default_matrix_REPLACED_BY_cairo_identity_matrix 81 | #define cairo_matrix_set_affine cairo_matrix_set_affine_REPLACED_BY_cairo_matrix_init 82 | #define cairo_matrix_set_identity cairo_matrix_set_identity_REPLACED_BY_cairo_matrix_init_identity 83 | #define cairo_pattern_add_color_stop cairo_pattern_add_color_stop_REPLACED_BY_cairo_pattern_add_color_stop_rgba 84 | #define cairo_set_rgb_color cairo_set_rgb_color_REPLACED_BY_cairo_set_source_rgb 85 | #define cairo_set_pattern cairo_set_pattern_REPLACED_BY_cairo_set_source 86 | #define cairo_xlib_surface_create_for_pixmap_with_visual cairo_xlib_surface_create_for_pixmap_with_visual_REPLACED_BY_cairo_xlib_surface_create 87 | #define cairo_xlib_surface_create_for_window_with_visual cairo_xlib_surface_create_for_window_with_visual_REPLACED_BY_cairo_xlib_surface_create 88 | #define cairo_xcb_surface_create_for_pixmap_with_visual cairo_xcb_surface_create_for_pixmap_with_visual_REPLACED_BY_cairo_xcb_surface_create 89 | #define cairo_xcb_surface_create_for_window_with_visual cairo_xcb_surface_create_for_window_with_visual_REPLACED_BY_cairo_xcb_surface_create 90 | #define cairo_ps_surface_set_dpi cairo_ps_surface_set_dpi_REPLACED_BY_cairo_surface_set_fallback_resolution 91 | #define cairo_pdf_surface_set_dpi cairo_pdf_surface_set_dpi_REPLACED_BY_cairo_surface_set_fallback_resolution 92 | #define cairo_svg_surface_set_dpi cairo_svg_surface_set_dpi_REPLACED_BY_cairo_surface_set_fallback_resolution 93 | #define cairo_atsui_font_face_create_for_atsu_font_id cairo_atsui_font_face_create_for_atsu_font_id_REPLACED_BY_cairo_quartz_font_face_create_for_atsu_font_id 94 | 95 | #define cairo_current_path cairo_current_path_DEPRECATED_BY_cairo_copy_path 96 | #define cairo_current_path_flat cairo_current_path_flat_DEPRECATED_BY_cairo_copy_path_flat 97 | #define cairo_get_path cairo_get_path_DEPRECATED_BY_cairo_copy_path 98 | #define cairo_get_path_flat cairo_get_path_flat_DEPRECATED_BY_cairo_get_path_flat 99 | #define cairo_set_alpha cairo_set_alpha_DEPRECATED_BY_cairo_set_source_rgba_OR_cairo_paint_with_alpha 100 | #define cairo_show_surface cairo_show_surface_DEPRECATED_BY_cairo_set_source_surface_AND_cairo_paint 101 | #define cairo_copy cairo_copy_DEPRECATED_BY_cairo_create_AND_MANY_INDIVIDUAL_FUNCTIONS 102 | #define cairo_surface_set_repeat cairo_surface_set_repeat_DEPRECATED_BY_cairo_pattern_set_extend 103 | #define cairo_surface_set_matrix cairo_surface_set_matrix_DEPRECATED_BY_cairo_pattern_set_matrix 104 | #define cairo_surface_get_matrix cairo_surface_get_matrix_DEPRECATED_BY_cairo_pattern_get_matrix 105 | #define cairo_surface_set_filter cairo_surface_set_filter_DEPRECATED_BY_cairo_pattern_set_filter 106 | #define cairo_surface_get_filter cairo_surface_get_filter_DEPRECATED_BY_cairo_pattern_get_filter 107 | #define cairo_matrix_create cairo_matrix_create_DEPRECATED_BY_cairo_matrix_t 108 | #define cairo_matrix_destroy cairo_matrix_destroy_DEPRECATED_BY_cairo_matrix_t 109 | #define cairo_matrix_copy cairo_matrix_copy_DEPRECATED_BY_cairo_matrix_t 110 | #define cairo_matrix_get_affine cairo_matrix_get_affine_DEPRECATED_BY_cairo_matrix_t 111 | #define cairo_set_target_surface cairo_set_target_surface_DEPRECATED_BY_cairo_create 112 | #define cairo_set_target_image cairo_set_target_image_DEPRECATED_BY_cairo_image_surface_create_for_data 113 | #define cairo_set_target_pdf cairo_set_target_pdf_DEPRECATED_BY_cairo_pdf_surface_create 114 | #define cairo_set_target_png cairo_set_target_png_DEPRECATED_BY_cairo_surface_write_to_png 115 | #define cairo_set_target_ps cairo_set_target_ps_DEPRECATED_BY_cairo_ps_surface_create 116 | #define cairo_set_target_quartz cairo_set_target_quartz_DEPRECATED_BY_cairo_quartz_surface_create 117 | #define cairo_set_target_win32 cairo_set_target_win32_DEPRECATED_BY_cairo_win32_surface_create 118 | #define cairo_set_target_xcb cairo_set_target_xcb_DEPRECATED_BY_cairo_xcb_surface_create 119 | #define cairo_set_target_drawable cairo_set_target_drawable_DEPRECATED_BY_cairo_xlib_surface_create 120 | #define cairo_get_status_string cairo_get_status_string_DEPRECATED_BY_cairo_status_AND_cairo_status_to_string 121 | #define cairo_status_string cairo_status_string_DEPRECATED_BY_cairo_status_AND_cairo_status_to_string 122 | 123 | #endif /* CAIRO_DEPRECATED_H */ 124 | -------------------------------------------------------------------------------- /cairo/include/cairo-features.h: -------------------------------------------------------------------------------- 1 | /* Generated by Makefile.win32.features-h. Do not edit. */ 2 | #ifndef CAIRO_FEATURES_H 3 | #define CAIRO_FEATURES_H 1 4 | #define CAIRO_HAS_WIN32_SURFACE 1 5 | #define CAIRO_HAS_WIN32_FONT 1 6 | #define CAIRO_HAS_PNG_FUNCTIONS 1 7 | #define CAIRO_HAS_SCRIPT_SURFACE 1 8 | #define CAIRO_HAS_FT_FONT 1 9 | #define CAIRO_HAS_PS_SURFACE 1 10 | #define CAIRO_HAS_PDF_SURFACE 1 11 | #define CAIRO_HAS_SVG_SURFACE 1 12 | #define CAIRO_HAS_IMAGE_SURFACE 1 13 | #define CAIRO_HAS_MIME_SURFACE 1 14 | #define CAIRO_HAS_RECORDING_SURFACE 1 15 | #define CAIRO_HAS_OBSERVER_SURFACE 1 16 | #define CAIRO_HAS_TEE_SURFACE 1 17 | #define CAIRO_HAS_USER_FONT 1 18 | #define CAIRO_HAS_INTERPRETER 1 19 | #endif 20 | -------------------------------------------------------------------------------- /cairo/include/cairo-ft.h: -------------------------------------------------------------------------------- 1 | /* cairo - a vector graphics library with display and print output 2 | * 3 | * Copyright © 2005 Red Hat, Inc 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it either under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation 8 | * (the "LGPL") or, at your option, under the terms of the Mozilla 9 | * Public License Version 1.1 (the "MPL"). If you do not alter this 10 | * notice, a recipient may use your version of this file under either 11 | * the MPL or the LGPL. 12 | * 13 | * You should have received a copy of the LGPL along with this library 14 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 16 | * You should have received a copy of the MPL along with this library 17 | * in the file COPYING-MPL-1.1 18 | * 19 | * The contents of this file are subject to the Mozilla Public License 20 | * Version 1.1 (the "License"); you may not use this file except in 21 | * compliance with the License. You may obtain a copy of the License at 22 | * http://www.mozilla.org/MPL/ 23 | * 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 25 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 26 | * the specific language governing rights and limitations. 27 | * 28 | * The Original Code is the cairo graphics library. 29 | * 30 | * The Initial Developer of the Original Code is Red Hat, Inc. 31 | * 32 | * Contributor(s): 33 | * Graydon Hoare 34 | * Owen Taylor 35 | */ 36 | 37 | #ifndef CAIRO_FT_H 38 | #define CAIRO_FT_H 39 | 40 | #include "cairo.h" 41 | 42 | #if CAIRO_HAS_FT_FONT 43 | 44 | /* Fontconfig/Freetype platform-specific font interface */ 45 | 46 | #include 47 | #include FT_FREETYPE_H 48 | 49 | #if CAIRO_HAS_FC_FONT 50 | #include 51 | #endif 52 | 53 | CAIRO_BEGIN_DECLS 54 | 55 | cairo_public cairo_font_face_t * 56 | cairo_ft_font_face_create_for_ft_face (FT_Face face, 57 | int load_flags); 58 | 59 | /** 60 | * cairo_ft_synthesize_t: 61 | * @CAIRO_FT_SYNTHESIZE_BOLD: Embolden the glyphs (redraw with a pixel offset) 62 | * @CAIRO_FT_SYNTHESIZE_OBLIQUE: Slant the glyph outline by 12 degrees to the 63 | * right. 64 | * 65 | * A set of synthesis options to control how FreeType renders the glyphs 66 | * for a particular font face. 67 | * 68 | * Individual synthesis features of a #cairo_ft_font_face_t can be set 69 | * using cairo_ft_font_face_set_synthesize(), or disabled using 70 | * cairo_ft_font_face_unset_synthesize(). The currently enabled set of 71 | * synthesis options can be queried with cairo_ft_font_face_get_synthesize(). 72 | * 73 | * Note: that when synthesizing glyphs, the font metrics returned will only 74 | * be estimates. 75 | * 76 | * Since: 1.12 77 | **/ 78 | typedef enum { 79 | CAIRO_FT_SYNTHESIZE_BOLD = 1 << 0, 80 | CAIRO_FT_SYNTHESIZE_OBLIQUE = 1 << 1 81 | } cairo_ft_synthesize_t; 82 | 83 | cairo_public void 84 | cairo_ft_font_face_set_synthesize (cairo_font_face_t *font_face, 85 | unsigned int synth_flags); 86 | 87 | cairo_public void 88 | cairo_ft_font_face_unset_synthesize (cairo_font_face_t *font_face, 89 | unsigned int synth_flags); 90 | 91 | cairo_public unsigned int 92 | cairo_ft_font_face_get_synthesize (cairo_font_face_t *font_face); 93 | 94 | 95 | cairo_public FT_Face 96 | cairo_ft_scaled_font_lock_face (cairo_scaled_font_t *scaled_font); 97 | 98 | cairo_public void 99 | cairo_ft_scaled_font_unlock_face (cairo_scaled_font_t *scaled_font); 100 | 101 | #if CAIRO_HAS_FC_FONT 102 | 103 | cairo_public cairo_font_face_t * 104 | cairo_ft_font_face_create_for_pattern (FcPattern *pattern); 105 | 106 | cairo_public void 107 | cairo_ft_font_options_substitute (const cairo_font_options_t *options, 108 | FcPattern *pattern); 109 | 110 | #endif 111 | 112 | CAIRO_END_DECLS 113 | 114 | #else /* CAIRO_HAS_FT_FONT */ 115 | # error Cairo was not compiled with support for the freetype font backend 116 | #endif /* CAIRO_HAS_FT_FONT */ 117 | 118 | #endif /* CAIRO_FT_H */ 119 | -------------------------------------------------------------------------------- /cairo/include/cairo-gobject.h: -------------------------------------------------------------------------------- 1 | /* cairo - a vector graphics library with display and print output 2 | * 3 | * Copyright © 2010 Red Hat Inc. 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it either under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation 8 | * (the "LGPL") or, at your option, under the terms of the Mozilla 9 | * Public License Version 1.1 (the "MPL"). If you do not alter this 10 | * notice, a recipient may use your version of this file under either 11 | * the MPL or the LGPL. 12 | * 13 | * You should have received a copy of the LGPL along with this library 14 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 16 | * You should have received a copy of the MPL along with this library 17 | * in the file COPYING-MPL-1.1 18 | * 19 | * The contents of this file are subject to the Mozilla Public License 20 | * Version 1.1 (the "License"); you may not use this file except in 21 | * compliance with the License. You may obtain a copy of the License at 22 | * http://www.mozilla.org/MPL/ 23 | * 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 25 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 26 | * the specific language governing rights and limitations. 27 | * 28 | * The Original Code is the cairo graphics library. 29 | * 30 | * The Initial Developer of the Original Code is University of Southern 31 | * California. 32 | * 33 | * Contributor(s): 34 | * Benjamin Otte 35 | */ 36 | 37 | #ifndef CAIRO_GOBJECT_H 38 | #define CAIRO_GOBJECT_H 39 | 40 | #include 41 | 42 | #if CAIRO_HAS_GOBJECT_FUNCTIONS 43 | 44 | #include 45 | 46 | CAIRO_BEGIN_DECLS 47 | 48 | /* structs */ 49 | 50 | #define CAIRO_GOBJECT_TYPE_CONTEXT cairo_gobject_context_get_type () 51 | cairo_public GType 52 | cairo_gobject_context_get_type (void); 53 | 54 | #define CAIRO_GOBJECT_TYPE_DEVICE cairo_gobject_device_get_type () 55 | cairo_public GType 56 | cairo_gobject_device_get_type (void); 57 | 58 | #define CAIRO_GOBJECT_TYPE_PATTERN cairo_gobject_pattern_get_type () 59 | cairo_public GType 60 | cairo_gobject_pattern_get_type (void); 61 | 62 | #define CAIRO_GOBJECT_TYPE_SURFACE cairo_gobject_surface_get_type () 63 | cairo_public GType 64 | cairo_gobject_surface_get_type (void); 65 | 66 | #define CAIRO_GOBJECT_TYPE_RECTANGLE cairo_gobject_rectangle_get_type () 67 | cairo_public GType 68 | cairo_gobject_rectangle_get_type (void); 69 | 70 | #define CAIRO_GOBJECT_TYPE_SCALED_FONT cairo_gobject_scaled_font_get_type () 71 | cairo_public GType 72 | cairo_gobject_scaled_font_get_type (void); 73 | 74 | #define CAIRO_GOBJECT_TYPE_FONT_FACE cairo_gobject_font_face_get_type () 75 | cairo_public GType 76 | cairo_gobject_font_face_get_type (void); 77 | 78 | #define CAIRO_GOBJECT_TYPE_FONT_OPTIONS cairo_gobject_font_options_get_type () 79 | cairo_public GType 80 | cairo_gobject_font_options_get_type (void); 81 | 82 | #define CAIRO_GOBJECT_TYPE_RECTANGLE_INT cairo_gobject_rectangle_int_get_type () 83 | cairo_public GType 84 | cairo_gobject_rectangle_int_get_type (void); 85 | 86 | #define CAIRO_GOBJECT_TYPE_REGION cairo_gobject_region_get_type () 87 | cairo_public GType 88 | cairo_gobject_region_get_type (void); 89 | 90 | /* enums */ 91 | 92 | #define CAIRO_GOBJECT_TYPE_STATUS cairo_gobject_status_get_type () 93 | cairo_public GType 94 | cairo_gobject_status_get_type (void); 95 | 96 | #define CAIRO_GOBJECT_TYPE_CONTENT cairo_gobject_content_get_type () 97 | cairo_public GType 98 | cairo_gobject_content_get_type (void); 99 | 100 | #define CAIRO_GOBJECT_TYPE_OPERATOR cairo_gobject_operator_get_type () 101 | cairo_public GType 102 | cairo_gobject_operator_get_type (void); 103 | 104 | #define CAIRO_GOBJECT_TYPE_ANTIALIAS cairo_gobject_antialias_get_type () 105 | cairo_public GType 106 | cairo_gobject_antialias_get_type (void); 107 | 108 | #define CAIRO_GOBJECT_TYPE_FILL_RULE cairo_gobject_fill_rule_get_type () 109 | cairo_public GType 110 | cairo_gobject_fill_rule_get_type (void); 111 | 112 | #define CAIRO_GOBJECT_TYPE_LINE_CAP cairo_gobject_line_cap_get_type () 113 | cairo_public GType 114 | cairo_gobject_line_cap_get_type (void); 115 | 116 | #define CAIRO_GOBJECT_TYPE_LINE_JOIN cairo_gobject_line_join_get_type () 117 | cairo_public GType 118 | cairo_gobject_line_join_get_type (void); 119 | 120 | #define CAIRO_GOBJECT_TYPE_CLUSTER_FLAGS cairo_gobject_cluster_flags_get_type () 121 | cairo_public GType 122 | cairo_gobject_text_cluster_flags_get_type (void); 123 | 124 | #define CAIRO_GOBJECT_TYPE_FONT_SLANT cairo_gobject_font_slant_get_type () 125 | cairo_public GType 126 | cairo_gobject_font_slant_get_type (void); 127 | 128 | #define CAIRO_GOBJECT_TYPE_FONT_WEIGHT cairo_gobject_font_weight_get_type () 129 | cairo_public GType 130 | cairo_gobject_font_weight_get_type (void); 131 | 132 | #define CAIRO_GOBJECT_TYPE_SUBPIXEL_ORDER cairo_gobject_subpixel_order_get_type () 133 | cairo_public GType 134 | cairo_gobject_subpixel_order_get_type (void); 135 | 136 | #define CAIRO_GOBJECT_TYPE_HINT_STYLE cairo_gobject_hint_style_get_type () 137 | cairo_public GType 138 | cairo_gobject_hint_style_get_type (void); 139 | 140 | #define CAIRO_GOBJECT_TYPE_HNT_METRICS cairo_gobject_hint_metrics_get_type () 141 | cairo_public GType 142 | cairo_gobject_hint_metrics_get_type (void); 143 | 144 | #define CAIRO_GOBJECT_TYPE_FONT_TYPE cairo_gobject_font_type_get_type () 145 | cairo_public GType 146 | cairo_gobject_font_type_get_type (void); 147 | 148 | #define CAIRO_GOBJECT_TYPE_PATH_DATA_TYPE cairo_gobject_path_data_type_get_type () 149 | cairo_public GType 150 | cairo_gobject_path_data_type_get_type (void); 151 | 152 | #define CAIRO_GOBJECT_TYPE_DEVICE_TYPE cairo_gobject_device_type_get_type () 153 | cairo_public GType 154 | cairo_gobject_device_type_get_type (void); 155 | 156 | #define CAIRO_GOBJECT_TYPE_SURFACE_TYPE cairo_gobject_surface_type_get_type () 157 | cairo_public GType 158 | cairo_gobject_surface_type_get_type (void); 159 | 160 | #define CAIRO_GOBJECT_TYPE_FORMAT cairo_gobject_format_get_type () 161 | cairo_public GType 162 | cairo_gobject_format_get_type (void); 163 | 164 | #define CAIRO_GOBJECT_TYPE_PATTERN_TYPE cairo_gobject_pattern_type_get_type () 165 | cairo_public GType 166 | cairo_gobject_pattern_type_get_type (void); 167 | 168 | #define CAIRO_GOBJECT_TYPE_EXTEND cairo_gobject_extend_get_type () 169 | cairo_public GType 170 | cairo_gobject_extend_get_type (void); 171 | 172 | #define CAIRO_GOBJECT_TYPE_FILTER cairo_gobject_filter_get_type () 173 | cairo_public GType 174 | cairo_gobject_filter_get_type (void); 175 | 176 | #define CAIRO_GOBJECT_TYPE_REGION_OVERLAP cairo_gobject_region_overlap_get_type () 177 | cairo_public GType 178 | cairo_gobject_region_overlap_get_type (void); 179 | 180 | CAIRO_END_DECLS 181 | 182 | #else /* CAIRO_HAS_GOBJECT_FUNCTIONS */ 183 | # error Cairo was not compiled with support for GObject 184 | #endif /* CAIRO_HAS_GOBJECT_FUNCTIONS */ 185 | 186 | #endif /* CAIRO_GOBJECT_H */ 187 | -------------------------------------------------------------------------------- /cairo/include/cairo-pdf.h: -------------------------------------------------------------------------------- 1 | /* cairo - a vector graphics library with display and print output 2 | * 3 | * Copyright © 2002 University of Southern California 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it either under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation 8 | * (the "LGPL") or, at your option, under the terms of the Mozilla 9 | * Public License Version 1.1 (the "MPL"). If you do not alter this 10 | * notice, a recipient may use your version of this file under either 11 | * the MPL or the LGPL. 12 | * 13 | * You should have received a copy of the LGPL along with this library 14 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 16 | * You should have received a copy of the MPL along with this library 17 | * in the file COPYING-MPL-1.1 18 | * 19 | * The contents of this file are subject to the Mozilla Public License 20 | * Version 1.1 (the "License"); you may not use this file except in 21 | * compliance with the License. You may obtain a copy of the License at 22 | * http://www.mozilla.org/MPL/ 23 | * 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 25 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 26 | * the specific language governing rights and limitations. 27 | * 28 | * The Original Code is the cairo graphics library. 29 | * 30 | * The Initial Developer of the Original Code is University of Southern 31 | * California. 32 | * 33 | * Contributor(s): 34 | * Carl D. Worth 35 | */ 36 | 37 | #ifndef CAIRO_PDF_H 38 | #define CAIRO_PDF_H 39 | 40 | #include "cairo.h" 41 | 42 | #if CAIRO_HAS_PDF_SURFACE 43 | 44 | CAIRO_BEGIN_DECLS 45 | 46 | /** 47 | * cairo_pdf_version_t: 48 | * @CAIRO_PDF_VERSION_1_4: The version 1.4 of the PDF specification. (Since 1.10) 49 | * @CAIRO_PDF_VERSION_1_5: The version 1.5 of the PDF specification. (Since 1.10) 50 | * 51 | * #cairo_pdf_version_t is used to describe the version number of the PDF 52 | * specification that a generated PDF file will conform to. 53 | * 54 | * Since: 1.10 55 | **/ 56 | typedef enum _cairo_pdf_version { 57 | CAIRO_PDF_VERSION_1_4, 58 | CAIRO_PDF_VERSION_1_5 59 | } cairo_pdf_version_t; 60 | 61 | cairo_public cairo_surface_t * 62 | cairo_pdf_surface_create (const char *filename, 63 | double width_in_points, 64 | double height_in_points); 65 | 66 | cairo_public cairo_surface_t * 67 | cairo_pdf_surface_create_for_stream (cairo_write_func_t write_func, 68 | void *closure, 69 | double width_in_points, 70 | double height_in_points); 71 | 72 | cairo_public void 73 | cairo_pdf_surface_restrict_to_version (cairo_surface_t *surface, 74 | cairo_pdf_version_t version); 75 | 76 | cairo_public void 77 | cairo_pdf_get_versions (cairo_pdf_version_t const **versions, 78 | int *num_versions); 79 | 80 | cairo_public const char * 81 | cairo_pdf_version_to_string (cairo_pdf_version_t version); 82 | 83 | cairo_public void 84 | cairo_pdf_surface_set_size (cairo_surface_t *surface, 85 | double width_in_points, 86 | double height_in_points); 87 | 88 | /** 89 | * cairo_pdf_outline_flags_t: 90 | * @CAIRO_PDF_OUTLINE_FLAG_OPEN: The outline item defaults to open in the PDF viewer (Since 1.16) 91 | * @CAIRO_PDF_OUTLINE_FLAG_BOLD: The outline item is displayed by the viewer in bold text (Since 1.16) 92 | * @CAIRO_PDF_OUTLINE_FLAG_ITALIC: The outline item is displayed by the viewer in italic text (Since 1.16) 93 | * 94 | * #cairo_pdf_outline_flags_t is used by the 95 | * cairo_pdf_surface_add_outline() function specify the attributes of 96 | * an outline item. These flags may be bitwise-or'd to produce any 97 | * combination of flags. 98 | * 99 | * Since: 1.16 100 | **/ 101 | typedef enum _cairo_pdf_outline_flags { 102 | CAIRO_PDF_OUTLINE_FLAG_OPEN = 0x1, 103 | CAIRO_PDF_OUTLINE_FLAG_BOLD = 0x2, 104 | CAIRO_PDF_OUTLINE_FLAG_ITALIC = 0x4, 105 | } cairo_pdf_outline_flags_t; 106 | 107 | #define CAIRO_PDF_OUTLINE_ROOT 0 108 | 109 | cairo_public int 110 | cairo_pdf_surface_add_outline (cairo_surface_t *surface, 111 | int parent_id, 112 | const char *utf8, 113 | const char *link_attribs, 114 | cairo_pdf_outline_flags_t flags); 115 | 116 | /** 117 | * cairo_pdf_metadata_t: 118 | * @CAIRO_PDF_METADATA_TITLE: The document title (Since 1.16) 119 | * @CAIRO_PDF_METADATA_AUTHOR: The document author (Since 1.16) 120 | * @CAIRO_PDF_METADATA_SUBJECT: The document subject (Since 1.16) 121 | * @CAIRO_PDF_METADATA_KEYWORDS: The document keywords (Since 1.16) 122 | * @CAIRO_PDF_METADATA_CREATOR: The document creator (Since 1.16) 123 | * @CAIRO_PDF_METADATA_CREATE_DATE: The document creation date (Since 1.16) 124 | * @CAIRO_PDF_METADATA_MOD_DATE: The document modification date (Since 1.16) 125 | * 126 | * #cairo_pdf_metadata_t is used by the 127 | * cairo_pdf_surface_set_metadata() function specify the metadata to set. 128 | * 129 | * Since: 1.16 130 | **/ 131 | typedef enum _cairo_pdf_metadata { 132 | CAIRO_PDF_METADATA_TITLE, 133 | CAIRO_PDF_METADATA_AUTHOR, 134 | CAIRO_PDF_METADATA_SUBJECT, 135 | CAIRO_PDF_METADATA_KEYWORDS, 136 | CAIRO_PDF_METADATA_CREATOR, 137 | CAIRO_PDF_METADATA_CREATE_DATE, 138 | CAIRO_PDF_METADATA_MOD_DATE, 139 | } cairo_pdf_metadata_t; 140 | 141 | cairo_public void 142 | cairo_pdf_surface_set_metadata (cairo_surface_t *surface, 143 | cairo_pdf_metadata_t metadata, 144 | const char *utf8); 145 | 146 | cairo_public void 147 | cairo_pdf_surface_set_page_label (cairo_surface_t *surface, 148 | const char *utf8); 149 | 150 | cairo_public void 151 | cairo_pdf_surface_set_thumbnail_size (cairo_surface_t *surface, 152 | int width, 153 | int height); 154 | 155 | CAIRO_END_DECLS 156 | 157 | #else /* CAIRO_HAS_PDF_SURFACE */ 158 | # error Cairo was not compiled with support for the pdf backend 159 | #endif /* CAIRO_HAS_PDF_SURFACE */ 160 | 161 | #endif /* CAIRO_PDF_H */ 162 | -------------------------------------------------------------------------------- /cairo/include/cairo-ps.h: -------------------------------------------------------------------------------- 1 | /* cairo - a vector graphics library with display and print output 2 | * 3 | * Copyright © 2002 University of Southern California 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it either under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation 8 | * (the "LGPL") or, at your option, under the terms of the Mozilla 9 | * Public License Version 1.1 (the "MPL"). If you do not alter this 10 | * notice, a recipient may use your version of this file under either 11 | * the MPL or the LGPL. 12 | * 13 | * You should have received a copy of the LGPL along with this library 14 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 16 | * You should have received a copy of the MPL along with this library 17 | * in the file COPYING-MPL-1.1 18 | * 19 | * The contents of this file are subject to the Mozilla Public License 20 | * Version 1.1 (the "License"); you may not use this file except in 21 | * compliance with the License. You may obtain a copy of the License at 22 | * http://www.mozilla.org/MPL/ 23 | * 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 25 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 26 | * the specific language governing rights and limitations. 27 | * 28 | * The Original Code is the cairo graphics library. 29 | * 30 | * The Initial Developer of the Original Code is University of Southern 31 | * California. 32 | * 33 | * Contributor(s): 34 | * Carl D. Worth 35 | */ 36 | 37 | #ifndef CAIRO_PS_H 38 | #define CAIRO_PS_H 39 | 40 | #include "cairo.h" 41 | 42 | #if CAIRO_HAS_PS_SURFACE 43 | 44 | #include 45 | 46 | CAIRO_BEGIN_DECLS 47 | 48 | /* PS-surface functions */ 49 | 50 | /** 51 | * cairo_ps_level_t: 52 | * @CAIRO_PS_LEVEL_2: The language level 2 of the PostScript specification. (Since 1.6) 53 | * @CAIRO_PS_LEVEL_3: The language level 3 of the PostScript specification. (Since 1.6) 54 | * 55 | * #cairo_ps_level_t is used to describe the language level of the 56 | * PostScript Language Reference that a generated PostScript file will 57 | * conform to. 58 | * 59 | * Since: 1.6 60 | **/ 61 | typedef enum _cairo_ps_level { 62 | CAIRO_PS_LEVEL_2, 63 | CAIRO_PS_LEVEL_3 64 | } cairo_ps_level_t; 65 | 66 | cairo_public cairo_surface_t * 67 | cairo_ps_surface_create (const char *filename, 68 | double width_in_points, 69 | double height_in_points); 70 | 71 | cairo_public cairo_surface_t * 72 | cairo_ps_surface_create_for_stream (cairo_write_func_t write_func, 73 | void *closure, 74 | double width_in_points, 75 | double height_in_points); 76 | 77 | cairo_public void 78 | cairo_ps_surface_restrict_to_level (cairo_surface_t *surface, 79 | cairo_ps_level_t level); 80 | 81 | cairo_public void 82 | cairo_ps_get_levels (cairo_ps_level_t const **levels, 83 | int *num_levels); 84 | 85 | cairo_public const char * 86 | cairo_ps_level_to_string (cairo_ps_level_t level); 87 | 88 | cairo_public void 89 | cairo_ps_surface_set_eps (cairo_surface_t *surface, 90 | cairo_bool_t eps); 91 | 92 | cairo_public cairo_bool_t 93 | cairo_ps_surface_get_eps (cairo_surface_t *surface); 94 | 95 | cairo_public void 96 | cairo_ps_surface_set_size (cairo_surface_t *surface, 97 | double width_in_points, 98 | double height_in_points); 99 | 100 | cairo_public void 101 | cairo_ps_surface_dsc_comment (cairo_surface_t *surface, 102 | const char *comment); 103 | 104 | cairo_public void 105 | cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface); 106 | 107 | cairo_public void 108 | cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface); 109 | 110 | CAIRO_END_DECLS 111 | 112 | #else /* CAIRO_HAS_PS_SURFACE */ 113 | # error Cairo was not compiled with support for the ps backend 114 | #endif /* CAIRO_HAS_PS_SURFACE */ 115 | 116 | #endif /* CAIRO_PS_H */ 117 | -------------------------------------------------------------------------------- /cairo/include/cairo-script-interpreter.h: -------------------------------------------------------------------------------- 1 | /* cairo - a vector graphics library with display and print output 2 | * 3 | * Copyright © 2008 Chris Wilson 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it either under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation 8 | * (the "LGPL") or, at your option, under the terms of the Mozilla 9 | * Public License Version 1.1 (the "MPL"). If you do not alter this 10 | * notice, a recipient may use your version of this file under either 11 | * the MPL or the LGPL. 12 | * 13 | * You should have received a copy of the LGPL along with this library 14 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 16 | * You should have received a copy of the MPL along with this library 17 | * in the file COPYING-MPL-1.1 18 | * 19 | * The contents of this file are subject to the Mozilla Public License 20 | * Version 1.1 (the "License"); you may not use this file except in 21 | * compliance with the License. You may obtain a copy of the License at 22 | * http://www.mozilla.org/MPL/ 23 | * 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 25 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 26 | * the specific language governing rights and limitations. 27 | * 28 | * The Original Code is the cairo graphics library. 29 | * 30 | * The Initial Developer of the Original Code is Chris Wilson 31 | * 32 | * Contributor(s): 33 | * Chris Wilson 34 | */ 35 | 36 | #ifndef CAIRO_SCRIPT_INTERPRETER_H 37 | #define CAIRO_SCRIPT_INTERPRETER_H 38 | 39 | #include 40 | #include 41 | 42 | CAIRO_BEGIN_DECLS 43 | 44 | typedef struct _cairo_script_interpreter cairo_script_interpreter_t; 45 | 46 | /* XXX expose csi_dictionary_t and pass to hooks */ 47 | typedef void 48 | (*csi_destroy_func_t) (void *closure, 49 | void *ptr); 50 | 51 | typedef cairo_surface_t * 52 | (*csi_surface_create_func_t) (void *closure, 53 | cairo_content_t content, 54 | double width, 55 | double height, 56 | long uid); 57 | typedef cairo_t * 58 | (*csi_context_create_func_t) (void *closure, 59 | cairo_surface_t *surface); 60 | typedef void 61 | (*csi_show_page_func_t) (void *closure, 62 | cairo_t *cr); 63 | 64 | typedef void 65 | (*csi_copy_page_func_t) (void *closure, 66 | cairo_t *cr); 67 | 68 | typedef struct _cairo_script_interpreter_hooks { 69 | void *closure; 70 | csi_surface_create_func_t surface_create; 71 | csi_destroy_func_t surface_destroy; 72 | csi_context_create_func_t context_create; 73 | csi_destroy_func_t context_destroy; 74 | csi_show_page_func_t show_page; 75 | csi_copy_page_func_t copy_page; 76 | } cairo_script_interpreter_hooks_t; 77 | 78 | cairo_public cairo_script_interpreter_t * 79 | cairo_script_interpreter_create (void); 80 | 81 | cairo_public void 82 | cairo_script_interpreter_install_hooks (cairo_script_interpreter_t *ctx, 83 | const cairo_script_interpreter_hooks_t *hooks); 84 | 85 | cairo_public cairo_status_t 86 | cairo_script_interpreter_run (cairo_script_interpreter_t *ctx, 87 | const char *filename); 88 | 89 | cairo_public cairo_status_t 90 | cairo_script_interpreter_feed_stream (cairo_script_interpreter_t *ctx, 91 | FILE *stream); 92 | 93 | cairo_public cairo_status_t 94 | cairo_script_interpreter_feed_string (cairo_script_interpreter_t *ctx, 95 | const char *line, 96 | int len); 97 | 98 | cairo_public unsigned int 99 | cairo_script_interpreter_get_line_number (cairo_script_interpreter_t *ctx); 100 | 101 | cairo_public cairo_script_interpreter_t * 102 | cairo_script_interpreter_reference (cairo_script_interpreter_t *ctx); 103 | 104 | cairo_public cairo_status_t 105 | cairo_script_interpreter_finish (cairo_script_interpreter_t *ctx); 106 | 107 | cairo_public cairo_status_t 108 | cairo_script_interpreter_destroy (cairo_script_interpreter_t *ctx); 109 | 110 | cairo_public cairo_status_t 111 | cairo_script_interpreter_translate_stream (FILE *stream, 112 | cairo_write_func_t write_func, 113 | void *closure); 114 | 115 | CAIRO_END_DECLS 116 | 117 | #endif /*CAIRO_SCRIPT_INTERPRETER_H*/ 118 | -------------------------------------------------------------------------------- /cairo/include/cairo-script.h: -------------------------------------------------------------------------------- 1 | /* cairo - a vector graphics library with display and print output 2 | * 3 | * Copyright © 2008 Chris Wilson 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it either under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation 8 | * (the "LGPL") or, at your option, under the terms of the Mozilla 9 | * Public License Version 1.1 (the "MPL"). If you do not alter this 10 | * notice, a recipient may use your version of this file under either 11 | * the MPL or the LGPL. 12 | * 13 | * You should have received a copy of the LGPL along with this library 14 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 16 | * You should have received a copy of the MPL along with this library 17 | * in the file COPYING-MPL-1.1 18 | * 19 | * The contents of this file are subject to the Mozilla Public License 20 | * Version 1.1 (the "License"); you may not use this file except in 21 | * compliance with the License. You may obtain a copy of the License at 22 | * http://www.mozilla.org/MPL/ 23 | * 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 25 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 26 | * the specific language governing rights and limitations. 27 | * 28 | * The Original Code is the cairo graphics library. 29 | * 30 | * The Initial Developer of the Original Code is Chris Wilson 31 | * 32 | * Contributor(s): 33 | * Chris Wilson 34 | */ 35 | 36 | #ifndef CAIRO_SCRIPT_H 37 | #define CAIRO_SCRIPT_H 38 | 39 | #include "cairo.h" 40 | 41 | #if CAIRO_HAS_SCRIPT_SURFACE 42 | 43 | CAIRO_BEGIN_DECLS 44 | 45 | /** 46 | * cairo_script_mode_t: 47 | * @CAIRO_SCRIPT_MODE_ASCII: the output will be in readable text (default). (Since 1.12) 48 | * @CAIRO_SCRIPT_MODE_BINARY: the output will use byte codes. (Since 1.12) 49 | * 50 | * A set of script output variants. 51 | * 52 | * Since: 1.12 53 | **/ 54 | typedef enum { 55 | CAIRO_SCRIPT_MODE_ASCII, 56 | CAIRO_SCRIPT_MODE_BINARY 57 | } cairo_script_mode_t; 58 | 59 | cairo_public cairo_device_t * 60 | cairo_script_create (const char *filename); 61 | 62 | cairo_public cairo_device_t * 63 | cairo_script_create_for_stream (cairo_write_func_t write_func, 64 | void *closure); 65 | 66 | cairo_public void 67 | cairo_script_write_comment (cairo_device_t *script, 68 | const char *comment, 69 | int len); 70 | 71 | cairo_public void 72 | cairo_script_set_mode (cairo_device_t *script, 73 | cairo_script_mode_t mode); 74 | 75 | cairo_public cairo_script_mode_t 76 | cairo_script_get_mode (cairo_device_t *script); 77 | 78 | cairo_public cairo_surface_t * 79 | cairo_script_surface_create (cairo_device_t *script, 80 | cairo_content_t content, 81 | double width, 82 | double height); 83 | 84 | cairo_public cairo_surface_t * 85 | cairo_script_surface_create_for_target (cairo_device_t *script, 86 | cairo_surface_t *target); 87 | 88 | cairo_public cairo_status_t 89 | cairo_script_from_recording_surface (cairo_device_t *script, 90 | cairo_surface_t *recording_surface); 91 | 92 | CAIRO_END_DECLS 93 | 94 | #else /*CAIRO_HAS_SCRIPT_SURFACE*/ 95 | # error Cairo was not compiled with support for the CairoScript backend 96 | #endif /*CAIRO_HAS_SCRIPT_SURFACE*/ 97 | 98 | #endif /*CAIRO_SCRIPT_H*/ 99 | -------------------------------------------------------------------------------- /cairo/include/cairo-svg.h: -------------------------------------------------------------------------------- 1 | /* cairo - a vector graphics library with display and print output 2 | * 3 | * cairo-svg.h 4 | * 5 | * Copyright © 2005 Emmanuel Pacaud 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it either under the terms of the GNU Lesser General Public 9 | * License version 2.1 as published by the Free Software Foundation 10 | * (the "LGPL") or, at your option, under the terms of the Mozilla 11 | * Public License Version 1.1 (the "MPL"). If you do not alter this 12 | * notice, a recipient may use your version of this file under either 13 | * the MPL or the LGPL. 14 | * 15 | * You should have received a copy of the LGPL along with this library 16 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 18 | * You should have received a copy of the MPL along with this library 19 | * in the file COPYING-MPL-1.1 20 | * 21 | * The contents of this file are subject to the Mozilla Public License 22 | * Version 1.1 (the "License"); you may not use this file except in 23 | * compliance with the License. You may obtain a copy of the License at 24 | * http://www.mozilla.org/MPL/ 25 | * 26 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 27 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 28 | * the specific language governing rights and limitations. 29 | * 30 | */ 31 | 32 | #ifndef CAIRO_SVG_H 33 | #define CAIRO_SVG_H 34 | 35 | #include "cairo.h" 36 | 37 | #if CAIRO_HAS_SVG_SURFACE 38 | 39 | CAIRO_BEGIN_DECLS 40 | 41 | /** 42 | * cairo_svg_version_t: 43 | * @CAIRO_SVG_VERSION_1_1: The version 1.1 of the SVG specification. (Since 1.2) 44 | * @CAIRO_SVG_VERSION_1_2: The version 1.2 of the SVG specification. (Since 1.2) 45 | * 46 | * #cairo_svg_version_t is used to describe the version number of the SVG 47 | * specification that a generated SVG file will conform to. 48 | * 49 | * Since: 1.2 50 | **/ 51 | typedef enum _cairo_svg_version { 52 | CAIRO_SVG_VERSION_1_1, 53 | CAIRO_SVG_VERSION_1_2 54 | } cairo_svg_version_t; 55 | 56 | /** 57 | * cairo_svg_unit_t: 58 | * 59 | * @CAIRO_SVG_UNIT_USER: User unit, a value in the current coordinate system. 60 | * If used in the root element for the initial coordinate systems it 61 | * corresponds to pixels. (Since 1.16) 62 | * @CAIRO_SVG_UNIT_EM: The size of the element's font. (Since 1.16) 63 | * @CAIRO_SVG_UNIT_EX: The x-height of the element’s font. (Since 1.16) 64 | * @CAIRO_SVG_UNIT_PX: Pixels (1px = 1/96th of 1in). (Since 1.16) 65 | * @CAIRO_SVG_UNIT_IN: Inches (1in = 2.54cm = 96px). (Since 1.16) 66 | * @CAIRO_SVG_UNIT_CM: Centimeters (1cm = 96px/2.54). (Since 1.16) 67 | * @CAIRO_SVG_UNIT_MM: Millimeters (1mm = 1/10th of 1cm). (Since 1.16) 68 | * @CAIRO_SVG_UNIT_PT: Points (1pt = 1/72th of 1in). (Since 1.16) 69 | * @CAIRO_SVG_UNIT_PC: Picas (1pc = 1/6th of 1in). (Since 1.16) 70 | * @CAIRO_SVG_UNIT_PERCENT: Percent, a value that is some fraction of another 71 | * reference value. (Since 1.16) 72 | * 73 | * #cairo_svg_unit_t is used to describe the units valid for coordinates and 74 | * lengths in the SVG specification. 75 | * 76 | * See also: 77 | * https://www.w3.org/TR/SVG/coords.html#Units 78 | * https://www.w3.org/TR/SVG/types.html#DataTypeLength 79 | * https://www.w3.org/TR/css-values-3/#lengths 80 | * 81 | * Since: 1.16 82 | **/ 83 | typedef enum _cairo_svg_unit { 84 | CAIRO_SVG_UNIT_USER = 0, 85 | CAIRO_SVG_UNIT_EM, 86 | CAIRO_SVG_UNIT_EX, 87 | CAIRO_SVG_UNIT_PX, 88 | CAIRO_SVG_UNIT_IN, 89 | CAIRO_SVG_UNIT_CM, 90 | CAIRO_SVG_UNIT_MM, 91 | CAIRO_SVG_UNIT_PT, 92 | CAIRO_SVG_UNIT_PC, 93 | CAIRO_SVG_UNIT_PERCENT 94 | } cairo_svg_unit_t; 95 | 96 | cairo_public cairo_surface_t * 97 | cairo_svg_surface_create (const char *filename, 98 | double width_in_points, 99 | double height_in_points); 100 | 101 | cairo_public cairo_surface_t * 102 | cairo_svg_surface_create_for_stream (cairo_write_func_t write_func, 103 | void *closure, 104 | double width_in_points, 105 | double height_in_points); 106 | 107 | cairo_public void 108 | cairo_svg_surface_restrict_to_version (cairo_surface_t *surface, 109 | cairo_svg_version_t version); 110 | 111 | cairo_public void 112 | cairo_svg_get_versions (cairo_svg_version_t const **versions, 113 | int *num_versions); 114 | 115 | cairo_public const char * 116 | cairo_svg_version_to_string (cairo_svg_version_t version); 117 | 118 | cairo_public void 119 | cairo_svg_surface_set_document_unit (cairo_surface_t *surface, 120 | cairo_svg_unit_t unit); 121 | 122 | cairo_public cairo_svg_unit_t 123 | cairo_svg_surface_get_document_unit (cairo_surface_t *surface); 124 | 125 | CAIRO_END_DECLS 126 | 127 | #else /* CAIRO_HAS_SVG_SURFACE */ 128 | # error Cairo was not compiled with support for the svg backend 129 | #endif /* CAIRO_HAS_SVG_SURFACE */ 130 | 131 | #endif /* CAIRO_SVG_H */ 132 | -------------------------------------------------------------------------------- /cairo/include/cairo-tee.h: -------------------------------------------------------------------------------- 1 | /* cairo - a vector graphics library with display and print output 2 | * 3 | * Copyright © 2009 Chris Wilson 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it either under the terms of the GNU Lesser General Public 7 | * License version 2.1 as published by the Free Software Foundation 8 | * (the "LGPL") or, at your option, under the terms of the Mozilla 9 | * Public License Version 1.1 (the "MPL"). If you do not alter this 10 | * notice, a recipient may use your version of this file under either 11 | * the MPL or the LGPL. 12 | * 13 | * You should have received a copy of the LGPL along with this library 14 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 16 | * You should have received a copy of the MPL along with this library 17 | * in the file COPYING-MPL-1.1 18 | * 19 | * The contents of this file are subject to the Mozilla Public License 20 | * Version 1.1 (the "License"); you may not use this file except in 21 | * compliance with the License. You may obtain a copy of the License at 22 | * http://www.mozilla.org/MPL/ 23 | * 24 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 25 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 26 | * the specific language governing rights and limitations. 27 | * 28 | * The Original Code is the cairo graphics library. 29 | * 30 | * The Initial Developer of the Original Code is Chris Wilson 31 | * 32 | * Contributor(s): 33 | * Chris Wilson 34 | */ 35 | 36 | #ifndef CAIRO_TEE_H 37 | #define CAIRO_TEE_H 38 | 39 | #include "cairo.h" 40 | 41 | #if CAIRO_HAS_TEE_SURFACE 42 | 43 | CAIRO_BEGIN_DECLS 44 | 45 | cairo_public cairo_surface_t * 46 | cairo_tee_surface_create (cairo_surface_t *master); 47 | 48 | cairo_public void 49 | cairo_tee_surface_add (cairo_surface_t *surface, 50 | cairo_surface_t *target); 51 | 52 | cairo_public void 53 | cairo_tee_surface_remove (cairo_surface_t *surface, 54 | cairo_surface_t *target); 55 | 56 | cairo_public cairo_surface_t * 57 | cairo_tee_surface_index (cairo_surface_t *surface, 58 | unsigned int index); 59 | 60 | CAIRO_END_DECLS 61 | 62 | #else /*CAIRO_HAS_TEE_SURFACE*/ 63 | # error Cairo was not compiled with support for the TEE backend 64 | #endif /*CAIRO_HAS_TEE_SURFACE*/ 65 | 66 | #endif /*CAIRO_TEE_H*/ 67 | -------------------------------------------------------------------------------- /cairo/include/cairo-version.h: -------------------------------------------------------------------------------- 1 | #ifndef CAIRO_VERSION_H 2 | #define CAIRO_VERSION_H 3 | 4 | #define CAIRO_VERSION_MAJOR 1 5 | #define CAIRO_VERSION_MINOR 17 6 | #define CAIRO_VERSION_MICRO 2 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /cairo/include/cairo-win32.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */ 2 | /* cairo - a vector graphics library with display and print output 3 | * 4 | * Copyright © 2005 Red Hat, Inc 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it either under the terms of the GNU Lesser General Public 8 | * License version 2.1 as published by the Free Software Foundation 9 | * (the "LGPL") or, at your option, under the terms of the Mozilla 10 | * Public License Version 1.1 (the "MPL"). If you do not alter this 11 | * notice, a recipient may use your version of this file under either 12 | * the MPL or the LGPL. 13 | * 14 | * You should have received a copy of the LGPL along with this library 15 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA 17 | * You should have received a copy of the MPL along with this library 18 | * in the file COPYING-MPL-1.1 19 | * 20 | * The contents of this file are subject to the Mozilla Public License 21 | * Version 1.1 (the "License"); you may not use this file except in 22 | * compliance with the License. You may obtain a copy of the License at 23 | * http://www.mozilla.org/MPL/ 24 | * 25 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY 26 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for 27 | * the specific language governing rights and limitations. 28 | * 29 | * The Original Code is the cairo graphics library. 30 | * 31 | * The Initial Developer of the Original Code is Red Hat, Inc. 32 | * 33 | * Contributor(s): 34 | * Owen Taylor 35 | */ 36 | 37 | #ifndef _CAIRO_WIN32_H_ 38 | #define _CAIRO_WIN32_H_ 39 | 40 | #include "cairo.h" 41 | 42 | #if CAIRO_HAS_WIN32_SURFACE 43 | 44 | #include 45 | 46 | CAIRO_BEGIN_DECLS 47 | 48 | cairo_public cairo_surface_t * 49 | cairo_win32_surface_create (HDC hdc); 50 | 51 | cairo_public cairo_surface_t * 52 | cairo_win32_surface_create_with_format (HDC hdc, 53 | cairo_format_t format); 54 | 55 | cairo_public cairo_surface_t * 56 | cairo_win32_printing_surface_create (HDC hdc); 57 | 58 | cairo_public cairo_surface_t * 59 | cairo_win32_surface_create_with_ddb (HDC hdc, 60 | cairo_format_t format, 61 | int width, 62 | int height); 63 | 64 | cairo_public cairo_surface_t * 65 | cairo_win32_surface_create_with_dib (cairo_format_t format, 66 | int width, 67 | int height); 68 | 69 | cairo_public HDC 70 | cairo_win32_surface_get_dc (cairo_surface_t *surface); 71 | 72 | cairo_public cairo_surface_t * 73 | cairo_win32_surface_get_image (cairo_surface_t *surface); 74 | 75 | #if CAIRO_HAS_WIN32_FONT 76 | 77 | /* 78 | * Win32 font support 79 | */ 80 | 81 | cairo_public cairo_font_face_t * 82 | cairo_win32_font_face_create_for_logfontw (LOGFONTW *logfont); 83 | 84 | cairo_public cairo_font_face_t * 85 | cairo_win32_font_face_create_for_hfont (HFONT font); 86 | 87 | cairo_public cairo_font_face_t * 88 | cairo_win32_font_face_create_for_logfontw_hfont (LOGFONTW *logfont, HFONT font); 89 | 90 | cairo_public cairo_status_t 91 | cairo_win32_scaled_font_select_font (cairo_scaled_font_t *scaled_font, 92 | HDC hdc); 93 | 94 | cairo_public void 95 | cairo_win32_scaled_font_done_font (cairo_scaled_font_t *scaled_font); 96 | 97 | cairo_public double 98 | cairo_win32_scaled_font_get_metrics_factor (cairo_scaled_font_t *scaled_font); 99 | 100 | cairo_public void 101 | cairo_win32_scaled_font_get_logical_to_device (cairo_scaled_font_t *scaled_font, 102 | cairo_matrix_t *logical_to_device); 103 | 104 | cairo_public void 105 | cairo_win32_scaled_font_get_device_to_logical (cairo_scaled_font_t *scaled_font, 106 | cairo_matrix_t *device_to_logical); 107 | 108 | #endif /* CAIRO_HAS_WIN32_FONT */ 109 | 110 | CAIRO_END_DECLS 111 | 112 | #else /* CAIRO_HAS_WIN32_SURFACE */ 113 | # error Cairo was not compiled with support for the win32 backend 114 | #endif /* CAIRO_HAS_WIN32_SURFACE */ 115 | 116 | #endif /* _CAIRO_WIN32_H_ */ 117 | -------------------------------------------------------------------------------- /cairo/lib/cairo.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/cairo/lib/cairo.lib -------------------------------------------------------------------------------- /cairo/lib/pixman-1.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nithishakumar/Pattern-After-Effects-Plugin/6ba34fcb7d536c19a1021c498368c25acc5dc7ff/cairo/lib/pixman-1.lib -------------------------------------------------------------------------------- /cairo/lib/temp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /color-static-lib/Color.cpp: -------------------------------------------------------------------------------- 1 | // (c) 2021 Nithisha Nantha Kumar 2 | // This code is licensed under MIT license (see LICENSE.md for details) 3 | 4 | #include "pch.h" 5 | #include "framework.h" 6 | #include "Color.h" 7 | 8 | 9 | bool color::isPresent(pixel& ob) { 10 | for (int i = int(palette.size()) - 1; i >= 0; i--) { 11 | if (palette[i].red == ob.red && 12 | palette[i].green == ob.green && 13 | palette[i].blue == ob.blue) { 14 | return true; 15 | } 16 | } 17 | 18 | return false; 19 | } 20 | 21 | double color::calculate_brightness(pixel& ob) { 22 | return (ob.red * 299 + ob.green * 587 + ob.blue * 114) / 1000.0; 23 | } 24 | double color::calculate_brightness_difference(pixel& ob1, pixel& ob2) { 25 | return fabs(calculate_brightness(ob1) - calculate_brightness(ob2)); 26 | } 27 | 28 | double color::calculate_color_difference(pixel& ob1, pixel& ob2) { 29 | return (max(ob1.red, ob2.red) - min(ob1.red, ob2.red)) + 30 | (max(ob1.green, ob2.green) - min(ob1.green, ob2.green)) + 31 | (max(ob1.blue, ob2.blue) - min(ob1.blue, ob2.blue)); 32 | } 33 | 34 | bool color::areColorsVisible(pixel& ob1, pixel& ob2) { 35 | return (calculate_brightness_difference(ob1, ob2) > COLOR_BRIGHTNESS_RANGE 36 | && calculate_color_difference(ob1, ob2) > COLOR_DIFFERENCE_RANGE); 37 | } 38 | 39 | void color::open_image() { 40 | srand((unsigned)time(0)); 41 | string backslash = "\\"; 42 | int randomNumber = (rand() % IMAGE_DATASET_SIZE) + 1; 43 | string path = "C:" + backslash + "Users" + backslash + "nithi" + 44 | backslash + "Desktop" + backslash + "AfterEffectsSDK" + 45 | backslash + "Examples" + backslash + "Template" + backslash + 46 | "Pattern Plugin" + backslash + "ImageDataset" + backslash + 47 | "frame (" + to_string(randomNumber) + ").jpg"; 48 | source_img = imread(path); 49 | } 50 | 51 | void color::reduce_color() { 52 | // Serialize the image 53 | cv::Mat data = source_img.reshape(1, source_img.total()); 54 | data.convertTo(data, CV_32F); 55 | 56 | // Perform k-means clustering 57 | labels.clear(); 58 | cv::Mat3f centers; 59 | cv::kmeans(data, K, labels, cv::TermCriteria(), 60 | 1, cv::KMEANS_PP_CENTERS, centers); 61 | 62 | // Reduce the colors of the image 63 | for (int i = 0; i < (int)labels.size(); ++i) { 64 | data.at(i, 0) = centers.at(labels[i], 0); 65 | data.at(i, 1) = centers.at(labels[i], 1); 66 | data.at(i, 2) = centers.at(labels[i], 2); 67 | } 68 | 69 | // De-serialize the image 70 | cv::Mat destination = data.reshape(3, source_img.rows); 71 | destination.convertTo(source_img, CV_8UC3); 72 | } 73 | 74 | void color::get_palette() { 75 | palette.clear(); 76 | for (size_t i = 0; i < source_img.rows; i++) { 77 | for (size_t j = 0; j < source_img.cols; j++) { 78 | Vec3b color = source_img.at(i, j); 79 | pixel obj; 80 | obj.red = int(color[2]); 81 | obj.green = int(color[1]); 82 | obj.blue = int(color[0]); 83 | if (!isPresent(obj)) { 84 | palette.push_back(obj); 85 | } 86 | } 87 | } 88 | 89 | } 90 | 91 | vector color::get_color_combo() { 92 | 93 | // Store indices of each color in the palette 94 | indices.clear(); 95 | for (int i = 0; i < int(palette.size()); i++) { 96 | indices.push_back(i); 97 | } 98 | 99 | srand((unsigned)time(0)); 100 | random_shuffle(palette.begin(), palette.end()); 101 | random_shuffle(indices.begin(), indices.end()); 102 | 103 | pixel color1, color2; 104 | bool indicator = false; 105 | 106 | while (!indicator) { 107 | 108 | // Choose a random color in the palette 109 | int randomNumber = (rand() % (int(palette.size()) - 1)); 110 | randomNumber = indices[randomNumber]; 111 | random_shuffle(palette.begin(), palette.end()); 112 | 113 | for (int i = 0; i < int(palette.size()); i++) { 114 | // Find another color compatible with the given color from the palette 115 | if (i != randomNumber && 116 | areColorsVisible(palette[i], palette[randomNumber])) { 117 | color1 = palette[i]; 118 | color2 = palette[randomNumber]; 119 | indicator = true; 120 | break; 121 | } 122 | 123 | } 124 | } 125 | 126 | // Sorting colors in ascending order of their brightness 127 | if (calculate_brightness(color1) > calculate_brightness(color2)) { 128 | return { color1, color2 }; 129 | } 130 | 131 | return { color2, color1 }; 132 | } 133 | 134 | vector color::generate_color_combo() { 135 | open_image(); 136 | reduce_color(); 137 | get_palette(); 138 | return get_color_combo(); 139 | } -------------------------------------------------------------------------------- /color-static-lib/Color.h: -------------------------------------------------------------------------------- 1 | // (c) 2021 Nithisha Nantha Kumar 2 | // This code is licensed under MIT license (see LICENSE.md for details) 3 | 4 | #pragma once 5 | 6 | #ifndef Color_H 7 | #define Color_H 8 | 9 | #include "opencv2/opencv.hpp" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | using namespace cv; 18 | 19 | #define COLOR_BRIGHTNESS_RANGE 110 20 | #define COLOR_DIFFERENCE_RANGE 220 21 | #define IMAGE_DATASET_SIZE 1195 22 | #define K 10 23 | 24 | struct pixel { 25 | int red; 26 | int green; 27 | int blue; 28 | }; 29 | 30 | class color { 31 | 32 | private: 33 | 34 | Mat source_img; // Source Image Pixel Matrix 35 | vector palette; // Color palette of the source image 36 | vector indices; // Indices of each pixel in the color palette 37 | vector labels; // Labels for performing k-means 38 | 39 | //EFFECTS: returns true if the pixel is present in the palette & 40 | // false otherwise 41 | bool isPresent(pixel& ob); 42 | 43 | //EFFECTS: calculates & returns the brightness of the pixel's color 44 | double calculate_brightness(pixel& ob); 45 | 46 | //EFFECTS: calculates & returns the brightness difference of 47 | // the 2 pixels' colors 48 | double calculate_brightness_difference(pixel& ob1, pixel& ob2); 49 | 50 | //EFFECTS: calculates & returns the color difference of 51 | // the 2 pixels' colors 52 | double calculate_color_difference(pixel& ob1, pixel& ob2); 53 | 54 | //EFFECTS: returns true if an object of ob1's color is visible when 55 | // placed over an object of ob2's color or vice versa. 56 | // (Color Visiblity Algorithm: https://www.w3.org/TR/AERT/#color-contrast) 57 | bool areColorsVisible(pixel& ob1, pixel& ob2); 58 | 59 | //MODIFIES: source_img 60 | //EFFECTS: opens a random image from the dataset 61 | void open_image(); 62 | 63 | //MODIFIES: labels, source_img 64 | //EFFECTS: performs k-means clustering to reduce the color of the image 65 | // Refer to: https://t.ly/Xti4 66 | void reduce_color(); 67 | 68 | //MODIFIES: palette 69 | //EFFECTS: stores the colors of the image in palette 70 | void get_palette(); 71 | 72 | //MODIFIES: indices 73 | //EFFECTS: returns a random visible color combination from the palette 74 | vector get_color_combo(); 75 | 76 | public: 77 | 78 | //MODIFIES: source_img, palette, indices, labels 79 | //EFFECTS: returns visible color combination 80 | vector generate_color_combo(); 81 | 82 | }; 83 | #endif // Color_H -------------------------------------------------------------------------------- /color-static-lib/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | -------------------------------------------------------------------------------- /color-static-lib/pch.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "pch.h" 3 | 4 | // When using pre-compiled headers, this source file is necessary for compilation to succeed. 5 | -------------------------------------------------------------------------------- /color-static-lib/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: This is a precompiled header file. 2 | // Files listed below are compiled only once, improving build performance for future builds. 3 | // This also affects IntelliSense performance, including code completion and many code browsing features. 4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds. 5 | // Do not add files here that you will be updating frequently as this negates the performance advantage. 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // add headers that you want to pre-compile here 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | --------------------------------------------------------------------------------