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

Documentation: How to use this? #2

Closed
probonopd opened this issue May 5, 2020 · 19 comments
Closed

Documentation: How to use this? #2

probonopd opened this issue May 5, 2020 · 19 comments

Comments

@probonopd
Copy link

probonopd commented May 5, 2020

Thanks for this useful repository. Can you please document a bit more clearly how to use it e.g., on an Ubuntu xenial system?

me@host:~$ git clone https://github.com/skef/FFSVGFig --depth 1

me@host:~$ cd FFSVGFig

me@host:~$ sudo apt-get install -y python3-setuptools python3-pip git

me@host:~$ pip3 install csscompressor svgwrite csscompressor fontforge

# python-fontforge cannot be installed this way, hence I assume I need
# to install the pyhton modules from the distribution python-... packages
# This dichotomy between distribution packages and pip packages
# makes Python really unpleaseant to use

sudo apt-get install -y git fontforge python-fontforge python-csscompressor python-svgwrite
./bin/FFSVGFig LeutkirchSans-Regular.otf e

# The dichotomy between Python 2 and 3 doesn't make it any better...
# Somethnig always seems to complain about something
# This is why I prefer Go lately 

me@host:~/FFSVGFig$ /usr/bin/python bin/FFSVGFig
Traceback (most recent call last):
  File "bin/FFSVGFig", line 11, in <module>
    class FFSVGFig:
  File "bin/FFSVGFig", line 97, in FFSVGFig
    fontforge.splineCurve: svgwrite.shapes.Circle(r=7,class_='ff_onp ff_curve'),
AttributeError: 'module' object has no attribute 'splineCurve'

me@host:~/FFSVGFig$ /usr/bin/python3 bin/FFSVGFig
Traceback (most recent call last):
  File "bin/FFSVGFig", line 6, in <module>
    import psMat
ModuleNotFoundError: No module named 'psMat'

# The only psMat I have is in
# /usr/lib/python2.7/dist-packages/psMat.x86_64-linux-gnu.so

# So I can only speculate that this is meant for Python 2...
# "#!/usr/bin/env python" should be forbidden, it should be mandatory
# to use "#!/usr/bin/env python2" or "#!/usr/bin/env python3"...

me@host:~/FFSVGFig$  /usr/bin/fontforge -lang=py -script
Copyright (c) 2000-2014 by George Williams. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Based on sources from 11:21 UTC 24-Sep-2017-ML-D.
 Based on source from git with hash: 
Python 2.7.17 (default, Nov  7 2019, 10:07:09) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

me@host:~/FFSVGFig$ /usr/bin/fontforge -lang=py -script bin/FFSVGFig 
Copyright (c) 2000-2014 by George Williams. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Based on sources from 11:21 UTC 24-Sep-2017-ML-D.
 Based on source from git with hash: 
Traceback (most recent call last):
  File "bin/FFSVGFig", line 11, in <module>
    class FFSVGFig:
  File "bin/FFSVGFig", line 97, in FFSVGFig
    fontforge.splineCurve: svgwrite.shapes.Circle(r=7,class_='ff_onp ff_curve'),
AttributeError: 'module' object has no attribute 'splineCurve'

Do I need to use https://launchpad.net/~silnrsi/+archive/ubuntu/smith-py3/? It seems not to be available for xenial, only for the very recent bionic.

I realize that those are not issues specific to your code but more long-standing annoyance factors with Python. Nevertheless I would appreciate if you could point me in the right direction. Thanks!

@skef
Copy link
Owner

skef commented May 5, 2020

I use Arch not Ubuntu so I can't give super-reliable answers here. But this is probably close:

When your OS package manager has prepped packages it's better to use them. It looks to me like sudo apt-get install -y python3-csscompressor python3-svgwrite would be the preferred way to install the prerequisites.

