Ejemplo n.º 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
}
Ejemplo n.º 2
0
func GenerateTweetInfo(W *XWindow, t *anaconda.Tweet) *TweetInfo {
	var text string
	if t.RetweetedStatus != nil {
		text = fmt.Sprintf("<i><small>%s</small></i> <span color='#5C5'>⇄</span> <b>%s</b> <small>@%s</small>\n%s", html.EscapeString(t.User.Name),
			t.RetweetedStatus.User.Name, t.RetweetedStatus.User.ScreenName,
			html.EscapeString(t.RetweetedStatus.Text))

	} else {
		text = fmt.Sprintf("<b>%s</b> <small>@%s</small>\n%s",
			html.EscapeString(t.User.Name),
			t.User.ScreenName,
			html.EscapeString(t.Text))
	}
	text = strings.Replace(text, "&amp;", "&", -1)
	text = replaceURLS(text, func(s string) string { return "<span color='#88F'>" + s + "</span>" })
	text += "\n<span size='x-large' color='#777'>↶     "

	// Add favorite icon
	favoriteColor := "#777"
	favoriteText := "      "
	favoriteCount := t.FavoriteCount
	if t.RetweetedStatus != nil {
		favoriteCount = t.RetweetedStatus.FavoriteCount
	}
	if favoriteCount > 0 {
		favoriteText = fmt.Sprintf("<span size='medium'> %-4d </span>", favoriteCount)
	}
	if t.Favorited {
		favoriteColor = "#D22"
	}
	text += fmt.Sprintf("<span color='%s'>❤</span><span size='medium'>%s</span>", favoriteColor, favoriteText)

	// Add RT icon
	retweetColor := "#777"
	retweetText := "      "
	if t.Retweeted {
		retweetColor = "#3D3"
	}
	retweetCount := t.RetweetCount
	if t.RetweetedStatus != nil {
		retweetCount = t.RetweetedStatus.RetweetCount
	}
	if retweetCount > 0 {
		retweetText = fmt.Sprintf("<span size='medium'> %-4d </span>", retweetCount)
	}
	text += fmt.Sprintf("<span color='%s'>⇄</span>%s", retweetColor, retweetText)

	// Add "more options" icon
	text += "<span color='#777'>…</span></span>"

	userImageUrl := t.User.ProfileImageURL
	if t.RetweetedStatus != nil {
		userImageUrl = t.RetweetedStatus.User.ProfileImageURL
	}

	errorText := "[[INTERNAL ERROR, COULD NOT PROCESS TWEET]]"

	var strippedText *C.char = nil //&outputText[0]

	// Generate tweet layout
	if C.pango_parse_markup(C.CString(text), -1, 0,
		&W.AttrList,
		&strippedText, nil, nil) != 1 {
		fmt.Println("error parsing", text)
		strippedText = C.CString(errorText)
	}

	layout := getLayout()
	C.pango_layout_set_font_description(layout, W.FontDesc)
	C.pango_layout_set_attributes(layout, W.AttrList)
	C.pango_layout_set_text(layout, strippedText, -1)

	Result := TweetInfo{
		ID:        t.Id,
		Text:      t.Text,
		UserImage: userImageUrl,
		Layout:    layout,
	}

	return &Result
}
Ejemplo n.º 3
0
func (v *Layout) SetFontDescription(desc *FontDescription) {
	C.pango_layout_set_font_description(v.native(), desc.native())
}
Ejemplo n.º 4
0
func (v *Layout) SetFontDescription(d *FontDescription) {
	C.pango_layout_set_font_description(v.GLayout, d.GFontDescription)
}