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