示例#1
0
func (t *PDFStreamTextObject) WriteAt(text string, props TypesettingProps, x float64, y float64) error {
	var layout *C.PangoLayout
	var font_description *C.PangoFontDescription

	font_description = C.pango_font_description_new()
	cfontname := C.CString(props.Fontname)
	defer C.free(unsafe.Pointer(cfontname))
	C.pango_font_description_set_family(font_description, cfontname)
	C.pango_font_description_set_weight(font_description, C.PANGO_WEIGHT_NORMAL)
	C.pango_font_description_set_absolute_size(font_description, C.double(props.Fontsize)*C.PANGO_SCALE)

	layout = C.pango_cairo_create_layout(t.context)
	C.pango_layout_set_font_description(layout, font_description)
	width := props.PageWidth - props.LeftMargin - props.RightMargin
	fmt.Printf("width is %f\n", width)
	C.pango_layout_set_width(layout, C.int(width*C.PANGO_SCALE))
	C.pango_layout_set_justify(layout, C.TRUE)
	ctext := C.CString(text)
	defer C.free(unsafe.Pointer(ctext))
	C.pango_layout_set_text(layout, ctext, -1)

	C.cairo_set_source_rgb(t.context, 0.0, 0.0, 0.0)
	C.cairo_move_to(t.context, C.double(x), C.double(y))
	skip := props.Baselineskip
	nlines := int(C.pango_layout_get_line_count(layout))
	for i := 0; i < nlines; i++ {
		C.cairo_move_to(t.context, C.double(x), C.double(y+float64(i)*skip))
		C.pango_cairo_show_layout_line(t.context, C.pango_layout_get_line(layout, C.int(i)))
	}

	C.g_object_unref(C.gpointer(layout))
	C.pango_font_description_free(font_description)
	return nil
}
示例#2
0
func getLayout() *C.PangoLayout {
	if len(layoutsCache.Layouts) == 0 {
		return C.pango_cairo_create_layout(layoutsCache.Cairo)
	}
	result := layoutsCache.Layouts[len(layoutsCache.Layouts)-1]
	layoutsCache.Layouts = layoutsCache.Layouts[:len(layoutsCache.Layouts)-1]
	return result
}
示例#3
0
func CreateLayout(cr0 *cairo.Context) *pango.Layout {
	var cr1 *C.cairoContext
	if cr0 != nil {
		cr1 = (*C.cairoContext)(cr0.C)
	}
	ret1 := C.pango_cairo_create_layout(cr1)
	var ret2 *pango.Layout
	ret2 = (*pango.Layout)(gobject.ObjectWrap(unsafe.Pointer(ret1), false))
	return ret2
}
示例#4
0
//PangoLayout *pango_cairo_create_layout (cairo_t     *cr);
func CairoCreateLayout(cr *cairo.Context) *Layout {
	c := C.pango_cairo_create_layout(cairo_context(cr))
	layout := new(Layout)
	layout.pangoLayout = (*C.PangoLayout)(c)
	return layout
}