Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Font Serialization/Deserialization (Read 1362 times)
nikulin_andrey
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 26
Joined: Dec 1st, 2006
Font Serialization/Deserialization
Feb 1st, 2007 at 1:45pm
Print Post  
Hi,

I found that in flowchart output file you have serialized Font.

<InplaceEditFont>
  <Name>Microsoft Sans Serif</Name>
  <Size>8.25</Size>
  <Unit>Point</Unit>
  <Bold>False</Bold>
  <Italic>False</Italic>
  <Underline>False</Underline>
  <Strikeout>False</Strikeout>
  </InplaceEditFont>

Before I have had a problem with Font Serialization/Deserialization. It is imposible deserialize font because font class doesnt have a parameterless constructor.

How you managed to do that?

Thanks in advance.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Font Serialization/Deserialization
Reply #1 - Feb 1st, 2007 at 2:04pm
Print Post  
Hi,

We don't use the .NET's built-in serialization, we have implemented our own for FlowChart.NET. The code looks like this -

Code
Select All
private Font ReadFontElement(System.Xml.XmlReader reader)
{
	bool isThereAFont = false;

	string tag;
	string name = "Arial";
	float size = 8f;
	GraphicsUnit unit = GraphicsUnit.Pixel;
	bool bold = false;
	bool italic = false;
	bool underline = false;
	bool strikeout = false;

	int depth = reader.Depth;
	while (true)
	{
		reader.Read();
		if (reader.Depth == depth)
			break;

		isThereAFont = true;
		tag = reader.Name;

		// Read the value
		reader.Read();
		switch (tag)
		{
		case "Name":
			name = reader.Value;
			break;

		case "Size":
			size = XmlConvert.ToSingle(reader.Value);
			break;

		case "Unit":
			unit = (GraphicsUnit)XmlConvert.ToEnum(
				typeof(GraphicsUnit), reader.Value);
			break;

		case "Bold":
			bold = XmlConvert.ToBoolean(reader.Value.ToLower());
			break;

		case "Italic":
			italic = XmlConvert.ToBoolean(reader.Value.ToLower());
			break;

		case "Underline":
			underline = XmlConvert.ToBoolean(reader.Value.ToLower());
			break;

		case "Strikeout":
			strikeout = XmlConvert.ToBoolean(reader.Value.ToLower());
			break;
		}

		// Read the closing element
		reader.Read();
	}

	if (isThereAFont)
	{
		return new Font(name, size,
			(bold ? FontStyle.Bold : 0) |
			(italic ? FontStyle.Italic : 0) |
			(underline ? FontStyle.Underline : 0) |
			(strikeout ? FontStyle.Strikeout : 0),
			unit);
	}
	else
	{
		return null;
	}
}
 



Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint