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