deck: github.com/ajstarks/deck Index | Files | Directories

package deck

import "github.com/ajstarks/deck"

Package deck makes slide decks

Package deck is a library for clients to make scalable presentations, using a standard markup language. Clients read deck files into the Deck structure, and traverse the structure for display, publication, etc. Clients may be interactive or produce standard formats such as SVG or PDF. Decks may also be served via a RESTful web API

Elements

Here are the elements of a deck:

deck: enclosing element
canvas: describe the dimensions of the drawing canvas, one per deck
metadata elements: title, creator, date, publisher, subject, description
slide: within a deck, any number of slides, specify the slide duration, gradient colors, background and text colors.

within slides an number of:

text: plain, textblock, or code
list: plain, bullet, number
image: JPEG or PNG images
line: straight line
rect: rectangle
ellipse: ellipse
curve: Quadratic Bezier curve
arc: elliptical arc
polygon: polygon

Markup

Here is a sample deck in XML:

<deck>
  <canvas width="1024" height="768" />
  <slide duration="2s" bg="white" fg="black">
      <image xp="50" yp="60" width="256" height="179" name="work.png" caption="my desk"/>
      <text  xp="20" yp="80" sp="4">Deck uses these elements</text>
      <list  xp="20" yp="70" sp="2" type="bullet">
         <li>text</li>
         <li>list</li>
         <li>image</li>
         <li>line</li>
         <li color="rgb(127,0,0)">rect</li>
         <li color="rgb(0,127,0)">ellipse</li>
         <li color="rgb(0,0,127)">arc</li>
         <li color="rgb(127,127,127)">curve</li>
         <li color="rgb(0,0,127)">polygon</li>
      </list>
      <line    xp1="20" yp1="10" xp2="30" yp2="10"/>
      <rect    xp="35"  yp="10" wp="4" hp="3" color="rgb(127,0,0)"/>
      <ellipse xp="45"  yp="10" wp="4" hp="3" color="rgb(0,127,0)"/>
      <arc     xp="55"  yp="10" wp="4" hp="3" a1="0" a2="180" color="rgb(0,0,127)"/>
      <curve   xp1="60" yp1="10" xp2="75" yp2="20" xp3="70" yp3="10" />
      <polygon xc="75 75 80" yc="8 12 10" color="rgb(0,0,127)"/>
  </slide>
</deck>

The list, text, rect, and ellipse elements have common attributes:

xp: horizontal percentage
yp: vertical percentage
sp: font size percentage
lp: line spacing percentage
type: "bullet", "number" (list), "block", "code" (text)
align: "left", "middle", "end"
opacity: 0.0-1.0 (fully transparent - opaque)
color: SVG names ("maroon"), or RGB "rgb(127,0,0)"
font: "sans", "serif", "mono", "symbol"
link: url

Layout

All layout in done in terms of percentages, using a coordinate system with the origin (0%, 0%) at the lower left. The x (horizontal) direction increases to the right, and the y (vertical) direction increasing to upwards. For example to place an element in the middle of the canvas, specify xp="50" yp="50". To place an element one-third from the top, and one-third from the bottom: xp="66.6" yp="33.3".

The size of text is also scaled to the width of the canvas. For example sp="3" is a typical size for slide headings. The sizes of graphical elements (width, height, stroke width) are also scaled to the canvas width.

The content of the slides are automatically scaled based on the specified canvas size (sane defaults are should be set by clients, if dimensions are not specified).

Example

package main

import (
	"fmt"
	"log"

	"github.com/ajstarks/deck"
)

func dotext(x, y, size float64, text deck.Text) {
	fmt.Println("\tText:", x, y, size, text.Tdata)
}

func dolist(x, y, size float64, list deck.List) {
	fmt.Println("\tList:", x, y, size)
	for i, l := range list.Li {
		fmt.Println("\t\titem", i, l)
	}
}
func main() {
	presentation, err := deck.Read("deck.xml", 1024, 768) // open the deck
	if err != nil {
		log.Fatal(err)
	}
	for slidenumber, slide := range presentation.Slide { // for every slide...
		fmt.Println("Processing slide", slidenumber)
		for _, t := range slide.Text { // process the text elements
			x, y, size := deck.Dimen(presentation.Canvas, t.Xp, t.Yp, t.Sp)
			dotext(x, y, size, t)
		}
		for _, l := range slide.List { // process the list elements
			x, y, size := deck.Dimen(presentation.Canvas, l.Xp, l.Yp, l.Sp)
			dolist(x, y, size, l)
		}
	}
}

Index

Package Files

deck.go doc.go

func Dimen Uses

func Dimen(c canvas, xp, yp, sp float64) (x, y, s float64)

Dimen computes the coordinates and size of an object

func Dump Uses

func Dump(d Deck)

Dump shows the decoded description

func Pwidth Uses

func Pwidth(wp, cw, defval float64) float64

Pwidth computes the percent width based on canvas size

func Search(d Deck, s string) int

Search searches the deck for the specified text, returning the slide number if found

type Arc Uses

type Arc struct {
    Dimension
    A1      float64 `xml:"a1,attr"`
    A2      float64 `xml:"a2,attr"`
    Opacity float64 `xml:"opacity,attr"`
}

Arc defines an elliptical arc the arc is defined by a beginning and ending angle in percentages <arc xp="55" yp="10" wp="4" hr="75" a1="0" a2="180"/>

type CommonAttr Uses

type CommonAttr struct {
    Xp      float64 `xml:"xp,attr"`      // X coordinate
    Yp      float64 `xml:"yp,attr"`      // Y coordinate
    Sp      float64 `xml:"sp,attr"`      // size
    Lp      float64 `xml:"lp,attr"`      // linespacing (leading) percentage
    Type    string  `xml:"type,attr"`    // type: block, plain, code, number, bullet
    Align   string  `xml:"align,attr"`   // alignment: center, end, begin
    Color   string  `xml:"color,attr"`   // item color
    Opacity float64 `xml:"opacity,attr"` // opacity percentage
    Font    string  `xml:"font,attr"`    // font type: i.e. sans, serif, mono
    Link    string  `xml:"link,attr"`    // reference to other content (i.e. http:// or mailto:)
}

CommonAttr are the common attributes for text and list

type Curve Uses

type Curve struct {
    Xp1     float64 `xml:"xp1,attr"`
    Yp1     float64 `xml:"yp1,attr"`
    Xp2     float64 `xml:"xp2,attr"`
    Yp2     float64 `xml:"yp2,attr"`
    Xp3     float64 `xml:"xp3,attr"`
    Yp3     float64 `xml:"yp3,attr"`
    Sp      float64 `xml:"sp,attr"`
    Color   string  `xml:"color,attr"`
    Opacity float64 `xml:"opacity,attr"`
}

Curve defines a quadratic Bezier curve The begining, ending, and control points are required: <curve xp1="60" yp1="10" xp2="75" yp2="20" xp3="70" yp3="10" />

type Deck Uses

type Deck struct {
    Title       string  `xml:"title"`
    Creator     string  `xml:"creator"`
    Subject     string  `xml:"subject"`
    Publisher   string  `xml:"publisher"`
    Description string  `xml:"description"`
    Date        string  `xml:"date"`
    Canvas      canvas  `xml:"canvas"`
    Slide       []Slide `xml:"slide"`
}

Deck defines the structure of a presentation deck The size of the canvas, and series of slides

func Read Uses

func Read(filename string, w, h int) (Deck, error)

Read reads the deck description file

func ReadDeck Uses

func ReadDeck(r io.ReadCloser, w, h int) (Deck, error)

ReadDeck reads the deck description file from a io.Reader

type Dimension Uses

type Dimension struct {
    CommonAttr
    Wp  float64 `xml:"wp,attr"` // width percentage
    Hp  float64 `xml:"hp,attr"` // height percentage
    Hr  float64 `xml:"hr,attr"` // height relative percentage
    Hw  float64 `xml:"hw,attr"` // height by width
}

Dimension describes a graphics object with width and height

type Ellipse Uses

type Ellipse struct {
    Dimension
}

Ellipse describes a rectangle with x,y,w,h <ellipse xp="45" yp="10" wp="4" hr="75" color="rgb(0,127,0)"/>

type Image Uses

type Image struct {
    CommonAttr
    Width     int     `xml:"width,attr"`     // image width
    Height    int     `xml:"height,attr"`    // image height
    Scale     float64 `xml:"scale,attr"`     // image scale percentage
    Autoscale string  `xml:"autoscale,attr"` // scale the image to the canvas
    Name      string  `xml:"name,attr"`      // image file name
    Caption   string  `xml:"caption,attr"`   // image caption
}

Image describes an image <image xp="20" yp="30" width="256" height="256" scale="50" name="picture.png" caption="Pretty picture"/>

type Line Uses

type Line struct {
    Xp1     float64 `xml:"xp1,attr"`     // begin x coordinate
    Yp1     float64 `xml:"yp1,attr"`     // begin y coordinate
    Xp2     float64 `xml:"xp2,attr"`     // end x coordinate
    Yp2     float64 `xml:"yp2,attr"`     // end y coordinate
    Sp      float64 `xml:"sp,attr"`      // line thickness
    Color   string  `xml:"color,attr"`   // line color
    Opacity float64 `xml:"opacity,attr"` // line opacity (1-100)
}

Line defines a straight line <line xp1="20" yp1="10" xp2="30" yp2="10"/>

type List Uses

type List struct {
    CommonAttr
    Wp  float64    `xml:"wp,attr"`
    Li  []ListItem `xml:"li"`
}

List describes the list element

type ListItem Uses

type ListItem struct {
    Color    string  `xml:"color,attr"`
    Opacity  float64 `xml:"opacity,attr"`
    Font     string  `xml:"font,attr"`
    ListText string  `xml:",chardata"`
}

ListItem describes a list item <list xp="20" yp="70" sp="1.5">

<li>canvas<li>
<li>slide</li>

</list>

type Polygon Uses

type Polygon struct {
    XC      string  `xml:"xc,attr"`
    YC      string  `xml:"yc,attr"`
    Color   string  `xml:"color,attr"`
    Opacity float64 `xml:"opacity,attr"`
}

Polygon defines a polygon, x and y coordinates are specified by strings of space-separated percentages: <polygon xc="10 20 30" yc="30 40 50"/>

type Rect Uses

type Rect struct {
    Dimension
}

Rect describes a rectangle with x,y,w,h <rect xp="35" yp="10" wp="4" hp="3"/>

type Slide Uses

type Slide struct {
    Bg          string    `xml:"bg,attr"`
    Fg          string    `xml:"fg,attr"`
    Gradcolor1  string    `xml:"gradcolor1,attr"`
    Gradcolor2  string    `xml:"gradcolor2,attr"`
    GradPercent float64   `xml:"gp,attr"`
    Duration    string    `xml:"duration,attr"`
    Note        string    `xml:"note"`
    List        []List    `xml:"list"`
    Text        []Text    `xml:"text"`
    Image       []Image   `xml:"image"`
    Ellipse     []Ellipse `xml:"ellipse"`
    Line        []Line    `xml:"line"`
    Rect        []Rect    `xml:"rect"`
    Curve       []Curve   `xml:"curve"`
    Arc         []Arc     `xml:"arc"`
    Polygon     []Polygon `xml:"polygon"`
}

Slide is the structure of an individual slide within a deck <slide bg="black" fg="rgb(255,255,255)" duration="2s" note="hello, world"> <slide gradcolor1="black" gradcolor2="white" gp="20" duration="2s" note="wassup">

type Text Uses

type Text struct {
    CommonAttr
    Wp    float64 `xml:"wp,attr"`
    File  string  `xml:"file,attr"`
    Tdata string  `xml:",chardata"`
}

Text describes the text element

Directories

PathSynopsis
cmd/codepicdeckcodepicdeck: make code+pic slide decks
cmd/codepicdeck/code
cmd/deckdeck -- command line access to the deck web API
cmd/keyframekeyframe: take a snapshot (as a raw raster) of th specified slide
cmd/mkblurbmkblurb: make a text blurb slide for the deck package
cmd/pdfdeckpdfdeck is a program for making PDF slides using the deck package.
cmd/sexsex is a server program that provides an API for slide decks.
cmd/svgdecksvgdeck is a program for making SVG slides using the deck package.
cmd/testdecktestdeck: dump a slide deck
cmd/testgen
cmd/vgdeckvgdeck is a program for showing presentations on the Raspberry Pi, using the deck and openvg libraries.
generatePackage generate provides a high-level API for the creation of slide decks using the structures of the deck package (github.com/ajstarks/deck).

Package deck imports 5 packages (graph) and is imported by 8 packages. Updated 2016-11-22. Refresh now. Tools for package owners.