volume

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrientationPortrait = iota
	OrientationLandscape
	OrientationSquare
)

Variables

This section is empty.

Functions

func IsSupportedColorDepth

func IsSupportedColorDepth(depth uint) error

Types

type Config

type Config struct {
	Density float64
	IsRTL   bool
	// IsRTLSet is true when the read direction is explicitly set by the user.
	// It takes precedence over the read direction in the input file.
	IsRTLSet bool
	// SkipUnreadablePage is true when a page which cannot be read is skipped
	// instead of stopping the formatting.
	SkipUnreadablePage bool
}

type FormatConfig

type FormatConfig struct {
	Spread    SpreadConfig
	Trim      TrimConfig
	Resize    ResizeConfig
	Grayscale GrayscaleConfig
	WorkDir   string
}

type FormattingProgressFunc

type FormattingProgressFunc func(v *Volume, completed float64, lastPageNo int)

type GrayscaleConfig

type GrayscaleConfig struct {
	Enabled    bool
	PageRange  PageRange
	ColorDepth uint
}

type Info

type Info struct {
	Title  string
	Author string
}

type InputSource added in v0.8.0

type InputSource interface {
	// Name is the input format name. It is used in log messages.
	Name() string

	// PageCount is the total number of pages in the input file.
	PageCount() int

	// Skipped is the pages in the input file which are skipped and left out of
	// the page count.
	Skipped() SkippedPages

	// Metadata is the volume information found in the input file. Its fields
	// are left empty if the input file has no such information.
	Metadata() SourceMetadata

	// LoadImage loads the image of the page number(1-based) in the input file.
	LoadImage(pageNo int, cfg Config, workDir string, logger log.Logger) (image.Image, error)
}

InputSource reads pages from an input volume file. Each supported input file format has its own implementation.

type Orientation

type Orientation int

func (Orientation) String

func (o Orientation) String() string

type Page

type Page struct {
	PageNo      int
	OtherPageNo int // the other page number that this page connected with
	// contains filtered or unexported fields
}

func (*Page) Connect

func (left *Page) Connect(right *Page, logger log.Logger) (*Page, error)

func (*Page) ConvertToGrayscale

func (p *Page) ConvertToGrayscale(cfg GrayscaleConfig, logger log.Logger) error

func (*Page) Destroy

func (p *Page) Destroy()

func (Page) Filename

func (p Page) Filename(suffix string) string

func (Page) Filepath

func (p Page) Filepath(dir string, suffix string) string

func (*Page) Format

func (p *Page) Format(cfg FormatConfig, keepOrientation bool, logger log.Logger) (*format.Page, error)

func (*Page) IsDoublePageSpread

func (left *Page) IsDoublePageSpread(right *Page, cfg SpreadConfig, logger log.Logger) (bool, error)

func (*Page) LeftRight

func (p *Page) LeftRight(other *Page) (left *Page, right *Page)

func (Page) Rect

func (p Page) Rect() Rect

func (*Page) ResizeToFit

func (p *Page) ResizeToFit(cfg ResizeConfig, keepOrientation bool, logger log.Logger) error

func (Page) Size

func (p Page) Size() Size

func (*Page) Trim

func (p *Page) Trim(cfg TrimConfig, logger log.Logger) error

func (Page) WriteFile

func (p Page) WriteFile(filepath string, logger log.Logger) error

type PageRange

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

func NewPageRange

func NewPageRange() *PageRange

func (*PageRange) Add

func (pr *PageRange) Add(start int, end int)

func (PageRange) All

func (pr PageRange) All() []int

func (PageRange) Contains

func (pr PageRange) Contains(page int) bool

func (PageRange) First

func (pr PageRange) First() int

func (PageRange) Last

func (pr PageRange) Last() int

func (PageRange) PageCount

func (pr PageRange) PageCount() int

func (*PageRange) Parse

func (pr *PageRange) Parse(str string, total int) error

func (PageRange) String

func (pr PageRange) String() string

type PdfPageExtractor

type PdfPageExtractor interface {
	Name() string
	Detect() error
	Extract(inputFile string, page int, dpi float64, outputFile string, logger log.Logger) error
}

func FindPdfExtractor

func FindPdfExtractor(logger log.Logger) (PdfPageExtractor, error)

