Set baseline with fontforge scriping - typography

I'm using FontForge to create a ttf font from SVG files. But the baseline is all wrong and I can't understand how to set the baseline from the FontForge command line scriping tool.
Any ideas?

The baseline is where y = '0' in the cartesian grid system of the 'em square'. If you look at the emsize, its likely 1,000, and typically there are 200 units below the baseline and 800 units above.
You can move the glyphs so that their base point is on the baseline, ie, their point has a y value of 0

If you are using FF's python module, you'd do something like this to translate a single glyph:
import fontforge
import psMat
base_matrix = psMat.translate(0, 200)
# …
glyph.importOutlines(some_svg_file_object)
glyph.transform(base_matrix)

Related

gnuplot - plot both from a data file and a gnuplot function in a single image

I have the following snippet:
set grid
set xlabel "Entropy"
set ylabel "Amortized work"
set xrange [-0.05:1.05]
set style line 1 linecolor rgb '#516db0' linetype 2 linewidth 5
f(x) = -1.3973 * x ** 2 + 1.3947 * x + 0.5796
F = '$-1.3973 x^2 + 1.3947 x + 0.5796$'
set terminal cairolatex pdf input size 700,700 color colortext
set key opaque box lc "black" linewidth 3
plot 'RatioVerboseData.dat', f(x)
set output
The data file RatioVerboseData.dat looks like this:
0.93070 0.290710
0.94060 0.281450
0.95050 0.254771
0.96040 0.241656
When I run the script with the gnuplot, it outputs:
plot 'RatioVerboseData.dat', f(x)
^
cairolatex terminal cannot write to standard output
"EntropyVerboseData.plt", line 15: util.c: No error
I use gnuplot 4.6.7 and MiKTeX-pdfTeX 4.10 (MiKTeX 22.7)
You need to specify an output file. Otherwise gnuplot tries to write back to the input terminal (stdout). That makes sense for some terminal types, e.g. the "dumb" terminal, and is not revelant for terminal type with their own display window, e.b. "qt", "wxt". But it cannot work for terminal types that need to create multiple output streams and then combine them to produce the final document, which covers most (all?) of the LaTeX terminal types.
Add a line:
set output "RatioVerboseData.tex"
Why are you using a 7.5 year old gnuplot version? Current version is 5.4.
I can reproduce your observation (on Win10 with gnuplot 4.6.7) that gnuplot gets stuck.
I couldn't find a hint in help cairolatex, but I guess if you don't add units to the size it will be interpreted as inches. But this does not yet explain why gnuplot freezes when you want to create a 700in x 700in large graph.
Anyway, if you add units, I guess at least in and cm are accepted and if you add the output file as #Ethan already suggested then it should work.
...
set terminal cairolatex pdf input size 7cm,7cm color colortext
set output "RatioVerboseData.tex"
...

How do I set representations properly in .vmdrc for VMD

I'm trying to setup default representations on load, and currently have added the following to the default .vmdrc file.
display depthcue off
color Display Background white
display projection orthographic
mol default color {index}
mol default style {CPK 1.0 12 0.3 12}
mol default selection {all}
menu main move 62 1236
menu graphics move 166 1477
I have also tried this line:
mol default style CPK
And variations on the selection command, such as {name A}, since I'm using hoomd and A type particles, but all to no avail, it ignores the representation style and color settings no matter what I do, but the other settings work just fine. Anyone able to help me figure out why? Thanks.
This is due to the molecule not being read into vmd upon startup (at the time of your .vmdrc file being read). I suspect you start vmd from command line with "vmd molecule.file" rather than opening up vmd first, then loading in the molecule from the File > New Molecule tab. If you do it the former way, then your "mol" instructions in the .vmdrc file are being applied to a non-existent molecule. The latter should work with the commands you've provided.
See here for how to get these defaults working for you with a command line startup.

Overlapping lines in Gnuplot when exporting

