Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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
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 ¶ added in v1.16.0
Analysis options.
type FileConverter ¶
func ForType ¶
func ForType(mimeType string, opts map[string]interface{}) FileConverter
type FontLoader ¶ added in v1.16.0
type FontLoader struct {
// contains filtered or unexported fields
}
Represents a FontLoader. Use the "NewFontLoader" to get a instance
func NewFontLoader ¶ added in v1.16.0
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 ¶ added in v1.16.0
func (fl *FontLoader) GetFaceOptDPI() float64
func (*FontLoader) GetFaceOptSize ¶ added in v1.16.0
func (fl *FontLoader) GetFaceOptSize() float64
func (*FontLoader) GetScriptList ¶ added in v1.16.0
func (fl *FontLoader) GetScriptList() []string
func (*FontLoader) LoadFaceForScript ¶ added in v1.16.0
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 ¶ added in v1.16.0
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 ¶ added in v1.16.0
It contains the location of the loaded file (in FLoc) and the FontMap loaded from the file
type GifDecoder ¶ added in v1.19.0
type GifDecoder struct{}
type ImageDecoder ¶
type ImageDecoder struct{}
type LoadedFace ¶ added in v1.16.0
It contains the location of the font used, and the loaded face (font.Face) ready to be used
type MergeMap ¶ added in v1.16.0
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 ¶ added in v1.16.0
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 ¶ added in v1.16.0
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 ¶ added in v1.16.0
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 ¶ added in v1.16.0
type TextAnalyzer struct {
// contains filtered or unexported fields
}
The TextAnalyzer object contains private members. It should be created via "NewTextAnalyzer" function.
func NewTextAnalyzer ¶ added in v1.16.0
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 ¶ added in v1.16.0
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
}