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 |
FontCompiler::FontCompiler():
|
sl@0
|
19 |
iInputFile(),
|
sl@0
|
20 |
iOutputFile(),
|
sl@0
|
21 |
iFxf(NULL),
|
sl@0
|
22 |
iFontSpace(NULL),
|
sl@0
|
23 |
iWorkSpace(NULL),
|
sl@0
|
24 |
iMapSpace(NULL),
|
sl@0
|
25 |
iWorkSpaceSize(0),
|
sl@0
|
26 |
iHeaderDataLen(0),
|
sl@0
|
27 |
iHeaderData()
|
sl@0
|
28 |
{}
|
sl@0
|
29 |
|
sl@0
|
30 |
int FontCompiler::Init(char* infile,char* outfile,char* mapfile)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
if(mapfile)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
iMapSpace=new short int[256];
|
sl@0
|
35 |
if(!iMapSpace) return(NoMemory);
|
sl@0
|
36 |
|
sl@0
|
37 |
#ifdef __MSVCDOTNET__
|
sl@0
|
38 |
fstream tempfile(mapfile, ios::in | ios::binary);
|
sl@0
|
39 |
#else //!__MSVCDOTNET__
|
sl@0
|
40 |
fstream tempfile(mapfile, ios::in | ios::binary | ios::nocreate);
|
sl@0
|
41 |
#endif //__MSVCDOTNET__
|
sl@0
|
42 |
|
sl@0
|
43 |
if(!tempfile.is_open())
|
sl@0
|
44 |
return(NoFile);
|
sl@0
|
45 |
tempfile.read((char*)iMapSpace,512);
|
sl@0
|
46 |
tempfile.close();
|
sl@0
|
47 |
}
|
sl@0
|
48 |
iOutputFile.open(outfile, ios::out);
|
sl@0
|
49 |
|
sl@0
|
50 |
#ifdef __MSVCDOTNET__
|
sl@0
|
51 |
iInputFile.open(infile, ios::in | ios::binary);
|
sl@0
|
52 |
#else //!__MSVCDOTNET__
|
sl@0
|
53 |
iInputFile.open(infile, ios::in | ios::binary | ios::nocreate);
|
sl@0
|
54 |
#endif //__MSVCDOTNET__
|
sl@0
|
55 |
|
sl@0
|
56 |
if(!(iOutputFile.is_open() && iInputFile.is_open()))
|
sl@0
|
57 |
return(NoFile);
|
sl@0
|
58 |
iFxf=new Fxf;
|
sl@0
|
59 |
if(!iFxf) return(NoMemory);
|
sl@0
|
60 |
iFxf->iBold=0;
|
sl@0
|
61 |
iFxf->iItalic=0;
|
sl@0
|
62 |
iFxf->iProportional=0;
|
sl@0
|
63 |
iFxf->iSerif=0;
|
sl@0
|
64 |
iFxf->iSymbol=0;
|
sl@0
|
65 |
iFxf->iUid=0;
|
sl@0
|
66 |
iFontSpace=new char[0x100000];
|
sl@0
|
67 |
if(!iFontSpace) return(NoMemory);
|
sl@0
|
68 |
return(NoError);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
char* FontCompiler::FontStore() const
|
sl@0
|
72 |
{
|
sl@0
|
73 |
return(iFontSpace);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
int FontCompiler::Read(FontType aInputType)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
FontRead *read=NULL;
|
sl@0
|
79 |
switch(aInputType)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
case EFontTypeFsc:
|
sl@0
|
82 |
read=new FscRead(iInputFile,*this,iFxf);
|
sl@0
|
83 |
break;
|
sl@0
|
84 |
case EFontTypeEff:
|
sl@0
|
85 |
read=new EffRead(iInputFile,*this,iFxf,iMapSpace);
|
sl@0
|
86 |
break;
|
sl@0
|
87 |
default:
|
sl@0
|
88 |
return(Parameter);
|
sl@0
|
89 |
}
|
sl@0
|
90 |
if(!read)
|
sl@0
|
91 |
return(NoMemory);
|
sl@0
|
92 |
int error=read->ReadFont();
|
sl@0
|
93 |
delete read;
|
sl@0
|
94 |
return(error);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
void FontCompiler::RemoveBlankSpace()
|
sl@0
|
98 |
{
|
sl@0
|
99 |
int count=0;
|
sl@0
|
100 |
const int maxbytewidth=(MAX_CHAR_WID+15)>>3;
|
sl@0
|
101 |
unsigned char buf[maxbytewidth];
|
sl@0
|
102 |
unsigned char zbuf[maxbytewidth];
|
sl@0
|
103 |
|
sl@0
|
104 |
for(count=0;count<maxbytewidth;count++)
|
sl@0
|
105 |
zbuf[count]=0;
|
sl@0
|
106 |
for(int chNum=iFxf->FirstChr;chNum<iFxf->n_chars;chNum++)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
FcmCharHead *fChar=iFxf->chr[chNum];
|
sl@0
|
109 |
if(fChar)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
int LastNonBlank=0;
|
sl@0
|
112 |
int TopCount=0;
|
sl@0
|
113 |
int MinLeftBlank=fChar->width;
|
sl@0
|
114 |
int MinRightBlank=0;
|
sl@0
|
115 |
|
sl@0
|
116 |
// DEF102183: Graphics tools fail to build using MS VC8.
|
sl@0
|
117 |
int row;
|
sl@0
|
118 |
int x;
|
sl@0
|
119 |
for(row=0;row<fChar->height;)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
memcpy(buf,iFontSpace+fChar->offset+fChar->ByteWid*row,fChar->ByteWid);
|
sl@0
|
122 |
unsigned char bit=1;
|
sl@0
|
123 |
unsigned char* pb=buf;
|
sl@0
|
124 |
for(x=0;x<MinLeftBlank;x++)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
if ((*pb)&bit)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
MinLeftBlank=x;
|
sl@0
|
129 |
break;
|
sl@0
|
130 |
}
|
sl@0
|
131 |
bit<<=1;
|
sl@0
|
132 |
if (bit==0)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
bit=1;
|
sl@0
|
135 |
pb++;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
}
|
sl@0
|
138 |
bit=(unsigned char)(1<<((fChar->width-1)%8));
|
sl@0
|
139 |
pb=&buf[((fChar->width-1)>>3)];
|
sl@0
|
140 |
for(x=fChar->width;x>MinRightBlank;x--)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
if ((*pb)&bit)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
MinRightBlank=x;
|
sl@0
|
145 |
break;
|
sl@0
|
146 |
}
|
sl@0
|
147 |
bit>>=1;
|
sl@0
|
148 |
if (bit==0)
|
sl@0
|
149 |
{
|
sl@0
|
150 |
bit=unsigned char(0x80);
|
sl@0
|
151 |
pb--;
|
sl@0
|
152 |
}
|
sl@0
|
153 |
}
|
sl@0
|
154 |
row++;
|
sl@0
|
155 |
if(memcmp(zbuf,buf,fChar->ByteWid))
|
sl@0
|
156 |
{
|
sl@0
|
157 |
if (TopCount==0)
|
sl@0
|
158 |
TopCount=row; /* Count of blank rows at the top */
|
sl@0
|
159 |
LastNonBlank=row;
|
sl@0
|
160 |
}
|
sl@0
|
161 |
}
|
sl@0
|
162 |
if (TopCount==0)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
fChar->height=0;
|
sl@0
|
165 |
fChar->width=0;
|
sl@0
|
166 |
fChar->xOffset=0;
|
sl@0
|
167 |
fChar->yOffset=0;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
else
|
sl@0
|
170 |
{
|
sl@0
|
171 |
TopCount--;
|
sl@0
|
172 |
fChar->height=LastNonBlank-TopCount;
|
sl@0
|
173 |
fChar->width=MinRightBlank-MinLeftBlank;
|
sl@0
|
174 |
fChar->yOffset-=TopCount;
|
sl@0
|
175 |
fChar->offset+=TopCount*fChar->ByteWid;
|
sl@0
|
176 |
fChar->xOffset+=MinLeftBlank;
|
sl@0
|
177 |
if (MinLeftBlank)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
int byte_step=MinLeftBlank/8;
|
sl@0
|
180 |
int bit_shift=MinLeftBlank%8;
|
sl@0
|
181 |
unsigned char mask=(unsigned char)(0xFF>>(7-((fChar->width-1)%8)));
|
sl@0
|
182 |
for(row=0;row<fChar->height;row++)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
memcpy(buf,iFontSpace+fChar->offset+fChar->ByteWid*row,fChar->ByteWid);
|
sl@0
|
185 |
for(x=0;x<(fChar->ByteWid-byte_step);x++)
|
sl@0
|
186 |
buf[x]=(unsigned char)((buf[x+byte_step]>>bit_shift)+
|
sl@0
|
187 |
(buf[x+byte_step+1]<<(8-bit_shift)));
|
sl@0
|
188 |
buf[x-1]&=mask;
|
sl@0
|
189 |
memcpy(iFontSpace+fChar->offset+fChar->ByteWid*row,buf,fChar->ByteWid);
|
sl@0
|
190 |
}
|
sl@0
|
191 |
}
|
sl@0
|
192 |
}
|
sl@0
|
193 |
}
|
sl@0
|
194 |
}
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|