int i_t1_has_chars(i_t1_font_t font, const char *text, size_t len, int utf8, char *out) { int count = 0; int font_num = font->font_id; i_mutex_lock(mutex); mm_log((1, "i_t1_has_chars(font_num %d, text %p, len %u, utf8 %d)\n", font_num, text, (unsigned)len, utf8)); i_clear_error(); if (T1_LoadFont(font_num)) { t1_push_error(); i_mutex_unlock(mutex); return 0; } while (len) { unsigned long c; if (utf8) { c = i_utf8_advance(&text, &len); if (c == ~0UL) { i_push_error(0, "invalid UTF8 character"); i_mutex_unlock(mutex); return 0; } } else { c = (unsigned char)*text++; --len; } if (c >= 0x100) { /* limit of 256 characters for T1 */ *out++ = 0; } else { char const * name = T1_GetCharName(font_num, (unsigned char)c); if (name) { *out++ = strcmp(name, ".notdef") != 0; } else { mm_log((2, " No name found for character %lx\n", c)); *out++ = 0; } } ++count; } i_mutex_unlock(mutex); return count; }
int i_t1_glyph_name(i_t1_font_t font, unsigned long ch, char *name_buf, size_t name_buf_size) { char *name; int font_num = font->font_id; i_clear_error(); if (ch > 0xFF) { return 0; } i_mutex_lock(mutex); if (T1_LoadFont(font_num)) { t1_push_error(); i_mutex_unlock(mutex); return 0; } name = T1_GetCharName(font_num, (unsigned char)ch); if (name) { if (strcmp(name, ".notdef")) { size_t len = strlen(name); strncpy(name_buf, name, name_buf_size); name_buf[name_buf_size-1] = '\0'; i_mutex_unlock(mutex); return len + 1; } else { i_mutex_unlock(mutex); return 0; } } else { t1_push_error(); i_mutex_unlock(mutex); return 0; } }
int T1_LoadFont( int FontID) { int i, j, k, l, m; char *FileName, *FileNamePath; int mode; /* This is used by the type1-library for error reporting */ char *charname; /* The following vars are used for reallocation of VM */ long tmp_size; float ascender; #ifdef ANSI_REALLOC_VM unsigned long shift; unsigned long ldummy; char *tmp_ptr; #endif struct region *area; struct XYspace *S; /* These are for constructing the kerning lookup table: */ PairKernData *pkd; METRICS_ENTRY *kern_tbl; int char1, char2; if (CheckForInit()) { T1_errno=T1ERR_OP_NOT_PERMITTED; return(-1); } i=CheckForFontID(FontID); if (i==1) return(0); /* Font already loaded */ if (i==-1) { T1_errno=T1ERR_INVALID_FONTID; return(-1); /* illegal FontID */ } /* Allocate memory for ps_font structure: */ if ((pFontBase->pFontArray[FontID].pType1Data=(psfont *)malloc(sizeof(psfont)))==NULL) { T1_PrintLog( "T1_LoadFont()", "Failed to allocate memory for psfont-struct (FontID=%d)", T1LOG_ERROR, FontID); T1_errno=T1ERR_ALLOC_MEM; return(-1); } /* Check for valid filename */ if ((FileName=T1_GetFontFileName(FontID))==NULL) { T1_PrintLog( "T1_LoadFont()", "No font file name for font %d", T1LOG_ERROR, FontID); return(-1); } /* Fetch the full path of type1 font file */ if ((FileNamePath=intT1_Env_GetCompletePath( FileName, T1_PFAB_ptr))==NULL) { T1_PrintLog( "T1_LoadFont()", "Couldn't locate font file for font %d in %s", T1LOG_ERROR, FontID, T1_GetFileSearchPath(T1_PFAB_PATH)); T1_errno=T1ERR_FILE_OPEN_ERR; return(-1); } /* And load all PostScript information into memory */ if (fontfcnA( FileNamePath, &mode, pFontBase->pFontArray[FontID].pType1Data) == FALSE) { T1_PrintLog( "T1_LoadFont()", "Loading font with ID = %d failed! (mode = %d)", T1LOG_ERROR, FontID, mode); free(FileNamePath); pFontBase->pFontArray[FontID].pType1Data=NULL; T1_errno=mode; return(-1); } free(FileNamePath); /* Store the base address of virtual memory and realloc in order not to waste too much memory: */ pFontBase->pFontArray[FontID].vm_base=vm_base; #ifdef ANSI_REALLOC_VM /* We first get the size of pointers on the current system */ /* Get size of VM, ... */ tmp_size=((unsigned long)vm_used - (unsigned long)vm_base); /* ... realloc to that size ... */ tmp_ptr=(char *)realloc(vm_base, tmp_size); /* ... and shift all pointers refering to that area */ if (tmp_ptr > vm_base) { shift= (unsigned long)tmp_ptr - (unsigned long)vm_base; sprintf( err_warn_msg_buf, "Old VM at 0x%lX, new VM at 0x%lX, shifting up by %lu", (unsigned long)vm_base, (unsigned long)tmp_ptr, tmp_size); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); /* We start by shifting the topmost pointers: */ pFontBase->pFontArray[FontID].vm_base=tmp_ptr; ldummy=(long)(pFontBase->pFontArray[FontID].pType1Data->vm_start); ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->vm_start=(char *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->CharStringsP=(psdict *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->Private=(psdict *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP=(psdict *)ldummy; ldummy=(long)(pFontBase->pFontArray[FontID].pType1Data->BluesP); ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->BluesP=(struct blues_struct *)ldummy; /* We now have to care for correcting all pointers which are in the VM and refer to some place in the VM! Note: Instead of selecting the appropriate pointer-elements of the union we simply shift the unspecified pointer "valueP". Note: The filename entry does not need to be modified since it does not need to be shifted since it points to memory managed by t1lib. */ /* FontInfo-dictionary: All name-pointers and the pointers to all array types have to be shifted: */ i=pFontBase->pFontArray[FontID].pType1Data->fontInfoP[0].key.len; for (j=1; j<=i; j++) { if ((pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_ARRAY) || (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_STRING) || (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_NAME) || (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_FILE)) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP=(char *)ldummy; } /* The encoding needs special treatment: */ if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_ENCODING) { /* If a builtin encoding is used, it is sufficient to shift the pointer to the Encoding since the character-namestrings of builtin encodings are static and thus located on the heap. For font-specific encoding, character-namestrings reside in VM and thus each entry has to be shifted. Caution: We still have to shift the builtin encoding-pointer, since they also point to are located in VM: */ ldummy=(long)StdEncArrayP; ldummy +=shift; StdEncArrayP=(psobj *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP=(char *)ldummy; if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.arrayP == StdEncArrayP) { /* Font uses builtin standard encoding */ ; } else { /* Font-specific encoding */ for (k=0; k<256; k++) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.arrayP[k].data.arrayP; /* The ".notdef" is also static and may not be shifted (Thanks, Derek ;) */ if (ldummy != (unsigned long)not_def) { ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.arrayP[k].data.arrayP=(struct ps_obj *)ldummy; } } } } /* end of encoding-handling */ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].key.data.valueP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].key.data.valueP=(char *)ldummy; } /* fontinfo-dict done */ /* Private-dictionary: All name-pointers and the pointers to all array types have to be shifted: */ i=pFontBase->pFontArray[FontID].pType1Data->Private[0].key.len; for (j=1; j<=i; j++) { if ((pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_ARRAY) || (pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_STRING) || (pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_NAME) || (pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_FILE)) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private[j].value.data.valueP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->Private[j].value.data.valueP=(char *)ldummy; } ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private[j].key.data.valueP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->Private[j].key.data.valueP=(char *)ldummy; } /* BluesP: The entry "next" is the only pointer in blues_struct. Although it is not used anywhere we should shift it for correctness reasons (in case its not NULL)! */ if (pFontBase->pFontArray[FontID].pType1Data->BluesP->next != NULL) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->BluesP->next; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->BluesP->next=(struct blues_struct *)ldummy; } /* The CharStrings-dictionary: Every namepointer and its corresponding charstring has to be shifted: */ i=pFontBase->pFontArray[FontID].pType1Data->CharStringsP[0].key.len; for (j=1; j<=i; j++) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].value.data.valueP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].value.data.valueP=(char *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].key.data.valueP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].key.data.valueP=(char *)ldummy; } /* The Subroutines have also to be reorganized: */ i=pFontBase->pFontArray[FontID].pType1Data->Subrs.len; /* First, shift pointer to array-start and after that the pointers to each command string: */ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP=(struct ps_obj *)ldummy; for (j=0; j<i; j++) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP[j].data.valueP; ldummy +=shift; pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP[j].data.valueP=(char *)ldummy; } } /* end of if( tmp_ptr > vm_base ) */ else if ( vm_base > tmp_ptr) { shift= (unsigned long)vm_base - (unsigned long)tmp_ptr; sprintf( err_warn_msg_buf, "Old VM at 0x%lX, new VM at 0x%lX, shifting down by %lu", (unsigned long)vm_base, (unsigned long)tmp_ptr, tmp_size); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); /* We start by shifting the topmost pointers: */ pFontBase->pFontArray[FontID].vm_base=tmp_ptr; ldummy=(long)(pFontBase->pFontArray[FontID].pType1Data->vm_start); ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->vm_start=(char *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->CharStringsP=(psdict *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->Private=(psdict *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP=(psdict *)ldummy; ldummy=(long)(pFontBase->pFontArray[FontID].pType1Data->BluesP); ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->BluesP=(struct blues_struct *)ldummy; /* We now have to care for correcting all pointers which are in the VM and refer to some place in the VM! Note: Instead of selecting the appropriate pointer-elements of the union we simply shift the unspecified pointer "valueP". Note: The filename entry does not need to be modified since it does not need to be shifted since it points to memory managed by t1lib. */ /* FontInfo-dictionary: All name-pointers and the pointers to all array types have to be shifted: */ i=pFontBase->pFontArray[FontID].pType1Data->fontInfoP[0].key.len; for (j=1; j<=i; j++) { if ((pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_ARRAY) || (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_STRING) || (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_NAME) || (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_FILE)) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP=(char *)ldummy; } /* The encoding needs special treatment: */ if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.type==OBJ_ENCODING) { /* If a builtin encoding is used, it is sufficient to shift the pointer to the Encoding since the character-namestrings of builtin encodings are static and thus located on the heap. For font-specific encoding, character-namestrings reside in VM and thus each entry has to be shifted. Caution: We still have to shift the builtin encoding-pointer, since they also point to are located in VM: */ ldummy=(long)StdEncArrayP; ldummy -=shift; StdEncArrayP=(psobj *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.valueP=(char *)ldummy; if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.arrayP == StdEncArrayP) { /* Font uses builtin encoding */ ; } else { /* Font-specific encoding */ for (k=0; k<256; k++) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.arrayP[k].data.arrayP; /* The ".notdef" is also static and may not be shifted (Thanks, Derek ;) */ if (ldummy != (unsigned long)not_def) { ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].value.data.arrayP[k].data.arrayP=(struct ps_obj *)ldummy; } } } } /* end of encoding-handling */ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].key.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->fontInfoP[j].key.data.valueP=(char *)ldummy; } /* fontinfo-dict done */ /* Private-dictionary: All name-pointers and the pointers to all array types have to be shifted: */ i=pFontBase->pFontArray[FontID].pType1Data->Private[0].key.len; for (j=1; j<=i; j++) { if ((pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_ARRAY) || (pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_STRING) || (pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_NAME) || (pFontBase->pFontArray[FontID].pType1Data->Private[j].value.type==OBJ_FILE)) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private[j].value.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->Private[j].value.data.valueP=(char *)ldummy; } ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Private[j].key.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->Private[j].key.data.valueP=(char *)ldummy; } /* BluesP: The entry "next" is the only pointer in blues_struct. Although it is not used anywhere we should shift it for correctness reasons (in case its not NULL)! */ if (pFontBase->pFontArray[FontID].pType1Data->BluesP->next != NULL) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->BluesP->next; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->BluesP->next=(struct blues_struct *)ldummy; } /* The CharStrings-dictionary: Every namepointer and its corresponding charstring has to be shifted: */ i=pFontBase->pFontArray[FontID].pType1Data->CharStringsP[0].key.len; for (j=1; j<=i; j++) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].value.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].value.data.valueP=(char *)ldummy; ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].key.data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->CharStringsP[j].key.data.valueP=(char *)ldummy; } /* The Subroutines have also to be reorganized: */ i=pFontBase->pFontArray[FontID].pType1Data->Subrs.len; /* First, shift pointer to array-start and after that the pointers to each command string: */ ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP=(struct ps_obj *)ldummy; for (j=0; j<i; j++) { ldummy=(long)pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP[j].data.valueP; ldummy -=shift; pFontBase->pFontArray[FontID].pType1Data->Subrs.data.arrayP[j].data.valueP=(char *)ldummy; } } /* end of if( vm_base > tmp_ptr ) */ else { /* VM addess has not changed during reallocation */ sprintf( err_warn_msg_buf, "Old VM and new VM at 0x%lX, no pointer-shifting", (unsigned long)vm_base); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); } #endif /* Generate a message how much VM the current font consumes */ sprintf( err_warn_msg_buf, "VM for Font %d: %d bytes", FontID, (int) tmp_size); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_STATISTIC); /* Set the matrix for common transformations to "no transformations" */ pFontBase->pFontArray[FontID].FontTransform[0]=1.0; pFontBase->pFontArray[FontID].FontTransform[1]=0.0; pFontBase->pFontArray[FontID].FontTransform[2]=0.0; pFontBase->pFontArray[FontID].FontTransform[3]=1.0; /* Now, that the font has been loaded into memory, try to find the FontMatrix in the font info dictionary. If it exists, load it into our local fontmatrix, otherwise use a default matrix which scales to 1/1000 (since font outlines are defined in a 1000 point space) and does no further transformations. */ if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP == NULL) { pFontBase->pFontArray[FontID].FontMatrix[0]=0.001; pFontBase->pFontArray[FontID].FontMatrix[1]=0.0; pFontBase->pFontArray[FontID].FontMatrix[2]=0.0; pFontBase->pFontArray[FontID].FontMatrix[3]=0.001; } else { pFontBase->pFontArray[FontID].FontMatrix[0]= (double)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP[0].data.real; pFontBase->pFontArray[FontID].FontMatrix[1]= (double)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP[1].data.real; pFontBase->pFontArray[FontID].FontMatrix[2]= (double)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP[2].data.real; pFontBase->pFontArray[FontID].FontMatrix[3]= (double)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[FONTMATRIX].value.data.arrayP[3].data.real; } /* Set the default values for transformation: */ pFontBase->pFontArray[FontID].slant=0.0; pFontBase->pFontArray[FontID].extend=1.0; /* Now try to load afm-structures from corresponding .afm-file (if not suppressed by the user). */ if ((pFontBase->t1lib_flags & T1_NO_AFM)!=0) { pFontBase->pFontArray[FontID].pAFMData = NULL; T1_PrintLog( "T1_LoadFont()", "Suppressing AFM data handling on user request", T1LOG_STATISTIC); } else { if ((i=openFontMetricsFile( FontID, 0))) { /* Try a fallback, opening sloppy: */ if ((i=openFontMetricsFile( FontID, 1))) { sprintf( err_warn_msg_buf, "Alert: Error (%d) sloppy-processing afm-file for Font %d!", i ,FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_STATISTIC); if ((pFontBase->pFontArray[FontID].pAFMData= T1_GenerateAFMFallbackInfo(FontID))==NULL) { sprintf( err_warn_msg_buf, "Ultimately failed to generate metrics information Font %d!", FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_WARNING); } else { pFontBase->pFontArray[FontID].info_flags |=AFM_SELFGEN_SUCCESS; T1_PrintLog( "T1_LoadFont()", "Generating AFM-information from fontfile successful!", T1LOG_STATISTIC); } } else { pFontBase->pFontArray[FontID].info_flags |=AFM_SLOPPY_SUCCESS; sprintf( err_warn_msg_buf, "Alert: Limited afm-information for Font %d",FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_STATISTIC); } } else { pFontBase->pFontArray[FontID].info_flags |=AFM_SUCCESS; } } /* Now, set Encodingvector entry to default if the font's internal encoding is "StandardEncoding". */ if (pFontBase->pFontArray[FontID].pType1Data->fontInfoP[ENCODING].value.data.arrayP == StdEncArrayP) { pFontBase->pFontArray[FontID].info_flags |=USES_STANDARD_ENCODING; pFontBase->pFontArray[FontID].pFontEnc=pFontBase->default_enc; sprintf( err_warn_msg_buf, "Font %d reencoded to default",FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); } else { sprintf( err_warn_msg_buf, "Font %d not reencoded to default",FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); pFontBase->pFontArray[FontID].pFontEnc = NULL; } /* If AFM-Info available we try to speed up some things: */ if (pFontBase->pFontArray[FontID].pAFMData != NULL) { /* We have to fill the array that maps the current encodings' indices to the indices used in afm file. The interpretation has been changed in in t1lib-1.2. We now use positive values for indexing into the charmetrics array and negative values for indexing into the composite character array. an index of zero indicates that no metrics are defined for this character. This may happen because (a) not all AFM-files define metrics for the .notdef character, and (b) because font and AFM-file do not match. */ if ((pFontBase->pFontArray[FontID].pEncMap= (int *)calloc(256,sizeof(int)))==NULL) { sprintf( err_warn_msg_buf, "Error allocating memory for encoding map (FontID=%d)", FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_WARNING); T1_errno=T1ERR_ALLOC_MEM; return(-1); } for (i=0; i<256; i++) { charname=T1_GetCharName( FontID, i); /* in a first loop check for ordinary characters */ for ( j=0; j<pFontBase->pFontArray[FontID].pAFMData->numOfChars; j++) { if (strcmp( charname, pFontBase->pFontArray[FontID].pAFMData->cmi[j].name)==0) { pFontBase->pFontArray[FontID].pEncMap[i]=j+1; /* index 0 is reserved! */ continue; } } /* if nothing has been found, check for composite characters */ for ( j=0; j<pFontBase->pFontArray[FontID].pAFMData->numOfComps; j++) { if (strcmp( charname, pFontBase->pFontArray[FontID].pAFMData->ccd[j].ccName)==0) { pFontBase->pFontArray[FontID].pEncMap[i]=-(j+1); /* index 0 is reserved! */ continue; } } } /* For composite characters, we still have to compute the width and bbox */ for ( j=0; j<pFontBase->pFontArray[FontID].pAFMData->numOfComps; j++) { /*and bounding box by ourselves. First, set up an identity charspace matrix and then generate an edgelist for the composite character at size 1000bp using no transformation and current encoding. Note: This action is only required when loading a font at first time, but not when reencoding a font. */ S=(struct XYspace *)IDENTITY; S=(struct XYspace *)Permanent (Transform(S, pFontBase->pFontArray[FontID].FontTransform[0], pFontBase->pFontArray[FontID].FontTransform[1], pFontBase->pFontArray[FontID].FontTransform[2], pFontBase->pFontArray[FontID].FontTransform[3])); area=fontfcnB_ByName( FontID, 0, S, pFontBase->pFontArray[FontID].pAFMData->ccd[j].ccName, &mode, pFontBase->pFontArray[FontID].pType1Data, DO_RASTER); /* Store bounding box ... */ pFontBase->pFontArray[FontID].pAFMData->ccd[j].charBBox.llx=area->xmin; pFontBase->pFontArray[FontID].pAFMData->ccd[j].charBBox.urx=area->xmax; pFontBase->pFontArray[FontID].pAFMData->ccd[j].charBBox.lly=area->ymin; pFontBase->pFontArray[FontID].pAFMData->ccd[j].charBBox.ury=area->ymax; /* ... and character width. This should be the width of the base character of the composite! */ pFontBase->pFontArray[FontID].pAFMData->ccd[j].wx=NEARESTPEL(area->ending.x); /* clean up. */ KillRegion (area); if (S!=NULL) { KillSpace (S); S=NULL; } } /* We now create an encoding-specific kerning table which will speed up looking for kerning pairs! */ /* First, get number of defined kerning pairs: */ k=pFontBase->pFontArray[FontID].pAFMData->numOfPairs; if (k>0) { /* i.e., there are any pairs */ /* OK, it does not suffice to alloc numOfPairs METRICS_ENTRYs, because a given character might be encoded at several locations and kerning should still work. As a worst case estimation, we allocate 256^2 and realloc later. */ if ((pFontBase->pFontArray[FontID].pKernMap= (METRICS_ENTRY *)malloc( (256*256) *sizeof( METRICS_ENTRY)))==NULL) { sprintf( err_warn_msg_buf, "Error allocating memory for metrics map (FontID=%d)", FontID); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_WARNING); T1_errno=T1ERR_ALLOC_MEM; return(-1); } kern_tbl=pFontBase->pFontArray[FontID].pKernMap; pkd=pFontBase->pFontArray[FontID].pAFMData->pkd; j=0; for ( i=0; i<k; i++) { /* We do not check T1_GetEncodingIndices() against the return value NULL because we just loading the font in question: */ l=0; while ((char1=(T1_GetEncodingIndices( FontID, pkd[i].name1))[l++])!=-1) { /* pair could be relevant in current encoding */ m=0; while ((char2=(T1_GetEncodingIndices( FontID, pkd[i].name2))[m++])!=-1) { /* Since we get here we have a relevant pair --> Put char1 in higher byte and char2 in LSB: */ kern_tbl[j].chars=(char1 << 8) | char2; /* We only make use of horizontal kerning */ kern_tbl[j].hkern=pkd[i].xamt; j++; } /* while (char2) */ } /* while (char1) */ } /* for */ /* We are done, realloc memory: */ kern_tbl=(METRICS_ENTRY*) realloc( kern_tbl, j*sizeof(METRICS_ENTRY)); /* We now sort the kerning array with respect to char indices */ qsort( kern_tbl, (size_t) j, sizeof(METRICS_ENTRY), &cmp_METRICS_ENTRY ); /* Finally write back pointer for the case that realloc changed the pointer */ pFontBase->pFontArray[FontID].pKernMap=kern_tbl; pFontBase->pFontArray[FontID].KernMapSize=j; } else pFontBase->pFontArray[FontID].pKernMap=NULL; } else { /* no AFM data */ pFontBase->pFontArray[FontID].pKernMap=NULL; pFontBase->pFontArray[FontID].pEncMap=NULL; } /* End of "if (AFM-info ..)" */ /* We have just loaded a physical font into memory, thus .... */ pFontBase->pFontArray[FontID].physical=1; /* Set reference-counter to 1: */ pFontBase->pFontArray[FontID].refcount=1; /* Get the index into encoding vector where the space character is found. If not encoded, set space_position to -1. */ pFontBase->pFontArray[FontID].space_position=-1; i=0; if (pFontBase->pFontArray[FontID].pFontEnc) { /* external default encoding */ while (i<256) { if (strcmp( (char *)pFontBase->pFontArray[FontID].pFontEnc[i], "space")==0) { /* space found at position i: */ pFontBase->pFontArray[FontID].space_position=i; break; } i++; } } else { /* internal encoding */ while (i<256) { if (strcmp( (char *)pFontBase->pFontArray[FontID].pType1Data->fontInfoP[ENCODING].value.data.arrayP[i].data.arrayP, "space")==0) { /* space found at position i: */ pFontBase->pFontArray[FontID].space_position=i; break; } i++; } } /* Set the lining rule parameters to default values */ pFontBase->pFontArray[FontID].UndrLnPos= pFontBase->pFontArray[FontID].pType1Data->fontInfoP[UNDERLINEPOSITION].value.data.real; pFontBase->pFontArray[FontID].UndrLnThick= pFontBase->pFontArray[FontID].pType1Data->fontInfoP[UNDERLINETHICKNESS].value.data.real; /* We have to set the value for the typographic ascender. If possible, we get it from the afm-File. But be aware this value might be undefined! This value should in any acse explicitly be set later by the user! */ if (pFontBase->pFontArray[FontID].pAFMData!=NULL && pFontBase->pFontArray[FontID].pAFMData->gfi!=NULL) { ascender=(float) pFontBase->pFontArray[FontID].pAFMData->gfi->ascender; } else { ascender=(float) T1_GetCharBBox( FontID, T1_GetEncodingIndex( FontID, "d")).ury; } pFontBase->pFontArray[FontID].OvrLnPos=ascender + (float) abs( (double)pFontBase->pFontArray[FontID].UndrLnPos); pFontBase->pFontArray[FontID].OvrStrkPos=ascender / 2.0; pFontBase->pFontArray[FontID].OvrLnThick=pFontBase->pFontArray[FontID].UndrLnThick; pFontBase->pFontArray[FontID].OvrStrkThick=pFontBase->pFontArray[FontID].UndrLnThick; /* Finally, set the font size dependencies pointer to NULL since we can assume, that at load time of a font, no size specific data of this font is available. */ pFontBase->pFontArray[FontID].pFontSizeDeps=NULL; /* If wanted, some debugging information is put into logfile */ sprintf( err_warn_msg_buf, "Pointer vm_base: 0x%lX", (long)pFontBase->pFontArray[FontID].vm_base); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); sprintf( err_warn_msg_buf, "Pointer vm_start: 0x%lX", (long)pFontBase->pFontArray[FontID].pType1Data->vm_start); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); sprintf( err_warn_msg_buf, "Pointer CharStringsP: 0x%lX", (long)pFontBase->pFontArray[FontID].pType1Data->CharStringsP); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); sprintf( err_warn_msg_buf, "Pointer Private: 0x%lX", (long)pFontBase->pFontArray[FontID].pType1Data->Private); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); sprintf( err_warn_msg_buf, "Pointer fontInfoP: 0x%lX", (long)pFontBase->pFontArray[FontID].pType1Data->fontInfoP); T1_PrintLog( "T1_LoadFont()", err_warn_msg_buf, T1LOG_DEBUG); return(0); }