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

前端 未结 19 2058
佛祖请我去吃肉
佛祖请我去吃肉 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:33

    If you are familiar with nodejs/npm, ttembed-js is an easy way to set the "installable embedding allowed" flag on a TTF font. This will modify the specified .ttf file:

    npm install -g ttembed-js
    
    ttembed-js somefont.ttf
    
    0 讨论(0)
  • 2020-11-27 10:34

    As Knu said, you can use this tool, however it's compiled only for MS-DOS. I compiled it for Win64. Download.

    Usage:

    1. Place the .exe in the same folder as the font you need to modify

    2. Navigate to that directory in the command line

    3. type embed fontname.fonttype, replacing fontname with the filename and fonttype with the extension i.e. embed brokenFont.ttf

    4. All done! Your font should now work.

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

    If you want to do this with a PHP script instead of having to run C code (or you're on a Mac like me and you can't be arsed compiling with Xcode only to wait a year for it to open), here's a PHP function that you can use to remove the embedding permissions from the font:

    function convertRestrictedFont($filename) {
        $font = fopen($filename,'r+');
        if ($font === false) {
            throw new Exception('Could not open font file.');
        }
    
        fseek($font, 12, 0);
    
        while (!feof($font)) {
            $type = '';
            for ($i = 0; $i < 4; $i++) {
                $type .= fgetc($font);
                if (feof($font)) {
                    fclose($font);
                    throw new Exception('Could not read the table definitions of the font.');
                }
            }
            if ($type == 'OS/2') {
                // Save the location of the table definition
                // containing the checksum and pointer to the data
                $os2TableDefinition = ftell($font);
                $checksum = 0;
    
                for ($i = 0; $i < 4; $i++) {
                    fgetc($font);
                    if (feof($font)) {
                        fclose($font);
                        throw new Exception('Could not read the OS/2 table header of the font.');
                    }
                }
    
                // Get the pointer to the OS/2 table data
                $os2TablePointer = ord(fgetc($font)) << 24;
                $os2TablePointer |= ord(fgetc($font)) << 16;
                $os2TablePointer |= ord(fgetc($font)) << 8;
                $os2TablePointer |= ord(fgetc($font));
    
                $length = ord(fgetc($font)) << 24;
                $length |= ord(fgetc($font)) << 16;
                $length |= ord(fgetc($font)) << 8;
                $length |= ord(fgetc($font));
    
                if (fseek($font, $os2TablePointer + 8, 0) !== 0) {
                    fclose($font);
                    throw new Exception('Could not read the embeddable type of the font.');
                }
    
                // Read the fsType before overriding it
                $fsType = ord(fgetc($font)) << 8;
                $fsType |= ord(fgetc($font));
    
                error_log('Installable Embedding: ' . ($fsType == 0));
                error_log('Reserved: ' . ($fsType & 1));
                error_log('Restricted License: ' . ($fsType & 2));
                error_log('Preview & Print: ' . ($fsType & 4));
                error_log('Editable Embedding: ' . ($fsType & 8));
                error_log('Reserved: ' . ($fsType & 16)); 
                error_log('Reserved: ' . ($fsType & 32));
                error_log('Reserved: ' . ($fsType & 64));
                error_log('Reserved: ' . ($fsType & 128));
                error_log('No subsetting: ' . ($fsType & 256));
                error_log('Bitmap embedding only: ' . ($fsType & 512));                         
                error_log('Reserved: ' . ($fsType & 1024));
                error_log('Reserved: ' . ($fsType & 2048));
                error_log('Reserved: ' . ($fsType & 4096));
                error_log('Reserved: ' . ($fsType & 8192));
                error_log('Reserved: ' . ($fsType & 16384));
                error_log('Reserved: ' . ($fsType & 32768));
    
                fseek($font, ftell($font) - 2);
    
                // Set the two bytes of fsType to 0
                fputs($font, chr(0), 1);
                fputs($font, chr(0), 1);
    
                // Go to the beginning of the OS/2 table data
                fseek($font, $os2TablePointer, 0);
    
                // Generate a new checksum based on the changed 
                for ($i = 0; $i < $length; $i++) {
                    $checksum += ord(fgetc($font));
                }
                fseek($font, $os2TableDefinition, 0);
                fputs($font, chr($checksum >> 24), 1);
                fputs($font, chr(255 & ($checksum >> 16)), 1);
                fputs($font, chr(255 & ($checksum >> 8)), 1);
                fputs($font, chr(255 & $checksum), 1);
    
                fclose($font);
    
                return true;
            }
            for ($i = 0; $i < 12; $i++) {
                fgetc($font);
                if (feof($font)) {
                    fclose($font);
                    throw new Exception('Could not skip a table definition of the font.');
                }
            }
        }
    
        fclose($font);
    
        return false;
    }
    

    Make sure to backup your font file before running this code and don't blame me if it corrupts.

    Original source in C can be found here.

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

    For everyone who gets the error: "tableversion must be 0, 1 or and is hex:003" when using ttfpatch, i've compiled embed for 64bit. I have not changed anything, just added need libs and compiled. Use at own risk.

    Usage: ConsoleApplication1 font.ttf

    http://www.mediafire.com/download/8x1px8aqq18lcx8/ConsoleApplication1.exe

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

    This works for me:

    @font-face {
      font-family: FontName;
      src: url('@{path-fonts}/FontName.eot?akitpd');
      src: url('@{path-fonts}/FontName.eot?akitpd#iefix') format('embedded-opentype'),
        url('@{path-fonts}/FontName.ttf?akitpd') format('truetype'),
        url('@{path-fonts}/FontName.woff?akitpd') format('woff'),
        url('@{path-fonts}/FontName.svg?akitpd#salvage') format('svg');
    }
    
    0 讨论(0)
  • 2020-11-27 10:37

    As a Mac user, I was unable to use the MS-DOS and Windows command line tools that were mentioned to fix the font embedding permission. However, I found out that you can fix this using FontLab to set the permission to 'Everything is allowed'. I hope this recipe on how to set the font permission to Installable on Mac OS X is useful for others as well.

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