mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
sfntly builds on windows
This commit is contained in:
parent
062dbe2bbe
commit
5efd38eb4b
@ -257,6 +257,7 @@ if isunix:
|
|||||||
cc = os.environ.get('CC', 'gcc')
|
cc = os.environ.get('CC', 'gcc')
|
||||||
cxx = os.environ.get('CXX', 'g++')
|
cxx = os.environ.get('CXX', 'g++')
|
||||||
cflags = os.environ.get('OVERRIDE_CFLAGS',
|
cflags = os.environ.get('OVERRIDE_CFLAGS',
|
||||||
|
# '-Wall -DNDEBUG -ggdb -fno-strict-aliasing -pipe')
|
||||||
'-O3 -Wall -DNDEBUG -fno-strict-aliasing -pipe')
|
'-O3 -Wall -DNDEBUG -fno-strict-aliasing -pipe')
|
||||||
cflags = shlex.split(cflags) + ['-fPIC']
|
cflags = shlex.split(cflags) + ['-fPIC']
|
||||||
ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall')
|
ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall')
|
||||||
|
@ -46,6 +46,7 @@ class SfntlyBuilderMixin(object):
|
|||||||
self.sfntly_cflags += [
|
self.sfntly_cflags += [
|
||||||
'-D_UNICODE', '-DUNICODE',
|
'-D_UNICODE', '-DUNICODE',
|
||||||
] + shlex.split('/W4 /WX /Gm- /Gy /GR-')
|
] + shlex.split('/W4 /WX /Gm- /Gy /GR-')
|
||||||
|
self.cflags += ['-DWIN32']
|
||||||
else:
|
else:
|
||||||
# Possibly add -fno-inline (slower, but more robust)
|
# Possibly add -fno-inline (slower, but more robust)
|
||||||
self.sfntly_cflags += [
|
self.sfntly_cflags += [
|
||||||
@ -63,7 +64,10 @@ class SfntlyBuilderMixin(object):
|
|||||||
cflags.remove('/Ox')
|
cflags.remove('/Ox')
|
||||||
if '-O3' in cflags:
|
if '-O3' in cflags:
|
||||||
cflags.remove('-O3')
|
cflags.remove('-O3')
|
||||||
cflags.insert(0, '/O2' if iswindows else '-O2')
|
if '/W3' in cflags:
|
||||||
|
cflags.remove('/W3')
|
||||||
|
if '-ggdb' not in cflags:
|
||||||
|
cflags.insert(0, '/O2' if iswindows else '-O2')
|
||||||
|
|
||||||
groups = []
|
groups = []
|
||||||
all_headers = set()
|
all_headers = set()
|
||||||
@ -71,7 +75,7 @@ class SfntlyBuilderMixin(object):
|
|||||||
src_dir = self.absolutize([os.path.join('sfntly', 'src')])[0]
|
src_dir = self.absolutize([os.path.join('sfntly', 'src')])[0]
|
||||||
inc_dirs = [src_dir]
|
inc_dirs = [src_dir]
|
||||||
self.inc_dirs += inc_dirs
|
self.inc_dirs += inc_dirs
|
||||||
inc_flags = builder.inc_dirs_to_cflags(inc_dirs)
|
inc_flags = builder.inc_dirs_to_cflags(self.inc_dirs)
|
||||||
for loc in ('', 'port', 'data', 'math', 'table', 'table/bitmap',
|
for loc in ('', 'port', 'data', 'math', 'table', 'table/bitmap',
|
||||||
'table/core', 'table/truetype'):
|
'table/core', 'table/truetype'):
|
||||||
path = os.path.join(src_dir, 'sfntly', *loc.split('/'))
|
path = os.path.join(src_dir, 'sfntly', *loc.split('/'))
|
||||||
|
@ -10,6 +10,12 @@ __docformat__ = 'restructuredtext en'
|
|||||||
from future_builtins import map
|
from future_builtins import map
|
||||||
|
|
||||||
class NoGlyphs(ValueError):
|
class NoGlyphs(ValueError):
|
||||||
|
'Raised when the font has no glyphs for the specified characters'
|
||||||
|
pass
|
||||||
|
|
||||||
|
class UnsupportedFont(ValueError):
|
||||||
|
'Raised when the font is not supported for subsetting '
|
||||||
|
'(usually an OTF font with PostScript outlines).'
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def load_sfntly():
|
def load_sfntly():
|
||||||
@ -19,7 +25,7 @@ def load_sfntly():
|
|||||||
raise RuntimeError('Failed to load sfntly: %s'%err)
|
raise RuntimeError('Failed to load sfntly: %s'%err)
|
||||||
return sfntly
|
return sfntly
|
||||||
|
|
||||||
def subset(font_data, individual_chars, ranges):
|
def subset(font_data, individual_chars, ranges=()):
|
||||||
if font_data[:4] not in {b'\x00\x01\x00\x00', b'OTTO', b'true', b'typ1'}:
|
if font_data[:4] not in {b'\x00\x01\x00\x00', b'OTTO', b'true', b'typ1'}:
|
||||||
raise ValueError('Not a supported font file. sfnt_version not recognized: %r'%
|
raise ValueError('Not a supported font file. sfnt_version not recognized: %r'%
|
||||||
font_data[:4])
|
font_data[:4])
|
||||||
@ -37,6 +43,8 @@ def subset(font_data, individual_chars, ranges):
|
|||||||
except sfntly.NoGlyphs:
|
except sfntly.NoGlyphs:
|
||||||
raise NoGlyphs('No glyphs were found in this font for the'
|
raise NoGlyphs('No glyphs were found in this font for the'
|
||||||
' specified characters. Subsetting is pointless')
|
' specified characters. Subsetting is pointless')
|
||||||
|
except sfntly.UnsupportedFont as e:
|
||||||
|
raise UnsupportedFont(type('')(e))
|
||||||
|
|
||||||
def option_parser():
|
def option_parser():
|
||||||
import textwrap
|
import textwrap
|
||||||
@ -99,6 +107,31 @@ def test():
|
|||||||
if len(sf) > 0.3 * len(raw):
|
if len(sf) > 0.3 * len(raw):
|
||||||
raise Exception('Subsetting failed')
|
raise Exception('Subsetting failed')
|
||||||
|
|
||||||
|
def all():
|
||||||
|
from calibre.utils.fonts.scanner import font_scanner
|
||||||
|
failed = []
|
||||||
|
for family in font_scanner.find_font_families():
|
||||||
|
for font in font_scanner.fonts_for_family(family):
|
||||||
|
raw = font_scanner.get_font_data(font)
|
||||||
|
print ('Subsetting', font['full_name'])
|
||||||
|
try:
|
||||||
|
sf, old_stats, new_stats = subset(raw, set(('a', 'b', 'c')), ())
|
||||||
|
except (NoGlyphs, UnsupportedFont) as e:
|
||||||
|
continue
|
||||||
|
except Exception as e:
|
||||||
|
print ('Failed!')
|
||||||
|
failed.append((font['full_name'], font['path'], unicode(e)))
|
||||||
|
else:
|
||||||
|
print ('Reduced to:', '%.1f'%(
|
||||||
|
sum(new_stats.itervalues())/sum(old_stats.itervalues())
|
||||||
|
* 100), '%')
|
||||||
|
if failed:
|
||||||
|
print ('\n\nFailures:')
|
||||||
|
for name, path, err in failed:
|
||||||
|
print (name, path, err)
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
import sys, time
|
import sys, time
|
||||||
from calibre import prints
|
from calibre import prints
|
||||||
|
Loading…
x
Reference in New Issue
Block a user