color

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: GPL-3.0 Imports: 4 Imported by: 1

Documentation

Overview

Package color implements the PDF color spaces and colors.

Index

Constants

This section is empty.

Variables

View Source
var (
	// WhitePointD65 represents the D65 whitepoint.
	// The given values are CIE 1931 XYZ coordinates.
	//
	// https://en.wikipedia.org/wiki/Illuminant_D65
	WhitePointD65 = []float64{0.95047, 1.0, 1.08883}

	// WhitePointD50 represents the D50 whitepoint.
	// The given values are CIE 1931 XYZ coordinates.
	//
	// https://en.wikipedia.org/wiki/Standard_illuminant#Illuminant_series_D
	WhitePointD50 = []float64{0.964212, 1.0, 0.8251883}
)
View Source
var (
	// DeviceGray is the DeviceGray color space.
	DeviceGray = SpaceDeviceGray{}

	// DeviceRGB is the DeviceRGB color space.
	DeviceRGB = SpaceDeviceRGB{}

	// DeviceCMYK is the DeviceCMYK color space.
	DeviceCMYK = SpaceDeviceCMYK{}
)

Functions

func CheckCurrent

func CheckCurrent(cur, new Color) (needsColorSpace bool, needsColor bool)

CheckCurrent checks whether the changing from the current color to the new color requires a color space change and/or a color change.

func CheckVersion

func CheckVersion(cs Space, v pdf.Version) error

CheckVersion checks whether the given color space can be used in the given PDF version.

func IsIndexed added in v0.4.2

func IsIndexed(s Space) bool

IsIndexed returns whether the given color space is an indexed color space.

func IsPattern added in v0.4.2

func IsPattern(s Space) bool

IsPattern returns whether the given color space is a pattern color space.

func NumValues added in v0.4.2

func NumValues(s Space) int

NumValues returns the number of color values for the given color space.

func Operator

func Operator(c Color) ([]float64, pdf.Resource, string)

Operator returns the color values, the pattern resource, and the operator name for the given color. The operator name is for stroking operations. The corresponding operator for filling operations is the operator name converted to lower case.

Types

type Color

type Color interface {
	ColorSpace() Space
	// contains filtered or unexported methods
}

Color represents a PDF color.

type PatternColored added in v0.4.2

type PatternColored struct {
	pdf.Res
}

PatternColored represents a colored tiling pattern or a shading pattern.

In case of a colored tiling pattern, `Res.Data“ must be a PDF stream defining a pattern with PatternType 1 and PaintType 1. In case of a shading pattern, `Res.Data“ must be a PDF pattern dictionary with PatternType 2.

func (PatternColored) ColorSpace added in v0.4.2

func (c PatternColored) ColorSpace() Space

ColorSpace implements the Color interface.

type Space

type Space interface {
	pdf.Resource

	ColorSpaceFamily() string
	// contains filtered or unexported methods
}

Space represents a PDF color space.

type SpaceCalGray

type SpaceCalGray struct {
	pdf.Res
	// contains filtered or unexported fields
}

SpaceCalGray represents a CalGray color space.

func CalGray

func CalGray(whitePoint, blackPoint []float64, gamma float64, defName pdf.Name) (*SpaceCalGray, error)

CalGray returns a new CalGray color space.

WhitePoint is the diffuse white point in CIE 1931 XYZ coordinates. This must be a slice of length 3, with positive entries, and Y=1.

BlackPoint (optional) is the diffuse black point in the CIE 1931 XYZ coordinates. If non-nil, this must be a slice of three non-negative numbers. The default is [0 0 0].

The gamma parameter is a positive number (usually greater than or equal to 1).

DefName is the default resource name to use within content streams. This can be left empty to allocate names automatically.

func (*SpaceCalGray) ColorSpaceFamily

func (s *SpaceCalGray) ColorSpaceFamily() string

ColorSpaceFamily implements the [ColorSpace] interface.

func (*SpaceCalGray) Embed

func (s *SpaceCalGray) Embed(out *pdf.Writer) (*SpaceCalGray, error)

Embed embeds the color space in the PDF file. This saves space in case the color space is used in multiple content streams.

func (*SpaceCalGray) New

func (s *SpaceCalGray) New(gray float64) Color

New returns a new CalGray color.

type SpaceCalRGB

type SpaceCalRGB struct {
	pdf.Res
	// contains filtered or unexported fields
}

SpaceCalRGB represents a CalRGB color space.

func CalRGB

func CalRGB(whitePoint, blackPoint, gamma, matrix []float64, defName pdf.Name) (*SpaceCalRGB, error)

CalRGB returns a new CalRGB color space.

WhitePoint is the diffuse white point in CIE 1931 XYZ coordinates. This must be a slice of length 3, with positive entries, and Y=1.

BlackPoint (optional) is the diffuse black point in the CIE 1931 XYZ coordinates. If non-nil, this must be a slice of three non-negative numbers. The default is [0 0 0].

Gamma (optional) gives the gamma values for the red, green and blue components. If non-nil, this must be a slice of three numbers. The default is [1 1 1].

Matrix (optional) is a 3x3 matrix. The default is [1 0 0 0 1 0 0 0 1].

DefName is the default resource name to use within content streams. This can be left empty to allocate names automatically.

func (*SpaceCalRGB) ColorSpaceFamily

func (s *SpaceCalRGB) ColorSpaceFamily() string

ColorSpaceFamily implements the [ColorSpace] interface.

func (*SpaceCalRGB) Embed

func (s *SpaceCalRGB) Embed(out *pdf.Writer) (*SpaceCalRGB, error)

