Exemplo n.º 1
0
func (pw *PageWriter) init(dw *DocWriter, options options.Options) *PageWriter {
	pw.dw = dw
	pw.options = options
	pw.lineSpacing = options.FloatDefault("line_spacing", 1.0)
	pw.units = UnitConversions[options.StringDefault("units", "pt")]
	ps := newPageStyle(options)
	pw.pageHeight = ps.pageSize.y2
	pw.pageWidth = ps.pageSize.x2
	pw.page = newPage(pw.dw.nextSeq(), 0, pw.dw.catalog.pages)
	pw.page.setMediaBox(ps.pageSize)
	pw.page.setCropBox(ps.cropSize)
	pw.page.setRotate(ps.rotate)
	pw.page.setResources(pw.dw.resources)
	pw.dw.file.body.add(pw.page)
	pw.autoPath = true
	pw.mw = newMiscWriter(&pw.stream)
	pw.tw = newTextWriter(&pw.stream)
	pw.gw = newGraphWriter(&pw.stream)

	return pw
}
Exemplo n.º 2
0
func New(family string, options options.Options, fontSources FontSources) (*Font, error) {
	font := &Font{
		family:       family,
		Weight:       options.StringDefault("weight", ""),
		style:        options.StringDefault("style", ""),
		RelativeSize: options.FloatDefault("relative_size", 100) / 100.0,
	}
	if Ranges, ok := options["ranges"]; ok {
		switch Ranges := Ranges.(type) {
		case []string:
			font.Ranges = Ranges
		case RuneSet:
			font.RuneSet = Ranges
		}
	}
	var err error
	for _, fontSource := range fontSources {
		if font.metrics, err = fontSource.Select(font.family, font.Weight, font.style, font.Ranges); err == nil {
			font.subType = fontSource.SubType()
			return font, nil
		}
	}
	return nil, err
}
Exemplo n.º 3
0
func (pw *PageWriter) PrintWithOptions(text string, options options.Options) (err error) {
	var para []*rich_text.RichText
	rt, err := pw.richTextForString(text)
	if err != nil {
		return
	}
	if width := options.FloatDefault("width", 0); width > 0 {
		flags := make([]wordbreaking.Flags, rt.Len())
		wordbreaking.MarkRuneAttributes(rt.String(), flags)
		para = rt.WrapToWidth(pw.units.toPts(width), flags, false)
	} else {
		para = []*rich_text.RichText{rt}
	}
	pw.PrintParagraph(para)
	return nil
}