How are font variations written - python

I have been thinking for some time that variable fonts were simply combinations of multiple fonts, and that values were interpolated between them. However, I just read about this project, protottypo (which is unfortunately discontinued), and discovered about how they were storing their fonts as variables. See this screenshot from a promotional video, a few years ago:
And it seemed just so logical! Why not use a real language-like format, with variables and all. In the picture above, it (kinda) looks like python code.
And then I thought "It must have been thought through, let's look at how OpenType font variations are implemented."
And I looked on the web for the schema and the specification, but could not find it.
So the actual question(s):
How are variable fonts stored in otf files? Is it simply, as I thought before, multiple fonts and the other values are interpolated between them? Is there a variable language like the one above used to write the variable parts of the font (obviously)?
Where can I find the TTF specification for variable fonts? Is there any?
Is there a way to write a variable font with a regular text file (of course involving some vector graphics of some sort, like: const d = 'M23.6,0c-3.4,0-6.3,2.7-7.6,5.6C14.7,2.7,11.8,0,8.4,0C3.8,0,0,3.8,0,8.4c0,9.4,9.5,11.9,16,21.2 c6.1-9.3,16-12.1,16-21.2C32,3.8,28.2,0,23.6,0z' (this one makes a heart)
Thank you (that's what the heart is for :)

Related

How to programmatically distinguish between a TeX and a LaTeX file

I have a big collection of .tex files (TeX/LaTeX), and I'm writing a Python script that analyzes these files. I wish only to analyze LaTeX files, thus I want to remove all pure TeX files.
I have thought about making sure \begin{document} is contained in every file, but this rejects quite a big amount of my files, since several files are only chapters in a book, long lists, or sections in a dissertation that does not have the \begin{document} command.
Does anybody have an idea, how to filter all the pure TeX files away from my collection?
I think there's unlikely to be a completely foolproof way of doing this, given that you want to be sensitive to files which can be input with \input or \include. Given a particular file, though, you can probably classify it with considerable confidence by spotting the first of the following which you find.
TeX files usually end with \bye, and that's typically not defined in a LaTeX file.
The macro \begin is unlikely to be defined in a ‘normal’ TeX file (though \end is defined in the plain format).
That's probably about the best you can do, though it would surely be enough for the sort of statistical analysis you appear to be doing.
There's nothing to stop someone writing a TeX file from defining \begin to mean something, nor someone writing a LaTeX file to define \bye to mean something. The problem, from your point of view, is that there aren't any TeX constructs that are truly forbidden in a LaTeX file (and vice versa), even though things like \halign would be rare in LaTeX. Indeed, since LaTeX is ‘just’ a TeX format, there isn't any fundamental difference between the two, at all.
Just to drive the latter point home, there's such a thing as ConTeXt, which is a TeX format which isn't plain, but which isn't LaTeX either. It's rather rare, though.
Yeah sure, add all you file names to array, do this by listing the directory.
x = os.listdir("path")
This will add the directory contents to the variable x.
Then loop through it:
PureTex = []
for Char in x:
if Char.endswith('.tex'):
PureTex.append(Char)
else:
pass
Now the PureTex array will contain the pure files.

Get dynamic text with python and present it in LaTeX, format depending on content

I try to gather some graphics and text from different folders and present them in a comprehensive way. For this I use python to copy them into one folder and derive a dynamic LaTeX presentation, where I plot the copied graphics and print the text. The problem I'm facing now is, that I can derive the title for a slide dynamically from a text file, but if it's too long it will obviously wrap around. This dynamic title can be pretty long, so it might fill the whole slide. What I'd like to do now is to limit the space used by this text, without losing its information. The non-elegant solution I have to this problem is to count the characters and if it's over a certain threshold, use a smaller font. This solution is tedious and not optimal, I'd love to hear a better idea.

wxPython StyledTextCtrl Hexadecimal formatting

To whomever can lend a hand.
I'm building an app with BoaConstructor in Python which uses a wx.STC.StyledTextCtrl. In this styledtextctrl I am outputting hexadecimal data through Scapy's hexdump function. It adds the line numbers, hexadecimal dump and character transcode. Unfortunately, I cannot figure out how to format this text in the StyledTextCtrl so it displays like a regular hex editor would (see images here http://imgur.com/a/tqE02). Thanks!
Since you said that the output looks OK in other editors, I'm guessing the issue is that the font uses variable pixel widths for characters (e.g. if a wide character like "w" is 15 pixels wide then a thinner character like "i" may be only 10 pixels). In a fixed-width font (sometimes called monowidth font or typewritter text font) all characters have the exact same width.
You can see evidence of this in your screen shot; there is a slight extra indent on the second row right before the ".(." part. It seems that the space character is much thinner than numerals, so all those missing pixels make the third "column" of the bottom row appear too far left (while extra width in the second row pushes it slightly right)
You need to find a font such that IsFixedWidth() returns True then set up your STC to use that font. Normally, you'd set this using the SetFont() method but I happen to know that STCs prefer to use there own methods. I found this StyleSetFont() method that is specific to STCs, so that's probably a better bet.
As for choosing your font, here is a good tutorial about how fonts work in wxpython. The author actually is an active member here. Specially, search that article for his "wx.FontEnumerator widget" example. It should allow you to find fixed-widths fonts and view them to see if you like them. For a quick-and-dirty solution, this forum post talks about the wx.TELETYPE flag that guarantees fixed-width and these code samples should give you some idea how to use it.
Good luck!
----EDIT----
I'm not very familiar with STCs but I remember from a previous answer I gave to a question involving STCs that you might need to call StyleClearAll() after setting your font. See the EDIT section of that answer for more information about why this may be required.

Is there any document for the Python win32com operations on Powerpoint?

I have gat some samples about how to open a presentation and access the slides and shapes. But I want to do some more other operations(e.g. generate a thumbnail from a specified slide). What methods can I use? Is there any document illustrating all the functionalities?
Not to discourage you, but my experience using COM from Python is that you won't find many examples.
I would be shocked (but happy to see) if anybody posted a big tutorial or reference using PowerPoint in Python. Probably the best you'll find, which you've probably already found, is this article
However, if you follow along through that article and some of the other Python+COM code around, you start to see the patterns of how VB and C# code converts to Python code using the same interfaces.
Once you understand that, your best source of information is probably the PowerPoint API reference on MSDN.
From looking at the samples Jeremiah pointed to, it looks like you'd start there then do something like this, assuming you wanted to export slide #42:
Slide = Presentation.Slides(42)
Slide.Export FileName, "PNG", 1024, 768
Substitute the full path\filename.ext to the file you want to export to for Filename; string.
Use PNG, JPG, GIF, WMF, EMF, TIF (not always a good idea from PowerPoint), etc; string
The next two numbers are the width and height (in pixels) at which to export the image; VBLong (signed 32-bit (4-byte) numbers ranging in value from -2,147,483,648 to 2,147,483,647)
I've petted pythons but never coded in them; this is my best guess as to syntax. Shouldn't be too much of a stretch to fix any errors.

Programmatically change font color of text in PDF

I'm not familiar with the PDF specification at all. I was wondering if it's possible to directly manipulate a PDF file so that certain blocks of text that I've identified as important are highlighted in colors of my choice. Language of choice would be python.
It's possible, but not necessarily easy, because the PDF format is so rich. You can find a document describing it in detail here. The first elementary example it gives about how PDFs display text is:
BT
/F13 12 Tf
288 720 Td
(ABC) Tj
ET
BT and ET are commands to begin and end a text object; Tf is a command to use external font resource F13 (which happens to be Helvetica) at size 12; Td is a command to position the cursor at the given coordinates; Tj is a command to write the glyphs for the previous string. The flavor is somewhat "reverse-polish notation"-oid, and indeed quite close to the flavor of Postscript, one of Adobe's other great contributions to typesetting.
The problem is, there is nothing in the PDF specs that says that text that "looks" like it belongs together on the page as displayed must actually "be" together; since precise coordinates can always be given, if the PDF is generated by a sophisticated typography layout system, it might position text precisely, character by character, by coordinates. Reconstructing text in form of words and sentences is therefore not necessarily easy -- it's almost as hard as optical text recognition, except that you are given the characters precisely (well -- almost... some alleged "images" might actually display as characters...;-).
pyPdf is a very simple pure-Python library that's a good starting point for playing around with PDF files. Its "text extraction" function is quite elementary and does nothing but concatenate the arguments of a few text-drawing commands; you'll see that suffices on some docs, and is quite unusable on others, but at least it's a start. As distributed, pyPdf does just about nothing with colors, but with some hacking that could be remedied.
reportlab's powerful Python library is entirely focused on generating new PDFs, not on interpreting or modifying existing ones. At the other extreme, pure Python library pdfminer entirely focusing on parsing PDF files; it does do some clustering to try and reconstruct text in cases in which simpler libraries would be stumped.
I don't know of an existing library that performs the transformational tasks you desire, but it should be feasible to mix and match some of these existing ones to get most of it done... good luck!
Highlight is possible in pdf file using PDF annotations but doing it natively is not that easy job. If any of the mentioned library provide such facility is something that you may look for.

Categories

Resources