コード例 #1
0
ファイル: xyview.cpp プロジェクト: vortexlaboratory/neuron
void View::transform(
    Transformer& t, const Allocation& a, const Allocation&
) const {
    scene2view(a);
    const Allotment& ax = a.x_allotment();
    const Allotment& ay = a.y_allotment();
    csize(ax.begin(), ax.span(), ay.begin(), ay.span());
    float sx = ax.span()/XYView::width();
    float sy = ay.span()/XYView::height();
//	if (sx > sy) sx = sy;
    t.translate( -x(), -y());
    t.scale(sx, sx);
    View* v = (View*)this;
    v->x_pick_epsilon_ = pick_epsilon/sx;
    v->y_pick_epsilon_ = pick_epsilon/sx;
    t.translate((ax.begin() + ax.end())/2,(ay.begin() + ay.end())/2);
//printf("\nx origin=%g span=%g alignment=%g begin=%g end=%g\n", ax.origin(), ax.span(), ax.alignment(), ax.begin(), ax.end());
//printf("\ny origin=%g span=%g alignment=%g begin=%g end=%g\n", ay.origin(), ay.span(), ay.alignment(), ay.begin(), ay.end());
    Coord x1,y1;
    t.transform(x() - x_span_/2, y() - y_span_/2, x1, y1);
    if (!Math::equal(ax.begin(), x1, 1) || !Math::equal(ay.begin(), y1, 1)) {
        t.inverse_transform(ax.begin(), ay.begin(), x1, y1);
        v->x_span_ = 2*(x() - x1);
        v->y_span_ = 2*(y() - y1);
        v->size(x1,y1,x1+v->x_span_, y1+v->y_span_);
    }

}
コード例 #2
0
ファイル: xyview.cpp プロジェクト: vortexlaboratory/neuron
void XYView::transform(
    Transformer& t, const Allocation& a, const Allocation& n
) const {
#if 0
    Allotment ax, ay;
    if (view_margin()) {
        const Allotment& alx = a.x_allotment();
        ax.span(alx.span() - 2*view_margin());
        ax.origin(alx.begin() + view_margin());
        ax.alignment(0);
        const Allotment& aly = a.y_allotment();
        ay.span(aly.span() - 2*view_margin());
        ay.origin(aly.begin() + view_margin());
        ay.alignment(0);
    } else {
        ax = a.x_allotment();
        ay = a.y_allotment();
    }
    Allocation al;
    al.allot_x(ax);
    al.allot_y(ay);
    scene2view(al);
#else
    scene2view(a);
    const Allotment& ax = a.x_allotment();
    const Allotment& ay = a.y_allotment();
#endif
    const Allotment& nx = n.x_allotment();
    const Allotment& ny = n.y_allotment();
    XYView* v = (XYView*)this;
    csize(ax.begin(), ax.span(), ay.begin(), ay.span());
    float sx = xsize_/width();
    float sy = ysize_/height();
    XYView* xv = (XYView*)this;
    xv->x_pick_epsilon_ = pick_epsilon/sx;
    xv->y_pick_epsilon_ = pick_epsilon/sy;
    t.translate( -left(), -bottom());
    t.scale(sx, sy);
    t.translate(ax.begin(), ay.begin());
#if 0
    printf("XYView::transform ax origin=%g span=%g alignment=%g begin=%g\n",
           ax.origin(), ax.span(), ax.alignment(), ax.begin());
    printf("XYView::transform ay origin=%g span=%g alignment=%g begin=%g %g\n",
           ay.origin(), ay.span(), ay.alignment(), ay.begin(), ay.end());
    printf("XYView::transform natx origin=%g span=%g alignment=%g begin=%g\n",
           nx.origin(), nx.span(), nx.alignment(), nx.begin());
    printf("XYView::transform naty origin=%g span=%g alignment=%g begin=%g %g\n",
           ny.origin(), ny.span(), ny.alignment(), ny.begin(), ny.end());
#endif
}
コード例 #3
0
void TransformFitter::transform(
    Transformer& t, const Allocation& a, const Allocation& natural
) const {
    const Allotment& natural_x = natural.x_allotment();
    const Allotment& natural_y = natural.y_allotment();
    if (!Math::equal(natural_x.span(), Coord(0), float(1e-2)) &&
	!Math::equal(natural_y.span(), Coord(0), float(1e-2))
    ) {
	const Allotment& ax = a.x_allotment();
	const Allotment& ay = a.y_allotment();
	t.scale(
	    a.x_allotment().span() / natural_x.span(),
	    a.y_allotment().span() / natural_y.span()
	);
    }
    t.translate(a.x(), a.y());
}
コード例 #4
0
Glyph* read_idraw_graphic (
    FILE* file, const Brush* pb, const Color* pfg, const Color* pbg,
    const Font* pf, Stipple* ps
) {
    skip(file);
    Transformer tx;
    Glyph* glyph = nil;
    const LayoutKit& layout = *LayoutKit::instance();
    if (fscanf(file, "%s", buffer) != EOF) {
        figure& fig = figures[which(figures, buffer)];

        if (strcmp(fig.name, "Idraw") == 0) {
            fscanf(file, "%d", &drawing_version);
            figures = versions[drawing_version];
        }
        const Brush* b = (fig.brush) ? read_brush(file) : nil;
        const Color* fg = (fig.foreground) ? read_color(file) : nil;
        const Color* bg = (fig.background) ? read_color(file) : nil;
        const Font* f = (fig.font) ? read_font(file) : nil;
        Stipple* s = (fig.pattern) ? read_stipple(file) : nil;
        if (fig.transformer) {
            read_transformer(file, tx);
        }

        if (pb) b = pb;
        if (pfg) fg = pfg;
        if (pbg) bg = pbg;
        if (pf) f = pf;
        if (ps) s = ps;

        if (fig.name == nil) {
            ; // error
        } else if (
            strcmp(fig.name, "Idraw") == 0 || strcmp(fig.name, "Pict") == 0
        ) {
            Glyph* pic = layout.overlay();
            Glyph* g;
            do {
                g = read_idraw_graphic(file, b, fg, bg, f, s);
                if (g != nil) {
                    pic->append(g);
                }
            } while (g != nil);
            glyph = pic;
        } else if (strcmp(fig.name, "eop") == 0) {
            glyph = nil;
        } else if (strcmp(fig.name, "Text") == 0) {
            skip(file);
            fscanf(file, "%s", buffer);
            getc(file);
            PolyGlyph* col = layout.vbox_first_aligned();
            PolyGlyph* line = layout.hbox_first_aligned();
	    FontBoundingBox bbox;
	    f->font_bbox(bbox);
            Coord lineheight = bbox.font_ascent() + bbox.font_descent();
            if (_idraw_font_metrics) {
                lineheight /= fixtextscale;
            }
            int c;
            while ((c = getc(file)) != ']') {
                if (c == '\n') {
                    line->append(layout.strut(f));
                    col->append(
			layout.v_fixed_span(line, lineheight)
		    );
                    line = layout.hbox();
                } else if (c == ' ') {
                    if (_idraw_font_metrics) {
                        line->append(
			    layout.shape_of(new Character(' ', f, fg))
			);
                    } else {
                        line->append(new Character(' ', f, fg));
                    }
                } else if (c != ')' && c != '(') {
                    if (c == '\\') {
                        c = getc(file);
			if (isdigit(c)) {
			    c -= '0';
			    c = (c * 8) + getc(file) - '0';
			    c = (c * 8) + getc(file) - '0';
			}
                    }
                    line->append(new Character(c, f, fg));
                }
            }
            Transformer fixtext;
            if (_idraw_font_metrics) {
                fixtext.scale(fixtextscale, fixtextscale);
            }
            fixtext.translate(0, bbox.font_descent() - lineheight);
            glyph = new TransformSetter(col, fixtext);
        } else {
            skip(file);
            int c = fig.coords;
            if (c == -1) { 
                fscanf(file, "%d", &c);
            }
            Coord xx, yy;
            Coord* x = new Coord[c];
            Coord* y = new Coord[c];
            for (int i = 0; i < c; ++i) {
                fscanf(file, "%g %g", &xx, &yy);
                x[i] = xx;
                y[i] = yy;
            }

            const Brush* brush = (b != no_brush) ? b : nil;
            const Color* stroke = fg;
            const Color* fill = (
                (s != no_stipple) ? dither_color(fg, bg, s->_dither) : nil
            );
            if (strcmp(fig.name, "Line") == 0) {
                glyph = new Line(brush, stroke, fill, x[0], y[0], x[1], y[1]);
            } else if (strcmp(fig.name, "BSpl") == 0) {
                glyph = new Open_BSpline(brush, stroke, fill, x, y, c);
            } else if (strcmp(fig.name, "CBSpl") == 0) {
                glyph = new Closed_BSpline(brush, stroke, fill, x, y, c);
            } else if (strcmp(fig.name, "MLine") == 0) {
                glyph = new Polyline(brush, stroke, fill, x, y, c);
            } else if (strcmp(fig.name, "Poly") == 0) {
                glyph = new Polygon(brush, stroke, fill, x, y, c);
            } else if (strcmp(fig.name, "Rect") == 0) {
                glyph = new Rectangle(brush, stroke, fill,x[0],y[0],x[1],y[1]);
            } else if (strcmp(fig.name, "Circ") == 0) {
                fscanf(file, "%f", &xx);
                glyph = new Circle(brush, stroke, fill, x[0], y[0], xx);
            } else if (strcmp(fig.name, "Elli") == 0) {
                fscanf(file, "%f %f", &xx, &yy);
                glyph = new Ellipse(brush, stroke, fill, x[0], y[0], xx, yy);
            } else {
                glyph = nil;
            }
            delete x;
            delete y;
        }
        for (int extra = fig.skip; extra > 0; --extra) {
            skip(file);
        }
    }
    if (glyph != nil && !tx.identity()) {
        glyph = new TransformSetter(glyph, tx);
    }
    return glyph;
}