Ejemplo n.º 1
0
int project_add_font(Quark *project, const Fontdef *f)
{
    Project *pr = project_get_data(project);
    Fontdef *fnew;
    pr->fontmap = amem_realloc(project->amem,
        pr->fontmap, (pr->nfonts + 1)*sizeof(Fontdef));
    fnew = &pr->fontmap[pr->nfonts];
    fnew->id = f->id;
    fnew->fontname = amem_strdup(project->amem, f->fontname);
    fnew->fallback = amem_strdup(project->amem, f->fallback);
    pr->nfonts++;
    
    return RETURN_SUCCESS;
}
Ejemplo n.º 2
0
Project *project_data_new(AMem *amem)
{
    Project *pr;
    
    pr = amem_malloc(amem, sizeof(Project));
    if (!pr) {
        return NULL;
    }
    memset(pr, 0, sizeof(Project));
    
    pr->description = NULL;
    
    pr->prec = 8;

    pr->timestamp = amem_strdup(amem, "");

    /* FIXME: #defines */
    pr->page_wpp = 792;
    pr->page_hpp = 612;

    pr->ref_date = 0.0;
    pr->wrap_year = 1950;
    pr->two_digits_years = FALSE;
    
    pr->bgcolor  = 0;
    pr->bgfill   = TRUE;

    pr->fscale   = 0.025;
    pr->lscale   = 0.0015;

    pr->grdefaults = d_d;
    
    return pr;
}
Ejemplo n.º 3
0
int project_add_color(Quark *project, const Colordef *c)
{
    Project *pr = project_get_data(project);
    Colordef *cbuf;
    unsigned int i;
    
    /* Check whether a color with this id exists */
    for (i = 0; i < pr->ncolors; i++) {
        cbuf = &pr->colormap[i];
        if (cbuf->id == c->id) {
            cbuf->rgb = c->rgb;
            cbuf->cname = amem_strcpy(project->amem, cbuf->cname, c->cname);
            
            return RETURN_SUCCESS;
        }
    }
    
    /* If id not found */
    pr->colormap = amem_realloc(project->amem,
        pr->colormap, (pr->ncolors + 1)*sizeof(Colordef));
    cbuf = &pr->colormap[pr->ncolors];
    cbuf->id = c->id;
    cbuf->rgb = c->rgb;
    cbuf->cname = amem_strdup(project->amem, c->cname);
    pr->ncolors++;
    
    pr->colorlist.colormap = pr->colormap;
    pr->colorlist.ncolors  = pr->ncolors;

    return RETURN_SUCCESS;
}
Ejemplo n.º 4
0
/* 
 * Coalesce two SSDs. fromq will be deleted, preceded by transferring of all
 * its children to toq
 */
