include/vcl/graph.hxx | 3 +++ vcl/source/filter/png/PngImageWriter.cxx | 4 ++++ vcl/source/gdi/graph.cxx | 15 +++++++++++++++ 3 files changed, 22 insertions(+)
New commits: commit 32ab4b4b6364652294891f66a86f153b65abfbbe Author: Noel Grandin <[email protected]> AuthorDate: Fri Oct 25 12:12:59 2024 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Fri Oct 25 15:40:24 2024 +0200 tdf#139152 Exporting Image or Drawing to PNG is missing metada implement this in a similar fashion to how export to JPEG does it. Add a new method to calculate pixels-per-meter, because that is how PNG stores the values internally Change-Id: I1e4cd5a36af22e52a7c52f5b3bc2407f8523ef9f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175636 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx index 9d1499ea98c1..c4046e178337 100644 --- a/include/vcl/graph.hxx +++ b/include/vcl/graph.hxx @@ -140,7 +140,10 @@ public: MapMode GetPrefMapMode() const; void SetPrefMapMode( const MapMode& rPrefMapMode ); + /** pixels per inch i.e. DPI */ basegfx::B2DSize GetPPI() const; + /** pixels per meter */ + basegfx::B2DSize GetPPM() const; Size GetSizePixel( const OutputDevice* pRefDevice = nullptr ) const; diff --git a/vcl/source/filter/png/PngImageWriter.cxx b/vcl/source/filter/png/PngImageWriter.cxx index f2b7ac038b34..54334469f65e 100644 --- a/vcl/source/filter/png/PngImageWriter.cxx +++ b/vcl/source/filter/png/PngImageWriter.cxx @@ -142,6 +142,10 @@ static bool pngWrite(SvStream& rStream, const Graphic& rGraphic, int nCompressio return false; } + basegfx::B2DSize const aPPM = rGraphic.GetPPM(); + png_set_pHYs(pPng, pInfo, std::round(aPPM.getWidth()), std::round(aPPM.getHeight()), + PNG_RESOLUTION_METER); + BitmapEx aBitmapEx; if (rGraphic.GetBitmapEx().getPixelFormat() == vcl::PixelFormat::N32_BPP) { diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index f90adeb24703..0325fa6a18ec 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -407,6 +407,21 @@ basegfx::B2DSize Graphic::GetPPI() const return basegfx::B2DSize(nGrfDPIx, nGrfDPIy); } +basegfx::B2DSize Graphic::GetPPM() const +{ + const MapMode aGrfMap(GetPrefMapMode()); + const Size aGrfPixelSize(GetSizePixel()); + const Size aGrfPrefMapModeSize(GetPrefSize()); + const Size aGrf100thMMSize = OutputDevice::LogicToLogic( + aGrfPrefMapModeSize, aGrfMap, MapMode(MapUnit::Map100thMM)); + double nGrfDPMx = aGrf100thMMSize.Width() == 0 + ? 0.0 : 100000.0 * aGrfPixelSize.Width() / aGrf100thMMSize.Width(); + double nGrfDPMy = aGrf100thMMSize.Height() == 0 + ? 0.0 : 100000.0 * aGrfPixelSize.Height() / aGrf100thMMSize.Height(); + + return basegfx::B2DSize(nGrfDPMx, nGrfDPMy); +} + Size Graphic::GetSizePixel( const OutputDevice* pRefDevice ) const { Size aRet;
