예제 #1
0
static void
gnm_soi_write_image (SheetObject const *so, char const *format, 
		     G_GNUC_UNUSED double resolution,
		     GsfOutput *output, GError **err)
{
	SheetObjectImage *soi = SHEET_OBJECT_IMAGE (so);
	gboolean res = FALSE;
	GdkPixbuf *pixbuf = go_image_get_pixbuf (soi->image);

	if (!soi->type || strcmp (format, soi->type) == 0) {
		if (soi->bytes.len == 0) {
			gsize length;
			guint8 const *data = go_image_get_data (soi->image, &length);
			res = gsf_output_write (output,	length, data);
		} else
			res = gsf_output_write (output,
						soi->bytes.len, soi->bytes.data);
	} else if (pixbuf)
		res = gdk_pixbuf_save_to_callback (pixbuf,
						   soi_gdk_pixbuf_save, output,
						   format,
						   err, NULL);
	if (pixbuf)
		g_object_unref (pixbuf);
	if (!res && err && *err == NULL)
		*err = g_error_new (gsf_output_error_id (), 0,
				   _("Unknown failure while saving image"));
}
예제 #2
0
static gboolean
zip_header_write (GsfOutfileZip *zip)
{
	static guint8 const header_signature[] =
		{ 'P', 'K', 0x03, 0x04 };
	guint8 hbuf[ZIP_HEADER_SIZE];
	GsfZipDirent *dirent = zip->vdir->dirent;
	char *name = dirent->name;
	int   nlen = strlen (name);
	gboolean ret;

	memset (hbuf, 0, sizeof hbuf);
	memcpy (hbuf, header_signature, sizeof header_signature);
	GSF_LE_SET_GUINT16 (hbuf + ZIP_HEADER_VERSION, 0x14);
	GSF_LE_SET_GUINT16 (hbuf + ZIP_HEADER_FLAGS, dirent->flags);
	GSF_LE_SET_GUINT16 (hbuf + ZIP_HEADER_COMP_METHOD,
			    dirent->compr_method);
	GSF_LE_SET_GUINT32 (hbuf + ZIP_HEADER_TIME, dirent->dostime);
	GSF_LE_SET_GUINT16 (hbuf + ZIP_HEADER_NAME_LEN, nlen);
	ret = gsf_output_write (zip->sink, sizeof hbuf, hbuf);
	if (ret)
		ret = gsf_output_write (zip->sink, nlen, name);

	return ret;
}
예제 #3
0
static gboolean
zip_dirent_write (GsfOutput *sink, GsfZipDirent *dirent)
{
	static guint8 const dirent_signature[] =
		{ 'P', 'K', 0x01, 0x02 };
	guint8 buf[ZIP_DIRENT_SIZE];
	int nlen = strlen (dirent->name);
	gboolean ret;

	memset (buf, 0, sizeof buf);
	memcpy (buf, dirent_signature, sizeof dirent_signature);
	GSF_LE_SET_GUINT16 (buf + ZIP_DIRENT_ENCODER, 0x317); /* Unix */
	GSF_LE_SET_GUINT16 (buf + ZIP_DIRENT_EXTRACT, 0x14);
	GSF_LE_SET_GUINT16 (buf + ZIP_DIRENT_FLAGS, dirent->flags);
	GSF_LE_SET_GUINT16 (buf + ZIP_DIRENT_COMPR_METHOD,
			    dirent->compr_method);
	GSF_LE_SET_GUINT32 (buf + ZIP_DIRENT_DOSTIME, dirent->dostime);
	GSF_LE_SET_GUINT32 (buf + ZIP_DIRENT_CRC32, dirent->crc32);
	GSF_LE_SET_GUINT32 (buf + ZIP_DIRENT_CSIZE, dirent->csize);
	GSF_LE_SET_GUINT32 (buf + ZIP_DIRENT_USIZE, dirent->usize);
	GSF_LE_SET_GUINT16 (buf + ZIP_DIRENT_NAME_SIZE, nlen);
	GSF_LE_SET_GUINT16 (buf + ZIP_DIRENT_EXTRAS_SIZE, 0);
	GSF_LE_SET_GUINT16 (buf + ZIP_DIRENT_COMMENT_SIZE, 0);
	GSF_LE_SET_GUINT16 (buf + ZIP_DIRENT_DISKSTART, 0);
	GSF_LE_SET_GUINT16 (buf + ZIP_DIRENT_FILE_TYPE, 0);
	/* Hardcode file mode 644 */
	GSF_LE_SET_GUINT32 (buf + ZIP_DIRENT_FILE_MODE, 0644 << 16);
	GSF_LE_SET_GUINT32 (buf + ZIP_DIRENT_OFFSET, dirent->offset);

	ret = gsf_output_write (sink, sizeof buf, buf);
	if (ret)
		ret = gsf_output_write (sink, nlen, dirent->name);

	return ret;
}
예제 #4
0
/* Utility routine to generate a BAT for a file known to be sequential and
 * continuous. */
