⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttf2bdf.c

📁 字体缩放显示
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright 2000 Computing Research Labs, New Mexico State University * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. */#ifndef lint#ifdef __GNUC__static char rcsid[] __attribute__ ((unused)) = "$Id: ttf2bdf.c,v 1.1.1.1 2000/04/14 17:53:50 davidT Exp $";#elsestatic char rcsid[] = "$Id: ttf2bdf.c,v 1.1.1.1 2000/04/14 17:53:50 davidT Exp $";#endif#endif#include <stdio.h>#ifdef WIN32#include <windows.h>#else#include <stdlib.h>#include <unistd.h>#endif#include <string.h>#include <freetype.h>#include <extend/ftxsbit.h>/* * Include the remapping support. */#include "remap.h"/************************************************************************** * * Macros. * **************************************************************************//* * The version of ttf2bdf. */#define TTF2BDF_VERSION "2.9"/* * Set the default values used to generate a BDF font. */#ifndef DEFAULT_PLATFORM_ID#define DEFAULT_PLATFORM_ID 3#endif#ifndef DEFAULT_ENCODING_ID#define DEFAULT_ENCODING_ID 1#endif#ifndef DEFAULT_POINT_SIZE#define DEFAULT_POINT_SIZE 12#endif#ifndef DEFAULT_RESOLUTION#define DEFAULT_RESOLUTION 100#endif/* * Used as a fallback for XLFD names where the character set/encoding can not * be determined. */#ifndef DEFAULT_XLFD_CSET#define DEFAULT_XLFD_CSET "-FontSpecific-0"#endif/* * nameID macros for getting strings from the TT font. */#define TTF_COPYRIGHT 0#define TTF_TYPEFACE  1#define TTF_PSNAME    6#ifndef MAX#define MAX(h,i) ((h) > (i) ? (h) : (i))#endif#ifndef MIN#define MIN(l,o) ((l) < (o) ? (l) : (o))#endif/************************************************************************** * * General globals set from command line. * **************************************************************************//* * The program name. */static char *prog;/* * The flag indicating whether messages should be printed or not. */static int verbose = 0;/* * Flags used when loading glyphs. */static int load_flags = TTLOAD_SCALE_GLYPH | TTLOAD_HINT_GLYPH;/* * The default platform and encoding ID's. */static int pid = DEFAULT_PLATFORM_ID;static int eid = DEFAULT_ENCODING_ID;/* * Default point size and resolutions. */static int point_size = DEFAULT_POINT_SIZE;static int hres = DEFAULT_RESOLUTION;static int vres = DEFAULT_RESOLUTION;/* * The user supplied foundry name to use in the XLFD name. */static char *foundry_name = 0;/* * The user supplied typeface name to use in the XLFD name. */static char *face_name = 0;/* * The user supplied weight name to use in the XLFD name. */static char *weight_name = 0;/* * The user supplied slant name to use in the XLFD name. */static char *slant_name = 0;/* * The user supplied width name to use in the XLFD name. */static char *width_name = 0;/* * The user supplied additional style name to use in the XLFD name. */static char *style_name = 0;/* * The user supplied spacing (p = proportional, c = character cell, * m = monospace). */static int spacing = 0;/* * The dash character to use in the names retrieved from the font.  Default is * the space. */static int dashchar = ' ';/* * Flag, bitmask, and max code for generating a subset of the glyphs in a font. */static int do_subset = 0;static unsigned short maxcode;static unsigned long subset[2048];/* * The flag that indicates the remapping table should be used to * reencode the font. */static int do_remap = 0;/************************************************************************** * * Internal globals. * **************************************************************************//* * Structure used for calculating the font bounding box as the glyphs are * generated. */typedef struct {    short minlb;    short maxlb;    short maxrb;    short maxas;    short maxds;    short rbearing;} bbx_t;static bbx_t bbx;/* * The buffer used to transfer the temporary file to the actual output file. */#define TTF2BDF_IOBUFSIZ 8192static char iobuf[TTF2BDF_IOBUFSIZ];/* * The Units Per Em value used in numerous places. */static TT_UShort upm;/* * A flag indicating if a CMap was found or not. */static TT_UShort nocmap;/* * The scaling factor needed to compute the SWIDTH (scalable width) value * for BDF glyphs. */static double swscale;/* * Mac encoding names used when creating the BDF XLFD font name. */static char *mac_encodings[] = {    "-MacRoman-0",    "-MacJapanese-0",   "-MacChinese-0",   "-MacKorean-0",    "-MacArabic-0",   "-MacHebrew-0",     "-MacGreek-0",     "-MacRussian-0",    "-MacRSymbol-0",  "-MacDevanagari-0", "-MacGurmukhi-0",  "-MacGujarati-0",    "-MacOriya-0",    "-MacBengali-0",    "-MacTamil-0",     "-MacTelugu-0",    "-MacKannada-0",  "-MacMalayalam-0",  "-MacSinhalese-0", "-MacBurmese-0",    "-MacKhmer-0",    "-MacThai-0",       "-MacLaotian-0",   "-MacGeorgian-0",    "-MacArmenian-0", "-MacMaldivian-0",  "-MacTibetan-0",   "-MacMongolian-0",    "-MacGeez-0",     "-MacSlavic-0",     "-MacVietnamese-0","-MacSindhi-0",    "-MacUninterp-0"};static int num_mac_encodings = sizeof(mac_encodings) /                               sizeof(mac_encodings[0]);/* * ISO encoding names used when creating the BDF XLFD font name. */static char *iso_encodings[] = {    "-ASCII-0", "-ISO10646-0", "-ISO8859-1"};static int num_iso_encodings = sizeof(iso_encodings) /                               sizeof(iso_encodings[0]);/* * Microsoft encoding names used when creating the BDF XLFD font name. */static char *ms_encodings[] = {    "-Symbol-0", "-ISO10646-1", "-ShiftJIS-0", "-GB2312.1980-0", "-Big5-0",    "-KSC5601.1987-0", "-KSC5601.1992-0"};static int num_ms_encodings = sizeof(ms_encodings) /                              sizeof(ms_encodings[0]);/* * The propery names for all the XLFD properties. */static char *xlfd_props[] = {    "FOUNDRY",    "FAMILY_NAME",    "WEIGHT_NAME",    "SLANT",    "SETWIDTH_NAME",    "ADD_STYLE_NAME",    "PIXEL_SIZE",    "POINT_SIZE",    "RESOLUTION_X",    "RESOLUTION_Y",    "SPACING",    "AVERAGE_WIDTH",    "CHARSET_REGISTRY",    "CHARSET_ENCODING",};/* * Whether the font has bitmaps for the resolution and point size. */static int have_strike;/************************************************************************** * * Freetype globals. * **************************************************************************/static TT_Engine engine;static TT_Face face;static TT_Face_Properties properties;static TT_Instance instance;static TT_SBit_Strike strike;static TT_SBit_Image *sbit;static TT_Glyph glyph;static TT_Big_Glyph_Metrics metrics;static TT_Instance_Metrics imetrics;static TT_Raster_Map raster;static TT_CharMap cmap;/************************************************************************** * * Freetype related code. * **************************************************************************//* * A generic routine to get a name from the TT name table.  This routine * always looks for English language names and checks three possibilities: * 1. English names with the MS Unicode encoding ID. * 2. English names with the MS unknown encoding ID. * 3. English names with the Apple Unicode encoding ID. * * The particular name ID mut be provided (e.g. nameID = 0 for copyright * string, nameID = 6 for Postscript name, nameID = 1 for typeface name. * * If the `dash' flag is non-zero, all dashes (-) in the name will be replaced * with the character passed. * * Returns the number of bytes added. */static int#ifdef __STDC__ttf_get_english_name(char *name, int nameID, int dash)#elsettf_get_english_name(name, nameID, dash)char *name;int nameID, dash;#endif{    TT_UShort slen;    int i, j, encid, nrec;    unsigned short nrPlatformID, nrEncodingID, nrLanguageID, nrNameID;    char *s;    nrec = TT_Get_Name_Count(face);    for (encid = 1, j = 0; j < 2; j++, encid--) {        /*         * Locate one of the MS English font names.         */        for (i = 0; i < nrec; i++) {            TT_Get_Name_ID(face, i, &nrPlatformID, &nrEncodingID,                           &nrLanguageID, &nrNameID);            if (nrPlatformID == 3 &&                nrEncodingID == encid &&                nrNameID == nameID &&                (nrLanguageID == 0x0409 || nrLanguageID == 0x0809 ||                 nrLanguageID == 0x0c09 || nrLanguageID == 0x1009 ||                 nrLanguageID == 0x1409 || nrLanguageID == 0x1809)) {                TT_Get_Name_String(face, i, &s, &slen);                break;            }        }        if (i < nrec) {            /*             * Found one of the MS English font names.  The name is by             * definition encoded in Unicode, so copy every second byte into             * the `name' parameter, assuming there is enough space.             */            for (i = 1; s != 0 && i < slen; i += 2) {                if (dash)                  *name++ = (s[i] == '-' || s[i] == ' ') ? dash : s[i];                else if (s[i] == '\r' || s[i] == '\n') {                    if (s[i] == '\r' && i + 2 < slen && s[i + 2] == '\n')                      i += 2;                    *name++ = ' ';                    *name++ = ' ';                } else                  *name++ = s[i];            }            *name = 0;            return (slen >> 1);        }    }    /*     * No MS English name found, attempt to find an Apple Unicode English     * name.     */    for (i = 0; i < nrec; i++) {        TT_Get_Name_ID(face, i, &nrPlatformID, &nrEncodingID,                       &nrLanguageID, &nrNameID);        if (nrPlatformID == 0 && nrLanguageID == 0 &&            nrNameID == nameID) {            TT_Get_Name_String(face, i, &s, &slen);            break;        }    }    if (i < nrec) {        /*         * Found the Apple Unicode English name.  The name is by definition         * encoded in Unicode, so copy every second byte into the `name'         * parameter, assuming there is enough space.         */        for (i = 1; s != 0 && i < slen; i += 2) {            if (dash)              *name++ = (s[i] == '-' || s[i] == ' ') ? dash : s[i];            else if (s[i] == '\r' || s[i] == '\n') {                if (s[i] == '\r' && i + 2 < slen && s[i + 2] == '\n')                  i += 2;                *name++ = ' ';                *name++ = ' ';            } else              *name++ = s[i];        }        *name = 0;        return (slen >> 1);    }    return 0;}/************************************************************************** * * General code. * **************************************************************************//* * Create an XLFD name.  Assumes there is enough space in the string passed * to fit a reasonably long XLFD name into, up to the 256 byte maximum. */static void#ifdef __STDC__make_xlfd_name(char *name, TT_Long awidth, int ismono)#elsemake_xlfd_name(name, awidth, ismono)char *name;TT_Long awidth;int ismono;#endif{    TT_Long i;    TT_ULong val;    char *r, *e;    double dr, dp;    /*     * Default the foundry name to "FreeType" in honor of the project and     * because the foundry name is too difficult to automatically determine     * from the names in TT fonts. But the user can provide his own.     */    if (foundry_name == 0) {        (void) strcpy(name, "-FreeType");        name += 9;    } else {        *(name++)='-';        strcpy(name,foundry_name);        name+=strlen(foundry_name);    }    /*     * Add the typeface name from the font.  The fallback default will be     * "Unknown".     */    *name++ = '-';    if (face_name == 0) {        if((i = ttf_get_english_name(name, TTF_TYPEFACE, dashchar)))          name += i;        else {            (void) strcpy(name, "Unknown");            name += 7;        }    } else {        (void) strcpy(name, face_name);        name += strlen(face_name);    }    /*     * Add the weight name.  The default will be "Medium".     */    if (weight_name != 0) {        sprintf(name, "-%s", weight_name);        name += strlen(weight_name) + 1;    } else {        if (properties.os2->fsSelection & 0x20) {            (void) strcpy(name, "-Bold");            name += 5;        } else {            (void) strcpy(name, "-Medium");            name += 7;        }    }    /*     * Add the slant name.  The default will be 'R'.     */    if (slant_name) {        sprintf(name, "-%s", slant_name);        name += strlen(slant_name) + 1;    } else {        *name++ = '-';        if (properties.os2->fsSelection & 0x01)          *name++ = 'I';        else          *name++ = 'R';    }    /*     * Default the setwidth name to "Normal" but user can specify one.     */    if (width_name == 0) {        (void) strcpy(name, "-Normal");        name += 7;    } else {        *(name++)='-';        strcpy(name,width_name);        name+=strlen(width_name);    }    /*     * Default the additional style name to NULL but user can specify one.     */    *name++ = '-';    if (style_name != 0) {        strcpy(name,style_name);        name+=strlen(style_name);    }    /*     * Determine the pixel size from the point size and resolution.     */    dr = (double) vres;    dp = (double) (point_size * 10);    val = (unsigned long) (((dp * dr) / 722.7) + 0.5);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -