File indexing completed on 2024-04-28 11:38:33

0001 /*
0002     This file is part of the KDE libraries
0003 
0004     The Original Code is WOFF font packaging code.
0005     Copyright (C) 2009 Mozilla Corporation
0006 
0007     Contributor(s):
0008       Jonathan Kew <jfkthame@gmail.com>
0009       Germain Garand <germain@ebooksfrance.org>
0010 
0011     This library is free software; you can redistribute it and/or
0012     modify it under the terms of the GNU Library General Public
0013     License as published by the Free Software Foundation; either
0014     version 2 of the License, or (at your option) any later version.
0015 
0016     This library is distributed in the hope that it will be useful,
0017     but WITHOUT ANY WARRANTY; without even the implied warranty of
0018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0019     Library General Public License for more details.
0020 
0021     You should have received a copy of the GNU Library General Public License
0022     along with this library; see the file COPYING.LIB.  If not, write to
0023     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0024     Boston, MA 02110-1301, USA.
0025 */
0026 
0027 #ifndef WOFF_H_
0028 #define WOFF_H_
0029 
0030 /* API for the decoding of WOFF (Web Open Font Format) font files */
0031 
0032 typedef enum {
0033     /* Success */
0034     eWOFF_ok = 0,
0035 
0036     /* Errors: no valid result returned */
0037     eWOFF_out_of_memory = 1,       /* malloc or realloc failed */
0038     eWOFF_invalid = 2,             /* invalid input file (e.g., bad offset) */
0039     eWOFF_compression_failure = 3, /* error in zlib call */
0040     eWOFF_bad_signature = 4,       /* unrecognized file signature */
0041     eWOFF_buffer_too_small = 5,    /* the provided buffer is too small */
0042     eWOFF_bad_parameter = 6,       /* bad parameter (e.g., null source ptr) */
0043     eWOFF_illegal_order = 7,       /* improperly ordered chunks in WOFF font */
0044 
0045     /* Warnings: call succeeded but something odd was noticed.
0046        Multiple warnings may be OR'd together. */
0047     eWOFF_warn_unknown_version = 0x0100,   /* unrecognized version of sfnt,
0048                                             not standard TrueType or CFF */
0049     eWOFF_warn_checksum_mismatch = 0x0200, /* bad checksum, use with caution;
0050                                             any DSIG will be invalid */
0051     eWOFF_warn_misaligned_table = 0x0400,  /* table not long-aligned; fixing,
0052                                             but DSIG will be invalid */
0053     eWOFF_warn_trailing_data = 0x0800,     /* trailing junk discarded,
0054                                             any DSIG may be invalid */
0055     eWOFF_warn_unpadded_table = 0x1000,    /* sfnt not correctly padded,
0056                                             any DSIG may be invalid */
0057     eWOFF_warn_removed_DSIG = 0x2000       /* removed digital signature
0058                                             while fixing checksum errors */
0059 } WOFFStatus;
0060 
0061 /* Note: status parameters must be initialized to eWOFF_ok before calling
0062    WOFF functions. If the status parameter contains an error code,
0063    functions will return immediately. */
0064 
0065 #define WOFF_SUCCESS(status) (((status) & 0xff) == eWOFF_ok)
0066 #define WOFF_FAILURE(status) (!WOFF_SUCCESS(status))
0067 #define WOFF_WARNING(status) ((status) & ~0xff)
0068 
0069 namespace WOFF
0070 {
0071 
0072 /*****************************************************************************
0073  * Returns the size of buffer needed to decode the font (or zero on error).
0074  */
0075 int getDecodedSize(const char *woffData, int woffLen, int *pStatus);
0076 
0077 /*****************************************************************************
0078  * Decodes WOFF font to a caller-supplied buffer of size bufferLen.
0079  * Returns the actual size of the decoded sfnt data in pActualSfntLen
0080  * (must be <= bufferLen, otherwise an error will be returned).
0081  */
0082 void decodeToBuffer(const char *woffData, int woffLen, char *sfntData, int bufferLen,
0083                     int *pActualSfntLen, int *pStatus);
0084 
0085 }
0086 
0087 #endif