However, now you need FontForge, and this is Ubuntu's list of fontforge packages: https://packages.ubuntu.com/search?keywords=fontforge . So you're right, the only xenial versions of FontForge are 20120731, which is super old and almost certainly python 2 anyway. The focal or groovy packages would work fine -- I don't believe my script depends on anything in the very latest version, and if it does I could probably fix that, but it at least needs access to the point types via python, which were added in 2019.

I think the next thing to try is seeing if I can help you compile and install it. The current installation guidance is actually Ubuntu-focused, which is handy. So suppose you do the following to compile in a src subdirectory of your home directory:

sudo apt-get install libjpeg-dev libtiff5-dev libpng-dev libfreetype6-dev libgif-dev libgtk-3-dev libxml2-dev libpango1.0-dev libcairo2-dev libspiro-dev libuninameslist-dev python3-dev ninja-build cmake build-essential;
cd 
mkdir src
cd src
git clone https://github.com/fontforge/fontforge
cd fontforge
mkdir build
cd build
cmake -GNinja ..
ninja 

(So, compiling but stopping before the installation step.) What happens?

@skef
Copy link
Owner

skef commented May 5, 2020

Installation instructions are here, btw: https://github.com/fontforge/fontforge/blob/master/INSTALL.md

@probonopd
Copy link
Author

probonopd commented May 5, 2020

I wonder if I could use the FontForge AppImage to run your script? if so, how?
https://github.com/fontforge/fontforge/releases/download/20200314/FontForge-2020-03-14-67687b0-x86_64.AppImage

@skef
Copy link
Owner

skef commented May 5, 2020

That will be at least a bit tricky, but let me experiment a little.

@skef
Copy link
Owner

skef commented May 5, 2020

Well, you're somewhat of an expert on appimages, right?

If I do:

~/FontForge-2020-03-14-67687b0-x86_64.AppImage -lang=py -script /home/skef/bin/FFSVGFig psvg/doc.sfd J

(so, run the program via the app image directly passing the full path) I get a No module named 'csscompressor' error, which is pretty close to working. The problem is that there's no easy way to install the dependencies in the app image.

Now, you already have the dependencies installed in a site-packages directory on your system. (Mine are in /usr/lib/python3.8/site-packages.) So unless csscompressor or svgwrite have compiled portions, or depend on non-core python packages with compiled portions, just pointing the python inside the appimage to that directory would probably work. Under normal circumstances one can do something like PYTHONPATH=/usr/lib/python3.8/site-packages to accomplish that.

So the question is: Is it possible to set specific environment variables pointing to "external" resources with an AppImage?

@probonopd
Copy link
Author

Well, you're somewhat of an expert on appimages, right?

Well, there may be some truth in that ;-)

Looks like the Python inside the FontForge AppImage has no pip. Which means that we need to use a pip3 from the outside of the AppImage.

This may be the brute-force method, but I seem to be getting somewhere with it:

wget -c "https://github.com/fontforge/fontforge/releases/download/20200314/FontForge-2020-03-14-67687b0-x86_64.AppImage"

./FontForge-2020-03-14-67687b0-x86_64.AppImage --appimage-extract

# pip install stuff as above

