https://bugs.documentfoundation.org/show_bug.cgi?id=167922
Bug ID: 167922
Summary: Compress Graphics dialog reports negative “%
reduction” when size increases
Product: LibreOffice
Version: unspecified
Hardware: All
OS: All
Status: UNCONFIRMED
Severity: minor
Priority: medium
Component: framework
Assignee: [email protected]
Reporter: [email protected]
Created attachment 202301
--> https://bugs.documentfoundation.org/attachment.cgi?id=202301&action=edit
In image that increases in size when compressed.
# Summary
Compress Graphics dialog reports negative “% reduction” when size increases.
Observed in current core; dialog code in
`svx/source/dialog/compressgraphicdialog.cxx`. Bug likely visible across
Writer/Draw/Impress since dialog is shared in svx.
# Reproduce
Steps to reproduce:
1. Drag/insert test image (poc_1.png) into Writer to compress
2. Right click image in Writer, select "Compress"
3. Pick settings that increase size
4. Click “Calculate New Size” button
5. Observe that a negative value is calculated, even though the image size is
reported as increase
# Suspected cause
In `CalculateClickHdl` the code computes a signed percentage `(orig -
new)/orig*100` but always uses the "% reduction" template string. The sign
becomes a negative “reduction” instead of switching the wording.
# Relevant code paths
I think these are the most relevant code bits for this report.
- Writer invocation: `sw/source/uibase/shells/grfsh.cxx` case
`SID_COMPRESS_GRAPHIC`
- Dialog logic: `svx/source/dialog/compressgraphicdialog.cxx` with
`CalculateClickHdl` size strings
- Strings: `include/svx/strings.hrc`
# Proposed fix
There are a number of way to fix this issue, but I will leave it up to the devs
to choose appropriate path forward. However, here is one possible way to
implement it:
- Select template by sign based on calculated size i.e., increase vs reduction
template.
- Display abs(pct), round sensibly, and include appropriate string template.
Which would mean the fix would look something like:
```cpp
// svx/source/dialog/compressgraphicdialog.cxx
// inside CalculateClickHdl,
...
const sal_Int64 orig = m_aNativeSize;
const sal_Int64 now = aSize;
OUString label;
if (orig > 0) {
const double pctSigned = (static_cast<double>(now) -
static_cast<double>(orig))
* 100.0 / static_cast<double>(orig);
const sal_Int32 pctAbs =
static_cast<sal_Int32>(std::lround(std::fabs(pctSigned)));
const bool increased = pctSigned > 0.0;
OUString tmpl = SvxResId(increased
? STR_IMAGE_CAPACITY_WITH_INCREASE
: STR_IMAGE_CAPACITY_WITH_REDUCTION);
label = tmpl.replaceAll("$(CAPACITY)", OUString::number(now / 1024))
.replaceAll("$(PERCENT)", OUString::number(pctAbs));
} else {
label = SvxResId(STR_IMAGE_CAPACITY)
.replaceAll("$(CAPACITY)", OUString::number(now / 1024));
}
m_xFixedText6->set_label(label);
...
```
--
You are receiving this mail because:
You are the assignee for the bug.