Comments (6)
Hi! I don't think there's anything simple that will do this.
Interactive drawing applications probably store all graphics 'in the abstract' and then render them on any size drawing at scale/position, etc. And image editing applications can probably copy a buffer quickly onto another surface of a different size. With Cairo/Luxor, it's more like when you start to draw on a sheet of paper or whiteboard and then realize too late that you started out in the wrong place... :)
The nearest you're going to get at present is by using a recording surface and snapshots. I don't know anything about these (the feature was coded by @hustf :)), but the idea is that you specify a bounding box when you output the file. Of course, you still have to be able to keep track of and calculate the bounding box somehow (since graphics are inaccessible once they've been drawn).
Drawing(NaN, NaN, :rec) # no bounds
background("antiquewhite")
n_circles = 5
margin = 10
@layer begin # non-permanent transformations
for _ in 1:n_circles
randomhue()
circle(O, 10, :fill)
translate(30, 0)
end
end
snapshot(fname="/tmp/temp.svg",
cb=BoundingBox(Point(-margin, -100), Point(150, 100)))
finish()
from luxor.jl.
Talking of recording surfaces, there appears to be a Cairo function called cairo_recording_surface_ink_extents()
(https://cairographics.org/manual/cairo-Recording-Surfaces.html#cairo-recording-surface-ink-extents). This suggests that it could calculate the bounding box required to enclose the recording surface. However, my abilities in calling Cairo functions - and my understanding of the recording surface feature - are limited, and my attempt below doesn't work.
function recording_surface_ink_extents()
x0 = Cdouble[0]
y0 = Cdouble[0]
w = Cdouble[0]
h = Cdouble[0]
d = Luxor._get_current_drawing_save()
if d.surfacetype === :rec
ccall((:cairo_recording_surface_ink_extents, Luxor.Cairo.libcairo),
Ptr{Nothing},
(Ptr{Nothing}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}),
d.surface.ptr, x0, y0, w, h)
return BoundingBox(Point(x0[1], y0[1]), Point(x0[1] + w[1], y0[1] + h[1]))
else
throw(error("not a recording surface"))
end
end
See JuliaGraphics/Cairo.jl#356 for upstream solution.
from luxor.jl.
Hi! I don't think there's anything simple that will do this.
Thanks for the speedy response! I think the recording surface + snapshot looks like a great solution, and luckily in my case manually tracking the bounding box isn't too hard. From the docs on snapshot
referencing drawing
it seems like the snapshots can also be in memory with fname = :svg
? Seems excellent.
from luxor.jl.
If you encounter problems, it night be worth running on the current master. There’s been some recent work on this which hasn’t yet been released. (Here’s a place to start: #150 )
from luxor.jl.
Yes, this complicates things fast, which is why it's not in Luxor currently. Also, a surprising number of Luxor functions uses the limits defined in Drawing. In #258, I linked to a proposal, which makes alternative functions for limitless drawings.
from luxor.jl.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from luxor.jl.
Related Issues (20)
- Base Subtract operator between Luxor.Point and a Number is incorrect HOT 12
- Release 3.8.0 HOT 2
- MethodError: objects of type String are not callable HOT 3
- Update sethue() and setcolor() to accept Nothing arguement HOT 2
- Source code for how to create a graph for inclusion in Luxor Documentation HOT 7
- Drop dependencies like FFMPEG (in the long run)? HOT 6
- You can't just "Plot a pixel on the screen" HOT 3
- Remove dependency on Juno.jl HOT 3
- SVG with transparent background HOT 2
- transparency does not work for background color in svg HOT 2
- clip() using lines or boxes does not return an output HOT 2
- set_next_drawing_index` not defined HOT 3
- Time to release v4? HOT 5
- A 1x1 box is semi-transparent HOT 4
- Running @draw in a loop HOT 2
- Julia v1.11 internal changes HOT 2
- Add noindex and banner to older version documentations HOT 1
- Inconsistent behavior around tolerances in `isequal` and `isless` HOT 5
- Release 4.0 HOT 1
- Windows test failure because of Cairo_jll HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luxor.jl.