Groups | Blog | Home
all groups > dotnet drawing api > september 2005 >

dotnet drawing api : font serialization



SharpCoderMP
9/8/2005 12:00:00 AM
hi,
i posted this erlier to the other group but got no response :(
so i'm trying now this one...

according to the documentation System.Drawing.Font is serializable, well
at least it should be because it implements ISerializable. but when i
try to serialize it with XmlSerializer i get exception saying that this
object cannot be serialized because it hasn't got defined default public
constructor (or something like that - this is translation from other
language, so it may sound wired).

so how can i serialize Font object? is it serializable or this is
SharpCoderMP
9/13/2005 12:00:00 AM
hi,

well i did (almost) the same. i couldn't find any info about this and
frankly i had no time to dig for it. so this "feature" remains a mystery
to me.

thanks for reply.


[quoted text, click to view]
Andrea Piccinini
9/13/2005 10:00:55 AM
hi,
I have same problem and i had more difficult to got info about Objet
serialization such as font,graphicspath,pen, ecc ...

I solved this problem with a "manually" serialization ,I dont't think that
is a right solution but that is an only way that I find for serialize some
graphics object such as Font

void Grafica::SerializeFont(Font* xFont,SerializationInfo *info,String* ID)
{
info->AddValue(String::Concat(ID,"N"),xFont->FontFamily->Name);
info->AddValue(String::Concat(ID,"H"),xFont->Height);
info->AddValue(String::Concat(ID,"S"),__box(xFont->Style),__typeof(FontStyle));
info->AddValue(String::Concat(ID,"U"),__box(xFont->Unit),__typeof(GraphicsUnit));
info->AddValue(String::Concat(ID,"C"),xFont->GdiCharSet);
info->AddValue(String::Concat(ID,"V"),xFont->GdiVerticalFont);
}

and relative deserialization

Font* Grafica::DeSerializeFont(SerializationInfo *info,String *ID)
{
String* familyname = info->GetString(String::Concat(ID,"N"));
float emsize = info->GetSingle(String::Concat(ID,"H"));
FontStyle stile = *dynamic_cast<FontStyle __box*>
(info->GetValue(String::Concat(ID,"S"),__typeof(System::Object)));
GraphicsUnit unit = *dynamic_cast<GraphicsUnit
__box*>(info->GetValue(String::Concat(ID,"U"),__typeof(System::Object)));
System::Byte gdcharset = info->GetByte(String::Concat(ID,"C"));
bool gdiverticalfont = info->GetBoolean(String::Concat(ID,"V"));
return new Font(familyname,emsize,stile,unit,gdcharset,gdiverticalfont);
}

I enjoy if anyone has a better solution.

hi,
I Apologize for my english.









"SharpCoderMP" <csharp_mp@interia.pl.NFSPM> ha scritto nel messaggio
news:um3BUvGtFHA.304@TK2MSFTNGP11.phx.gbl...
[quoted text, click to view]

Chris Y
9/25/2005 12:00:00 AM
I am just starting to read up on serialization. Your first problem appears
to be a limitation of shallow XML serialization, where only public
properties can be serialized and the class must have a default constructor
taking no parameters. This last requirement is causing that error message.

Sorry I can't help much.

[quoted text, click to view]

SharpCoderMP
9/27/2005 8:26:45 PM
well, if you'll ever need to serialize font, i did this for serialization:
protected void XmlFontSerialize(XmlTextWriter w, Font font)
{
if (font != null && w != null)
{
w.WriteStartElement("Font");
XmlSerializer ser = new XmlSerializer(typeof(GraphicsUnit));
w.WriteElementString("fontFamily",font.FontFamily.Name);
w.WriteElementString("fontSize",XmlConvert.ToString(font.Size));
ser.Serialize(w,font.Unit);
ser = new XmlSerializer(typeof(FontStyle));
ser.Serialize(w,font.Style);
w.WriteEndElement();
}
}

desierialization is a bit tricky but works very simmilar. if someone
needs it i'll post the code.

[quoted text, click to view]
AddThis Social Bookmark Button