Make Adobe fonts work with CSS3 @font-face in IE9

前端 未结 19 2057
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 10:04

I\'m in the process of building a small intranet application and try, with no luck, to use Adobe font I purchased lately. As I was informed, in our case it\

相关标签:
19条回答
  • 2020-11-27 10:25

    Try this, add this lines in the web.config.

    <system.webServer>
      <staticContent>
         <mimeMap fileExtension=".woff" mimeType="application/octet-stream" />
      </staticContent>
    </system.webServer>
    
    0 讨论(0)
  • 2020-11-27 10:26

    I recently encountered this issue with .eot and .otf fonts producing the CSS3114 and CSS3111 errors in the console when loading. The solution that worked for me was to use only .woff and .woff2 formats with a .ttf format fallback. The .woff formats will be used before .ttf in most browsers and don't seem to trigger the font embedding permissions issue (css3114) and the font naming incorrect format issue (css3111). I found my solution in this extremely helpful article about the CSS3111 and CSS3114 issue, and also reading this article on using @font-face.

    note: This solution does not require re-compiling, converting or editing any font files. It is a css-only solution. The font I tested with did have .eot, .otf, .woff, .woff2 and .svg versions generated for it, probably from the original .ttf source which did produce the 3114 error when i tried it, however the .woff and .woff2 files seemed to be immune to this issue.

    This is what DID work for me with @font-face:

    @font-face {
      font-family: "Your Font Name";
      font-weight: normal;
      src: url('your-font-name.woff2') format('woff2'),
           url('your-font-name.woff') format('woff'),
           url('your-font-name.ttf')  format('truetype');
    }
    

    This was what triggered the errors with @font-face in IE:

    @font-face {
      font-family: 'Your Font Name';
      src: url('your-font-name.eot');
      src: url('your-font-name.eot?#iefix') format('embedded-opentype'),
           url('your-font-name.woff2') format('woff2'),
           url('your-font-name.woff') format('woff'),
           url('your-font-name.ttf')  format('truetype'),
           url('your-font-name.svg#svgFontName') format('svg');
    }
    
    0 讨论(0)
  • 2020-11-27 10:30

    I can only explain you how to fix the "CSS3114" error.
    You have to change the embedding level of your TTF file.

    Using the appropriate tool you can set it to installable embedding allowed.
    For a 64-bit version, check @user22600's answer.

    0 讨论(0)
  • 2020-11-27 10:30

    A Different Answer: Legal issues.

    There's a couple of things to note before you do this. First, to get this error, in IE, inspect element, switch your tabs, and look for the errors, I believe "CSS3114" appears in the console.

    What you need to understand is this is a licensing issue. I.E. (pun intended) if you are trying to load a font that causes this error, you don't have permissions on the file to use the font, and if you don't have permission, it is highly likely that you may lose a legal battle (which itself is highly unlikely) over using this font in this manner unless you are holding the license. So, you can, for the first time, thank IE for being the only browser to tell you "no", because it at least lets you know that you are doing something questionable.

    That said, here is your answer:

    First ensure you're using the best code in .css, see some of the other css answers for that.
    IE 11 css example (works in all modern browsers may need to be tweaked for IE9):

    @font-face {
    font-family: "QuestionableLegalFont";
    font-weight: bold;
    src: url('../fonts/QuestionableLegalFont.ttf') format('truetype');
    }
    

    Then, ensure you have a working web-font (you probably already know this by seeing your font in other browsers). If you need an online font converter, check here: https://onlinefontconverter.com/

    Finally, To get rid of the "CSS3114" error. For an online tool, click here: https://www.andrebacklund.com/fontfixer.html

    0 讨论(0)
  • 2020-11-27 10:31

    If you want to do this with a Python script instead of having to run C / PHP code, here's a Python3 function that you can use to remove the embedding permissions from the font:

    def convert_restricted_font(filename):
    with open(filename, 'rb+') as font:
    
        font.read(12)
        while True:
            _type = font.read(4)
            if not _type:
                raise Exception('Could not read the table definitions of the font.')
            try:
                _type = _type.decode()
            except UnicodeDecodeError:
                pass
            except Exception as err:
                pass
            if _type != 'OS/2':
                continue
            loc = font.tell()
            font.read(4)
            os2_table_pointer = int.from_bytes(font.read(4), byteorder='big')
            length = int.from_bytes(font.read(4), byteorder='big')
            font.seek(os2_table_pointer + 8)
    
            fs_type = int.from_bytes(font.read(2), byteorder='big')
            print(f'Installable Embedding: {fs_type == 0}')
            print(f'Restricted License: {fs_type & 2}')
            print(f'Preview & Print: {fs_type & 4}')
            print(f'Editable Embedding: {fs_type & 8}')
    
            print(f'No subsetting: {fs_type & 256}')
            print(f'Bitmap embedding only: {fs_type & 512}')
    
            font.seek(font.tell()-2)
            installable_embedding = 0 # True
            font.write(installable_embedding.to_bytes(2, 'big'))
            font.seek(os2_table_pointer)
            checksum = 0
            for i in range(length):
                checksum += ord(font.read(1))
            font.seek(loc)
            font.write(checksum.to_bytes(4, 'big'))
            break
    
    
    if __name__ == '__main__':
        convert_restricted_font("19700-webfont.ttf")
    

    it works, but I ended up solving the problem of loading fonts in IE by https like this this

    thanks NobleUplift

    Original source in C can be found here.

    0 讨论(0)
  • 2020-11-27 10:32

    I wasted a lot of time because of this issue. Finally I found great solution myself. Before I was using .ttf font only. But I added one extra font format .eot that started to work in IE.

    I used following code and it worked like charm in all browsers.

    @font-face {
    font-family: OpenSans;
    src: url(assets/fonts/OpenSans/OpenSans-Regular.ttf), 
    url(assets/fonts/OpenSans/OpenSans-Regular.eot);
    }
    
    @font-face {
    font-family: OpenSans Bold;
    src: url(assets/fonts/OpenSans/OpenSans-Bold.ttf),
    url(assets/fonts/OpenSans/OpenSans-Bold.eot);
    }
    

    I hope this will help someone.

    0 讨论(0)
提交回复
热议问题