Fixed bug #3582282 where the capture was cropped. Also fixed the error handling so now when the export failed this is also displayed.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2234 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-11-04 17:18:39 +00:00
commit d49a203b3a
2 changed files with 28 additions and 23 deletions

View file

@ -107,48 +107,48 @@ namespace Greenshot.Interop.Office {
float height = imageSize.Height;
bool isLayoutPictureWithCaption = false;
IShape shapeForCaption = null;
bool isWidthResized = false;
bool isHeightResized = false;
bool hasScaledWidth = false;
bool hasScaledHeight = false;
try {
slide = presentation.Slides.Add(presentation.Slides.Count + 1, (int)PPSlideLayout.ppLayoutPictureWithCaption);
isLayoutPictureWithCaption = true;
// Shapes[2] is the image shape on this layout.
shapeForCaption = slide.Shapes.item(1);
IShape shapeForLocation = slide.Shapes.item(2);
if (width > shapeForLocation.Width) {
width = shapeForLocation.Width;
isWidthResized = true;
left = shapeForLocation.Left;
hasScaledWidth = true;
} else {
//left = (shapeForLocation.Left + (shapeForLocation.Width / 2)) - (imageSize.Width / 2);
shapeForLocation.Width = width;
shapeForLocation.Left = left;
}
shapeForLocation.Width = imageSize.Width;
if (height > shapeForLocation.Height) {
height = shapeForLocation.Height;
isHeightResized = true;
top = shapeForLocation.Top;
hasScaledHeight = true;
} else {
top = (shapeForLocation.Top + (shapeForLocation.Height / 2)) - (imageSize.Height / 2);
shapeForLocation.Height = height;
//shapeForLocation.Top = top;
}
//shapeForLocation.Top = top;
//LOG.DebugFormat("Shape {0},{1},{2},{3}", shapeForLocation.Left, shapeForLocation.Top, imageSize.Width, imageSize.Height);
shapeForLocation.Height = imageSize.Height;
} catch (Exception e) {
LOG.Error(e);
slide = presentation.Slides.Add(presentation.Slides.Count + 1, (int)PPSlideLayout.ppLayoutBlank);
}
IShape shape = slide.Shapes.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, width, height);
shape.LockAspectRatio = MsoTriState.msoTrue;
shape.ScaleHeight(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromMiddle);
shape.ScaleWidth(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromMiddle);
if (hasScaledWidth) {
shape.Width = width;
}
if (hasScaledHeight) {
shape.Height = height;
}
shape.Left = left;
shape.Top = top;
if (!isHeightResized) {
shape.ScaleHeight(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromMiddle);
}
if (!isWidthResized) {
shape.ScaleWidth(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromMiddle);
}
shape.AlternativeText = title;
if (isLayoutPictureWithCaption && shapeForCaption != null) {
try {
@ -164,15 +164,22 @@ namespace Greenshot.Interop.Office {
}
}
public static void InsertIntoNewPresentation(string tmpFile, Size imageSize, string title) {
public static bool InsertIntoNewPresentation(string tmpFile, Size imageSize, string title) {
bool isPictureAdded = false;
using (IPowerpointApplication powerpointApplication = COMWrapper.GetOrCreateInstance<IPowerpointApplication>()) {
if (powerpointApplication != null) {
powerpointApplication.Visible = true;
IPresentation presentation = powerpointApplication.Presentations.Add(MsoTriState.msoTrue);
AddPictureToPresentation(presentation, tmpFile, imageSize, title);
presentation.Application.Activate();
try {
AddPictureToPresentation(presentation, tmpFile, imageSize, title);
isPictureAdded = true;
presentation.Application.Activate();
} catch (Exception e) {
LOG.Error(e);
}
}
}
return isPictureAdded;
}
}
}

View file

@ -119,8 +119,7 @@ namespace GreenshotOfficePlugin {
}
}
if (presentationName != null) {
PowerpointExporter.ExportToPresentation(presentationName, tmpFile, imageSize, captureDetails.Title);
exportInformation.ExportMade = true;
exportInformation.ExportMade = PowerpointExporter.ExportToPresentation(presentationName, tmpFile, imageSize, captureDetails.Title);
} else {
if (!manuallyInitiated) {
List<string> presentations = PowerpointExporter.GetPowerpointPresentations();
@ -134,8 +133,7 @@ namespace GreenshotOfficePlugin {
return ShowPickerMenu(false, surface, captureDetails, destinations);
}
} else if (!exportInformation.ExportMade) {
PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title);
exportInformation.ExportMade = true;
exportInformation.ExportMade = PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title);
}
}
ProcessExport(exportInformation, surface);