|
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 "GDSFCOMP.H" |
|
17 #include "toolsver.h" |
|
18 |
|
19 int GdsFontCompiler::WriteFont() |
|
20 { |
|
21 int index=0; |
|
22 index=WriteHeader(); |
|
23 if(index<0) return(index); |
|
24 for(int ch=index;ch<iFxf->n_chars;ch++) |
|
25 WriteCharData(ch); |
|
26 WriteFooter(); |
|
27 return(NoError); |
|
28 } |
|
29 |
|
30 int GdsFontCompiler::WriteHeader() |
|
31 { |
|
32 int mncw=0; |
|
33 for(char letter='A';letter<='Z';letter++) |
|
34 { |
|
35 FcmCharHead* fChar=iFxf->chr[letter]; |
|
36 if(fChar) |
|
37 { |
|
38 int letterwidth=fChar->move; |
|
39 if(letterwidth>mncw) |
|
40 mncw=letterwidth; |
|
41 } |
|
42 } |
|
43 WriteFormattedData("FontBitmap "); |
|
44 WriteFormattedData(iFxf->name,1); |
|
45 WriteFormattedData("Uid "); |
|
46 WriteFormattedData(iFxf->iUid); |
|
47 if(iFxf->iBold) |
|
48 WriteFormattedData(" Bold"); |
|
49 if(iFxf->iItalic) |
|
50 WriteFormattedData(" Italic"); |
|
51 if(iFxf->iProportional) |
|
52 WriteFormattedData(" Proportional"); |
|
53 if(iFxf->iSerif) |
|
54 WriteFormattedData(" Serif"); |
|
55 if(iFxf->iSymbol) |
|
56 WriteFormattedData(" Symbol"); |
|
57 WriteNewLine(); |
|
58 WriteFormattedData("MaxNormalCharWidth "); |
|
59 WriteFormattedData(mncw,1); |
|
60 WriteFormattedData("CellHeight "); |
|
61 WriteFormattedData(iFxf->cell_height,1); |
|
62 WriteFormattedData("Ascent "); |
|
63 WriteFormattedData(iFxf->nominal_ascent,1); |
|
64 // WriteFormattedData("Uline "); |
|
65 // WriteFormattedData(iFxf->UlinePos,0); |
|
66 // WriteFormattedData(" "); |
|
67 // WriteFormattedData(iFxf->UlineThickness,1); |
|
68 int index=0; |
|
69 while(!iFxf->chr[index]) |
|
70 index++; |
|
71 if(index>=iFxf->n_chars) |
|
72 return(FileFormat); |
|
73 WriteFormattedData("CodeSection "); |
|
74 WriteFormattedData(index,0); |
|
75 WriteFormattedData(":"); |
|
76 WriteFormattedData(iFxf->n_chars-1,1); |
|
77 return(index); |
|
78 } |
|
79 |
|
80 void GdsFontCompiler::WriteFooter() |
|
81 { |
|
82 WriteFormattedData("EndCodeSection",1); |
|
83 WriteFormattedData("EndFontBitmap",1); |
|
84 WriteNewLine(); |
|
85 } |
|
86 |
|
87 void GdsFontCompiler::WriteCharData(int charnum) |
|
88 { |
|
89 unsigned short int* pSrc; |
|
90 unsigned short int bit; |
|
91 char buf[10+MAX_CHAR_WID]; |
|
92 unsigned short int srcBuf[(MAX_CHAR_WID+15)>>4]; |
|
93 |
|
94 const FcmCharHead* fChar=iFxf->chr[charnum]; |
|
95 WriteNewLine(); |
|
96 WriteFormattedData("Char "); |
|
97 WriteFormattedData(charnum); |
|
98 if(fChar==NULL) |
|
99 { |
|
100 WriteNewLine(); |
|
101 WriteFormattedData("EndChar",1); |
|
102 return; |
|
103 } |
|
104 WriteFormattedData(" Adjust "); |
|
105 |
|
106 int bitwid=fChar->move+(fChar->xOffset<0?-fChar->xOffset:0); |
|
107 const int ohang=fChar->move-fChar->xOffset-fChar->width; |
|
108 WriteFormattedData(fChar->xOffset); |
|
109 WriteFormattedData(" "); |
|
110 WriteFormattedData(ohang); |
|
111 bitwid+=ohang; |
|
112 if (charnum>31) |
|
113 { |
|
114 WriteFormattedData(" ! '"); |
|
115 WriteFormattedData((char*)&charnum); |
|
116 WriteFormattedData("'"); |
|
117 } |
|
118 WriteNewLine(); |
|
119 if (fChar->width!=0) |
|
120 { |
|
121 WriteBlankLines(iFxf->cell_height-iFxf->descent-fChar->yOffset,fChar->width); |
|
122 for(int y=0;y<fChar->height;y++) |
|
123 { |
|
124 memcpy(srcBuf,iFontSpace+fChar->offset+y*fChar->ByteWid,fChar->ByteWid); |
|
125 pSrc=&srcBuf[0]; |
|
126 bit=1; |
|
127 int pb=0; |
|
128 for(int i=0;i<fChar->width;i++) |
|
129 { |
|
130 buf[pb++]=((*pSrc)&bit)?SetPixel:BlankPixel; |
|
131 bit<<=1; |
|
132 if(!bit) |
|
133 { |
|
134 bit=1; |
|
135 pSrc++; |
|
136 } |
|
137 } |
|
138 buf[pb]=0; |
|
139 WriteFormattedData(buf,1); |
|
140 } |
|
141 WriteBlankLines(iFxf->descent+fChar->yOffset-fChar->height,fChar->width); |
|
142 } |
|
143 WriteFormattedData("EndChar",1); |
|
144 } |
|
145 |
|
146 void GdsFontCompiler::WriteBlankLines(int num,int width) |
|
147 { |
|
148 char buf[2+MAX_CHAR_WID+20]; |
|
149 memset(&buf[0],BlankPixel,width); |
|
150 buf[width] ='\0'; |
|
151 for(int i=0;i<num;i++) |
|
152 WriteFormattedData(buf,1); |
|
153 } |
|
154 |
|
155 void GdsFontCompiler::WriteFormattedData(char* aData,int aNewLine) |
|
156 { |
|
157 if(aData) |
|
158 iOutputFile << aData; |
|
159 if(aNewLine) |
|
160 WriteNewLine(); |
|
161 } |
|
162 |
|
163 void GdsFontCompiler::WriteFormattedData(int aNum,int aNewLine) |
|
164 { |
|
165 char numbuf[16]; |
|
166 _itoa(aNum,numbuf,10); |
|
167 WriteFormattedData(numbuf,aNewLine); |
|
168 } |
|
169 |
|
170 void GdsFontCompiler::WriteNewLine() |
|
171 { |
|
172 iOutputFile << "\n"; |
|
173 } |
|
174 |
|
175 int main(int argc,char *argv[]) |
|
176 { |
|
177 if(argc<3 || argc>5) |
|
178 { |
|
179 cout << "\n"; |
|
180 cout << "FONTCOMP Version 0.01(" << version << ")\n"; |
|
181 cout << "\n"; |
|
182 cout << "USAGE: FONTCOMP srcfile destfile [/e [mapfile]|/f]\n"; |
|
183 cout << "Where srcfile is the file to be processed,\n"; |
|
184 cout << "destfile is the file to be created,\n"; |
|
185 cout << "/e specifies EFF format (default) and /f\n"; |
|
186 cout << "specifies FSC format. If the format is EFF then\n"; |
|
187 cout << "the optional mapfile may be used for altenative\n"; |
|
188 cout << "character sets.\n\n"; |
|
189 return(0); |
|
190 } |
|
191 FontType type=EFontTypeEff; |
|
192 if(argc==4) |
|
193 if(argv[3][1]=='f' || argv[3][1]=='F') |
|
194 type=EFontTypeFsc; |
|
195 char* mapfile=NULL; |
|
196 if(argc==5) mapfile=argv[4]; |
|
197 GdsFontCompiler fontcomp; |
|
198 int ret=fontcomp.Init(argv[1],argv[2],mapfile); |
|
199 if(ret==NoError) |
|
200 ret=fontcomp.Read(type); |
|
201 if(ret==NoError) |
|
202 fontcomp.RemoveBlankSpace(); |
|
203 if(ret==NoError) |
|
204 ret=fontcomp.WriteFont(); |
|
205 switch(ret) |
|
206 { |
|
207 case NoError: |
|
208 cout << "Success\n\n"; |
|
209 break; |
|
210 case NoMemory: |
|
211 cout << "Out of memory\n\n"; |
|
212 break; |
|
213 case NoFile: |
|
214 cout << "File does not exist\n\n"; |
|
215 break; |
|
216 case FileRead: |
|
217 cout << "File read error\n\n"; |
|
218 break; |
|
219 case FileWrite: |
|
220 cout << "File write error\n\n"; |
|
221 break; |
|
222 case FileFormat: |
|
223 cout << "File has wrong format\n\n"; |
|
224 break; |
|
225 case Parameter: |
|
226 cout << "Bad parameter\n\n"; |
|
227 break; |
|
228 } |
|
229 return(ret); |
|
230 } |
|
231 |