~sbinet/star-tex

7dbbac8ac24d73db9e18b2a859f2d62ebf9f3030 — Sebastien Binet 4 months ago 5f7eb3f
dvi: add the ability to setup x,y-offset (x,y-margins)

Signed-off-by: Sebastien Binet <s@sbinet.org>
3 files changed, 32 insertions(+), 3 deletions(-)

M dvi/machine.go
M dvi/option.go
M dvi/state.go
M dvi/machine.go => dvi/machine.go +6 -1
@@ 29,6 29,8 @@ type Machine struct {

	conv     float32 // converts DVI units to pixels
	trueConv float32 // converts unmagnified DVI units to pixels
	xoff     int32   // width offset
	yoff     int32   // height offset

	w   io.Writer
	buf []byte // 80-col buffer of text


@@ 49,6 51,9 @@ func NewMachine(opts ...Option) Machine {
		rdr:   cfg.rdr,
		state: newState(),

		xoff: cfg.xoff,
		yoff: cfg.yoff,

		w:   cfg.out,
		buf: make([]byte, 0, 80-len("[]\n")),
	}


@@ 116,7 121,7 @@ func (m *Machine) run(p Program, ip int) error {

	bop := op.cmd().(*CmdBOP)
	bop.read(p.r)
	m.state.reset()
	m.state.reset(m.xoff, m.yoff, m.pixels)

	m.printf(" \n%d: beginning of page %d \n", beg, bop.C0)


M dvi/option.go => dvi/option.go +18 -0
@@ 7,6 7,7 @@ package dvi
import (
	"io"

	"star-tex.org/x/tex/font/fixed"
	"star-tex.org/x/tex/kpath"
)



@@ 16,6 17,9 @@ type config struct {
	ctx kpath.Context
	rdr Renderer
	out io.Writer

	xoff int32 // width offset
	yoff int32 // height offset
}

func newConfig() *config {


@@ 46,3 50,17 @@ func WithLogOutput(w io.Writer) Option {
		return nil
	}
}

func WithOffsetX(v fixed.Int12_20) Option {
	return func(cfg *config) error {
		cfg.xoff = int32(v)
		return nil
	}
}

func WithOffsetY(v fixed.Int12_20) Option {
	return func(cfg *config) error {
		cfg.yoff = int32(v)
		return nil
	}
}

M dvi/state.go => dvi/state.go +8 -2
@@ 43,9 43,15 @@ func newState() state {
	}
}

func (st *state) reset() {
func (st *state) reset(xoff, yoff int32, pixels func(v int32) int32) {
	st.stack = st.stack[:1]
	st.stack[0] = regs{}
	st.stack[0] = regs{
		h: xoff,
		v: yoff,

		hh: pixels(xoff),
		vv: pixels(yoff),
	}
	st.f = -1
}