textstyle

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: MIT Imports: 2 Imported by: 0

README

go-textstyle

An implement of transform.Transformer to change text style. For example, Gopher to 𝔾𝕠𝕡𝕙𝕖𝕣, 𝕲𝖔𝖕𝖍𝖊𝖗 and so on.

Note

This package is on proof of concept stage. There would be some breaking changes. Do not use this on your products.

Usage

This package provides some implementations of transform.Transformer. Combining with transform.Reader enables you to accept any kind of io.Reader to transform text styles.

Here is a simple example.

package main

import (
	"io"
	"os"
	"strings"

	"github.com/tenkoh/go-textstyle"
	"golang.org/x/text/transform"
)

func main() {
	s := "Hello, Gophers"
	r := transform.NewReader(strings.NewReader(s), textstyle.Bold())
	io.Copy(os.Stdout, r)
	//Output: 𝐇𝐞𝐥𝐥𝐨, 𝐆𝐨𝐩𝐡𝐞𝐫𝐬
}

You can use other io.Reader like os.Stdin, *os.File, http.Response.Body and so on.

Available styles

  • Bold
  • Italic
  • BoldItalic
  • Script
  • BoldScript
  • Fraktur
  • BoldFraktur
  • DoubleStruck
  • SansSerif
  • SansSerifBold
  • SansSerifItalic
  • SansSerifBoldItalic
  • Monospce

Contribution

I'm very welcome your contribution. There are some assets to help adding text styles. If you are eager to add a complex transformation, do it your way without the assets.

Code generation

If you want to add simple replacement, which means just giving codepoint offsets, you can use code generation tool. Please open tool/generate_style.go, then add Style refering to existing styles. After editting, go generate command generates styles.go including added styles.

Alternative character's map

Unicode table has some lacks (or reserved part) to alphabets. If you can not realize simple repalcement due to a few excepts, please consider to add a pairs to alternate them into altMap in textstyle.go.

Roadmap

  • 0.0.1: Basic functions and some styles (current)
  • 0.0.x: Add Greek styles and enclosed styles.

Thanks

I was very impressed by https://github.com/ikanago/omekasy , CLI tool to change text style implemented in Rust.

License

MIT

Author

tenkoh

Documentation

Overview

Code generated by generate_style.go; DO NOT EDIT.

Index

Examples

Constants

View Source
const (
	BOLD_LOWER_OFFSET                   = 119737
	BOLD_UPPER_OFFSET                   = 119743
	BOLD_DIGIT_OFFSET                   = 120734
	ITALIC_LOWER_OFFSET                 = 119789
	ITALIC_UPPER_OFFSET                 = 119795
	ITALIC_DIGIT_OFFSET                 = 0
	BOLD_ITALIC_LOWER_OFFSET            = 119841
	BOLD_ITALIC_UPPER_OFFSET            = 119847
	BOLD_ITALIC_DIGIT_OFFSET            = 120734
	SCRIPT_LOWER_OFFSET                 = 119893
	SCRIPT_UPPER_OFFSET                 = 119899
	SCRIPT_DIGIT_OFFSET                 = 0
	BOLD_SCRIPT_LOWER_OFFSET            = 119945
	BOLD_SCRIPT_UPPER_OFFSET            = 119951
	BOLD_SCRIPT_DIGIT_OFFSET            = 120734
	FRAKTUR_LOWER_OFFSET                = 119997
	FRAKTUR_UPPER_OFFSET                = 120003
	FRAKTUR_DIGIT_OFFSET                = 0
	BOLD_FRAKTUR_LOWER_OFFSET           = 120101
	BOLD_FRAKTUR_UPPER_OFFSET           = 120107
	BOLD_FRAKTUR_DIGIT_OFFSET           = 120734
	DOUBLE_STRUCK_LOWER_OFFSET          = 120049
	DOUBLE_STRUCK_UPPER_OFFSET          = 120055
	DOUBLE_STRUCK_DIGIT_OFFSET          = 120744
	SANS_SERIF_LOWER_OFFSET             = 120153
	SANS_SERIF_UPPER_OFFSET             = 120159
	SANS_SERIF_DIGIT_OFFSET             = 120754
	SANS_SERIF_BOLD_LOWER_OFFSET        = 120205
	SANS_SERIF_BOLD_UPPER_OFFSET        = 120211
	SANS_SERIF_BOLD_DIGIT_OFFSET        = 120764
	SANS_SERIF_ITALIC_LOWER_OFFSET      = 120257
	SANS_SERIF_ITALIC_UPPER_OFFSET      = 120263
	SANS_SERIF_ITALIC_DIGIT_OFFSET      = 120754
	SANS_SERIF_BOLD_ITALIC_LOWER_OFFSET = 120309
	SANS_SERIF_BOLD_ITALIC_UPPER_OFFSET = 120315
	SANS_SERIF_BOLD_ITALIC_DIGIT_OFFSET = 120764
	MONOSPACE_LOWER_OFFSET              = 120361
	MONOSPACE_UPPER_OFFSET              = 120367
	MONOSPACE_DIGIT_OFFSET              = 120774
)

