1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstools/gdi_tools/fontcomp/EFF.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,161 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "FONTCOMP.H"
1.20 +
1.21 +EffRead::EffRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf,short int* aMapSpace):
1.22 + FontRead(aFile,aFontCompiler,aFxf),
1.23 + iMapSpace(aMapSpace)
1.24 + {}
1.25 +
1.26 +int EffRead::ReadFont()
1.27 + {
1.28 + int count=0;
1.29 + int version=0;
1.30 + char* outbuffer[(MAX_CHAR_WID+7)>>3];
1.31 + int bitpos,len1,len2;
1.32 + int ReadSize,widToGo;
1.33 + int widthofi=0;
1.34 + int widthofM=0;
1.35 + FcmCharHead* pFxf;
1.36 + LetterTableData lettertabledata;
1.37 + LetterData letterdata;
1.38 + letterdata.blx = 0;
1.39 + letterdata.bly = 0;
1.40 + letterdata.rWid = 0;
1.41 + letterdata.rHgt = 0;
1.42 + int FileSize,FontNameOffs,VariousDataOffs,LetterOffs,LetterOffsBase,seekpos;
1.43 + unsigned short int* pDest;
1.44 + unsigned short int* pSrc;
1.45 + EffVariousData VariousData;
1.46 +
1.47 + char* inBuffer=new char[((MAX_CHAR_WID+7)>>3)*MAX_HEIGHT];
1.48 + if(!inBuffer) return(NoMemory);
1.49 + iInputFile.read((char*)&FileSize,4);
1.50 + iInputFile.read((char*)&FontNameOffs,4);
1.51 + iInputFile.read((char*)&VariousDataOffs,4);
1.52 + iInputFile.read((char*)&VariousDataOffs,4);
1.53 + iInputFile.read((char*)&LetterOffs,4);
1.54 + iInputFile.seekg(FontNameOffs);
1.55 +
1.56 + char tmpName[FONT_NAME_LEN+1];
1.57 + iInputFile.read(tmpName,FONT_NAME_LEN);
1.58 + tmpName[FONT_NAME_LEN]=0;
1.59 + strcpy(iFxf->name,tmpName);
1.60 + *(iFxf->typeface)=0;
1.61 +
1.62 + iInputFile.seekg(VariousDataOffs);
1.63 + iInputFile.read((char*)&VariousData,sizeof(VariousData));
1.64 + version=VariousData.version;
1.65 + if(version==0) version=1;
1.66 + if(version!=1 && version!=2) return(FileFormat);
1.67 + pFxf=new FcmCharHead[MAX_CHARS];
1.68 + for(count=0;count<sizeof(FcmCharHead)*MAX_CHARS;count++)
1.69 + ((char*)pFxf)[count]=0;
1.70 + int offset=0;
1.71 + int first=1;
1.72 + LetterOffsBase=LetterOffs;
1.73 + iFxf->descent= -VariousData.bly;
1.74 + iFxf->UlinePos= -VariousData.UnderLinePos-VariousData.UnderLineThickness;
1.75 + iFxf->UlineThickness=VariousData.UnderLineThickness;
1.76 + iFxf->nominal_ascent=(VariousData.Hgt/*+VariousData.LineSpacing*/)-iFxf->descent;
1.77 + iFxf->MaxChrWidth=0;
1.78 + iFxf->cell_height=VariousData.Hgt;
1.79 + for(unsigned int chNum=0;chNum<MAX_CHARS;chNum++)
1.80 + {
1.81 + if(iMapSpace)
1.82 + iInputFile.seekg((*(iMapSpace+chNum)<<2)+LetterOffsBase);
1.83 + else
1.84 + iInputFile.seekg(LetterOffs);
1.85 + iInputFile.read((char*)&lettertabledata,sizeof(LetterTableData));
1.86 + if(version==1)
1.87 + {
1.88 + lettertabledata.width>>=4;
1.89 + iInputFile.read((char*)&letterdata,sizeof(LetterData));
1.90 + LetterOffs+=sizeof(LetterData);
1.91 + }
1.92 + LetterOffs+=sizeof(LetterTableData);
1.93 + iFxf->chr[chNum]=0;
1.94 +// char 0 in EFF fonts have a garbage offset so ignore them.
1.95 +// if(letterdata.offset)
1.96 + if(lettertabledata.offset && chNum>0)
1.97 + {
1.98 + seekpos=LetterOffsBase+lettertabledata.offset;
1.99 + iInputFile.seekg(seekpos);
1.100 + if(version==2)
1.101 + iInputFile.read((char*)&letterdata,sizeof(LetterData));
1.102 + if(first)
1.103 + {
1.104 + iFxf->FirstChr=chNum;
1.105 + first=0;
1.106 + }
1.107 + iFxf->n_chars=chNum+1;
1.108 + iFxf->chr[chNum]=pFxf;
1.109 + pFxf->offset=offset;
1.110 + pFxf->xOffset=letterdata.blx;
1.111 + pFxf->yOffset=letterdata.rHgt+letterdata.bly;
1.112 + pFxf->width=letterdata.rWid;
1.113 + if(chNum=='i')
1.114 + widthofi=pFxf->width;
1.115 + if(chNum=='M')
1.116 + widthofM=pFxf->width;
1.117 + pFxf->ByteWid=((pFxf->width+15)>>3)&(~1);
1.118 + pFxf->height=letterdata.rHgt;
1.119 + pFxf->move=lettertabledata.width;
1.120 + int chWid=letterdata.rWid;
1.121 + if(chWid>iFxf->MaxChrWidth)
1.122 + iFxf->MaxChrWidth=chWid;
1.123 + ReadSize=(letterdata.rWid*letterdata.rHgt+7)>>3;
1.124 + iInputFile.read(inBuffer,ReadSize);
1.125 + bitpos=0;
1.126 + pSrc=(unsigned short int*)inBuffer;
1.127 + for(int i=0;i<letterdata.rHgt;i++)
1.128 + {
1.129 + pDest=(unsigned short int*)outbuffer;
1.130 + for(int j=0;j<pFxf->ByteWid;j+=2)
1.131 + {
1.132 + len1=16-bitpos;
1.133 + *pDest=(unsigned short int)((*pSrc)>>bitpos);
1.134 + widToGo=letterdata.rWid-(j<<3);
1.135 + if (len1>widToGo)
1.136 + {
1.137 + len1=widToGo;
1.138 + len2=0;
1.139 + }
1.140 + else
1.141 + {
1.142 + pSrc++;
1.143 + if ((len1+bitpos)>widToGo)
1.144 + len2=widToGo-len1;
1.145 + else
1.146 + len2=bitpos;
1.147 + if (len2)
1.148 + *pDest|= (*pSrc)<<(16-bitpos);
1.149 + }
1.150 + *pDest&=0xFFFF>>(16-len2-len1);
1.151 + bitpos=(bitpos+len1+len2)&0xF;
1.152 + pDest++;
1.153 + }
1.154 + memcpy(iFontCompiler->FontStore()+offset+pFxf->ByteWid*(letterdata.rHgt-i-1),outbuffer,pFxf->ByteWid);
1.155 + }
1.156 + offset+=pFxf->ByteWid*letterdata.rHgt;
1.157 + }
1.158 + pFxf++;
1.159 + }
1.160 + if(widthofi && widthofM)
1.161 + iFxf->iProportional=(widthofi!=widthofM);
1.162 + return(NoError);
1.163 + }
1.164 +