static void
ole_write_bat (GsfOutput *sink, guint32 block, unsigned blocks)
{
	guint8 buf [BAT_INDEX_SIZE];

/* FIXME FIXME FIXME  optimize this to dump a buffer in 1 step */
	while (blocks-- > 1) {
		block++;
		GSF_LE_SET_GUINT32 (buf, block);
		gsf_output_write (sink, BAT_INDEX_SIZE, buf);
	}
	GSF_LE_SET_GUINT32 (buf, BAT_MAGIC_END_OF_CHAIN);
	gsf_output_write (sink, BAT_INDEX_SIZE, buf);
}
예제 #5
0
static gboolean
gsf_output_csv_write (GsfOutput *output,
		      size_t num_bytes, guint8 const *data)
{
	GsfOutputCsv *csv = GSF_OUTPUT_CSV (output);
	return gsf_output_write (csv->sink, num_bytes, data);
}
예제 #6
0
/**
 * gsf_structured_blob_write:
 * @blob: #GsfStructuredBlob
 * @container: #GsfOutfile
 *
 * Dumps structured blob @blob onto the @container.  Will fail if the output is
 * not an Outfile and blob has multiple streams.
 *
 * Returns: %TRUE on success.
 **/
gboolean
gsf_structured_blob_write (GsfStructuredBlob *blob, GsfOutfile *container)
{
	GsfOutput *output;
	gboolean has_kids;

	g_return_val_if_fail (GSF_IS_STRUCTURED_BLOB (blob), FALSE);
	g_return_val_if_fail (GSF_IS_OUTFILE (container), FALSE);

	has_kids = (blob->children != NULL && blob->children->len > 0);

	output = gsf_outfile_new_child  (GSF_OUTFILE (container),
		gsf_input_name (GSF_INPUT (blob)),
		has_kids);
	if (has_kids) {
		GsfStructuredBlob *child_blob;
		unsigned i;

		for (i = 0 ; i < blob->children->len ; i++) {
			child_blob = g_ptr_array_index (blob->children, i);
			if (!gsf_structured_blob_write (child_blob, GSF_OUTFILE (output)))
				return FALSE;
		}
	}

	if (blob->data != NULL)
		gsf_output_write (output, blob->data->size, blob->data->buf);
	gsf_output_close (output);
	g_object_unref (output);

	return TRUE;
}
예제 #7
0
static void
pwcsv_print_encoded (GsfOutput *output, char const *str)
{
    gunichar c;
    gchar *encoded;

    if (str == NULL)
        return;

    gsf_output_puts (output, "\"");
    for (; *str != '\0' ; str = g_utf8_next_char (str)) {
        switch (*str) {
            case '"':
                gsf_output_puts (output, "\"\"");
                break;
            default:
                c = g_utf8_get_char (str);
                if (((c >= 0x20) && (c < 0x80)) || (c == '\n') || (c == '\r') || (c == '\t')) {
                    gsf_output_write (output, 1, (guint8 *)str);
                } else {
                    c = g_utf8_get_char (str);
                    encoded = g_ucs4_to_utf8(&c, 1, NULL, NULL, NULL);
                    gsf_output_puts (output, encoded);
                    g_free(encoded);
                }
                break;
        }
    }
    gsf_output_puts (output, "\",");
}
예제 #8
0
/* write the metadata (dirents, small block, xbats) and close the sink */
static gboolean
gsf_outfile_msole_close_root (GsfOutfileMSOle *ole)
{
	GsfOutfile *tmp;
	guint8  buf [OLE_HEADER_SIZE];
	guint32	sbat_start, num_sbat, sb_data_start, sb_data_size, sb_data_blocks;
	guint32	bat_start, num_bat, dirent_start, num_dirent_blocks, next, child_index;
	unsigned i, j, blocks, num_xbat, xbat_pos;
	gsf_off_t data_size;
	unsigned metabat_size = ole->bb.size / BAT_INDEX_SIZE - 1;
	GPtrArray *elem = ole->root->content.dir.root_order;

	/* write small block data */
	blocks = 0;
	sb_data_start = ole_cur_block (ole);
	data_size = gsf_output_tell (ole->sink);
	for (i = 0 ; i < elem->len ; i++) {
		GsfOutfileMSOle *child = g_ptr_array_index (elem, i);
		if (child->type == MSOLE_SMALL_BLOCK) {
			gsf_off_t size = gsf_output_size (GSF_OUTPUT (child));
			if (size > 0) {
				child->blocks = ((size - 1) >> ole->sb.shift) + 1;
				gsf_output_write (ole->sink,
						  child->blocks << ole->sb.shift,
						  child->content.small_block.buf);
				child->first_block = blocks;
				blocks += child->blocks;
			} else {
예제 #9
0
uint32_t FileWriterI::fileWrite(int32_t handler, uint8_t * data, uint32_t len) {
    if (handler >=0 && handler < (int32_t)openFileHandler.size()) {
        GsfOutput * output = openFileHandler[handler];

        if (output->is_closed) {
			ERROR << "ops::msole::FileWriterI::fileWrite() : file already closed";
            return ops::RET_ERR;
        }

        if ( data != NULL && len > 0 ) {
                if (!gsf_output_write (output, len, (const guint8*)data)) {
						ERROR << "ops::msole::FileReader::fileWrite() : can't write in file ";
                        return RET_ERR;
                }
        }

		DEBUG << "ops::msole::FileWriterI::fileWrite() : data writed";

        return ops::RET_OK;
    } else {
		ERROR << "ops::msole::FileWriterI::fileWrite() : unknown handler";
        return ops::RET_ERR;
    }

}
예제 #10
0
static void clone(GsfInput * input, GsfOutput * output)
{
    guint8 const *data;
    size_t len;
    int i;

    if (gsf_input_size(input) > 0) {
        while ((len = gsf_input_remaining(input)) > 0) {
            /* copy in odd sized chunks to exercise system */
            if (len > 314)
                len = 314;
            if (NULL == (data = gsf_input_read(input, len, NULL))) {
                g_warning("error reading ?");
                return;
            }
            if (!gsf_output_write(output, len, data)) {
                g_warning("error writing ?");
                return;
            }
        }
    }

    gsf_output_close(output);
    g_object_unref(G_OBJECT(output));
    g_object_unref(G_OBJECT(input));
}
예제 #11
0
gboolean
gsf_output_csv_write_eol (GsfOutputCsv *csv)
{
	g_return_val_if_fail (GSF_IS_OUTPUT_CSV (csv), FALSE);

	csv->fields_on_line = FALSE;
	return gsf_output_write (csv->sink, csv->eol_len, csv->eol);
}
예제 #12
0
static void
ole_pad_zero (GsfOutfileMSOle *ole)
{
	/* no need to bounds check.  len will always be less than bb.size, and
	 * we already check that zero_buf is big enough at creation */
	unsigned len = ole_bytes_left_in_block (ole);
	if (len > 0)
		gsf_output_write (ole->sink, len, zero_buf);
}
예제 #13
0
static void
ole_write_const (GsfOutput *sink, guint32 value, unsigned n)
{
	guint8 buf [BAT_INDEX_SIZE];

	GSF_LE_SET_GUINT32 (buf, value);
	while (n-- > 0)
		gsf_output_write (sink, BAT_INDEX_SIZE, buf);
}
예제 #14
0
void s_XSL_FO_Listener::_handleDataItems(void)
{
	const char * szName = NULL;
    std::string mimeType;
	const UT_ByteBuf * pByteBuf;

	for (UT_uint32 k=0; (m_pDocument->enumDataItems(k, NULL, &szName, &pByteBuf, &mimeType)); k++)
	{	  	  
		UT_sint32 loc = -1;
		for (UT_sint32 i = 0; i < m_utvDataIDs.getItemCount(); i++)
		{
			if(strcmp(reinterpret_cast<const char*>(m_utvDataIDs[i]), szName) == 0)
			{
				loc = i;
				break;
			}
		}

		if(loc > -1)
		{
			UT_UTF8String fname;

			UT_UTF8String_sprintf(fname, "%s_data", m_pie->getFileName());
			UT_go_directory_create(fname.utf8_str(), 0750, NULL);

			if (mimeType == "image/svg+xml")
				UT_UTF8String_sprintf(fname, "%s/%d.svg", fname.utf8_str(), loc);
			else if (mimeType == "application/mathml+xml")
				UT_UTF8String_sprintf(fname, "%s/%d.mathml", fname.utf8_str(), loc);
			else // raster Image
			{  
                const char * extension = "png";
                if(mimeType == "image/jpeg") {
                    extension = "jpg";
                }
				char * temp = _stripSuffix(UT_go_basename(szName), '_');
				char * fstripped = _stripSuffix(temp, '.');
				UT_UTF8String_sprintf(fname, "%s/%s.%s", fname.utf8_str(), fstripped, extension);

				FREEP(temp);
				FREEP(fstripped);
			}
	  
			GsfOutput *fp = UT_go_file_create (fname.utf8_str(), NULL);
	  
			if(!fp)
				continue;
	  
			gsf_output_write(fp, pByteBuf->getLength(), (const guint8 *)pByteBuf->getPointer(0));
			gsf_output_close(fp);
			g_object_unref(fp);
		}
	}

	return;
}
예제 #15
0
static GsfInput *
make_local_copy (GFile *file, GInputStream *stream)
{
    GsfOutput *out;
    GsfInput  *copy;
    GFileInfo *info;

    out = gsf_output_memory_new ();

    while (1) {
        guint8 buf[4096];
        gssize nread;

        nread = g_input_stream_read (stream, buf, sizeof(buf), NULL, NULL);

        if (nread > 0) {
            if (!gsf_output_write (out, nread, buf)) {
                copy = NULL;
                goto cleanup_and_exit;
            }
        }
        else if (nread == 0)
            break;
        else {
            copy = NULL;
            goto cleanup_and_exit;
        }
    }

    copy = gsf_input_memory_new_clone
           (gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (out)),
            gsf_output_size (out));

    if (copy != NULL) {
        info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, NULL);
        if (info) {
            gsf_input_set_name (GSF_INPUT (copy), g_file_info_get_name (info));
            g_object_unref (info);
        }
    }

cleanup_and_exit:

    gsf_output_close (out);
    g_object_unref (out);

    g_input_stream_close (stream, NULL, NULL);
    g_object_unref (stream);

    set_name_from_file (copy, file);

    return copy;
}
예제 #16
0
static gboolean
bzip_output_block (GsfOutputBzip *bzip)
{
	size_t num_bytes = bzip->buf_size - bzip->stream.avail_out;
	
	if (!gsf_output_write (bzip->sink, num_bytes, bzip->buf))
		return FALSE;

	bzip->stream.next_out  = bzip->buf;
	bzip->stream.avail_out = bzip->buf_size;

	return TRUE;
}
예제 #17
0
static GsfInput *
make_local_copy (FILE *stream, const char *filename, GError **err)
{
	GsfOutput *out;
	GsfInput *copy = NULL;

	out = gsf_output_memory_new ();

	while (1) {
		guint8 buf[4096];
		gssize nread;

		nread = fread (buf, 1, sizeof(buf), stream);

		if (nread > 0) {
			if (!gsf_output_write (out, nread, buf))
				goto error;
		} else if (nread == 0)
			break;
		else
			goto error;
	}

	copy = gsf_input_memory_new_clone
		(gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (out)),
		 gsf_output_size (out));

	gsf_output_close (out);
	g_object_unref (out);

	if (filename)
		gsf_input_set_name_from_filename (GSF_INPUT (copy), filename);

	return copy;

error:
	if (err) {
		char *utf8name = filename
			? g_filename_display_name (filename)
			: g_strdup ("?");
		g_set_error (err, gsf_input_error_id (), 0,
			     "%s: not a regular file",
			     utf8name);
		g_free (utf8name);
	}

	gsf_output_close (out);
	g_object_unref (out);

	return NULL;
}
예제 #18
0
static GnmValue *
cb_sylk_write_cell (GnmCellIter const *iter, SylkWriter *state)
{
	GnmValue const *v;
	GnmExprTop const *texpr;
	GnmExprArrayCorner const *array;

	if (iter->pp.eval.row != state->cur_row)
		gsf_output_printf (state->output, "C;Y%d;X%d",
			(state->cur_row = iter->pp.eval.row) + 1,
			iter->pp.eval.col + 1);
	else
		gsf_output_printf (state->output, "C;X%d",
			iter->pp.eval.col + 1);

	if (NULL != (v = iter->cell->value)) {
		if (VALUE_IS_STRING (v)) {
			gsf_output_write (state->output, 3, ";K\"");
			sylk_write (state, v->v_str.val->str);
			gsf_output_write (state->output, 1, "\"");
		} else if (VALUE_IS_NUMBER (v) || VALUE_IS_ERROR (v)) {
			GString *res = g_string_sized_new (10);
			value_get_as_gstring (v, res, state->convs);
			gsf_output_write (state->output, 2, ";K");
			gsf_output_write (state->output, res->len, res->str);
			g_string_free (res, TRUE);
		} /* ignore the rest */
	}

	if (NULL != (texpr = iter->cell->base.texpr)) {
		if (NULL != (array = gnm_expr_top_get_array_corner (texpr))) {
			gsf_output_printf (state->output, ";R%d;C%d;M",
				iter->pp.eval.row + array->rows,
				iter->pp.eval.col + array->cols);
		} else if (gnm_expr_top_is_array_elem (texpr, NULL, NULL)) {
			gsf_output_write (state->output, 2, ";I");
			texpr = NULL;
		} else
			gsf_output_write (state->output, 2, ";E");

		if (texpr != NULL) {
			GnmConventionsOut out;
			out.accum = g_string_new (NULL);
			out.pp    = &iter->pp;
			out.convs = state->convs;
			gnm_expr_top_as_gstring (texpr, &out);
			sylk_write (state, out.accum->str);
			g_string_free (out.accum, TRUE);
		}
	}
	gsf_output_write (state->output, 2, "\r\n");
	return NULL;
}
static gboolean
soi_gdk_pixbuf_save (gchar const *buf,
		     gsize count,
		     GError **error,
		     gpointer data)
{
	GsfOutput *output = GSF_OUTPUT (data);
	gboolean ok = gsf_output_write (output, count, buf);

	if (!ok && error)
		*error = g_error_copy (gsf_output_error (output));

	return ok;
}
예제 #20
0
static GnmValue *
cb_get_content (GnmCellIter const *iter, GsfOutput *buf)
{
	GnmCell *cell;

	if (NULL != (cell = iter->cell)) {
		char *tmp;
		if (gnm_cell_has_expr (cell))
			tmp = gnm_expr_top_as_string (cell->base.texpr,
				&iter->pp, iter->pp.sheet->convs);
		else if (VALUE_FMT (cell->value) != NULL)
			tmp = format_value (NULL, cell->value, -1,
				workbook_date_conv (iter->pp.wb));
		else
			tmp = value_get_as_string (cell->value);

		gsf_output_write (buf, strlen (tmp), tmp);
		g_free (tmp);
	}
	gsf_output_write (buf, 1, "\n");

	return NULL;
}
예제 #21
0
static void
sylk_write_sheet (SylkWriter *state)
{
	GnmRange extent;

/* collect style and font info */
	extent = sheet_get_extent (state->sheet, FALSE, TRUE);
	sheet_style_foreach (state->sheet,
			     (GFunc)cb_sylk_collect_styles, state);
	sheet_cell_foreach (state->sheet,
			    (GHFunc)cb_sylk_collect_cell_styles, state);

	/*
	 * 1) formats P;P.....
	 * 2.1) ??	fonts   P;F....
	 * 2.2) indexed fonts   P;E....
	 * 3) global formats F;
	 */

/* Global Formatting */
	/* F;P0;DG0G10;SM0;Z;M280;N3 10 */

/* Bounds */
	gsf_output_printf (state->output, "B;Y%d;X%d;D0 0 %d %d\r\n",
		extent.end.row + 1,	extent.end.col + 1,
		extent.end.row,		extent.end.col);

/* Global options */
	gsf_output_printf (state->output, "O;%c%d %f",
		(state->wb->iteration.enabled ? 'A' : 'G'),
		state->wb->iteration.max_number,
		state->wb->iteration.tolerance);
	if (!state->sheet->convs->r1c1_addresses)
		gsf_output_puts (state->output, ";L");
	if (!state->wb->recalc_auto)
		gsf_output_puts (state->output, ";M");
	gsf_output_printf (state->output, ";V%d",
		workbook_date_conv (state->wb)->use_1904 ? 4 : 0);
	if (state->sheet->hide_zero)
		gsf_output_puts (state->output, ";Z");
	gsf_output_write (state->output, 2, "\r\n");

/* dump content */
	state->cur_row = -1;
	sheet_foreach_cell_in_range (state->sheet, CELL_ITER_IGNORE_BLANK,
		extent.start.col, extent.start.row,
		extent.end.col,   extent.end.row,
		(CellIterFunc) cb_sylk_write_cell, state);
}
예제 #22
0
static void
clone (GsfInput *input, GsfOutput *output)
{
	guint8 const *data;
	size_t len;
	int i;

	if (gsf_input_size (input) > 0) {
		while ((len = gsf_input_remaining (input)) > 0) {
			/* copy in odd sized chunks to exercise system */
			if (len > 314)
				len = 314;
			if (NULL == (data = gsf_input_read (input, len, NULL))) {
				g_warning ("error reading ?");
				return;
			}
			if (!gsf_output_write (output, len, data)) {
				g_warning ("error writing ?");
				return;
			}
		}
	} 

	/* See test-cp-msole.c for explanation how to distinct directories
	 * from regular files.
	 */
	if (GSF_IS_INFILE (input) &&
	    gsf_infile_num_children (GSF_INFILE (input)) > 0) {
		GsfInfile *in = GSF_INFILE (input);
		GsfOutfile *out = GSF_OUTFILE (output);
		GsfInput *src;
		GsfOutput *dst;
		gboolean is_dir;

		for (i = 0 ; i < gsf_infile_num_children (in) ; i++) {
			src = gsf_infile_child_by_index (in, i);
			is_dir = GSF_IS_INFILE (src) &&
				gsf_infile_num_children (GSF_INFILE (src)) >= 0;
			dst = gsf_outfile_new_child  (out,
				gsf_infile_name_by_index (in, i),
				is_dir);
			clone (src, dst);
		}
	}

	gsf_output_close (output);
	g_object_unref (G_OBJECT (output));
	g_object_unref (G_OBJECT (input));
}
예제 #23
0
bool UT_ByteBuf::writeToURI(const char* pszURI) const
{
	UT_ASSERT(pszURI && pszURI[0]);
	
	GsfOutput *fp = UT_go_file_create(pszURI, NULL);
	if (!fp)
	  return false;

	gboolean res = gsf_output_write(fp, m_iSize, (guint8*)m_pBuf);

	gsf_output_close(fp);
	g_object_unref(G_OBJECT(fp));

	return static_cast<bool>(res);
}
예제 #24
0
static void
sylk_write (SylkWriter *state, char const *str)
{
	char const *p, *next;
	gunichar c;

	/* export the valid chunks */
	for (p = str ; *p ; p = next) {
		next = g_utf8_next_char (p);
		c = g_utf8_get_char (p);

		if (c == ';') {
			gsf_output_write (state->output, p - str, str);
			gsf_output_write (state->output, 2, ";;");
			str = next;
		} else if ((next - p) > 1) {
			gsf_output_write (state->output, p - str, str);
			gsf_output_write (state->output, 1, "?");
			str = next;
		}
#warning handle the magic ascii escaping
	}
	gsf_output_write (state->output, p - str, str);
}
예제 #25
0
UT_uint32 IE_Exp_AbiWord_1::_writeBytes(const UT_Byte * pBytes, UT_uint32 length)
{
	if(!pBytes || !length)
	  return 0;

	if (m_output)
		{
			gsf_output_write(m_output, length, pBytes);
			return length;
		}
	else
		{
			return IE_Exp::_writeBytes(pBytes, length);
		}
}
예제 #26
0
static gboolean
zip_output_block (GsfOutfileZip *zip)
{
	size_t num_bytes = zip->buf_size - zip->stream->avail_out;
	GsfZipDirent *dirent = zip->vdir->dirent;

	if (!gsf_output_write (zip->sink, num_bytes, zip->buf)) {
		return FALSE;
	}
	dirent->csize += num_bytes;
	zip->stream->next_out  = zip->buf;
	zip->stream->avail_out = zip->buf_size;

	return TRUE;
}
예제 #27
0
파일: dzsave.c 프로젝트: eeertekin/libvips
static int
write_blank( VipsForeignSaveDz *dz )
{
	VipsImage *x, *t;
	int n;
	VipsArea *ones;
	double *d;
	int i;
	void *buf;
	size_t len;
	GsfOutput *out; 

	if( vips_black( &x, dz->tile_size, dz->tile_size, NULL ) ) 
		return( -1 );

	vips_area_get_data( (VipsArea *) dz->background, NULL, &n, NULL, NULL );
	ones = vips_area_new_array( G_TYPE_DOUBLE, sizeof( double ), n );
	d = (double *) vips_area_get_data( ones, NULL, NULL, NULL, NULL );
	for( i = 0; i < n; i++ )
		d[i] = 1.0; 
	if( vips_linear( x, &t, 
		d, 
		(double *) vips_area_get_data( (VipsArea *) dz->background, 
			NULL, NULL, NULL, NULL ),
		n, NULL ) ) {
		vips_area_unref( ones );
		g_object_unref( x );
		return( -1 );
	}
	vips_area_unref( ones );
	g_object_unref( x );
	x = t;

	if( vips_pngsave_buffer( x, &buf, &len, NULL ) ) {
		g_object_unref( x );
		return( -1 );
	}
	g_object_unref( x );

	out = vips_gsf_path( dz->tree, "blank.png", NULL ); 
	gsf_output_write( out, len, buf );
	gsf_output_close( out );
	g_object_unref( out );

	g_free( buf );

	return( 0 );
}
예제 #28
0
static gboolean
zip_trailer_write (GsfOutfileZip *zip, unsigned entries, gsf_off_t dirpos)
{
	static guint8 const trailer_signature[] =
		{ 'P', 'K', 0x05, 0x06 };
	guint8 buf[ZIP_TRAILER_SIZE];
	gsf_off_t pos = gsf_output_tell (zip->sink);

	memset (buf, 0, sizeof buf);
	memcpy (buf, trailer_signature, sizeof trailer_signature);
	GSF_LE_SET_GUINT16 (buf + ZIP_TRAILER_ENTRIES, entries);
	GSF_LE_SET_GUINT16 (buf + ZIP_TRAILER_TOTAL_ENTRIES, entries);
	GSF_LE_SET_GUINT32 (buf + ZIP_TRAILER_DIR_SIZE, pos - dirpos);
	GSF_LE_SET_GUINT32 (buf + ZIP_TRAILER_DIR_POS, dirpos);

	return gsf_output_write (zip->sink, sizeof buf, buf);
}
예제 #29
0
/*
 * html_print_encoded:
 *
 * @output: the stream
 * @str: the string
 *
 * print the string to output encoded all special chars
 *
 */
static void
html_print_encoded (GsfOutput *output, char const *str)
{
    gunichar c;
    gchar *encoded;

	if (str == NULL)
		return;
	for (; *str != '\0' ; str = g_utf8_next_char (str)) {
		switch (*str) {
            case '"':
                gsf_output_puts (output, "\"\"");
                break;
            case '<':
				gsf_output_puts (output, "&lt;");
				break;
			case '>':
				gsf_output_puts (output, "&gt;");
				break;
			case '&':
				gsf_output_puts (output, "&amp;");
				break;
			case '\n':
				gsf_output_puts (output, "<br />\n");
				break;
			case '\r':
				gsf_output_puts (output, "<br />\r");
				if( *(str+1) == '\n' ) {
					gsf_output_puts (output, "\n");
					str++;
				}
				break;
			default:
                c = g_utf8_get_char (str);
                if (((c >= 0x20) && (c < 0x80)) || (c == '\n') || (c == '\r') || (c == '\t')) {
                    gsf_output_write (output, 1, (guint8 *)str);
                } else {
                    c = g_utf8_get_char (str);
                    encoded = g_ucs4_to_utf8(&c, 1, NULL, NULL, NULL);
                    gsf_output_puts (output, encoded);
                    g_free(encoded);
                }
                break;
		}
	}
}
예제 #30
0
/* Write the per stream data descriptor */
static gboolean
zip_ddesc_write (GsfOutfileZip *zip)
{
	static guint8 const ddesc_signature[] =
		{ 'P', 'K', 0x07, 0x08 };
	guint8 buf[16];
	GsfZipDirent *dirent = zip->vdir->dirent;

	memcpy (buf, ddesc_signature, sizeof ddesc_signature);
	GSF_LE_SET_GUINT32 (buf + 4, dirent->crc32);
	GSF_LE_SET_GUINT32 (buf + 8, dirent->csize);
	GSF_LE_SET_GUINT32 (buf + 12, dirent->usize);
	if (!gsf_output_write (zip->sink, sizeof buf, buf)) {
		return FALSE;
	}

	return TRUE;
}