Skip to content

Commit d1f74a3

Browse files
authored
Fix the issue that the default scale modes set by PAGExporter is not applied. (#2684)
1 parent 594fec6 commit d1f74a3

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

include/pag/pag.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ class PAG_API PAGImageLayer : public PAGLayer {
808808
Frame getFrameFromTimeRemap(Frame value);
809809
void measureBounds(tgfx::Rect* bounds) override;
810810
int64_t contentDurationInternal();
811+
int getDefaultScaleMode();
811812

812813
friend class RenderCache;
813814

src/rendering/editing/ImageReplacement.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
#include "rendering/graphics/Recorder.h"
2323

2424
namespace pag {
25-
ImageReplacement::ImageReplacement(ImageLayer* imageLayer, std::shared_ptr<PAGImage> pagImage)
26-
: pagImage(std::move(pagImage)) {
27-
auto imageFillRule = imageLayer->imageFillRule;
28-
defaultScaleMode = imageFillRule ? imageFillRule->scaleMode : PAGScaleMode::LetterBox;
29-
contentWidth = imageLayer->imageBytes->width;
30-
contentHeight = imageLayer->imageBytes->height;
25+
ImageReplacement::ImageReplacement(std::shared_ptr<PAGImage> pagImage, int scaleMode,
26+
ImageBytes* imageBytes)
27+
: pagImage(std::move(pagImage)), defaultScaleMode(scaleMode), contentWidth(imageBytes->width),
28+
contentHeight(imageBytes->height) {
3129
}
3230

3331
void ImageReplacement::measureBounds(tgfx::Rect* bounds) {

src/rendering/editing/ImageReplacement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace pag {
2323
class ImageReplacement : public Content {
2424
public:
25-
ImageReplacement(ImageLayer* imageLayer, std::shared_ptr<PAGImage> pagImage);
25+
ImageReplacement(std::shared_ptr<PAGImage> pagImage, int scaleMode, ImageBytes* imageBytes);
2626

2727
void measureBounds(tgfx::Rect* bounds) override;
2828
void draw(Recorder* recorder) override;

src/rendering/layers/PAGImageLayer.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ void PAGImageLayer::setImageInternal(std::shared_ptr<PAGImage> image) {
202202
}
203203
delete replacement;
204204
if (image != nullptr) {
205-
replacement = new ImageReplacement(static_cast<ImageLayer*>(layer), image);
205+
replacement = new ImageReplacement(image, getDefaultScaleMode(),
206+
static_cast<ImageLayer*>(layer)->imageBytes);
206207
} else {
207208
replacement = nullptr;
208209
}
@@ -676,4 +677,17 @@ int64_t PAGImageLayer::contentDurationInternal() {
676677
return FrameToTime(maxFrame + 1, frameRate);
677678
}
678679

680+
int PAGImageLayer::getDefaultScaleMode() {
681+
auto imageLayer = static_cast<ImageLayer*>(layer);
682+
if (imageLayer && imageLayer->imageFillRule) {
683+
return imageLayer->imageFillRule->scaleMode;
684+
}
685+
int index = editableIndex();
686+
if (index >= 0 && file && file->imageScaleModes && !file->imageScaleModes->empty()) {
687+
return file->imageScaleModes->at(index);
688+
}
689+
690+
return PAGScaleMode::LetterBox;
691+
}
692+
679693
} // namespace pag

0 commit comments

Comments
 (0)