Variables

This section is empty.

Functions

func Replace

func Replace(rep Replacer, p []byte) []byte

replace replaces a-zA-Z0-9 with regular style into specific styles. Invalid bytes, which could not be decoded into rune, are passed through.

Types

type Replacer

type Replacer interface {
	LowerFunc(rune) rune
	UpperFunc(rune) rune
	DigitFunc(rune) rune
}

Replacer defines replacing method for a-z, A-Z and 0-9.

type SimpleReplacer

type SimpleReplacer struct {
	Name        string
	LowerOffset rune
	UpperOffset rune
	DigitOffset rune
}

SimpleReplacer is an implementation of Replacer which just offsets a-z, A-Z and 0-9.

func NewSimpleReplacer

func NewSimpleReplacer(name string, lo, uo, do rune) *SimpleReplacer

func (*SimpleReplacer) DigitFunc

func (sr *SimpleReplacer) DigitFunc(src rune) rune

func (*SimpleReplacer) LowerFunc

func (sr *SimpleReplacer) LowerFunc(src rune) rune

func (*SimpleReplacer) UpperFunc

func (sr *SimpleReplacer) UpperFunc(src rune) rune

type Transformer

type Transformer struct {
	Rep Replacer
	// contains filtered or unexported fields
}

Transformer is a implement of transform.Transformer. This aims to replace characters which is composed of one byte, so multi bytes characters or invalid bytes are passed through.

Example
s := "Hello, Gophers"
r := transform.NewReader(strings.NewReader(s), textstyle.Bold())
io.Copy(os.Stdout, r)
Output:

𝐇𝐞𝐥𝐥𝐨, 𝐆𝐨𝐩𝐡𝐞𝐫𝐬

func Bold

func Bold() *Transformer

func BoldFraktur

func BoldFraktur() *Transformer

func BoldItalic

func BoldItalic() *Transformer

func BoldScript

func BoldScript() *Transformer

func DoubleStruck

func DoubleStruck() *Transformer

func Fraktur

func Fraktur() *Transformer

func Italic

func Italic() *Transformer

func Monospace

func Monospace() *Transformer

func NewTransformer

func NewTransformer(r Replacer) *Transformer

func SansSerif

func SansSerif() *Transformer

func SansSerifBold

func SansSerifBold() *Transformer

func SansSerifBoldItalic

func SansSerifBoldItalic() *Transformer

func SansSerifItalic

func SansSerifItalic() *Transformer

func Script

func Script() *Transformer

func (*Transformer) Reset

func (tr *Transformer) Reset()

func (*Transformer) Transform

func (tr *Transformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Transform conducts transforming following its Replacer. Other specifications follow transform.Transformer.

Directories

Path Synopsis
_example

Jump to

Keyboard shortcuts

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