def run_c_preprocessor(header_contents): """ Run a C preprocessor on the given header file contents. """ from pcpp.preprocessor import Preprocessor cpp = Preprocessor() if platform.system() == "Windows": cpp.define("_MSC_VER") # NOTE: the cffi 'cdef' parser doesn't appear to understand # the windows '__int32'. So give it a definition. # - Not entirely sure what the ramifications of this are, # but it now compiles and runs on Windows... # - A better solution here would probably be to define # NK_INT32 ourselves as int32_t. cpp.define("__int32 int") if platform.architecture()[0] == "64bit": cpp.define("_WIN64") else: cpp.define("WIN32") cpp.define("_WIN32") else: cpp.define("__GNUC__") if platform.architecture()[0] == "64bit": cpp.define("__x86_64__") cpp.parse(header_contents) output = StringIO.StringIO() cpp.write(output) return output.getvalue()
def run_c_preprocessor(header_contents): """ Run a C preprocessor on the given header file contents. """ from pcpp.preprocessor import Preprocessor cpp = Preprocessor() cpp.parse(header_contents) output = StringIO.StringIO() cpp.write(output) return output.getvalue()
def __init__(self, filename, features, version): self._font = fontforge.open(filename) self._version = version self._features = StringIO() if features: preprocessor = Preprocessor() for d in ("italic", "sans", "display", "math"): if d in filename.lower(): preprocessor.define(d.upper()) with open(features) as f: preprocessor.parse(f) preprocessor.write(self._features)
def __init__(self, filename, features): self._font = font = ufoLib2.Font(validate=False) parser = SFDParser(filename, font, ignore_uvs=False, ufo_anchors=False, ufo_kerning=False, minimal=True) parser.parse() if features: preprocessor = Preprocessor() for d in ("italic", "sans", "display", "math"): if d in filename.lower(): preprocessor.define(d.upper()) with open(features) as f: preprocessor.parse(f) feafile = StringIO() preprocessor.write(feafile) feafile.write(font.features.text) font.features.text = feafile.getvalue()
def generateFeatures(font, args): """Generates feature text by merging feature file with mark positioning lookups (already in the font) and making sure they come after kerning lookups (from the feature file), which is required by Uniscribe to get correct mark positioning for kerned glyphs.""" oldfea = "" for lookup in font.gpos_lookups: oldfea += generateFeatureString(font, lookup) for lookup in font.gpos_lookups + font.gsub_lookups: font.removeLookup(lookup) # open feature file and insert the generated GPOS features in place of the # placeholder text with open(args.features) as f: o = StringIO() preprocessor = Preprocessor() if args.quran: preprocessor.define("QURAN") elif args.slant: preprocessor.define("ITALIC") preprocessor.parse(f) preprocessor.write(o) fea_text = tounicode(o.getvalue(), "utf-8") fea_text = fea_text.replace("{%anchors%}", oldfea) bases = [g.glyphname for g in font.glyphs() if g.glyphclass != "mark"] marks = [g.glyphname for g in font.glyphs() if g.glyphclass == "mark"] carets = {g.glyphname: g.lcarets for g in font.glyphs() if any(g.lcarets)} gdef = [] gdef.append("@GDEFBase = [%s];" % " ".join(bases)) gdef.append("@GDEFMark = [%s];" % " ".join(marks)) gdef.append("table GDEF {") gdef.append(" GlyphClassDef @GDEFBase, , @GDEFMark, ;") for k, v in carets.items(): gdef.append(" LigatureCaretByPos %s %s;" % (k, " ".join(map(str, v)))) gdef.append("} GDEF;") fea_text += "\n".join(gdef) return fea_text
def generateFeatures(font, args): """Generates feature text by merging feature file with mark positioning lookups (already in the font) and making sure they come after kerning lookups (from the feature file), which is required by Uniscribe to get correct mark positioning for kerned glyphs.""" # open feature file and insert the generated GPOS features in place of the # placeholder text preprocessor = Preprocessor() if args.quran: preprocessor.define("QURAN") elif args.slant: preprocessor.define("ITALIC") with open(args.features) as f: preprocessor.parse(f) o = StringIO() preprocessor.write(o) fea = o.getvalue() font.features.text = fea.replace("#{%anchors%}", font.features.text.asFea())
def initialise_ent(): '''Initialise the ENT library ''' with open('include/ent.h') as f: header = f.read() # Prune the header header = re.sub(r'(?m)^#include.*\n?', '', header) cpp = Preprocessor() cpp.parse(header) output = io.StringIO() cpp.write(output) header = output.getvalue() ffi = FFI() ffi.cdef(header) # Load the library lib = ffi.dlopen('lib/libent.so') return ffi, lib
def run_c_preprocessor(header_contents): cpp = Preprocessor() cpp.parse(header_contents) output = StringIO.StringIO() cpp.write(output) return output.getvalue()