using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using Biff8Excel.Interfaces; namespace Biff8Excel.Records { [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] struct RecordFont { public ushort opcode ; public ushort length; public ushort size; public ushort attributes; public ushort colourIndex; public ushort boldWeight; public ushort superSubScript; [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte underline; [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte family; [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte charset; [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte zero ; // must be zero [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte fontNameLen; [MarshalAs(UnmanagedType.U1, SizeConst = 1)]public byte isunicode; // Flag to store as unicode } internal class Font : IRecords { RecordFont font; ushort recLen; byte[] m_fontName; public Font() { font.opcode = 0x31; this.Size = 10; font.boldWeight = 0x190; font.zero = 0x0; this.FontName = "ËÎÌå"; //this.FontName = "Tahoma"; //font.charset = (byte)enumFontCharacterSet.csANSI_Chinese_Simplified; } public ushort ID { get { return font.opcode; } } public ushort RecordSize { get { return recLen; } } public ushort Size { set { font.size = (ushort)(value * 20); } get { if ( font.size > 0) return (ushort)(font.size / 20); return 0; } } public ushort Attributes { set { font.attributes = value; if ((value & 0x1) == 1) font.boldWeight = 0x2BC; } } public ushort ColourIndex { set { font.colourIndex = value; } } public ushort BoldWeight { set { font.boldWeight = value; } } public ushort Escapement { set { font.superSubScript = value; } } public byte Underline { set { font.underline = value; } } public byte Family { set { font.family = value; } } public byte Charset { set { font.charset = value; } } public string FontName { set { font.fontNameLen = (byte)value.Length; //m_fontName = Globals.GetUnicodeBytes(value); if (font.fontNameLen != (byte)Globals.GetDefaultBytesLength(value)) { font.isunicode = 0x1; m_fontName = Globals.GetUnicodeBytes(value); } else { font.isunicode = 0x0; m_fontName = Globals.GetDefaultBytes(value); } } } #region IRecords ³ÉÔ± public byte[] GetByte() { //font.length = (ushort)((font.fontNameLen * 2) + 16); //byte[] b = new byte[(font.fontNameLen * 2) + 20]; font.length = (ushort)(m_fontName.Length + 16); byte[] b = new byte[m_fontName.Length + 20]; Globals.GetStructToBytes(font).CopyTo(b, 0); m_fontName.CopyTo(b, 20); return b; } #endregion } }