コード例 #1
0
ファイル: tweetslist.go プロジェクト: jonvaldes/gowitt
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
}
コード例 #2
0
ファイル: pango-layout.go プロジェクト: Lazyshot/gotk3
//void           pango_layout_set_attributes (PangoLayout    *layout,
//					    PangoAttrList  *attrs);
func (v *Layout) SetAttributes(attrs *AttrList) {
	C.pango_layout_set_attributes(v.native(), attrs.native())
}