Skip to content

Commit

Permalink
Fix border padding on the right and bottom sides not being placed (fix
Browse files Browse the repository at this point in the history
…aseprite#3993)

Prior to this fix, border padding was clipped to the edge of sprites
on the right and bottom in all export sprite sheet types.

This commit includes tests for 'Export Sprite Sheet' command using
shape padding, border padding, inner padding with 'Packed' sheet type
+ 'Trim Cels' = true.

This fix complements the aseprite/laf commit named:
"Fix overlapped shape padding between frame images on Packed
sheet type"
  • Loading branch information
Gasparoken committed Aug 10, 2023
1 parent ab2d7f7 commit 85ec9e0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/app/doc_exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,11 @@ void DocExporter::trimTexture(const Samples& samples,
sample.isEmpty())
continue;

bounds |= sample.inTextureBounds();
// We add the border padding in the sample size to do an union
// between full bounds and sample's inTextureBounds (it
// shouldn't make full bounds bigger).
bounds |= gfx::Rect(
sample.inTextureBounds()).inflate(m_borderPadding);
}

if (m_textureWidth == 0) {
Expand Down
47 changes: 46 additions & 1 deletion tests/scripts/app_command.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright (C) 2019-2020 Igara Studio S.A.
-- Copyright (C) 2019-2023 Igara Studio S.A.
-- Copyright (C) 2018 David Capello
--
-- This file is released under the terms of the MIT license.
Expand Down Expand Up @@ -54,6 +54,51 @@ do -- ExportSpriteSheet
11,8,11,21,11,8,11,
11,8,11,21,11,11,8,
})

local s = Sprite{ fromFile="sprites/4f-index-4x4.aseprite" }
app.command.ExportSpriteSheet {
type=SpriteSheetType.PACKED,
textureFilename="_test_export_spritesheet2.png",
borderPadding=1,
shapePadding=1,
trim=true,
}
local i = Image{ fromFile="_test_export_spritesheet2.png" }
expect_img(i, {
0,0,0,0,0,0,0,
0,1,0,2,0,3,0,
0,1,0,2,0,3,0,
0,1,0,0,0,0,0,
0,0,0,4,4,0,0,
0,0,0,0,0,0,0,
})

app.sprite = s
app.command.ExportSpriteSheet {
type=SpriteSheetType.PACKED,
textureFilename="_test_export_spritesheet3.png",
borderPadding=2,
shapePadding=1,
innerPadding=1,
trim=true,
}
local i = Image{ fromFile="_test_export_spritesheet3.png" }
expect_img(i, {
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,
0,0,0,1, 0,0,0,2, 0,0,0,3, 0,0,0,

0,0,0,1, 0,0,0,2, 0,0,0,3, 0,0,0,
0,0,0,1, 0,0,0,0, 0,0,0,0, 0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,

0,0,0,0, 0,0,0,4, 4,0,0,0, 0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,
})
end

do -- NewLayer/RemoveLayer
Expand Down
Binary file added tests/sprites/4f-index-4x4.aseprite
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/sprites/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
merged in the same texture atlas.
* `2f-index-3x3.aseprite`: Indexed, 2 frames, 1 layer, mask color set
to index 21.
* `4f-index-4x4.aseprite`: Indexed, 4 frames, 1 layer, mask color set
to index 0.
* `file-tests-props.aseprite`: Indexed, 64x64, 6 frames, 4 layers (one
of them is a tilemap), 13 cels, 1 tag.
* `slices.aseprite`: Indexed, 4x4, background layer, 2 slices.
Expand Down

0 comments on commit 85ec9e0

Please sign in to comment.