def on_directive_handle(self, directive, toks, ifpassthru,
                                precedingtoks):

            if directive.value == 'define' or directive.value == 'undef':
                if toks[0].type == 'CPP_ID' and toks[0].value in [
                        'SPGM', 'FSPGM', 'PROGMEM_STRING_DEF',
                        'AUTO_INIT_SPGM', 'AUTO_STRING_DEF'
                ]:
                    raise OutputDirective(Action.IgnoreAndPassThrough)
            # elif directive.value=='include':
            #     file = self.tokens_to_string(toks)
            #     if os.path.isabs(file):
            #         files = [file]
            #     else:
            #         files = []
            #         for path in self.path:
            #             new_path = os.path.abspath(os.path.join(path, file))
            #             if os.path.isfile(new_path):
            #                 files.append(new_path)
            #     for file in files:
            #         for ignore in self._skip_includes:
            #             if fnmatch.fnmatch(file, ignore):
            #                 if self.verbose:
            #                     print('include include %s' % file)
            #                 raise OutputDirective(Action.IgnoreAndPassThrough)
            #         break
            #     if self.verbose:
            #         if len(files)==1:
            #             files = files[0]
            #         self._include_counter += 1
            #         print('include %u: %s' % (self._include_counter, files))

            return Preprocessor.on_directive_handle(self, directive, toks,
                                                    ifpassthru, precedingtoks)
예제 #2
0
파일: build.py 프로젝트: qirh/amiri
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
예제 #3
0
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())
예제 #4
0
    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, display_info=True):
     Preprocessor.__init__(self)
     self.define('FLASH_STRINGS_AUTO_INIT 1')
     self.define(
         'AUTO_STRING_DEF(name,  value, ...) AUTO_INIT_SPGM(name,value,##__VA_ARGS__);'
     )
     self.define(
         'AUTO_INIT_SPGM(name, ...) __INTERNAL_AUTOINIT_FLASH_STRING_START(#name,__VA_ARGS__,__INTERNAL_AUTOINIT_FLASH_STRING_END)'
     )
     self.define(
         'SPGM(name, ...) __INTERNAL_SPGM_FLASH_STRING_START(#name,__VA_ARGS__,__INTERNAL_SPGM_FLASH_STRING_END)'
     )
     self.define(
         'FSPGM(name, ...) __INTERNAL_SPGM_FLASH_STRING_START(#name,__VA_ARGS__,__INTERNAL_SPGM_FLASH_STRING_END)'
     )
     self.define(
         'PROGMEM_STRING_DEF(name, value) __INTERNAL_DEFINE_FLASH_STRING_START(#name,value,__INTERNAL_DEFINE_FLASH_STRING_END)'
     )
     self._skip_includes = []
     self._items = []
     # self._include_once = []
     self._files = []
     self._display_info = display_info
예제 #6
0
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()
예제 #7
0
    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 on_file_open(self, is_system_include, includepath):
            if path.isfile(includepath):
                includepath = os.path.abspath(includepath)

                for skip_include in self._skip_includes:
                    if fnmatch.fnmatch(includepath, skip_include):
                        # SpgmConfig.debug('skip include %s pattern=%s' % (includepath, skip_include))
                        raise OutputDirective(Action.IgnoreAndPassThrough)

            # SpgmConfig.debug('pcpp %s' % includepath)

            try:
                result = Preprocessor.on_file_open(self, is_system_include,
                                                   includepath)
                if not includepath in self._files:
                    self._files.append(includepath)
                if self._display_info:
                    # tmp = includepath.split(os.sep)
                    # if len(tmp)>4:
                    #     includepath = os.sep.join(tmp[-4:])
                    print('Preprocessing %s' % path.relpath(includepath))
            except Exception as e:
                raise e
            return result
예제 #9
0
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
예제 #10
0
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 on_error(self, file, line, msg):
     # print(file + ':' + str(line) + ': ' + msg)
     # sys.exit(1)
     return Preprocessor.on_error(self, file, line, msg)
예제 #12
0
def run_c_preprocessor(header_contents):
    cpp = Preprocessor()
    cpp.parse(header_contents)
    output = StringIO.StringIO()
    cpp.write(output)
    return output.getvalue()