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