📄 do_char.c
字号:
/* $XConsortium: do_char.c /main/5 1995/10/24 11:22:28 gildea $ *//*Copyright 1989-1991, Bitstream Inc., Cambridge, MA.You are hereby granted permission under all Bitstream propriety rights touse, copy, modify, sublicense, sell, and redistribute the Bitstream Speedosoftware and the Bitstream Charter outline font for any purpose and withoutrestrictions; provided, that this notice is left intact on all copies of suchsoftware or font and that Bitstream's trademark is acknowledged as shown belowon all unmodified copies of such font.BITSTREAM CHARTER is a registered trademark of Bitstream Inc.BITSTREAM INC. DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDINGWITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR APARTICULAR PURPOSE. BITSTREAM SHALL NOT BE LIABLE FOR ANY DIRECT OR INDIRECTDAMAGES, INCLUDING BUT NOT LIMITED TO LOST PROFITS, LOST DATA, OR ANY OTHERINCIDENTAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR IN ANY WAY CONNECTEDWITH THE SPEEDO SOFTWARE OR THE BITSTREAM CHARTER OUTLINE FONT.*//***************************** D O - C H A R . C ***************************** * * * This is the top level module for processing one simple or composite * * character. * * ****************************************************************************/#include "spdo_prv.h" /* General definitions for Speedo */#define DEBUG 0#if DEBUG#include <stdio.h>#define SHOW(X) printf("X = %d\n", X)#else#define SHOW(X)#endif/***** GLOBAL VARIABLES *****//***** GLOBAL FUNCTIONS *****//***** EXTERNAL VARIABLES *****//***** EXTERNAL FUNCTIONS *****//***** STATIC VARIABLES *****//***** STATIC FUNCTIONS *****/#if PROTOS_AVAILstatic boolean sp_make_simp_char(PROTO_DECL2 ufix8 FONTFAR *pointer,ufix8 format);static boolean sp_make_comp_char(PROTO_DECL2 ufix8 FONTFAR *pointer);static ufix8 FONTFAR *sp_get_char_org(PROTO_DECL2 ufix16 char_index,boolean top_level);static fix15 sp_get_posn_arg(PROTO_DECL2 ufix8 FONTFAR *STACKFAR *ppointer,ufix8 format);static fix15 sp_get_scale_arg(PROTO_DECL2 ufix8 FONTFAR *STACKFAR *ppointer,ufix8 format);#elsestatic boolean sp_make_simp_char(); /* Process simple character data */static boolean sp_make_comp_char(); /* Process compound character data */static ufix8 FONTFAR *sp_get_char_org(); /* Look up char in character directory */static fix15 sp_get_posn_arg(); /* Read Xpos Ypos args in DOCH instruction */static fix15 sp_get_scale_arg(); /* read Xscale Yscale args in DOCH instruction */#endifFUNCTION ufix16 get_char_id(char_index)GDECLufix16 char_index; /* Index to character in char directory *//* * Returns character id for specified character index in currently * selected font. * Reports Error 10 and returns 0 if no font selected. * Reports Error 12 and returns 0 if character data not available. */{ufix8 FONTFAR *pointer; /* Pointer to character data */if (!sp_globals.specs_valid) /* Font specs not defined? */ { report_error(10); /* Report font not specified */ return (ufix16)0; /* Return zero character id */ }pointer = sp_get_char_org(char_index, TRUE); /* Get pointer to character data */if (pointer == NULL) /* Character data not available? */ { report_error(12); /* Report character data not avail */ return (ufix16)0; /* Return zero character id */ }return 0xffff & NEXT_WORD(pointer); /* Return character id */}#if INCL_METRICSFUNCTION fix31 get_char_width(char_index)GDECLufix16 char_index; /* Index to character in char directory *//* * Returns character set width for specified character index in currently * selected font in units of 1/65536 em. * Reports Error 10 and returns 0 if no font selected. * Reports Error 12 and returns 0 if character data not available. */{ufix8 FONTFAR *pointer; /* Pointer to character data */fix31 set_width; /* Set width of character */if (!sp_globals.specs_valid) /* Font specs not defined? */ { report_error(10); /* Report font not specified */ return (fix31)0; /* Return zero character width */ }pointer = sp_get_char_org(char_index, TRUE); /* Get pointer to character data */if (pointer == NULL) /* Character data not available? */ { report_error(12); /* Report character data not avail */ return (fix31)0; /* Return zero character width */ }pointer += 2; /* Skip over character id */set_width = (fix31)NEXT_WORD(pointer); /* Read set width and Convert units */set_width = ((set_width << 16) + (sp_globals.metric_resolution >> 1)) / sp_globals.metric_resolution;return set_width; /* Return in 1/65536 em units */}#endif#if INCL_METRICSFUNCTION fix15 get_track_kern(track, point_size)GDECLfix15 track; /* Track required (0 - 3) */fix15 point_size; /* Point size (units of whole points) *//* * Returns inter-character spacing adjustment in units of 1/256 * points for the specified kerning track and point size. * If the specified point size is larger than the maximum point * size for the specified track, the adjustment for the maximum * point size is used. * If the specified point size is smaller than the minimum point * size for the specified track, the adjustment for the minimum * point size is used. * If the specified point size is between the minimum point size * and the maximum point size for the specified track, the * adjustment is interpolated linearly between the minimum and * maximum adjustments. * Reports Error 10 and returns 0 if no font selected. * Reports Error 13 and returns 0 if track kerning data not in font. */{ufix8 FONTFAR *pointer; /* Pointer to character data */fix15 no_tracks; /* Number of kerning tracks in font */ufix8 format; /* Track kerning format byte */fix15 i; /* Track counter */fix15 min_pt_size; /* Minimum point size for track */fix15 max_pt_size; /* Maximum point size for track */fix15 min_adj; /* Adjustment for min point size */fix15 max_adj; /* Adjustment for max point size */fix31 delta_pt_size;/* Max point size - min point size */fix31 delta_adj; /* Min adjustment - max adjustment */fix15 adj = 0; /* Interpolated adjustment */if (track == 0) /* Track zero selected? */ { return adj; /* Return zero track kerning adjustment */ }if (!sp_globals.specs_valid) /* Font specs not defined? */ { report_error(10); /* Report font not specified */ return adj; /* Return zero track kerning adjustment */ }no_tracks = sp_globals.kern.no_tracks; /* Number of kerning tracks */if (track > no_tracks) /* Required track not available? */ { report_error(13); /* Report track kerning data not avail */ return adj; /* Return zero track kerning adjustment */ }pointer = sp_globals.kern.tkorg; /* Point to start of track kern data */for (i = 0; i < track; i++) /* Read until track required is read */ { format = NEXT_BYTE(pointer); /* Read track kerning format byte */ min_pt_size = (format & BIT0)? NEXT_WORD(pointer): (fix15)NEXT_BYTE(pointer); min_adj = (format & BIT1)? NEXT_WORD(pointer): (fix15)NEXT_BYTE(pointer); max_pt_size = (format & BIT2)? NEXT_WORD(pointer): (fix15)NEXT_BYTE(pointer); max_adj = (format & BIT3)? NEXT_WORD(pointer): (fix15)NEXT_BYTE(pointer); }if (point_size <= min_pt_size) /* Smaller than minimum point size? */ { return min_adj; /* Return minimum adjustment (1/256 points) */ }if (point_size >= max_pt_size) /* Larger than maximum point size? */ { return max_adj; /* Return maximum adjustment (1/256 points) */ }delta_pt_size = (fix31)(max_pt_size - min_pt_size);delta_adj = (fix31)(min_adj - max_adj);adj = (fix15)(min_adj - (((fix31)(point_size - min_pt_size) * delta_adj + (delta_pt_size >> 1)) / delta_pt_size));return adj; /* Return interpolated adjustment (1/256 points) */}#endif#if INCL_METRICSFUNCTION fix31 get_pair_kern(char_index1, char_index2)GDECLufix16 char_index1; /* Index to first character in char directory */ufix16 char_index2; /* Index to second character in char directory *//* * Returns inter-character spacing adjustment in units of 1/65536 em * for the specified pair of characters. * Reports Error 10 and returns 0 if no font selected. * Reports Error 14 and returns 0 if pair kerning data not in font. */{ufix8 FONTFAR *origin; /* Pointer to first kerning pair record */ufix8 FONTFAR *pointer; /* Pointer to character data */ufix16 tmpufix16; /* Temporary workspace */fix15 no_pairs; /* Number of kerning pairs in font */ufix8 format; /* Track kerning format byte */boolean long_id; /* TRUE if 2-byte character ids */fix15 rec_size; /* Number of bytes in kern pair record */fix15 n; /* Number of remaining kern pairs */fix15 nn; /* Number of kern pairs in first partition */fix15 base; /* Index to first record in rem kern pairs */fix15 i; /* Index to kern pair being tested */fix31 adj = 0; /* Returned value of adjustment */fix15 adj_base; /* Adjustment base for relative adjustments */if (!sp_globals.specs_valid) /* Font specs not defined? */ { report_error(10); /* Report font not specified */ return adj; /* Return zero pair kerning adjustment */ }no_pairs = sp_globals.kern.no_pairs; /* Number of kerning pairs */if (no_pairs == 0) /* Pair kerning data not available? */ { report_error(14); /* Report pair kerning data not avail */ return adj; /* Return zero pair kerning adjustment */ }pointer = sp_globals.kern.pkorg; /* Point to start of pair kern data */format = NEXT_BYTE(pointer); /* Read pair kerning format byte */if (!(format & BIT0)) /* One-byte adjustment values? */ adj_base = NEXT_WORD(pointer); /* Read base adjustment */origin = pointer; /* First byte of kerning pair data */rec_size = format + 3; /* Compute kerning pair record size */long_id = format & BIT1; /* Set flag for 2-byte char index */n = no_pairs; /* Consider all kerning pairs */base = 0; /* Set base at first kern pair record */while (n != 0) /* While 1 or more kern pairs remain ... */ { nn = n >> 1; /* Size of first partition */ i = base + nn; /* Index to record to be tested */ pointer = origin + (i * rec_size); tmpufix16 = NEXT_CHNDX(pointer, long_id); if (char_index1 < tmpufix16) { n = nn; /* Number remaining in first partition */ continue; } if (char_index1 > tmpufix16) { n -= nn + 1; /* Number remaining in second partition */ base = i + 1; /* Base index for second partition */ continue; } tmpufix16 = NEXT_CHNDX(pointer, long_id); if (char_index2 < tmpufix16) { n = nn; /* Number remaining in first partition */ continue; } if (char_index2 > tmpufix16) { n -= nn + 1; /* Number remaining in second partition */ base = i + 1; /* Base index for second partition */ continue; } adj = (format & BIT0)? (fix31)NEXT_WORD(pointer): (fix31)(adj_base + (fix15)NEXT_BYTE(pointer)); adj = ((adj << 16) + (sp_globals.orus_per_em >> 1)) / sp_globals.orus_per_em; /* Convert units */ n = 0; /* No more to consider */ }return adj; /* Return pair kerning adjustment */}#endif#if INCL_METRICS#ifdef oldFUNCTION boolean get_char_bbox(char_index, bbox)GDECLufix16 char_index;bbox_t *bbox;{/* * returns true if character exists, false if it doesn't * provides transformed character bounding box in 1/65536 pixels * in the provided bbox_t structure. Bounding box may be * conservative in the event that the transformation is not * normal or the character is compound. */ufix8 FONTFAR *pointer;fix15 tmp;point_t Pmin, Pmax;#if REENTRANT_ALLOCplaid_t plaid;sp_globals.plaid = &plaid;#endifif (!sp_globals.specs_valid) /* Font specs not defined? */ { report_error(10); /* Report font not specified */ return FALSE; /* Error return */ }init_tcb(); /* Initialize transformation control block */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -