This commit is contained in:
Rich 2010-03-25 19:38:51 +00:00
parent 076fcfae10
commit 74673d17ae
32 changed files with 5048 additions and 0 deletions

View File

@ -0,0 +1,671 @@
using System;
using System.Collections.Generic;
using System.Text;
//using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Drawing;
namespace Volian.Svg.Library
{
public class DisplayText
{
#region Properties
// list of 'pieces of text' for this item. Pieces include symbols, ros,
// transitions & plain text.
private List<displayTextElement> _DisplayTextElementList;
public List<displayTextElement> DisplayTextElementList
{
get { return _DisplayTextElementList; }
set { _DisplayTextElementList = value; }
}
// dictionary for the font table for this item. Note that this may
// go away (it is not really used).
private Dictionary<int, string> _dicRtfFontTable;
public Dictionary<int, string> dicRtfFontTable
{
get { return _dicRtfFontTable; }
set { _dicRtfFontTable = value; }
}
public string OriginalText; // compare for save to see if change.
#endregion
#region Constructors
private Font TextFont;
/// <summary>
/// DisplayText constructor:
/// Creates a DisplayText object that converts the database text into a list of
/// displayTextElement elements.
/// Arguments are:
/// ItemInfo itemInfo - the item whose text will be resolved
/// E_EditPrintMode ep_mode - edit or print.
/// E_ViewMode vw_mode - view or edit.
/// </summary>
public DisplayText(string text)
{
DisplayTextElementList = new List<displayTextElement>();
OriginalText = text;
TextFont = new Font("Prestige Elite Tall",12);
//TextFont = GetItemFont();
// if in print mode or view mode, do replace words. Only if in edit mode are replace
// words left as is.
//_MyFormat = itemInfo.ActiveFormat;
//if (epMode == E_EditPrintMode.Print || vwMode == E_ViewMode.View) text = DoReplaceWords(text);
// as a precaution, convert any \~ to \u160?. This is for Hard spaces.. see the commentary in the
// save portion of this code for an explanation.
text = text.Replace(@"\~", @"\u160?");
// replace the dash/hyphen or whatever you want to call it, with a hard hyphen. The 16-bit program
// treated the dash/hyphen as such. Translate back on any data saves.
text = text.Replace(@"-", @"\u8209?");
// displayTextElement List items are created for anything that is handled differently in RTB, i.e.
// symbols, ros, trans, text.
int startIndex = 0;
int index = -1;
while ((index = FindTokenChar(text, startIndex)) > -1)
{
// Do any 'plain' text that preceeds the token.
if (index > startIndex) DoTextElement(text, startIndex, index);
// Now do any other types
if (text[index] == '\x15')
index = DoRO(text, index);
else if (text[index] == '\x252C' || text[index] == '\x2566')
index = DoTran(text, index);
else
index = DoSymbol(text, startIndex, index);
startIndex = index; // +1;
if (startIndex >= text.Length) break;
}
// Add any remaining text.
if (startIndex < text.Length) DoTextElement(text, startIndex, index);
}
#endregion
#region SaveData
//public bool Save(string rtf)
//{
// try
// {
// List<displayLinkElement> origList = GetLinkList(DisplayTextElementList);
// // massage string to store in DisplayTextElementList...
// RtfToDisplayTextElements(rtf);
// // take the list & convert to data in the format to save to the database.
// StringBuilder sret = new StringBuilder();
// foreach (displayTextElement vte in DisplayTextElementList)
// {
// if (vte.Type == E_TextElementType.Text || vte.Type == E_TextElementType.Symbol)
// sret.Append(vte.Text);
// else if (vte.Type == E_TextElementType.ReferencedObject)
// sret.Append(ToData_RO((displayLinkElement)vte));
// else if (vte.Type == E_TextElementType.Transition || vte.Type == E_TextElementType.TransitionRange)
// sret.Append(ToData_Trans((displayLinkElement)vte));
// }
// string modtext = sret.ToString();
// if (modtext != OriginalText)
// {
// Item itm = _MyItemInfo.Get();
// // check for different text, i.e. text from this itm doesn't match
// // original text.
// if (OriginalText != itm.MyContent.Text)
// {
// Console.WriteLine("Save Failed because text changed outside of this edit session.");
// return false;
// }
// // Compare ro/transition lists and delete or add any to the item for any ros/transitions that have been
// // added/deleted or modified.
// ProcessRoTranChanges(itm, origList);
// itm.MyContent.Text = modtext;
// itm.Save();
// OriginalText = modtext;
// }
// else
// return true; // no text changed, but did not fail so return true.
// }
// catch (Exception ex)
// {
// Console.WriteLine("Save Failed with error: {0}", ex.Message);
// return false;
// }
// return true;
//}
private List<displayLinkElement> GetLinkList(List<displayTextElement> locDisplayTextElementList)
{
List<displayLinkElement> retList = new List<displayLinkElement>();
foreach (displayTextElement vte in locDisplayTextElementList)
{
if (vte.Type == E_TextElementType.ReferencedObject || vte.Type == E_TextElementType.TransitionRange || vte.Type == E_TextElementType.Transition)
{
displayLinkElement tmp = (displayLinkElement)vte;
displayLinkElement copy_vte = new displayLinkElement();
copy_vte.Type = tmp.Type;
copy_vte.Link = tmp.Link;
copy_vte.Text = tmp.Text;
retList.Add(copy_vte);
}
}
return retList;
}
private void RtfToDisplayTextElements(string rtf)
{
// For hardspaces, the windows richtextbox does some 'quirky' things:
// A unicode representation of \u160? is sent INTO the rtb. Coming out,
// that \u160? was translated to a \~ (by the underlying windows rtb).
// Note that if the \~ is sent to the rtb, it is treated as a regular space,
// i.e. no longer a hardspace, and actually is converted to a regular space.
// SO, on the way out, convert any \~ to \u160?
string noExtraRtfStr = rtf.Replace(@"\~", @"\u160?");
// GetFontTable returns a non-negative number font number in the
// font table for the unicode font, if it is used (otherwise -1)
//int unicodeFont = GetFontTable(rtb.Rtf);
// strip off all rtf commands...
noExtraRtfStr = StripRtfCommands(noExtraRtfStr);
//Console.WriteLine("StripRtf: {0}", noExtraRtfStr);
// Also, set back the hard dash to a regular dash... Do this after the removal
// of other rtf commands though since the \u8209 was surrounded by font commands
// that, without there removal first, was also removing the dash. Have it with
// a space & without because if it is at the end, there will be no space (leave
// it to rtf processing to make it more complicated)
noExtraRtfStr = noExtraRtfStr.Replace(@"\u8209? ", @"-");
noExtraRtfStr = noExtraRtfStr.Replace(@"\u8209?", @"-");
DisplayTextElementList.Clear();
int startIndex = 0;
int index = -1;
while ((index = FindRtfChar(noExtraRtfStr, startIndex)) > -1)
{
int fndindx = -1;
// Do any 'plain' text that preceeds the token.
if (index > startIndex)
index = SaveTextElement(noExtraRtfStr, startIndex, index);
if ((fndindx = noExtraRtfStr.IndexOf(@"\protect", index)) == index)
index = SaveLink(noExtraRtfStr, index);
else
index = SaveSymbolTE(noExtraRtfStr, index);
startIndex = index + 1;
if (startIndex >= noExtraRtfStr.Length) break;
}
// Add any remaining text.
if (startIndex < noExtraRtfStr.Length) DoTextElement(noExtraRtfStr, startIndex, index);
//Console.WriteLine(noExtraRtfStr);
}
private int SaveTextElement(string data, int startIndex, int index)
{
displayTextElement vte = new displayTextElement();
vte.Type = E_TextElementType.Text;
int len = (index == -1) ? data.Length - startIndex : index - startIndex;
vte.Text = data.Substring(startIndex, len);
DisplayTextElementList.Add(vte);
return index;
}
private int SaveSymbolTE(string data, int startIndex)
{
displayLinkElement vte = new displayLinkElement();
vte.Type = E_TextElementType.Symbol;
// symbols are just the unicode/rtf command, no font associated with it
// by the time it gets here... A symbol can be represented by \'xy or \uxyz?
// if the \'xy is used the length of the symbol number will always be two,
// otherwise find the index of the '?' to find the end.
int endindx = -1;
if (data[startIndex + 1] == '\'') endindx = startIndex + 3;
else endindx = data.IndexOf("?", startIndex);
if (endindx == -1) return startIndex; // not found - error
vte.Text = data.Substring(startIndex, endindx - startIndex + 1);
DisplayTextElementList.Add(vte);
if (endindx + 1 < data.Length && data[endindx + 1] != ' ') return endindx;
return endindx + 1; // add one to get past the space that was added after a symbol (to end the font cmd)
}
private int SaveLink(string data, int stIndex)
{
////displayLinkElement vte = new displayLinkElement();
//// find the end of the link text, i.e. either the ending \v0 or \protect0. The win32 rtf box can
//// put these in either order, take the lowest index.
//int startIndex = stIndex + @"\protect ".Length;
//int indx_v0 = data.IndexOf(@"\v0", startIndex);
//int indx_protect0 = data.IndexOf(@"\protect0", startIndex);
//int indx = indx_v0 < indx_protect0 ? indx_v0 : indx_protect0;
//LinkText lt = new LinkText(data.Substring(startIndex, indx - startIndex));
//displayLinkElement vte = new displayLinkElement();
//vte.Type = (E_TextElementType)lt.MyParsedLinkType;
//vte.Text = lt.MyValue;
//vte.Link = lt.MyLink;
//DisplayTextElementList.Add(vte);
//return (indx_v0 < indx_protect0 ? indx_protect0 + 1 : indx_v0 + 1);
////if (lt.MyParsedLinkType == ParsedLinkType.ReferencedObject) return
////// first find if ReferencedObject or trans, the ReferencedObject has a #R.
////int istart = data.IndexOf("#Link:", startIndex);
////if (data[istart + 6] == 'R') return SaveROTE(data, startIndex);
////else if (data.Substring(istart+6,11) == "TransitionR")
//// return SaveTranTE(data, startIndex, E_TextElementType.TRANS_Range);
////return SaveTranTE(data, startIndex, E_TextElementType.TRANS_Single);
return 0;
}
//private int SaveTranTE(string data, int startIndex, E_TextElementType type)
//{
// displayLinkElement vte = new displayLinkElement();
// vte.Type = type;
// // \protect {transition text} \v #Link:Transition(Range): 1 2 3\protect0\v0
// // where 1 2 3 are transition type and ids
// int indx = data.IndexOf("\\v #Link:Transition", startIndex);
// // use '9' to get past \\protect
// vte.Text = data.Substring(startIndex + 9, indx - startIndex - 9);
// // the link is the text between the #Link... and the next '\\'.
// int iend = data.IndexOf("\\", indx+1);
// int bindx = data.IndexOf("#", indx);
// vte.Link = data.Substring(bindx, iend - bindx);
// DisplayTextElementList.Add(vte);
// // unfortunately, the rtf box may add the \protect0 \v0 in either order
// // and with or without one or more spaces between then. The number of text
// // characters = 11 for \protect0\v0 - find the number of spaces between them
// // if any?
// int nsp = 0;
// for (int c = iend; c < iend + 11; c++) if (data[c] == ' ') nsp++;
// return iend + 11 + nsp;
//}
//private int SaveROTE(string data, int startIndex)
//{
// displayLinkElement vte = new displayLinkElement();
// vte.Type = E_TextElementType.ReferencedObject;
// // \protect {rovalue} \v #Link:ReferencedObject (RoUsageId) {ROID}\protect0\v0
// int indx = data.IndexOf("\\v #Link:ReferencedObject", startIndex);
// // use '9' to get past \\protect
// vte.Text = data.Substring(startIndex + 9, indx - startIndex - 9);
// // the link is the text between the #Link... and the next '\\'.
// int iend = data.IndexOf("\\", indx);
// int bindx = data.IndexOf("#", indx);
// vte.Link = data.Substring(bindx, iend - bindx);
// DisplayTextElementList.Add(vte);
// // unfortunately, the rtf box may add the \protect0 \v0 in either order
// // and with or without one or more spaces between then. The number of text
// // characters = 11 for \protect0\v0 - find the number of spaces between them
// // if any?
// int nsp = 0;
// for (int c = iend; c < iend + 11; c++) if (data[c] == ' ') nsp++;
// return iend + 11 + nsp;
//}
private int FindRtfChar(string text, int startIndex)
{
int prindx = text.IndexOf("\\protect", startIndex);
int symindx1 = text.IndexOf("\\'", startIndex);
int symindx2 = text.IndexOf("\\u", startIndex);
if (symindx2 > -1)
{
if (text[symindx2 + 2] == 'l') symindx2 = -1; // don't process underlines
}
if (prindx == -1 && symindx1 == -1 && symindx2 == -1) return -1;
if (prindx == -1) prindx = text.Length + 1;
if (symindx1 == -1) symindx1 = text.Length + 1;
if (symindx2 == -1) symindx2 = text.Length + 1;
// Which token has smallest number, to determine which item is next
// in the string. If it is a symbol - see if it has a font specifier
// first.
int symindx = symindx1 < symindx2 ? symindx1 : symindx2;
int smallest = (prindx < symindx ? prindx : symindx);
return smallest;
}
private int GetFontTable(string rtf)
{
dicRtfFontTable = new Dictionary<int, string>();
// return unicode (symbol) font number, if it exists, to expedite finding
// the font for symbols.
int unicodeFont = -1;
int bindx = rtf.IndexOf(@"{\fonttbl");
if (bindx < -1) return -1;
int eindx = rtf.IndexOf("}}", bindx);
// get font table string and then do regular expressions to get font number
// with font name.
string tbl = rtf.Substring(bindx + 9, eindx - bindx - 8);
tbl = tbl.Replace("{", "<");
tbl = tbl.Replace("}", ">");
string pat = @"(?:<\\f)([0-9]+)(?:[\S]+ )([\w ]+)";
StringBuilder sb = new StringBuilder();
foreach (Match m in Regex.Matches(tbl, pat))
{
int num = Convert.ToInt32(m.Result("${1}"));
string nam = m.Result("${2}");
dicRtfFontTable.Add(num, nam);
if ((unicodeFont == -1) && (nam == "Arial Unicode MS")) unicodeFont = num;
}
return unicodeFont;
}
private string RemoveRtfStyles(string rtf)
{
string retval = rtf;
// remove rtf commands for any styles that were added. Note that if
// the entire item has a style, and also contains 'pieces' of text with
// the same style, the underlying rtf box removes the embedded rtf commands,
// for example, if the entire step is bolded, and 'THEN' has bold on/off
// surrounding it, the rtf box removes the bold around the 'THEN'
// These remove the command with a following space or the command alone,
// either case may exist, because if there are rtf commands following the
// style command, there will be no space character following the style command.
if ((TextFont.Style & FontStyle.Bold) > 0)
{
retval = Regex.Replace(retval, @"\\ulnone\\b0 ?", "\\ulnone");
retval = Regex.Replace(retval, @"\\b0 ?", "");
retval = Regex.Replace(retval, @"\\ul\\b ?", "\\ul");
retval = Regex.Replace(retval, @"\\b ?", "");
}
if ((TextFont.Style & FontStyle.Underline) > 0)
{
retval = Regex.Replace(retval, @"\\ul0 ?", "");
retval = Regex.Replace(retval, @"\\ul ?", "");
}
if ((TextFont.Style & FontStyle.Italic) > 0)
{
retval = Regex.Replace(retval, @"\\i0 ?", "");
retval = Regex.Replace(retval, @"\\i ?", "");
}
return retval;
}
public static string ReplaceRTFClause(Match m)
{
switch (m.Value[1])
{
case 'u':
if (Regex.IsMatch(m.Value, @"\\u[0-9]+"))
return m.Value; // Special Charcaters
if (Regex.IsMatch(m.Value, @"\\ulnone"))
return m.Value;
if (Regex.IsMatch(m.Value, @"\\ul.*"))
return m.Value; // Underline
break;
case '\'': // Special Character
return m.Value;
case 'b': // Bold
return m.Value;
case 's': // sub or super....
if (m.Value == @"\sub") return m.Value;
if (m.Value == @"\super") return m.Value;
break;
case 'n': // nosubsuper...
if (m.Value == @"\nosupersub") return m.Value;
break;
case 'i': // Italics
return m.Value;
case 'v': // save link hidden info
if (m.Value == @"\v") return m.Value; // part of link
if (Regex.IsMatch(m.Value, @"\\v0"))
return m.Value; // hidden info off
break;
case 'p':
if (m.Value == @"\par") return "\r\n";
if (m.Value == @"\protect")
return m.Value;
if (m.Value == @"\protect0")
return m.Value;
break;
}
return "";//Strip All
}
public static string StripRtfCommands(string rtf)
{
string retval = Regex.Replace(rtf, @"[\r\n]", "", RegexOptions.Singleline); // Strip Carriage Returns and Newlines
retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces
retval = Regex.Replace(retval, @"\\[^ \\?]+", new MatchEvaluator(ReplaceRTFClause)); // take backslash xyz and evaluates them
// remove a space if there is one as the first character..
if (retval[0] == ' ') retval = retval.Remove(0, 1);
// remove \r\n at end of string - this was added with the \par at the end of string by the rtf box
if (retval.Substring(retval.Length - 2, 2) == "\r\n") retval = retval.Remove(retval.Length - 2, 2);
// TODO: retval = RemoveRtfStyles(retval);
return retval;
}
private string ToData_RO(displayLinkElement vte)
{
// get past the #Link:ReferencedObject part of the link.
return String.Format("\x15ReferencedObjectv RO\\v0 {0}\\v #{1}\\v0", vte.Text, vte.Link.Substring(23, vte.Link.Length - 23));
}
private string ToData_Trans(displayLinkElement vte)
{
char trchar = vte.Type == E_TextElementType.Transition ? '\x252C' : '\x2566';
// depending on type, get past the #Link:Transition: or #Link:TransitionRange: part
// of text.
int indx = vte.Type == E_TextElementType.Transition ? 18 : 23;
return String.Format("{0}\\v TRAN\\v0 {1}\\v {2}\\v0", trchar, vte.Text, vte.Link.Substring(indx, vte.Link.Length - indx));
}
#endregion
//#region StyleData
//private VE_Font GetItemFont()
//{
// VE_Font font = null;
// FormatInfo format = _MyItemInfo.ActiveFormat;
// int type = (int)_MyItemInfo.MyContent.Type;
// switch (type / 10000)
// {
// case 0: // procedure
// font = format.PlantFormat.FormatData.Font;
// break;
// case 1: // section
// font = format.PlantFormat.FormatData.SectData.SectionHeader.Font;
// break;
// case 2: // step types
// int typindx = type - 20000; // what to do for other types rather than steps
// font = format.PlantFormat.FormatData.StepDataList[typindx].Font;
// break;
// }
// TextFont = font;
// return font;
//}
//#endregion
#region DoListElements
private int FindTokenChar(string txt, int startIndex)
{
// tokens are ro, transitions and possible symbol
char[] tok = { '\x15', '\x252C', '\x2566', '\\' };
bool done = false;
// If there is only an rtf token from the indexed position on, don't return the
// IndexOfAny index value, because it will by one character past the '\' and throw
// of the return value of where in the string the text should be saved. For example
// for the string '\b text \v somevalue \v0\b0', the first time through the while
// loop has the index at the '\b' char of the b0.
//int savstartIndex = startIndex;
while (!done)
{
int indx = txt.IndexOfAny(tok, startIndex);
if (indx < 0) return indx;
if (txt[indx] != '\\') return indx;
// see if symbol (but not underline) or another rtf command: has a 'u'
// followed by a non-underline or single quote, and if so, return it.
// Otherwise, get next index, must have been a slash or other rtf command.
if (((txt[indx + 1] == 'u' && txt[indx + 2] != 'l')) || (txt[indx + 1] == '\'')) return indx;
startIndex = indx + 1;
}
return -1;
}
private int DoTextElement(string text, int startIndex, int index)
{
displayTextElement vte = new displayTextElement();
vte.Type = E_TextElementType.Text;
int len = (index == -1) ? text.Length - startIndex : index - startIndex;
vte.Text = text.Substring(startIndex, len);
DisplayTextElementList.Add(vte);
return index + 1;
}
private string CreateLink(E_TextElementType type, string linktxt)
{
string retlink = "";
if (type == E_TextElementType.ReferencedObject)
retlink = "#Link:ReferencedObject:" + linktxt;
else if (type == E_TextElementType.Transition)
retlink = "#Link:Transition:" + linktxt;
else
retlink = "#Link:TransitionRange:" + linktxt;
return retlink;
}
private int DoRO(string text, int index)
{
displayLinkElement vte = new displayLinkElement();
vte.Type = E_TextElementType.ReferencedObject;
int iend = text.IndexOf(@"\v", index);
vte.Text = text.Substring(index + 1, iend - index - 1);
int istart = text.IndexOf("#", index);
iend = text.IndexOf(@"\v0", istart);
vte.Link = text.Substring(istart, iend - istart);
DisplayTextElementList.Add(vte);
return iend + 3;
}
//private string FixTransition(string link, string text)
//{
// int transitionID = Convert.ToInt32(link.Split(" ".ToCharArray())[1]);
// // Find the transition
// foreach (TransitionInfo ti in _MyItemInfo.MyContent.ContentTransitions)
// {
// if (ti.TransitionID == transitionID)
// {
// //string path = ti.PathTo.Replace(" Section PROCEDURE STEPS ", ", ");
// //path = path.Replace(" Section PROCEDURE STEPS", "");
// string path = ti.ResolvePathTo(_MyFormat, _MyItemInfo, ItemInfo.Get(ti.ToID), ti.RangeID == 0 ? null : ItemInfo.Get(ti.RangeID));
// return path;
// }
// }
// return text;
//}
private int DoTran(string text, int index)
{
//displayLinkElement vte = new displayLinkElement();
//if (text[index] == '\x252C') vte.Type = E_TextElementType.Transition;
//else vte.Type = E_TextElementType.TransitionRange; // '\x2566'\
//int iend = text.IndexOf(@"\v", index);
//vte.Text = text.Substring(index + 1, iend - index - 1);
//int istart = text.IndexOf("#", index);
//iend = text.IndexOf(@"\v0", istart);
//vte.Link = text.Substring(istart, iend - istart);
//vte.Text = FixTransition(vte.Link, vte.Text); // TODO: Transition text resolution?
//DisplayTextElementList.Add(vte);
//return iend + 3;
return 0;
}
private int DoSymbol(string text, int startIndex, int index)
{
displayTextElement vte = new displayTextElement();
vte.Type = E_TextElementType.Symbol;
// symbols are the unicode/rtf command. A symbol can be represented by \'xy or
// in the text from the database \uxyz?. If the \'xy is used the length of the
// symbol number will always be two, otherwise find the index of the '?' to
// find the end.
int endindx = -1;
if (text[index + 1] == '\'') endindx = index + 3;
else endindx = text.IndexOf("?", index);
vte.Text = text.Substring(index, endindx - index + 1);
DisplayTextElementList.Add(vte);
// return the position just past the symbol.
return endindx + 1;
}
#endregion
#region ReplaceWords
//private ReplaceStr _rs;
//private string ReplaceIt(Match m)
//{
// string s = m.ToString();
// string t = s.Replace(_rs.ReplaceWord, _rs.ReplaceWith);
// return m.ToString().Replace(_rs.ReplaceWord, _rs.ReplaceWith);
//}
//private string DoReplaceWords(string Text)
//{
// ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
// foreach (ReplaceStr rs in rsl)
// {
// if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
// bool replaceit = false;
// // note that the order of this check is important. Check in this order...
// // background here
// if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true;
// else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true;
// else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
// else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
// else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
// else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
// else if (_MyItemInfo.IsAccPages & (rs.Flag & E_ReplaceFlags.Attach) > 0) replaceit = true;
// if (replaceit)
// {
// // CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace
// // with the ReplaceWith string as is
// if ((rs.Flag & E_ReplaceFlags.CaseInsens) > 0)
// {
// string res = "";
// string fortest = Text.ToUpper();
// string pat = @"(?<=\W|^)" + rs.ReplaceWord.ToUpper() + @"(?=\W|$)";
// int cpindx = 0;
// foreach (Match m in Regex.Matches(fortest, pat))
// {
// res += Text.Substring(cpindx, m.Index - cpindx);
// cpindx += (m.Index - cpindx);
// res += rs.ReplaceWith;
// cpindx += rs.ReplaceWord.Length;
// }
// if (cpindx < Text.Length) res += Text.Substring(cpindx, Text.Length - cpindx);
// Text = res;
// }
// // CASEINSENSALL: Do ReplaceWords for all words that match the ReplaceWord, regardless of case
// else if ((rs.Flag & E_ReplaceFlags.CaseInsensAll) > 0)
// {
// // not in hlp
// }
// // CASEINSENSFIRST: Do ReplaceWords for all words that exactly match the ReplaceWord,
// // except the case where the first character may be different
// else if ((rs.Flag & E_ReplaceFlags.CaseInsensFirst) > 0)
// {
// // not in hlp
// }
// else
// {
// string pat = @"(?<=\W|^)" + rs.ReplaceWord + @"(?=\W|$)";
// Text = Regex.Replace(Text, pat, rs.ReplaceWith);
// }
// }
// }
// return Text;
//}
#endregion
}
#region displayTextElementClass
public enum E_TextElementType : uint
{
Text = 0,
Transition = 1,
TransitionRange = 2,
ReferencedObject = 3,
Symbol = 4
};
public class displayTextElement
{
private E_TextElementType _Type;
public E_TextElementType Type
{
get { return _Type; }
set { _Type = value; }
}
private string _Text;
public string Text
{
get { return _Text; }
set { _Text = value; }
}
}
public class displayLinkElement : displayTextElement
{
private string _Link;
public string Link
{
get { return _Link; }
set { _Link = value; }
}
}
#endregion
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Win32;
namespace Volian.Svg.Library
{
//public static class FontFind
//{
// public static string FileName(string fontName)
// {
// string baseFont = string.Empty;
// Regex find = new Regex(fontName + @".* ?\(.*\)", RegexOptions.IgnoreCase);
// RegistryKey regKey = Registry.LocalMachine.CreateSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Fonts");
// string[] values = regKey.GetValueNames();
// baseFont = regKey.GetValue(values[0]).ToString();
// foreach (string valueName in regKey.GetValueNames())
// {
// if (find.IsMatch(valueName))
// return regKey.GetValue(valueName).ToString();
// }
// return baseFont;
// }
// public static string FullFileName(string fontName)
// {
// return @"c:\windows\fonts\" + FileName(fontName);
// }
//}
}

View File

@ -0,0 +1,195 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
namespace Volian.Svg.Library
{
public abstract partial class SvgPart
{
public abstract void Draw(Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent);
}
public partial class SvgPartInheritance : SvgPart
{
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
}
}
public partial class Svg : SvgGroup
{
public void Draw(Graphics graphics)
{
//SetupInheritance();
//Console.WriteLine("{0}, DPI {1}", graphics.VisibleClipBounds, graphics.DpiX);
SvgParts.Draw(graphics, new SvgScale(DeviceDPI(graphics), graphics.VisibleClipBounds, _Width, _Height, _ViewBox), this, this);
//SvgParts.Draw(graphics, new SvgScale(100, graphics.VisibleClipBounds, _Width, _Height, _ViewBox));
}
public static float DeviceDPI(Graphics g)
{
PointF[] tmp = { new PointF(g.DpiX, g.DpiY) };
g.TransformPoints(CoordinateSpace.World, CoordinateSpace.Device, tmp);
return (float)Math.Round((double)tmp[0].X, 0);
}
}
public partial class SvgArc : SvgShapePart
{
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
//_MyLineSettings.Scale = scale.M(1F);
if (FillColor != Color.Transparent)
using (Brush brush = new SolidBrush(FillColor))
graphics.FillEllipse(brush, scale.X(CX - Radius), scale.Y(CY - Radius), scale.M(Radius * 2), scale.M(Radius * 2));
if (OutlineWidth.Value != 0F && OutlineColor != Color.Empty)
using (Pen pen = new Pen(OutlineColor, scale.M(OutlineWidth)))
graphics.DrawEllipse(pen, scale.X(CX - Radius), scale.Y(CY - Radius), scale.M(Radius * 2), scale.M(Radius * 2));
}
}
public partial class SvgCircle : SvgShapePart
{
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
//_MyLineSettings.Scale = scale.M(1F);
if (FillColor != Color.Transparent)
using (Brush brush = new SolidBrush(FillColor))
graphics.FillEllipse(brush, scale.X(CX - Radius), scale.Y(CY - Radius), scale.M(Radius * 2), scale.M(Radius * 2));
if (OutlineWidth.Value != 0F && OutlineColor != Color.Empty)
using (Pen pen = new Pen(OutlineColor, scale.M(OutlineWidth)))
graphics.DrawEllipse(pen, scale.X(CX - Radius), scale.Y(CY - Radius), scale.M(Radius * 2), scale.M(Radius * 2));
}
}
public partial class SvgDefine : SvgGroup
{
public override void Draw(Graphics graphics, SvgScale myScale, Svg mySvg, SvgPartInheritance myParent)
{
// Don't draw
//_SvgParts.Draw(graphics, myScale);
}
}
public partial class SvgEllipse : SvgShapePart
{
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
if (FillColor != Color.Transparent)
using (Brush brush = new SolidBrush(FillColor))
graphics.FillEllipse(brush, scale.X(CX - RX), scale.Y(CY - RY), scale.M(2 * RX), scale.M(2 * RY));
if (OutlineWidth.Value != 0F && OutlineColor != Color.Empty)
using (Pen pen = new Pen(OutlineColor, scale.M(OutlineWidth)))
graphics.DrawEllipse(pen, scale.X(CX - RX), scale.Y(CY - RY), scale.M(2 * RX), scale.M(2 * RY));
}
}
public partial class SvgGroup : SvgPartInheritance
{
public override void Draw(Graphics graphics, SvgScale myScale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
_SvgParts.Draw(graphics, myScale, mySvg, this);
}
}
public partial class SvgImage : SvgPart
{
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
graphics.DrawImage(Image.FromFile(ImagePath), scale.X(X), scale.Y(Y), scale.M(Width), scale.M(Height));
}
}
public partial class SvgLine : SvgLinePart
{
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
if (LineColor != Color.Empty)
{
Color myColor = AdjustColorForWidth(LineColor, scale.M(LineWidth));
using (Pen pen = new Pen(LineColor, scale.M(LineWidth)))
graphics.DrawLine(pen, scale.X(X1), scale.Y(Y1), scale.X(X2), scale.Y(Y2));
}
}
}
public partial class SvgParts : CollectionBase
{
public void Draw(Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
foreach (SvgPart svgPart in List)
svgPart.Draw(graphics,scale,mySvg, myParent);
}
}
public partial class SvgRectangle : SvgShapePart
{
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
if (FillColor != Color.Transparent)
using (Brush brush = new SolidBrush(FillColor))
graphics.FillRectangle(brush, scale.X(X),scale.Y(Y),scale.M(Width),scale.M(Height));
if (OutlineWidth.Value != 0F && OutlineColor != Color.Empty)
using (Pen pen = new Pen(OutlineColor, scale.M(OutlineWidth)))
graphics.DrawRectangle(pen, scale.X(X),scale.Y(Y), scale.M(Width), scale.M(Height));
}
}
public partial class SvgRtf : SvgShapePart
{
//private static float _Factor = 1.085F; // 20 point Arial Font
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
_MyFontSettings.Scale = scale.M(1F);
}
private float YAdjustment(Graphics gr, Font fnt)
{
int yAsc = fnt.FontFamily.GetCellAscent(fnt.Style);
int yLS = fnt.FontFamily.GetLineSpacing(fnt.Style);
float gth = fnt.GetHeight(gr);
float fAsc = (yAsc * gth) / yLS;
return -fAsc;
}
}
public partial class SvgText : SvgShapePart
{
//private static float _Factor = 1.085F; // 20 point Arial Font
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
_MyFontSettings.Scale = scale.M(1F);
StringFormat stringFormat = StringFormat.GenericTypographic;
float YAdj = YAdjustment(graphics, Font);
using (Brush brush = new System.Drawing.SolidBrush(FillColor))
graphics.DrawString(Text, Font, brush, scale.X(X), scale.Y(Y) + YAdj, stringFormat);
SizeF sf = graphics.MeasureString(Text, Font, graphics.VisibleClipBounds.Size, stringFormat);
if (OutlineWidth.Value != 0 && OutlineColor != Color.Empty)
using (GraphicsPath path = GetStringPath(Text, Svg.DeviceDPI(graphics), new PointF(scale.X(X), scale.Y(Y) + YAdj), Font, stringFormat))
using (Pen myPen = new Pen(OutlineColor, scale.M(OutlineWidth)))
graphics.DrawPath(myPen, path);
}
GraphicsPath GetStringPath(string s, float dpi, PointF loc, Font font, StringFormat format)
{
GraphicsPath path = new GraphicsPath();
// Convert font size into appropriate coordinates
float emSize = dpi * font.SizeInPoints / 72;
path.AddString(s, font.FontFamily, (int)font.Style, emSize, loc, format);
return path;
}
private float YAdjustment(Graphics gr, Font fnt)
{
int yAsc = fnt.FontFamily.GetCellAscent(fnt.Style);
//int yDesc = fnt.FontFamily.GetCellDescent(fnt.Style);
//int yEm = fnt.FontFamily.GetEmHeight(fnt.Style);
int yLS = fnt.FontFamily.GetLineSpacing(fnt.Style);
float gth = fnt.GetHeight(gr);
float fh = fnt.Size;
float fAsc = (yAsc * gth) / yLS;
return -fAsc;
}
}
public partial class SvgUse : SvgPartInheritance
{
public override void Draw(System.Drawing.Graphics graphics, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
{
SetupInheritance(myParent.MyInheritedSettings);
mySvg[_UseID.Substring(1)].Draw(graphics, scale.AdjustOrigin(X, Y), mySvg, this);
}
}
}

