Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions src/CoreGraphics/CGContextPDF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,123 @@ public void SetPageTagStructureTree (NSDictionary pageTagStructureTreeDictionary
GC.KeepAlive (pageTagStructureTreeDictionary);
}

#if !__TVOS__
[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPDFContextBeginMarkedContentSequence (IntPtr context, CGPdfTagType tagType);

/// <summary>Begins a structural marked-content sequence.</summary>
/// <param name="tagType">The structure tag for the marked content.</param>
/// <returns>The marked-content item to add to a structure element, or <see langword="null" /> if another structural sequence is already open.</returns>
/// <remarks>Use a structural tag such as <see cref="CGPdfTagType.Paragraph" /> or <see cref="CGPdfTagType.Span" />, and balance each successful call with <see cref="EndMarkedContentSequence" />. <see cref="CGPdfTagType.Artifact" /> is not valid for structural marked content.</remarks>
[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
public CGPDFMarkedContentItem? BeginMarkedContentSequence (CGPdfTagType tagType)
{
var handle = CGPDFContextBeginMarkedContentSequence (GetCheckedHandle (), tagType);
return handle == IntPtr.Zero ? null : new CGPDFMarkedContentItem (handle, owns: true);
}

[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.CoreGraphicsLibrary)]
static extern void CGPDFContextBeginNonStructuralMarkedContentSequence (IntPtr context, CGPdfTagType tagType);

/// <summary>Begins a marked-content sequence that is excluded from the document's logical structure.</summary>
/// <param name="tagType">The non-structural tag for the marked content.</param>
/// <remarks>Use <see cref="CGPdfTagType.Artifact" /> for non-structural content and balance this call with <see cref="EndMarkedContentSequence" />. <see cref="CGPdfTagType.NonStructure" /> is a structural grouping tag and is not valid here.</remarks>
[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
public void BeginNonStructuralMarkedContentSequence (CGPdfTagType tagType)
{
CGPDFContextBeginNonStructuralMarkedContentSequence (GetCheckedHandle (), tagType);
}

[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.CoreGraphicsLibrary)]
static extern void CGPDFContextEndMarkedContentSequence (IntPtr context);

/// <summary>Ends the current structural or non-structural marked-content sequence.</summary>
[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
public void EndMarkedContentSequence ()
{
CGPDFContextEndMarkedContentSequence (GetCheckedHandle ());
}

[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPDFContextBeginObjectReference (IntPtr context);

/// <summary>Begins a reference to a single object drawn into the PDF context.</summary>
/// <returns>The marked-content item to add to a structure element, or <see langword="null" /> if the reference could not be created.</returns>
/// <remarks>Draw exactly one object before calling <see cref="EndObjectReference" />.</remarks>
[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
public CGPDFMarkedContentItem? BeginObjectReference ()
{
var handle = CGPDFContextBeginObjectReference (GetCheckedHandle ());
return handle == IntPtr.Zero ? null : new CGPDFMarkedContentItem (handle, owns: true);
}

[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.CoreGraphicsLibrary)]
static extern void CGPDFContextEndObjectReference (IntPtr context);

/// <summary>Ends the current object reference.</summary>
[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
public void EndObjectReference ()
{
CGPDFContextEndObjectReference (GetCheckedHandle ());
}

[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.CoreGraphicsLibrary)]
static extern OSStatus CGPDFContextAddStructureTreeRootChild (IntPtr context, IntPtr structureElement);

/// <summary>Adds a structure element as a child of the PDF document's structure-tree root.</summary>
/// <param name="structureElement">The structure element to add.</param>
/// <returns>An <c>OSStatus</c> value, where zero indicates success.</returns>
[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
public OSStatus AddStructureTreeRootChild (CGPDFStructureElement structureElement)
{
var status = CGPDFContextAddStructureTreeRootChild (GetCheckedHandle (), structureElement.GetNonNullHandle (nameof (structureElement)));
GC.KeepAlive (structureElement);
return status;
}
#endif // !__TVOS__

/// <inheritdoc />
protected override void Dispose (bool disposing)
{
Expand Down
3 changes: 3 additions & 0 deletions src/CoreGraphics/CGEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ public enum CGPdfTagType /* int32_t */ {
Form,
[TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
Object = 800,
/// <summary>A non-structural tag for content that should be excluded from the document's logical structure.</summary>
[NoTV, Mac (27, 0), iOS (27, 0), MacCatalyst (27, 0)]
Artifact = 900,
}

// untyped enum -> CGPDFObject.h
Expand Down
58 changes: 58 additions & 0 deletions src/CoreGraphics/CGPDFMarkedContentItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#nullable enable

#if !__TVOS__

using System.Diagnostics.CodeAnalysis;
using CoreFoundation;

namespace CoreGraphics {

/// <summary>Represents the association between drawn PDF content and its place in a PDF structure tree.</summary>
[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
public class CGPDFMarkedContentItem : NativeObject {

[DynamicDependency (DynamicallyAccessedMemberTypes.NonPublicConstructors, typeof (CGPDFMarkedContentItem))]
static CGPDFMarkedContentItem ()
{
}

internal CGPDFMarkedContentItem (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.CoreGraphicsLibrary)]
static extern IntPtr CGPDFMarkedContentItemRetain (IntPtr markedContentItem);

[SupportedOSPlatform ("ios27.0")]
[SupportedOSPlatform ("maccatalyst27.0")]
[SupportedOSPlatform ("macos27.0")]
[UnsupportedOSPlatform ("tvos")]
[DllImport (Constants.CoreGraphicsLibrary)]
static extern void CGPDFMarkedContentItemRelease (IntPtr markedContentItem);

/// <inheritdoc />
protected internal override void Retain ()
{
CGPDFMarkedContentItemRetain (GetCheckedHandle ());
}

/// <inheritdoc />
protected internal override void Release ()
{
CGPDFMarkedContentItemRelease (GetCheckedHandle ());
}
}
}

#endif // !__TVOS__
Loading
Loading