~sbinet/star-tex

5a592cd3ee8f28d9160ea83e7cae3a01a633eb64 — Sebastien Binet 4 months ago 7dbbac8
dvi: export Metrics, Name and Size from Font

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

M dvi/font.go
M dvi/machine.go
M dvi/font.go => dvi/font.go +15 -2
@@ 12,12 12,25 @@ import (
// Font describes a DVI font, with TeX Font Metrics and its
// associated font glyph data.
type Font struct {
	name  string
	font  tfm.Font
	scale fixed.Int12_20
}

func (fnt *Font) name() string {
	return fnt.font.Name()
// Name returns the name of the DVI font.
// ex: "cmr10", "cmmi10" or "cmti10".
func (fnt *Font) Name() string {
	return fnt.name
}

// Size returns the DVI font size.
func (fnt *Font) Size() fixed.Int12_20 {
	return fnt.scale
}

// Metrics returns the associated TeX Font Metrics.
func (fnt *Font) Metrics() *tfm.Font {
	return &fnt.font
}

func (fnt *Font) advance(r rune) (fixed.Int12_20, bool) {

M dvi/machine.go => dvi/machine.go +2 -1
@@ 936,7 936,7 @@ func (m *Machine) drawGlyph(op opCode, cmd int32) error {

	adv, ok := fnt.advance(rune(cmd))
	if !ok {
		return fmt.Errorf("dvi: font %q has no glyph %c", fnt.name(), cmd)
		return fmt.Errorf("dvi: font %q has no glyph %c", fnt.name, cmd)
	}

	if op >= opPut1 {


@@ 1083,6 1083,7 @@ func (m *Machine) loadFont(i int) (*Font, error) {
	}

	def.font = &Font{
		name:  def.Name,
		font:  font,
		scale: fixed.Int12_20(def.Size),
	}