Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add a "line drawing (Straight)" from code only #752

Open
celalnuriakgun opened this issue Apr 6, 2022 · 6 comments
Open

How can I add a "line drawing (Straight)" from code only #752

celalnuriakgun opened this issue Apr 6, 2022 · 6 comments

Comments

@celalnuriakgun
Copy link

Summary
How can I add a "line drawing (Straight)" from code only, without providing any action from the editor? How can I adjust its position relative to the coordinates? How can I do it in skew?

Thanks.

Version
3.15.2

@celalnuriakgun
Copy link
Author

Oh, so sorry. I mean "rotate" instead "skew".

@celalnuriakgun
Copy link
Author

Or how to access Fabric class? Etc. fabric.Line?

Example:
var canvas = new fabric.Canvas('c');
var line = new fabric.Line([canvas.width / 2, 0, canvas.width / 2, canvas.height], {
strokeWidth:2,
stroke: 'red',
});

canvas.add(line);

@lja1018
Copy link
Contributor

lja1018 commented Apr 13, 2022

@celalnuriakgun
You cannot add directly by code. You have to turn on drawing mode and set brushes.

@celalnuriakgun
Copy link
Author

celalnuriakgun commented Apr 18, 2022

I solved;

editor.addShape('rect', {
        fill        : 'red',
        stroke      : 'red',
        top         : line.top,
        left        : line.left,
        height      : 5,
        width       : 200,
        angle       : 90,
})

@gongluzhen
Copy link

    // 画线路径
    const l = []
    // 画横线
    if (type === 'h') {
      l.push(rect.aCoords.tl.x - 1, e.y, rect.aCoords.tr.x + 1, e.y)
    }
    // 画竖线
    if (type === 'v') {
      l.push(e.x, rect.aCoords.tl.y - 1, e.x, rect.aCoords.br.y + 1)
    }
    var line = new fabric.Line(l, {
      strokeWidth: 3,
      stroke: 'red',
    })
    imageEditor._graphics._canvas.add(line)

但是 ctrl z 撤回不行

@stale
Copy link

stale bot commented Jul 31, 2022

This issue has been automatically marked as inactive because there hasn’t been much going on it lately. It is going to be closed after 7 days. Thanks!

@stale stale bot added the inactive label Jul 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants