aseldawy / rasem Goto Github PK
View Code? Open in Web Editor NEWrasem is a pure ruby gem that allows you to describe your SVG images in ruby code
License: MIT License
rasem is a pure ruby gem that allows you to describe your SVG images in ruby code
License: MIT License
Rasem prefixes every generated SVG with a XML- and DOCTYPE-header.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="#{width}" height="#{height}" version="1.1"
xmlns="http://www.w3.org/2000/svg">
There should be an option to disable this header when outputting directly into HTML code (i.e. embedding the SVG in HTML-code).
Thanks!
can not use the transform "style" to do things like rotation and scaling.
I forked and added code to "write_style(style)"
It works with text but still need to test with other objects
exp:
File.open("test.svg", "w") do |f|
Rasem::SVGImage.new(100, 100, f) do |f|
text 50+(-10+(rand(20))), 50+(-10+(rand(20))), "O", :font_family=>"Akho Desire", "font-size"=>24
text 50+(-10+(rand(20))), 50+(-10+(rand(20))), "I", :font_family=>"Akho Will", "font-size"=>24
text 50+(-10+(rand(20))), 50+(-10+(rand(20))), "A", :font_family=>"Akho Believe", "font-size"=>24, :transform=>" matrix(0,1,-1,0,0,0)"
end
end
When the .rasem file has a syntax error or runtime error, we need the stack trace to point to the error in this file rather than a backtrace pointing to the gem source files
For SVGs we generate, we need to have attributes on the root node, e.g., viewBox
, class
, and style
. I don't see a documented or spec'ed way to do this.
i = Rasem::SVGImage.new(100, 100) do
line(0, 0, 100, 100)
end
TypeError: no implicit conversion of Symbol into Integer
from /.rvm/gems/ruby-2.3.3/gems/rasem-0.7.1/lib/rasem/svg_image.rb:426:in `[]'
from /.rvm/gems/ruby-2.3.3/gems/rasem-0.7.1/lib/rasem/svg_image.rb:426:in `initialize'
from (irb):17:in `new'
from (irb):17
from /.rvm/rubies/ruby-2.3.3/bin/irb:11:in `<main>'
Ruby 2.3.3
rasem-0.7.1
Hi Ahmet,
your gem is look like awesome! I want to ask how to edit world map svg image with your gem? Can i open any file with it? And if i can, can i edit it and export to svg or other file type?
Thanks!
Ilker
Solution: change this line to set them to nil
instead of 0
, as (surprisingly) 0 && 0
is truthy.
I'd make a PR if there was any recent activity indicating it would be merged.
Any progress on the export to PNG feature? :)
Add support for text
I love this gem; I end up pulling it out of the toolbox for something about every six months.
Problem
Following the example at https://stackoverflow.com/questions/30229943/hand-drawing-crayon-style-for-svg-path, I tried to create a brush-stroke filter like:
filter(:id=>'strokeFilter') do
feTurbulence(:baseFrequency=>"0.2", :numOctaves=>"3", :type=>"fractalNoise")
feDisplacementMap(:xChannelSelector=>"R", :in=>"SourceGraphic", :'scale'=>"8")
end
and got:
"svg_image.rb:169:in `validate_attribute': feDisplacementMap does not support attribute transform"
It looks like validate_attributes(attributes) sees the 'scale' attribute and tries to translate it to a 'transform' attribute internally, but 'scale' is actually a valid attribute on feDisplacementMap.
Possible Solution
I modified validate_attributes like:
def validate_attributes(attributes , tag )
clean_attributes = {}
transforms = {}
styles = {}
attributes.each do |attribute, value|
if Rasem::SVG_TRANSFORM.include?(attribute) && !Rasem::SVG_STRUCTURE[@tag.to_sym][:attributes].include?(attribute.to_sym)
transforms[attribute] = value
...
(adding the tag parameter and the && !Rasem::SVG_STRUCTURE...) and it seems to work fine now. I haven't tested anything else, though.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.