How to get coordinates of an svg? - dictionary

How can I find out the coordinates of an svg? I have an Adobe Illustrator file that contains a map, this has been drawn and separated into US states, how can I find the coordinates of each state?
I'm just using the US map as an example, I'm going to potentially use this technique for several other maps (much more local!!).

Inkscape does that beautifully. It has a command interface, described in http://tavmjong.free.fr/INKSCAPE/MANUAL/html/CommandLine.html . (The link is to a copy of the manual on the website of its author, Tavmjong Bah. Note that it warns that the manual hasn't been updated for the latest version of Inkscape. However, the command worked fine when I tried it.)
This command
inkscape -S some_file.svg
will output lines containing an element id, the x and y coordinates of the top-left corner, and the element's width and height. There is one line for each element of the SVG. Here's an example:
svg2293,26.447175,24,97.105652,92.450851
layer1,26.447175,24,97.105652,92.450851
MyStar,26.447175,24,97.105652,92.450851
This example comes from http://tavmjong.free.fr/INKSCAPE/MANUAL/html/CommandLine-Query.html . It extracts information from an SVG which includes a star shape, shown on my first link.
On my Windows 10 system, Inkscape lives in c:\Program Files\Inkscape\ , and the executables are in the bin\ subdirectory of that. If I cd to that subdirectory, Windows will recognise the inkscape command; likewise if I use the full path to the executable from somewhere else, e.g.
"c:\Program Files\Inkscape"\bin\inkscape -S some_file.svg
Putting it on my PATH would presumably also work.
Inkscape has a lot of other commands, which include others for extracting information about object positions and sizes. The latter are called "query commands". One can extract information about a specified object, e.g.
inkscape --query-id=zoom-in -X /usr/share/inkscape/icons/icons.svg
This is an example of finding the x position of the zoom-in icon in the default icon file on a Linux system.
To save the output to a file, use > . E.g.
"c:\Program Files\Inkscape"\bin\inkscape -S some_file.svg > coords.txt
As it's reassuring to see actual examples, here are two screenshots of this working.
Once you have the data in a file, you can read it into programs. Below is a screenshot of me doing this in the R programming language, using the read_csv function ( https://readr.tidyverse.org/reference/read_delim.html ). This puts the data into a table, which I then displayed.

SVG have an XML structure. The states will be in <path> tags, hopefully with the name of the state somewhere as an attribute. The coordinates of a path are defined by the d attribute, but they can get quite complex as they can be relative or absolute and have various types of curves. With curves, it's probably simplest to consider just the final two values, which is where the curve ends.
For full details, see: http://www.w3.org/TR/SVG/paths.html#PathDataGeneralInformation
The situation may be more complex if further transforms are applied to the paths. Good luck!

Related

Compare actual file with file at specific baseline

I'm using clearcase 8.0.1.17, I want to compare a file in my wiew and his version at a specific baseline.
I can open version tree and see my baseline but I want to do that with command line.
My purpose is to do something like :
> myScript.sh file.c baseline
This will open bcompare and compare my actual file vs the version baseline
How can I do that ?
I can do :
> cleartool lsvtree myfile | grep myBaseline
But is there is no changes at myBaline it doesn't work.
First, make sure to try that in a dynamic view
Then check out the concept of version extended path: using a pathname_ccase syntax, you can add characters to the end of a relative or full path name, turning it into a VOB-extended path name.
VOB-extended path names that specify versions of elements are the most commonly used; they are called version-extended path names.
/vobs/proj/foo.c##/main/motif/4
That means you can:
find the version of the file with as label the Baseline name: see "How to search files by label"
compare that extended path name with the one currently visible in your view.
The idea is: in a dynamic view, you can access (read the content of) any version of a file through the extended pathname.
Which means you can execute bcompare on those contents (the one with the extended path, and the one currently visible in your view)
Of course, if this is an incremental baseline (instead of full), you might need a cleartool chbl -full to convert it to a full baseline, applying the UCM associated label to all files.
If you do a cleartool describe baseline:mybaseline#\myvobtag you will probably find that your baseline is an incremental baseline. Incremental baselines do not have a label on the version if it was changed in a prior baseline and not the current one...
cleartool diffbl -versions {baseline} {current stream} | grep {filename} can be used to find the version of the target file that is in the baseline, which you can use to do the compare...

Command-line equivalent of CSS filter

I'm currently working with pictures and I try to do the same thing as the CSS filter below but in command line:
filter: invert(0.86) hue-rotate(180deg);
To do the trick I used imagemagick's convert tool.
convert $in -evaluate add -26% -negate -modulate 100,100,0 $out
I get close to the result I expect, but I have a huge quality drop. Let's show this in an example
Original version (a random jpg image)
Clean version (made with CSS, expected result)
Dirty one, made with convert
Is there any way (with this tool or another) to convert my image smoothly? The best would be to directly apply css to this image but I don't know whether it's possible in commandline...

GNAT Metric and RTL files

For running GNAT metric (for Windows, GPL 2017 or CE 2018) I'd like to include the RTL sources as well. There is a "-a" switch but it seems to be ineffective. When I'm forcing visibility of RTL sources, only ada.ads and system.ads are processed. Guessing it is a "crunched name" issue (RTL file names forced to 8 character names) I've tried other tricks without success.
My question is: is there a way to get the RTL source metrics (of the source files actually used) with GNAT Metric?
I'm using the command
gnatmetric -a -xs -nt -j0 -Pmyproj.gpr -U somemain.adb
TIA
In the meantime I've found a workaround by using the gnathtml.pl script.
I've customized the script a bit by removing the H1 headers.
The result is a few hundreds of HTML files with the sources of units actually used: the script does find all dependencies, recursively, through the .ali files - including the RTL.
Then I group the HTML files together, convert them back to text files, pass them through Adalog's Normalize tool for removing comments and empty lines, count lines with the wc command, and the job is done.

How can I verify a SVG doc is correct? (version 1.2)

I used a program called Fritzing to draw some basic Arduino schematics, and then export the output as a SVG. This works just as expected, but then I noticed that the SVG output only looks okay in some browsers and only okay in some versions of Firefox.
Since Fritzing is a open source app I figured that I could look into the code (and maybe help out a little).
But now over to the question, what is a correct SVG supposed to look like? What verifier over at W3C can I use to check the file?
I tried to use the verifiers found on this page: http://validator.w3.org/dev/tests/
But they all complained a lot, especially about the SVG version. The verifiers seem to like version 1.0 and 1.1, but when I look at the top of this file seems to be using version 1.2?
This is the top three lines from the problematic file (reformatted for readability):
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<!-- Created with Fritzing (http://www.fritzing.org/) -->
<svg width="3.50927in"
x="0in"
version="1.2"
y="0in"
xmlns="http://www.w3.org/2000/svg"
height="2.81713in"
viewBox="0 0 252.667 202.833"
baseProfile="tiny"
xmlns:svg="http://www.w3.org/2000/svg">
Is there a specific SVG 1.2 verifier I can use?
Or shall I try to verify the SVG as if it was a classical XML file?
(As a side note, Fritzing seems to use Qt, so if there some QTest I can use it may be useful.)
You can use e.g http://validator.nu. Since your file is standalone, select xml parsing, paste the RNG url in the schema textfield (the schema url you're looking can be found in the relevant specification, in this case SVG 1.2 Tiny: http://www.w3.org/TR/SVGTiny12/relaxng/Tiny-1.2.rng ).
Even your three line snippet isn't valid SVG 1.2 Tiny content (x and y attributes are not allowed on the <svg> element in Tiny). You should add a link to your file somewhere, otherwise it's hard to say what it should look like.
There is a python utility in terminal svgcheck, which claims to target version 1.2, as defined in draft-7996-bis. A promising utility, IMHO.
SVG Checking Procedure.
pip install svgcheck
svgcheck ~/path/to/mysvgfile.svg
The svg file with proper standards will give something like:
$ svgcheck alert-circle.svg
Parsing file alert-circle.svg
INFO: File conforms to SVG requirements.
Make sure you have pip installed and python configured properly
For the subset SVG Tiny 1.2 Portable/Secure (SVG P/S), used for example in Brand Indicators for Message Identification (BIMI), see Using the RNC Schema to Validate BIMI SVG Images. It shows how to perform Relax NG Compact (RNC) XML schema validation on the command line.
pip3 install jingtrang
wget 'https://bimigroup.org/resources/SVG_PS-latest.rnc.txt'
pyjing -c SVG_PS-latest.rnc.txt my-image.svg
For my use-case, a PNG logotype converted to SVG Tiny 1.2 using png2svg, this was the output.
my-image.svg:1:159: error: value of attribute "baseProfile" is invalid; must be equal to "tiny-ps"
my-image.svg:1:174: error: element "g" not allowed yet; missing required element "title"
Errors were easily fixed by editing the baseProfile value and adding <title>A very nice image title</title>.

What are the dark corners of Vim your mom never told you about? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
There are a plethora of questions where people talk about common tricks, notably "Vim+ctags tips and tricks".
However, I don't refer to commonly used shortcuts that someone new to Vim would find cool. I am talking about a seasoned Unix user (be they a developer, administrator, both, etc.), who thinks they know something 99% of us never heard or dreamed about. Something that not only makes their work easier, but also is COOL and hackish. After all, Vim resides in the most dark-corner-rich OS in the world, thus it should have intricacies that only a few privileged know about and want to share with us.
Might not be one that 99% of Vim users don't know about, but it's something I use daily and that any Linux+Vim poweruser must know.
Basic command, yet extremely useful.
:w !sudo tee %
I often forget to sudo before editing a file I don't have write permissions on. When I come to save that file and get a permission error, I just issue that vim command in order to save the file without the need to save it to a temp file and then copy it back again.
You obviously have to be on a system with sudo installed and have sudo rights.
Something I just discovered recently that I thought was very cool:
:earlier 15m
Reverts the document back to how it was 15 minutes ago. Can take various arguments for the amount of time you want to roll back, and is dependent on undolevels. Can be reversed with the opposite command :later
:! [command] executes an external command while you're in Vim.
But add a dot after the colon, :.! [command], and it'll dump the output of the command into your current window. That's : . !
For example:
:.! ls
I use this a lot for things like adding the current date into a document I'm typing:
:.! date
Not exactly obscure, but there are several "delete in" commands which are extremely useful, like..
diw to delete the current word
di( to delete within the current parens
di" to delete the text between the quotes
Others can be found on :help text-objects
de Delete everything till the end of the word by pressing . at your heart's desire.
ci(xyz[Esc] -- This is a weird one. Here, the 'i' does not mean insert mode. Instead it means inside the parenthesis. So this sequence cuts the text inside parenthesis you're standing in and replaces it with "xyz". It also works inside square and figure brackets -- just do ci[ or ci{ correspondingly. Naturally, you can do di (if you just want to delete all text without typing anything. You can also do a instead of i if you want to delete the parentheses as well and not just text inside them.
ci" - cuts the text in current quotes
ciw - cuts the current word. This works just like the previous one except that ( is replaced with w.
C - cut the rest of the line and switch to insert mode.
ZZ -- save and close current file (WAY faster than Ctrl-F4 to close the current tab!)
ddp - move current line one row down
xp -- move current character one position to the right
U - uppercase, so viwU upercases the word
~ - switches case, so viw~ will reverse casing of entire word
Ctrl+u / Ctrl+d scroll the page half-a-screen up or down. This seems to be more useful than the usual full-screen paging as it makes it easier to see how the two screens relate. For those who still want to scroll entire screen at a time there's Ctrl+f for Forward and Ctrl+b for Backward. Ctrl+Y and Ctrl+E scroll down or up one line at a time.
Crazy but very useful command is zz -- it scrolls the screen to make this line appear in the middle. This is excellent for putting the piece of code you're working on in the center of your attention. Sibling commands -- zt and zb -- make this line the top or the bottom one on the sreen which is not quite as useful.
% finds and jumps to the matching parenthesis.
de -- delete from cursor to the end of the word (you can also do dE to delete until the next space)
bde -- delete the current word, from left to right delimiter
df[space] -- delete up until and including the next space
dt. -- delete until next dot
dd -- delete this entire line
ye (or yE) -- yanks text from here to the end of the word
ce - cuts through the end of the word
bye -- copies current word (makes me wonder what "hi" does!)
yy -- copies the current line
cc -- cuts the current line, you can also do S instead. There's also lower cap s which cuts current character and switches to insert mode.
viwy or viwc. Yank or change current word. Hit w multiple times to keep selecting each subsequent word, use b to move backwards
vi{ - select all text in figure brackets. va{ - select all text including {}s
vi(p - highlight everything inside the ()s and replace with the pasted text
b and e move the cursor word-by-word, similarly to how Ctrl+Arrows normally do. The definition of word is a little different though, as several consecutive delmiters are treated as one word. If you start at the middle of a word, pressing b will always get you to the beginning of the current word, and each consecutive b will jump to the beginning of the next word. Similarly, and easy to remember, e gets the cursor to the end of the current, and each subsequent, word.
similar to b/e, capital B and E move the cursor word-by-word using only whitespaces as delimiters.
capital D (take a deep breath) Deletes the rest of the line to the right of the cursor, same as Shift+End/Del in normal editors (notice 2 keypresses -- Shift+D -- instead of 3)
One that I rarely find in most Vim tutorials, but it's INCREDIBLY useful (at least to me), is the
g; and g,
to move (forward, backward) through the changelist.
Let me show how I use it. Sometimes I need to copy and paste a piece of code or string, say a hex color code in a CSS file, so I search, jump (not caring where the match is), copy it and then jump back (g;) to where I was editing the code to finally paste it. No need to create marks. Simpler.
Just my 2cents.
:%!xxd
Make vim into a hex editor.
:%!xxd -r
Revert.
Warning: If you don't edit with binary (-b), you might damage the file. – Josh Lee in the comments.
gv
Reselects last visual selection.
Sometimes a setting in your .vimrc will get overridden by a plugin or autocommand. To debug this a useful trick is to use the :verbose command in conjunction with :set. For example, to figure out where cindent got set/unset:
:verbose set cindent?
This will output something like:
cindent
Last set from /usr/share/vim/vim71/indent/c.vim
This also works with maps and highlights. (Thanks joeytwiddle for pointing this out.) For example:
:verbose nmap U
n U <C-R>
Last set from ~/.vimrc
:verbose highlight Normal
Normal xxx guifg=#dddddd guibg=#111111 font=Inconsolata Medium 14
Last set from ~/src/vim-holodark/colors/holodark.vim
:%TOhtml
Creates an html rendering of the current file.
Not sure if this counts as dark-corner-ish at all, but I've only just learnt it...
:g/match/y A
will yank (copy) all lines containing "match" into the "a/#a register. (The capitalization as A makes vim append yankings instead of replacing the previous register contents.) I used it a lot recently when making Internet Explorer stylesheets.
Want to look at your :command history?
q:
Then browse, edit and finally to execute the command.
Ever make similar changes to two files and switch back and forth between them? (Say, source and header files?)
:set hidden
:map <TAB> :e#<CR>
Then tab back and forth between those files.
Vim will open a URL, for example
vim http://stackoverflow.com/
Nice when you need to pull up the source of a page for reference.
Macros can call other macros, and can also call itself.
eg:
qq0dwj#qq#q
...will delete the first word from every line until the end of the file.
This is quite a simple example but it demonstrates a very powerful feature of vim
Assuming you have Perl and/or Ruby support compiled in, :rubydo and :perldo will run a Ruby or Perl one-liner on every line in a range (defaults to entire buffer), with $_ bound to the text of the current line (minus the newline). Manipulating $_ will change the text of that line.
You can use this to do certain things that are easy to do in a scripting language but not so obvious using Vim builtins. For example to reverse the order of the words in a line:
:perldo $_ = join ' ', reverse split
To insert a random string of 8 characters (A-Z) at the end of every line:
:rubydo $_ += ' ' + (1..8).collect{('A'..'Z').to_a[rand 26]}.join
You are limited to acting on one line at a time and you can't add newlines.
^O and ^I
Go to older/newer position.
When you are moving through the file (by searching, moving commands etc.) vim rember these "jumps", so you can repeat these jumps backward (^O - O for old) and forward (^I - just next to I on keyboard). I find it very useful when writing code and performing a lot of searches.
gi
Go to position where Insert mode was stopped last.
I find myself often editing and then searching for something. To return to editing place press gi.
gf
put cursor on file name (e.g. include header file), press gf and the file is opened
gF
similar to gf but recognizes format "[file name]:[line number]". Pressing gF will open [file name] and set cursor to [line number].
^P and ^N
Auto complete text while editing (^P - previous match and ^N next match)
^X^L
While editing completes to the same line (useful for programming).
You write code and then you recall that you have the same code somewhere in file. Just press ^X^L and the full line completed
^X^F
Complete file names.
You write "/etc/pass" Hmm. You forgot the file name. Just press ^X^F and the filename is completed
^Z or :sh
Move temporary to the shell. If you need a quick bashing:
press ^Z (to put vi in background) to return to original shell and press fg to return to vim back
press :sh to go to sub shell and press ^D/exit to return to vi back
Typing == will correct the indentation of the current line based on the line above.
Actually, you can do one = sign followed by any movement command. ={movement}
For example, you can use the % movement which moves between matching braces. Position the cursor on the { in the following code:
if (thisA == that) {
//not indented
if (some == other) {
x = y;
}
}
And press =% to instantly get this:
if (thisA == that) {
//not indented
if (some == other) {
x = y;
}
}
Alternately, you could do =a{ within the code block, rather than positioning yourself right on the { character.
" insert range ip's
"
" ( O O )
" =======oOO=(_)==OOo======
:for i in range(1,255) | .put='10.0.0.'.i | endfor
This is a nice trick to reopen the current file with a different encoding:
:e ++enc=cp1250 %:p
Useful when you have to work with legacy encodings. The supported encodings are listed in a table under encoding-values (see help encoding-values). Similar thing also works for ++ff, so that you can reopen file with Windows/Unix line ends if you get it wrong for the first time (see help ff).
imap jj <esc>
Let's see some pretty little IDE editor do column transposition.
:%s/\(.*\)^I\(.*\)/\2^I\1/
Explanation
\( and \) is how to remember stuff in regex-land. And \1, \2 etc is how to retrieve the remembered stuff.
>>> \(.*\)^I\(.*\)
Remember everything followed by ^I (tab) followed by everything.
>>> \2^I\1
Replace the above stuff with "2nd stuff you remembered" followed by "1st stuff you remembered" - essentially doing a transpose.
Not exactly a dark secret, but I like to put the following mapping into my .vimrc file, so I can hit "-" (minus) anytime to open the file explorer to show files adjacent to the one I just edit. In the file explorer, I can hit another "-" to move up one directory, providing seamless browsing of a complex directory structures (like the ones used by the MVC frameworks nowadays):
map - :Explore<cr>
These may be also useful for somebody. I like to scroll the screen and advance the cursor at the same time:
map <c-j> j<c-e>
map <c-k> k<c-y>
Tab navigation - I love tabs and I need to move easily between them:
map <c-l> :tabnext<enter>
map <c-h> :tabprevious<enter>
Only on Mac OS X: Safari-like tab navigation:
map <S-D-Right> :tabnext<cr>
map <S-D-Left> :tabprevious<cr>
Often, I like changing current directories while editing - so I have to specify paths less.
cd %:h
I like to use 'sudo bash', and my sysadmin hates this. He locked down 'sudo' so it could only be used with a handful of commands (ls, chmod, chown, vi, etc), but I was able to use vim to get a root shell anyway:
bash$ sudo vi +'silent !bash' +q
Password: ******
root#
I often use many windows when I work on a project and sometimes I need to resize them. Here's what I use:
map + <C-W>+
map - <C-W>-
These mappings allow to increase and decrease the size of the current window. It's quite simple but it's fast.
:r! <command>
pastes the output of an external command into the buffer.
Do some math and get the result directly in the text:
:r! echo $((3 + 5 + 8))
Get the list of files to compile when writing a Makefile:
:r! ls *.c
Don't look up that fact you read on wikipedia, have it directly pasted into the document you are writing:
:r! lynx -dump http://en.wikipedia.org/wiki/Whatever
Not an obscure feature, but very useful and time saving.
If you want to save a session of your open buffers, tabs, markers and other settings, you can issue the following:
mksession session.vim
You can open your session using:
vim -S session.vim
Map F5 to quickly ROT13 your buffer:
map <F5> ggg?G``
You can use it as a boss key :).
I use vim for just about any text editing I do, so I often times use copy and paste. The problem is that vim by default will often times distort imported text via paste. The way to stop this is to use
:set paste
before pasting in your data. This will keep it from messing up.
Note that you will have to issue :set nopaste to recover auto-indentation. Alternative ways of pasting pre-formatted text are the clipboard registers (* and +), and :r!cat (you will have to end the pasted fragment with ^D).
It is also sometimes helpful to turn on a high contrast color scheme. This can be done with
:color blue
I've noticed that it does not work on all the versions of vim I use but it does on most.
I just found this one today via NSFAQ:
Comment blocks of code.
Enter Blockwise Visual mode by hitting CTRL-V.
Mark the block you wish to comment.
Hit I (capital I) and enter your comment string at the beginning of the line. (// for C++)
Hit ESC and all lines selected will have // prepended to the front of the line.

Resources