I'm trying to plot a discrete brownian path in gnuplot, which involves a lot of overlaping lines. This is how it's displayed in the qt terminal (I have generated the image with a screenshot):
Notice how the overlapping lines get colored in a stronger color, which is beautiful.
If I export it in png, with
set term pngcairo size 1366,768 enhanced
I obtain this:
All the lines have the same intensity. Setting transparent doesn't help, either.
The same happens with this MWE:
set term pngcairo size 1366,768 background '#000000' enhanced
set output "image.png"
unset key
set border 0
unset xtics
unset ytics
set samples 1e6
set xrange [0:0.1]
p sin(1/x) w l lw 0.3
set output
I'm running gnuplot -d each time so my local config does not get loaded. How should I export the plot to obtain the same effect as in the GUI?
Here are some results of my investigation :
I couldn't achieve beautiful results with pngcairo either. Opacity isn't added when 2 curves overlap each other.
Exporting to SVG and converting to PNG looked a bit better, either with inkscape -z -e image.png -w 1600 -h 1200 image.svg or convert -density 3000 -resize 1600x1200 image.svg image.png. This step could be included in gnuplot as a system command.
It is possible to export the qt render to png directly from the qt window. First menu icon on the left → Export to image
This process could in theory be automated directly from Gnuplot, without user interaction. A patch has been submitted : https://sourceforge.net/p/gnuplot/patches/665/. As far as I can tell, it hasn't been yet integrated into Gnuplot 5.0.x
Here is a related discussion on Gnuplot-dev.
If you feel adventurous, you could try to recompile Gnuplot with the applied patch. The submitter might be able to help you.
Very offtopic in this question, but as a workaround I have made a Julia script that replicates the image feeling that I am looking for. I will post it here in case anybody finds it useful.
using Images
function paint(Ny, Nx, iters=1e6; stepsize = 50)
randstep() = rand([-1;1])
x = Nx÷2
y = Ny÷2
M = zeros(Nx,Ny)
for i in 1:iters
rx = randstep()
ry = randstep()
for i in 1:stepsize
x = mod1(x+rx, Nx)
y = mod1(y+ry, Ny)
M[x,y] += 1
end
end
clamped = M/maximum(M)
img = [Colors.RGB(0,mm,0) for mm in clamped]
end
img = convert(Image,paint(1366,768,1e4,stepsize=10))
save("coolbrownianwalk.png", img)
This produces images like this:

256 colors in zsh-syntax-highlighting?

OK, so I'm using this little fancy cutting edge technology called zsh-syntax-highlighting and although I'm overall happy with the result I don't know how to set styles to anything but 8 basic colors (black, red, green, yellow, blue, magenta, cyan, white), e.g.
#works
ZSH_HIGHLIGHT_STYLES[path]='fg=red'
ZSH_HIGHLIGHT_STYLES[path]='fg=1'
#doesn't work
ZSH_HIGHLIGHT_STYLES[path]='fg=31m'
ZSH_HIGHLIGHT_STYLES[path]='fg=\e[31m'
ZSH_HIGHLIGHT_STYLES[path]='fg=%{\e[31m%}'
ZSH_HIGHLIGHT_STYLES[path]='31m'
ZSH_HIGHLIGHT_STYLES[path]='\e[31m'
ZSH_HIGHLIGHT_STYLES[path]='%{\e[31m%}'
ZSH_HIGHLIGHT_STYLES[path]='%{\e[1;38;5;118m%}'
So, how do I set more fancy colors for this zshzle plugin?
As you pointed out in the comment to chepner answer terminator is a fork of gnome-terminal and it still uses a lot of functions from gnome. In fact it seems that the whole terminator VTE widget comes from gnome and gnome-terminal by defaults "supports" only 8 basic colors. You can check that with echotc Co command. It will return 8 for both of them and for xterm too (although in xterm case this is true and only 8 colors), so basically all 3 terminal emulators you tried so far.
Now, you noted that teminator (and gnome-terminal) can in fact display more colors, but this is only because it more or less processes all those special color codes without paying attention to TERM settings what does not obey standards but well, this is gnome. Anyway to make long story short you need to set TERM environment variable to something like xterm-256color and check again with echotc Co - you should now see 256, and your ZSH_HIGHLIGHT_STYLES[path]='fg=217' should work as well.
To always start with 256 colors you can put into you .zshrc
[[ "$TERM" == "xterm" ]] && export TERM=xterm-256color
and if you have any gnome shortcuts with terminator then change them as follows
terminator -e "TERM=xterm-256color pine"
http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting suggests that the value for fg be a single integer from 0 to 255:
ZSH_HIGHLIGHT_STYLES[path]='fg=167' # Whatever color 167 is in the 256-color palette.
I Notice you are using [path], it could be that a custom path with it's own color setting is interfering with your highlight setting. Try testing with a different item such as [command]:
ZSH_HIGHLIGHT_STYLES[command]='fg=222'
I tried the above line and it works for me. I tried using the same value for path already knowing my custom prompt has its own colors and my prompts custom colors won out over the highlight.
I use a ZSH helper called Oh-My-ZSH so the following may be a bit different or not apply to you:
Make sure you are changing the color definition after the highlight plugin is loaded. On my setup it will actually generate an error but since I only tested on my syetem (OSX10,9, ZSH 5.0.7, Oh-My-ZSH, iTerm v2) your experience may be different.
Doesn't work:
ZSH_HIGHLIGHT_STYLES[command]='fg=222'
...
plugins=(git osx jim colorize zsh-syntax-highlighting)
Does work:
plugins=(git osx jim colorize zsh-syntax-highlighting)
...
ZSH_HIGHLIGHT_STYLES[command]='fg=222'

How to get coordinates of an svg?

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!

Resources