Example #1
0
File: glib.go Project: leif/go-gtk
func FilenameToUri(filename string, hostname string) (uri string, err error) {
	pfilename := C.CString(filename)
	defer C.free_string(pfilename)
	phostname := C.CString(hostname)
	defer C.free_string(phostname)
	var gerror *C.GError
	uri = C.GoString(C.to_charptr(C.g_filename_to_uri(C.to_gcharptr(pfilename), C.to_gcharptr(phostname), &gerror)))
	if unsafe.Pointer(gerror) != nil {
		err = ErrorFromNative(unsafe.Pointer(gerror))
	} else {
		err = nil
	}
	return
}
Example #2
0
func PopplerDocumentNewFromFile(filename string) (PopplerDocument, error) {
	filename, err := filepath.Abs(filename)
	if err != nil {
		return 0, err
	}

	cFilename := (*C.gchar)(C.CString(filename))
	defer C.free(unsafe.Pointer(cFilename))

	var gerr *C.GError
	uri := C.g_filename_to_uri(cFilename, nil, &gerr)
	if uri == nil || gerr != nil {
		return 0, gErrorToGoError(gerr)
	}
	defer C.g_free(C.gpointer(uri))

	doc := C.poppler_document_new_from_file((*C.char)(uri), nil, &gerr)
	if gerr != nil {
		return 0, gErrorToGoError(gerr)
	}

	return PopplerDocument(unsafe.Pointer(doc)), nil
}