int ssd_coalesce(Quark *toq, Quark *fromq)
{
    unsigned int nrows, ncols, i, j;
    ss_data *ssd;
    AMem *amem  = toq->amem;
    coalesce_hook_t p;
       
    nrows = ssd_get_nrows(fromq);
    if (nrows > ssd_get_nrows(toq)) {
        if (ssd_set_nrows(toq, nrows) != RETURN_SUCCESS) {
            return RETURN_FAILURE;
        }
    }

    /* original number of columns */
    ncols = ssd_get_ncols(toq);
    
    ssd = ssd_get_data(fromq);
    for (i = 0; i < ssd->ncols; i++) {
        ss_column *col = &ssd->cols[i];
        
        ss_column *col_new = ssd_add_col(toq, col->format);
        if (!col_new) {
            return RETURN_FAILURE;
        }
        
        col_new->label = amem_strdup(amem, col->label);
        
        if (col->format == FFORMAT_STRING) {
            for (j = 0; j < nrows; j++) {
                ((char **) col_new->data)[j] =
                    amem_strdup(amem, ((char **) col->data)[j]);
            }
        } else {
            memcpy(col_new->data, col->data, nrows*SIZEOF_DOUBLE);
        }
    }
    
    p.toq = toq;
    p.nshift = ncols;
    quark_traverse(fromq, coalesce_hook, &p);
    
    quark_free(fromq);
    
    return RETURN_SUCCESS;
}
Ejemplo n.º 5
0
int set_axisgrid_data(AGridUI *ui, Quark *q, void *caller)
{
    tickmarks *t = axisgrid_get_data(q);

    if (t && ui) {
        AMem *amem = quark_get_amem(q);
        int i;
        
        if (!caller || caller == ui->type) {
            t->type = GetOptionChoice(ui->type);
        }

        if (!caller || caller == ui->tmajor) {
            if (xv_evalexpr(ui->tmajor, &t->tmajor) != RETURN_SUCCESS) {
                errmsg("Specify major tick spacing");
                return RETURN_FAILURE;
            }
        }
        if (!caller || caller == ui->nminor) {
            t->nminor = (int) SpinChoiceGetValue(ui->nminor);
        }
        if (!caller || caller == ui->tlform) {
            Format *format = GetFormatChoice(ui->tlform);
            AMem *amem = quark_get_amem(q);
            amem_free(amem, t->tl_format.fstring);
            t->tl_format = *format;
            t->tl_format.fstring = amem_strdup(amem, format->fstring);
            format_free(format);
        }
        if (!caller || caller == ui->tlfont) {
            t->tl_tprops.font = GetOptionChoice(ui->tlfont);
        }
        if (!caller || caller == ui->tlcolor) {
            t->tl_tprops.color = GetOptionChoice(ui->tlcolor);
        }
        if (!caller || caller == ui->barpen) {
            GetPenChoice(ui->barpen, &t->bar.pen);
        }
        if (!caller || caller == ui->barlinew) {
            t->bar.width = SpinChoiceGetValue(ui->barlinew);
        }
        if (!caller || caller == ui->barlines) {
            t->bar.style = GetOptionChoice(ui->barlines);
        }
        if (!caller || caller == ui->tlcharsize) {
            t->tl_tprops.charsize = SpinChoiceGetValue(ui->tlcharsize);
        }
        if (!caller || caller == ui->tlangle) {
            t->tl_tprops.angle = GetAngleChoice(ui->tlangle);
        }
        if (!caller || caller == ui->tlstagger) {
            t->tl_staggered = GetOptionChoice(ui->tlstagger);
        }
        if (!caller || caller == ui->tlstarttype) {
            t->tl_starttype = GetOptionChoice(ui->tlstarttype) == 0 ?
                TYPE_AUTO : TYPE_SPEC;
        }
        if (!caller || caller == ui->tlstart) {
            if (t->tl_starttype == TYPE_SPEC) {
                if (xv_evalexpr(ui->tlstart, &t->tl_start) != RETURN_SUCCESS) {
                errmsg("Specify tick label start");
                    return RETURN_FAILURE;
                }
            }
        }
        if (!caller || caller == ui->tlstoptype) {
            t->tl_stoptype = GetOptionChoice(ui->tlstoptype) == 0 ?
                TYPE_AUTO : TYPE_SPEC;
        }
        if (!caller || caller == ui->tlstop) {
            if (t->tl_stoptype == TYPE_SPEC) {
                if (xv_evalexpr(ui->tlstop, &t->tl_stop) != RETURN_SUCCESS) {
                    errmsg("Specify tick label stop");
                    return RETURN_FAILURE;
                }
            }
        }
        if (!caller || caller == ui->tlskip) {
            t->tl_skip = GetOptionChoice(ui->tlskip);
        }
        if (!caller || caller == ui->tlformula) {
            char *s = TextGetString(ui->tlformula);
            t->tl_formula = amem_strcpy(amem, t->tl_formula, s);
            xfree(s);
        }
        if (!caller || caller == ui->tlprestr) {
            char *s = TextGetString(ui->tlprestr);
            t->tl_prestr = amem_strcpy(amem, t->tl_prestr, s);
            xfree(s);
        }
        if (!caller || caller == ui->tlappstr) {
            char *s = TextGetString(ui->tlappstr);
            t->tl_appstr = amem_strcpy(amem, t->tl_appstr, s);
            xfree(s);
        }
        if (!caller || caller == ui->tlgap_para) {
            xv_evalexpr(ui->tlgap_para, &t->tl_gap.x);
        }
        if (!caller || caller == ui->tlgap_perp) {
            xv_evalexpr(ui->tlgap_perp, &t->tl_gap.y);
        }
        if (!caller || caller == ui->tround) {
            t->t_round = ToggleButtonGetState(ui->tround);
        }
        if (!caller || caller == ui->autonum) {
            t->t_autonum = GetOptionChoice(ui->autonum) + 2;
        }


        if (!caller || caller == ui->tgrid) {
            t->gprops.onoff = ToggleButtonGetState(ui->tgrid);
        }
        if (!caller || caller == ui->tgridpen) {
            GetPenChoice(ui->tgridpen, &t->gprops.line.pen);
        }
        if (!caller || caller == ui->tgridlinew) {
            t->gprops.line.width = SpinChoiceGetValue(ui->tgridlinew);
        }
        if (!caller || caller == ui->tgridlines) {
            t->gprops.line.style = GetOptionChoice(ui->tgridlines);
        }

        if (!caller || caller == ui->tmgrid) {
            t->mgprops.onoff = ToggleButtonGetState(ui->tmgrid);
        }
        if (!caller || caller == ui->tmgridpen) {
            GetPenChoice(ui->tmgridpen, &t->mgprops.line.pen);
        }
        if (!caller || caller == ui->tmgridlinew) {
            t->mgprops.line.width = SpinChoiceGetValue(ui->tmgridlinew);
        }
        if (!caller || caller == ui->tmgridlines) {
            t->mgprops.line.style = GetOptionChoice(ui->tmgridlines);
        }


        if (!caller || caller == ui->tinout) {
            t->props.inout = GetOptionChoice(ui->tinout);
        }
        if (!caller || caller == ui->tlen) {
            t->props.size = SpinChoiceGetValue(ui->tlen);
        }
        if (!caller || caller == ui->tpen) {
            GetPenChoice(ui->tpen, &t->props.line.pen);
        }
        if (!caller || caller == ui->tgridlinew) {
            t->props.line.width = SpinChoiceGetValue(ui->tlinew);
        }
        if (!caller || caller == ui->tgridlines) {
            t->props.line.style = GetOptionChoice(ui->tlines);
        }
        if (!caller || caller == ui->tminout) {
            t->mprops.inout = GetOptionChoice(ui->tminout);
        }
        if (!caller || caller == ui->tmlen) {
            t->mprops.size = SpinChoiceGetValue(ui->tmlen);
        }
        if (!caller || caller == ui->tmpen) {
            GetPenChoice(ui->tmpen, &t->mprops.line.pen);
        }
        if (!caller || caller == ui->tmgridlinew) {
            t->mprops.line.width = SpinChoiceGetValue(ui->tmlinew);
        }
        if (!caller || caller == ui->tmgridlines) {
            t->mprops.line.style = GetOptionChoice(ui->tmlines);
        }
        if (!caller ||
            caller == ui->specticks || caller == ui->nspec || caller == ui->specloc) {
            t->t_spec = GetOptionChoice(ui->specticks);
            /* only read special info if special ticks used */
            if (t->t_spec != TICKS_SPEC_NONE) {
                t->nticks = (int) SpinChoiceGetValue(ui->nspec);
                /* ensure that enough tick positions have been specified */
                for (i = 0; i < t->nticks; i++) {
                    if (xv_evalexpr(ui->specloc[i], &t->tloc[i].wtpos) ==
                                                        RETURN_SUCCESS) {
                        char *cp, *s;
                        cp = TextGetString(ui->speclabel[i]);
                        if (cp[0] == '\0') {
                            t->tloc[i].type = TICK_TYPE_MINOR;
                        } else {
                            t->tloc[i].type = TICK_TYPE_MAJOR;
                        }
                        if (t->t_spec == TICKS_SPEC_BOTH) {
                            s = cp;
                        } else {
                            s = NULL;
                        }
                        t->tloc[i].label =
                            amem_strcpy(amem, t->tloc[i].label, s);
                        xfree(cp);
                    }
                } 
            }
        }
        
        quark_dirtystate_set(q, TRUE);
        
        return RETURN_SUCCESS;
    } else {
        return RETURN_FAILURE;
    }
}
Ejemplo n.º 6
0
int graph_set_data(GraphUI *ui, Quark *q, void *caller)
{
    if (quark_fid_get(q) == QFlavorGraph) {
        double axislim, znorm;
        world w;
        GLocator *locator;

        graph_get_world(q, &w);
        locator = graph_get_locator(q);

        if (!caller || caller == ui->graph_type) {
            graph_set_type(q, GetOptionChoice(ui->graph_type));
        }
        if (!caller || caller == ui->stacked) {
            graph_set_stacked(q, GetToggleButtonState(ui->stacked));
        }
        if (!caller || caller == ui->flip_xy) {
            graph_set_xyflip(q, GetToggleButtonState(ui->flip_xy));
        }

        if (!caller || caller == ui->start_x) {
            if (xv_evalexpr(ui->start_x, &axislim) != RETURN_SUCCESS) {
                errmsg("Axis start/stop values undefined");
                return RETURN_FAILURE;
            }
            w.xg1 = axislim;
        }
        if (!caller || caller == ui->stop_x) {
            if (xv_evalexpr(ui->stop_x, &axislim) != RETURN_SUCCESS) {
                errmsg("Axis start/stop values undefined");
                return RETURN_FAILURE;
            }
            w.xg2 = axislim;
        }

        if (!caller || caller == ui->start_y) {
            if (xv_evalexpr(ui->start_y, &axislim) != RETURN_SUCCESS) {
                errmsg("Axis start/stop values undefined");
                return RETURN_FAILURE;
            }
            w.yg1 = axislim;
        }
        if (!caller || caller == ui->stop_y) {
            if (xv_evalexpr(ui->stop_y, &axislim) != RETURN_SUCCESS) {
                errmsg("Axis start/stop values undefined");
                return RETURN_FAILURE;
            }
            w.yg2 = axislim;
        }

        if (!caller ||
            caller == ui->start_x || caller == ui->stop_x ||
            caller == ui->start_y || caller == ui->stop_y) {
            graph_set_world(q, &w);
        }

        if (!caller || caller == ui->scale_x) {
            graph_set_xscale(q, GetOptionChoice(ui->scale_x));
        }
        if (!caller || caller == ui->invert_x)  {
            graph_set_xinvert(q, GetToggleButtonState(ui->invert_x));
        }

        if (!caller || caller == ui->scale_y) {
            graph_set_yscale(q, GetOptionChoice(ui->scale_y));
        }
        if (!caller || caller == ui->invert_y)  {
            graph_set_yinvert(q, GetToggleButtonState(ui->invert_y));
        }

        if (!caller || caller == ui->bargap) {
            graph_set_bargap(q, GetSpinChoice(ui->bargap));
        }
        if (!caller || caller == ui->znorm) {
            xv_evalexpr(ui->znorm, &znorm);
            graph_set_znorm(q, znorm);
        }


        if (!caller || caller == ui->loc_type) {
            locator->type = GetOptionChoice(ui->loc_type);
            quark_dirtystate_set(q, TRUE);
        }
        if (!caller || caller == ui->loc_fx) {
            Format *format = GetFormatChoice(ui->loc_fx);
            AMem *amem = quark_get_amem(q);
            amem_free(amem, locator->fx.fstring);
            locator->fx = *format;
            locator->fx.fstring = amem_strdup(amem, format->fstring);
            format_free(format);
            quark_dirtystate_set(q, TRUE);
        }
        if (!caller || caller == ui->loc_fy) {
            Format *format = GetFormatChoice(ui->loc_fy);
            AMem *amem = quark_get_amem(q);
            amem_free(amem, locator->fy.fstring);
            locator->fy = *format;
            locator->fy.fstring = amem_strdup(amem, format->fstring);
            format_free(format);
            quark_dirtystate_set(q, TRUE);
        }
        if (!caller || caller == ui->fixedp) {
            locator->pointset = GetToggleButtonState(ui->fixedp);
            quark_dirtystate_set(q, TRUE);
        }
        if (!caller || caller == ui->locx) {
            xv_evalexpr(ui->locx, &locator->origin.x); 
            quark_dirtystate_set(q, TRUE);
        }
        if (!caller || caller == ui->locy) {
            xv_evalexpr(ui->locy, &locator->origin.y); 
            quark_dirtystate_set(q, TRUE);
        }

        return RETURN_SUCCESS;
    } else {
        return RETURN_FAILURE;
    }
}