 #endif
 import Foundation
 
+/// The `DrawingContext` class represents a PDF drawing destination.
+///
+/// You cannot initialize the context directly. You need to call the `PDFPage.draw(_:)` method; an instance
+/// of `DrawingContext` will be passed to the provided closure. That instance is only valid during the lifetime
+/// of that closure.
+///
+/// Each instance of `DrawingContext` is bound to some `PDFPage`, hence you can use it to perform
+/// drawing operations on only one page.
 public final class DrawingContext {
     
-    private weak var _document: PDFDocument?
+    private unowned var _document: PDFDocument
     private var __page: HPDF_Page
     private var _documentHandle: HPDF_Doc
     private var _isInvalidated = false

        set {
            guard let font = HPDF_GetFont(_documentHandle, newValue.name, encoding.name) else {
                
                switch _document?._error {
                case .some(PDFError.invalidFontName):
                    preconditionFailure("Font \(newValue) must be loaded in the document using " +
                        "loadTrueTypeFont(from:embeddingGlyphData:) or " +
                        "loadTrueTypeFontFromCollection(from:index:embeddingGlyphData:) methods.")
                case .some(let error):
                    preconditionFailure(error.description)
                default:
                    return
                }
            }
            

        
        _document = page.document
        
        _documentHandle = _document._documentHandle
    }
    
    internal func _cleanup() {
