1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
# include "appUtilConfig.h"
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <ctype.h>
# define y0 math_y0
# define y1 math_y1
# include <math.h>
# undef y0
# undef y1
# include <locale.h>
# include "docFont.h"
# include "psFont.h"
# include "appSystem.h"
# include <appDebugon.h>
# ifndef M_PI
# define M_PI 3.14159265358979323846
# endif
/************************************************************************/
/* */
/* Set the encoding of an afi according to glyph names. */
/* */
/************************************************************************/
static int psFindAlternate( const AfmFontInfo * afi,
const char * glyphName )
{
const AlternateGlyphName * agn= PS_AlternateNames;
while( agn->agnStandardName )
{
if ( ! strcmp( glyphName, agn->agnStandardName ) )
{
int j;
AfmCharMetric * acm;
acm= afi->afiMetrics;
for ( j= 0; j < afi->afiMetricCount; acm++, j++ )
{
if ( ! strcmp( acm->acmN, agn->agnAlternateName ) )
{ break; }
}
if ( j < afi->afiMetricCount )
{ return j; }
}
agn++;
}
return -1;
}
/************************************************************************/
/* */
/* Set an encoding array for a PostScript font. */
/* */
/************************************************************************/
static int psSetEncoding( int * codeToGlyph,
const AfmFontInfo * afi,
const char * const * glyphNames,
int nameCount,
int complain )
{
int i;
int rval= 0;
if ( nameCount > 256 )
{ LLDEB(nameCount,256); return -1; }
for ( i= 0; i < nameCount; i++ )
{
int j;
AfmCharMetric * acm;
if ( ! glyphNames[i] )
{ codeToGlyph[i]= -1; continue; }
acm= afi->afiMetrics;
for ( j= 0; j < afi->afiMetricCount; acm++, j++ )
{
if ( ! strcmp( acm->acmN, glyphNames[i] ) )
{ break; }
}
if ( j >= afi->afiMetricCount )
{ j= psFindAlternate( afi, glyphNames[i] ); }
if ( j < 0 )
{
if ( complain )
{ LSDEB(i,glyphNames[i]); }
codeToGlyph[i]= -1;
rval= 1;
}
else{ codeToGlyph[i]= j; }
}
while( i < 256 )
{ codeToGlyph[i++]= -1; }
return rval;
}
/************************************************************************/
/* */
/* Try to determine what character sets are supported by a particular */
/* PostScript font. */
/* */
/* The positions in the array should match the ENCODINGpsSOMETHING */
/* defines in <utilFontEncoding.h> */
/* */
/************************************************************************/
static int psTryEncoding( SupportedCharset * sc,
const AfmFontInfo * afi,
const FontCharset * fc,
int complain )
{
if ( ! psSetEncoding( sc->scCodeToGlyphMapping, afi,
fc->fcGlyphNames, fc->fcGlyphCount, complain ) )
{ sc->scSupported= 1; return 0; }
sc->scSupported= 0;
if ( complain )
{ SDEB(afi->afiFullName); }
return -1;
}
int psGetFontEncodings( AfmFontInfo * afi )
{
int i;
const FontCharset * fc;
SupportedCharset * sc;
int hasSupportedCharset= 0;
fc= PS_Encodings;
sc= afi->afiSupportedCharsets;
for ( i= 0; i < ENCODINGps_COUNT; sc++, fc++, i++ )
{
const int complain= 0;
if ( ! psTryEncoding( sc, afi, fc, complain ) )
{ hasSupportedCharset= 1; }
}
if ( hasSupportedCharset )
{ return 0; }
fc= PS_Encodings;
sc= afi->afiSupportedCharsets;
for ( i= 0; i < ENCODINGps_COUNT; sc++, fc++, i++ )
{
const int complain= 1;
psTryEncoding( sc, afi, fc, complain );
}
return -1;
}
/************************************************************************/
/* */
/* Calculate the width of a string. */
/* */
/* 1) Assume that space is encoded as space. */
/* 2) Contrary to expectations, kerning is an aplication subject. The */
/* printer by itself does not do kerning. */
/* */
/************************************************************************/
int psCalculateStringExtents( AfmBBox * abb,
const unsigned char * s,
int len,
int twipsSize,
int withKerning,
int encoding,
const AfmFontInfo * afi )
{
long right= 0L;
long unitsWide= 0L;
long top= 0;
long bottom= 0;
long prevRight= 0;
const int * codeToGlyph;
if ( encoding < 0 ||
encoding >= ENCODINGps_COUNT )
{ LLDEB(encoding,ENCODINGps_COUNT); return -1; }
if ( ! afi->afiSupportedCharsets[encoding].scSupported )
{
LLDEB(encoding,afi->afiSupportedCharsets[encoding].scSupported);
return -1;
}
codeToGlyph= afi->afiSupportedCharsets[encoding].scCodeToGlyphMapping;
while( len > 0 )
{
int c= codeToGlyph[*(s++)];
AfmCharMetric * acm;
if ( c < 0 )
{
c= codeToGlyph[' '];
if ( c < 0 )
{ LDEB(c); return -1; }
}
acm= afi->afiMetrics+ c;
if ( top < acm->acmBBox.abbTop )
{ top= acm->acmBBox.abbTop; }
if ( bottom < acm->acmBBox.abbBottom )
{ bottom= acm->acmBBox.abbBottom; }
prevRight= unitsWide;
unitsWide += acm->acmWX;
/* 2 */
if ( withKerning && len > 1 )
{
int cc= codeToGlyph[*s];
if ( c >= 0 )
{
int j;
AfmKerningPair * akp= acm->acmKernPairs;
for ( j= 0; j < acm->acmKernPairCount; akp++, j++ )
{
if ( akp->akpPosition == cc )
{ unitsWide += akp->akpXVec; break; }
}
}
}
if ( c != ' ' )
{ right= prevRight+ acm->acmBBox.abbRight; }
len--;
}
abb->abbLeft= 0;
abb->abbTop= ( twipsSize* top+ 500 )/1000;
abb->abbBottom= ( twipsSize* bottom+ 500 )/1000;
abb->abbRight= ( twipsSize* right+ 500 )/1000;
return ( twipsSize* unitsWide+ 500 )/1000;
}
/************************************************************************/
/* */
/* Initialise a font family struct. */
/* */
/************************************************************************/
void docInitFontFamily( AppFontFamily * aff )
{
aff->affFontFamilyName= (char *)0;
aff->affFontFamilyText= (char *)0;
aff->affFaces= (AppFontTypeface *)0;
aff->affFaceCount= 0;
aff->affHasFixedWidth= 0;
aff->affHasProportionalWidth= 0;
aff->affDefaultEncoding= -1;
return;
}
void docInitFontTypeface( AppFontTypeface * aft )
{
aft->aftFaceName= (char *)0;
aft->aftSizes= (int *)0;
aft->aftSizeCount= 0;
aft->aftIsBold= 0;
aft->aftIsSlanted= 0;
aft->aftIsScalable= 0;
aft->aftIsFixedWidth= 0;
aft->aftPrintingData= (void *)0;
aft->aftXQueryFormat= (char *)0;
aft->aftWidth= FONTwidthMEDIUM;
aft->aftWeight= FONTweightMEDIUM;
aft->aftDefaultEncoding= -1;
return;
}
|