Skip to content

Fix the issue that the imageScaleModes is not effective with editable image#2684

Merged
domchen merged 6 commits intoTencent:mainfrom
CodeJhF:main
Feb 19, 2025
Merged

Fix the issue that the imageScaleModes is not effective with editable image#2684
domchen merged 6 commits intoTencent:mainfrom
CodeJhF:main

Conversation

@CodeJhF
Copy link
Collaborator

@CodeJhF CodeJhF commented Feb 19, 2025

Fix the issue that the imageScaleModes is not effective with editable image

Comment on lines +30 to +48
auto file = pagFile->getFile();
if (file && file->imageScaleModes && !file->imageScaleModes->empty()) {
auto editableImages = pagFile->getEditableIndices(LayerType::Image);
for (size_t i = 0; i < editableImages.size(); i++) {
bool found = false;
auto imageLayers = file->getImageAt(editableImages.at(i));
for (size_t j = 0; j < imageLayers.size(); j++) {
auto tmpImageLayer = imageLayers.at(j);
if (imageLayer == tmpImageLayer) {
defaultScaleMode = file->imageScaleModes->at(i);
found = true;
break;
}
}
if (found) {
break;
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

不用这么复杂。imageLayer本身就有editableIndex, 用来作为imageScaleModes的索引就行了。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Clipboard_Screenshot_1739933491 imageLayer的类型是pag::ImageLayer,应该没有editableIndex属性吧;类型pag::PAGLayer(pag::PAGImageLayer的父类)倒是有editableIndex属性

delete replacement;
if (image != nullptr) {
replacement = new ImageReplacement(static_cast<ImageLayer*>(layer), image);
replacement = new ImageReplacement(rootFile, static_cast<ImageLayer*>(layer), image);
Copy link
Collaborator

Choose a reason for hiding this comment

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

不用传递rootFile, imageLayer->getFile()就行。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

imageLayer好像没有getFile这个方法

@codecov-commenter
Copy link

codecov-commenter commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.25%. Comparing base (594fec6) to head (471ef87).

Files with missing lines Patch % Lines
src/rendering/layers/PAGImageLayer.cpp 70.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2684      +/-   ##
==========================================
- Coverage   77.30%   77.25%   -0.06%     
==========================================
  Files         425      425              
  Lines       22461    22467       +6     
  Branches     6356     6357       +1     
==========================================
- Hits        17364    17357       -7     
- Misses       3805     3813       +8     
- Partials     1292     1297       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +681 to +691
int defaultScaleMode = PAGScaleMode::LetterBox;
int index = editableIndex();
if (index >= 0 && file && file->imageScaleModes && !file->imageScaleModes->empty()) {
defaultScaleMode = file->imageScaleModes->at(index);
}
auto imageLayer = static_cast<ImageLayer*>(layer);
if (imageLayer && imageLayer->imageFillRule) {
defaultScaleMode = imageLayer->imageFillRule->scaleMode;
}

return defaultScaleMode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

要避免重复计算,应该是最先判断ImageFillRule上的scaleMode,如果存在就直接return。然后再判断editableIndex,return。最后return letterbox。if-return 这是推荐的代码写法。逻辑更清晰,代码执行也没有重复。

defaultScaleMode = imageFillRule ? imageFillRule->scaleMode : PAGScaleMode::LetterBox;
contentWidth = imageLayer->imageBytes->width;
contentHeight = imageLayer->imageBytes->height;
defaultScaleMode = scaleMode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

这几个参数已经不需要判断或者计算了,可以直接在构造函数初始化的地方赋值。类似pagImage(std::move(pagImage)),defaultScaleMode(scale), contentWidth...


namespace pag {
ImageReplacement::ImageReplacement(ImageLayer* imageLayer, std::shared_ptr<PAGImage> pagImage)
ImageReplacement::ImageReplacement(int scaleMode, ImageBytes* bytes,
Copy link
Collaborator

Choose a reason for hiding this comment

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

ImageBytes* bytes 改成:ImageBytes* imageBytes, 避免含义误解。另外参数列表顺序调整一下,PAGImage调整到第一个。

@domchen domchen merged commit d1f74a3 into Tencent:main Feb 19, 2025
8 checks passed
kevingpqi123 pushed a commit that referenced this pull request Feb 20, 2025
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.

3 participants