github.com/unidoc/unidoc@v2.2.0+incompatible/pdf/creator/drawable.go (about)

     1  /*
     2   * This file is subject to the terms and conditions defined in
     3   * file 'LICENSE.md', which is part of this source code package.
     4   */
     5  
     6  package creator
     7  
     8  // Drawable is a widget that can be used to draw with the Creator.
     9  type Drawable interface {
    10  	// Draw onto blocks representing Page contents. As the content can wrap over many pages, multiple
    11  	// templates are returned, one per Page.  The function also takes a draw context containing information
    12  	// where to draw (if relative positioning) and the available height to draw on accounting for Margins etc.
    13  	GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error)
    14  }
    15  
    16  // VectorDrawable is a Drawable with a specified width and height.
    17  type VectorDrawable interface {
    18  	Drawable
    19  
    20  	// Width returns the width of the Drawable.
    21  	Width() float64
    22  
    23  	// Height returns the height of the Drawable.
    24  	Height() float64
    25  }
    26  
    27  // DrawContext defines the drawing context. The DrawContext is continuously used and updated when drawing the page
    28  // contents in relative mode.  Keeps track of current X, Y position, available height as well as other page parameters
    29  // such as margins and dimensions.
    30  type DrawContext struct {
    31  	// Current page number.
    32  	Page int
    33  
    34  	// Current position.  In a relative positioning mode, a drawable will be placed at these coordinates.
    35  	X, Y float64
    36  
    37  	// Context dimensions.  Available width and height (on current page).
    38  	Width, Height float64
    39  
    40  	// Page Margins.
    41  	Margins margins
    42  
    43  	// Absolute Page size, widths and height.
    44  	PageWidth  float64
    45  	PageHeight float64
    46  
    47  	// Controls whether the components are stacked horizontally
    48  	Inline bool
    49  }