Example #1
0
static void
pdf__setdashpattern(PDF *p, float *darray, int length, float phase)
{
    pdf_gstate *gs = &p->gstate[p->sl];

    /* length == 0 or 1 means solid line */
    if (length < 2)
    {
        if (gs->dashed || PDF_FORCE_OUTPUT())
        {
            pdc_puts(p->out, "[] 0 d\n");
            gs->dashed = pdc_false;
        }
    }
    else
    {
        int i;

        pdc_puts(p->out, "[");
        for (i = 0; i < length; i++)
        {
            pdc_printf(p->out, "%f ", darray[i]);
        }
        pdc_printf(p->out, "] %f d\n", phase);
        gs->dashed = pdc_true;
    }
}
Example #2
0
void
pdf__clip(PDF *p)
{
    if (p->curr_ppt->fillrule == pdf_fill_winding)
        pdc_puts(p->out, "W n\n");
    else if (p->curr_ppt->fillrule == pdf_fill_evenodd)
        pdc_puts(p->out, "W* n\n");

    pdf_end_path(p);
}
Example #3
0
void
pdf__closepath_fill_stroke(PDF *p)
{
    if (p->curr_ppt->fillrule == pdf_fill_winding)
        pdc_puts(p->out, "b\n");
    else if (p->curr_ppt->fillrule == pdf_fill_evenodd)
        pdc_puts(p->out, "b*\n");

    pdf_end_path(p);
}
Example #4
0
pdc_bool
pdc_init_output(
    void *opaque,
    pdc_output *out,
    const char *filename,
    FILE *fp,
    size_t (*writeproc)(pdc_output *out, void *data, size_t size),
    int compatibility)
{
    static const char *fn = "pdc_init_output";
    pdc_core *pdc = out->pdc;
    int i;

    out->lastobj = 0;

    if (out->file_offset == NULL) {
	out->file_offset_capacity = + ID_CHUNKSIZE;

	out->file_offset = (long *) pdc_malloc(pdc,
		sizeof(long) * out->file_offset_capacity, fn);
    }

    for (i = 1; i < out->file_offset_capacity; ++i)
	out->file_offset[i] = PDC_BAD_ID;

    out->compresslevel	= PDF_DEFAULT_COMPRESSION;
    out->compr_changed	= pdc_false;

    out->opaque		= opaque;

    memcpy(out->id[0], out->id[1], MD5_DIGEST_LENGTH);


    if (!pdc_init_stream(pdc, out, filename, fp, writeproc))
	return pdc_false;

    /* Write the document header */
    if (compatibility == PDC_1_5)
	pdc_puts(out, "%PDF-1.5\n");
    else if (compatibility == PDC_1_4)
	pdc_puts(out, "%PDF-1.4\n");
    else
	pdc_puts(out, "%PDF-1.3\n");

    /* binary magic number */
#define PDC_MAGIC_BINARY "\045\344\343\317\322\012"
    pdc_write(out, PDC_MAGIC_BINARY, sizeof(PDC_MAGIC_BINARY) - 1);

    return pdc_true;
}
Example #5
0
void
pdf_write_page_extgstates(PDF *p)
{
    int i, total = 0;
    int bias = p->curr_ppt->eg_bias;

    for (i = 0; i < p->extgstates_number; i++)
	if (p->extgstates[i].used_on_current_page)
	    total++;

    if (total > 0 || bias)
    {
	pdc_puts(p->out, "/ExtGState");
	pdc_begin_dict(p->out);
    }

    if (total > 0)
    {
	for (i = 0; i < p->extgstates_number; i++)
	{
	    if (p->extgstates[i].used_on_current_page)
	    {
		p->extgstates[i].used_on_current_page = pdc_false; /* reset */
		pdc_printf(p->out, "/GS%d", bias + i);
		pdc_objref(p->out, "", p->extgstates[i].obj_id);
	    }
	}

	if (!bias)
	    pdc_end_dict(p->out);
    }
}
Example #6
0
void
pdf_write_page_shadings(PDF *p)
{
    int i, total = 0;

    for (i = 0; i < p->shadings_number; i++)
	if (p->shadings[i].used_on_current_page)
	    total++;

    if (total > 0)
    {
	pdc_puts(p->out, "/Shading");
	pdc_begin_dict(p->out);
    }

    if (total > 0)
    {
	for (i = 0; i < p->shadings_number; i++)
	{
	    if (p->shadings[i].used_on_current_page)
	    {
		p->shadings[i].used_on_current_page = pdc_false; /* reset */
		pdc_printf(p->out, "/Sh%d", i);
		pdc_objref(p->out, "", p->shadings[i].obj_id);
	    }
	}

	    pdc_end_dict(p->out);
    }
}
Example #7
0
void
pdf_write_page_extgstates(PDF *p)
{
    int i, total = 0;

    for (i = 0; i < p->extgstates_number; i++)
	if (p->extgstates[i].used_on_current_page)
	    total++;

    if (total > 0) {
	pdc_puts(p->out, "/ExtGState");

	pdc_begin_dict(p->out);			/* ExtGState names */

	for (i = 0; i < p->extgstates_number; i++) {
	    if (p->extgstates[i].used_on_current_page) {
		p->extgstates[i].used_on_current_page = pdc_false; /* reset */
		pdc_printf(p->out, "/GS%d %ld 0 R\n",
		    i, p->extgstates[i].obj_id);
	    }
	}

	pdc_end_dict(p->out);			/* ExtGState names */
    }
}
Example #8
0
void
pdf_setdashpattern_internal(PDF *p, pdc_scalar *darray, int length,
                            pdc_scalar phase)
{
    pdf_gstate *gs = &p->curr_ppt->gstate[p->curr_ppt->sl];

    /* length == 0 or 1 means solid line */
    if (length < 2)
    {
        if (gs->dashed || PDF_FORCE_OUTPUT())
        {
            pdc_puts(p->out, "[] 0 d\n");
            gs->dashed = pdc_false;
        }
    }
    else
    {
        int i;

	pdc_begin_array(p->out);
        for (i = 0; i < length; i++)
        {
            pdc_printf(p->out, "%f ", darray[i]);
        }
	pdc_end_array_c(p->out);
        pdc_printf(p->out, "%f d\n", phase);
        gs->dashed = pdc_true;
    }
}
Example #9
0
File: p_color.c Project: LuaDist/cd
void
pdf_write_function_dict(PDF *p, pdf_color *c0, pdf_color *c1, pdc_scalar N)
{
    static const char *fn = "pdf_write_function_dict";

    pdf_colorspace *cs;

    cs = &p->colorspaces[c1->cs];

    pdc_begin_dict(p->out);			/* function dict */

    pdc_puts(p->out, "/FunctionType 2\n");
    pdc_puts(p->out, "/Domain[0 1]\n");
    pdc_printf(p->out, "/N %f\n", N);

    switch (cs->type) {

	case DeviceGray:
	pdc_puts(p->out, "/Range[0 1]\n");
	if (c0->val.gray != 0) pdc_printf(p->out, "/C0[%f]\n", c0->val.gray);
	if (c1->val.gray != 1) pdc_printf(p->out, "/C1[%f]", c1->val.gray);
	break;

	case DeviceRGB:
	pdc_puts(p->out, "/Range[0 1 0 1 0 1]\n");
	pdc_printf(p->out, "/C0[%f %f %f]\n",
		c0->val.rgb.r, c0->val.rgb.g, c0->val.rgb.b);
	pdc_printf(p->out, "/C1[%f %f %f]",
		c1->val.rgb.r, c1->val.rgb.g, c1->val.rgb.b);
	break;

	case DeviceCMYK:
	pdc_puts(p->out, "/Range[0 1 0 1 0 1 0 1]\n");
	pdc_printf(p->out, "/C0[%f %f %f %f]\n",
		c0->val.cmyk.c, c0->val.cmyk.m, c0->val.cmyk.y, c0->val.cmyk.k);
	pdc_printf(p->out, "/C1[%f %f %f %f]",
		c1->val.cmyk.c, c1->val.cmyk.m, c1->val.cmyk.y, c1->val.cmyk.k);
	break;


	default:
	pdc_error(p->pdc, PDF_E_INT_BADCS, fn, "(unknown)",
	    pdc_errprintf(p->pdc, "%d", cs->type), 0);
    }

    pdc_end_dict_c(p->out);		/* function dict */
} /* pdf_write_function_dict */
Example #10
0
int
pdf__shading_pattern(PDF *p, int shading, const char *optlist)
{
    pdc_resopt *results;
    pdc_clientdata data;
    int gstate = -1;
    int retval = -1;

    if (p->compatibility == PDC_1_3)
	pdc_error(p->pdc, PDF_E_SHADING13, 0, 0, 0, 0);

    pdf_check_handle(p, shading, pdc_shadinghandle);

    if (optlist && strlen(optlist)) {
        pdf_set_clientdata(p, &data);
	results = pdc_parse_optionlist(p->pdc,
            optlist, pdf_shading_pattern_options, &data, pdc_true);

        (void) pdc_get_optvalues("gstate", results, &gstate, NULL);

	pdc_cleanup_optionlist(p->pdc, results);
    }

    if (p->pattern_number == p->pattern_capacity)
	pdf_grow_pattern(p);

    if (PDF_GET_STATE(p) == pdf_state_page)
	pdf_end_contents_section(p);

    							/* Pattern object */
    p->pattern[p->pattern_number].obj_id = pdc_begin_obj(p->out, PDC_NEW_ID);

    /* Shadings don't have a painttype, but this signals to the
     * code which writes the pattern usage that no color values
     * will be required when setting the pattern color space.
     */
    p->pattern[p->pattern_number].painttype = 1;

    pdc_begin_dict(p->out);				/* Pattern dict*/

    pdc_puts(p->out, "/PatternType 2\n");		/* shading pattern */

    pdc_objref(p->out, "/Shading", p->shadings[shading].obj_id);

    p->shadings[shading].used_on_current_page = pdc_true;

    if (gstate != -1)
	pdc_objref(p->out, "/ExtGState", pdf_get_gstate_id(p, gstate));

    pdc_end_dict(p->out);				/* Pattern dict*/
    pdc_end_obj(p->out);				/* Pattern object */

    if (PDF_GET_STATE(p) == pdf_state_page)
	pdf_begin_contents_section(p);

    retval = p->pattern_number;
    p->pattern_number++;
    return retval;
}
Example #11
0
void
pdc_begin_pdfstream(pdc_output *out)
{
    pdc_puts(out, "stream\n");

    out->start_pos = pdc_tell_out(out);

    if (out->compresslevel)
	pdc_begin_compress(out);
}
Example #12
0
void
pdf__closepath(PDF *p)
{
    pdf_ppt *ppt = p->curr_ppt;

    pdc_puts(p->out, "h\n");

    ppt->gstate[ppt->sl].x = ppt->gstate[ppt->sl].startx;
    ppt->gstate[ppt->sl].y = ppt->gstate[ppt->sl].starty;
}
Example #13
0
void
pdf_put_cidglyph_widths(PDF *p, pdf_font *font)
{
    if (font->opt.monospace)
    {
        if (font->opt.monospace != FNT_DEFAULT_CIDWIDTH)
        pdc_printf(p->out, "/DW %d\n", font->opt.monospace);
    }
    else
    {
        const char **widths = fnt_get_cid_widths_array(p->pdc, &font->ft);
        int i;

        pdc_puts(p->out, "/W");
        pdc_begin_array(p->out);
        for (i = 0; i < FNT_CIDMETRIC_INCR - 1; i++)
            pdc_puts(p->out, widths[i]);
        pdc_end_array(p->out);
    }
}
Example #14
0
void
pdf__restore(PDF *p)
{
    if (p->sl == 0)
	pdc_error(p->pdc, PDF_E_GSTATE_RESTORE, 0, 0, 0, 0);

    pdf_end_text(p);

    pdc_puts(p->out, "Q\n");

    p->sl--;
}
Example #15
0
void
pdc_end_pdfstream(pdc_output *out)
{
    if (out->compresslevel)
	pdc_end_compress(out);

    out->length = pdc_tell_out(out) - out->start_pos;

    /* some PDF consumers seem to need the additional "\n" before "endstream",
    ** the PDF reference allows it, and Acrobat's "repair" feature relies on it.
    */
    pdc_puts(out, "\nendstream\n");
}
Example #16
0
File: p_color.c Project: LuaDist/cd
void
pdf_write_colormap(PDF *p, int slot)
{
    PDF_data_source src;
    pdf_colorspace *cs, *base;
    pdc_id length_id;

    cs   = &p->colorspaces[slot];

    if (cs->type != Indexed || cs->val.indexed.colormap_done == pdc_true)
	return;

    base = &p->colorspaces[cs->val.indexed.base];

    pdc_begin_obj(p->out, cs->val.indexed.colormap_id);	/* colormap object */
    pdc_begin_dict(p->out);

    if (pdc_get_compresslevel(p->out))
	pdc_puts(p->out, "/Filter/FlateDecode\n");

    /* Length of colormap object */
    length_id = pdc_alloc_id(p->out);
    pdc_objref(p->out, "/Length", length_id);
    pdc_end_dict(p->out);

    src.init		= NULL;
    src.fill		= pdf_data_source_buf_fill;
    src.terminate	= NULL;

    src.buffer_start	= (unsigned char *) cs->val.indexed.colormap;

    src.buffer_length = (size_t) (cs->val.indexed.palette_size *
				pdf_color_components(p, cs->val.indexed.base));

    src.bytes_available = 0;
    src.next_byte	= NULL;

    /* Write colormap data */
    pdf_copy_stream(p, &src, pdc_true);	/* colormap data */

    pdc_end_obj(p->out);				/* colormap object */

    pdc_put_pdfstreamlength(p->out, length_id);

    /* free the colormap now that it's written */
    pdc_free(p->pdc, cs->val.indexed.colormap);
    cs->val.indexed.colormap = NULL;
    cs->val.indexed.colormap_done = pdc_true;
} /* pdf_write_colormap */
Example #17
0
void
pdf__save(PDF *p)
{
    if (p->sl == PDF_MAX_SAVE_LEVEL - 1)
	pdc_error(p->pdc, PDF_E_GSTATE_SAVELEVEL,
	    pdc_errprintf(p->pdc, "%d", PDF_MAX_SAVE_LEVEL - 1), 0, 0, 0);

    pdf_end_text(p);

    pdc_puts(p->out, "q\n");

    /* propagate states to next level */
    p->sl++;
    memcpy(&p->gstate[p->sl], &p->gstate[p->sl - 1], sizeof(pdf_gstate));
    memcpy(&p->tstate[p->sl], &p->tstate[p->sl - 1], sizeof(pdf_tstate));
    memcpy(&p->cstate[p->sl], &p->cstate[p->sl - 1], sizeof(pdf_cstate));
}
Example #18
0
void
pdf_put_cidglyph_widths(PDF *p, pdc_font *font)
{
    int slot;

    /* Check whether the font name is among the known CID fonts */
    for (slot = 0; slot < SIZEOF_CID_METRICS; slot++) {
        if (!strcmp(pdf_cid_metrics[slot].name, font->apiname))
            break;
    }
    pdc_printf(p->out, "/DW %d\n",
        font->monospace ? font->monospace : PDF_DEFAULT_CIDWIDTH);
    if (!font->monospace)
    {
        if (slot < SIZEOF_CID_METRICS && pdf_cid_width_arrays[slot]) {
            pdc_puts(p->out, pdf_cid_width_arrays[slot]);
        }
    }
}
Example #19
0
void
pdf__save(PDF *p)
{
    pdf_ppt *	ppt = p->curr_ppt;
    int		sl = ppt->sl;

    if (sl == PDF_MAX_SAVE_LEVEL - 1)
	pdc_error(p->pdc, PDF_E_GSTATE_SAVELEVEL,
	    pdc_errprintf(p->pdc, "%d", PDF_MAX_SAVE_LEVEL - 1), 0, 0, 0);

    pdf_end_text(p);
    pdc_puts(p->out, "q\n");

    /* propagate states to next level */
    memcpy(&ppt->gstate[sl + 1], &ppt->gstate[sl], sizeof(pdf_gstate));
    pdf_save_cstate(p);
    pdf_save_tstate(p);
    ++ppt->sl;
}
Example #20
0
File: p_color.c Project: LuaDist/cd
void
pdf_write_doc_colorspaces(PDF *p)
{
    int i;

    for (i = 0; i < p->colorspaces_number; i++) {
	pdf_colorspace *cs = &p->colorspaces[i];

	/* don't write simple color spaces as resource */
	if (PDF_SIMPLE_COLORSPACE(cs))
	    continue;

	pdc_begin_obj(p->out, cs->obj_id);
	pdf_write_colorspace(p, i, pdc_true);
	pdc_puts(p->out, "\n");
	pdc_end_obj(p->out);			/* color space resource */

	pdf_write_colormap(p, i);		/* write pending colormaps */
    }
}
Example #21
0
File: p_color.c Project: LuaDist/cd
void
pdf_write_page_colorspaces(PDF *p)
{
    int i, total = 0;

    for (i = 0; i < p->colorspaces_number; i++)
	if (p->colorspaces[i].used_on_current_page)
	    total++;

    if (total > 0
       )
    {
	pdc_puts(p->out, "/ColorSpace");
	pdc_begin_dict(p->out);

	if (total > 0)
	{
	    for (i = 0; i < p->colorspaces_number; i++)
	    {
		pdf_colorspace *cs = &p->colorspaces[i];

		if (cs->used_on_current_page)
		{
		    cs->used_on_current_page = pdc_false; /* reset */

		    /* don't write simple color spaces as resource */
		    if (!PDF_SIMPLE_COLORSPACE(cs))
		    {
			pdc_printf(p->out, "/C%d", i);
			pdc_objref(p->out, "", cs->obj_id);
		    }
		}
	    }
	}


	    pdc_end_dict(p->out);		/* color space names */
    }
} /* pdf_write_page_colorspaces */
Example #22
0
void
pdf_write_destination(PDF *p, pdf_dest *dest)
{
    if (dest->type == nameddest)
    {
        pdf_put_hypertext(p, dest->name);
        pdc_puts(p->out, "\n");
        return;
    }

    pdc_begin_array(p->out);

    if (dest->remote_page)
    {
        pdc_printf(p->out, "%d", dest->remote_page - 1);   /* zero-based */
    }
    else
    {
        if (dest->page == PDC_BAD_ID)
	    dest->page = pdf_get_page_id(p, dest->pgnum);

        pdc_objref_c(p->out, dest->page);
    }

    switch (dest->type) {

        case fixed:
        pdc_puts(p->out, "/XYZ ");

        if (dest->left != -1)
            pdc_printf(p->out, "%f ", dest->left);
        else
            pdc_puts(p->out, "null ");

        if (dest->top != -1)
            pdc_printf(p->out, "%f ", dest->top);
        else
            pdc_puts(p->out, "null ");

        if (dest->zoom != -1)
            pdc_printf(p->out, "%f", dest->zoom);
        else
            pdc_puts(p->out, "null");

        break;

        case fitwindow:
        pdc_puts(p->out, "/Fit");
        break;

        case fitwidth:
        pdc_printf(p->out, "/FitH %f", dest->top);
        break;

        case fitheight:
        pdc_printf(p->out, "/FitV %f", dest->left);
        break;

        case fitrect:
        pdc_printf(p->out, "/FitR %f %f %f %f",
            dest->left, dest->bottom, dest->right, dest->top);
        break;

        case fitvisible:
        pdc_puts(p->out, "/FitB");
        break;

        case fitvisiblewidth:
        pdc_printf(p->out, "/FitBH %f", dest->top);
        break;

        case fitvisibleheight:
        pdc_printf(p->out, "/FitBV %f", dest->left);
        break;

        default:
        break;
    }

    pdc_end_array(p->out);
}
Example #23
0
int
pdf__shading(
    PDF *p,
    const char *type,
    pdc_scalar x_0, pdc_scalar y_0,
    pdc_scalar x_1, pdc_scalar y_1,
    pdc_scalar c_1, pdc_scalar c_2, pdc_scalar c_3, pdc_scalar c_4,
    const char *optlist)
{
    pdf_shadingtype_e shtype = shnone;
    pdf_color *color0, color1;
    pdf_colorspace *cs;
    pdc_resopt *results;
    pdc_scalar N = 1.0;
    pdc_scalar r_0, r_1;
    pdc_bool extend0 = pdc_false, extend1 = pdc_false, antialias = pdc_false;
    int retval = -1;

    if (p->compatibility == PDC_1_3)
	pdc_error(p->pdc, PDF_E_SHADING13, 0, 0, 0, 0);

    if (!pdc_stricmp(type, "axial")) {
	shtype = axial;

    } else if (!pdc_stricmp(type, "radial")) {
	shtype = radial;

    } else
	pdc_error(p->pdc, PDC_E_ILLARG_STRING, "type", type, 0, 0);

    pdc_check_number(p->pdc, "x_0", x_0);
    pdc_check_number(p->pdc, "y_0", y_0);
    pdc_check_number(p->pdc, "x_1", x_1);
    pdc_check_number(p->pdc, "y_1", y_1);
    pdc_check_number(p->pdc, "c_1", c_1);
    pdc_check_number(p->pdc, "c_2", c_2);
    pdc_check_number(p->pdc, "c_3", c_3);
    pdc_check_number(p->pdc, "c_4", c_4);

    color0 = pdf_get_cstate(p, pdf_fill);

    color1.cs = color0->cs;

    cs = &p->colorspaces[color0->cs];

    switch (cs->type) {
	case DeviceGray:
	color1.val.gray = c_1;
	break;

	case DeviceRGB:
	color1.val.rgb.r = c_1;
	color1.val.rgb.g = c_2;
	color1.val.rgb.b = c_3;
	break;

	case DeviceCMYK:
	color1.val.cmyk.c = c_1;
	color1.val.cmyk.m = c_2;
	color1.val.cmyk.y = c_3;
	color1.val.cmyk.k = c_4;
	break;



	default:
	pdc_error(p->pdc, PDF_E_INT_BADCS,
	    pdc_errprintf(p->pdc, "%d", color0->cs), 0, 0, 0);
    }

    results = pdc_parse_optionlist(p->pdc,
        optlist, pdf_shading_options, NULL, pdc_true);

    (void) pdc_get_optvalues("N", results, &N, NULL);

    (void) pdc_get_optvalues("antialias", results, &antialias,NULL);

    if (shtype == radial) {
        if (pdc_get_optvalues("r0", results, &r_0, NULL) != 1)
            pdc_error(p->pdc, PDC_E_OPT_NOTFOUND, "r0", 0, 0, 0);

        if (pdc_get_optvalues("r1", results, &r_1, NULL) != 1)
            pdc_error(p->pdc, PDC_E_OPT_NOTFOUND, "r1", 0, 0, 0);
    }

    if (shtype == axial) {
        if (pdc_get_optvalues("r0", results, &r_0, NULL) == 1)
            pdc_warning(p->pdc, PDC_E_OPT_IGNORED, "r0", 0, 0, 0);

        if (pdc_get_optvalues("r1", results, &r_1, NULL) == 1)
            pdc_warning(p->pdc, PDC_E_OPT_IGNORED, "r1", 0, 0, 0);
    }

    if (shtype == radial || shtype == axial) {
        pdc_get_optvalues("extend0", results, &extend0, NULL);
        pdc_get_optvalues("extend1", results, &extend1, NULL);
    }

    pdc_cleanup_optionlist(p->pdc, results);

    if (p->shadings_number == p->shadings_capacity)
	pdf_grow_shadings(p);

    if (PDF_GET_STATE(p) == pdf_state_page)
	pdf_end_contents_section(p);

    							/* Shading object */
    p->shadings[p->shadings_number].obj_id = pdc_begin_obj(p->out, PDC_NEW_ID);

    pdc_begin_dict(p->out);				/* Shading dict*/

    pdc_printf(p->out, "/ShadingType %d\n", (int) shtype);

    pdc_printf(p->out, "/ColorSpace");
    pdf_write_colorspace(p, color1.cs, pdc_false);
    pdc_puts(p->out, "\n");

    if (antialias)
	pdc_printf(p->out, "/AntiAlias true\n");

    switch (shtype) {
	case axial:	/* Type 2 */
	pdc_printf(p->out, "/Coords[%f %f %f %f]\n", x_0, y_0, x_1, y_1);
	if (extend0 || extend1)
	    pdc_printf(p->out, "/Extend[%s %s]\n",
		extend0 ? "true" : "false", extend1 ? "true" : "false");
	pdc_puts(p->out, "/Function");
	pdf_write_function_dict(p, color0, &color1, N);
	break;

	case radial:	/* Type 3 */
	pdc_printf(p->out, "/Coords[%f %f %f %f %f %f]\n",
	    x_0, y_0, r_0, x_1, y_1, r_1);
	if (extend0 || extend1)
	    pdc_printf(p->out, "/Extend[%s %s]\n",
		extend0 ? "true" : "false", extend1 ? "true" : "false");
	pdc_puts(p->out, "/Function");
	pdf_write_function_dict(p, color0, &color1, N);
	break;

	default:
	break;
    }

    pdc_end_dict(p->out);				/* Shading dict */
    pdc_end_obj(p->out);				/* Shading object */

    if (PDF_GET_STATE(p) == pdf_state_page)
	pdf_begin_contents_section(p);

    retval = p->shadings_number;
    p->shadings_number++;
    return retval;
}
Example #24
0
File: p_color.c Project: LuaDist/cd
static void
pdf_write_color_values(PDF *p, pdf_color *color, pdf_drawmode drawmode)
{
    static const char	fn[] = "pdf_write_color_values";

    pdf_colorspace *	cs = &p->colorspaces[color->cs];

    switch (cs->type)
    {
	case DeviceGray:
	{
	    pdc_printf(p->out, "%f", color->val.gray);

	    if (drawmode == pdf_fill)
		pdc_puts(p->out, " g\n");
	    else if (drawmode == pdf_stroke)
		pdc_puts(p->out, " G\n");

	    break;
	}

	case DeviceRGB:
	{
	    pdc_printf(p->out, "%f %f %f",
		    color->val.rgb.r, color->val.rgb.g, color->val.rgb.b);

	    if (drawmode == pdf_fill)
		pdc_puts(p->out, " rg\n");
	    else if (drawmode == pdf_stroke)
		pdc_puts(p->out, " RG\n");

	    break;
	}

	case DeviceCMYK:
	{
	    pdc_printf(p->out, "%f %f %f %f",
		    color->val.cmyk.c, color->val.cmyk.m,
		    color->val.cmyk.y, color->val.cmyk.k);

	    if (drawmode == pdf_fill)
		pdc_puts(p->out, " k\n");
	    else if (drawmode == pdf_stroke)
		pdc_puts(p->out, " K\n");

	    break;
	}


	case PatternCS:
	{
	    if (drawmode == pdf_fill)
	    {
		if (p->pattern[color->val.pattern].painttype == 1)
		{
		    pdc_puts(p->out, "/Pattern cs");
		}
		else if (p->pattern[color->val.pattern].painttype == 2)
		{
                    pdf_color *fillcolor = pdf_get_cstate(p, pdf_fill);

		    pdc_printf(p->out, "/C%d cs ", color->cs);
                    pdf_write_color_values(p, fillcolor, pdf_none);
		}

		pdc_printf(p->out, "/P%d scn\n", color->val.pattern);
	    }
	    else if (drawmode == pdf_stroke)
	    {
		if (p->pattern[color->val.pattern].painttype == 1)
		{
		    pdc_puts(p->out, "/Pattern CS");
		}
		else if (p->pattern[color->val.pattern].painttype == 2)
		{
                    pdf_color *strokecolor = pdf_get_cstate(p, pdf_stroke);

		    pdc_printf(p->out, "/C%d CS ", color->cs);
                    pdf_write_color_values(p, strokecolor, pdf_none);
		}

		pdc_printf(p->out, "/P%d SCN\n", color->val.pattern);
	    }

	    p->pattern[color->val.pattern].used_on_current_page = pdc_true;
	    break;
	}


	case Indexed: /* LATER */
	default:
	    pdc_error(p->pdc, PDF_E_INT_BADCS, fn,
		pdc_errprintf(p->pdc, "%d", color->cs),
		pdc_errprintf(p->pdc, "%d", cs->type), 0);
    }
} /* pdf_write_color_values */
Example #25
0
File: p_color.c Project: LuaDist/cd
void
pdf_write_colorspace(PDF *p, int slot, pdc_bool direct)
{
    static const char *fn = "pdf_write_colorspace";

    pdf_colorspace *cs;
    int base;

    if (slot < 0 || slot >= p->colorspaces_number)
	pdc_error(p->pdc, PDF_E_INT_BADCS, fn,
            pdc_errprintf(p->pdc, "%d", slot),
            "(unknown)", 0);

    cs = &p->colorspaces[slot];

    /* we always write simple colorspaces directly */
    if (PDF_SIMPLE_COLORSPACE(cs))
	direct = pdc_true;

    if (!direct) {
	pdc_objref_c(p->out, cs->obj_id);
	return;
    }

    switch (cs->type) {
	case DeviceGray:
	pdc_printf(p->out, "/DeviceGray");
	break;

	case DeviceRGB:
	pdc_printf(p->out, "/DeviceRGB");
	break;

	case DeviceCMYK:
	pdc_printf(p->out, "/DeviceCMYK");
	break;


	case Indexed:
	base = cs->val.indexed.base;

	pdc_begin_array(p->out);
	pdc_puts(p->out, "/Indexed");

	pdf_write_colorspace(p, base, pdc_false);

	pdc_printf(p->out, " %d", cs->val.indexed.palette_size - 1);
	pdc_objref_c(p->out, cs->val.indexed.colormap_id);
	pdc_end_array_c(p->out);
	break;

	case PatternCS:
	pdc_begin_array(p->out);
	pdc_printf(p->out, "/Pattern");
	pdf_write_colorspace(p, cs->val.pattern.base, pdc_false);
	pdc_end_array(p->out);
	break;

	default:
	pdc_error(p->pdc, PDF_E_INT_BADCS, fn,
	    pdc_errprintf(p->pdc, "%d", slot),
	    pdc_errprintf(p->pdc, "%d", cs->type), 0);
    }
} /* pdf_write_colorspace */
Example #26
0
static void
pdf_write_outline_dict(PDF *p, int entry)
{
    pdf_outline *outline = &p->outlines[entry];
    pdc_id act_idlist[PDF_MAX_EVENTS];

    /* write action objects */
    if (outline->action)
        pdf_parse_and_write_actionlist(p, event_bookmark, act_idlist,
                                       (const char *) outline->action);

    pdc_begin_obj(p->out, OBJ_ID(entry));   /* outline object */
    pdc_begin_dict(p->out);

    pdc_objref(p->out, "/Parent", OBJ_ID(PARENT(entry)));

    /* outline destination */
    if (outline->dest)
    {
        pdc_puts(p->out, "/Dest");
        pdf_write_destination(p, outline->dest);
    }

    /* write Action entries */
    else if (outline->action)
        pdf_write_action_entries(p, event_bookmark, act_idlist);

    pdc_puts(p->out, "/Title"); /* outline text */
    pdf_put_hypertext(p, outline->text);
    pdc_puts(p->out, "\n");

    if (PREV(entry))
        pdc_objref(p->out, "/Prev", OBJ_ID(PREV(entry)));
    if (NEXT(entry))
        pdc_objref(p->out, "/Next", OBJ_ID(NEXT(entry)));

    if (FIRST(entry)) {
        pdc_objref(p->out, "/First", OBJ_ID(FIRST(entry)));
        pdc_objref(p->out, "/Last", OBJ_ID(LAST(entry)));
    }
    if (COUNT(entry)) {
        if (OPEN(entry))
            pdc_printf(p->out, "/Count %d\n", COUNT(entry));    /* open */
        else
            pdc_printf(p->out, "/Count %d\n", -COUNT(entry));/* closed */
    }

    /* Color */
    if (outline->textcolor[0] != 0.0 ||
        outline->textcolor[1] != 0.0 ||
        outline->textcolor[2] != 0.0)
        pdc_printf(p->out, "/C[%f %f %f]\n", outline->textcolor[0],
                                              outline->textcolor[1],
                                              outline->textcolor[2]);

    /* FontStyle */
    if (outline->fontstyle != fnt_Normal)
    {
        int fontstyle = 0;
        if (outline->fontstyle == fnt_Bold)
            fontstyle = 2;
        if (outline->fontstyle == fnt_Italic)
            fontstyle = 1;
        if (outline->fontstyle == fnt_BoldItalic)
            fontstyle = 3;
        pdc_printf(p->out, "/F %d\n", fontstyle);
    }

    pdc_end_dict(p->out);
    pdc_end_obj(p->out);                        /* outline object */
}
Example #27
0
static pdc_id
pdf_write_action(PDF *p, pdf_action *action, pdc_id next_id)
{
    pdc_id ret_id = PDC_BAD_ID;
    int i, flags = 0;


    ret_id = pdc_begin_obj(p->out, PDC_NEW_ID);         /* Action object */
    pdc_begin_dict(p->out);                             /* Action dict */

    pdc_puts(p->out, "/Type/Action\n");
    pdc_printf(p->out, "/S/%s\n",
               pdc_get_keyword(action->atype, pdf_action_pdfkeylist));

    /* next action */
    if (next_id != PDC_BAD_ID)
	pdc_objref(p->out, "/Next", next_id);
    else
        action->obj_id = ret_id;

    /* destination */
    switch (action->atype)
    {
        case pdf_goto:
        case pdf_gotor:

        pdc_puts(p->out, "/D");
        pdf_write_destination(p, action->dest);

        default:
        break;
    }

    /* file specification */
    switch (action->atype)
    {
        case pdf_gotor:
        case pdf_launch:
        if (action->newwindow != pdc_undef)
            pdc_printf(p->out, "/NewWindow %s\n",
                PDC_BOOLSTR(action->newwindow));
        case pdf_importdata:

        if (action->parameters || action->operation || action->defaultdir)
        {
            /* Windows-specific launch parameters */
            pdc_puts(p->out, "/Win");
            pdc_begin_dict(p->out);                     /* Win dict */
            pdc_puts(p->out, "/F");
            pdf_put_pdffilename(p, action->nativefilename);
            pdc_puts(p->out, "\n");
            if (p->compatibility >= PDC_1_7)
            {
                pdc_puts(p->out, "/UF");
                pdf_put_pdfunifilename(p, action->filename);
                pdc_puts(p->out, "\n");
            }
            if (action->parameters)
            {
                pdc_puts(p->out, "/P");
                pdf_put_hypertext(p, action->parameters);
                pdc_puts(p->out, "\n");
                pdc_free(p->pdc, action->parameters);
                action->parameters = NULL;
            }
            if (action->operation)
            {
                pdc_puts(p->out, "/O");
                pdf_put_hypertext(p, action->operation);
                pdc_puts(p->out, "\n");
                action->operation = NULL;
            }
            if (action->defaultdir)
            {
                pdc_puts(p->out, "/D");
                pdf_put_hypertext(p, action->defaultdir);
                pdc_puts(p->out, "\n");
                pdc_free(p->pdc, action->defaultdir);
                action->defaultdir = NULL;
            }
            pdc_end_dict(p->out);                       /* Win dict */
        }
        else
        {
            pdc_puts(p->out, "/F");
            pdc_begin_dict(p->out);                     /* F dict */
            pdc_puts(p->out, "/Type/Filespec\n");
            pdc_puts(p->out, "/F");
            pdf_put_pdffilename(p, action->nativefilename);
            pdc_puts(p->out, "\n");
            if (p->compatibility >= PDC_1_7)
            {
                pdc_puts(p->out, "/UF");
                pdf_put_pdfunifilename(p, action->filename);
                pdc_puts(p->out, "\n");
            }
            pdc_end_dict(p->out);                       /* F dict */
        }

        default:
        break;
    }

    /* URI */
    switch (action->atype)
    {
        case pdf_uri:
        pdc_puts(p->out, "/URI");
        pdf_put_hypertext(p, action->filename);
        pdc_puts(p->out, "\n");

        /* IsMap */
        if (action->ismap == pdc_true)
            pdc_puts(p->out, "/IsMap true\n");

        default:
        break;
    }

    /* Named */
    switch (action->atype)
    {
        case pdf_named:
        pdc_puts(p->out, "/N");
	pdf_put_pdfname(p, action->menuname);
        pdc_puts(p->out, "\n");

        default:
        break;
    }

    /* name list */
    switch (action->atype)
    {
        case pdf_hide:
        if (action->hide == pdc_false)
            pdc_puts(p->out, "/H false\n");
        case pdf_submitform:
        case pdf_resetform:

        if (action->nsnames)
        {
            pdc_printf(p->out, "/%s",
                       (action->atype == pdf_hide) ? "T" : "Fields");
            pdc_begin_array(p->out);
            for (i = 0; i < action->nsnames; i++)
            {
                pdf_put_hypertext(p, action->namelist[i]);
                if (i < action->nsnames - 1)
                    pdc_puts(p->out, "\n");
                else
                    pdc_end_array(p->out);
            }
        }

        default:
        break;
    }

    /* URL */
    switch (action->atype)
    {
        case pdf_submitform:
        pdc_puts(p->out, "/F");
        pdc_begin_dict(p->out);                     /* F dict */
        pdc_puts(p->out, "/FS/URL\n");
        pdc_printf(p->out, "/F");
        pdf_put_hypertext(p, action->filename);
        pdc_puts(p->out, "\n");
        pdc_end_dict(p->out);                       /* F dict */

        default:
        break;
    }

    /* Trans */
    switch (action->atype)
    {
        case pdf_trans:
        pdc_puts(p->out, "/Trans");
        pdc_begin_dict(p->out);                     /* Trans dict */
        pdc_puts(p->out, "/Type/Trans\n");
        if (action->transition != trans_replace)
            pdc_printf(p->out, "/S/%s",
                pdc_get_keyword(action->transition, pdf_transition_pdfkeylist));
        if (action->duration > 0)
            pdc_printf(p->out, "/D %f\n", action->duration);
        pdc_end_dict(p->out);                       /* Trans dict */

        default:
        break;
    }

    /* Flags */
    switch (action->atype)
    {
        case pdf_submitform:
        flags = (int) action->exportmethod;
        if (action->submitemptyfields)
            flags |= (1<<1);
        if (action->canonicaldate)
            flags |= (1<<9);
        case pdf_resetform:

        if (action->exclude)
            flags |= (1<<0);
        if (flags)
            pdc_printf(p->out, "/Flags %d\n", flags);

        default:
        break;
    }

    /* Movie */


    pdc_end_dict(p->out);                              /* Action dict */
    pdc_end_obj(p->out);                               /* Action object */

    return ret_id;
}
Example #28
0
pdc_bool
pdf_write_action_entries(PDF *p, pdf_event_object eventobj, pdc_id *act_idlist)
{
    const pdc_keyconn *keyconntable = NULL;
    const char *keyword;
    pdc_id act_id = PDC_BAD_ID;
    pdc_bool adict = pdc_false;
    pdc_bool aadict = pdc_false;
    int code;


    switch(eventobj)
    {

        case event_annotation:
        keyconntable = pdf_annotevent_pdfkeylist;
        break;

        case event_bookmark:
        keyconntable = pdf_bookmarkevent_pdfkeylist;
        break;

        case event_document:
        keyconntable = pdf_documentevent_pdfkeylist;
        break;

        case event_page:
        keyconntable = pdf_pageevent_pdfkeylist;
        break;

        default:
        break;
    }

    for (code = 0; ; code++)
    {
        keyword = pdc_get_keyword(code, keyconntable);
        if (keyword)
        {
            act_id = act_idlist[code];
            if (act_id != PDC_BAD_ID)
            {
                if (code && !aadict)
                {
                    pdc_puts(p->out, "/AA");
                    pdc_begin_dict(p->out);                 /* AA dict */
                    aadict = pdc_true;
                }
                else if (!code)
                    adict = pdc_true;
                pdc_printf(p->out, "/%s", keyword);
                pdc_objref_c(p->out, act_id);
            }
        }
        else
            break;
    }
    if (aadict)
        pdc_end_dict(p->out);                               /* AA dict */
    else if (adict)
        pdc_puts(p->out, "\n");

    return adict;
}
Example #29
0
pdc_id
pdf_write_info(PDF *p, pdc_bool moddate)
{
    pdc_bool logg3 = pdc_logg_is_enabled(p->pdc, 3, trc_xmp);
    char time_str[PDC_TIME_SBUF_SIZE];
    char producer[PDC_GEN_BUFSIZE];
    pdf_info    *info;
    pdc_id      info_id;



    const char *product = "PDFlib Lite";
    const char *security = "";

    (void) logg3;


    if (!p->pdc->smokerun)
        pdc_logg_cond(p->pdc, 1, trc_api,
            "[Full product name: \"%s\"]\n", product);

    info_id = pdc_begin_obj(p->out, PDC_NEW_ID);        /* Info object */

    pdc_begin_dict(p->out);

    /*
     * Although it would be syntactically correct, we must not remove
     * the space characters after the dictionary keys since this
     * would break the PDF properties feature in Windows Explorer.
     */

    if (p->userinfo)
    {
        for (info = p->userinfo; info != NULL; info = info->next)
        {
            pdf_put_pdfname(p, info->key);
            pdc_puts(p->out, " ");

            if (strcmp(info->key, "Trapped"))
                pdf_put_hypertext(p, info->value);
            else
                pdf_put_pdfname(p, info->value);

            pdc_puts(p->out, "\n");
        }
    }


    pdc_get_timestr(time_str, pdc_false);

    /* creation date and time */
    pdc_puts(p->out, "/CreationDate ");
    pdf_put_hypertext(p, time_str);
    pdc_puts(p->out, "\n");

    /* modification date and time */
    if (moddate)
    {
        pdc_puts(p->out, "/ModDate ");
        pdf_put_hypertext(p, time_str);
        pdc_puts(p->out, "\n");
    }

    /*
     * If you change the /Producer entry your license to use
     * PDFlib will be void!
     */

    if (p->pdc->binding)
        pdc_sprintf(p->pdc, pdc_false, producer, "%s %s%s (%s/%s)", product,
            PDFLIB_VERSIONSTRING, security, p->pdc->binding, PDF_PLATFORM);
    else
        pdc_sprintf(p->pdc, pdc_false, producer, "%s %s%s (%s)", product,
            PDFLIB_VERSIONSTRING, security, PDF_PLATFORM);

    pdc_puts(p->out, "/Producer ");
    pdf_put_hypertext(p, producer);
    pdc_puts(p->out, "\n");

    pdc_end_dict(p->out);
    pdc_end_obj(p->out);                        /* Info object */




    return info_id;
}
Example #30
0
void
pdf__add_nameddest(
    PDF *p,
    const char *name,
    int len,
    const char *optlist)
{
    pdc_resopt *resopts = NULL;
    pdc_text_format hypertextformat = p->hypertextformat;
    pdc_encoding hypertextencoding;
    int hypertextcodepage;
    pdc_id obj_id = PDC_BAD_ID;
    char *name2 = NULL;
    pdf_dest *dest;
    int inum;

    len = pdc_check_text_length(p->pdc, &name, len, PDF_MAXSTRINGSIZE);
    if (!len)
        pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "name", 0, 0, 0);

    resopts = pdc_parse_optionlist(p->pdc, optlist,
                                   pdf_destination_options, NULL, pdc_true);

    hypertextencoding =
        pdf_get_hypertextencoding_opt(p, resopts, &hypertextcodepage, pdc_true);

    if (pdc_get_optvalues("hypertextformat", resopts, &inum, NULL))
    {
        hypertextformat = (pdc_text_format) inum;
        pdf_check_hypertextformat(p, hypertextformat);
    }

    pdc_cleanup_optionlist(p->pdc, resopts);

    /* create hypertext string */
    name2 = pdf_convert_hypertext(p, name, len, hypertextformat,
                                  hypertextencoding, hypertextcodepage, &len,
                                  pdc_true, pdc_true);
    if (name2 == NULL || len == 0)
        pdc_error(p->pdc, PDC_E_ILLARG_EMPTY, "name", 0, 0, 0);

    /* parsing option list */
    dest = pdf_parse_destination_optlist(p, optlist, 0, pdf_nameddest);

    /* interrupt the content stream if we are on a page */
    if (PDF_GET_STATE(p) == pdf_state_page)
        pdf_end_contents_section(p);

    obj_id = pdc_begin_obj(p->out, PDC_NEW_ID); /* Dest object */
    pdc_begin_dict(p->out);                     /* Destination dict */

    pdc_puts(p->out, "/D");
    pdf_write_destination(p, dest);

    pdc_end_dict(p->out);                       /* Destination dict */
    pdc_end_obj(p->out);                        /* Dest object */

    /* continue the contents stream */
    if (PDF_GET_STATE(p) == pdf_state_page)
        pdf_begin_contents_section(p);

    pdf_cleanup_destination(p, dest);

    /* insert name in tree */
    pdf_insert_name(p, name2, names_dests, obj_id);
}