Skip to content

Conversation

@yisibl
Copy link
Member

@yisibl yisibl commented Sep 23, 2025

No description provided.

@yisibl yisibl requested a review from Copilot September 23, 2025 09:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a padding parameter to the cropByBBox() API to specify bleed area around the bounding box. The padding value defaults to 0.0 and allows for expanding the crop area by the specified amount on all sides.

  • Added optional padding parameter to cropByBBox() method in both Rust and JavaScript APIs
  • Updated HTML demo to include a bleed size slider control
  • Modified example usage to demonstrate the new parameter

Reviewed Changes

Copilot reviewed 6 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/lib.rs Added padding parameter to crop_by_bbox methods with calculations for expanded dimensions
wasm/index.mjs Updated method signatures and formatting improvements
wasm/index.js Updated method signatures and formatting improvements
wasm/index.html Added bleed size UI control and updated function calls
example/bbox.js Updated example to use new padding parameter
CHANGELOG.md Added entry documenting the new feature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

src/lib.rs Outdated

self.tree.view_box.rect =
usvg::NonZeroRect::from_xywh(bbox.x as f32, bbox.y as f32, width, height).unwrap();
usvg::NonZeroRect::from_xywh(x, y, width, height).unwrap();
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation can produce negative coordinates for x and y when padding exceeds the bbox position, which will cause from_xywh() to panic since it requires non-negative values. Consider clamping x and y to ensure they remain >= 0.

Copilot uses AI. Check for mistakes.
src/lib.rs Outdated

self.tree.view_box.rect =
usvg::NonZeroRect::from_xywh(bbox.x as f32, bbox.y as f32, width, height).unwrap();
usvg::NonZeroRect::from_xywh(x, y, width, height).unwrap();
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation can produce negative coordinates for x and y when padding exceeds the bbox position, which will cause from_xywh() to panic since it requires non-negative values. Consider clamping x and y to ensure they remain >= 0.

Copilot uses AI. Check for mistakes.
<text x="50%" y="62%" font-size="38" fill="#FFF" dominant-baseline="middle" text-anchor="middle">高性能 SVG 渲染引擎和工具包</text>
</g>
</svg>`
svgString: `<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="800.000000" height="800.000000" viewBox="0 0 800.000000 800.000000"><g transform="translate(0.000000,800.000000) scale(0.100000,-0.100000)" fill="#000000" stroke="none"><path d="M3770 6484 c-241 -29 -397 -62 -574 -121 -732 -242 -1303 -798 -1559 -1518 -103 -290 -142 -523 -141 -850 2 -409 78 -741 254 -1100 230 -470 595 -848 1051 -1089 261 -138 500 -216 824 -271 128 -22 462 -30 615 -16 783 76 1472 494 1885 1146 75 119 194 364 239 494 171 490 189 1021 52 1522 -19 69 -46 155 -60 189 -14 35 -26 67 -26 71 0 4 -24 59 -53 121 -125 264 -280 483 -491 693 -220 219 -393 344 -661 475 -236 115 -491 196 -745 236 -101 15 -525 28 -610 18z m515 -299 c345 -49 683 -173 955 -352 717 -471 1091 -1326 955 -2183 -141 -880 -782 -1570 -1659 -1786 -184 -45 -344 -64 -536 -64 -759 2 -1443 363 -1856 981 -190 285 -316 641 -355 1004 -14 134 -6 432 15 560 109 641 449 1160 992 1511 247 159 596 286 904 328 140 19 457 20 585 1z"/><path d="M3588 5860 c-248 -52 -453 -136 -654 -268 -116 -76 -146 -131 -110 -200 8 -15 203 -215 433 -444 l419 -418 45 0 c32 0 55 7 73 21 58 45 56 28 56 656 0 556 -1 579 -20 610 -39 65 -91 74 -242 43z"/><path d="M4221 5862 c-19 -10 -43 -34 -53 -53 -17 -31 -18 -71 -18 -602 0 -604 0 -608 49 -651 12 -11 42 -21 72 -24 l51 -5 419 419 c230 230 426 433 434 451 36 75 -4 135 -147 221 -192 116 -401 198 -617 241 -127 26 -147 26 -190 3z"/><path d="M2516 5180 c-41 -13 -79 -52 -141 -145 -135 -206 -256 -526 -272 -725 -5 -72 -4 -77 21 -107 15 -18 44 -37 64 -43 40 -11 1127 -15 1181 -4 37 8 87 56 94 91 12 61 -3 79 -436 511 -232 232 -430 422 -439 422 -9 0 -22 2 -30 4 -7 2 -26 0 -42 -4z"/><path d="M5405 5176 c-45 -21 -862 -845 -870 -878 -10 -40 12 -95 48 -120 l32 -23 580 -3 c379 -2 592 1 616 7 85 25 103 89 71 247 -42 202 -123 409 -234 592 -67 111 -120 169 -167 182 -44 12 -39 12 -76 -4z"/><path d="M2164 3831 c-72 -44 -79 -91 -40 -263 48 -208 139 -428 246 -593 93 -143 142 -179 213 -156 49 17 873 845 882 887 9 44 -17 99 -57 124 -32 19 -49 20 -623 20 -563 0 -591 -1 -621 -19z"/><path d="M4592 3830 c-40 -24 -66 -81 -58 -124 9 -46 846 -881 893 -891 64 -13 105 16 183 130 125 185 219 407 270 640 33 149 25 199 -39 242 l-34 23 -591 0 c-575 0 -592 -1 -624 -20z"/><path d="M3675 3460 c-11 -4 -208 -197 -437 -427 -458 -460 -450 -449 -412 -528 35 -74 310 -229 539 -304 112 -37 311 -81 363 -81 36 0 81 28 102 63 19 31 20 54 20 612 0 558 -1 581 -20 612 -32 53 -100 77 -155 53z"/><path d="M4212 3450 c-63 -39 -62 -31 -62 -656 0 -626 -1 -615 64 -655 41 -25 76 -24 215 7 214 47 400 119 573 220 156 91 209 163 174 235 -9 19 -202 220 -430 448 -403 403 -414 413 -457 418 -33 3 -52 -1 -77 -17z"/></g></svg>`
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This extremely long SVG string (over 2000 characters) is inlined in the HTML, making it difficult to read and maintain. Consider moving this to a separate file or using a more compact SVG for the example.

Copilot uses AI. Check for mistakes.
@yisibl yisibl force-pushed the add-bleed-size branch 2 times, most recently from 8ed96bd to 2dd597a Compare September 24, 2025 08:44
@yisibl yisibl merged commit 247ea7e into main Sep 24, 2025
42 checks passed
@yisibl yisibl deleted the add-bleed-size branch September 24, 2025 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant