gfx

package
v0.1.0-experimental.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package gfx implements a backend for graphics. The backend connects to various drawing engines (e.g., raster, SVG, PDF, ...). I have migrated to the Canvas-projekt (https://github.com/tdewolff/canvas) for the backend. It is a Cairo-style library and is becoming more complete by the minute.

That said, I am not convinced every use case of TySE will require (or justify to include) a large library like Surface. I therefore try do de-couple it (at compile time) for less sophisticated use cases. I will retain interoperatibility to Surface, however, to allow users mix in Surface code for more demanding pieces of art.

We abstract the details away with an interface 'Surface' (used to be named 'Canvas', but I dropped the name to avoid confusion) which represents a rectangular drawing area. The main operation on a Surface is AddContour, the drawing and/or filling of a path.

Clients often won't use Surface directly, but rather an enclosing struct type Picture, which holds a Surface plus some administrative information.

BSD License

Copyright (c) 2017-21, Norbert Pillmayer <norbert@pillmayer.com>

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of Norbert Pillmayer nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const PENCIRCLE int = 1

PENCIRCLE is a pen with a round nib

View Source
const PENSQUARE int = 2

PENSQUARE is a pen with a square nib

Variables

This section is empty.

Functions

func G

func G() tracing.Trace

G traces to the graphics tracer.

Types

type DrawableContour

type DrawableContour interface {
	IsCycle() bool
	Start() arithm.Pair
	ToNextKnot() (k arithm.Pair, c1 arithm.Pair, c2 arithm.Pair)
}

DrawableContour is an interface for a stroke. The central operation on Surfacees is AddContour, the drawing and/or filling of a path. Different clients may have a different understanding of what a path is and how to store it. Interface DrawableContour tries to be a common denomiator for drawing operations on paths.

The 3 parameters for ToNextKnot() are the target point, together with 2 optional control points for spline curves (quadratic or cubic).

type OutputRoutine

type OutputRoutine interface {
	Shipout(pic *Picture, gfxFormat string) bool
}

OutputRoutine is an interface for output routines to ship out completed images.

func NewDebuggingOutputRoutine

func NewDebuggingOutputRoutine(level tracing.TraceLevel) OutputRoutine

NewDebuggingOutputRoutine returns an output routine suited for debugging and testing.

Its Shipout method prints a debug representation of a picture to the terminal.

Attention: not yet implemented (TODO) !

type Pen

type Pen struct {
	// contains filtered or unexported fields
}

Pen is a drawing pen.

func NewPencircle

func NewPencircle(diam float64) *Pen

NewPencircle creates a new round pen.

func NewPensquare

func NewPensquare(diam float64) *Pen

NewPensquare create a new square pen.

type Picture

type Picture struct {
	Name string
	// contains filtered or unexported fields
}

Picture is the type for the backend to work with.

func NewPicture

func NewPicture(name string, surface Surface) *Picture

NewPicture creates a new Picture. Caller has to provide an identifier and a Surface.

func (*Picture) Draw

func (pic *Picture) Draw(contour DrawableContour)

Draw a line. Uses the current pen.

func (*Picture) Fill

func (pic *Picture) Fill(contour DrawableContour)

Fill a closed path. Uses the current pen.

func (*Picture) FillDraw

func (pic *Picture) FillDraw(contour DrawableContour)

FillDraw is MetaPost's filldraw command. Uses the current pen and color.

func (*Picture) SetColor

func (pic *Picture) SetColor(color color.Color)

SetColor sets the current color. Will be used for subsequent drawing operations.

func (*Picture) SetOutputRoutine

func (pic *Picture) SetOutputRoutine(o OutputRoutine)

SetOutputRoutine sets an output routine. Will be used for subsequent output of completed images.

func (*Picture) SetPen

func (pic *Picture) SetPen(pen *Pen)

SetPen sets the current pen. Will be used for subsequent drawing operations.

func (*Picture) Shipout

func (pic *Picture) Shipout(gfxType string)

Shipout returns a completed picture.

type Surface

type Surface interface {
	W() float64                                                    // width
	H() float64                                                    // height
	AddContour(DrawableContour, float64, color.Color, color.Color) // filldraw with pen with colors
	SetOption(int)                                                 // set a drawing option
}

Surface is an interface type for a drawing surface.

func NewDebuggingSurface

func NewDebuggingSurface() Surface

NewDebuggingSurface creates and returns a pseudo-Surface usable for tests and debugging.

Directories

Path Synopsis
Package canvasadapter implements a bridge to the the Canvas graphics library.
Package canvasadapter implements a bridge to the the Canvas graphics library.
Package hobbyadapter implements a bridge to splines according to J.Hobby.
Package hobbyadapter implements a bridge to splines according to J.Hobby.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL