grfmgr.cxx (ddde725d) grfmgr.cxx (2376739d)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 995 unchanged lines hidden (view full) ---

1004 aMtf.Scale( Fraction( rDestSize.Width(), aSrcSize.Width() ), Fraction( rDestSize.Height(), aSrcSize.Height() ) );
1005 aMtf.SetPrefMapMode( rDestMap );
1006 }
1007
1008 aTransGraphic = aMtf;
1009 }
1010 else if( GRAPHIC_BITMAP == eType )
1011 {
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 995 unchanged lines hidden (view full) ---

1004 aMtf.Scale( Fraction( rDestSize.Width(), aSrcSize.Width() ), Fraction( rDestSize.Height(), aSrcSize.Height() ) );
1005 aMtf.SetPrefMapMode( rDestMap );
1006 }
1007
1008 aTransGraphic = aMtf;
1009 }
1010 else if( GRAPHIC_BITMAP == eType )
1011 {
1012 BitmapEx aBitmapEx( aTransGraphic.GetBitmapEx() );
1012 BitmapEx aBitmapEx( aTransGraphic.GetBitmapEx() );
1013 Rectangle aCropRect;
1013
1014
1014 // convert crops to pixel
1015 aCropLeftTop = Application::GetDefaultDevice()->LogicToPixel( Size( rAttr.GetLeftCrop(),
1016 rAttr.GetTopCrop() ),
1017 aMap100 );
1018 aCropRightBottom = Application::GetDefaultDevice()->LogicToPixel( Size( rAttr.GetRightCrop(),
1019 rAttr.GetBottomCrop() ),
1020 aMap100 );
1015 // convert crops to pixel (crops are always in GraphicObject units)
1016 if(rAttr.IsCropped())
1017 {
1018 aCropLeftTop = Application::GetDefaultDevice()->LogicToPixel(
1019 Size(rAttr.GetLeftCrop(), rAttr.GetTopCrop()),
1020 aMapGraph);
1021 aCropRightBottom = Application::GetDefaultDevice()->LogicToPixel(
1022 Size(rAttr.GetRightCrop(), rAttr.GetBottomCrop()),
1023 aMapGraph);
1021
1024
1022 // convert from prefmapmode to pixel
1023 const Size aSrcSizePixel( Application::GetDefaultDevice()->LogicToPixel( aSrcSize,
1024 aMapGraph ) );
1025 // convert from prefmapmode to pixel
1026 Size aSrcSizePixel(
1027 Application::GetDefaultDevice()->LogicToPixel(
1028 aSrcSize,
1029 aMapGraph));
1025
1030
1026 // setup crop rectangle in pixel
1027 Rectangle aCropRect( aCropLeftTop.Width(), aCropLeftTop.Height(),
1028 aSrcSizePixel.Width() - aCropRightBottom.Width(),
1029 aSrcSizePixel.Height() - aCropRightBottom.Height() );
1031 if(rAttr.IsCropped()
1032 && (aSrcSizePixel.Width() != aBitmapEx.GetSizePixel().Width() || aSrcSizePixel.Height() != aBitmapEx.GetSizePixel().Height())
1033 && aSrcSizePixel.Width())
1034 {
1035 // the size in pixels calculated from Graphic's internal MapMode (aTransGraphic.GetPrefMapMode())
1036 // and it's internal size (aTransGraphic.GetPrefSize()) is different from it's real pixel size.
1037 // This can be interpreted as this values to be set wrong, but needs to be corrected since e.g.
1038 // existing cropping is calculated based on this logic values already.
1039 // aBitmapEx.Scale(aSrcSizePixel);
1030
1040
1041 // another possibility is to adapt the values created so far with a factor; this
1042 // will keep the original Bitmap untouched and thus quality will not change
1043 const double fFactorX(aBitmapEx.GetSizePixel().Width() / aSrcSizePixel.Width());
1044 const double fFactorY(aBitmapEx.GetSizePixel().Height() / aSrcSizePixel.Height());
1045
1046 aCropLeftTop.Width() = basegfx::fround(aCropLeftTop.Width() * fFactorX);
1047 aCropLeftTop.Height() = basegfx::fround(aCropLeftTop.Height() * fFactorY);
1048 aCropRightBottom.Width() = basegfx::fround(aCropRightBottom.Width() * fFactorX);
1049 aCropRightBottom.Height() = basegfx::fround(aCropRightBottom.Height() * fFactorY);
1050
1051 aSrcSizePixel = aBitmapEx.GetSizePixel();
1052 }
1053
1054 // setup crop rectangle in pixel
1055 aCropRect = Rectangle( aCropLeftTop.Width(), aCropLeftTop.Height(),
1056 aSrcSizePixel.Width() - aCropRightBottom.Width(),
1057 aSrcSizePixel.Height() - aCropRightBottom.Height() );
1058 }
1059
1031 // #105641# Also crop animations
1032 if( aTransGraphic.IsAnimated() )
1033 {
1034 sal_uInt16 nFrame;
1035 Animation aAnim( aTransGraphic.GetAnimation() );
1036
1037 for( nFrame=0; nFrame<aAnim.Count(); ++nFrame )
1038 {

--- 48 unchanged lines hidden (view full) ---

1087 aAnim.Replace( aAnimBmp, nFrame );
1088 }
1089 }
1090
1091 aTransGraphic = aAnim;
1092 }
1093 else
1094 {
1060 // #105641# Also crop animations
1061 if( aTransGraphic.IsAnimated() )
1062 {
1063 sal_uInt16 nFrame;
1064 Animation aAnim( aTransGraphic.GetAnimation() );
1065
1066 for( nFrame=0; nFrame<aAnim.Count(); ++nFrame )
1067 {

--- 48 unchanged lines hidden (view full) ---

1116 aAnim.Replace( aAnimBmp, nFrame );
1117 }
1118 }
1119
1120 aTransGraphic = aAnim;
1121 }
1122 else
1123 {
1095 BitmapEx aBmpEx( aTransGraphic.GetBitmapEx() );
1096
1097 ImplTransformBitmap( aBmpEx, rAttr, aCropLeftTop, aCropRightBottom,
1124 ImplTransformBitmap( aBitmapEx, rAttr, aCropLeftTop, aCropRightBottom,
1098 aCropRect, rDestSize, sal_True );
1099
1125 aCropRect, rDestSize, sal_True );
1126
1100 aTransGraphic = aBmpEx;
1127 aTransGraphic = aBitmapEx;
1101 }
1102
1103 aTransGraphic.SetPrefSize( rDestSize );
1104 aTransGraphic.SetPrefMapMode( rDestMap );
1105 }
1106
1107 GraphicObject aGrfObj( aTransGraphic );
1108 aTransGraphic = aGrfObj.GetTransformedGraphic( &rAttr );

