@@ -232,13 +232,6 @@ public static PresentationDocument Open(Package package)
232232 public static PresentationDocument Open ( string path , bool isEditable , OpenSettings openSettings )
233233 => CreateDefaultBuilder ( )
234234 . UseSettings ( openSettings )
235- . Use ( package =>
236- {
237- if ( openSettings . VerifyMinimumPackage )
238- {
239- package . ThrowIfNotMinimumPackage ( ) ;
240- }
241- } )
242235 . Build ( )
243236 . Open ( path , isEditable ) ;
244237
@@ -256,13 +249,6 @@ public static PresentationDocument Open(string path, bool isEditable, OpenSettin
256249 public static PresentationDocument Open ( Stream stream , bool isEditable , OpenSettings openSettings )
257250 => CreateDefaultBuilder ( )
258251 . UseSettings ( openSettings )
259- . Use ( package =>
260- {
261- if ( openSettings . VerifyMinimumPackage )
262- {
263- package . ThrowIfNotMinimumPackage ( ) ;
264- }
265- } )
266252 . Build ( )
267253 . Open ( stream , isEditable ) ;
268254
@@ -279,58 +265,9 @@ public static PresentationDocument Open(Stream stream, bool isEditable, OpenSett
279265 public static PresentationDocument Open ( Package package , OpenSettings openSettings )
280266 => CreateDefaultBuilder ( )
281267 . UseSettings ( openSettings )
282- . Use ( package =>
283- {
284- if ( openSettings . VerifyMinimumPackage )
285- {
286- package . ThrowIfNotMinimumPackage ( ) ;
287- }
288- } )
289268 . Build ( )
290269 . Open ( package ) ;
291270
292- /// <summary>
293- /// Validates that the current <see cref="PresentationDocument"/> meets the minimum requirements for a valid package.
294- /// </summary>
295- /// <exception cref="NotSupportedException">
296- /// Thrown if the <see cref="PresentationDocumentType"/> is <see cref="PresentationDocumentType.Slideshow"/>,
297- /// <see cref="PresentationDocumentType.MacroEnabledSlideshow"/>, or <see cref="PresentationDocumentType.AddIn"/>,
298- /// as validation for these types is not supported.
299- /// </exception>
300- /// <exception cref="FileFormatException">
301- /// Thrown if the <see cref="PresentationPart"/> does not contain valid <c>NotesSize</c> dimensions
302- /// or if the dimensions are outside the acceptable range for PowerPoint to open.
303- /// </exception>
304- /// <remarks>
305- /// This method ensures that the document conforms to the minimum requirements for PowerPoint to open it.
306- /// </remarks>
307- protected override void ThrowIfNotMinimumPackage ( )
308- {
309- if ( this . DocumentType == PresentationDocumentType . Slideshow )
310- {
311- throw new NotSupportedException ( "Minimum package verification for PresentationDocumentType.Slideshow (.ppsx) is not supported." ) ;
312- }
313-
314- if ( this . DocumentType == PresentationDocumentType . MacroEnabledSlideshow )
315- {
316- throw new NotSupportedException ( "Minimum package verification for PresentationDocumentType.MacroEnabledSlideshow (.ppsm) is not supported." ) ;
317- }
318-
319- if ( this . DocumentType == PresentationDocumentType . AddIn )
320- {
321- throw new NotSupportedException ( "Minimum package verification for PresentationDocumentType.AddIn (.ppam) is not supported." ) ;
322- }
323-
324- NotesSize ? notesSize = this . PresentationPart ? . Presentation ? . NotesSize ;
325-
326- if ( ! ( notesSize is not null && notesSize . Cx is not null && notesSize . Cx . HasValue &&
327- notesSize . Cx >= 0 && notesSize . Cx <= 27273042316900 && notesSize . Cy is not null &&
328- notesSize . Cy . HasValue && notesSize . Cy >= 0 && notesSize . Cy <= 27273042316900 ) )
329- {
330- throw new FileFormatException ( "The provided package does not conform to the minimum requirements for PowerPoint to open." ) ;
331- }
332- }
333-
334271 /// <summary>
335272 /// Changes the document type.
336273 /// </summary>
@@ -570,7 +507,8 @@ public LabelInfoPart? LabelInfoPart
570507 private partial class PresentationDocumentFeatures : TypedPackageFeatureCollection < PresentationDocumentType , PresentationPart > ,
571508 IApplicationTypeFeature ,
572509 IMainPartFeature ,
573- IProgrammaticIdentifierFeature
510+ IProgrammaticIdentifierFeature ,
511+ IMinimumDocumentFeature
574512 {
575513 public PresentationDocumentFeatures ( OpenXmlPackage package )
576514 : base ( package )
@@ -608,6 +546,25 @@ public PresentationDocumentFeatures(OpenXmlPackage package)
608546 "application/vnd.ms-powerpoint.addin.macroEnabled.main+xml" => PresentationDocumentType . AddIn ,
609547 _ => default ,
610548 } ;
549+
550+ bool IMinimumDocumentFeature . Validate ( )
551+ {
552+ if ( DocumentType is PresentationDocumentType . Slideshow or PresentationDocumentType . MacroEnabledSlideshow or PresentationDocumentType . AddIn )
553+ {
554+ return false ;
555+ }
556+
557+ NotesSize ? notesSize = MainPart ? . Presentation ? . NotesSize ;
558+
559+ if ( ! ( notesSize is not null && notesSize . Cx is not null && notesSize . Cx . HasValue &&
560+ notesSize . Cx >= 0 && notesSize . Cx <= 27273042316900 && notesSize . Cy is not null &&
561+ notesSize . Cy . HasValue && notesSize . Cy >= 0 && notesSize . Cy <= 27273042316900 ) )
562+ {
563+ return false ;
564+ }
565+
566+ return true ;
567+ }
611568 }
612569 }
613570}
0 commit comments