Пример #1
0
// PixbufAtSize loads an image from disk as pixbuf.
//
func PixbufAtSize(file string, maxW, maxH int) (*gdk.Pixbuf, error) {
	// if _, imgW, imgH := gdk.PixbufGetFileInfo(file); imgW > 0 {
	// 	ratio := math.Min(math.Min(float64(maxW)/float64(imgW), float64(maxH)/float64(imgH)), 1)
	// 	// log.Info("ratio", ratio)
	// 	pix, e := gdk.PixbufNewFromFileAtSize(file, int(float64(imgW)*ratio), int(float64(imgH)*ratio))
	// 	return pix, e
	// }
	// return nil, errors.New("Problem getting file info: " + file)

	return gdk.PixbufNewFromFileAtScale(file, maxW, maxH, true)
}
Пример #2
0
// SetPackage fills the handbook data with a package.
//
func (widget *Handbook) SetPackage(book datatype.Handbooker) {
	title := common.Bold(common.Big(book.GetTitle()))
	if widget.ShowVersion {
		title += " v" + book.GetModuleVersion()
	}
	widget.title.SetMarkup(title)

	author := book.GetAuthor()
	if author != "" {
		author = fmt.Sprintf("by %s", author)
		widget.author.SetMarkup(common.Small(common.Mono(author)))
	}
	widget.author.SetVisible(author != "")

	widget.description.SetMarkup("<span rise='8000'>" + book.GetDescription() + "</span>")

	previewFound := false
	defer func() { widget.previewFrame.SetVisible(previewFound) }()

	file := book.GetPreviewFilePath()
	if file == "" {
		return
	}
	_, w, h := gdk.PixbufGetFileInfo(file)

	var pixbuf *gdk.Pixbuf
	var e error
	if w > PreviewSizeMax || h > PreviewSizeMax {
		pixbuf, e = gdk.PixbufNewFromFileAtScale(file, PreviewSizeMax, PreviewSizeMax, true)
	} else {
		pixbuf, e = gdk.PixbufNewFromFile(file)
	}

	if e == nil && pixbuf != nil {
		previewFound = true
		widget.previewImage.SetFromPixbuf(pixbuf)
	}
}