1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstools/gdi_tools/fontcomp/GDSFCOMP.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,231 @@
1.4 +// Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "GDSFCOMP.H"
1.20 +#include "TOOLSVER.H"
1.21 +
1.22 +int GdsFontCompiler::WriteFont()
1.23 + {
1.24 + int index=0;
1.25 + index=WriteHeader();
1.26 + if(index<0) return(index);
1.27 + for(int ch=index;ch<iFxf->n_chars;ch++)
1.28 + WriteCharData(ch);
1.29 + WriteFooter();
1.30 + return(NoError);
1.31 + }
1.32 +
1.33 +int GdsFontCompiler::WriteHeader()
1.34 + {
1.35 + int mncw=0;
1.36 + for(char letter='A';letter<='Z';letter++)
1.37 + {
1.38 + FcmCharHead* fChar=iFxf->chr[letter];
1.39 + if(fChar)
1.40 + {
1.41 + int letterwidth=fChar->move;
1.42 + if(letterwidth>mncw)
1.43 + mncw=letterwidth;
1.44 + }
1.45 + }
1.46 + WriteFormattedData("FontBitmap ");
1.47 + WriteFormattedData(iFxf->name,1);
1.48 + WriteFormattedData("Uid ");
1.49 + WriteFormattedData(iFxf->iUid);
1.50 + if(iFxf->iBold)
1.51 + WriteFormattedData(" Bold");
1.52 + if(iFxf->iItalic)
1.53 + WriteFormattedData(" Italic");
1.54 + if(iFxf->iProportional)
1.55 + WriteFormattedData(" Proportional");
1.56 + if(iFxf->iSerif)
1.57 + WriteFormattedData(" Serif");
1.58 + if(iFxf->iSymbol)
1.59 + WriteFormattedData(" Symbol");
1.60 + WriteNewLine();
1.61 + WriteFormattedData("MaxNormalCharWidth ");
1.62 + WriteFormattedData(mncw,1);
1.63 + WriteFormattedData("CellHeight ");
1.64 + WriteFormattedData(iFxf->cell_height,1);
1.65 + WriteFormattedData("Ascent ");
1.66 + WriteFormattedData(iFxf->nominal_ascent,1);
1.67 +// WriteFormattedData("Uline ");
1.68 +// WriteFormattedData(iFxf->UlinePos,0);
1.69 +// WriteFormattedData(" ");
1.70 +// WriteFormattedData(iFxf->UlineThickness,1);
1.71 + int index=0;
1.72 + while(!iFxf->chr[index])
1.73 + index++;
1.74 + if(index>=iFxf->n_chars)
1.75 + return(FileFormat);
1.76 + WriteFormattedData("CodeSection ");
1.77 + WriteFormattedData(index,0);
1.78 + WriteFormattedData(":");
1.79 + WriteFormattedData(iFxf->n_chars-1,1);
1.80 + return(index);
1.81 + }
1.82 +
1.83 +void GdsFontCompiler::WriteFooter()
1.84 + {
1.85 + WriteFormattedData("EndCodeSection",1);
1.86 + WriteFormattedData("EndFontBitmap",1);
1.87 + WriteNewLine();
1.88 + }
1.89 +
1.90 +void GdsFontCompiler::WriteCharData(int charnum)
1.91 + {
1.92 + unsigned short int* pSrc;
1.93 + unsigned short int bit;
1.94 + char buf[10+MAX_CHAR_WID];
1.95 + unsigned short int srcBuf[(MAX_CHAR_WID+15)>>4];
1.96 +
1.97 + const FcmCharHead* fChar=iFxf->chr[charnum];
1.98 + WriteNewLine();
1.99 + WriteFormattedData("Char ");
1.100 + WriteFormattedData(charnum);
1.101 + if(fChar==NULL)
1.102 + {
1.103 + WriteNewLine();
1.104 + WriteFormattedData("EndChar",1);
1.105 + return;
1.106 + }
1.107 + WriteFormattedData(" Adjust ");
1.108 +
1.109 + int bitwid=fChar->move+(fChar->xOffset<0?-fChar->xOffset:0);
1.110 + const int ohang=fChar->move-fChar->xOffset-fChar->width;
1.111 + WriteFormattedData(fChar->xOffset);
1.112 + WriteFormattedData(" ");
1.113 + WriteFormattedData(ohang);
1.114 + bitwid+=ohang;
1.115 + if (charnum>31)
1.116 + {
1.117 + WriteFormattedData(" ! '");
1.118 + WriteFormattedData((char*)&charnum);
1.119 + WriteFormattedData("'");
1.120 + }
1.121 + WriteNewLine();
1.122 + if (fChar->width!=0)
1.123 + {
1.124 + WriteBlankLines(iFxf->cell_height-iFxf->descent-fChar->yOffset,fChar->width);
1.125 + for(int y=0;y<fChar->height;y++)
1.126 + {
1.127 + memcpy(srcBuf,iFontSpace+fChar->offset+y*fChar->ByteWid,fChar->ByteWid);
1.128 + pSrc=&srcBuf[0];
1.129 + bit=1;
1.130 + int pb=0;
1.131 + for(int i=0;i<fChar->width;i++)
1.132 + {
1.133 + buf[pb++]=((*pSrc)&bit)?SetPixel:BlankPixel;
1.134 + bit<<=1;
1.135 + if(!bit)
1.136 + {
1.137 + bit=1;
1.138 + pSrc++;
1.139 + }
1.140 + }
1.141 + buf[pb]=0;
1.142 + WriteFormattedData(buf,1);
1.143 + }
1.144 + WriteBlankLines(iFxf->descent+fChar->yOffset-fChar->height,fChar->width);
1.145 + }
1.146 + WriteFormattedData("EndChar",1);
1.147 + }
1.148 +
1.149 +void GdsFontCompiler::WriteBlankLines(int num,int width)
1.150 + {
1.151 + char buf[2+MAX_CHAR_WID+20];
1.152 + memset(&buf[0],BlankPixel,width);
1.153 + buf[width] ='\0';
1.154 + for(int i=0;i<num;i++)
1.155 + WriteFormattedData(buf,1);
1.156 + }
1.157 +
1.158 +void GdsFontCompiler::WriteFormattedData(char* aData,int aNewLine)
1.159 + {
1.160 + if(aData)
1.161 + iOutputFile << aData;
1.162 + if(aNewLine)
1.163 + WriteNewLine();
1.164 + }
1.165 +
1.166 +void GdsFontCompiler::WriteFormattedData(int aNum,int aNewLine)
1.167 + {
1.168 + char numbuf[16];
1.169 + _itoa(aNum,numbuf,10);
1.170 + WriteFormattedData(numbuf,aNewLine);
1.171 + }
1.172 +
1.173 +void GdsFontCompiler::WriteNewLine()
1.174 + {
1.175 + iOutputFile << "\n";
1.176 + }
1.177 +
1.178 +int main(int argc,char *argv[])
1.179 + {
1.180 + if(argc<3 || argc>5)
1.181 + {
1.182 + cout << "\n";
1.183 + cout << "FONTCOMP Version 0.01(" << version << ")\n";
1.184 + cout << "\n";
1.185 + cout << "USAGE: FONTCOMP srcfile destfile [/e [mapfile]|/f]\n";
1.186 + cout << "Where srcfile is the file to be processed,\n";
1.187 + cout << "destfile is the file to be created,\n";
1.188 + cout << "/e specifies EFF format (default) and /f\n";
1.189 + cout << "specifies FSC format. If the format is EFF then\n";
1.190 + cout << "the optional mapfile may be used for altenative\n";
1.191 + cout << "character sets.\n\n";
1.192 + return(0);
1.193 + }
1.194 + FontType type=EFontTypeEff;
1.195 + if(argc==4)
1.196 + if(argv[3][1]=='f' || argv[3][1]=='F')
1.197 + type=EFontTypeFsc;
1.198 + char* mapfile=NULL;
1.199 + if(argc==5) mapfile=argv[4];
1.200 + GdsFontCompiler fontcomp;
1.201 + int ret=fontcomp.Init(argv[1],argv[2],mapfile);
1.202 + if(ret==NoError)
1.203 + ret=fontcomp.Read(type);
1.204 + if(ret==NoError)
1.205 + fontcomp.RemoveBlankSpace();
1.206 + if(ret==NoError)
1.207 + ret=fontcomp.WriteFont();
1.208 + switch(ret)
1.209 + {
1.210 + case NoError:
1.211 + cout << "Success\n\n";
1.212 + break;
1.213 + case NoMemory:
1.214 + cout << "Out of memory\n\n";
1.215 + break;
1.216 + case NoFile:
1.217 + cout << "File does not exist\n\n";
1.218 + break;
1.219 + case FileRead:
1.220 + cout << "File read error\n\n";
1.221 + break;
1.222 + case FileWrite:
1.223 + cout << "File write error\n\n";
1.224 + break;
1.225 + case FileFormat:
1.226 + cout << "File has wrong format\n\n";
1.227 + break;
1.228 + case Parameter:
1.229 + cout << "Bad parameter\n\n";
1.230 + break;
1.231 + }
1.232 + return(ret);
1.233 + }
1.234 +