diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2016-02-13 16:08:01 +1100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2016-02-14 20:51:08 +0000 |
commit | f8355221ae62b89a706f2d04b63eda658f3ccfa5 (patch) | |
tree | 6a01919926776dc5c36ffb825dc69b46ba66fbac /vcl/source/gdi/graph.cxx | |
parent | 19fb09dce67d29d480ff39c538209b887f661dc9 (diff) |
tdf#85761 vcl: JPEG export does not save PPI values correctly
JPEG values are currently hardcoded to 96PPI when we export JPEGs. The
Graphic class doesn't have an easy way to get the PPI, but this can
actually be calculated from the pref size and pref map mode (no idea
why it is called "Pref").
Interestingly, you need to get a multiplier to work this out, relative
to units of 100th mm. The EPS filter code had a function that does
exactly this, but it's entirely based on MapMode units so it was really
implemented in the wrong class IMO. I have thus moved it out of PSWriter
and into MapMode.
This also fixes tdf#65695, which was partially fixed, but had the JPEG
PPI hardcoded to 96dpi.
Also fixes tdf#97481.
Change-Id: Iedb674141dd4e22fcbfb7be357dc777f732aa3aa
Reviewed-on: https://gerrit.libreoffice.org/22339
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source/gdi/graph.cxx')
-rw-r--r-- | vcl/source/gdi/graph.cxx | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index 6acf9b19abe3..2c14d8f3bc9a 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -37,8 +37,8 @@ static void ImplDrawDefault( OutputDevice* pOutDev, const OUString* pText, vcl::Font* pFont, const Bitmap* pBitmap, const BitmapEx* pBitmapEx, const Point& rDestPt, const Size& rDestSize ) { - sal_uInt16 nPixel = (sal_uInt16) pOutDev->PixelToLogic( Size( 1, 1 ) ).Width(); - sal_uInt16 nPixelWidth = nPixel; + sal_uInt16 nPixel = (sal_uInt16) pOutDev->PixelToLogic( Size( 1, 1 ) ).Width(); + sal_uInt16 nPixelWidth = nPixel; Point aPoint( rDestPt.X() + nPixelWidth, rDestPt.Y() + nPixelWidth ); Size aSize( rDestSize.Width() - ( nPixelWidth << 1 ), rDestSize.Height() - ( nPixelWidth << 1 ) ); bool bFilled = ( pBitmap != nullptr || pBitmapEx != nullptr || pFont != nullptr ); @@ -407,6 +407,28 @@ void Graphic::SetPrefMapMode( const MapMode& rPrefMapMode ) mpImpGraphic->ImplSetPrefMapMode( rPrefMapMode ); } +basegfx::B2DSize Graphic::GetPPI() const +{ + MapMode aMapMode = GetPrefMapMode(); + + double fWidthInches = ( GetPrefSize().Width() * aMapMode.GetUnitMultiplier() ) / 2540; + double fHeightInches = ( GetPrefSize().Height() * aMapMode.GetUnitMultiplier() ) / 2540; + double fPpiX = 0; + double fPpiY = 0; + + if ( fWidthInches > 0 || fHeightInches > 0 ) // we don't want a divide by 0 situation + { + fPpiX = GetSizePixel().Width() / fWidthInches; + fPpiY = GetSizePixel().Height() / fHeightInches; + } + else + { + SAL_WARN("vcl", "PPI X is " << fPpiX << " and PPI Y is " << fPpiY << ": thus we are making this 0 DPI. This is unlikely."); + } + + return basegfx::B2DSize( fPpiX, fPpiY ); +} + Size Graphic::GetSizePixel( const OutputDevice* pRefDevice ) const { Size aRet; |