preprocessor

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultMergeMap = MergeMap{
	"Han": map[string]string{
		"Hiragana": "Hiragana",
		"Katakana": "Katakana",
	},
	"Hiragana": map[string]string{
		"Han":      "Hiragana",
		"Katakana": "Hiragana",
	},
	"Katakana": map[string]string{
		"Han":      "Katakana",
		"Hiragana": "Hiragana",
	},
}

The default mergeMap containing info for the japanese scripts

View Source
var DefaultScripts = []string{
	"Arabic",
	"Common",
	"Devanagari",
	"Han",
	"Hangul",
	"Hiragana",
	"Inherited",
	"Katakana",
	"Latin",
}

Default list of scripts to be analyzed within the string.

Scripts that aren't present in the list will be considered as part of the last "known" script. For example, if "Avestan" script (which isn't present) is preceeded by "Arabic" script, then the "Avestan" script will be considered as "Arabic"

Punctuation symbols are usually considered part of the "Common" script

Functions

This section is empty.

Types

type AnalysisOpts

type AnalysisOpts struct {
	UseMergeMap bool
	MergeMap    MergeMap
}

Analysis options.

type FileConverter

type FileConverter interface {
	Convert(r io.Reader) (interface{}, error)
}

func ForType

func ForType(mimeType string, opts map[string]interface{}) FileConverter

type FontLoader

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

Represents a FontLoader. Use the "NewFontLoader" to get a instance

func NewFontLoader

func NewFontLoader(fontMapFile string, faceOpts *opentype.FaceOptions) (*FontLoader, error)

Create a new FontLoader based on the fontMapFile. The FaceOptions will be the same for all the font loaded by this instance. Note that only the fonts described in the fontMapFile will be used.

The fontMapFile has the following structure

{
	"fontMap": {
		"Han": "packaged/myFont-CJK.otf",
		"Arabic": "packaged/myFont-Arab.otf",
		"Latin": "/fonts/regular/myFont.otf"
	}
	"defaultFont": "/fonts/regular/myFont.otf"
}

The fontMapFile contains paths to where the fonts are located in the FS. Absolute paths can be used as shown above. If a relative path is used, it will be relative to the fontMapFile location. This should make the packaging easier since all the fonts can be placed in the same directory where the fontMapFile is, or in inner directories.

func (*FontLoader) GetFaceOptDPI

func (fl *FontLoader) GetFaceOptDPI() float64

func (*FontLoader) GetFaceOptSize

func (fl *FontLoader) GetFaceOptSize() float64

func (*FontLoader) GetScriptList

func (fl *FontLoader) GetScriptList() []string

func (*FontLoader) LoadFaceForScript

func (fl *FontLoader) LoadFaceForScript(script string) (*LoadedFace, error)

Load and return the font face to be used for that script according to the FontMap set when the FontLoader was created. If the script doesn't have an associated font, a default font will be used. Note that the default font might not be able to handle properly the script

type FontMap

type FontMap struct {
	FontMap     map[string]string `json:"fontMap"`
	DefaultFont string            `json:"defaultFont"`
}

FontMap maps a script with the target font to be used for that script It also uses a DefaultFont in case there isn't a matching script in the map

For cases like Japanese where multiple scripts are used, we rely on the text analyzer to use the script which is unique to japanese (Hiragana or Katakana) even if it has to overwrite the "official" detected script (Han). This means that "Han" should be used just for chinese while "Hiragana" and "Katakana" should be used for japanese

type FontMapData

type FontMapData struct {
	FMap *FontMap
	FLoc string
}

It contains the location of the loaded file (in FLoc) and the FontMap loaded from the file

type GifDecoder

type GifDecoder struct{}

func (GifDecoder) Convert

func (i GifDecoder) Convert(r io.Reader) (interface{}, error)

type ImageDecoder

type ImageDecoder struct{}

func (ImageDecoder) Convert

func (i ImageDecoder) Convert(r io.Reader) (interface{}, error)

type LoadedFace

type LoadedFace struct {
	FontFile string
	Face     font.Face
}

It contains the location of the font used, and the loaded face (font.Face) ready to be used

type MergeMap

type MergeMap map[string]map[string]string

Convenient map[string]map[string]string type used to merge multiple scripts into one. This is mainly used for japanese language which uses "Han", "Hiragana" and "Katakana" scripts.

The map contains the expected previous script as first key, the expected current script as second key, and the resulting script (if both keys match) as value

type ScriptRange

type ScriptRange struct {
	Low, High    int
	Spaces       []int
	TargetScript string
	RuneCount    int
}

A script range. The range should be attached to a string which could contain multiple scripts. The "TargetScript" will go from bytes "Low" to "High" (both inclusive), and contains a "RuneCount" number of runes or chars (mostly for debugging purposes). The Space contains the bytes (inside the range) that are considered as white space.

type TextAnalysis

type TextAnalysis struct {
	ScriptRanges []ScriptRange
	RuneCount    map[string]int
	Text         string
}

The result of a text analysis. It contains the analyzed text, a list of script ranges (see the ScriptRange type) and a map containing how many runes have been detected for a particular script.

func (*TextAnalysis) MergeCommon

func (tr *TextAnalysis) MergeCommon(mergeMap MergeMap)

Change the "Common" script to the one used in the previous script range. The ranges will be readjusted and merged if they're adjacent. This naive approach should be good enough for normal use cases

The MergeMap is needed in case of the japanese language: the ranges "Han"-"Common"-"Katakana" might be replaced to "Han"-"Hiragana"-"Katakana" However, the ranges should be merged together into a big "Hiragana" range. If the MergeMap isn't needed, use an empty one

type TextAnalyzer

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

The TextAnalyzer object contains private members. It should be created via "NewTextAnalyzer" function.

func NewTextAnalyzer

func NewTextAnalyzer(scriptList []string) TextAnalyzer

Create a new TextAnalyzer. A list of scripts must be provided. You can use the "DefaultScripts" variable for a default list, although it doesn't contain all the available scripts. See the unicode.Scripts variable (in the unicode package) for a full list. Note that using invalid scripts will cause an undefined behavior

func (*TextAnalyzer) AnalyzeString

func (ta *TextAnalyzer) AnalyzeString(word string, opts AnalysisOpts) TextAnalysis

Analyze the target string using the specified options. A TextAnalysis will be returned with the result of the analysis.

type TxtToImageConverter

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

func (TxtToImageConverter) Convert

func (t TxtToImageConverter) Convert(r io.Reader) (interface{}, error)

Jump to

Keyboard shortcuts

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