utils

package
v0.0.0-...-716ed4d Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcRealSize

func CalcRealSize(sizeStr string, parentSize int) (size int, err error)

CalcRealSize 判断和计算sizeStr是纯数字类型的指标,还是百分百类型的,都转换为数字类型的返回, CalcRealSize("30", 200)=>30, CalcRealSize("30%", 200)=>60,CalcRealSize("30.0%", 200)=>60,

func DeferWhenOnRequestDone

func DeferWhenOnRequestDone() func(retCode *int, msg, url, rBody, wBody *string)

func DrawHorizLine

func DrawHorizLine(img *image.RGBA, c color.Color, fromX, toX, y int)

DrawHorizLine 画一条水平线

func DrawVertLine

func DrawVertLine(img *image.RGBA, c color.Color, x, fromY, toY int)

DrawVertLine 画一条竖直线

func GetFontSizeByHeight

func GetFontSizeByHeight(tf *truetype.Font, dpi float64, fontHeight int) (fontSize float64, err error)

GetFontSizeByHeight 通过文字的高度得到文字的大小(fontsize)

func Hex2RGB

func Hex2RGB(hexStr string) (c color.Color, err error)

Hex2RGB 将十六进制的颜色码转换为颜色对象,比如#123456=>(R:12,G:34,B:56), #12345678=>((R:12,G:34,B:56,A:78)

func LoadFont

func LoadFont(fontFile string) (font *truetype.Font, err error)

LoadFont 加载字体

func MeasureText

func MeasureText(oneLineText string, tf *truetype.Font, dpi, fontSize float64) (width int, height int, err error)

MeasureText 测量一行文字的宽高

func MinInt

func MinInt(v1, v2 int) (min int)

func ParseAbsoluteLocation

func ParseAbsoluteLocation(absolutePositionStr string, parentSize [2]int, selfSize [2]int) (minX, minY, maxX, maxY int, err error)

ParseAbsoluteLocation 根据绝对定位配置,计算自身位置信息,ParseAbsoluteLocation("1% none none 2%",{100,200},{20,20})==>(20,20,40,40,nil)(如果没找到,则返回 math.MaxInt32)

func ParseNumPercentNumNone

func ParseNumPercentNumNone(numStr string, baseSize int) (isNone bool, realSize int, err error)

ParseNumPercentNumNone 解析字符串是整数型|百分比数|none,如果是非none,计算返回真正的尺寸

func ParseRelativeLocation

func ParseRelativeLocation(relativePositionStr string, parentSize [2]int, selfSize [2]int, relativePosition [4]int) (minX, minY, maxX, maxY int, err error)

ParseRelativeLocation 根据相对定位配置,计算自身位置信息(如果没找到,则返回 math.MaxInt32)

func RequestResource

func RequestResource(resUrl string) (body io.ReadCloser, contentType string, err error)

RequestResource 请求资源(一般来说是指获取图片资源)

func ToRGBA

func ToRGBA(img image.Image) *image.RGBA

ToRGBA 将任意image.Image转换为image.RGBA类型

Types

This section is empty.

Jump to

Keyboard shortcuts

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