View File

@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
namespace Volian.Svg.Library
{
[XmlRoot("svg")]
public partial class Svg : SvgGroup
{
#region XML Serializer Namespaces
private XmlSerializerNamespaces _Namespaces = null;
[XmlNamespaceDeclarations]
public XmlSerializerNamespaces Namespaces
{
get
{
if (_Namespaces == null)
{
_Namespaces = new XmlSerializerNamespaces();
_Namespaces.Add("xlink", "http://www.w3.org/1999/xlink");
}
return _Namespaces;
}
set { _Namespaces = value; }
}
#endregion
#region Width
private SvgMeasurement _Width = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Width
{
get { return _Width; }
set { _Width = value; }
}
[System.ComponentModel.DefaultValueAttribute("0")]
[XmlAttribute("width")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Width_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Width); }
set { _Width = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private string _Watermark="";
[XmlAttribute("watermark")]
public string Watermark
{
get { return _Watermark; }
set { _Watermark = value; }
}
public void SetValidWaterMark(string token, string watermark)
{
if (token == "{" + watermark.ToUpper() + "PAGE}" )
_Watermark = watermark;
}
#endregion
#region Height
private SvgMeasurement _Height = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Height
{
get { return _Height; }
set { _Height = value; }
}
[System.ComponentModel.DefaultValueAttribute("0")]
[XmlAttribute("height")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Height_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Height); }
set { _Height = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region ViewBox
private SvgViewBox _ViewBox = new SvgViewBox("0 0 0 0");
[XmlIgnore]
public SvgViewBox ViewBox
{
get { return _ViewBox; }
set { _ViewBox = value; }
}
[System.ComponentModel.DefaultValueAttribute("0 0 0 0")]
[XmlAttribute("viewBox")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string SVGViewBox_XmlSurrogate
{
get { return SvgXmlConverter<SvgViewBox>.GetString(_ViewBox); }
set { _ViewBox = SvgXmlConverter<SvgViewBox>.GetObject(value); }
}
#endregion
//#region Setup Inheritance
//private void SetupInheritance()
//{
// SvgParts.SetupInheritance(_MyInheritedSettings);
//}
////override internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
////{
//// _MyInheritedSettings.MyParentsSettings = myParentsSettings;
//// SvgParts.SetupInheritance(_MyInheritedSettings);
////}
//#endregion
#region Part Lookup
private Dictionary<string, SvgPart> _LookUp;
[XmlIgnore]
private Dictionary<string, SvgPart> LookUp
{
get
{
if (_LookUp == null)
{
_LookUp = new Dictionary<string, SvgPart>();
AddLookup(_LookUp);
}
return _LookUp;
}
}
public SvgPart this[string id]
{ get { return LookUp[id]; } }
#endregion
}
}

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgArc : SvgShapePart
{
#region ctor
public SvgArc() { ;}
public SvgArc(PointF location, float radius, float startAngle, float endAngle, Color fillColor, Color lineColor, float lineWidth)
{
_CX.Value = location.X;
_CY.Value = location.Y;
_Radius.Value = radius;
FillColor = fillColor;
LineColor = lineColor;
LineWidth = new SvgMeasurement(lineWidth);
}
//XMLElementAttribute(ElementName = "PREFIX", IsNullable = false)
#endregion
#region Location
private SvgMeasurement _CX = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement CX
{
get { return _CX; }
set { _CX = value; }
}
[XmlAttribute("cx")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string CX_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_CX); }
set { _CX = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _CY = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement CY
{
get { return _CY; }
set { _CY = value; }
}
[XmlAttribute("cy")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string CY_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_CY); }
set { _CY = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Radius
private SvgMeasurement _Radius = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Radius
{
get { return _Radius; }
set { _Radius = value; }
}
[XmlAttribute("r")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string X_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Radius); }
set { _Radius = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Angles
#endregion
}
}

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgCircle : SvgShapePart
{
#region ctor
public SvgCircle() { ;}
public SvgCircle(PointF location, float radius, Color fillColor, Color lineColor, float lineWidth)
{
_CX.Value = location.X;
_CY.Value = location.Y;
_Radius.Value = radius;
FillColor = fillColor;
LineColor = lineColor;
LineWidth = new SvgMeasurement(lineWidth);
}
//XMLElementAttribute(ElementName = "PREFIX", IsNullable = false)
#endregion
#region Location
private SvgMeasurement _CX = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement CX
{
get { return _CX; }
set { _CX = value; }
}
[XmlAttribute("cx")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string CX_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_CX); }
set { _CX = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _CY = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement CY
{
get { return _CY; }
set { _CY = value; }
}
[XmlAttribute("cy")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string CY_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_CY); }
set { _CY = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Radius
private SvgMeasurement _Radius = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Radius
{
get { return _Radius; }
set { _Radius = value; }
}
[XmlAttribute("r")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string X_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Radius); }
set { _Radius = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgDefine : SvgGroup
{
// Nothing here - Draw definitions in individual modules
}
}

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgEllipse : SvgShapePart
{
#region ctor
public SvgEllipse() { ;}
public SvgEllipse(PointF location, float radiusX, float radiusY, Color fillColor, Color lineColor, float lineWidth)
{
_CX.Value = location.X;
_CY.Value = location.Y;
_RX.Value = radiusX;
_RY.Value = radiusY;
FillColor = fillColor;
LineColor = lineColor;
LineWidth = new SvgMeasurement(lineWidth);
}
//XMLElementAttribute(ElementName = "PREFIX", IsNullable = false)
#endregion
#region Location
private SvgMeasurement _CX = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement CX
{
get { return _CX; }
set { _CX = value; }
}
[XmlAttribute("cx")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string CX_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_CX); }
set { _CX = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _CY = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement CY
{
get { return _CY; }
set { _CY = value; }
}
[XmlAttribute("cy")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string CY_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_CY); }
set { _CY = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Size
private SvgMeasurement _RX = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement RX
{
get { return _RX; }
set { _RX = value; }
}
[XmlAttribute("rx")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string RX_RXmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_RX); }
set { _RX = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _RY = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement RY
{
get { return _RY; }
set { _RY = value; }
}
[XmlAttribute("ry")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string RY_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_RY); }
set { _RY = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
}
}