cp -r ~/.local/lib/python3.6/site-packages/* squashfs-root/usr/lib/python3/dist-packages/

me@host:~/FFSVGFig$ ../squashfs-root/AppRun  -lang=py -script /home/me/FFSVGFig/bin/FFSVGFig 
Copyright (c) 2000-2020. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Version: 20200314
 Based on sources from 2020-03-14 03:38 UTC-ML-TtfDb-D-GDK3.
 Based on source from git with hash: 67687b099f82022d7384c76d0e1509fcc5e938b9
usage: FFSVGFig [-h] [-w WIDTH] [-m MARGIN] [-t PTMAG] [-b] [-n filename)]
                [-p] [-e (url]
                font glyph_name
FFSVGFig: error: the following arguments are required: font, glyph_name

I think I can work with this...

@skef
Copy link
Owner

skef commented May 5, 2020

Oh, yeah, I don't think you'd get that usage error at all unless it was basically working.

@probonopd
Copy link
Author

In fact it is working so well that I just noticed a bug in the typeface I am working on ;-)

me@host:~/FFSVGFig$ ../squashfs-root/AppRun  -lang=py -script /home/me/FFSVGFig/bin/FFSVGFig /home/me/Downloads/LeutkirchSans-Regular.otf e
Copyright (c) 2000-2020. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Version: 20200314
 Based on sources from 2020-03-14 03:38 UTC-ML-TtfDb-D-GDK3.
 Based on source from git with hash: 67687b099f82022d7384c76d0e1509fcc5e938b9
The following table(s) in the font have been ignored by FontForge
  Ignoring 'DSIG' digital signature table
In LeutkirchSans-Regular, the advance width (1000) for glyph uni0013 is greater than the maximum (940)
  Subsequent errors will not be reported.

@probonopd
Copy link
Author

Can you upload doc.sfd so that I have something to work from?

@skef
Copy link
Owner

skef commented May 5, 2020

Sure: doc.sfd.txt

Note that it's just a disorganized jumble of the source contours for my Expand Stroke documentation.

@probonopd
Copy link
Author

probonopd commented May 5, 2020

...works for me:

wget https://github.com/skef/FFSVGFig/files/4583509/doc.sfd.txt -O doc.sfd
../squashfs-root/AppRun  -lang=py -script /home/me/FFSVGFig/bin/FFSVGFig /home/me/FFSVGFig/doc.sfd J -n /home/me/FFSVGFig/J

Any chance to turn it into a png directly? mobi does not support svg...

And using convert J.svg J.png cripples it:

J

@skef
Copy link
Owner

skef commented May 5, 2020

If you have inkscape installed try inkscape --without-gui -b white -e J.png J.svg

@skef
Copy link
Owner

skef commented May 5, 2020

I haven't thought about this much because my whole point in writing it was to avoid the problems of screenshots, and converting to PNG at the end still has most of those problems. Of course, one could still organize one's document sources using SVG and generate images only for those platforms that need them -- when possible generating at multiple resolutions so the tool-at-the-end can pick the one that best matches the screen resolution.

@probonopd
Copy link
Author

probonopd commented May 5, 2020

Let's go for the 1.0 Inkscape that was released yesterday...

wget -c https://media.inkscape.org/dl/resources/file/Inkscape-4035a4f-x86_64.AppImage # 1.0
chmod +x ./Inkscape-*-x86_64.AppImage

me@host:~/FFSVGFig$ ./Inkscape-*-x86_64.AppImage --version
Run experimental bundle that bundles everything
Inkscape 1.0 (4035a4f, 2020-05-01)
    Pango version: 1.42.3

me@host:~/FFSVGFig$ ./Inkscape-*-x86_64.AppImage --batch-process  -b white  /home/me/FFSVGFig/J.svg --export-type="png"
Run experimental bundle that bundles everything
Background RRGGBBAA: ffffff00
Area 0:0:1059:824 exported to 1059 x 824 pixels (96 dpi)

J

@skef
Copy link
Owner

skef commented May 5, 2020

Well, unusually (as an Arch Linux user) I have an older version of Inkscape installed. What does --help report for v1.0?

@skef
Copy link
Owner

skef commented May 5, 2020

Yup, looks right to me ...

@probonopd
Copy link
Author

probonopd commented May 5, 2020

Edited above, seems to work. Is the output as expected? Cool! 👍

@skef
Copy link
Owner

skef commented May 5, 2020

I recommend playing with the width and ptmag arguments. Also background, given that "J" has a nib in the background not yet displayed.

@probonopd
Copy link
Author

We would now need to think about how to put the instructions ("recipe") for each illustration into the "source code" of the book. But I guess we need to discuss that back over in fontforge/designwithfontforge.com#204.

In any case, thanks for helping here, I think this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants