Is importing a truetype font for perl module possible? - linux

After a great deal of toiling I have managed to hack up a perl script that use PDF::Create to create pdf labels for a label printer. The script now works perfectly to suit my needs but the choices of fonts are limited. I have installed a true type font with gnome-font-viewer (I am using Debian Stretch).
According to the docs for PDF::Create: A postscript named "BaseFont" (Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique, Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique, Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic or Symbol) can be used to create the pdf.
How can I add my newly installed true type font to this list of Postscript basefonts so that I can use it to create a PDF? Or is this not possible?

There is an old and unresolved ticket requesting that feature on that module, so I suspect for PDF::Create, the answer is no, you can't use TTF fonts (I'd be happy to be proven wrong on that point).
Other Perl modules can use True Type and Open Type fonts. PDF::API2 does support them. I'll confess, I found that module's API to be somewhat intimidating.
Another module I have used extensively is PDF::Reuse which can be used to create PDFs from scratch, or by combining existing pages as templates and overlaying text and other elements. PDF::Reuse also supports the use of True Type fonts.

Related

Tkinter cross-platform compatability

I have written a set of customized tkinter widgets, defined as classes, and loaded into the main app as modules. I am working in Windows 10, but have specific concerns in three areas in regard to compatibility with Linux and Mac. These are shown below.
Fonts
I am sticking with tkinter default fonts, and defining the desired font within each individual custom widget. I have found, surprisingly, that I can successfully specify fonts as follows, naming 'TkDefaultFont' just as I might name 'Arial' for example.
font=('TkDefaultFont',11)
font=('TkDefaultFont',10,'bold')
font=('TkDefaultFont',10,'italic')
Would this approach work across Linux and Mac as well as windows?
Importing modules
All of the resources for my main app are stored in a Folder named 'AppAssets' (which is in the same folder as the main app). The custom widgets are stored inside that folder, in another folder named 'TkMods'. In Windows, I am successfully importing these modules as follows, specifying a relative path:
from AppAssets.TkMods import ModButton
Again, would this work across Linux and Mac? If not, is there a line or lines of code that would work instead across all three platforms?
Importing image files
Many of the modules use custom image files (such as a rounded button image, for example). I am importing these as follows, again specifying a relative path.
btnimg = tk.PhotoImage(file="AppAssets/TkMods/Button.png")
Again, would this work cross-platform? If not, is there a single solution that would work across Windows, Mac and Linux?
Any advice appreciated.
I have found, surprisingly, that I can successfully specify fonts as follows, naming 'TkDefaultFont' just as I might name 'Arial' for example...
Would this approach work across Linux and Mac as well as windows?
It works, but probably not the way you think. You could use 'NotARealFont' instead of 'TkDefaultFont' and get the same results. The first parameter when defining a font as a tuple is a font family, and TkDefaultFont is not the name of a valid font family. It's the name of an internal font object, which is not the same thing. When you don't give a valid font family, tkinter will fall back to using the font defined by TkDefaultFont.
I am successfully importing these modules as follows... Again, would this work across Linux and Mac?
Yes, importing python modules works the same on platforms. This isn't anything unique to tkinter.
Many of the modules use custom image files ... I am importing these as follows, again specifying a relative path... Again, would this work cross-platform?
It should work the same on all platforms. Note that "work the same" also means it will fail in the same way on all platforms. The path is relative to the current working directory which may or may not be the same as the directory with the script.

wxPython pdfviewer unknown font preventing pdf loading

While checking out wxPython's wx.lib.pdfViewer, I ran the code in the documentation. It worked well, but most of the pdf did not load, and messages like these
Unknown font ghlcbg+arial
Unknown font ghlcdi+arial,bold
were printed. I surmise that it is because the fonts used in the pdf are not implemented by PyPDF2. How can I solve this problem? I can preprocess the pdf to replace the fonts if necessary, but this I do not know how to do either.
Is there a library which allows for replacement of fonts? If there is not, is there a replacement for PyPDF2 which permits this replacement (PyMuPDF does not work for me due to another error)? If such a replacement is not possible, is there an extension which permits the interpretation of such fonts?
wxPython cannot load a PDF that PyPDF2 does not support. I think there is talk about moving to pdfrw, but that has not occurred as of yet and I don't know if it actually has handling for unknown fonts or not. The main benefit to moving is PyPDF2 is no longer being maintained.
PyQt can do it since it integrates with poppler. See https://github.com/frescobaldi/python-poppler-qt4 or http://shallowsky.com/blog/programming/qt5-poppler-pdf.html

beamer includegraphics with screenshots