Embed embeds the color space in the PDF file. This saves space in case the color space is used in multiple content streams.

func (*SpaceCalRGB) New

func (s *SpaceCalRGB) New(r, g, b float64) Color

New returns a new CalRGB color.

type SpaceDeviceCMYK

type SpaceDeviceCMYK struct{}

SpaceDeviceCMYK represents the DeviceCMYK color space. Use DeviceCMYK to access this color space.

func (SpaceDeviceCMYK) ColorSpaceFamily

func (s SpaceDeviceCMYK) ColorSpaceFamily() string

ColorSpaceFamily implements the [ColorSpace] interface.

func (SpaceDeviceCMYK) DefaultName

func (s SpaceDeviceCMYK) DefaultName() pdf.Name

DefaultName implements the [ColorSpace] interface.

func (SpaceDeviceCMYK) New

func (s SpaceDeviceCMYK) New(c, m, y, k float64) Color

New returns a color in the DeviceCMYK color space.

func (SpaceDeviceCMYK) PDFObject

func (s SpaceDeviceCMYK) PDFObject() pdf.Object

PDFObject implements the [ColorSpace] interface.

type SpaceDeviceGray

type SpaceDeviceGray struct{}

SpaceDeviceGray represents the DeviceGray color space. Use DeviceGray to access this color space.

func (SpaceDeviceGray) ColorSpaceFamily

func (s SpaceDeviceGray) ColorSpaceFamily() string

ColorSpaceFamily implements the [ColorSpace] interface.

func (SpaceDeviceGray) DefaultName

func (s SpaceDeviceGray) DefaultName() pdf.Name

DefaultName implements the [ColorSpace] interface.

func (SpaceDeviceGray) New

func (s SpaceDeviceGray) New(gray float64) Color

New returns a color in the DeviceGray color space.

func (SpaceDeviceGray) PDFObject

func (s SpaceDeviceGray) PDFObject() pdf.Object

PDFObject implements the [ColorSpace] interface.

type SpaceDeviceRGB

type SpaceDeviceRGB struct{}

SpaceDeviceRGB represents the DeviceRGB color space. Use DeviceRGB to access this color space.

func (SpaceDeviceRGB) ColorSpaceFamily

func (s SpaceDeviceRGB) ColorSpaceFamily() string

ColorSpaceFamily implements the [ColorSpace] interface.

func (SpaceDeviceRGB) DefaultName

func (s SpaceDeviceRGB) DefaultName() pdf.Name

DefaultName implements the [ColorSpace] interface.

func (SpaceDeviceRGB) New

func (s SpaceDeviceRGB) New(r, g, b float64) Color

New returns a color in the DeviceRGB color space.

func (SpaceDeviceRGB) PDFObject

func (s SpaceDeviceRGB) PDFObject() pdf.Object

PDFObject implements the [ColorSpace] interface.

type SpaceIndexed

type SpaceIndexed struct {
	pdf.Res
	Space  Space
	NumCol int
}

SpaceIndexed represents an indexed color space.

func Indexed

func Indexed(colors []Color, defName pdf.Name) (*SpaceIndexed, error)

Indexed returns a new indexed color space.

The colors must all have the same color space, and the number of colors must be between 1 and 256.

func (*SpaceIndexed) ColorSpaceFamily

func (s *SpaceIndexed) ColorSpaceFamily() string

ColorSpaceFamily implements the [ColorSpace] interface.

func (*SpaceIndexed) Embed

func (s *SpaceIndexed) Embed(out *pdf.Writer) (*SpaceIndexed, error)

Embed embeds the color space in the PDF file. This saves space in case the color space is used in multiple content streams.

func (*SpaceIndexed) New

func (s *SpaceIndexed) New(idx int) Color

New returns a new indexed color.

type SpaceLab

type SpaceLab struct {
	pdf.Res
	// contains filtered or unexported fields
}

SpaceLab represents a CIE 1976 L*a*b* color space.

func Lab

func Lab(whitePoint, blackPoint, ranges []float64, defName pdf.Name) (*SpaceLab, error)

Lab returns a new CIE 1976 L*a*b* color space.

WhitePoint is the diffuse white point in CIE 1931 XYZ coordinates. This must be a slice of length 3, with positive entries, and Y=1.

BlackPoint (optional) is the diffuse black point in the CIE 1931 XYZ coordinates. If non-nil, this must be a slice of three non-negative numbers. The default is [0 0 0].

Ranges (optional) is a slice of four numbers, [aMin, aMax, bMin, bMax], which define the valid range of the a* and b* components. The default is [-100 100 -100 100].

DefName is the default resource name to use within content streams. This can be left empty to allocate names automatically.

func (*SpaceLab) ColorSpaceFamily

func (s *SpaceLab) ColorSpaceFamily() string

ColorSpaceFamily implements the [ColorSpace] interface.

func (*SpaceLab) Embed

func (s *SpaceLab) Embed(out *pdf.Writer) (*SpaceLab, error)

Embed embeds the color space in the PDF file. This saves space in case the color space is used in multiple content streams.

func (*SpaceLab) New

func (s *SpaceLab) New(l, a, b float64) (Color, error)

New returns a new Lab color.

type TilingPatternUncolored added in v0.4.2

type TilingPatternUncolored struct {
	pdf.Res
}

TilingPatternUncolored represents an uncolored PDF tiling pattern.

Res.Data must be a PDF stream defining a pattern with PatternType 1 and PaintType 2.

func (*TilingPatternUncolored) New added in v0.4.2

func (p *TilingPatternUncolored) New(col Color) Color

New returns a Color which paints the given tiling pattern in the given color.

Jump to

Keyboard shortcuts

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