void pdf__curveto(PDF *p, pdc_scalar x_1, pdc_scalar y_1, pdc_scalar x_2, pdc_scalar y_2, pdc_scalar x_3, pdc_scalar y_3) { pdf_ppt *ppt = p->curr_ppt; pdc_check_number(p->pdc, "x_1", x_1); pdc_check_number(p->pdc, "y_1", y_1); pdc_check_number(p->pdc, "x_2", x_2); pdc_check_number(p->pdc, "y_2", y_2); pdc_check_number(p->pdc, "x_3", x_3); pdc_check_number(p->pdc, "y_3", y_3); /* second c.p. coincides with final point */ if (fabs(x_2 - x_3) < PDC_FLOAT_PREC && fabs(y_2 - y_3) < PDC_FLOAT_PREC) pdc_printf(p->out, "%f %f %f %f y\n", x_1, y_1, x_3, y_3); /* general case with four distinct points */ else pdc_printf(p->out, "%f %f %f %f %f %f c\n", x_1, y_1, x_2, y_2, x_3, y_3); ppt->gstate[ppt->sl].x = x_3; ppt->gstate[ppt->sl].y = y_3; }
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; } }
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; } }
int _dbg_write_trylock(rwlock_t *rw, const char *bfile, int bline) { #if 0 void *inline_pc = __builtin_return_address(0); int cpu = smp_processor_id(); #endif if(unlikely(in_interrupt())) { /* acquiring write lock in interrupt context, bad idea */ pdc_printf("write_lock caller: %s:%d, IRQs enabled,\n", bfile, bline); BUG(); } /* Note: if interrupts are disabled (which is most likely), the printk will never show on the console. We might need a polling method to flush the dmesg buffer anyhow. */ _raw_spin_lock(&rw->lock); if(rw->counter != 0) { /* this basically never happens */ _raw_spin_unlock(&rw->lock); return 0; } /* got it. now leave without unlocking */ rw->counter = -1; /* remember we are locked */ #if 0 pdc_printf("%s:%d: try write_lock grabbed in %s at %p(%d)\n", bfile, bline, current->comm, inline_pc, cpu); #endif return 1; }
void _dbg_write_lock(rwlock_t *rw, const char *bfile, int bline) { void *inline_pc = __builtin_return_address(0); unsigned long started = jiffies; long stuck = INIT_STUCK; int printed = 0; int cpu = smp_processor_id(); if(unlikely(in_interrupt())) { /* acquiring write lock in interrupt context, bad idea */ pdc_printf("write_lock caller: %s:%d, IRQs enabled,\n", bfile, bline); BUG(); } /* Note: if interrupts are disabled (which is most likely), the printk will never show on the console. We might need a polling method to flush the dmesg buffer anyhow. */ retry: _raw_spin_lock(&rw->lock); if(rw->counter != 0) { /* this basically never happens */ _raw_spin_unlock(&rw->lock); stuck--; if ((unlikely(stuck <= 0)) && (rw->counter < 0)) { pdc_printf( "%s:%d: write_lock stuck on writer" " in %s at %p(%d) %ld ticks\n", bfile, bline, current->comm, inline_pc, cpu, jiffies - started); stuck = INIT_STUCK; printed = 1; } else if (unlikely(stuck <= 0)) { pdc_printf( "%s:%d: write_lock stuck on reader" " in %s at %p(%d) %ld ticks\n", bfile, bline, current->comm, inline_pc, cpu, jiffies - started); stuck = INIT_STUCK; printed = 1; } while(rw->counter != 0); goto retry; } /* got it. now leave without unlocking */ rw->counter = -1; /* remember we are locked */ if (unlikely(printed)) { pdc_printf( "%s:%d: write_lock grabbed in %s at %p(%d) %ld ticks\n", bfile, bline, current->comm, inline_pc, cpu, jiffies - started); } }
void _dbg_spin_lock(spinlock_t * lock, const char *base_file, int line_no) { volatile unsigned int *a; long stuck = INIT_STUCK; void *inline_pc = __builtin_return_address(0); unsigned long started = jiffies; int printed = 0; int cpu = smp_processor_id(); try_again: /* Do the actual locking */ /* <T-Bone> ggg: we can't get stuck on the outter loop? * <ggg> T-Bone: We can hit the outer loop * alot if multiple CPUs are constantly racing for a lock * and the backplane is NOT fair about which CPU sees * the update first. But it won't hang since every failed * attempt will drop us back into the inner loop and * decrement `stuck'. * <ggg> K-class and some of the others are NOT fair in the HW * implementation so we could see false positives. * But fixing the lock contention is easier than * fixing the HW to be fair. * <tausq> __ldcw() returns 1 if we get the lock; otherwise we * spin until the value of the lock changes, or we time out. */ mb(); a = __ldcw_align(lock); while (stuck && (__ldcw(a) == 0)) while ((*a == 0) && --stuck); mb(); if (unlikely(stuck <= 0)) { pdc_printf( "%s:%d: spin_lock(%s/%p) stuck in %s at %p(%d)" " owned by %s:%d in %s at %p(%d)\n", base_file, line_no, lock->module, lock, current->comm, inline_pc, cpu, lock->bfile, lock->bline, lock->task->comm, lock->previous, lock->oncpu); stuck = INIT_STUCK; printed = 1; goto try_again; } /* Exiting. Got the lock. */ lock->oncpu = cpu; lock->previous = inline_pc; lock->task = current; lock->bfile = (char *)base_file; lock->bline = line_no; if (unlikely(printed)) { pdc_printf( "%s:%d: spin_lock grabbed in %s at %p(%d) %ld ticks\n", base_file, line_no, current->comm, inline_pc, cpu, jiffies - started); } }
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); } }
void pdf_write_outlines(PDF *p) { int i; if (p->outline_count == 0) /* no outlines: return */ return; pdc_begin_obj(p->out, p->outlines[0].obj_id); /* root outline object */ pdc_begin_dict(p->out); if (p->outlines[0].count != 0) pdc_printf(p->out, "/Count %d\n", COUNT(0)); pdc_objref(p->out, "/First", OBJ_ID(FIRST(0))); pdc_objref(p->out, "/Last", OBJ_ID(LAST(0))); pdc_end_dict(p->out); pdc_end_obj(p->out); /* root outline object */ #define PDF_FLUSH_AFTER_MANY_OUTLINES 1000 /* ca. 50-100 KB */ for (i = 1; i <= p->outline_count; i++) { /* reduce memory usage for many outline entries */ if (i % PDF_FLUSH_AFTER_MANY_OUTLINES == 0) pdc_flush_stream(p->out); pdf_write_outline_dict(p, i); } }
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); } }
void pdf_concat_raw(PDF *p, pdc_matrix *m) { if (!pdc_is_identity_matrix(m)) { char sa[32], sb[32], sc[32], sd[32]; pdc_sprintf(p->pdc, pdc_true, sa, "%f", m->a); pdc_sprintf(p->pdc, pdc_true, sb, "%f", m->b); pdc_sprintf(p->pdc, pdc_true, sc, "%f", m->c); pdc_sprintf(p->pdc, pdc_true, sd, "%f", m->d); if ((!strcmp(sa, "0") || !strcmp(sd, "0")) && (!strcmp(sb, "0") || !strcmp(sc, "0"))) { pdc_error(p->pdc, PDC_E_ILLARG_MATRIX, pdc_errprintf(p->pdc, "%f %f %f %f %f %f", m->a, m->b, m->c, m->d, m->e, m->f), 0, 0, 0); } pdf_end_text(p); pdc_printf(p->out, "%s %s %s %s %f %f cm\n", sa, sb, sc, sd, m->e, m->f); pdc_multiply_matrix(m, &p->curr_ppt->gstate[p->curr_ppt->sl].ctm); } }
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 */ } }
void pdc_put_pdfstreamlength(pdc_output *out, pdc_id length_id) { pdc_begin_obj(out, length_id); /* Length object */ pdc_printf(out, "%lld\n", out->length); pdc_end_obj(out); }
void pdf__set_gstate(PDF *p, int gstate) { int bias = p->curr_ppt->eg_bias; pdf_check_handle(p, gstate, pdc_gstatehandle); pdc_printf(p->out, "/GS%d gs\n", bias + gstate); p->extgstates[gstate].used_on_current_page = pdc_true; }
void pdf__setlinejoin(PDF *p, int join) { pdf_gstate *gs = &p->gstate[p->sl]; if (join != gs->ljoin || PDF_FORCE_OUTPUT()) { gs->ljoin = join; pdc_printf(p->out, "%d j\n", join); } }
void pdf__setlinecap(PDF *p, int cap) { pdf_gstate *gs = &p->gstate[p->sl]; if (cap != gs->lcap || PDF_FORCE_OUTPUT()) { gs->lcap = cap; pdc_printf(p->out, "%d J\n", cap); } }
pdc_bool pdc_init_output( void *opaque, pdc_output *out, int compatibility, pdc_outctl *oc) { static const char *fn = "pdc_init_output"; pdc_core *pdc = out->pdc; int i; pdc_cleanup_output(out, pdc_false); out->opaque = opaque; out->lastobj = 0; #if defined(MVS) || defined(MVS_TEST) out->fopenparams = oc->fopenparams; out->recordsize = oc->recordsize; #endif if (out->file_offset == NULL) { out->file_offset_capacity = ID_CHUNKSIZE; out->file_offset = (pdc_off_t *) pdc_malloc(pdc, sizeof(pdc_off_t) * 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->flush = oc->flush; memcpy(out->id[0], out->id[1], MD5_DIGEST_LENGTH); if (!pdc_init_stream(pdc, out, oc->filename, oc->fp, oc->writeproc)) return pdc_false; { /* Write the document header */ pdc_printf(out, "%%PDF-%s\n", pdc_get_pdfversion(pdc, compatibility)); #define PDC_MAGIC_BINARY "\045\344\343\317\322\012" pdc_write(out, PDC_MAGIC_BINARY, sizeof(PDC_MAGIC_BINARY) - 1); } out->open = pdc_true; return pdc_true; }
pdc_id pdc_begin_obj(pdc_output *out, pdc_id obj_id) { if (obj_id == PDC_NEW_ID) obj_id = pdc_alloc_id(out); out->file_offset[obj_id] = pdc_tell_out(out); pdc_printf(out, "%ld 0 obj\n", obj_id); return obj_id; }
void pdf__setlinewidth(PDF *p, float width) { pdf_gstate *gs = &p->gstate[p->sl]; if (width != gs->lwidth || PDF_FORCE_OUTPUT()) { gs->lwidth = width; pdc_printf(p->out, "%f w\n", width); } }
void pdf__setmiterlimit(PDF *p, float miter) { pdf_gstate *gs = &p->gstate[p->sl]; if (miter != gs->miter || PDF_FORCE_OUTPUT()) { gs->miter = miter; pdc_printf(p->out, "%f M\n", miter); } }
void pdf__setflat(PDF *p, float flat) { pdf_gstate *gs = &p->gstate[p->sl]; if (flat != gs->flatness || PDF_FORCE_OUTPUT()) { gs->flatness = flat; pdc_printf(p->out, "%f i\n", flat); } }
void pdf_concat_raw(PDF *p, pdc_matrix *m) { if (pdc_is_identity_matrix(m)) return; pdf_end_text(p); pdc_printf(p->out, "%f %f %f %f %f %f cm\n", m->a, m->b, m->c, m->d, m->e, m->f); pdc_multiply_matrix(m, &p->gstate[p->sl].ctm); }
void pdf__setflat(PDF *p, pdc_scalar flat) { pdf_gstate *gs = &p->curr_ppt->gstate[p->curr_ppt->sl]; pdc_check_number_limits(p->pdc, "flat", flat, 0.0, 100.0); if (flat != gs->flatness || PDF_FORCE_OUTPUT()) { gs->flatness = flat; pdc_printf(p->out, "%f i\n", flat); } }
void pdf__lineto(PDF *p, pdc_scalar x, pdc_scalar y) { pdf_ppt *ppt = p->curr_ppt; pdc_check_number(p->pdc, "x", x); pdc_check_number(p->pdc, "y", y); pdc_printf(p->out, "%f %f l\n", x, y); ppt->gstate[ppt->sl].x = x; ppt->gstate[ppt->sl].y = y; }
void pdf__setmiterlimit(PDF *p, pdc_scalar miter) { pdf_gstate *gs = &p->curr_ppt->gstate[p->curr_ppt->sl]; pdc_check_number_limits(p->pdc, "miter", miter, 1.0, PDC_FLOAT_MAX); if (miter != gs->miter || PDF_FORCE_OUTPUT()) { gs->miter = miter; pdc_printf(p->out, "%f M\n", miter); } }
void pdf__shfill(PDF *p, int shading) { if (p->compatibility == PDC_1_3) pdc_error(p->pdc, PDF_E_SHADING13, 0, 0, 0, 0); pdf_check_handle(p, shading, pdc_shadinghandle); pdf_end_text(p); pdc_printf(p->out, "/Sh%d sh\n", shading); p->shadings[shading].used_on_current_page = pdc_true; }
void pdf__moveto(PDF *p, pdc_scalar x, pdc_scalar y) { pdf_ppt *ppt = p->curr_ppt; pdc_check_number(p->pdc, "x", x); pdc_check_number(p->pdc, "y", y); ppt->gstate[ppt->sl].startx = ppt->gstate[ppt->sl].x = x; ppt->gstate[ppt->sl].starty = ppt->gstate[ppt->sl].y = y; pdf_begin_path(p); pdc_printf(p->out, "%f %f m\n", x, y); }
void pdf__setlinewidth(PDF *p, pdc_scalar width) { pdf_gstate *gs = &p->curr_ppt->gstate[p->curr_ppt->sl]; pdc_check_number_limits(p->pdc, "width", width, PDC_FLOAT_PREC, PDC_FLOAT_MAX); if (width != gs->lwidth || PDF_FORCE_OUTPUT()) { gs->lwidth = width; pdc_printf(p->out, "%f w\n", width); } }
void _dbg_spin_unlock(spinlock_t * lock, const char *base_file, int line_no) { CHECK_LOCK(lock); volatile unsigned int *a; mb(); a = __ldcw_align(lock); if (unlikely((*a != 0) && lock->babble)) { lock->babble--; pdc_printf( "%s:%d: spin_unlock(%s:%p) not locked\n", base_file, line_no, lock->module, lock); } *a = 1; mb(); }
PDFLIB_API void PDFLIB_CALL PDF_set_gstate(PDF *p, int gstate) { static const char fn[] = "PDF_set_gstate"; if (!pdf_enter_api(p, fn, pdf_state_content, "(p[%p], %d)\n", (void *) p, gstate)) return; PDF_INPUT_HANDLE(p, gstate) pdf_check_handle(p, gstate, pdc_gstatehandle); pdc_printf(p->out, "/GS%d gs\n", gstate); p->extgstates[gstate].used_on_current_page = pdc_true; }
void pdf_put_length_objs(PDF *p, PDF_data_source *t1src, pdc_id length1_id, pdc_id length2_id, pdc_id length3_id) { pdc_begin_obj(p->out, length1_id); /* Length1 object */ pdc_printf(p->out, "%ld\n", (long) ((t1_private_data *) t1src->private_data)->length[1]); pdc_end_obj(p->out); pdc_begin_obj(p->out, length2_id); /* Length2 object */ pdc_printf(p->out, "%ld\n", (long) ((t1_private_data *) t1src->private_data)->length[2]); pdc_end_obj(p->out); pdc_begin_obj(p->out, length3_id); /* Length3 object */ pdc_printf(p->out, "%ld\n", (long) ((t1_private_data *) t1src->private_data)->length[3]); pdc_end_obj(p->out); if (((t1_private_data *) t1src->private_data)->fontfile) pdc_fclose(((t1_private_data *) t1src->private_data)->fontfile); pdc_free(p->pdc, (void *) t1src->private_data); }