View File

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace Volian.Svg.Library
{
public class SvgFillSettings
{
#region ctor
public SvgFillSettings() { ;}
public SvgFillSettings(Color myColor)
{
_Fill = ColorTranslator.ToHtml(myColor);
}
//public SvgFillSettings(string myFill)
//{
// _Fill = myFill;
//}
#endregion
#region Inheritance
private SvgFillSettings _MyParentsSettings = null;
public SvgFillSettings MyParentsSettings
{
get { return _MyParentsSettings; }
set
{
_MyParentsSettings = value;
}
}
#endregion
#region Internal Inherited Properties
protected string InheritedFill
{
get
{
// Fill = "", "0" - Default, otherwise the value
if (_Fill != "" && _Fill != "0" && _Fill.ToLower() != "empty") return _Fill; // Current Value
if (_MyParentsSettings != null) return _MyParentsSettings.InheritedFill; // Inherited
return "Black"; // Default
}
}
#endregion
#region Inherited Values
public Color FillColor
{
get
{
// Fill = "None" - Eliminate, otherwise the value
string myFill = InheritedFill;
if (myFill.ToLower() == "none") // Eliminate
return Color.Transparent;
return ColorTranslator.FromHtml(myFill);
}
set
{
if (value == Color.Transparent || value == Color.Empty)
_Fill = "none";
else
_Fill = ColorTranslator.ToHtml(value);
}
}
#endregion
#region Properties
private string _Fill = string.Empty; // Default value is None
public string Fill
{
get { return _Fill; }
set { _Fill = value; }
}
#endregion
}
}

