1 Star 0 Fork 0

zhaobingss / unipdf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
context.go 7.21 KB
一键复制 编辑 原始数据 按行查看 历史
zhaobingss 提交于 2023-07-29 19:20 . INIT
//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package context
import (
_b "errors"
_bae "gitee.com/zhaobingss/unipdf/v3/core"
_e "gitee.com/zhaobingss/unipdf/v3/internal/textencoding"
_ae "gitee.com/zhaobingss/unipdf/v3/internal/transform"
_ba "gitee.com/zhaobingss/unipdf/v3/model"
_de "github.com/unidoc/freetype/truetype"
_gg "golang.org/x/image/font"
_d "image"
_g "image/color"
)
func (_gab *TextState) ProcTStar() { _gab.ProcTd(0, -_gab.Tl) }
const (
LineJoinRound LineJoin = iota
LineJoinBevel
)
type LineJoin int
func (_cdac *TextState) ProcTd(tx, ty float64) {
_cdac.Tlm.Concat(_ae.TranslationMatrix(tx, ty))
_cdac.Tm = _cdac.Tlm.Clone()
}
func (_ffg *TextState) ProcQ(data []byte, ctx Context) { _ffg.ProcTStar(); _ffg.ProcTj(data, ctx) }
type Gradient interface {
Pattern
AddColorStop(_c float64, _f _g.Color)
}
func (_gfa *TextState) ProcTf(font *TextFont) { _gfa.Tf = font }
func (_bbc *TextFont) BytesToCharcodes(data []byte) []_e.CharCode {
if _bbc._ec != nil {
return _bbc._ec.BytesToCharcodes(data)
}
return _bbc.Font.BytesToCharcodes(data)
}
func (_dbd *TextFont) WithSize(size float64, originalFont *_ba.PdfFont) *TextFont {
return &TextFont{Font: _dbd.Font, Size: size, _fff: _dbd._fff, _ec: originalFont}
}
type FillRule int
func (_bfc *TextState) Reset() { _bfc.Tm = _ae.IdentityMatrix(); _bfc.Tlm = _ae.IdentityMatrix() }
func (_aec *TextState) ProcTm(a, b, c, d, e, f float64) {
_aec.Tm = _ae.NewMatrix(a, b, c, d, e, f)
_aec.Tlm = _aec.Tm.Clone()
}
func (_gag *TextState) ProcTj(data []byte, ctx Context) {
_ffb := _gag.Tf.Size
_def := _gag.Th / 100.0
_dcd := _gag.GlobalScale
_cf := _ae.NewMatrix(_ffb*_def, 0, 0, _ffb, 0, _gag.Ts)
_efd := ctx.Matrix()
_cbf := _efd.Clone().Mult(_gag.Tm.Clone().Mult(_cf)).ScalingFactorY()
_ceff := _gag.Tf.NewFace(_cbf)
_cac := _gag.Tf.BytesToCharcodes(data)
for _, _baaf := range _cac {
_gc, _gdd := _gag.Tf.CharcodeToRunes(_baaf)
_aba := string(_gdd)
if _aba == "\u0000" {
continue
}
_daa := _efd.Clone().Mult(_gag.Tm.Clone().Mult(_cf))
_cbb := _daa.ScalingFactorY()
_daa = _daa.Scale(1/_cbb, -1/_cbb)
if _gag.Tr != TextRenderingModeInvisible {
ctx.SetMatrix(_daa)
ctx.DrawString(_aba, _ceff, 0, 0)
ctx.SetMatrix(_efd)
}
_agd := 0.0
if _aba == "\u0020" {
_agd = _gag.Tw
}
_fgc, _, _ddc := _gag.Tf.GetCharMetrics(_gc)
if _ddc {
_fgc = _fgc * 0.001 * _ffb
} else {
_fgc, _ = ctx.MeasureString(_aba, _ceff)
_fgc = _fgc / _dcd
}
_cca := (_fgc + _gag.Tc + _agd) * _def
_gag.Tm = _gag.Tm.Mult(_ae.TranslationMatrix(_cca, 0))
}
}
type LineCap int
func (_dcbb *TextState) ProcTD(tx, ty float64) {
_dcbb.Tl = -ty
_dcbb.ProcTd(tx, ty)
}
type TextRenderingMode int
type TextFont struct {
Font *_ba.PdfFont
Size float64
_fff *_de.Font
_ec *_ba.PdfFont
}
func (_dad *TextFont) CharcodeToRunes(charcode _e.CharCode) (_e.CharCode, []rune) {
_baeb := []_e.CharCode{charcode}
if _dad._ec == nil || _dad._ec == _dad.Font {
if _dad.Font.IsSimple() && _dad._fff != nil {
if _dd := _dad._fff.Index(rune(charcode)); _dd > 0 {
return charcode, []rune{rune(charcode)}
}
}
return charcode, _dad.Font.CharcodesToUnicode(_baeb)
}
_efg := _dad._ec.CharcodesToUnicode(_baeb)
_fc, _ := _dad.Font.RunesToCharcodeBytes(_efg)
_bge := _dad.Font.BytesToCharcodes(_fc)
_eba := charcode
if len(_bge) > 0 && _bge[0] != 0 {
_eba = _bge[0]
}
return _eba, _efg
}
type Pattern interface{ ColorAt(_ab, _ed int) _g.Color }
func NewTextState() TextState {
return TextState{Th: 100, Tm: _ae.IdentityMatrix(), Tlm: _ae.IdentityMatrix()}
}
func (_gadf *TextState) ProcDQ(data []byte, aw, ac float64, ctx Context) {
_gadf.Tw = aw
_gadf.Tc = ac
_gadf.ProcQ(data, ctx)
}
const (
FillRuleWinding FillRule = iota
FillRuleEvenOdd
)
type Context interface {
Push()
Pop()
Matrix() _ae.Matrix
SetMatrix(_ce _ae.Matrix)
Translate(_cb, _af float64)
Scale(_ef, _bf float64)
Rotate(_gf float64)
MoveTo(_dc, _ca float64)
LineTo(_cef, _cd float64)
CubicTo(_df, _ea, _dg, _ggc, _eb, _afa float64)
QuadraticTo(_ga, _fe, _fg, _fec float64)
NewSubPath()
ClosePath()
ClearPath()
Clip()
ClipPreserve()
ResetClip()
LineWidth() float64
SetLineWidth(_bd float64)
SetLineCap(_ge LineCap)
SetLineJoin(_cda LineJoin)
SetDash(_aee ...float64)
SetDashOffset(_fd float64)
Fill()
FillPreserve()
Stroke()
StrokePreserve()
SetRGBA(_fgf, _cg, _gad, _aef float64)
SetFillRGBA(_fb, _fda, _cc, _fbe float64)
SetFillStyle(_eag Pattern)
SetFillRule(_ccc FillRule)
SetStrokeRGBA(_bg, _fbf, _eda, _fge float64)
SetStrokeStyle(_be Pattern)
FillPattern() Pattern
StrokePattern() Pattern
TextState() *TextState
DrawString(_eg string, _bb _gg.Face, _cdaf, _aa float64)
MeasureString(_feg string, _ff _gg.Face) (_aab, _cde float64)
DrawRectangle(_fbc, _db, _dba, _fa float64)
DrawImage(_bed _d.Image, _eff, _cdd int)
DrawImageAnchored(_baa _d.Image, _fdb, _ee int, _gea, _fag float64)
Height() int
Width() int
}
func (_dcb *TextFont) GetCharMetrics(code _e.CharCode) (float64, float64, bool) {
if _gb, _ag := _dcb.Font.GetCharMetrics(code); _ag && _gb.Wx != 0 {
return _gb.Wx, _gb.Wy, _ag
}
if _dcb._ec == nil {
return 0, 0, false
}
_adg, _fce := _dcb._ec.GetCharMetrics(code)
return _adg.Wx, _adg.Wy, _fce && _adg.Wx != 0
}
const (
TextRenderingModeFill TextRenderingMode = iota
TextRenderingModeStroke
TextRenderingModeFillStroke
TextRenderingModeInvisible
TextRenderingModeFillClip
TextRenderingModeStrokeClip
TextRenderingModeFillStrokeClip
TextRenderingModeClip
)
const (
LineCapRound LineCap = iota
LineCapButt
LineCapSquare
)
func NewTextFont(font *_ba.PdfFont, size float64) (*TextFont, error) {
_abb := font.FontDescriptor()
if _abb == nil {
return nil, _b.New("\u0063\u006fu\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0067\u0065\u0074\u0020\u0066\u006f\u006e\u0074\u0020\u0064\u0065\u0073\u0063\u0072\u0069pt\u006f\u0072")
}
_fbb, _da := _bae.GetStream(_abb.FontFile2)
if !_da {
return nil, _b.New("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d")
}
_gd, _edf := _bae.DecodeStream(_fbb)
if _edf != nil {
return nil, _edf
}
_gge, _edf := _de.Parse(_gd)
if _edf != nil {
return nil, _edf
}
return &TextFont{Font: font, Size: size, _fff: _gge}, nil
}
func NewTextFontFromPath(filePath string, size float64) (*TextFont, error) {
_afg, _ad := _ba.NewPdfFontFromTTFFile(filePath)
if _ad != nil {
return nil, _ad
}
return NewTextFont(_afg, size)
}
func (_dfc *TextFont) NewFace(size float64) _gg.Face {
return _de.NewFace(_dfc._fff, &_de.Options{Size: size})
}
type TextState struct {
Tc float64
Tw float64
Th float64
Tl float64
Tf *TextFont
Ts float64
Tm _ae.Matrix
Tlm _ae.Matrix
Tr TextRenderingMode
GlobalScale float64
}
func (_aeed *TextState) Translate(tx, ty float64) {
_aeed.Tm = _aeed.Tm.Mult(_ae.TranslationMatrix(tx, ty))
}
Go
1
https://gitee.com/zhaobingss/unipdf.git
git@gitee.com:zhaobingss/unipdf.git
zhaobingss
unipdf
unipdf
55e877b0b57f

搜索帮助