fix comments

This commit is contained in:
Celogeek 2024-02-08 21:05:27 +02:00
parent 84a7666b13
commit 07ba350d82
Signed by: celogeek
SSH Key Fingerprint: SHA256:DEDfxIK2nUWXbslbRkww3zsauDjhWHlTXar+ak4lDJ4
18 changed files with 56 additions and 69 deletions

View File

@ -30,7 +30,7 @@ type Converter struct {
startAt time.Time startAt time.Time
} }
// Create a new parser // New Create a new parser
func New() *Converter { func New() *Converter {
o := options.New() o := options.New()
cmd := flag.NewFlagSet("go-comic-converter", flag.ExitOnError) cmd := flag.NewFlagSet("go-comic-converter", flag.ExitOnError)
@ -61,35 +61,35 @@ func New() *Converter {
return conv return conv
} }
// Load default options (config + default) // LoadConfig Load default options (config + default)
func (c *Converter) LoadConfig() error { func (c *Converter) LoadConfig() error {
return c.Options.LoadConfig() return c.Options.LoadConfig()
} }
// Create a new section of config // AddSection Create a new section of config
func (c *Converter) AddSection(section string) { func (c *Converter) AddSection(section string) {
c.order = append(c.order, converterOrderSection{value: section}) c.order = append(c.order, converterOrderSection{value: section})
} }
// Add a string parameter // AddStringParam Add a string parameter
func (c *Converter) AddStringParam(p *string, name string, value string, usage string) { func (c *Converter) AddStringParam(p *string, name string, value string, usage string) {
c.Cmd.StringVar(p, name, value, usage) c.Cmd.StringVar(p, name, value, usage)
c.order = append(c.order, converterOrderName{value: name, isString: true}) c.order = append(c.order, converterOrderName{value: name, isString: true})
} }
// Add an integer parameter // AddIntParam Add an integer parameter
func (c *Converter) AddIntParam(p *int, name string, value int, usage string) { func (c *Converter) AddIntParam(p *int, name string, value int, usage string) {
c.Cmd.IntVar(p, name, value, usage) c.Cmd.IntVar(p, name, value, usage)
c.order = append(c.order, converterOrderName{value: name}) c.order = append(c.order, converterOrderName{value: name})
} }
// Add an float parameter // AddFloatParam Add an float parameter
func (c *Converter) AddFloatParam(p *float64, name string, value float64, usage string) { func (c *Converter) AddFloatParam(p *float64, name string, value float64, usage string) {
c.Cmd.Float64Var(p, name, value, usage) c.Cmd.Float64Var(p, name, value, usage)
c.order = append(c.order, converterOrderName{value: name}) c.order = append(c.order, converterOrderName{value: name})
} }
// Add a boolean parameter // AddBoolParam Add a boolean parameter
func (c *Converter) AddBoolParam(p *bool, name string, value bool, usage string) { func (c *Converter) AddBoolParam(p *bool, name string, value bool, usage string) {
c.Cmd.BoolVar(p, name, value, usage) c.Cmd.BoolVar(p, name, value, usage)
c.order = append(c.order, converterOrderName{value: name}) c.order = append(c.order, converterOrderName{value: name})
@ -159,7 +159,7 @@ func (c *Converter) InitParse() {
c.AddBoolParam(&c.Options.Help, "help", false, "Show this help message") c.AddBoolParam(&c.Options.Help, "help", false, "Show this help message")
} }
// Customize version of FlagSet.PrintDefaults // Usage Customize version of FlagSet.PrintDefaults
func (c *Converter) Usage(isString bool, f *flag.Flag) string { func (c *Converter) Usage(isString bool, f *flag.Flag) string {
var b strings.Builder var b strings.Builder
fmt.Fprintf(&b, " -%s", f.Name) // Two spaces before -; see next two comments. fmt.Fprintf(&b, " -%s", f.Name) // Two spaces before -; see next two comments.
@ -274,7 +274,7 @@ func (c *Converter) Parse() {
} }
} }
// Check parameters // Validate Check parameters
func (c *Converter) Validate() error { func (c *Converter) Validate() error {
// Check input // Check input
if c.Options.Input == "" { if c.Options.Input == "" {
@ -391,7 +391,7 @@ func (c *Converter) Validate() error {
return nil return nil
} }
// Helper to show usage, err and exit 1 // Fatal Helper to show usage, err and exit 1
func (c *Converter) Fatal(err error) { func (c *Converter) Fatal(err error) {
c.Cmd.Usage() c.Cmd.Usage()
fmt.Fprintf(os.Stderr, "\nError: %s\n", err) fmt.Fprintf(os.Stderr, "\nError: %s\n", err)

View File

@ -1,6 +1,4 @@
/* // Package options manage options with default value from config.
Manage options with default value from config.
*/
package options package options
import ( import (
@ -78,7 +76,7 @@ type Options struct {
profiles profiles.Profiles profiles profiles.Profiles
} }
// Initialize default options. // New Initialize default options.
func New() *Options { func New() *Options {
return &Options{ return &Options{
Profile: "SR", Profile: "SR",
@ -185,13 +183,13 @@ func (o *Options) MarshalJSON() ([]byte, error) {
return json.Marshal(out) return json.Marshal(out)
} }
// Config file: ~/.go-comic-converter.yaml // FileName Config file: ~/.go-comic-converter.yaml
func (o *Options) FileName() string { func (o *Options) FileName() string {
home, _ := os.UserHomeDir() home, _ := os.UserHomeDir()
return filepath.Join(home, ".go-comic-converter.yaml") return filepath.Join(home, ".go-comic-converter.yaml")
} }
// Load config files // LoadConfig Load config files
func (o *Options) LoadConfig() error { func (o *Options) LoadConfig() error {
f, err := os.Open(o.FileName()) f, err := os.Open(o.FileName())
if err != nil { if err != nil {
@ -206,7 +204,7 @@ func (o *Options) LoadConfig() error {
return nil return nil
} }
// Get current settings for fields that can be saved // ShowConfig Get current settings for fields that can be saved
func (o *Options) ShowConfig() string { func (o *Options) ShowConfig() string {
var profileDesc string var profileDesc string
profile := o.GetProfile() profile := o.GetProfile()
@ -295,7 +293,7 @@ func (o *Options) ShowConfig() string {
return b.String() return b.String()
} }
// reset all settings to default value // ResetConfig reset all settings to default value
func (o *Options) ResetConfig() error { func (o *Options) ResetConfig() error {
New().SaveConfig() New().SaveConfig()
return o.LoadConfig() return o.LoadConfig()
@ -311,12 +309,12 @@ func (o *Options) SaveConfig() error {
return yaml.NewEncoder(f).Encode(o) return yaml.NewEncoder(f).Encode(o)
} }
// shortcut to get current profile // GetProfile shortcut to get current profile
func (o *Options) GetProfile() *profiles.Profile { func (o *Options) GetProfile() *profiles.Profile {
return o.profiles.Get(o.Profile) return o.profiles.Get(o.Profile)
} }
// all available profiles // AvailableProfiles all available profiles
func (o *Options) AvailableProfiles() string { func (o *Options) AvailableProfiles() string {
return o.profiles.String() return o.profiles.String()
} }

View File

@ -1,6 +1,4 @@
/* // Package profiles manage supported profiles for go-comic-converter.
Manage supported profiles for go-comic-converter.
*/
package profiles package profiles
import ( import (
@ -17,7 +15,7 @@ type Profile struct {
type Profiles []Profile type Profiles []Profile
// Initialize list of all supported profiles. // New Initialize list of all supported profiles.
func New() Profiles { func New() Profiles {
return []Profile{ return []Profile{
// High Resolution for Tablet // High Resolution for Tablet
@ -68,7 +66,7 @@ func (p Profiles) String() string {
return strings.Join(s, "\n") return strings.Join(s, "\n")
} }
// Lookup profile by code // Get Lookup profile by code
func (p Profiles) Get(name string) *Profile { func (p Profiles) Get(name string) *Profile {
for _, profile := range p { for _, profile := range p {
if profile.Code == name { if profile.Code == name {

View File

@ -1,6 +1,4 @@
/* // Package epub Tools to create EPUB from images.
Tools to create EPUB from images.
*/
package epub package epub
import ( import (
@ -41,7 +39,7 @@ type epubPart struct {
Reader *zip.ReadCloser Reader *zip.ReadCloser
} }
// initialize EPUB // New initialize EPUB
func New(options *epuboptions.Options) *ePub { func New(options *epuboptions.Options) *ePub {
uid := uuid.Must(uuid.NewV4()) uid := uuid.Must(uuid.NewV4())
tmpl := template.New("parser") tmpl := template.New("parser")

View File

@ -1,6 +1,4 @@
/* // Package epubimage Image helpers to transform image.
Image helpers to transform image.
*/
package epubimage package epubimage
import ( import (
@ -50,22 +48,22 @@ func (i *Image) PagePath() string {
return fmt.Sprintf("Text/%s.xhtml", i.PageKey()) return fmt.Sprintf("Text/%s.xhtml", i.PageKey())
} }
// page path into the EPUB // EPUBPagePath page path into the EPUB
func (i *Image) EPUBPagePath() string { func (i *Image) EPUBPagePath() string {
return fmt.Sprintf("OEBPS/%s", i.PagePath()) return fmt.Sprintf("OEBPS/%s", i.PagePath())
} }
// key for image // ImgKey key for image
func (i *Image) ImgKey() string { func (i *Image) ImgKey() string {
return fmt.Sprintf("img_%d_p%d", i.Id, i.Part) return fmt.Sprintf("img_%d_p%d", i.Id, i.Part)
} }
// image path // ImgPath image path
func (i *Image) ImgPath() string { func (i *Image) ImgPath() string {
return fmt.Sprintf("Images/%s.%s", i.ImgKey(), i.Format) return fmt.Sprintf("Images/%s.%s", i.ImgKey(), i.Format)
} }
// image path into the EPUB // EPUBImgPath image path into the EPUB
func (i *Image) EPUBImgPath() string { func (i *Image) EPUBImgPath() string {
return fmt.Sprintf("OEBPS/%s", i.ImgPath()) return fmt.Sprintf("OEBPS/%s", i.ImgPath())
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/disintegration/gift" "github.com/disintegration/gift"
) )
// Automatically improve contrast // AutoContrast Automatically improve contrast
func AutoContrast() *autocontrast { func AutoContrast() *autocontrast {
return &autocontrast{} return &autocontrast{}
} }

View File

@ -7,7 +7,7 @@ import (
"github.com/disintegration/gift" "github.com/disintegration/gift"
) )
// Lookup for margin and crop // AutoCrop Lookup for margin and crop
func AutoCrop(img image.Image, bounds image.Rectangle, cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom int) gift.Filter { func AutoCrop(img image.Image, bounds image.Rectangle, cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom int) gift.Filter {
return gift.Crop( return gift.Crop(
findMargin(img, bounds, cutRatioOptions{cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom}), findMargin(img, bounds, cutRatioOptions{cutRatioLeft, cutRatioUp, cutRatioRight, cutRatioBottom}),

View File

@ -11,7 +11,7 @@ import (
"golang.org/x/image/font/gofont/gomonobold" "golang.org/x/image/font/gofont/gomonobold"
) )
// Create a title with the cover image // CoverTitle Create a title with the cover image
func CoverTitle(title string, align string, pctWidth int, pctMargin int, maxFontSize int, borderSize int) gift.Filter { func CoverTitle(title string, align string, pctWidth int, pctMargin int, maxFontSize int, borderSize int) gift.Filter {
return &coverTitle{title, align, pctWidth, pctMargin, maxFontSize, borderSize} return &coverTitle{title, align, pctWidth, pctMargin, maxFontSize, borderSize}
} }
@ -25,12 +25,12 @@ type coverTitle struct {
borderSize int borderSize int
} }
// size is the same as source // Bounds size is the same as source
func (p *coverTitle) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) { func (p *coverTitle) Bounds(srcBounds image.Rectangle) (dstBounds image.Rectangle) {
return srcBounds return srcBounds
} }
// blur the src image, and create a box with the title in the middle // Draw blur the src image, and create a box with the title in the middle
func (p *coverTitle) Draw(dst draw.Image, src image.Image, options *gift.Options) { func (p *coverTitle) Draw(dst draw.Image, src image.Image, options *gift.Options) {
draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src) draw.Draw(dst, dst.Bounds(), src, src.Bounds().Min, draw.Src)
if p.title == "" { if p.title == "" {

View File

@ -7,7 +7,8 @@ import (
"github.com/disintegration/gift" "github.com/disintegration/gift"
) )
// Cut a double page in 2 part: left and right. // CropSplitDoublePage Cut a double page in 2 part: left and right.
//
// This will cut in the middle of the page. // This will cut in the middle of the page.
func CropSplitDoublePage(right bool) gift.Filter { func CropSplitDoublePage(right bool) gift.Filter {
return &cropSplitDoublePage{right} return &cropSplitDoublePage{right}

View File

@ -8,7 +8,8 @@ import (
"github.com/disintegration/gift" "github.com/disintegration/gift"
) )
// Generate a blank pixel 1x1, if the size of the image is 0x0. // Pixel Generate a blank pixel 1x1, if the size of the image is 0x0.
//
// An image 0x0 is not a valid image, and failed to read. // An image 0x0 is not a valid image, and failed to read.
func Pixel() gift.Filter { func Pixel() gift.Filter {
return &pixel{} return &pixel{}

View File

@ -1,6 +1,4 @@
/* // Package epubimageprocessor extract and transform image into a compressed jpeg.
Extract and transform image into a compressed jpeg.
*/
package epubimageprocessor package epubimageprocessor
import ( import (
@ -27,7 +25,7 @@ func New(o *epuboptions.Options) *EPUBImageProcessor {
return &EPUBImageProcessor{o} return &EPUBImageProcessor{o}
} }
// extract and convert images // Load extract and convert images
func (e *EPUBImageProcessor) Load() (images []*epubimage.Image, err error) { func (e *EPUBImageProcessor) Load() (images []*epubimage.Image, err error) {
images = make([]*epubimage.Image, 0) images = make([]*epubimage.Image, 0)
imageCount, imageInput, err := e.load() imageCount, imageInput, err := e.load()
@ -300,7 +298,7 @@ func (e *EPUBImageProcessor) Cover16LevelOfGray(bounds image.Rectangle) draw.Ima
}) })
} }
// create a title page with the cover // CoverTitleData create a title page with the cover
func (e *EPUBImageProcessor) CoverTitleData(o *CoverTitleDataOptions) (*epubzip.ZipImage, error) { func (e *EPUBImageProcessor) CoverTitleData(o *CoverTitleDataOptions) (*epubzip.ZipImage, error) {
// Create a blur version of the cover // Create a blur version of the cover
g := gift.New(epubimagefilters.CoverTitle(o.Text, o.Align, o.PctWidth, o.PctMargin, o.MaxFontSize, o.BorderSize)) g := gift.New(epubimagefilters.CoverTitle(o.Text, o.Align, o.PctWidth, o.PctMargin, o.MaxFontSize, o.BorderSize))

View File

@ -1,6 +1,4 @@
/* // Package epuboptions Options for EPUB creation.
Options for EPUB creation.
*/
package epuboptions package epuboptions
import "fmt" import "fmt"

View File

@ -1,6 +1,4 @@
/* // Package epubprogress create a progress bar with custom settings.
create a progress bar with custom settings.
*/
package epubprogress package epubprogress
import ( import (

View File

@ -1,6 +1,4 @@
/* // Package epubtemplates Templates use to create xml files of the EPUB.
Templates use to create xml files of the EPUB.
*/
package epubtemplates package epubtemplates
import _ "embed" import _ "embed"

View File

@ -1,5 +1,5 @@
/* /*
Organize a list of filename with their path into a tree of directories. Package epubtree Organize a list of filename with their path into a tree of directories.
Example: Example:
- A/B/C/D.jpg - A/B/C/D.jpg
@ -39,12 +39,12 @@ func New() *tree {
}} }}
} }
// root node // Root root node
func (n *tree) Root() *node { func (n *tree) Root() *node {
return n.Nodes["."] return n.Nodes["."]
} }
// add the filename to the tree // Add add the filename to the tree
func (n *tree) Add(filename string) { func (n *tree) Add(filename string) {
cn := n.Root() cn := n.Root()
cp := "" cp := ""
@ -58,7 +58,7 @@ func (n *tree) Add(filename string) {
} }
} }
// string version of the tree // WriteString string version of the tree
func (n *node) WriteString(indent string) string { func (n *node) WriteString(indent string) string {
r := strings.Builder{} r := strings.Builder{}
if indent != "" { if indent != "" {

View File

@ -1,5 +1,5 @@
/* /*
Helper to write EPUB files. Package epubzip Helper to write EPUB files.
We create a zip with the magic EPUB mimetype. We create a zip with the magic EPUB mimetype.
*/ */
@ -16,7 +16,7 @@ type EPUBZip struct {
wz *zip.Writer wz *zip.Writer
} }
// create a new EPUB // New create a new EPUB
func New(path string) (*EPUBZip, error) { func New(path string) (*EPUBZip, error) {
w, err := os.Create(path) w, err := os.Create(path)
if err != nil { if err != nil {
@ -26,7 +26,7 @@ func New(path string) (*EPUBZip, error) {
return &EPUBZip{w, wz}, nil return &EPUBZip{w, wz}, nil
} }
// close compress pipe and file. // Close close compress pipe and file.
func (e *EPUBZip) Close() error { func (e *EPUBZip) Close() error {
if err := e.wz.Close(); err != nil { if err := e.wz.Close(); err != nil {
return err return err
@ -34,7 +34,8 @@ func (e *EPUBZip) Close() error {
return e.w.Close() return e.w.Close()
} }
// Write mimetype, in a very specific way. // WriteMagic Write mimetype, in a very specific way.
//
// This will be valid with epubcheck tools. // This will be valid with epubcheck tools.
func (e *EPUBZip) WriteMagic() error { func (e *EPUBZip) WriteMagic() error {
t := time.Now() t := time.Now()
@ -62,7 +63,7 @@ func (e *EPUBZip) Copy(fz *zip.File) error {
return e.wz.Copy(fz) return e.wz.Copy(fz)
} }
// Write image. They are already compressed, so we write them down directly. // WriteRaw Write image. They are already compressed, so we write them down directly.
func (e *EPUBZip) WriteRaw(raw *ZipImage) error { func (e *EPUBZip) WriteRaw(raw *ZipImage) error {
m, err := e.wz.CreateRaw(raw.Header) m, err := e.wz.CreateRaw(raw.Header)
if err != nil { if err != nil {
@ -72,7 +73,7 @@ func (e *EPUBZip) WriteRaw(raw *ZipImage) error {
return err return err
} }
// Write file. Compressed it using deflate. // WriteContent Write file. Compressed it using deflate.
func (e *EPUBZip) WriteContent(file string, content []byte) error { func (e *EPUBZip) WriteContent(file string, content []byte) error {
m, err := e.wz.CreateHeader(&zip.FileHeader{ m, err := e.wz.CreateHeader(&zip.FileHeader{
Name: file, Name: file,

View File

@ -17,7 +17,7 @@ type ZipImage struct {
Data []byte Data []byte
} }
// create gzip encoded jpeg // CompressImage create gzip encoded jpeg
func CompressImage(filename string, format string, img image.Image, quality int) (*ZipImage, error) { func CompressImage(filename string, format string, img image.Image, quality int) (*ZipImage, error) {
var ( var (
data, cdata bytes.Buffer data, cdata bytes.Buffer

View File

@ -39,7 +39,7 @@ func (b by) Swap(i, j int) {
b.paths[i], b.paths[j] = b.paths[j], b.paths[i] b.paths[i], b.paths[j] = b.paths[j], b.paths[i]
} }
// use sortpath.By with sort.Sort // By use sortpath.By with sort.Sort
func By(filenames []string, mode int) by { func By(filenames []string, mode int) by {
p := [][]part{} p := [][]part{}
for _, filename := range filenames { for _, filename := range filenames {