type Point

type Point struct {
	X int
	Y int
}

TODO: Use image.Point

func (Point) String

func (p Point) String() string

func (Point) TranslateBy

func (p Point) TranslateBy(dx int, dy int) Point

type Rect

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

TODO: Use image.Rectange

func FromRectangle

func FromRectangle(r image.Rectangle) Rect

func (Rect) BoundBy

func (r Rect) BoundBy(frame Rect) Rect

func (Rect) InsetBy

func (r Rect) InsetBy(dx int, dy int) Rect

func (Rect) MaxX

func (r Rect) MaxX() int

func (Rect) MaxY

func (r Rect) MaxY() int

func (Rect) MinX

func (r Rect) MinX() int

func (Rect) MinY

func (r Rect) MinY() int

func (Rect) MoveInside

func (r Rect) MoveInside(frame Rect) Rect

func (Rect) String

func (r Rect) String() string

func (Rect) ToRectangle

func (r Rect) ToRectangle() image.Rectangle

func (Rect) TranslateBy

func (r Rect) TranslateBy(dx int, dy int) Rect

type ResizeConfig

type ResizeConfig struct {
	Enabled    bool
	ScreenSize Size
}

type Size

type Size struct {
	Width  uint
	Height uint
}

func SizeFromBounds

func SizeFromBounds(b image.Rectangle) Size

func (Size) AspectFitIn

func (s Size) AspectFitIn(box Size, enlarge bool) Size

func (Size) CanFitIn

func (s Size) CanFitIn(box Size) bool

func (Size) Orientation

func (s Size) Orientation() Orientation

func (Size) Rotate

func (s Size) Rotate() Size

func (Size) ScaleBy

func (s Size) ScaleBy(f float64) Size

func (Size) String

func (s Size) String() string

type SkipReason added in v0.8.0

type SkipReason int

SkipReason tells why a page in the input file cannot be read

const (
	NotSkipped SkipReason = iota
	SkipNoImage
	SkipEncrypted
)

func (SkipReason) String added in v0.8.0

func (r SkipReason) String() string

String is why the page cannot be read. It is a part of the error message. It is empty when the page is not skipped.

type SkippedPage added in v0.8.0

type SkippedPage struct {
	PageNo int        // the page number in the input file
	Reason SkipReason // why the page cannot be read
}

SkippedPage is a page in the input file which is skipped so it is not in the output file

type SkippedPages added in v0.8.0

type SkippedPages []SkippedPage

SkippedPages are the pages in the input file which are skipped so they are not in the output file

func (SkippedPages) Count added in v0.8.0

func (s SkippedPages) Count(reason SkipReason) int

Count is the number of the skipped pages with the reason

type SourceMetadata added in v0.8.0

type SourceMetadata struct {
	Title      string
	Author     string
	Language   string
	Identifier string
	IsRTL      *bool // nil means the input file does not specify the read direction

	// Epub is the metadata which only an epub input file has
	Epub format.EpubMetadata
}

SourceMetadata is the volume information read from the input file

type SpreadConfig

type SpreadConfig struct {
	Enabled         bool
	KeepOrientation bool
	KeepOriginal    bool
	EdgeWidth       int
	Confidence      float64
}

type TrimConfig

type TrimConfig struct {
	Enabled  bool
	FuzzP    float64
	MinSizeP float64
	Margin   int
}

type Volume

type Volume struct {
	Filepath  string
	Info      Info
	PageCount int
	Config    Config
	// contains filtered or unexported fields
}

func NewVolume

func NewVolume(path string, info Info, cfg Config, logger log.Logger) (*Volume, error)

func (*Volume) Format

func (v *Volume) Format(pr PageRange, cfg FormatConfig, logger log.Logger, progress FormattingProgressFunc) (*format.Volume, error)

func (*Volume) LoadPage

func (v *Volume) LoadPage(pageNo int, workDir string, logger log.Logger) (*Page, error)

func (*Volume) Metadata added in v0.8.0

func (v *Volume) Metadata() SourceMetadata

Metadata is the volume information found in the input file

func (*Volume) Skipped added in v0.8.0

func (v *Volume) Skipped() SkippedPages

Skipped is the pages in the input file which are skipped so they are not in the output file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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