--- 254 unchanged lines hidden (view full) ---

1363 SvStream* pStream = utl::UcbStreamHelper::CreateStream( aURL, STREAM_READ );
1364 if( pStream )
1365 GraphicConverter::Import( *pStream, aGraphic );
1366 }
1367
1368 return GraphicObject( aGraphic );
1369 }
1370}
1128 }
1129
1130 aTransGraphic.SetPrefSize( rDestSize );
1131 aTransGraphic.SetPrefMapMode( rDestMap );
1132 }
1133
1134 GraphicObject aGrfObj( aTransGraphic );
1135 aTransGraphic = aGrfObj.GetTransformedGraphic( &rAttr );

--- 254 unchanged lines hidden (view full) ---

1390 SvStream* pStream = utl::UcbStreamHelper::CreateStream( aURL, STREAM_READ );
1391 if( pStream )
1392 GraphicConverter::Import( *pStream, aGraphic );
1393 }
1394
1395 return GraphicObject( aGraphic );
1396 }
1397}
1398
1399// calculate scalings between real image size and logic object size. This
1400// is necessary since the crop values are relative to original bitmap size
1401basegfx::B2DVector GraphicObject::calculateCropScaling(
1402 double fWidth,
1403 double fHeight,
1404 double fLeftCrop,
1405 double fTopCrop,
1406 double fRightCrop,
1407 double fBottomCrop) const
1408{
1409 const MapMode aMapMode100thmm(MAP_100TH_MM);
1410 Size aBitmapSize(GetPrefSize());
1411 double fFactorX(1.0);
1412 double fFactorY(1.0);
1413
1414 if(MAP_PIXEL == GetPrefMapMode().GetMapUnit())
1415 {
1416 aBitmapSize = Application::GetDefaultDevice()->PixelToLogic(aBitmapSize, aMapMode100thmm);
1417 }
1418 else
1419 {
1420 aBitmapSize = Application::GetDefaultDevice()->LogicToLogic(aBitmapSize, GetPrefMapMode(), aMapMode100thmm);
1421 }
1422
1423 const double fDivX(aBitmapSize.Width() - fLeftCrop - fRightCrop);
1424 const double fDivY(aBitmapSize.Height() - fTopCrop - fBottomCrop);
1425
1426 if(!basegfx::fTools::equalZero(fDivX))
1427 {
1428 fFactorX = fabs(fWidth) / fDivX;
1429 }
1430
1431 if(!basegfx::fTools::equalZero(fDivY))
1432 {
1433 fFactorY = fabs(fHeight) / fDivY;
1434 }
1435
1436 return basegfx::B2DVector(fFactorX,fFactorY);
1437}
1438
1439// eof