Powerpoint center, only works correctly with screenshots < shape size...

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1755 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-04-04 18:46:56 +00:00
commit 0827fd0913
2 changed files with 51 additions and 18 deletions

View file

@ -101,36 +101,60 @@ namespace Greenshot.Interop.Office {
if (presentation != null) { if (presentation != null) {
//ISlide slide = presentation.Slides.AddSlide( presentation.Slides.Count + 1, PPSlideLayout.ppLayoutPictureWithCaption); //ISlide slide = presentation.Slides.AddSlide( presentation.Slides.Count + 1, PPSlideLayout.ppLayoutPictureWithCaption);
ISlide slide; ISlide slide;
float left = 0; float left = (presentation.PageSetup.SlideWidth / 2) - (imageSize.Width / 2) ;
float top = 0; float top = (presentation.PageSetup.SlideHeight / 2) - (imageSize.Height / 2);
float width = imageSize.Width;
float height = imageSize.Height;
bool isLayoutPictureWithCaption = false; bool isLayoutPictureWithCaption = false;
IShape shapeForCaption = null;
bool isWidthResized = false;
bool isHeightResized = false;
try { try {
slide = presentation.Slides.Add(presentation.Slides.Count + 1, (int)PPSlideLayout.ppLayoutPictureWithCaption); slide = presentation.Slides.Add(presentation.Slides.Count + 1, (int)PPSlideLayout.ppLayoutPictureWithCaption);
isLayoutPictureWithCaption = true; isLayoutPictureWithCaption = true;
// Shapes[2] is the image shape on this layout. // Shapes[2] is the image shape on this layout.
shapeForCaption = slide.Shapes.item(1);
IShape shapeForLocation = slide.Shapes.item(2); IShape shapeForLocation = slide.Shapes.item(2);
shapeForLocation.Width = imageSize.Width; if (width > shapeForLocation.Width) {
shapeForLocation.Height = imageSize.Height; width = shapeForLocation.Width;
left = shapeForLocation.Left; isWidthResized = true;
top = shapeForLocation.Top; left = shapeForLocation.Left;
LOG.DebugFormat("Shape {0},{1},{2},{3}", shapeForLocation.Left, shapeForLocation.Top, imageSize.Width, imageSize.Height); } else {
//left = (shapeForLocation.Left + (shapeForLocation.Width / 2)) - (imageSize.Width / 2);
shapeForLocation.Width = width;
shapeForLocation.Left = left;
}
if (height > shapeForLocation.Height) {
height = shapeForLocation.Height;
isHeightResized = true;
top = shapeForLocation.Top;
} 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);
} catch (Exception e) { } catch (Exception e) {
LOG.Error(e); LOG.Error(e);
slide = presentation.Slides.Add(presentation.Slides.Count + 1, (int)PPSlideLayout.ppLayoutBlank); slide = presentation.Slides.Add(presentation.Slides.Count + 1, (int)PPSlideLayout.ppLayoutBlank);
} }
IShape shape = slide.Shapes.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, left, top, imageSize.Width, imageSize.Height); IShape shape = slide.Shapes.AddPicture(tmpFile, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, width, height);
shape.Width = imageSize.Width; shape.LockAspectRatio = MsoTriState.msoTrue;
shape.Height = imageSize.Height; shape.Left = left;
shape.ScaleWidth(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromMiddle); shape.Top = top;
shape.ScaleHeight(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromMiddle); if (!isHeightResized) {
if (isLayoutPictureWithCaption) { shape.ScaleHeight(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromMiddle);
}
if (!isWidthResized) {
shape.ScaleWidth(1, MsoTriState.msoTrue, MsoScaleFrom.msoScaleFromMiddle);
}
shape.AlternativeText = title;
if (isLayoutPictureWithCaption && shapeForCaption != null) {
try { try {
// Using try/catch to make sure problems with the text range don't give an exception. // Using try/catch to make sure problems with the text range don't give an exception.
ITextFrame textFrame = shape.TextFrame; ITextFrame textFrame = shapeForCaption.TextFrame;
if (textFrame.HasText == MsoTriState.msoTrue) { textFrame.TextRange.Text = title;
textFrame.TextRange.Text = title;
}
shape.AlternativeText = title;
} catch (Exception ex) { } catch (Exception ex) {
LOG.Warn("Problem setting the title to a text-range", ex); LOG.Warn("Problem setting the title to a text-range", ex);
} }

View file

@ -60,6 +60,7 @@ namespace Greenshot.Interop.Office {
IPowerpointApplication Application { get; } IPowerpointApplication Application { get; }
MsoTriState ReadOnly { get; } MsoTriState ReadOnly { get; }
bool Final { get; set; } bool Final { get; set; }
IPageSetup PageSetup { get; }
} }
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.presentations_members.aspx // See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.presentations_members.aspx
@ -68,11 +69,18 @@ namespace Greenshot.Interop.Office {
IPresentation item(int index); IPresentation item(int index);
} }
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.pagesetup_members.aspx
public interface IPageSetup : Common, Collection {
float SlideWidth { get; set; }
float SlideHeight { get; set; }
}
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.slide_members.aspx // See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.slide_members.aspx
public interface ISlide : Common { public interface ISlide : Common {
IShapes Shapes { get; } IShapes Shapes { get; }
void Select(); void Select();
int SlideNumber { get; } int SlideNumber { get; }
} }
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.shapes_members.aspx // See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.shapes_members.aspx
@ -92,6 +100,7 @@ namespace Greenshot.Interop.Office {
void ScaleWidth(float Factor, MsoTriState RelativeToOriginalSize, MsoScaleFrom fScale); void ScaleWidth(float Factor, MsoTriState RelativeToOriginalSize, MsoScaleFrom fScale);
void ScaleHeight(float Factor, MsoTriState RelativeToOriginalSize, MsoScaleFrom fScale); void ScaleHeight(float Factor, MsoTriState RelativeToOriginalSize, MsoScaleFrom fScale);
string AlternativeText { get; set; } string AlternativeText { get; set; }
MsoTriState LockAspectRatio { get; set; }
} }
public interface ITextFrame : Common { public interface ITextFrame : Common {