View File

@ -0,0 +1,159 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace Volian.Svg.Library
{
class SvgFontSettings
{
#region ctor
public SvgFontSettings() { ;}
public SvgFontSettings(Font myFont)
{
_FontFamily = myFont.FontFamily.Name;
_FontSize = myFont.SizeInPoints.ToString() + "PT";
_SVGFontStyle = ((myFont.Style & FontStyle.Italic) == FontStyle.Italic ? "italic" : "normal");
_FontWeight = ((myFont.Style & FontStyle.Bold) == FontStyle.Bold ? "bold" : "normal");
_TextDecoration = ((myFont.Style & FontStyle.Underline) == FontStyle.Underline ? "underline" : "normal");
}
//public SvgFontSettings(string myFontFamily, string myFontSize, string mySvgStyle, string myFontWeight, string myTextDecoration)
//{
// _FontFamilyName = myFontFamily;
// _FontSize = myFontSize;
// _SVGFontStyle = mySvgStyle;
// _FontWeight = myFontWeight;
// _TextDecoration = myTextDecoration;
//}
#endregion
#region Inheritance
private SvgFontSettings _MyParentsSettings = null;
public SvgFontSettings MyParentsSettings
{
get { return _MyParentsSettings; }
set
{
_MyParentsSettings = value;
}
}
#endregion
#region Internal Inherited Properties
protected string InheritedFontFamily
{
get
{
if (_FontFamily != "") return _FontFamily;
if (_MyParentsSettings != null) return _MyParentsSettings.InheritedFontFamily; // Default
return "Arial"; // Absolute Default
}
}
protected string InheritedFontSize
{
get
{
if (_FontSize != "") return _FontSize; // Current Value
if (_MyParentsSettings != null) return _MyParentsSettings.InheritedFontSize; // Default
return "9PT"; // Absolute Default
}
}
protected string InheritedFontStyle
{
get
{
if (_SVGFontStyle != "") return _SVGFontStyle; // Current Value
if (_MyParentsSettings != null) return _MyParentsSettings.InheritedFontStyle;// Default
return "normal"; // Absolute Default
}
}
protected string InheritedFontWeight
{
get
{
if (_FontWeight != "") return _FontWeight;// Current Value
if (_MyParentsSettings != null) return _MyParentsSettings.InheritedFontWeight;// Default
return "normal"; // Absolute Default
}
}
protected string InheritedTextDecoration
{
get
{
if (_TextDecoration != "") return _TextDecoration;// Current Value
if (_MyParentsSettings != null) return _MyParentsSettings.InheritedTextDecoration;// Default
return "normal"; // Absolute Default
}
}
#endregion
#region Scale
private float _Scale = 1;
internal float Scale
{
get { return _Scale; }
set { _Scale = value; Font = null; }
}
#endregion
#region Inherited Values
private Font _Font=null;
public Font Font
{
get
{
if (_Font == null)
{
_Font = new Font(InheritedFontFamily, _Scale * SvgMeasurement.StringToPoints(InheritedFontSize),
(InheritedFontStyle == "italic" ? FontStyle.Italic : FontStyle.Regular) |
(InheritedFontWeight == "bold" ? FontStyle.Bold : FontStyle.Regular) |
(InheritedTextDecoration == "underline" ? FontStyle.Underline : FontStyle.Regular)
, GraphicsUnit.Point);
}
return _Font;
}
set
{
if (_Font != null) _Font.Dispose();
if (value != null)
{
_FontFamily = value.FontFamily.Name;
_FontSize = value.SizeInPoints.ToString() + "PT";
_SVGFontStyle = ((value.Style & FontStyle.Italic) == FontStyle.Italic ? "italic" : "normal");
_FontWeight = ((value.Style & FontStyle.Bold) == FontStyle.Bold ? "bold" : "normal");
_TextDecoration = ((value.Style & FontStyle.Underline) == FontStyle.Underline ? "underline" : "normal");
}
_Font = value;
}
}
#endregion
#region Public Properties
private string _FontFamily = string.Empty;
public string FontFamily
{
get { return _FontFamily; }
set { _FontFamily = value; Font = null; }
}
private string _FontSize = string.Empty;
public string FontSize
{
get { return _FontSize; }
set { _FontSize = value; Font = null; }
}
private string _SVGFontStyle = string.Empty;
public string SVGFontStyle
{
get { return _SVGFontStyle; }
set { _SVGFontStyle = value; Font = null; }
}
private string _FontWeight = string.Empty;
public string FontWeight
{
get { return _FontWeight; }
set { _FontWeight = value; Font = null; }
}
private string _TextDecoration = string.Empty;
public string TextDecoration
{
get { return _TextDecoration; }
set { _TextDecoration = value; Font = null; }
}
#endregion
}
}

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgGroup : SvgPartInheritance
{
#region Description
private string _Description = string.Empty;
[System.ComponentModel.DefaultValueAttribute("")]
[XmlElement("desc")]
public string Description
{
get { return _Description; }
set { _Description = value; }
}
#endregion
#region Title
private string _Title = string.Empty;
[System.ComponentModel.DefaultValueAttribute("")]
[XmlElement("title")]
public string Title
{
get { return _Title; }
set { _Title = value; }
}
#endregion
#region Parts
// SVG Parts
SvgParts _SvgParts = new SvgParts();
[XmlElement("foreignObject", typeof(SvgRtf))]
[XmlElement("use", typeof(SvgUse))]
[XmlElement("image", typeof(SvgImage))]
[XmlElement("text", typeof(SvgText))]
[XmlElement("line", typeof(SvgLine))]
[XmlElement("circle", typeof(SvgCircle))]
[XmlElement("rect", typeof(SvgRectangle))]
[XmlElement("ellipse", typeof(SvgEllipse))]
[XmlElement("svg", typeof(Svg))]
[XmlElement("g", typeof(SvgGroup))]
[XmlElement("defs", typeof(SvgDefine))]
public SvgParts SvgParts
{
get { return _SvgParts; }
set { _SvgParts = value; }
}
public SvgPart Add(SvgPart svgPart)
{
_SvgParts.Add(svgPart);
return svgPart;
}
public void RemoveAt(int i)
{
_SvgParts.RemoveAt(i);
}
public int Count
{ get { return _SvgParts.Count; } }
#endregion
#region Dictionary of Parts
internal override void AddLookup(Dictionary<string, SvgPart> lookUp)
{
base.AddLookup(lookUp);
SvgParts.AddLookup(lookUp);
}
#endregion
public override string ToString()
{
return ID;
}
}
}

