手机电子书UMD数据格式实现代码(C#版)
原文地址:http://blog.joycode.com/uestc95/archive/2008/06/19/115155.aspxUMD格式是国内手机阅读中使用较多的一种格式,但其公司却并没有将UMD数据格式公开,但是却用另外一种方式将其公开,你去访问一下他们的站点然后下载他的制作工具就知道。
下面的是文本的UMD相关处理代码,图形的下一篇post出来
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->namespaceIkari
{
usingICSharpCode.SharpZipLib.Zip.Compression;
usingSystem;
usingSystem.Collections;
usingSystem.IO;
usingSystem.Reflection;
usingSystem.Runtime.InteropServices;
usingSystem.Text;
usingSystem.Windows.Forms;
publicclassUMD_GENEGINE
{
privateconstintA_32K_BYTE=0x8000;
privatebyteACTUAL_WIDTH_S60_HORI=0xcc;
privatebyteACTUAL_WIDTH_S60_VERT=0xac;
privatebyteACTUAL_WIDTH_SP=0xa6;
privateconstuintBASE_REFN_CHAP_OFF=0x3000;
privateconstuintBASE_REFN_CHAP_STR=0x4000;
privateconstuintBASE_REFN_CONTENT=0x2000;
privateconstuintBASE_REFN_COVER=0x1000;
privateconstuintBASE_REFN_PAGE_OFFSET=0x7000;
privateconststringBEYOND_END_FLAG="\0";
privateconstintBYTE_LEN=1;
privateconstbyteCOVER_TYPE_BMP=0;
privateconstbyteCOVER_TYPE_GIF=2;
privateconstbyteCOVER_TYPE_JPG=1;
privateconstintCURR_VERSION=1;
privateconstshortDCTS_CMD_ID_AUTHOR=3;
privateconstshortDCTS_CMD_ID_CDS_KEY=240;
privateconstshortDCTS_CMD_ID_CHAP_OFF=0x83;
privateconstshortDCTS_CMD_ID_CHAP_STR=0x84;
privateconstshortDCTS_CMD_ID_CONTENT_ID=10;
privateconstshortDCTS_CMD_ID_COVER_PAGE=130;
privateconstshortDCTS_CMD_ID_DAY=6;
privateconstshortDCTS_CMD_ID_FILE_LENGTH=11;
privateconstshortDCTS_CMD_ID_FIXED_LEN=12;
privateconstshortDCTS_CMD_ID_GENDER=7;
privateconstshortDCTS_CMD_ID_LICENSE_KEY=0xf1;
privateconstshortDCTS_CMD_ID_MONTH=5;
privateconstshortDCTS_CMD_ID_PAGE_OFFSET=0x87;
privateconstshortDCTS_CMD_ID_PUBLISHER=8;
privateconstshortDCTS_CMD_ID_REF_CONTENT=0x81;
privateconstshortDCTS_CMD_ID_TITLE=2;
privateconstshortDCTS_CMD_ID_VENDOR=9;
privateconstshortDCTS_CMD_ID_VERSION=1;
privateconstshortDCTS_CMD_ID_YEAR=4;
privateconstbyteFIXED_LINE_PER_PAGE_S60=50;
privateconstbyteFIXED_LINE_PER_PAGE_SP=0x19;
privatestringiAuthor;
privatebyte[]ibContent;
privateint[]iChapOff;
privateArrayListiChapStr=newArrayList();
privateArrayListiChapter=newArrayList();
privateintiCID;
privatestringiContent;
privatestringiCoverFile;
privatestringiDay;
privatestringiGender;
privatestringiMonth;
privateconstintINT_LEN=4;
privateshortiPGKSeed=0;
privatestringiPublisher;
privatestringiSaveTo;
privatestringiTitle;
privateintiTotalen;
privatestringiVendor;
privateArrayListiWidthData_S60=newArrayList();
privateArrayListiWidthData_SP=newArrayList();
privatestringiYear;
privatebyte[][]iZippedSeg;
privateconststringKEY_CODE_TAB="\t";
privateconstbyteS60_FONT_SIZE_BIG=0x10;
privateconstbyteS60_FONT_SIZE_SMALL=12;
privateconstbyteSEREIS60_FONTS_COUNT=2;
privateconstintSHORT_LEN=2;
privateconstbyteSP_FONT_SIZE_10=10;
privateconstbyteSP_FONT_SIZE_MAX=0x10;
privateconstbyteSP_FONT_SIZE_MIN=6;
privateconststringSYMBIAN_RETURN="\u2029";
privateconststringSYMBIAN_SPACE="";
privateconstbyteUMD_DCTD_HEAD_LEN=9;
privateconstbyteUMD_DCTS_HEAD_LEN=5;
privateconstintUMD_FREE_CID_MIN=0x5f5e100;
privateconstintUMD_FREE_PGK_SEED_MIN=0x400;
privateconstintUMD_LICENSEKEY_LEN=0x10;
privateconstintUMD_MAX_BOOKMARK_STR_LEN=40;
privateconstbyteUMD_PLATFORM_ID_NONE=0;
privateconstbyteUMD_PLATFORM_ID_S60=1;
privateconstbyteUMD_PLATFORM_ID_SP=5;
privateconstintUMD_SEGMENT_LENGTH=0x8000;
privateconstbyteVER_PKG_LEN=3;
privateconststringWINDOWS_RETURN="\r\n";
privateconstintZIP_LEVEL=9;
privatebyteCharWidth_S60(stringChar,bytepFontSize)
{
ushortnum=Char[0];
for(inti=0;i<this.iWidthData_S60.Count;i++)
{
SWidthDatadata=(SWidthData)this.iWidthData_S60;
if(((data.FontSize==pFontSize)&&(num>=data.rngFrom))&&(num<=data.rngTo))
{
if(data.vCount==1)
{
returndata.Value[0];
}
returndata.Value-data.rngFrom];
}
}
returnpFontSize;
}
privatebyteCharWidth_SP(stringChar,bytepFontSize)
{
ushortnum=Char[0];
for(inti=0;i<this.iWidthData_SP.Count;i++)
{
SWidthDatadata=(SWidthData)this.iWidthData_SP;
if(((data.FontSize==pFontSize)&&(num>=data.rngFrom))&&(num<=data.rngTo))
{
if(data.vCount==1)
{
returndata.Value[0];
}
returndata.Value-data.rngFrom];
}
}
returnpFontSize;
}
privateboolGetPageOffsetS60(bytesize,uintactual_width,refProgressBarpbar,outuint[]result)
{
ArrayListpPageoff=newArrayList();
if((size!=0x10)&&(size!=12))
{
result=newuint[0];
returnfalse;
}
this.GetWidthData_S60();
pPageoff.Add(0);
intnum=pbar.Value;
while(((int)pPageoff-1])<this.iContent.Length)
{
this.ParseOnePage((uint)(pPageoff.Count-1),size,actual_width,refpPageoff,1);
pbar.Value=num+((int)((uint)pPageoff-1]));
}
result=newuint;
for(inti=0;i<pPageoff.Count;i++)
{
result=((uint)pPageoff)*2;
}
returntrue;
}
privateboolGetPageOffsetSP(bytesize,uintactual_width,refProgressBarpbar,outuint[]result)
{
ArrayListpPageoff=newArrayList();
if((size<6)||(size>0x10))
{
result=newuint[0];
returnfalse;
}
this.GetWidthData_SP();
pPageoff.Add(0);
intnum=pbar.Value;
while(((uint)pPageoff-1])<this.iContent.Length)
{
this.ParseOnePage((uint)(pPageoff.Count-1),size,actual_width,refpPageoff,5);
if((num+((int)((uint)pPageoff-1])))<pbar.Maximum)
{
pbar.Value=num+((int)((uint)pPageoff-1]));
}
}
result=newuint;
for(inti=0;i<pPageoff.Count;i++)
{
result=(uint)pPageoff;
}
returntrue;
}
privatevoidGetWidthData_S60()
{
this.iWidthData_S60.Clear();
for(inti=0;i<2;i++)
{
stringpath="";
switch(i)
{
case0:
path=Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Remove(0,8))+@"\FontWidthData\S60CHS.S16.wdt";
break;
case1:
path=Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Remove(0,8))+@"\FontWidthData\S60CHS.S12.wdt";
break;
}
if(File.Exists(path))
{
FileStreaminput=newFileStream(path,FileMode.Open,FileAccess.Read);
BinaryReaderreader=newBinaryReader(input);
while(reader.BaseStream.Position<reader.BaseStream.Length)
{
ushortnum2=reader.ReadUInt16();
ushortnum3=reader.ReadUInt16();
uintnum4=reader.ReadUInt16();
byte[]buffer=newbyte;
for(uintj=0;j<num4;j++)
{
buffer=reader.ReadByte();
}
SWidthDatadata=newSWidthData();
switch(i)
{
case0:
data.FontSize=0x10;
break;
case1:
data.FontSize=12;
break;
}
data.rngFrom=num2;
data.rngTo=num3;
data.vCount=num4;
data.Value=buffer;
this.iWidthData_S60.Add(data);
}
reader.Close();
input.Close();
}
}
}
privatevoidGetWidthData_SP()
{
this.iWidthData_SP.Clear();
for(inti=0x10;i<0x11;i++)
{
stringpath=(Assembly.GetExecutingAssembly().CodeBase.Remove(0,8)+@"\FontWidthData\sunfon.s")+i.ToString()+".wdt";
if(File.Exists(path))
{
FileStreaminput=newFileStream(path,FileMode.Open,FileAccess.Read);
BinaryReaderreader=newBinaryReader(input);
while(reader.BaseStream.Position<reader.BaseStream.Length)
{
ushortnum2=reader.ReadUInt16();
ushortnum3=reader.ReadUInt16();
uintnum4=reader.ReadUInt16();
byte[]buffer=newbyte;
for(uintj=0;j<num4;j++)
{
buffer=reader.ReadByte();
}
SWidthDatadata=newSWidthData();
data.FontSize=(byte)i;
data.rngFrom=num2;
data.rngTo=num3;
data.vCount=num4;
data.Value=buffer;
<span style="color: rgb(0, 0, 255);">this<
页:
[1]