1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstools/gdi_tools/fontcomp/FSC.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,334 @@
1.4 +// Copyright (c) 1997-2009 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 "FONTCOMP.H"
1.20 +
1.21 +FscRead::FscRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf):
1.22 + FontRead(aFile,aFontCompiler,aFxf)
1.23 + {}
1.24 +
1.25 +int FscRead::DoCom(int aSecondPass)
1.26 +/*
1.27 +Takes a command and takes appropriate action
1.28 +Returns -ve if an error occured
1.29 + 0 for OKAY
1.30 + +ve number for new current character number
1.31 +*/
1.32 + {
1.33 + int ret=0,num=0,neg=0;
1.34 + int i=0;
1.35 + for (;i<iInputBufLen;i++)
1.36 + {
1.37 + char chr=iInputBuf[i];
1.38 + if (num==0 && chr=='-')
1.39 + neg=1;
1.40 + else if (chr>='0' && chr<='9')
1.41 + num=num*10+chr-'0';
1.42 + }
1.43 + if (neg)
1.44 + num= -num;
1.45 + if (iInputBuf[1]=='c')
1.46 + return(num);
1.47 + if (aSecondPass)
1.48 + ret=0;
1.49 + else switch(iInputBuf[1])
1.50 + {
1.51 + case 'd':
1.52 + iFxf->descent=num;
1.53 + break;
1.54 + case 'a':
1.55 + iFxf->nominal_ascent=num;
1.56 + break;
1.57 + case 'm':
1.58 + iFxf->max_info_width=num;
1.59 + break;
1.60 + case 'h':
1.61 + if ((iFxf->cell_height=num)>MAX_HEIGHT)
1.62 + ret=Parameter;
1.63 + if (iFxf->nominal_ascent==0)
1.64 + iFxf->nominal_ascent=iFxf->cell_height-iFxf->descent;
1.65 + break;
1.66 + case 'n': /* Font data label name */
1.67 + {
1.68 + int pos=0;
1.69 + while(iInputBuf[pos]!=' ')
1.70 + pos++;
1.71 + while(iInputBuf[pos]==' ')
1.72 + pos++;
1.73 + if(iInputBufLen-pos>FONT_NAME_LEN)
1.74 + return(FileFormat);
1.75 + memcpy(iFxf->name,&iInputBuf[pos],iInputBufLen-pos);
1.76 + (iFxf->name)[iInputBufLen-pos]=0;
1.77 + }
1.78 + break;
1.79 + case 't': /* Font data typeface */
1.80 + {
1.81 + int pos=0;
1.82 + while(iInputBuf[pos]!=' ')
1.83 + pos++;
1.84 + while(iInputBuf[pos]==' ')
1.85 + pos++;
1.86 + if(iInputBufLen-pos>FONT_NAME_LEN)
1.87 + return(FileFormat);
1.88 + memcpy(iFxf->typeface,&iInputBuf[pos],iInputBufLen-pos);
1.89 + (iFxf->typeface)[iInputBufLen-pos]=0;
1.90 + }
1.91 + break;
1.92 + case 'b':
1.93 + iFxf->iBold=1;
1.94 + break;
1.95 + case 'i':
1.96 + iFxf->iItalic=1;
1.97 + break;
1.98 + case 'f':
1.99 + // not a lot
1.100 + break;
1.101 + case 'v':
1.102 + iFxf->iUid=num;
1.103 + break;
1.104 + case 'o':
1.105 + iOverHang=num;
1.106 + break;
1.107 + case 'u':
1.108 + iUnderHang=num;
1.109 + break;
1.110 + default:
1.111 + ret=FileFormat;
1.112 + break;
1.113 + }
1.114 + return(ret);
1.115 + }
1.116 +
1.117 +char* FscRead::ScanLine(int& aLen)
1.118 +/* Scan the input line for the first '0' or '1' character and return a descriptor pointing to it,
1.119 +returns a zero length descriptor if not found.
1.120 +*/
1.121 + {
1.122 + aLen=0;
1.123 + if((iInputBuf[0]!='0' && iInputBuf[0]!='1') || iInputBufLen==0)
1.124 + return(NULL);
1.125 + while(iInputBuf[aLen]=='0' || iInputBuf[aLen]=='1')
1.126 + aLen++;
1.127 + return(iInputBuf);
1.128 + }
1.129 +
1.130 +
1.131 +int FscRead::ReadLine()
1.132 + {
1.133 + int pos=0;
1.134 + while(iFileBuf[iFileBufPos+pos]!='\n' && iFileBufPos+pos<iFileBufLen)
1.135 + pos++;
1.136 + if(iFileBufPos+pos==iFileBufLen) return(1);
1.137 + memcpy(iInputBuf,&iFileBuf[iFileBufPos],pos);
1.138 + iInputBufLen=pos-1;
1.139 + iFileBufPos+=pos+1;
1.140 + if(iFileBufPos>=iFileBufLen) return(1);
1.141 + return(0);
1.142 + }
1.143 +
1.144 +FontRead::FontRead(fstream& aFile,FontCompiler& aFontCompiler,Fxf* aFxf):
1.145 + iInputFile(aFile),
1.146 + iFontCompiler(&aFontCompiler),
1.147 + iFxf(aFxf)
1.148 + {
1.149 + }
1.150 +
1.151 +int FscRead::ReadFont()
1.152 + {
1.153 + iInputFile.seekg(0,ios::end);
1.154 + iFileBufLen=iInputFile.tellg();
1.155 + iInputFile.seekg(0);
1.156 + iFileBufPos=0;
1.157 + iFileBuf=new char[iFileBufLen];
1.158 + iInputFile.read(iFileBuf,iFileBufLen);
1.159 + int ret=Pass1();
1.160 + if(ret) return(ret);
1.161 + return(Pass2());
1.162 + }
1.163 +
1.164 +int FscRead::Pass1()
1.165 + {
1.166 + int n_row=0; // counts row in character picture
1.167 + int ret=0;
1.168 + int specChr=0;
1.169 + int isCharBody=0;
1.170 + int lastLine=0;
1.171 + int widthofi=0;
1.172 + int widthofM=0;
1.173 +
1.174 + iFxf->MaxChrWidth=0;
1.175 + iFxf->cell_height=0;
1.176 + iFxf->UlinePos=0;
1.177 + iFxf->UlineThickness=0;
1.178 + iFxf->nominal_ascent=0;
1.179 + iFxf->descent=0;
1.180 + iFxf->chr_seg=0;
1.181 + iFxf->FirstChr=0;
1.182 + iFxf->n_chars=0;
1.183 + iFxf->max_info_width=0;
1.184 + iFxf->flags=0;
1.185 + iFxf->special=0;
1.186 + iFxf->ByteWid=0;
1.187 + iFxf->UseWords=0;
1.188 + iFxf->iBold=0;
1.189 + iFxf->iItalic=0;
1.190 + iFxf->iProportional=0;
1.191 + iFxf->iSerif=0;
1.192 + iFxf->iSymbol=0;
1.193 + iFxf->iUid=0;
1.194 +
1.195 + iUnderHang=0;
1.196 + iOverHang=0;
1.197 + iChar=new FcmCharHead[MAX_CHARS];
1.198 + for(int letter=0;letter<MAX_CHARS;letter++)
1.199 + iFxf->chr[letter]=NULL;
1.200 +//**************************************************
1.201 +// First pass. Read header info & character widths *
1.202 +//**************************************************
1.203 + do
1.204 + {
1.205 + int width=0; // width of current character picture
1.206 +
1.207 + lastLine=ReadLine();
1.208 + isCharBody=0;
1.209 + if (iInputBufLen>0 && iInputBuf[0]=='*')
1.210 + {
1.211 + if ((ret=DoCom(0))<0)
1.212 + return(FileFormat);
1.213 + else if (ret)
1.214 + {
1.215 + for(;iFxf->n_chars<ret;iFxf->n_chars++)
1.216 + iFxf->chr[iFxf->n_chars]=NULL;
1.217 + specChr=iFxf->n_chars;
1.218 + }
1.219 + }
1.220 + else
1.221 + {
1.222 + int len=0;
1.223 + char* ptr=ScanLine(len);
1.224 + if (len)
1.225 + {
1.226 + isCharBody=1;
1.227 + if (iFxf->FirstChr<0)
1.228 + iFxf->FirstChr=iFxf->n_chars;
1.229 + if (n_row==0)
1.230 + {
1.231 + for (width=0;width<len && (ptr[width]=='0' || ptr[width]=='1');width++);
1.232 + if (iFxf->n_chars>255)
1.233 + return(FileFormat);
1.234 + iFxf->chr[iFxf->n_chars]=iChar;
1.235 + iFxf->n_chars++;
1.236 + iChar->xOffset= -iUnderHang;
1.237 + iChar->width=width;
1.238 + iChar->ByteWid=((iChar->width+15)>>3)&(~1);
1.239 + iChar->move=width-iUnderHang-iOverHang;
1.240 + if(iFxf->n_chars=='i')
1.241 + widthofi=iChar->move;
1.242 + else if(iFxf->n_chars=='M')
1.243 + widthofM=iChar->move;
1.244 + iUnderHang=0;
1.245 + iOverHang=0;
1.246 + if (width>iFxf->MaxChrWidth)
1.247 + iFxf->MaxChrWidth=width;
1.248 + }
1.249 + n_row++;
1.250 + }
1.251 + }
1.252 + if ((n_row!=0 && !isCharBody) || (lastLine && isCharBody))
1.253 + {
1.254 + if (n_row>iFxf->cell_height)
1.255 + return(FileFormat);
1.256 + iChar->height=n_row;
1.257 + iChar->yOffset=iFxf->cell_height-iFxf->descent;
1.258 + specChr++;
1.259 + n_row=0;
1.260 + width=0;
1.261 + iChar++;
1.262 + }
1.263 + } while(!lastLine);
1.264 + if (iFxf->cell_height==0)
1.265 + return(FileFormat);
1.266 + if(widthofi && widthofM)
1.267 + iFxf->iProportional=(widthofi!=widthofM);
1.268 + return(NoError);
1.269 + }
1.270 +
1.271 +int FscRead::Pass2()
1.272 +/******************************************************/
1.273 +/* Second pass. Read in actual picture data this time */
1.274 +/******************************************************/
1.275 + {
1.276 + unsigned int bit; // Used to set bits in pic
1.277 + int ret,chNum;
1.278 + int n_row; // counts row in character picture
1.279 + int offset=0;
1.280 + int isCharBody;
1.281 + int lastLine;
1.282 +
1.283 + iFileBufPos=0;
1.284 + n_row=0;
1.285 + chNum=0;
1.286 + do {
1.287 + lastLine=ReadLine();
1.288 + isCharBody=0;
1.289 + if (iInputBufLen>0 && iInputBuf[0]=='*')
1.290 + {
1.291 + if ((ret=DoCom(1))>0)
1.292 + {
1.293 + if (ret<chNum)
1.294 + return(FileFormat);
1.295 + chNum=ret;
1.296 + }
1.297 + }
1.298 + else
1.299 + {
1.300 + int len=0;
1.301 + char* ptr=ScanLine(len);
1.302 + if (len)
1.303 + {
1.304 + isCharBody=1;
1.305 + if (n_row==0)
1.306 + {
1.307 + iChar=iFxf->chr[chNum];
1.308 + chNum++;
1.309 + }
1.310 + unsigned short int* pDest=(unsigned short int*)(iFontCompiler->FontStore()+offset+iChar->ByteWid*n_row);
1.311 + bit=1;
1.312 + *pDest=0;
1.313 + for (int width=0;width<len && (ptr[width]=='0' || ptr[width]=='1');width++)
1.314 + {
1.315 + if (ptr[width]=='1')
1.316 + *pDest|=bit;
1.317 + if (bit==0x8000)
1.318 + {
1.319 + bit=1;
1.320 + pDest++;
1.321 + *pDest=0;
1.322 + }
1.323 + else
1.324 + bit<<=1;
1.325 + }
1.326 + n_row++;
1.327 + }
1.328 + }
1.329 + if ((n_row!=0 && !isCharBody) || (lastLine && isCharBody))
1.330 + {
1.331 + iChar->offset=offset;
1.332 + offset+=iChar->ByteWid*n_row;
1.333 + n_row=0;
1.334 + }
1.335 + } while(!lastLine);
1.336 + return(NoError);
1.337 + }