Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3428612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:58:48+00:00 2026-05-18T06:58:48+00:00

I found this script attached to a thread in the fontforge-users mailing list .

  • 0

I found this script attached to a thread in the fontforge-users mailing list. It does exactly what I want. However, it seems only to work on 32bit systems, and I would really like to use it on my 64bit system.

I’ve done a little reading but I can’t work out how I should modify this script (presumably the stuct?) to make it work under a 64bit architecture. Can anyone help?

Cheers!

#!/usr/bin/python
# vim:ts=8:sw=4:expandtab:encoding=utf-8
# Export named font from PDF file using fontforge and ctypes

import sys
from ctypes import *

STRING = c_char_p
real = c_longdouble

# We need the `map` attribute of SplineFont, so declear an incomplete struct.
# see: http://sourceforge.net/projects/wqy/files/misc/
# file: fontforge-bindctypes-0.1.tar.bz2
class splinefont(Structure):
    pass
SplineFont = splinefont
splinefont._fields_ = [
    ('fontname', STRING),
    ('fullname', STRING),
    ('familyname', STRING),
    ('weight', STRING),
    ('copyright', STRING),
    ('filename', STRING),
    ('defbasefilename', STRING),
    ('version', STRING),
    ('italicangle', real),
    ('upos', real),
    ('uwidth', real),
    ('ascent', c_int),
    ('descent', c_int),
    ('uniqueid', c_int),
    ('glyphcnt', c_int),
    ('glyphmax', c_int),
    ('glyphs', POINTER(c_void_p)),
    ('changed', c_uint, 1),
    ('changed_since_autosave', c_uint, 1),
    ('changed_since_xuidchanged', c_uint, 1),
    ('display_antialias', c_uint, 1),
    ('display_bbsized', c_uint, 1),
    ('dotlesswarn', c_uint, 1),
    ('onlybitmaps', c_uint, 1),
    ('serifcheck', c_uint, 1),
    ('issans', c_uint, 1),
    ('isserif', c_uint, 1),
    ('hasvmetrics', c_uint, 1),
    ('loading_cid_map', c_uint, 1),
    ('dupnamewarn', c_uint, 1),
    ('encodingchanged', c_uint, 1),
    ('multilayer', c_uint, 1),
    ('strokedfont', c_uint, 1),
    ('new', c_uint, 1),
    ('compacted', c_uint, 1),
    ('backedup', c_uint, 2),
    ('use_typo_metrics', c_uint, 1),
    ('weight_width_slope_only', c_uint, 1),
    ('save_to_dir', c_uint, 1),
    ('head_optimized_for_cleartype', c_uint, 1),
    ('ticked', c_uint, 1),
    ('internal_temp', c_uint, 1),
    ('complained_about_spiros', c_uint, 1),
    ('use_xuid', c_uint, 1),
    ('use_uniqueid', c_uint, 1),
    ('fv', c_void_p),
    ('metrics', c_void_p),
    ('uni_interp', c_int),
    ('for_new_glyphs', c_void_p),
    ('map', c_void_p),
    # ...
]

def main():
    if len(sys.argv) != 3:
        print "Usage: %s doc.pdf fontname" % sys.argv[0]
        sys.exit(2)
    pdfname = sys.argv[1]
    fontname = sys.argv[2]
    fontfile = fontname + '.ttf'

    # ctypes functions
    libc = CDLL("libc.so.6")
    libc.fopen.restype = c_void_p
    libc.fopen.argtype = [c_char_p, c_char_p]

    lib_ff = CDLL('libfontforge.so.1')

    # SplineFont *_SFReadPdfFont(FILE *pdf,char *filename,
    #     char *select_this_font, enum openflags openflags)
    lib_ff._SFReadPdfFont.argtypes = [c_void_p, c_char_p, c_char_p, c_int]
    lib_ff._SFReadPdfFont.restype = POINTER(SplineFont)

    # int GenerateScript(SplineFont *sf, char *filename, char *bitmaptype,
    #     int fmflags, int res, char *subfontdefinition, struct sflist *sfs,
    #     EncMap *map, NameList *rename_to,int layer)
    lib_ff.GenerateScript.argytpes = [POINTER(SplineFont), c_char_p, c_char_p,
            c_int, c_int, c_char_p, c_void_p, c_void_p, c_void_p, c_int]
    lib_ff.GenerateScript.restype = c_int

    # need to somehow initialize libfontforge or it will segfault somewhere.
    lib_ff.doinitFontForgeMain()
    fobj = libc.fopen(pdfname, "rb")
    if not fobj:
        print "%s not found" % pdfname
        sys.exit(1)

    font = lib_ff._SFReadPdfFont(fobj, pdfname, fontname, 0)
    ret = 0
    if bool(font):
        ret = lib_ff.GenerateScript(font, fontfile, None, -1, -1, None, None,
                font.contents.map, None, 1)
    if ret:
        print 'Font export to "%s".' % fontfile
    else:
        print "** Error ** Failed to export font!!"

if __name__ == '__main__':
    main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:58:49+00:00Added an answer on May 18, 2026 at 6:58 am

    The question is whether FONTFORGE_CONFIG_USE_LONGDOUBLE is defined or not in /usr/include/fontforge/config.h. If it is defined, then the code’s definition is correct. On my amd64 linux installation, neither FONTFORGE_CONFIG_USE_LONGDOUBLE nor FONTFORGE_CONFIG_USE_DOUBLE are defined, so I needed to change

    real = c_float
    

    With that change, it works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this script (http://coolersport.info/) and downloaded it. I want change some things in
I found this open-source library that I want to use in my Java application.
I found this script: <script language=Javascript TYPE=text/javascript> var container = document.getElementById('dl'); var seconds =
I found this script which parses a CSV file to XML. Problem is it
I have found this example on StackOverflow: var people = new List<Person> { new
Found this script: function stopRKey(evt) { var evt = (evt) ? evt : ((event)
I found this script for a Find In Page / Highlight / ScrollTo feature
Reading this question I found this as (note the quotation marks) code to solve
I found this link http://artis.imag.fr/~Xavier.Decoret/resources/glsl-mode/ , but there isn't a lot of description around
I found this in an article on Multithreaded Apartments, but can’t find a definition

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.