public void TestCopyTable() { Shape table = GetShape(TablePlaceholderSlide, Table); Shape copy = ShapeUtil.CopyMsoPlaceHolder(new Format[0], table, _templateShapes); Assert.AreEqual(copy, null); }
/// <summary> /// Saves shape in storage /// Returns a key to find the shape by, /// or null if the shape cannot be copied /// </summary> /// <param name="shape"></param> /// <param name="formats">Required for msoPlaceholder</param> /// <returns>identifier of copied shape</returns> public string CopyShape(Shape shape, Format[] formats) { Shape copiedShape = null; if (shape.Type == MsoShapeType.msoPlaceholder) { copiedShape = ShapeUtil.CopyMsoPlaceHolder(formats, shape, GetTemplateShapes()); } else { try { shape.Copy(); copiedShape = Slides[0].Shapes.Paste()[1]; } catch { copiedShape = null; } } if (copiedShape == null) { return(null); } string shapeKey = nextKey.ToString(); nextKey++; copiedShape.Name = shapeKey; ForceSave(); return(shapeKey); }
public void TestCopyChart() { Shape chart = GetShape(ChartPlaceholderSlide, Chart); Shape copy = ShapeUtil.CopyMsoPlaceHolder(new Format[0], chart, _templateShapes); Assert.AreEqual(copy, null); }
public void TestCopyPicture() { Shape picture = GetShape(PicturePlaceholderSlide, Picture); Shape copy = ShapeUtil.CopyMsoPlaceHolder(new Format[0], picture, _templateShapes); Assert.AreEqual(copy, null); }
/// <summary> /// Saves shape in storage /// Returns a key to find the shape by, /// or null if the shape cannot be copied /// </summary> /// <param name="shape"></param> /// <param name="formats">Required for msoPlaceholder</param> /// <returns>identifier of copied shape</returns> public string CopyShape(Shape shape, Format[] formats) { #pragma warning disable 618 PowerPointPresentation pres = PowerPointPresentation.Current; PowerPointSlide slide = PowerPointCurrentPresentationInfo.CurrentSlide; Shape copiedShape = null; if (shape.Type == MsoShapeType.msoPlaceholder) { ClipboardUtil.RestoreClipboardAfterAction(() => { copiedShape = ShapeUtil.CopyMsoPlaceHolder(formats, shape, GetTemplateShapes()); return(ClipboardUtil.ClipboardRestoreSuccess); }, pres, slide); } else { try { ClipboardUtil.RestoreClipboardAfterAction(() => { copiedShape = Slides[0].Shapes.SafeCopyPlaceholder(shape); return(ClipboardUtil.ClipboardRestoreSuccess); }, pres, slide); } catch { copiedShape = null; } } #pragma warning restore 618 if (copiedShape == null) { return(null); } string shapeKey = nextKey.ToString(); nextKey++; copiedShape.Name = shapeKey; #pragma warning disable 618 if (Globals.ThisAddIn.IsApplicationVersion2013()) { // sync glow, 2013 gives the wrong Glow.Fill color after copying the shape SyncFormats(shape, copiedShape, _glowFormats); // sync shape fill, 2013 gives the wrong fill color after copying the shape SyncFormats(shape, copiedShape, _fillFormats); // backup artistic effects for 2013 // ForceSave() will make artistic effect permanent on the shapes for 2013 and no longer retrievable List <MsoPictureEffectType> extractedEffects = ArtisticEffectFormat.GetArtisticEffects(copiedShape); _backupArtisticEffects.Add(shapeKey, extractedEffects); } #pragma warning restore 618 ForceSave(); return(shapeKey); }
private void EnsureFormatsAreRetainedAfterCopy(Shape placeHolder) { // ensure that each placeholder's copy supports the same or more formats Format[] formatsFromOriginal = ShapeUtil.GetCopyableFormats(placeHolder); Shape copy = ShapeUtil.CopyMsoPlaceHolder(formatsFromOriginal, placeHolder, _templateShapes); Format[] formatsFromCopy = ShapeUtil.GetCopyableFormats(copy); IEnumerable <Format> formatsInBoth = formatsFromCopy.Intersect(formatsFromOriginal); Assert.AreEqual(formatsInBoth.Count(), formatsFromOriginal.Count()); }
/// <summary> /// Saves shape in storage /// Returns a key to find the shape by, /// or null if the shape cannot be copied /// </summary> /// <param name="shape"></param> /// <param name="formats">Required for msoPlaceholder</param> /// <returns>identifier of copied shape</returns> public string CopyShape(Shape shape, Format[] formats) { Shape copiedShape = null; if (shape.Type == MsoShapeType.msoPlaceholder) { copiedShape = ShapeUtil.CopyMsoPlaceHolder(formats, shape, GetTemplateShapes()); } else { try { shape.Copy(); copiedShape = Slides[0].Shapes.Paste()[1]; } catch { copiedShape = null; } } if (copiedShape == null) { return(null); } string shapeKey = nextKey.ToString(); nextKey++; copiedShape.Name = shapeKey; #pragma warning disable 618 if (Globals.ThisAddIn.IsApplicationVersion2013()) { // sync glow, 2013 gives the wrong Glow.Fill color after copying the shape SyncFormats(shape, copiedShape, _glowFormats); // sync shape fill, 2013 gives the wrong fill color after copying the shape SyncFormats(shape, copiedShape, _fillFormats); // backup artistic effects for 2013 // ForceSave() will make artistic effect permanent on the shapes for 2013 and no longer retrievable List <MsoPictureEffectType> extractedEffects = ArtisticEffectFormat.GetArtisticEffects(copiedShape); _backupArtisticEffects.Add(shapeKey, extractedEffects); } #pragma warning restore 618 ForceSave(); return(shapeKey); }
// copies placeholder textboxes safely public static Shape SafeCopyPlaceholder(this Shapes shapes, Shape shape) { if (shape.Type != Microsoft.Office.Core.MsoShapeType.msoPlaceholder) { return(shapes.SafeCopy(shape)); } PowerPointLabs.SyncLab.ObjectFormats.Format[] formats = ShapeUtil.GetCopyableFormats(shape); Shape newShape = ShapeUtil.CopyMsoPlaceHolder(formats, shape, shapes); if (newShape == null) { throw new MsoPlaceholderException(shape.PlaceholderFormat.Type); } return(newShape); }
private void EnsureFormatsAreRetainedAfterCopy(Shape placeHolder) { // ensure that each placeholder's copy supports the same or more formats Format[] formatsFromOriginal = GetCopyableFormats(placeHolder); List <Type> typesFromOriginal = formatsFromOriginal.Select(format => format.FormatType).ToList(); Shape copy = ShapeUtil.CopyMsoPlaceHolder(formatsFromOriginal, placeHolder, _templateShapes); Format[] formatsFromCopy = GetCopyableFormats(copy); IEnumerable <Type> typesFromCopy = formatsFromCopy.Select(format => format.FormatType); IEnumerable <Type> typesInBoth = typesFromCopy.Intersect(typesFromOriginal); Assert.AreEqual(typesInBoth.Count(), typesFromOriginal.Count); }