This commit is contained in:
parent
922104f983
commit
99d18fec1c
@ -8,157 +8,5 @@ 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
|
||||
//}
|
||||
// planned to be done early on but became a problem.
|
||||
}
|
||||
|
@ -525,7 +525,6 @@ namespace Volian.Svg.Library
|
||||
tmp.RestoreState();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class SvgText : SvgShapePart
|
||||
{
|
||||
private static string ReplaceSpecialCharacter(Match m)
|
||||
@ -559,6 +558,7 @@ namespace Volian.Svg.Library
|
||||
return Element.ALIGN_LEFT;
|
||||
}
|
||||
}
|
||||
// Draw's using PdfContentByte are for drawing PageList items.
|
||||
public override void Draw(PdfContentByte cb, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
|
||||
{
|
||||
string text = mySvg.OnProcessText(Text, this, scale);
|
||||
@ -568,25 +568,20 @@ namespace Volian.Svg.Library
|
||||
cb.SaveState();
|
||||
bool fill = FillColor != System.Drawing.Color.Transparent;
|
||||
bool stroke = OutlineWidth.Value != 0F && OutlineColor != System.Drawing.Color.Empty;
|
||||
|
||||
// Strip out inline commands that are overridden by the fontStyle
|
||||
if (Font.Bold) text = StripCommands(text, @"\\b0", @"\\b");
|
||||
if (Font.Italic) text = StripCommands(text, @"\\i0", @"\\i");
|
||||
if (Font.Underline) text = StripCommands(text, @"\\ulnone", @"\\ul0", @"\\ul");
|
||||
|
||||
float fontSize = scale.M(new SvgMeasurement(Font.SizeInPoints, E_MeasurementUnits.PT));
|
||||
int fontStyle = (Font.Bold ? iTextSharp.text.Font.BOLD : 0) + (Font.Italic ? iTextSharp.text.Font.ITALIC : 0);
|
||||
VolianPdf.RegisterFont(Font.Name);
|
||||
iTextSharp.text.Font font = FontFactory.GetFont(Font.Name, BaseFont.IDENTITY_H, true, scale.M(new SvgMeasurement(Font.SizeInPoints, E_MeasurementUnits.PT)), fontStyle, new Color(FillColor));
|
||||
iTextSharp.text.pdf.FontSelector fs = new FontSelector();
|
||||
fs.AddFont(font);
|
||||
if (font.BaseFont.GetWidthPoint("m", 12) == font.BaseFont.GetWidthPoint(".", 12))
|
||||
{
|
||||
VolianPdf.RegisterFont("VESymbFix");
|
||||
fs.AddFont(FontFactory.GetFont("VESymbFix", BaseFont.IDENTITY_H, true, scale.M(new SvgMeasurement(Font.SizeInPoints, E_MeasurementUnits.PT)), fontStyle, new Color(FillColor)));
|
||||
}
|
||||
else
|
||||
{
|
||||
VolianPdf.RegisterFont("Arial Unicode MS");
|
||||
fs.AddFont(FontFactory.GetFont("Arial Unicode MS", BaseFont.IDENTITY_H, true, scale.M(new SvgMeasurement(Font.SizeInPoints, E_MeasurementUnits.PT)), fontStyle, new Color(FillColor)));
|
||||
}
|
||||
iTextSharp.text.Font font = FontFactory.GetFont(Font.Name, BaseFont.IDENTITY_H, true, fontSize, fontStyle, new Color(FillColor));
|
||||
|
||||
Phrase ph = BuildPhrase(text, fontSize, fontStyle, font);
|
||||
|
||||
ColumnText ct = new ColumnText(cb);
|
||||
text = Regex.Replace(text, @"\\u[0-9]+[?]", new MatchEvaluator(ReplaceSpecialCharacter));
|
||||
text = Regex.Replace(text, @"\\'[0-9a-fA-F][0-9a-fA-F]", new MatchEvaluator(ReplaceHexCharacter));
|
||||
Phrase ph = fs.Process(text);
|
||||
float x = scale.X(X);
|
||||
float w = 0; // chk.GetWidthPoint();
|
||||
foreach (Chunk chk in ph.Chunks)
|
||||
@ -618,6 +613,106 @@ namespace Volian.Svg.Library
|
||||
ct.Go();
|
||||
cb.RestoreState();
|
||||
}
|
||||
|
||||
private Phrase BuildPhrase(string text, float fontSize, int fontStyle, iTextSharp.text.Font font)
|
||||
{
|
||||
bool fontUnderline = false;
|
||||
float fontTextRise = 0;
|
||||
|
||||
text = Regex.Replace(text, @"\\u[0-9]+[?]", new MatchEvaluator(ReplaceSpecialCharacter));
|
||||
text = Regex.Replace(text, @"\\'[0-9a-fA-F][0-9a-fA-F]", new MatchEvaluator(ReplaceHexCharacter));
|
||||
text += " ";
|
||||
Phrase ph = new Phrase();
|
||||
while (text.Length > 0)
|
||||
{
|
||||
string next = "";
|
||||
Match m = Regex.Match(text, @"\\[^ ]*?[ $]");
|
||||
if (m.Success)
|
||||
{
|
||||
// text is portion of text and next is remaining portion to process next
|
||||
next = text.Substring(m.Index + m.Length);
|
||||
text = text.Substring(0, m.Index);
|
||||
}
|
||||
else
|
||||
if (text[text.Length - 1] == ' ') text = text.Substring(0, text.Length - 1);
|
||||
|
||||
foreach (Chunk chk in BuildPartialPhrase(text, fontSize, fontStyle, font).Chunks)
|
||||
{
|
||||
if (fontUnderline) chk.SetUnderline(font.Color, 0, 0.05F, 0, -.131F, PdfContentByte.LINE_CAP_ROUND);
|
||||
if (fontTextRise != 0) chk.SetTextRise(fontTextRise * chk.Font.Size);
|
||||
ph.Add(chk);
|
||||
}
|
||||
if (m.Success)
|
||||
{
|
||||
// bold, underline, italics, subscript, superscript
|
||||
if (m.Value.Contains(@"\ulnone") || m.Value.Contains(@"\ul0")) // off
|
||||
fontUnderline = false;
|
||||
else if (m.Value.Contains(@"\ul"))
|
||||
fontUnderline = true;
|
||||
if (m.Value.Contains(@"\up0") || m.Value.Contains(@"\dn0")) fontTextRise = 0;
|
||||
else if (m.Value.Contains(@"\up")) fontTextRise = .25F;
|
||||
else if (m.Value.Contains(@"\dn")) fontTextRise = -.25F;
|
||||
if (m.Value.Contains(@"\b0"))
|
||||
{
|
||||
fontStyle ^= iTextSharp.text.Font.BOLD;
|
||||
font = FontFactory.GetFont(font.Familyname, BaseFont.IDENTITY_H, true, fontSize, fontStyle, new Color(FillColor));
|
||||
}
|
||||
else if (m.Value.Contains(@"\b"))
|
||||
{
|
||||
fontStyle |= iTextSharp.text.Font.BOLD;
|
||||
font = FontFactory.GetFont(font.Familyname, BaseFont.IDENTITY_H, true, fontSize, fontStyle, new Color(FillColor));
|
||||
}
|
||||
if (m.Value.Contains(@"\i0"))
|
||||
{
|
||||
fontStyle ^= iTextSharp.text.Font.ITALIC;
|
||||
font = FontFactory.GetFont(font.Familyname, BaseFont.IDENTITY_H, true, fontSize, fontStyle, new Color(FillColor));
|
||||
}
|
||||
else if (m.Value.Contains(@"\i"))
|
||||
{
|
||||
fontStyle |= iTextSharp.text.Font.ITALIC;
|
||||
font = FontFactory.GetFont(font.Familyname, BaseFont.IDENTITY_H, true, fontSize, fontStyle, new Color(FillColor));
|
||||
}
|
||||
}
|
||||
text = next;
|
||||
}
|
||||
return ph;
|
||||
}
|
||||
|
||||
private Phrase BuildPartialPhrase(string text, float fontSize, int fontStyle, iTextSharp.text.Font font)
|
||||
{
|
||||
iTextSharp.text.pdf.FontSelector fs = new FontSelector();
|
||||
fs.AddFont(font);
|
||||
if (font.BaseFont.GetWidthPoint("m", 12) == font.BaseFont.GetWidthPoint(".", 12))
|
||||
{
|
||||
VolianPdf.RegisterFont("VESymbFix");
|
||||
fs.AddFont(FontFactory.GetFont("VESymbFix", BaseFont.IDENTITY_H, true, fontSize, fontStyle, new Color(FillColor)));
|
||||
}
|
||||
else
|
||||
{
|
||||
VolianPdf.RegisterFont("Arial Unicode MS");
|
||||
fs.AddFont(FontFactory.GetFont("Arial Unicode MS", BaseFont.IDENTITY_H, true, fontSize, fontStyle, new Color(FillColor)));
|
||||
}
|
||||
|
||||
Phrase ph = fs.Process(text);
|
||||
return ph;
|
||||
}
|
||||
|
||||
private string StripCommands(string text, params string [] rtfCommands)
|
||||
{
|
||||
foreach (string rtfCommand in rtfCommands)
|
||||
{
|
||||
// remove rtf command preceeded by another rtf command with previous
|
||||
// rtf ending with a space, i.e. "\ulnone\b0 " removing the "b0", leaves " "
|
||||
// * - as many as there are, ? - minimum number that results in a match
|
||||
text = Regex.Replace(text, @"(\\[^ ]*?)" + rtfCommand + " ", "$1 ");
|
||||
// remove rtf command follwed by a space
|
||||
text = Regex.Replace(text, rtfCommand + " ", "");
|
||||
// remove just the rtf command
|
||||
text = Regex.Replace(text, rtfCommand, "");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
// Draw's using PdfTemplate are for drawing SVG (16-bit genmac).
|
||||
public override void Draw(PdfTemplate tmp, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
|
||||
{
|
||||
string text = mySvg.OnProcessText(Text, this, scale);
|
||||
|
Loading…
x
Reference in New Issue
Block a user