- // C.) ignore other entries.
- }
- fclose(afmFile);
- }
- // hack to compute correct values for german 'Umlaute'
- // the correct way would be to map the character names
- // like 'adieresis' to corresp. positions of ISOEnc and read
- // these values from AFM files, too. Maybe later ...
- lastWidths[196] = lastWidths['A']; // Ä
- lastWidths[228] = lastWidths['a']; // ä
- lastWidths[214] = lastWidths['O']; // Ö
- lastWidths[246] = lastWidths['o']; // ö
- lastWidths[220] = lastWidths['U']; // Ü
- lastWidths[252] = lastWidths['u']; // ü
- lastWidths[223] = lastWidths[251]; // ß
- }
-
- // JC: calculate UnderlineThickness/UnderlinePosition
- m_underlinePosition = m_underlinePosition * fontToUse->GetPointSize() / 1000.0f;
- m_underlineThickness = m_underlineThickness * fontToUse->GetPointSize() / 1000.0f * m_scaleFactor;
-
- // 3. now the font metrics are read in, calc size *******************
- // this is done by adding the widths of the characters in the
- // string. they are given in 1/1000 of the size!
-
- long widthSum=0;
- long height=Size; // by default
- unsigned char *p;
- for(p=(unsigned char *)(const char *)string; *p; p++){
- if(lastWidths[*p]== INT_MIN){
- wxLogDebug("GetTextExtent: undefined width for character '%c' (%d)\n",
- *p,*p);
- widthSum += (long)(lastWidths[' ']/1000.0F * Size); // assume space
- }else{
- widthSum += (long)((lastWidths[*p]/1000.0F)*Size);
+ else
+ {
+ /* init the widths array */
+ for(int i=0; i<256; i++) lastWidths[i] = INT_MIN;
+ /* some variables for holding parts of a line */
+ char cString[10],semiString[10],WXString[10],descString[20];
+ char upString[30], utString[30], encString[50];
+ char line[256];
+ int ascii,cWidth;
+ /* read in the file and parse it */
+ while(fgets(line,sizeof(line),afmFile)!=NULL)
+ {
+ /* A.) check for descender definition */
+ if (strncmp(line,"Descender",9)==0)
+ {
+ if ((sscanf(line,"%s%d",descString,&lastDescender)!=2) ||
+ (strcmp(descString,"Descender")!=0))
+ {
+ wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad descender)\n"), afmName.c_str(),line );
+ }
+ }
+ /* JC 1.) check for UnderlinePosition */
+ else if(strncmp(line,"UnderlinePosition",17)==0)
+ {
+ if ((sscanf(line,"%s%lf",upString,&UnderlinePosition)!=2) ||
+ (strcmp(upString,"UnderlinePosition")!=0))
+ {
+ wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlinePosition)\n"), afmName.c_str(), line );
+ }
+ }
+ /* JC 2.) check for UnderlineThickness */
+ else if(strncmp(line,"UnderlineThickness",18)==0)
+ {
+ if ((sscanf(line,"%s%lf",utString,&UnderlineThickness)!=2) ||
+ (strcmp(utString,"UnderlineThickness")!=0))
+ {
+ wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad UnderlineThickness)\n"), afmName.c_str(), line );
+ }
+ }
+ /* JC 3.) check for EncodingScheme */
+ else if(strncmp(line,"EncodingScheme",14)==0)
+ {
+ if ((sscanf(line,"%s%s",utString,encString)!=2) ||
+ (strcmp(utString,"EncodingScheme")!=0))
+ {
+ wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (bad EncodingScheme)\n"), afmName.c_str(), line );
+ }
+ else if (strncmp(encString, "AdobeStandardEncoding", 21))
+ {
+ wxLogDebug( wxT("AFM-file '%hs': line '%hs' has error (unsupported EncodingScheme %hs)\n"),
+ afmName.c_str(),line, encString);
+ }
+ }
+ /* B.) check for char-width */
+ else if(strncmp(line,"C ",2)==0)
+ {
+ if (sscanf(line,"%s%d%s%s%d",cString,&ascii,semiString,WXString,&cWidth)!=5)
+ {
+ wxLogDebug(wxT("AFM-file '%hs': line '%hs' has an error (bad character width)\n"),afmName.c_str(),line);
+ }
+ if(strcmp(cString,"C")!=0 || strcmp(semiString,";")!=0 || strcmp(WXString,"WX")!=0)
+ {
+ wxLogDebug(wxT("AFM-file '%hs': line '%hs' has a format error\n"),afmName.c_str(),line);
+ }
+ /* printf(" char '%c'=%d has width '%d'\n",ascii,ascii,cWidth); */
+ if (ascii>=0 && ascii<256)
+ {
+ lastWidths[ascii] = cWidth; /* store width */
+ }
+ else
+ {
+ /* MATTHEW: this happens a lot; don't print an error */
+ /* wxLogDebug("AFM-file '%s': ASCII value %d out of range\n",afmName.c_str(),ascii); */
+ }
+ }
+ /* C.) ignore other entries. */
+ }
+ fclose(afmFile);
+ }
+ /* hack to compute correct values for german 'Umlaute'
+ / the correct way would be to map the character names
+ / like 'adieresis' to corresp. positions of ISOEnc and read
+ / these values from AFM files, too. Maybe later ... */
+ lastWidths[196] = lastWidths['A']; // Ä
+ lastWidths[228] = lastWidths['a']; // ä
+ lastWidths[214] = lastWidths['O']; // Ö
+ lastWidths[246] = lastWidths['o']; // ö
+ lastWidths[220] = lastWidths['U']; // Ü
+ lastWidths[252] = lastWidths['u']; // ü
+ lastWidths[223] = lastWidths[251]; // ß