diff options
Diffstat (limited to 'cui/source/tabpages/grfpage.cxx')
-rw-r--r-- | cui/source/tabpages/grfpage.cxx | 257 |
1 files changed, 152 insertions, 105 deletions
diff --git a/cui/source/tabpages/grfpage.cxx b/cui/source/tabpages/grfpage.cxx index 726b09647bc1..9e96fdbb603c 100644 --- a/cui/source/tabpages/grfpage.cxx +++ b/cui/source/tabpages/grfpage.cxx @@ -32,6 +32,7 @@ #include <svx/svxids.hrc> #include <strings.hrc> #include <vcl/fieldvalues.hxx> +#include <vcl/outdev.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> #include <svtools/unitconv.hxx> @@ -39,6 +40,7 @@ #include <basegfx/matrix/b2dhommatrix.hxx> #include <basegfx/polygon/b2dpolygontools.hxx> #include <o3tl/unit_conversion.hxx> +#include <officecfg/Office/Common.hxx> constexpr auto CM_1_TO_TWIP = o3tl::convert(1, o3tl::Length::cm, o3tl::Length::twip); // 567 @@ -54,9 +56,10 @@ static int lcl_GetValue(const weld::MetricSpinButton& rMetric, FieldUnit eUnit) SvxGrfCropPage::SvxGrfCropPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet) : SfxTabPage(pPage, pController, "cui/ui/croppage.ui", "CropPage", &rSet) - , nOldWidth(0) - , nOldHeight(0) - , bSetOrigSize(false) + , m_nOldWidth(0) + , m_nOldHeight(0) + , m_bSetOrigSize(false) + , m_aPreferredDPI(0) , m_xCropFrame(m_xBuilder->weld_widget("cropframe")) , m_xZoomConstRB(m_xBuilder->weld_radio_button("keepscale")) , m_xSizeConstRB(m_xBuilder->weld_radio_button("keepsize")) @@ -73,6 +76,7 @@ SvxGrfCropPage::SvxGrfCropPage(weld::Container* pPage, weld::DialogController* p , m_xOrigSizeGrid(m_xBuilder->weld_widget("origsizegrid")) , m_xOrigSizeFT(m_xBuilder->weld_label("origsizeft")) , m_xOrigSizePB(m_xBuilder->weld_button("origsize")) + , m_xUncropPB(m_xBuilder->weld_button("uncrop")) , m_xExampleWN(new weld::CustomWeld(*m_xBuilder, "preview", m_aExampleWN)) { SetExchangeSupport(); @@ -102,6 +106,7 @@ SvxGrfCropPage::SvxGrfCropPage(weld::Container* pPage, weld::DialogController* p m_xBottomMF->connect_value_changed( aLk ); m_xOrigSizePB->connect_clicked(LINK(this, SvxGrfCropPage, OrigSizeHdl)); + m_xUncropPB->connect_clicked(LINK(this, SvxGrfCropPage, UncropHdl)); } SvxGrfCropPage::~SvxGrfCropPage() @@ -119,7 +124,7 @@ void SvxGrfCropPage::Reset( const SfxItemSet *rSet ) const SfxPoolItem* pItem; const SfxItemPool& rPool = *rSet->GetPool(); - if(SfxItemState::SET == rSet->GetItemState( rPool.GetWhich( + if(SfxItemState::SET == rSet->GetItemState( rPool.GetWhichIDFromSlotID( SID_ATTR_GRAF_KEEP_ZOOM ), true, &pItem )) { if( static_cast<const SfxBoolItem*>(pItem)->GetValue() ) @@ -129,7 +134,7 @@ void SvxGrfCropPage::Reset( const SfxItemSet *rSet ) m_xZoomConstRB->save_state(); } - sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_CROP ); + sal_uInt16 nW = rPool.GetWhichIDFromSlotID( SID_ATTR_GRAF_CROP ); if( SfxItemState::SET == rSet->GetItemState( nW, true, &pItem)) { FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW )); @@ -159,55 +164,54 @@ void SvxGrfCropPage::Reset( const SfxItemSet *rSet ) m_xTopMF->save_value(); m_xBottomMF->save_value(); - nW = rPool.GetWhich( SID_ATTR_PAGE_SIZE ); + nW = rPool.GetWhichIDFromSlotID( SID_ATTR_PAGE_SIZE ); if ( SfxItemState::SET == rSet->GetItemState( nW, false, &pItem ) ) { // orientation and size from the PageItem FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW )); - aPageSize = static_cast<const SvxSizeItem*>(pItem)->GetSize(); + m_aPageSize = static_cast<const SvxSizeItem*>(pItem)->GetSize(); auto nMin = m_xWidthMF->normalize( 23 ); - auto nMax = m_xHeightMF->normalize(aPageSize.Height()); + auto nMax = m_xHeightMF->normalize(m_aPageSize.Height()); m_xHeightMF->set_range(nMin, nMax, eUnit); - nMax = m_xWidthMF->normalize(aPageSize.Width()); + nMax = m_xWidthMF->normalize(m_aPageSize.Width()); m_xWidthMF->set_range(nMin, nMax, eUnit); } else { - aPageSize = OutputDevice::LogicToLogic( + m_aPageSize = OutputDevice::LogicToLogic( Size( CM_1_TO_TWIP, CM_1_TO_TWIP ), MapMode( MapUnit::MapTwip ), MapMode( rSet->GetPool()->GetMetric( nW ) ) ); } bool bFound = false; - if( SfxItemState::SET == rSet->GetItemState( SID_ATTR_GRAF_GRAPHIC, false, &pItem ) ) + if( const SvxBrushItem* pGraphicItem = rSet->GetItemIfSet( SID_ATTR_GRAF_GRAPHIC, false ) ) { OUString referer; - SfxStringItem const * it = static_cast<SfxStringItem const *>( - rSet->GetItem(SID_REFERER)); + SfxStringItem const * it = rSet->GetItem(SID_REFERER); if (it != nullptr) { referer = it->GetValue(); } - const Graphic* pGrf = static_cast<const SvxBrushItem*>(pItem)->GetGraphic(referer); + const Graphic* pGrf = pGraphicItem->GetGraphic(referer); if( pGrf ) { - aOrigSize = GetGrfOrigSize( *pGrf ); - if (pGrf->GetType() == GraphicType::Bitmap && aOrigSize.Width() && aOrigSize.Height()) + m_aOrigSize = GetGrfOrigSize( *pGrf ); + if (pGrf->GetType() == GraphicType::Bitmap && m_aOrigSize.Width() && m_aOrigSize.Height()) { - aOrigPixelSize = pGrf->GetSizePixel(); + m_aOrigPixelSize = pGrf->GetSizePixel(); } - if( aOrigSize.Width() && aOrigSize.Height() ) + if( m_aOrigSize.Width() && m_aOrigSize.Height() ) { CalcMinMaxBorder(); m_aExampleWN.SetGraphic( *pGrf ); - m_aExampleWN.SetFrameSize( aOrigSize ); + m_aExampleWN.SetFrameSize( m_aOrigSize ); bFound = true; - if( !static_cast<const SvxBrushItem*>(pItem)->GetGraphicLink().isEmpty() ) - aGraphicName = static_cast<const SvxBrushItem*>(pItem)->GetGraphicLink(); + if( !pGraphicItem->GetGraphicLink().isEmpty() ) + m_aGraphicName = pGraphicItem->GetGraphicLink(); } } } @@ -223,21 +227,21 @@ bool SvxGrfCropPage::FillItemSet(SfxItemSet *rSet) if( m_xWidthMF->get_value_changed_from_saved() || m_xHeightMF->get_value_changed_from_saved() ) { - sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_FRMSIZE ); + constexpr TypedWhichId<SvxSizeItem> nW = SID_ATTR_GRAF_FRMSIZE; FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW )); std::shared_ptr<SvxSizeItem> aSz(std::make_shared<SvxSizeItem>(nW)); // size could already have been set from another page const SfxItemSet* pExSet = GetDialogExampleSet(); - const SfxPoolItem* pItem = nullptr; - if( pExSet && SfxItemState::SET ==pExSet->GetItemState( nW, false, &pItem ) ) + const SvxSizeItem* pSizeItem = nullptr; + if( pExSet && (pSizeItem = pExSet->GetItemIfSet( nW, false )) ) { - aSz.reset(static_cast< SvxSizeItem*>(pItem->Clone())); + aSz.reset(pSizeItem->Clone()); } else { - aSz.reset(static_cast< SvxSizeItem*>(GetItemSet().Get(nW).Clone())); + aSz.reset(GetItemSet().Get(nW).Clone()); } Size aTmpSz( aSz->GetSize() ); @@ -251,16 +255,16 @@ bool SvxGrfCropPage::FillItemSet(SfxItemSet *rSet) bModified |= nullptr != rSet->Put( *aSz ); - if( bSetOrigSize ) + if (m_bSetOrigSize) { - bModified |= nullptr != rSet->Put( SvxSizeItem( rPool.GetWhich( + bModified |= nullptr != rSet->Put( SvxSizeItem( rPool.GetWhichIDFromSlotID( SID_ATTR_GRAF_FRMSIZE_PERCENT ), Size( 0, 0 )) ); } } if( m_xLeftMF->get_value_changed_from_saved() || m_xRightMF->get_value_changed_from_saved() || m_xTopMF->get_value_changed_from_saved() || m_xBottomMF->get_value_changed_from_saved() ) { - sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_CROP ); + sal_uInt16 nW = rPool.GetWhichIDFromSlotID( SID_ATTR_GRAF_CROP ); FieldUnit eUnit = MapToFieldUnit( rSet->GetPool()->GetMetric( nW )); std::unique_ptr<SvxGrfCrop> pNew(static_cast<SvxGrfCrop*>(rSet->Get( nW ).Clone())); @@ -268,12 +272,12 @@ bool SvxGrfCropPage::FillItemSet(SfxItemSet *rSet) pNew->SetRight( lcl_GetValue( *m_xRightMF, eUnit ) ); pNew->SetTop( lcl_GetValue( *m_xTopMF, eUnit ) ); pNew->SetBottom( lcl_GetValue( *m_xBottomMF, eUnit ) ); - bModified |= nullptr != rSet->Put( *pNew ); + bModified |= nullptr != rSet->Put( std::move(pNew) ); } if( m_xZoomConstRB->get_state_changed_from_saved() ) { - bModified |= nullptr != rSet->Put( SfxBoolItem( rPool.GetWhich( + bModified |= nullptr != rSet->Put( SfxBoolItem( rPool.GetWhichIDFromSlotID( SID_ATTR_GRAF_KEEP_ZOOM), m_xZoomConstRB->get_active() ) ); } @@ -287,19 +291,23 @@ void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet) DBG_ASSERT( pPool, "Where is the pool?" ); #endif - bSetOrigSize = false; + auto& aProperties = getAdditionalProperties(); + auto aIterator = aProperties.find("PreferredDPI"); + if (aIterator != aProperties.end()) + m_aPreferredDPI = aIterator->second.get<sal_Int32>(); + + m_bSetOrigSize = false; // Size Size aSize; - const SfxPoolItem* pItem; - if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRAF_FRMSIZE, false, &pItem ) ) - aSize = static_cast<const SvxSizeItem*>(pItem)->GetSize(); + if( const SvxSizeItem* pFrmSizeItem = rSet.GetItemIfSet( SID_ATTR_GRAF_FRMSIZE, false ) ) + aSize = pFrmSizeItem->GetSize(); - nOldWidth = aSize.Width(); - nOldHeight = aSize.Height(); + m_nOldWidth = aSize.Width(); + m_nOldHeight = aSize.Height(); - auto nWidth = m_xWidthMF->normalize(nOldWidth); - auto nHeight = m_xHeightMF->normalize(nOldHeight); + auto nWidth = m_xWidthMF->normalize(m_nOldWidth); + auto nHeight = m_xHeightMF->normalize(m_nOldHeight); if (nWidth != m_xWidthMF->get_value(FieldUnit::TWIP)) m_xWidthMF->set_value(nWidth, FieldUnit::TWIP); @@ -309,29 +317,27 @@ void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet) m_xHeightMF->set_value(nHeight, FieldUnit::TWIP); m_xHeightMF->save_value(); - if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRAF_GRAPHIC, false, &pItem ) ) + if( const SvxBrushItem* pBrushItem = rSet.GetItemIfSet( SID_ATTR_GRAF_GRAPHIC, false ) ) { - const SvxBrushItem& rBrush = *static_cast<const SvxBrushItem*>(pItem); - if( !rBrush.GetGraphicLink().isEmpty() && - aGraphicName != rBrush.GetGraphicLink() ) - aGraphicName = rBrush.GetGraphicLink(); + if( !pBrushItem->GetGraphicLink().isEmpty() && + m_aGraphicName != pBrushItem->GetGraphicLink() ) + m_aGraphicName = pBrushItem->GetGraphicLink(); OUString referer; - SfxStringItem const * it = static_cast<SfxStringItem const *>( - rSet.GetItem(SID_REFERER)); + SfxStringItem const * it = rSet.GetItem(SID_REFERER); if (it != nullptr) { referer = it->GetValue(); } - const Graphic* pGrf = rBrush.GetGraphic(referer); + const Graphic* pGrf = pBrushItem->GetGraphic(referer); if( pGrf ) { m_aExampleWN.SetGraphic( *pGrf ); - aOrigSize = GetGrfOrigSize( *pGrf ); - if (pGrf->GetType() == GraphicType::Bitmap && aOrigSize.Width() > 1 && aOrigSize.Height() > 1) { - aOrigPixelSize = pGrf->GetSizePixel(); + m_aOrigSize = GetGrfOrigSize( *pGrf ); + if (pGrf->GetType() == GraphicType::Bitmap && m_aOrigSize.Width() > 1 && m_aOrigSize.Height() > 1) { + m_aOrigPixelSize = pGrf->GetSizePixel(); } - m_aExampleWN.SetFrameSize(aOrigSize); - GraphicHasChanged( aOrigSize.Width() && aOrigSize.Height() ); + m_aExampleWN.SetFrameSize(m_aOrigSize); + GraphicHasChanged( m_aOrigSize.Width() && m_aOrigSize.Height() ); CalcMinMaxBorder(); } else @@ -356,7 +362,7 @@ IMPL_LINK( SvxGrfCropPage, ZoomHdl, weld::MetricSpinButton&, rField, void ) { SfxItemPool* pPool = GetItemSet().GetPool(); DBG_ASSERT( pPool, "Where is the pool?" ); - FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich( + FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhichIDFromSlotID( SID_ATTR_GRAF_CROP ) ) ); if (&rField == m_xWidthZoomMF.get()) @@ -364,7 +370,7 @@ IMPL_LINK( SvxGrfCropPage, ZoomHdl, weld::MetricSpinButton&, rField, void ) tools::Long nLRBorders = lcl_GetValue(*m_xLeftMF, eUnit) +lcl_GetValue(*m_xRightMF, eUnit); m_xWidthMF->set_value( m_xWidthMF->normalize( - ((aOrigSize.Width() - nLRBorders) * rField.get_value(FieldUnit::NONE))/100), + ((m_aOrigSize.Width() - nLRBorders) * rField.get_value(FieldUnit::NONE))/100), eUnit); } else @@ -372,7 +378,7 @@ IMPL_LINK( SvxGrfCropPage, ZoomHdl, weld::MetricSpinButton&, rField, void ) tools::Long nULBorders = lcl_GetValue(*m_xTopMF, eUnit) +lcl_GetValue(*m_xBottomMF, eUnit); m_xHeightMF->set_value( m_xHeightMF->normalize( - ((aOrigSize.Height() - nULBorders ) * rField.get_value(FieldUnit::NONE))/100) , + ((m_aOrigSize.Height() - nULBorders ) * rField.get_value(FieldUnit::NONE))/100) , eUnit ); } } @@ -385,7 +391,7 @@ IMPL_LINK( SvxGrfCropPage, SizeHdl, weld::MetricSpinButton&, rField, void ) { SfxItemPool* pPool = GetItemSet().GetPool(); DBG_ASSERT( pPool, "Where is the pool?" ); - FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich( + FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhichIDFromSlotID( SID_ATTR_GRAF_CROP ) ) ); Size aSize( lcl_GetValue(*m_xWidthMF, eUnit), @@ -393,7 +399,7 @@ IMPL_LINK( SvxGrfCropPage, SizeHdl, weld::MetricSpinButton&, rField, void ) if(&rField == m_xWidthMF.get()) { - tools::Long nWidth = aOrigSize.Width() - + tools::Long nWidth = m_aOrigSize.Width() - ( lcl_GetValue(*m_xLeftMF, eUnit) + lcl_GetValue(*m_xRightMF, eUnit) ); if(!nWidth) @@ -403,7 +409,7 @@ IMPL_LINK( SvxGrfCropPage, SizeHdl, weld::MetricSpinButton&, rField, void ) } else { - tools::Long nHeight = aOrigSize.Height() - + tools::Long nHeight = m_aOrigSize.Height() - ( lcl_GetValue(*m_xTopMF, eUnit) + lcl_GetValue(*m_xBottomMF, eUnit)); if(!nHeight) @@ -421,7 +427,7 @@ IMPL_LINK( SvxGrfCropPage, CropModifyHdl, weld::MetricSpinButton&, rField, void { SfxItemPool* pPool = GetItemSet().GetPool(); DBG_ASSERT( pPool, "Where is the pool?" ); - FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich( + FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhichIDFromSlotID( SID_ATTR_GRAF_CROP ) ) ); bool bZoom = m_xZoomConstRB->get_active(); @@ -430,19 +436,19 @@ IMPL_LINK( SvxGrfCropPage, CropModifyHdl, weld::MetricSpinButton&, rField, void tools::Long nLeft = lcl_GetValue( *m_xLeftMF, eUnit ); tools::Long nRight = lcl_GetValue( *m_xRightMF, eUnit ); tools::Long nWidthZoom = static_cast<tools::Long>(m_xWidthZoomMF->get_value(FieldUnit::NONE)); - if (bZoom && nWidthZoom != 0 && ( ( ( aOrigSize.Width() - (nLeft + nRight )) * nWidthZoom ) - / 100 >= aPageSize.Width() ) ) + if (bZoom && nWidthZoom != 0 && ( ( ( m_aOrigSize.Width() - (nLeft + nRight )) * nWidthZoom ) + / 100 >= m_aPageSize.Width() ) ) { if (&rField == m_xLeftMF.get()) { - nLeft = aOrigSize.Width() - - ( aPageSize.Width() * 100 / nWidthZoom + nRight ); + nLeft = m_aOrigSize.Width() - + ( m_aPageSize.Width() * 100 / nWidthZoom + nRight ); m_xLeftMF->set_value( m_xLeftMF->normalize( nLeft ), eUnit ); } else { - nRight = aOrigSize.Width() - - ( aPageSize.Width() * 100 / nWidthZoom + nLeft ); + nRight = m_aOrigSize.Width() - + ( m_aPageSize.Width() * 100 / nWidthZoom + nLeft ); m_xRightMF->set_value( m_xRightMF->normalize( nRight ), eUnit ); } } @@ -467,20 +473,20 @@ IMPL_LINK( SvxGrfCropPage, CropModifyHdl, weld::MetricSpinButton&, rField, void tools::Long nTop = lcl_GetValue( *m_xTopMF, eUnit ); tools::Long nBottom = lcl_GetValue( *m_xBottomMF, eUnit ); tools::Long nHeightZoom = static_cast<tools::Long>(m_xHeightZoomMF->get_value(FieldUnit::NONE)); - if(bZoom && ( ( ( aOrigSize.Height() - (nTop + nBottom )) * nHeightZoom) - / 100 >= aPageSize.Height())) + if(bZoom && ( ( ( m_aOrigSize.Height() - (nTop + nBottom )) * nHeightZoom) + / 100 >= m_aPageSize.Height())) { assert(nHeightZoom && "div-by-zero"); if(&rField == m_xTopMF.get()) { - nTop = aOrigSize.Height() - - ( aPageSize.Height() * 100 / nHeightZoom + nBottom); + nTop = m_aOrigSize.Height() - + ( m_aPageSize.Height() * 100 / nHeightZoom + nBottom); m_xTopMF->set_value( m_xWidthMF->normalize( nTop ), eUnit ); } else { - nBottom = aOrigSize.Height() - - ( aPageSize.Height() * 100 / nHeightZoom + nTop); + nBottom = m_aOrigSize.Height() - + ( m_aPageSize.Height() * 100 / nHeightZoom + nTop); m_xBottomMF->set_value( m_xWidthMF->normalize( nBottom ), eUnit ); } } @@ -506,21 +512,47 @@ IMPL_LINK_NOARG(SvxGrfCropPage, OrigSizeHdl, weld::Button&, void) { SfxItemPool* pPool = GetItemSet().GetPool(); DBG_ASSERT( pPool, "Where is the pool?" ); - FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich( + FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhichIDFromSlotID( SID_ATTR_GRAF_CROP ) ) ); - tools::Long nWidth = aOrigSize.Width() - + tools::Long nWidth = m_aOrigSize.Width() - lcl_GetValue( *m_xLeftMF, eUnit ) - lcl_GetValue( *m_xRightMF, eUnit ); m_xWidthMF->set_value( m_xWidthMF->normalize( nWidth ), eUnit ); - tools::Long nHeight = aOrigSize.Height() - + tools::Long nHeight = m_aOrigSize.Height() - lcl_GetValue( *m_xTopMF, eUnit ) - lcl_GetValue( *m_xBottomMF, eUnit ); m_xHeightMF->set_value( m_xHeightMF->normalize( nHeight ), eUnit ); m_xWidthZoomMF->set_value(100, FieldUnit::NONE); m_xHeightZoomMF->set_value(100, FieldUnit::NONE); - bSetOrigSize = true; + m_bSetOrigSize = true; } + +/*-------------------------------------------------------------------- + description: reset crop + --------------------------------------------------------------------*/ + +IMPL_LINK_NOARG(SvxGrfCropPage, UncropHdl, weld::Button&, void) +{ + SfxItemPool* pPool = GetItemSet().GetPool(); + DBG_ASSERT( pPool, "Where is the pool?" ); + + m_xLeftMF->set_value(0, FieldUnit::NONE); + m_xRightMF->set_value(0, FieldUnit::NONE); + m_xTopMF->set_value(0, FieldUnit::NONE); + m_xBottomMF->set_value(0, FieldUnit::NONE); + + m_aExampleWN.SetLeft(0); + m_aExampleWN.SetRight(0); + m_aExampleWN.SetTop(0); + m_aExampleWN.SetBottom(0); + + m_aExampleWN.Invalidate(); + CalcMinMaxBorder(); + +} + + /*-------------------------------------------------------------------- description: compute scale --------------------------------------------------------------------*/ @@ -529,7 +561,7 @@ void SvxGrfCropPage::CalcZoom() { SfxItemPool* pPool = GetItemSet().GetPool(); DBG_ASSERT( pPool, "Where is the pool?" ); - FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich( + FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhichIDFromSlotID( SID_ATTR_GRAF_CROP ) ) ); tools::Long nWidth = lcl_GetValue( *m_xWidthMF, eUnit ); @@ -540,10 +572,10 @@ void SvxGrfCropPage::CalcZoom() lcl_GetValue( *m_xBottomMF, eUnit ); sal_uInt16 nZoom = 0; tools::Long nDen; - if( (nDen = aOrigSize.Width() - nLRBorders) > 0) + if( (nDen = m_aOrigSize.Width() - nLRBorders) > 0) nZoom = static_cast<sal_uInt16>((( nWidth * 1000 / nDen )+5)/10); m_xWidthZoomMF->set_value(nZoom, FieldUnit::NONE); - if( (nDen = aOrigSize.Height() - nULBorders) > 0) + if( (nDen = m_aOrigSize.Height() - nULBorders) > 0) nZoom = static_cast<sal_uInt16>((( nHeight * 1000 / nDen )+5)/10); else nZoom = 0; @@ -558,10 +590,10 @@ void SvxGrfCropPage::CalcMinMaxBorder() { SfxItemPool* pPool = GetItemSet().GetPool(); DBG_ASSERT( pPool, "Where is the pool?" ); - FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich( + FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhichIDFromSlotID( SID_ATTR_GRAF_CROP ) ) ); tools::Long nR = lcl_GetValue(*m_xRightMF, eUnit ); - tools::Long nMinWidth = (aOrigSize.Width() * 10) /11; + tools::Long nMinWidth = (m_aOrigSize.Width() * 10) /11; tools::Long nMin = nMinWidth - (nR >= 0 ? nR : 0); m_xLeftMF->set_max( m_xLeftMF->normalize(nMin), eUnit ); @@ -570,7 +602,7 @@ void SvxGrfCropPage::CalcMinMaxBorder() m_xRightMF->set_max( m_xRightMF->normalize(nMin), eUnit ); tools::Long nUp = lcl_GetValue( *m_xTopMF, eUnit ); - tools::Long nMinHeight = (aOrigSize.Height() * 10) /11; + tools::Long nMinHeight = (m_aOrigSize.Height() * 10) /11; nMin = nMinHeight - (nUp >= 0 ? nUp : 0); m_xBottomMF->set_max( m_xBottomMF->normalize(nMin), eUnit ); @@ -589,19 +621,19 @@ void SvxGrfCropPage::GraphicHasChanged( bool bFound ) { SfxItemPool* pPool = GetItemSet().GetPool(); DBG_ASSERT( pPool, "Where is the pool?" ); - FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich( + FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhichIDFromSlotID( SID_ATTR_GRAF_CROP ) )); - sal_Int64 nSpin = m_xLeftMF->normalize(aOrigSize.Width()) / 20; - nSpin = vcl::ConvertValue( nSpin, aOrigSize.Width(), 0, + sal_Int64 nSpin = m_xLeftMF->normalize(m_aOrigSize.Width()) / 20; + nSpin = vcl::ConvertValue( nSpin, m_aOrigSize.Width(), 0, eUnit, m_xLeftMF->get_unit()); // if the margin is too big, it is set to 1/3 on both pages tools::Long nR = lcl_GetValue( *m_xRightMF, eUnit ); tools::Long nL = lcl_GetValue( *m_xLeftMF, eUnit ); - if((nL + nR) < - aOrigSize.Width()) + if((nL + nR) < - m_aOrigSize.Width()) { - tools::Long nVal = aOrigSize.Width() / -3; + tools::Long nVal = m_aOrigSize.Width() / -3; m_xRightMF->set_value( m_xRightMF->normalize( nVal ), eUnit ); m_xLeftMF->set_value( m_xLeftMF->normalize( nVal ), eUnit ); m_aExampleWN.SetLeft(nVal); @@ -609,9 +641,9 @@ void SvxGrfCropPage::GraphicHasChanged( bool bFound ) } tools::Long nUp = lcl_GetValue(*m_xTopMF, eUnit ); tools::Long nLow = lcl_GetValue(*m_xBottomMF, eUnit ); - if((nUp + nLow) < - aOrigSize.Height()) + if((nUp + nLow) < - m_aOrigSize.Height()) { - tools::Long nVal = aOrigSize.Height() / -3; + tools::Long nVal = m_aOrigSize.Height() / -3; m_xTopMF->set_value( m_xTopMF->normalize( nVal ), eUnit ); m_xBottomMF->set_value( m_xBottomMF->normalize( nVal ), eUnit ); m_aExampleWN.SetTop(nVal); @@ -620,8 +652,8 @@ void SvxGrfCropPage::GraphicHasChanged( bool bFound ) m_xLeftMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE); m_xRightMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE); - nSpin = m_xTopMF->normalize(aOrigSize.Height()) / 20; - nSpin = vcl::ConvertValue( nSpin, aOrigSize.Width(), 0, + nSpin = m_xTopMF->normalize(m_aOrigSize.Height()) / 20; + nSpin = vcl::ConvertValue( nSpin, m_aOrigSize.Width(), 0, eUnit, m_xLeftMF->get_unit() ); m_xTopMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE); m_xBottomMF->set_increments(nSpin, nSpin * 10, FieldUnit::NONE); @@ -638,26 +670,27 @@ void SvxGrfCropPage::GraphicHasChanged( bool bFound ) xFld->set_digits(m_xWidthMF->get_digits()); xFld->set_max(INT_MAX - 1, FieldUnit::NONE); - xFld->set_value(xFld->normalize(aOrigSize.Width()), eUnit); + xFld->set_value(xFld->normalize(m_aOrigSize.Width()), eUnit); sTemp = xFld->get_text(); - xFld->set_value(xFld->normalize(aOrigSize.Height()), eUnit); + xFld->set_value(xFld->normalize(m_aOrigSize.Height()), eUnit); // multiplication sign (U+00D7) sTemp += u"\u00D7" + xFld->get_text(); } - if ( aOrigPixelSize.Width() && aOrigPixelSize.Height() ) { - sal_Int32 ax = 0.5 + aOrigPixelSize.Width() / - o3tl::convert<double>(aOrigSize.Width(), o3tl::Length::twip, + if ( m_aOrigPixelSize.Width() && m_aOrigPixelSize.Height() ) { + sal_Int32 ax = 0.5 + m_aOrigPixelSize.Width() / + o3tl::convert<double>(m_aOrigSize.Width(), o3tl::Length::twip, o3tl::Length::in); - sal_Int32 ay = 0.5 + aOrigPixelSize.Height() / - o3tl::convert<double>(aOrigSize.Height(), o3tl::Length::twip, + sal_Int32 ay = 0.5 + m_aOrigPixelSize.Height() / + o3tl::convert<double>(m_aOrigSize.Height(), o3tl::Length::twip, o3tl::Length::in); OUString sPPI = OUString::number(ax); if (abs(ax - ay) > 1) { sPPI += u"\u00D7" + OUString::number(ay); } - sTemp += " " + CuiResId(RID_SVXSTR_PPI).replaceAll("%1", sPPI); + sTemp += " " + CuiResId(RID_CUISTR_PPI).replaceAll("%1", sPPI); } + sTemp += "\n" + OUString::number(m_aOrigPixelSize.Width()) + u"\u00D7" + OUString::number(m_aOrigPixelSize.Height()) + " px"; m_xOrigSizeFT->set_label(sTemp); } @@ -670,13 +703,27 @@ void SvxGrfCropPage::GraphicHasChanged( bool bFound ) Size SvxGrfCropPage::GetGrfOrigSize(const Graphic& rGrf) { - const MapMode aMapTwip( MapUnit::MapTwip ); - Size aSize( rGrf.GetPrefSize() ); - if( MapUnit::MapPixel == rGrf.GetPrefMapMode().GetMapUnit() ) - aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, aMapTwip); + Size aSize; + + if (m_aPreferredDPI > 0) + { + Size aPixelSize = rGrf.GetSizePixel(); + double fWidth = aPixelSize.Width() / double(m_aPreferredDPI); + double fHeight = aPixelSize.Height() / double(m_aPreferredDPI); + fWidth = o3tl::convert(fWidth, o3tl::Length::in, o3tl::Length::twip); + fHeight = o3tl::convert(fHeight, o3tl::Length::in, o3tl::Length::twip); + aSize = Size(fWidth, fHeight); + } else - aSize = OutputDevice::LogicToLogic( aSize, - rGrf.GetPrefMapMode(), aMapTwip ); + { + const MapMode aMapTwip( MapUnit::MapTwip ); + aSize = rGrf.GetPrefSize(); + if( MapUnit::MapPixel == rGrf.GetPrefMapMode().GetMapUnit() ) + aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, aMapTwip); + else + aSize = OutputDevice::LogicToLogic( aSize, + rGrf.GetPrefMapMode(), aMapTwip ); + } return aSize; } @@ -728,7 +775,7 @@ void SvxCropExample::Paint(vcl::RenderContext& rRenderContext, const ::tools::Re // the former used XOR paint. const Color aColA(SvtOptionsDrawinglayer::GetStripeColorA().getBColor()); const Color aColB(SvtOptionsDrawinglayer::GetStripeColorB().getBColor()); - const double fStripeLength(SvtOptionsDrawinglayer::GetStripeLength()); + const double fStripeLength(officecfg::Office::Common::Drawinglayer::StripeLength::get()); const basegfx::B2DVector aDashVector(rRenderContext.GetInverseViewTransformation() * basegfx::B2DVector(fStripeLength, 0.0)); const double fLogicDashLength(aDashVector.getX()); |