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