View File

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgImage : SvgPart
{
#region ctor
public SvgImage() { ;}
public SvgImage(PointF location, SizeF size, string path)
{
_X.Value = location.X;
_Y.Value = location.Y;
_Width.Value = size.Width;
_Height.Value = size.Height;
_ImagePath = path;
}
#endregion
#region Location
private SvgMeasurement _X = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement X
{
get { return _X; }
set { _X = value; }
}
[XmlAttribute("x")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string X_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_X); }
set { _X = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Y = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Y
{
get { return _Y; }
set { _Y = value; }
}
[XmlAttribute("y")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Y_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Y); }
set { _Y = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Size
private SvgMeasurement _Width = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Width
{
get { return _Width; }
set { _Width = value; }
}
[XmlAttribute("width")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Width_WidthmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Width); }
set { _Width = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Height = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Height
{
get { return _Height; }
set { _Height = value; }
}
[XmlAttribute("height")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Height_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Height); }
set { _Height = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Path to Image File
private string _ImagePath = null;
[XmlAttribute(AttributeName = "href", Namespace = "http://www.w3.org/1999/xlink")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string ImagePath
{
get { return _ImagePath; }
set { _ImagePath = value; }
}
#endregion
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volian.Svg.Library
{
internal class SvgInheritedSettings
{
#region MyParent
SvgInheritedSettings _MyParentsSettings = null;
internal SvgInheritedSettings MyParentsSettings
{
get { return _MyParentsSettings; }
set
{
_MyParentsSettings = value;
MyLineSettings.MyParentsSettings = value.MyLineSettings;
MyFillSettings.MyParentsSettings = value.MyFillSettings;
MyFontSettings.MyParentsSettings = value.MyFontSettings;
}
}
#endregion
#region Line Settings
private SvgLineSettings _MyLineSettings = new SvgLineSettings();
public SvgLineSettings MyLineSettings
{
get { return _MyLineSettings; }
set { _MyLineSettings = value; }
}
public string Stroke
{
get { return _MyLineSettings.Stroke; }
set { _MyLineSettings.Stroke = value; }
}
public string StrokeWidth
{
get { return _MyLineSettings.StrokeWidth; }
set { _MyLineSettings.StrokeWidth = value; }
}
#endregion
#region Fill Settings
private SvgFillSettings _MyFillSettings = new SvgFillSettings();
internal SvgFillSettings MyFillSettings
{
get { return _MyFillSettings; }
set { _MyFillSettings = value; }
}
public string Fill
{
get { return _MyFillSettings.Fill; }
set { _MyFillSettings.Fill = value; }
}
#endregion
#region Font Settings
private SvgFontSettings _MyFontSettings = new SvgFontSettings();
internal SvgFontSettings MyFontSettings
{
get { return _MyFontSettings; }
set { _MyFontSettings = value; }
}
public string FontFamily
{
get { return _MyFontSettings.FontFamily; }
set { _MyFontSettings.FontFamily = value; }
}
public string FontSize
{
get { return _MyFontSettings.FontSize; }
set { _MyFontSettings.FontSize = value; }
}
public string SVGFontStyle
{
get { return _MyFontSettings.SVGFontStyle; }
set { _MyFontSettings.SVGFontStyle = value; }
}
public string FontWeight
{
get { return _MyFontSettings.FontWeight; }
set { _MyFontSettings.FontWeight = value; }
}
public string TextDecoration
{
get { return _MyFontSettings.TextDecoration; }
set { _MyFontSettings.TextDecoration = value; }
}
#endregion
}
}

View File

@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgLine : SvgLinePart
{
#region ctor
public SvgLine() { ;}
public SvgLine(PointF location1, PointF location2, Color lineColor, float lineWidth)
{
_X1.Value = location1.X;
_Y1.Value = location1.Y;
_X2.Value = location2.X;
_Y2.Value = location2.Y;
LineColor = lineColor;
LineWidth = new SvgMeasurement(lineWidth);
}
//XMLElementAttribute(ElementName = "PREFIX", IsNullable = false)
#endregion
#region Location1
private SvgMeasurement _X1 = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement X1
{
get { return _X1; }
set { _X1 = value; }
}
[XmlAttribute("x1")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string X1_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_X1); }
set { _X1 = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Y1 = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Y1
{
get { return _Y1; }
set { _Y1 = value; }
}
[XmlAttribute("y1")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Y1_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Y1); }
set { _Y1 = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Location2
private SvgMeasurement _X2 = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement X2
{
get { return _X2; }
set { _X2 = value; }
}
[XmlAttribute("x2")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string X2_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_X2); }
set { _X2 = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Y2 = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Y2
{
get { return _Y2; }
set { _Y2 = value; }
}
[XmlAttribute("y2")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Y_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Y2); }
set { _Y2 = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region LineColor
//protected Color _LineColor = Color.Empty;
//[XmlIgnoreAttribute()]
//public Color LineColor
//{
// get { return _LineWidth.Value == 0 ? Color.LightGray : _LineColor == Color.Empty ? Color.Gray : _LineColor; }
// set { _LineColor = value; }
//}
private Color AdjustColorForWidth(Color myColor, float myWidth)
{
if (myWidth > 1F) return myColor;
//Console.WriteLine("Line Width = {0}, Alpha = {1}", myWidth, Convert.ToInt32(myWidth * 255));
return Color.FromArgb(Convert.ToInt32(myWidth * 255), myColor);
}
// Serializes the 'BackgroundColor' Color to XML.
//[System.ComponentModel.DefaultValueAttribute("none")]
//[XmlAttribute("stroke")]
//public string Stroke
//{
// get { return _LineColor == Color.Empty ? "none" : _LineColor == Color.Black ? "" : ColorTranslator.ToHtml(_LineColor); }
// set { _LineColor = (value == "none" ? Color.Empty : (value == "" ? Color.Empty : ColorTranslator.FromHtml(value))); }
//}
#endregion
#region LineWidth
//private SvgMeasurement GetLineWidth()
//{
// if (_LineWidth.Value == -1) return new SvgMeasurement(1F);// Minimum Strokewidth
// if (_LineWidth.Value == 0) return new SvgMeasurement(.01F);// Minimum Strokewidth
// if (_LineColor == Color.Empty) return new SvgMeasurement( .01F);// No Color - Minimum Strokewidth
// return _LineWidth;
//}
//private SvgMeasurement _LineWidth = new SvgMeasurement();
//[XmlIgnore]
//public SvgMeasurement LineWidth
//{
// get { return _LineWidth; }
// set { _LineWidth = value; }
//}
//[XmlAttribute("stroke-width")]
//[Browsable(false)]
//[EditorBrowsable(EditorBrowsableState.Never)]
//public string LineWidth_XmlSurrogate
//{
// get
// {
// if (_LineWidth.Value == -1)
// return "none";
// return VolianXmlConverter<SvgMeasurement>.GetString(_LineWidth);
// }
// set
// {
// if (value == "none")
// _LineWidth = VolianXmlConverter<SvgMeasurement>.GetObject("-1");
// else
// _LineWidth = VolianXmlConverter<SvgMeasurement>.GetObject(value);
// }
//}
#endregion
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;
using System.ComponentModel;
namespace Volian.Svg.Library
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public abstract class SvgLinePart : SvgPart
{
#region Line Settings
protected SvgLineSettings _MyLineSettings = new SvgLineSettings();
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("stroke")]
public string Stroke
{
get { return _MyLineSettings.Stroke; }
set { _MyLineSettings.Stroke = value; }
}
[XmlIgnore]
protected Color LineColor
{
get { return _MyLineSettings.LineColor; }
set { _MyLineSettings.LineColor = value; }
}
[XmlIgnore]
protected Color OutlineColor
{
get { return _MyLineSettings.OutlineColor; }
set { _MyLineSettings.OutlineColor = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("stroke-width")]
public string StrokeWidth
{
get { return _MyLineSettings.StrokeWidth; }
set { _MyLineSettings.StrokeWidth = value; }
}
[XmlIgnore]
protected SvgMeasurement LineWidth
{
get { return _MyLineSettings.LineWidth; }
set { _MyLineSettings.LineWidth = value; }
}
[XmlIgnore]
protected SvgMeasurement OutlineWidth
{
get { return _MyLineSettings.OutlineWidth; }
set { _MyLineSettings.OutlineWidth = value; }
}
#endregion
#region Setup Inheritance
override internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
{
_MyLineSettings.MyParentsSettings = myParentsSettings.MyLineSettings;
}
#endregion
}
}

View File

@ -0,0 +1,167 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Xml.Serialization;
namespace Volian.Svg.Library
{
public class SvgLineSettings
{
#region ctor
public SvgLineSettings() { ;}
public SvgLineSettings(Color myColor, SvgMeasurement myWidth)
{
_Stroke = ColorTranslator.ToHtml(myColor);
_StrokeWidth = myWidth.ToString();
}
//public SvgLineSettings(string myStroke, string myStrokeWidth)
//{
// _Stroke = myStroke;
// _StrokeWidth = myStrokeWidth;
//}
#endregion
#region Inheritance
private SvgLineSettings _MyParentsSettings = null;
public SvgLineSettings MyParentsSettings
{
get { return _MyParentsSettings; }
set
{
_MyParentsSettings = value;
}
}
#endregion
#region Internal Inherited Properties
protected string InheritedStroke
{
get
{
// Stroke = "", "0" - Default, otherwise the value
if (_Stroke != "" && _Stroke != "0") return _Stroke; // Current Value
if (_MyParentsSettings != null) return _MyParentsSettings.InheritedStroke;// Inherited
return "None"; // Default
}
}
protected string InheritedLineWidth
{
get
{
// StrokeWidth = "", "none" - Default, otherwise the value
if (_StrokeWidth != "" && _StrokeWidth != "none") return _StrokeWidth; // Current Value
if (_MyParentsSettings != null) return _MyParentsSettings.InheritedLineWidth; // Inherited
return "1PX"; // Default
}
}
//protected string InheritedOutlineWidth
//{
// get
// {
// // StrokeWidth = "", "none" - Default, otherwise the value
// if (_StrokeWidth != "" && _StrokeWidth.ToLower() != "none") return _StrokeWidth; // Current Value
// if (_MyParent != null) return _MyParent.InheritedLineWidth; // Inherited
// return "1PX"; // Default
// }
//}
#endregion
#region Inherited Values
public SvgMeasurement LineWidth
{
get
{
// Stroke = "None" - Light, otherwise the value
// StrokeWidth = "None" Light, otherwise the value
string myStroke = InheritedStroke;
string myWidth = InheritedLineWidth;
//if (myStroke.ToLower() == "none" || myWidth.ToLower() == "none") // Light
// return new SvgMeasurement(.001F, E_MeasurementUnits.PX);
SvgMeasurement myMeasurement = new SvgMeasurement(myWidth);
//myMeasurement.Value *= _Scale;
return myMeasurement;
}
set
{
_StrokeWidth = value.ToString();
}
}
public SvgMeasurement OutlineWidth
{
get
{
// Stroke = "None" - Eliminate, otherwise the value
// StrokeWidth = "0" Eliminate, otherwise the value
string myStroke = InheritedStroke;
//string myWidth = InheritedOutlineWidth;
string myWidth = InheritedLineWidth;
if (myStroke.ToLower() == "none" || myWidth == "0") // Eliminate
return new SvgMeasurement(0, E_MeasurementUnits.PX);
SvgMeasurement myMeasurement = new SvgMeasurement(myWidth);
//myMeasurement.Value *= _Scale;
return myMeasurement;
}
set
{
_StrokeWidth = value.ToString();
}
}
public Color LineColor
{
get
{
// Stroke = "None" - Eliminate, otherwise the value
// StrokeWidth = "None" Eliminate, otherwise the value
string myStroke = InheritedStroke;
string myWidth = InheritedLineWidth;
if (myStroke.ToLower() == "none" || myWidth.ToLower() == "none" || myWidth == "0") // Light
return Color.LightGray;
return ColorTranslator.FromHtml(myStroke);
}
set
{
if (value == Color.Empty)
_Stroke = "none";
else
_Stroke = ColorTranslator.ToHtml(value);
}
}
public Color OutlineColor
{
get
{
// Stroke = "None" - Eliminate, otherwise the value
// StrokeWidth = "0" Eliminate, otherwise the value
string myStroke = InheritedStroke;
//string myWidth = InheritedOutlineWidth;
string myWidth = InheritedLineWidth;
if (myStroke.ToLower() == "none" || myWidth == "0") // Eliminate
return Color.Empty;
return ColorTranslator.FromHtml(myStroke);
}
set
{
if (value == Color.Empty)
_Stroke = "none";
else
_Stroke = ColorTranslator.ToHtml(value);
}
}
#endregion
#region Properties
private string _Stroke = string.Empty; // Default value is None
public string Stroke
{
get { return _Stroke; }
set { _Stroke = value; }
}
private string _StrokeWidth = string.Empty; // Default value is 1PX
public string StrokeWidth
{
get { return _StrokeWidth; }
set { _StrokeWidth = value; }
}
#endregion
}
}

View File

@ -0,0 +1,250 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace Volian.Svg.Library
{
[TypeConverter(typeof(MeasurementTypeConverter))]
public class SvgMeasurement
{
#region Operators
public static SvgMeasurement operator +(SvgMeasurement x1, SvgMeasurement x2)
{
E_MeasurementUnits tmpUnits = x1.Units;
SvgMeasurement tmp = new SvgMeasurement(x1.GetSizeInPoints(DPI) + x2.GetSizeInPoints(DPI),E_MeasurementUnits.PT);
tmp.Units = x1.Units;
return tmp;
}
public static SvgMeasurement operator -(SvgMeasurement x1, SvgMeasurement x2)
{
E_MeasurementUnits tmpUnits = x1.Units;
SvgMeasurement tmp = new SvgMeasurement(x1.GetSizeInPoints(DPI) - x2.GetSizeInPoints(DPI), E_MeasurementUnits.PT);
tmp.Units = x1.Units;
return tmp;
}
public static SvgMeasurement operator *(SvgMeasurement x1, float scaler)
{
E_MeasurementUnits tmpUnits = x1.Units;
SvgMeasurement tmp = new SvgMeasurement(x1.GetSizeInPoints(DPI) * scaler, E_MeasurementUnits.PT);
tmp.Units = x1.Units;
return tmp;
}
public static SvgMeasurement operator *(float scaler, SvgMeasurement x1)
{
E_MeasurementUnits tmpUnits = x1.Units;
SvgMeasurement tmp = new SvgMeasurement(x1.GetSizeInPoints(DPI) * scaler, E_MeasurementUnits.PT);
tmp.Units = x1.Units;
return tmp;
}
#endregion
#region DPI
private static float _DPI;
public static float DPI
{
get
{
if (_DPI == 0)
_DPI = 96;
return _DPI;
}
}
#endregion
#region ctor
public SvgMeasurement() { ;}
public SvgMeasurement(int value)
{
_Value = Convert.ToSingle(value);
_Units = E_MeasurementUnits.PX;
}
public SvgMeasurement(float value)
{
_Value = value;
_Units = E_MeasurementUnits.PX;
}
public SvgMeasurement(float value, E_MeasurementUnits units)
{
_Value = value;
_Units = units;
}
public SvgMeasurement(string val)
{
MatchCollection mc = Regex.Matches(val.ToLower(), "([+-]?[.0-9]+)|(in|cm|mm|em|ex|pc|pt|px|percentage)");
_Value = Convert.ToSingle(mc[0].Value);
if (mc.Count == 2)
{
//Console.WriteLine("{0} - '{1}'", val, mc[1].Value.ToUpper());
_Units = (E_MeasurementUnits)Enum.Parse(typeof(E_MeasurementUnits), mc[1].Value.ToUpper());
}
else
_Units = E_MeasurementUnits.PX;
}
#endregion
#region Properties
private E_MeasurementUnits _Units;
public E_MeasurementUnits Units
{
get { return _Units; }
set
{
float tmp = GetSizeInPoints(DPI);
_Units = value;
_Value *= (tmp / GetSizeInPoints(DPI));
}
}
private float _Value;
public float Value
{
get { return _Value; }
set { _Value = value; }
}
#endregion
#region ToString
public override string ToString()
{
switch (_Units)
{
case E_MeasurementUnits.PX: // Default
return string.Format("{0}", _Value);
case E_MeasurementUnits.PERCENTAGE: // Precentage is preceded by a space
return string.Format("{0} {1}", _Value, _Units);
}
return string.Format("{0}{1}", _Value, _Units);
}
#endregion
//public float SizeInPixels
//{
// get
// {
// switch (_Units)
// {
// case E_MeasurementUnits.PT: //Points - 72 per inch
// return _Value * DPI / 72F;
// case E_MeasurementUnits.PC: //Picas - 6 per inch
// return _Value * DPI / 6F;
// case E_MeasurementUnits.IN: //inches
// return _Value * DPI;
// case E_MeasurementUnits.CM: // Centimeter
// return _Value * DPI / 2.54F;
// case E_MeasurementUnits.MM: // Millimeter
// return _Value * DPI / 25.4F;
// case E_MeasurementUnits.EM: // EMs
// return _Value * DPI / 8;
// case E_MeasurementUnits.EX: // EXs
// return _Value * DPI / 16;
// default:
// return _Value;
// }
// }
//}
public float GetSizeInPoints(float myDPI)
{
switch (_Units)
{
case E_MeasurementUnits.PX: //Pixels myDPI per inch
return _Value * 72F / myDPI;
case E_MeasurementUnits.PC: //Picas - 6 per inch
return _Value * 72F / 6F;
case E_MeasurementUnits.IN: //inches
return _Value * 72F;
case E_MeasurementUnits.CM: // Centimeter
return _Value * 72F / 2.54F;
case E_MeasurementUnits.MM: // Millimeter
return _Value * 72F / 25.4F;
case E_MeasurementUnits.EM: // EMs
return _Value * 72F / 8;
case E_MeasurementUnits.EX: // EXs
return _Value * 72F / 16;
default: // Points
return _Value;
}
}
//public float SizeInPoints
//{ get { return SizeInPixels * 72 / DPI; } }
//public float SizeInInches
//{ get { return SizeInPixels / DPI; } }
//public float SizeInCentimeters
//{ get { return SizeInPixels * 2.54F / DPI; } }
//public float SizeInMillimeters
//{ get { return SizeInPixels * 25.4F / DPI; } }
//public float SizeInEms
//{ get { return SizeInPixels * 5 / (6 * DPI); } }
//public float SizeInExs
//{ get { return SizeInPixels * 5 / (6 * DPI); } }
//public float SizeInPicas
//{ get { return SizeInPixels * 6 / DPI; } }
//public Unit SizeInUnits
//{ get { return new Unit((double)SizeInPoints, UnitTypeEnum.Point); } }
public float GetSizeInPixels(float myDPI)
{ return GetSizeInPoints(myDPI) * myDPI / 72F;}
public float GetSizeInInches(float myDPI)
{ return GetSizeInPoints(myDPI) / 72F; }
public float GetSizeInCentimeters(float myDPI)
{ return GetSizeInPoints(myDPI) * 2.54F / 72F; }
public float GetSizeInMillimeters(float myDPI)
{ return GetSizeInPoints(myDPI) * 25.4F / 72F; }
public float GetSizeInEms(float myDPI)
{ return GetSizeInPoints(myDPI) * 5 / (6 * 72F); }
public float GetSizeInExs(float myDPI)
{ return GetSizeInPoints(myDPI) * 5 / (6 * 72F); }
public float GetSizeInPicas(float myDPI)
{ return GetSizeInPoints(myDPI) * 6 / 72F; }
//public Unit GetSizeInUnits(float myDPI)
//{ return new Unit((double)GetSizeInPoints(myDPI), UnitTypeEnum.Point); }
public static float StringToPoints(string value)
{
SvgMeasurement tmp = new SvgMeasurement(value);
float myPoints = tmp.GetSizeInPoints(72);
return myPoints;
}
}
public enum E_MeasurementUnits : int
{
[Description("Pixels")]
PX,
[Description("Points")]
PT,
[Description("Inches")]
IN,
[Description("Centimeters")]
CM,
[Description("Millimeters")]
MM,
[Description("EMs")]
EM,
[Description("EXs")]
EX,
[Description("Percentage")]
PERCENTAGE,
[Description("Picas")]
PC
}
public class MeasurementTypeConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type t)
{
return t == typeof(String);
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is SvgMeasurement)
{
return value.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type t)
{
return t == typeof(String);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object val)
{
SvgMeasurement measurement = new SvgMeasurement((string)val);
return measurement;
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.IO;
using System.Xml.Serialization;
using System.Drawing;
using System.ComponentModel;
using System.Collections.Generic;
namespace Volian.Svg.Library
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public abstract partial class SvgPart
{
#region ID
protected string _ID = string.Empty;
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("id")]
public string ID
{
get { return _ID; }
set { _ID = value; }
}
#endregion
//#region Parent and Containing Svg
//// ToDo: MyParent
//private SvgPartGrouping _MyParent;
//[XmlIgnore()]
//public SvgPartGrouping MyParent
//{
// get { return _MyParent; }
// set { _MyParent = value; }
//}
//// ToDo: MySvg
//private Svg _MySvg;
//public Svg MySvg
//{
// get { return _MySvg; }
// set { _MySvg = value; }
//}
//internal void SetParent(SvgPartGrouping myParent)
//{
// _MyParent = myParent;
// _MySvg = myParent.MySvg == null? MyParent : myParent.MySvg;
//}
//#endregion
#region Setup Inheritance
virtual internal void SetupInheritance(SvgInheritedSettings myParentsSettings) { ; }
#endregion
#region Dictionary of Parts
internal virtual void AddLookup(Dictionary<string, SvgPart> lookUp)
{
if (_ID != string.Empty && !lookUp.ContainsKey(_ID))
lookUp.Add(_ID, this);
}
#endregion
}
}

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgPartInheritance : SvgPart
{
#region InheritedSettings
internal SvgInheritedSettings _MyInheritedSettings = new SvgInheritedSettings();
[XmlIgnore()]
internal SvgInheritedSettings MyInheritedSettings
{
get { return _MyInheritedSettings; }
set { _MyInheritedSettings = value; }
}
#region Line Settings
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("stroke")]
public string Stroke
{
get { return _MyInheritedSettings.Stroke; }
set { _MyInheritedSettings.Stroke = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("stroke-width")]
public string StrokeWidth
{
get { return _MyInheritedSettings.StrokeWidth; }
set { _MyInheritedSettings.StrokeWidth = value; }
}
#endregion
#region Fill Settings
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("fill")]
public string Fill
{
get { return _MyInheritedSettings.Fill; }
set { _MyInheritedSettings.Fill = value; }
}
#endregion
#region Font Settings
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-family")]
public string FontFamily
{
get { return _MyInheritedSettings.FontFamily; }
set { _MyInheritedSettings.FontFamily = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-size")]
public string FontSize
{
get { return _MyInheritedSettings.FontSize; }
set { _MyInheritedSettings.FontSize = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-style")]
public string SVGFontStyle
{
get { return _MyInheritedSettings.SVGFontStyle; }
set { _MyInheritedSettings.SVGFontStyle = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-weight")]
public string FontWeight
{
get { return _MyInheritedSettings.FontWeight; }
set { _MyInheritedSettings.FontWeight = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("text-decoration")]
public string TextDecoration
{
get { return _MyInheritedSettings.TextDecoration; }
set { _MyInheritedSettings.TextDecoration = value; }
}
#endregion
#endregion
#region Setup Inheritance
override internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
{
_MyInheritedSettings.MyParentsSettings = myParentsSettings;
//_SvgParts.SetupInheritance(_MyInheritedSettings);
}
#endregion
}
}

View File

@ -0,0 +1,394 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.ComponentModel;
using System.Text;
namespace Volian.Svg.Library
{
/// <summary>
/// <para>
/// A collection that stores <see cref='SVGPart'/> objects.
/// </para>
/// </summary>
/// <seealso cref='SVGPart'/>
[Serializable()]
[TypeConverter(typeof(SVGPartsConverter))]
public partial class SvgParts : CollectionBase, ICustomTypeDescriptor
{
/// <summary>Notifies when the collection has been modified.</summary>
public event EventHandler OnItemsChanged;
/// <summary>Notifies that an item has been added.</summary>
public event SVGPartHandler OnItemAdd;
/// <summary>Notifies that items have been added.</summary>
public event SVGPartHandler OnItemsAdd;
/// <summary>Notifies that an item has been removed.</summary>
public event SVGPartHandler OnItemRemove;
/// <summary>
/// <para>
/// Initializes a new instance of <see cref='SVGPart'/>.
/// </para>
/// </summary>
public SvgParts()
{
}
/// <summary>
/// <para>
/// Initializes a new instance of <see cref='SVGPart'/> based on another <see cref='SVGPart'/>.
/// </para>
/// </summary>
/// <param name='value'>
/// A <see cref='SVGPart'/> from which the contents are copied
/// </param>
public SvgParts(SvgParts value)
{
this.AddRange(value);
}
/// <summary>
/// <para>
/// Initializes a new instance of <see cref='SVGPart'/> containing any array of <see cref='SVGPart'/> objects.
/// </para>
/// </summary>
/// <param name='value'>
/// A array of <see cref='SVGPart'/> objects with which to intialize the collection
/// </param>
public SvgParts(SvgPart[] value)
{
this.AddRange(value);
}
/// <summary>
/// <para>Represents the entry at the specified index of the <see cref='SVGPart'/>.</para>
/// </summary>
/// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
/// <value>
/// <para> The entry at the specified index of the collection.</para>
/// </value>
/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
public SvgPart this[int index]
{
get { return ((SvgPart)(List[index])); }
set { List[index] = value; }
}
//#region SetupInheritance
//internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
//{
// foreach (SvgPart svgPart in List)
// svgPart.SetupInheritance(myParentsSettings);
//}
//#endregion
#region Dictionary of Parts
internal void AddLookup(Dictionary<string, SvgPart> lookUp)
{
foreach (SvgPart svgPart in List)
svgPart.AddLookup(lookUp);
}
#endregion
internal static void ShowException(Exception ex)
{
StringBuilder sb = new StringBuilder();
string sep = "";
for (Exception ex1 = ex; ex1 != null; ex1 = ex1.InnerException)
{
sb.Append(sep + string.Format("{0} - {1}", ex1.GetType().Name, ex1.Message));
sep = "\r\n";
}
Console.WriteLine(sb);
}
/// <summary>
/// <para>Adds a <see cref='SVGPart'/> with the specified value to the
/// <see cref='SVGPart'/> .</para>
/// </summary>
/// <param name='value'>The <see cref='SVGPart'/> to add.</param>
/// <returns>
/// <para>The index at which the new element was inserted.</para>
/// </returns>
/// <seealso cref='SVGParts.AddRange'/>
public int Add(SvgPart value)
{
int ndx = List.Add(value);
if (OnItemAdd != null) { OnItemAdd(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
return ndx;
}
/// <summary>
/// <para>Copies the elements of an array to the end of the <see cref='SVGPart'/>.</para>
/// </summary>
/// <param name='value'>
/// An array of type <see cref='SVGPart'/> containing the objects to add to the collection.
/// </param>
/// <returns>
/// <para>None.</para>
/// </returns>
/// <seealso cref='SVGParts.Add'/>
public void AddRange(SvgPart[] value)
{
for (int i = 0; i < value.Length; i++)
{
this.Add(value[i]);
}
if (OnItemsAdd != null) { OnItemsAdd(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
}
/// <summary>
/// <para>
/// Adds the contents of another <see cref='SVGPart'/> to the end of the collection.
/// </para>
/// </summary>
/// <param name='value'>
/// A <see cref='SVGPart'/> containing the objects to add to the collection.
/// </param>
/// <returns>
/// <para>None.</para>
/// </returns>
/// <seealso cref='SVGParts.Add'/>
public void AddRange(SvgParts value)
{
for (int i = 0; i < value.Count; i++)
{
this.Add(value[i]);
}
if (OnItemsAdd != null) { OnItemsAdd(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
}
/// <summary>
/// <para>Gets a value indicating whether the
/// <see cref='SVGPart'/> contains the specified <see cref='SVGPart'/>.</para>
/// </summary>
/// <param name='value'>The <see cref='SVGPart'/> to locate.</param>
/// <returns>
/// <para><see langword='true'/> if the <see cref='SVGPart'/> is contained in the collection;
/// otherwise, <see langword='false'/>.</para>
/// </returns>
/// <seealso cref='SVGParts.IndexOf'/>
public bool Contains(SvgPart value)
{
return List.Contains(value);
}
/// <summary>
/// <para>Copies the <see cref='SVGPart'/> values to a one-dimensional <see cref='System.Array'/> instance at the
/// specified index.</para>
/// </summary>
/// <param name='array'><para>The one-dimensional <see cref='System.Array'/> that is the destination of the values copied from <see cref='SVGPart'/> .</para></param>
/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
/// <returns>
/// <para>None.</para>
/// </returns>
/// <exception cref='System.ArgumentException'><para><paramref name='array'/> is multidimensional.</para> <para>-or-</para> <para>The number of elements in the <see cref='SVGPart'/> is greater than the available space between <paramref name='arrayIndex'/> and the end of <paramref name='array'/>.</para></exception>
/// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
/// <seealso cref='System.Array'/>
public void CopyTo(SvgPart[] array, int index)
{
List.CopyTo(array, index);
}
/// <summary>
/// <para>Returns the index of a <see cref='SVGPart'/> in
/// the <see cref='SVGPart'/> .</para>
/// </summary>
/// <param name='value'>The <see cref='SVGPart'/> to locate.</param>
/// <returns>
/// <para>The index of the <see cref='SVGPart'/> of <paramref name='value'/> in the
/// <see cref='SVGPart'/>, if found; otherwise, -1.</para>
/// </returns>
/// <seealso cref='SVGParts.Contains'/>
public int IndexOf(SvgPart value)
{
return List.IndexOf(value);
}
/// <summary>
/// <para>Inserts a <see cref='SVGPart'/> into the <see cref='SVGParts'/> at the specified index.</para>
/// </summary>
/// <param name='index'>The zero-based index where <paramref name='value'/> should be inserted.</param>
/// <param name=' value'>The <see cref='SVGPart'/> to insert.</param>
/// <returns><para>None.</para></returns>
/// <seealso cref='SVGParts.Add'/>
public void Insert(int index, SvgPart value)
{
List.Insert(index, value);
if (OnItemAdd != null) { OnItemAdd(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
}
/// <summary>
/// <para> Removes a specific <see cref='SVGPart'/> from the
/// <see cref='SVGParts'/> .</para>
/// </summary>
/// <param name='value'>The <see cref='SVGPart'/> to remove from the <see cref='SVGParts'/> .</param>
/// <returns><para>None.</para></returns>
/// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>
public void Remove(SvgPart value)
{
List.Remove(value);
if (OnItemRemove != null) { OnItemRemove(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
}
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
/// <summary>
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
/// </summary>
/// <param name="attributes"></param>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
/// <summary>
/// Called to get the properties of this type.
/// </summary>
/// <returns></returns>
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
SvgPartsPropertyDescriptor pd = new SvgPartsPropertyDescriptor(this, i);
pds.Add(pd);
}
// return the property descriptor collection
return pds;
}
#endregion
/// Event arguments for the SVGParts collection class.
public class SVGPartArgs : EventArgs
{
private SvgParts t;
/// Default constructor.
public SVGPartArgs()
{
t = new SvgParts();
}
/// Initializes with a SVGPart.
/// Data object.
public SVGPartArgs(SvgPart t)
: this()
{
this.t.Add(t);
}
/// Initializes with a collection of SVGPart objects.
/// Collection of data.
public SVGPartArgs(SvgParts ts)
: this()
{
this.t.AddRange(ts);
}
/// Initializes with an array of SVGPart objects.
/// Array of data.
public SVGPartArgs(SvgPart[] ts)
: this()
{
this.t.AddRange(ts);
}
/// Gets or sets the data of this argument.
public SvgParts SVGParts
{
get { return t; }
set { t = value; }
}
}
/// SVGParts event handler.
public delegate void SVGPartHandler(object sender, SVGPartArgs e);
#region Property Descriptor
/// <summary>
/// Summary description for CollectionPropertyDescriptor.
/// </summary>
public partial class SvgPartsPropertyDescriptor : vlnListPropertyDescriptor
{
private SvgPart Item { get { return (SvgPart)_Item; } }
public SvgPartsPropertyDescriptor(SvgParts collection, int index) : base(collection, index) { ;}
public override string DisplayName
{ get { return Item.GetType().Name; } }
}
#endregion
[Serializable()]
public partial class vlnListPropertyDescriptor : PropertyDescriptor
{
protected object _Item = null;
public vlnListPropertyDescriptor(System.Collections.IList collection, int index)
: base("#" + index.ToString(), null)
{ _Item = collection[index]; }
public override bool CanResetValue(object component)
{ return true; }
public override Type ComponentType
{ get { return _Item.GetType(); } }
public override object GetValue(object component)
{ return _Item; }
public override bool IsReadOnly
{ get { return false; } }
public override Type PropertyType
{ get { return _Item.GetType(); } }
public override void ResetValue(object component)
{ ;}
public override bool ShouldSerializeValue(object component)
{ return true; }
public override void SetValue(object component, object value)
{ /*_Item = value*/;}
//public override AttributeCollection Attributes
//{ get { return new AttributeCollection(null); } }
public override string DisplayName
{ get { return _Item.ToString(); } }
public override string Description
{ get { return _Item.ToString(); } }
public override string Name
{ get { return _Item.ToString(); } }
} // Class
#region Converter
internal class SVGPartsConverter : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is SvgParts)
{
// Return department and department role separated by comma.
return ((SvgParts)value).List.Count.ToString() + " SVG Drawing Parts";
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
}
}

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgRectangle : SvgShapePart
{
#region ctor
public SvgRectangle() { ;}
public SvgRectangle(PointF location, SizeF size, Color fillColor, Color lineColor, float lineWidth)
{
_X.Value = location.X;
_Y.Value = location.Y;
_Width.Value = size.Width;
_Height.Value = size.Height;
FillColor = fillColor;
LineColor = lineColor;
LineWidth = new SvgMeasurement(lineWidth);
}
//XMLElementAttribute(ElementName = "PREFIX", IsNullable = false)
#endregion
#region Location
private SvgMeasurement _X = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement X
{
get { return _X; }
set { _X = value; }
}
[XmlAttribute("x")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string X_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_X); }
set { _X = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Y = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Y
{
get { return _Y; }
set { _Y = value; }
}
[XmlAttribute("y")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Y_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Y); }
set { _Y = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Size
private SvgMeasurement _Width = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Width
{
get { return _Width; }
set { _Width = value; }
}
[XmlAttribute("width")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Width_WidthmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Width); }
set { _Width = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Height = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Height
{
get { return _Height; }
set { _Height = value; }
}
[XmlAttribute("height")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Height_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Height); }
set { _Height = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
}
}

View File

@ -0,0 +1,164 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using System.ComponentModel;
namespace Volian.Svg.Library
{
public partial class SvgRtf : SvgShapePart
{
#region ctor
public SvgRtf() { ;}
public SvgRtf(PointF location, float width, string rtf, Font font, Color fillColor)
{
_X.Value = location.X;
_Y.Value = location.Y;
_Width.Value = width;
Rtf = rtf;
Font = font;
FillColor = fillColor;
LineColor = Color.Empty;
LineWidth = new SvgMeasurement(0);
}
#endregion
#region Location
private SvgMeasurement _X = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement X
{
get { return _X; }
set { _X = value; }
}
[XmlAttribute("x")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string X_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_X); }
set { _X = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Y = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Y
{
get { return _Y; }
set { _Y = value; }
}
[XmlAttribute("y")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Y_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Y); }
set { _Y = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Size
private SvgMeasurement _Width = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Width
{
get { return _Width; }
set { _Width = value; }
}
[XmlAttribute("width")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Width_WidthmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Width); }
set { _Width = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Height = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Height
{
get { return _Height; }
set { _Height = value; }
}
[XmlAttribute("height")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Height_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Height); }
set { _Height = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Rtf
private string _Rtf;
[XmlText()]
public string Rtf
{
get { return _Rtf; }
set { _Rtf = value; }
}
#endregion
#region Required Extensions
private string _RequiredExtensions = "http://Volian.Com/EmbeddedRTF";
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[XmlAttribute("requiredExtensions")]
public string RequiredExtensions
{
get { return _RequiredExtensions; }
set { _RequiredExtensions = value; }
}
#endregion
#region Font Settings
private SvgFontSettings _MyFontSettings = new SvgFontSettings();
[XmlIgnore]
public Font Font
{
get { return _MyFontSettings.Font; }
set { _MyFontSettings.Font = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-family")]
public string FontFamily
{
get { return _MyFontSettings.FontFamily; }
set { _MyFontSettings.FontFamily = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-size")]
public string FontSize
{
get { return _MyFontSettings.FontSize; }
set { _MyFontSettings.FontSize = value; }
}
[System.ComponentModel.DefaultValueAttribute("normal")]
[XmlAttribute("font-style")]
public string SVGFontStyle
{
get { return _MyFontSettings.SVGFontStyle; }
set { _MyFontSettings.SVGFontStyle = value; }
}
[System.ComponentModel.DefaultValueAttribute("normal")]
[XmlAttribute("font-weight")]
public string FontWeight
{
get { return _MyFontSettings.FontWeight; }
set { _MyFontSettings.FontWeight = value; }
}
[System.ComponentModel.DefaultValueAttribute("normal")]
[XmlAttribute("text-decoration")]
public string TextDecoration
{
get { return _MyFontSettings.TextDecoration; }
set { _MyFontSettings.TextDecoration = value; }
}
#endregion
#region Setup Inheritance
override internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
{
base.SetupInheritance(myParentsSettings);
_MyFontSettings.MyParentsSettings = myParentsSettings.MyFontSettings;
}
#endregion
}
}

View File

@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace Volian.Svg.Library
{
public class SvgScale
{
private float _XLowerLimit;
public float XLowerLimit
{
get { return _XLowerLimit; }
set { _XLowerLimit = value; }
}
private float _YLowerLimit;
public float YLowerLimit
{
get { return _YLowerLimit; }
set { _YLowerLimit = value; }
}
private float _Scale; // Scale from Logical to Physical
public float Scale
{ get { return _Scale; } }
private float _Width; // Physical Width
public float Width
{ get { return _Width; } }
private float _Height; // Physical Height
public float Height
{ get { return _Height; } }
public float XUpperLimit
{ get { return _Width * _Scale + _XLowerLimit; } }
public float YUpperLimit
{ get { return _Height * _Scale + _YLowerLimit; } }
private float _DPI;
public float DPI
{ get { return _DPI; } }
private SvgScale(SvgScale tmp,SvgMeasurement newX, SvgMeasurement newY)
{
_DPI = tmp.DPI;
_Scale = tmp.Scale;
_Width = tmp.Width;
_Height = tmp.Height;
_XLowerLimit = tmp.XLowerLimit - newX.GetSizeInPixels(DPI);
_YLowerLimit = tmp.YLowerLimit - newY.GetSizeInPixels(DPI);
}
public SvgScale(float myDPI, RectangleF bounds,SvgMeasurement width, SvgMeasurement height, SvgViewBox myViewBox)
{
// TODO: Should I convert to pixels or something fixed (Inches, Points, Picas, CMs, MMs, Twips)
_DPI = myDPI;
float outputWidth = width.GetSizeInPixels(100);
if(outputWidth == 0) outputWidth = bounds.Width;
float outputHeight = height.GetSizeInPixels(100);
if (outputHeight == 0) outputHeight = bounds.Height;
float inputWidth = myViewBox.Width;
if (inputWidth == 0) inputWidth = outputWidth;
float scalex = outputWidth / inputWidth;
float inputHeight = myViewBox.Height;
if (inputHeight == 0) inputHeight = outputHeight;
float scaley = outputHeight / inputHeight;
_Scale = (scalex < scaley) ? scaley : scalex;
//Console.WriteLine("'Scale',{0}",_Scale);
_Width = outputWidth / _Scale;
_Height = outputHeight / _Scale;
_XLowerLimit = myViewBox.X + (inputWidth - _Width) / 2;
_YLowerLimit = myViewBox.Y + (inputHeight - _Height) / 2;
//if (myDPI != 96) Console.WriteLine("DPI {0}", myDPI);
//Console.WriteLine("Scale,{0},{1},{2},{3},{4},{5},{6}", Scale, Width, Height, XLowerLimit, XUpperLimit, YLowerLimit, YUpperLimit);
}
public SvgScale AdjustOrigin(SvgMeasurement newX, SvgMeasurement newY)
{
return new SvgScale(this, newX, newY);
}
public float X(float x)
{
return _Scale * (x - XLowerLimit);
}
public float Y(float y)
{
return _Scale * (y - YLowerLimit);
}
public float Y(iTextSharp.text.pdf.PdfContentByte cb, float y)
{
return cb.PdfDocument.PageSize.Height - _Scale * (y - YLowerLimit);
}
public float M(float m)
{
return _Scale * m;
}
public float X(SvgMeasurement x)
{
float retval = _Scale * (x.GetSizeInPixels(DPI) - XLowerLimit);
return retval;
}
public float Y(SvgMeasurement y)
{
return _Scale * (y.GetSizeInPixels(DPI) - YLowerLimit);
}
public float Y(iTextSharp.text.pdf.PdfContentByte cb, SvgMeasurement y)
{
float yOffset = 0; // = (cb.PdfWriter.CurrentPageNumber -1) * .8F * cb.PdfDocument.PageSize.Height;
float myY = yOffset + cb.PdfDocument.PageSize.Height - _Scale * (y.GetSizeInPixels(DPI) - YLowerLimit);
if (myY < .1F * cb.PdfDocument.PageSize.Height)
{
cb.PdfDocument.NewPage();
myY += .8F * cb.PdfDocument.PageSize.Height;
}
return myY;
}
public float YY(SvgMeasurement y)
{
return -_Scale * y.GetSizeInPixels(DPI);
}
public float M(SvgMeasurement m)
{
return _Scale * m.GetSizeInPixels(DPI);
}
}
}

View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.Schema;
using System.IO;
namespace Volian.Svg.Library
{
public static class SvgSerializer<T> where T : class
{
public static string StringSerialize(T t)
{
string strOutput = string.Empty;
XmlSerializer xs = new XmlSerializer(typeof(T),"http://www.w3.org/2000/svg");
using (MemoryStream ms = new MemoryStream())
{
xs.Serialize( new NonXsiTextWriter(ms,Encoding.UTF8), t);
//xs.Serialize(ms, t);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
strOutput = sr.ReadToEnd();
ms.Close();
}
return strOutput;
}
public static T StringDeserialize(string s)
{
T t;
XmlSerializer xs = new XmlSerializer(typeof(T), "http://www.w3.org/2000/svg");
UTF8Encoding enc = new UTF8Encoding();
Byte[] arrBytData = enc.GetBytes(s);
using (MemoryStream ms = new MemoryStream(arrBytData))
{
t = (T)xs.Deserialize(ms);
}
return t;
}
public static void WriteFile(T t, string fileName)
{
string strOutput = string.Empty;
XmlSerializer xs = new XmlSerializer(typeof(T), "http://www.w3.org/2000/svg");
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
xs.Serialize(new NonXsiTextWriter(fs,Encoding.UTF8), t);
fs.Close();
}
}
public static T ReadFile(string fileName)
{
T t;
XmlSerializer xs = new XmlSerializer(typeof(T), "http://www.w3.org/2000/svg");
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
t = (T)xs.Deserialize(fs);
}
return t;
}
}
public class NonXsiTextWriter : XmlTextWriter
{
public NonXsiTextWriter( TextWriter w ) : base( w ) {}
public NonXsiTextWriter( Stream w, Encoding encoding ) : base( w, encoding ) {
this.Formatting = Formatting.Indented;
}
public NonXsiTextWriter( string filename, Encoding encoding ) : base( filename, encoding ) {}
bool _skip = false;
public override void WriteStartAttribute( string prefix, string localName, string ns )
{
if ((prefix == "xmlns" && (localName == "xsd" || localName == "xsi")) || // Omits XSD and XSI declarations.
ns == XmlSchema.InstanceNamespace ) // Omits all XSI attributes.
{
_skip = true;
return;
}
if(localName == "xlink_href")
base.WriteStartAttribute(prefix, "xlink:href", ns);
else
base.WriteStartAttribute( prefix, localName, ns );
}
public override void WriteString( string text ) {
if ( _skip ) return;
base.WriteString( text );
}
public override void WriteEndAttribute()
{
if ( _skip )
{ // Reset the flag, so we keep writing.
_skip = false;
return;
}
base.WriteEndAttribute();
}
}
}

View File

@ -0,0 +1,36 @@
using System;
using System.IO;
using System.Xml.Serialization;
using System.Drawing;
using System.ComponentModel;
namespace Volian.Svg.Library
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public abstract class SvgShapePart : SvgLinePart
{
#region Fill Settings
protected SvgFillSettings _MyFillSettings = new SvgFillSettings();
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("fill")]
public string Fill
{
get { return _MyFillSettings.Fill; }
set { _MyFillSettings.Fill = value; }
}
[XmlIgnore]
protected Color FillColor
{
get { return _MyFillSettings.FillColor; }
set { _MyFillSettings.FillColor = value; }
}
#endregion
#region Setup Inheritance
override internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
{
base.SetupInheritance(myParentsSettings);
_MyFillSettings.MyParentsSettings = myParentsSettings.MyFillSettings;
}
#endregion
}
}

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Drawing;
namespace Volian.Svg.Library
{
[XmlRoot("svg-test")]
public class SvgTest
{
public SvgTest()
{
_MyLineSettings = new SvgLineSettings(Color.Red,new SvgMeasurement(3, E_MeasurementUnits.PX));
_MyFillSettings = new SvgFillSettings(Color.Cyan);
_MyFontSettings = new SvgFontSettings(new Font("Cambria", 20, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, GraphicsUnit.Point));
}
#region Line Settings
private SvgLineSettings _MyLineSettings;
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("stroke")]
public string Stroke
{
get { return _MyLineSettings.Stroke; }
set { _MyLineSettings.Stroke = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("stroke-width")]
public string StrokeWidth
{
get { return _MyLineSettings.StrokeWidth; }
set { _MyLineSettings.StrokeWidth = value; }
}
#endregion
#region Fill Settings
private SvgFillSettings _MyFillSettings;
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("fill")]
public string Fill
{
get { return _MyFillSettings.Fill; }
set { _MyFillSettings.Fill = value; }
}
#endregion
#region Font Settings
private SvgFontSettings _MyFontSettings;
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-family")]
public string FontFamily
{
get { return _MyFontSettings.FontFamily; }
set { _MyFontSettings.FontFamily = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-size")]
public string FontSize
{
get { return _MyFontSettings.FontSize; }
set { _MyFontSettings.FontSize = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-style")]
public string SVGFontStyle
{
get { return _MyFontSettings.SVGFontStyle; }
set { _MyFontSettings.SVGFontStyle = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-weight")]
public string FontWeight
{
get { return _MyFontSettings.FontWeight; }
set { _MyFontSettings.FontWeight = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("text-decoration")]
public string TextDecoration
{
get { return _MyFontSettings.TextDecoration; }
set { _MyFontSettings.TextDecoration = value; }
}
#endregion
}
}

View File

@ -0,0 +1,146 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using System.ComponentModel;
namespace Volian.Svg.Library
{
public partial class SvgText : SvgShapePart
{
#region ctor
public SvgText() { ;}
public SvgText(PointF location, string text, Font font, Color fillColor)
{
_X.Value = location.X;
_Y.Value = location.Y;
Text = text;
Font = font;
FillColor = fillColor;
LineColor = Color.Empty;
LineWidth = new SvgMeasurement(0);
}
#endregion
#region Location
private SvgJustify _Justify = SvgJustify.Left;
[XmlAttribute("Justify")]
public SvgJustify Justify
{
get { return _Justify; }
set { _Justify = value; }
}
private SvgMeasurement _X = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement X
{
get { return _X; }
set { _X = value; }
}
[XmlAttribute("x")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string X_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_X); }
set { _X = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Y = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Y
{
get { return _Y; }
set { _Y = value; }
}
[XmlAttribute("y")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Y_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Y); }
set { _Y = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Text
private string _Text;
[XmlText()]
public string Text
{
get { return _Text; }
set { _Text = value; }
}
#endregion
#region Font Settings
private SvgFontSettings _MyFontSettings = new SvgFontSettings();
[XmlIgnore]
public Font Font
{
get
{
if (_MyFontSettings.Font.Size < 10)
Console.WriteLine("It didn't work!");
return _MyFontSettings.Font;
}
set
{
if (value.Size < 10)
Console.WriteLine("It didn't work!");
_MyFontSettings.Font = value;
}
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-family")]
public string FontFamily
{
get { return _MyFontSettings.FontFamily; }
set { _MyFontSettings.FontFamily = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-size")]
public string FontSize
{
get { return _MyFontSettings.FontSize; }
set { _MyFontSettings.FontSize = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-style")]
public string SVGFontStyle
{
get { return _MyFontSettings.SVGFontStyle; }
set { _MyFontSettings.SVGFontStyle = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("font-weight")]
public string FontWeight
{
get { return _MyFontSettings.FontWeight; }
set { _MyFontSettings.FontWeight = value; }
}
[System.ComponentModel.DefaultValueAttribute("")]
[XmlAttribute("text-decoration")]
public string TextDecoration
{
get { return _MyFontSettings.TextDecoration; }
set { _MyFontSettings.TextDecoration = value; }
}
#endregion
#region Setup Inheritance
override internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
{
base.SetupInheritance(myParentsSettings);
_MyFontSettings.MyParentsSettings = myParentsSettings.MyFontSettings;
}
#endregion
public override string ToString()
{
return string.Format("({0}, {1}) - '{2}'",this.X,this.Y,this.Text);
}
}
public enum SvgJustify
{
Left = 0,
Center = 1,
Right =2
}
}

View File

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing;
namespace Volian.Svg.Library
{
public partial class SvgUse : SvgPartInheritance
{
#region ctor
public SvgUse() { ;}
public SvgUse(PointF location, SizeF size, string id)
{
_X.Value = location.X;
_Y.Value = location.Y;
_Width.Value = size.Width;
_Height.Value = size.Height;
_ID = id;
}
#endregion
#region Location
private SvgMeasurement _X = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement X
{
get { return _X; }
set { _X = value; }
}
[XmlAttribute("x")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string X_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_X); }
set { _X = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Y = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Y
{
get { return _Y; }
set { _Y = value; }
}
[XmlAttribute("y")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Y_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Y); }
set { _Y = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region Size
private SvgMeasurement _Width = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Width
{
get { return _Width; }
set { _Width = value; }
}
[XmlAttribute("width")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Width_WidthmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Width); }
set { _Width = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
private SvgMeasurement _Height = new SvgMeasurement();
[XmlIgnore]
public SvgMeasurement Height
{
get { return _Height; }
set { _Height = value; }
}
[XmlAttribute("height")]
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public string Height_XmlSurrogate
{
get { return SvgXmlConverter<SvgMeasurement>.GetString(_Height); }
set { _Height = SvgXmlConverter<SvgMeasurement>.GetObject(value); }
}
#endregion
#region ID to be used
private string _UseID = null;
[XmlAttribute(AttributeName = "href", Namespace = "http://www.w3.org/1999/xlink")]
public string UseID
{
get { return _UseID; }
set { _UseID = value; }
}
#endregion
#region Setup Inheritance
override internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
{
_MyInheritedSettings.MyParentsSettings = myParentsSettings;
}
#endregion
public override string ToString()
{
return string.Format("({0}, {1}) Template '{2}'", this.X, this.Y, this.UseID);
}
}
}

View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;
namespace Volian.Svg.Library
{
[TypeConverter(typeof(ViewBoxTypeConverter))]
public class SvgViewBox
{
#region ctor
public SvgViewBox() { ;}
public SvgViewBox(float x, float y, float width, float height)
{
_MyRectangleF = new RectangleF(x, y, width, height);
}
public SvgViewBox(string val)
{
string[] parms = ((string)val).Split(' ');
_MyRectangleF = new RectangleF(Convert.ToSingle(parms[0]), Convert.ToSingle(parms[1]), Convert.ToSingle(parms[2]), Convert.ToSingle(parms[3]));
}
#endregion
#region Public Properties
private RectangleF _MyRectangleF = new RectangleF();
public float X
{
get { return _MyRectangleF.X; }
set { _MyRectangleF.X = value; }
}
public float Y
{
get { return _MyRectangleF.Y; }
set { _MyRectangleF.Y = value; }
}
public float Width
{
get { return _MyRectangleF.Width; }
set { _MyRectangleF.Width = value; }
}
public float Height
{
get { return _MyRectangleF.Height; }
set { _MyRectangleF.Height = value; }
}
#endregion
#region ToString
public override string ToString()
{
return string.Format("{0} {1} {2} {3}", X, Y, Width, Height);
}
#endregion
}
public class ViewBoxTypeConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type t)
{
return t == typeof(String);
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is SvgViewBox)
{
return value.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type t)
{
return t == typeof(String);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object val)
{
string[] parms = ((string)val).Split(' ');
SvgViewBox viewBox = new SvgViewBox(Convert.ToSingle(parms[0]), Convert.ToSingle(parms[1]), Convert.ToSingle(parms[2]), Convert.ToSingle(parms[3]));
return viewBox;
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
namespace Volian.Svg.Library
{
public static class SvgXmlConverter<T> where T : class
{
public static string GetString(T myObject)
{
if (myObject == null) return null;
TypeConverter FontConverter = TypeDescriptor.GetConverter(typeof(T));
return FontConverter.ConvertToInvariantString(myObject);
}
public static T GetObject(string value)
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
return (T)converter.ConvertFromInvariantString(value);
}
}
}

View File

@ -0,0 +1,111 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{293911B5-C602-483F-A97F-F962EEFB3CAE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Volian.Svg.Library</RootNamespace>
<AssemblyName>Volian.Svg.Library</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="Itenso.Rtf.Interpreter, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Downloads\Software\CodeProject\RtfConverter\Interpreter\bin\Debug\Itenso.Rtf.Interpreter.dll</HintPath>
</Reference>
<Reference Include="Itenso.Rtf.Parser, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Downloads\Software\CodeProject\RtfConverter\Parser\bin\Debug\Itenso.Rtf.Parser.dll</HintPath>
</Reference>
<Reference Include="itextsharp, Version=4.1.2.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Downloads\Software\PDF\iText\itextsharp-4.1.2-dll\itextsharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Drawing.Design" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DisplayText.cs" />
<Compile Include="FontFind.cs" />
<Compile Include="Graphics.cs" />
<Compile Include="iTextSharp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Svg.cs" />
<Compile Include="SvgArc.cs" />
<Compile Include="SvgCircle.cs" />
<Compile Include="SvgDefine.cs" />
<Compile Include="SvgEllipse.cs" />
<Compile Include="SvgFillSettings.cs" />
<Compile Include="SvgFontSettings.cs" />
<Compile Include="SvgGroup.cs" />
<Compile Include="SvgImage.cs" />
<Compile Include="SvgInheritedSettings.cs" />
<Compile Include="SvgLine.cs" />
<Compile Include="SvgLinePart.cs" />
<Compile Include="SvgLineSettings.cs" />
<Compile Include="SvgMeasurement.cs" />
<Compile Include="SvgPart.cs" />
<Compile Include="SvgPartInheritance.cs" />
<Compile Include="SvgParts.cs" />
<Compile Include="SvgRectangle.cs" />
<Compile Include="SvgRtf.cs" />
<Compile Include="SvgScale.cs" />
<Compile Include="SvgSerializer.cs" />
<Compile Include="SvgShapePart.cs" />
<Compile Include="SvgTest.cs" />
<Compile Include="SvgText.cs" />
<Compile Include="SvgUse.cs" />
<Compile Include="SvgViewBox.cs" />
<Compile Include="SvgXMLConverter.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

File diff suppressed because it is too large Load Diff