I'm using the LaTeX-Beamer class for making presentations. Every once in a while I need to include screenshots. Those graphics are pixel-based, of course. I use includegraphics like this:
\begin{figure}
\includegraphics[width= \paperwidth]{img/analyzer.png}
\end{figure}
or usually something like this:
\begin{figure}
\includegraphics[width= 0.8\linewidth]{img/analyzer.png}
\end{figure}
This leads to pretty bad readibility of the contained text, so I'm asking for your best practices: How would you include screenshots containing text considering, that I will do the output PDF with pdflatex?
EDIT: I suppose I'm looking for something like an 1:1 presetation of the image within beamer. However, [scale = 1.0] doesn't achieve what I'm looking for.
Your best bet is to scale the image outside of Latex for inclusion, and include it in 1:1 ratio. The scaling done by graphics packages in Latex isn't going to be anywhere near as good as possible from other tools. Latex (Tex) has limited floating-point arithmetic capabilities, whereas an external tool can use sophisticated algorithms to get the scaling better.
Another option is to use only a part of the screenshot, the one you want to concentrate on.
Edit: If you can change the font size before taking the screenshot, that's another option—just increase the font size for the screenshots.
Of course, you can combine the two methods.
I have done exactly what you do and e.g defined
\newcommand{\screenshot}[1]{\centerline{%
\includegraphics[height=7.8cm,transparent]{#1}}} % 7.8in
which worked with whatever style I was using at the time. The files included with this macro were all PNGs created with one the usual Linux screen capture tools.
Edit: You may have to play with the size (height and width) of your input files. It came out rather nice for me (and this was from a presentation in 2006).
How about scaling it as follows:
\includegraphics[scale=0.5]{images/myimage.jpg}
This works for me.
Have you tried to convert the image to .eps or .pdf file and use this file in LaTeX?
Maybe try also latex, dvips and ps2pdf.
Problem might be in used viewer, in Linux I use Document viewer or ePDFViewer and output is much worse than in Adobe Reader or Acrobat, which I use in Windows...

How do I have Emacs load a font from a file?

In the interest of making my emacs setup more portable, I'd like to be able to set the current font by specifying a file rather than a font name, i.e. "Load ~/config/myfont.ttf and use size 12". Is there a way to do that in my .emacs? All the instructions I've found assume the font is already installed on the system. I'm using the XFT support on Linux, so a linux specific hack would be OK but I'd prefer something that would work on all targets.
Update: To be clear, I'm using a font that isn't standard on Windows / OS X / Linux. I'm not just looking to set a different font based on platform, but to specify a specific font file that I have (TTFs work on Windows and Linux, if not on Mac I'll get another version of the file but I still want to specify the font via file rather than name).
Unfortunately, you can't.
Emacs on different platforms uses different windowing toolkits, all of which take care of font handling for it. I don't believe you can specify a font filename in Emacs on any platform - it just doesn't work that way.
As for how to find the font:
On Linux, you could use XFT's support for a user-specific font config file which is usually ~/.fonts.conf (but check /etc/fonts/font.conf to be sure) to add whatever directory you place your fonts into.
On a Mac, you can add the font into ~/Library/Fonts. TTFs work fine on Macs, BTW.
On Windows, I think you'd just have to add it to the system fonts directory.
From there, you then go and tell Emacs (through customize or not) to use your font. You'll find the naming schemes to be different on each platform (not sure what Windows looks like), but customize should help take care of this for you - just keep a separate customize file per machine if need be.
...so basically your portable Emacs setup has to encompass more than just an Emacs config file (which, given that you're carrying a font file around, it already does).

Tools for displaying text, powerpoint style, in linux

I have a problem where I need a way to display a repeating series of "images" on a computer monitor. Specifically, given a series of text files, I'd like a way to display the contents of said files on a screen in a way much like a powerpoint would.
My current thoughts are to find some tool that will take in a text file of some format, and then output an image which contains the text from the file. Then I'd put it in a directory and have some Slideshow program continuously go between the images in that directory. It's a very hacky solution, obviously.
So, does anyone know of tools that would do such a thing? Or is there a better way to do this? I've looked into the library libgd2, but it doesn't seem to support text-wrapping for images, which is something I'd need.
Thanks!
MagicPoint is a tool for displaying presentations. Presentations are written in a simple plain text file format, much like HTML.
You could easily generate the MagicPoint file automatically and then run it and display the presentation. You can also generate HTML, PS oder PDF from the presentation and display that.
Are you looking for powerpoint equivalent for linux? Openoffice??
have you tried some magic scripting with TeX?
a chain like
tex file | dvi2ps | ps2jpg > output
and define some TeX-Macros?
Showoff's pretty cool. It uses Markdown-formatted slides to create a simple little Sinatra app that you run (with showoff serve), and then view in a browser.
Docutils. See http://docutils.sourceforge.net/docs/user/slide-shows.html
The text syntax is reStructuredText
another idea:
text2gif
To complement the suggestions given by others, if you were going to write a program to do this, it would probably be more efficient to just render the text to the screen directly, rather than converting it to images first. It could probably be done using a canvas or text box component in a full-screen window on whatever window manager you are using (e.g. KDE or Gnome).
I give presentations with Opera's #media projection CSS support. On http://talks.webconverger.com/ you can find a template and an example which you can load in Opera's full screen mode and start sliding through.
So besides writing in a familiar language HTML, it's dead easy to share the slides and even get your audience to look at the slides as you're going through them.
If you are looking for something more flashy, there are tools on the Web to generate animations and what not, and again you would simply use a full screen browser to play it back to your audience.

Resources