|
1 /* |
|
2 * Copyright (c) 1997-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "FONTCOMP.H" |
|
20 |
|
21 EffRead::EffRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf,short int* aMapSpace): |
|
22 FontRead(aFile,aFontCompiler,aFxf), |
|
23 iMapSpace(aMapSpace) |
|
24 {} |
|
25 |
|
26 int EffRead::ReadFont() |
|
27 { |
|
28 int count=0; |
|
29 int version=0; |
|
30 char* outbuffer[(MAX_CHAR_WID+7)>>3]; |
|
31 int bitpos,len1,len2; |
|
32 int ReadSize,widToGo; |
|
33 int widthofi=0; |
|
34 int widthofM=0; |
|
35 FcmCharHead* pFxf; |
|
36 LetterTableData lettertabledata; |
|
37 LetterData letterdata; |
|
38 letterdata.blx = 0; |
|
39 letterdata.bly = 0; |
|
40 letterdata.rWid = 0; |
|
41 letterdata.rHgt = 0; |
|
42 int FileSize,FontNameOffs,VariousDataOffs,LetterOffs,LetterOffsBase,seekpos; |
|
43 unsigned short int* pDest; |
|
44 unsigned short int* pSrc; |
|
45 EffVariousData VariousData; |
|
46 |
|
47 char* inBuffer=new char[((MAX_CHAR_WID+7)>>3)*MAX_HEIGHT]; |
|
48 if(!inBuffer) return(NoMemory); |
|
49 iInputFile.read((char*)&FileSize,4); |
|
50 iInputFile.read((char*)&FontNameOffs,4); |
|
51 iInputFile.read((char*)&VariousDataOffs,4); |
|
52 iInputFile.read((char*)&VariousDataOffs,4); |
|
53 iInputFile.read((char*)&LetterOffs,4); |
|
54 iInputFile.seekg(FontNameOffs); |
|
55 |
|
56 char tmpName[FONT_NAME_LEN+1]; |
|
57 iInputFile.read(tmpName,FONT_NAME_LEN); |
|
58 tmpName[FONT_NAME_LEN]=0; |
|
59 strcpy(iFxf->name,tmpName); |
|
60 *(iFxf->typeface)=0; |
|
61 |
|
62 iInputFile.seekg(VariousDataOffs); |
|
63 iInputFile.read((char*)&VariousData,sizeof(VariousData)); |
|
64 version=VariousData.version; |
|
65 if(version==0) version=1; |
|
66 if(version!=1 && version!=2) return(FileFormat); |
|
67 pFxf=new FcmCharHead[MAX_CHARS]; |
|
68 for(count=0;count<sizeof(FcmCharHead)*MAX_CHARS;count++) |
|
69 ((char*)pFxf)[count]=0; |
|
70 int offset=0; |
|
71 int first=1; |
|
72 LetterOffsBase=LetterOffs; |
|
73 iFxf->descent= -VariousData.bly; |
|
74 iFxf->UlinePos= -VariousData.UnderLinePos-VariousData.UnderLineThickness; |
|
75 iFxf->UlineThickness=VariousData.UnderLineThickness; |
|
76 iFxf->nominal_ascent=(VariousData.Hgt/*+VariousData.LineSpacing*/)-iFxf->descent; |
|
77 iFxf->MaxChrWidth=0; |
|
78 iFxf->cell_height=VariousData.Hgt; |
|
79 for(unsigned int chNum=0;chNum<MAX_CHARS;chNum++) |
|
80 { |
|
81 if(iMapSpace) |
|
82 iInputFile.seekg((*(iMapSpace+chNum)<<2)+LetterOffsBase); |
|
83 else |
|
84 iInputFile.seekg(LetterOffs); |
|
85 iInputFile.read((char*)&lettertabledata,sizeof(LetterTableData)); |
|
86 if(version==1) |
|
87 { |
|
88 lettertabledata.width>>=4; |
|
89 iInputFile.read((char*)&letterdata,sizeof(LetterData)); |
|
90 LetterOffs+=sizeof(LetterData); |
|
91 } |
|
92 LetterOffs+=sizeof(LetterTableData); |
|
93 iFxf->chr[chNum]=0; |
|
94 // char 0 in EFF fonts have a garbage offset so ignore them. |
|
95 // if(letterdata.offset) |
|
96 if(lettertabledata.offset && chNum>0) |
|
97 { |
|
98 seekpos=LetterOffsBase+lettertabledata.offset; |
|
99 iInputFile.seekg(seekpos); |
|
100 if(version==2) |
|
101 iInputFile.read((char*)&letterdata,sizeof(LetterData)); |
|
102 if(first) |
|
103 { |
|
104 iFxf->FirstChr=chNum; |
|
105 first=0; |
|
106 } |
|
107 iFxf->n_chars=chNum+1; |
|
108 iFxf->chr[chNum]=pFxf; |
|
109 pFxf->offset=offset; |
|
110 pFxf->xOffset=letterdata.blx; |
|
111 pFxf->yOffset=letterdata.rHgt+letterdata.bly; |
|
112 pFxf->width=letterdata.rWid; |
|
113 if(chNum=='i') |
|
114 widthofi=pFxf->width; |
|
115 if(chNum=='M') |
|
116 widthofM=pFxf->width; |
|
117 pFxf->ByteWid=((pFxf->width+15)>>3)&(~1); |
|
118 pFxf->height=letterdata.rHgt; |
|
119 pFxf->move=lettertabledata.width; |
|
120 int chWid=letterdata.rWid; |
|
121 if(chWid>iFxf->MaxChrWidth) |
|
122 iFxf->MaxChrWidth=chWid; |
|
123 ReadSize=(letterdata.rWid*letterdata.rHgt+7)>>3; |
|
124 iInputFile.read(inBuffer,ReadSize); |
|
125 bitpos=0; |
|
126 pSrc=(unsigned short int*)inBuffer; |
|
127 for(int i=0;i<letterdata.rHgt;i++) |
|
128 { |
|
129 pDest=(unsigned short int*)outbuffer; |
|
130 for(int j=0;j<pFxf->ByteWid;j+=2) |
|
131 { |
|
132 len1=16-bitpos; |
|
133 *pDest=(unsigned short int)((*pSrc)>>bitpos); |
|
134 widToGo=letterdata.rWid-(j<<3); |
|
135 if (len1>widToGo) |
|
136 { |
|
137 len1=widToGo; |
|
138 len2=0; |
|
139 } |
|
140 else |
|
141 { |
|
142 pSrc++; |
|
143 if ((len1+bitpos)>widToGo) |
|
144 len2=widToGo-len1; |
|
145 else |
|
146 len2=bitpos; |
|
147 if (len2) |
|
148 *pDest|= (*pSrc)<<(16-bitpos); |
|
149 } |
|
150 *pDest&=0xFFFF>>(16-len2-len1); |
|
151 bitpos=(bitpos+len1+len2)&0xF; |
|
152 pDest++; |
|
153 } |
|
154 memcpy(iFontCompiler->FontStore()+offset+pFxf->ByteWid*(letterdata.rHgt-i-1),outbuffer,pFxf->ByteWid); |
|
155 } |
|
156 offset+=pFxf->ByteWid*letterdata.rHgt; |
|
157 } |
|
158 pFxf++; |
|
159 } |
|
160 if(widthofi && widthofM) |
|
161 iFxf->iProportional=(widthofi!=widthofM); |
|
162 return(NoError); |
|
163 } |
|
164 |